CoreFi: A Core Calculus for Embedded Systems with Bounded Shared-Memory Channels
Analyze & explore related research in Conceptio
Connect this record directly into your research workflow or AI agent. Explore citations across open repositories, query full text, and export structured proof bundles.
CoreFi: A Core Calculus for Embedded Systems with Bounded Shared-Memory Channels YAN LIU, Australian National University, Australia yan.liu@anu.edu.au
ALEX POTANIN, Australian National University, Australia
arXiv:2611.40661v1 [cs.PL] 30 Nov 2026
alex.potanin@anu.edu.au Embedded systems are built from components that compute on private state and communicate over bounded buffers in shared memory; since a component must keep running rather than wait on a slower one, a sender drops a message when the buffer is full, and a receiver blocks when it is empty. Process calculi, the established basis for reasoning about communicating systems, model these channels as bounded queues that block a sender when full. The code itself, written in a low-level language such as C, intertwines computation and communication so tightly that the message-passing protocol is hard to recover automatically for verification. We present CoreFi, a core calculus for embedded systems with bounded shared-memory channels, derived from Communicating Sequential Processes (CSP), that addresses both. Our channel semantics is faithful to embedded practice, and we extend CSP’s abstract events to concrete computation events, calls to foreign functions, so that a component’s program in CoreFi becomes an orchestration of its communication and computation events. The composition of the component processes is defined by the scheduling logic of the underlying kernel, one rule that says when a component runs its body next, from an initial configuration the boot leaves, rather than by a parallel operator; we instantiate it on the verified microkernel seL4 and its MicroKit framework. Deadlock freedom and determinism are two fundamental properties of embedded systems, and we prove both for every well-formed system, that is, one whose communication dependencies are acyclic and whose guarded choices partition the state space. The separation of computation from communication also separates local from global state change: computation events, which change only a component’s local state, can be absorbed into big steps, and the abstracted components compose to a smaller model of the global behaviour; a refinement relation guarantees that trace properties proved on the abstracted global state space hold of the complete one. We provide the formalisation and the proofs in Lean 4, assisted by a coding agent. CCS Concepts: • Software and its engineering → Domain specific languages; Formal language definitions; • Theory of computation → Process calculi; • Computer systems organization → Embedded software. Additional Key Words and Phrases: embedded systems, process algebra, seL4, microkernel
1
Introduction
Embedded systems run network appliances and protocol stacks, driver-assistance functions in cars, flight control in aircraft, and the control systems of critical infrastructure such as power grids and water treatment, where a failure costs more than a crash of the software; many run for years without a restart, so a fault cannot simply be patched after deployment. Whatever the domain, such a system is built the same way: as a set of components—drivers, protocol handlers, controllers—each running on private state, invoked by a kernel or a scheduler when something arrives for it, and communicating with the others through shared memory. A network driver, for example, is woken by its device and reads a frame’s header to decide whether to forward the frame, reply to it or discard it. Forwarding copies the frame into a buffer shared with the next component; when that buffer is full the frame is dropped, since the driver must keep running rather than wait. In C, the most common implementation language, the manipulation of shared memory, the computation and the signalling of other components are interleaved in one program. Such code is hard to write correctly and harder to verify: properties of the whole system, deadlock freedom first among them, depend on the communication protocol, which can be recovered from the intertwined code neither easily by hand nor reliably by a tool. It would therefore be ideal to program the communication protocol , Vol. 1, No. 1, Article . Publication date: December 2026.
apart from the computation, by which we mean both a component’s logic and its manipulation of memory, so that the protocol becomes a program of its own, an orchestration of each component’s computation and communication steps. That program can then serve directly as the model of the protocol: formalising it for a model checker [2, 9, 16, 30] becomes an automatic step, and the model evolves with the code, its verification results updated rather than invalidated when the program changes. P [6] was among the first languages to take this approach: its components are state machines exchanging events over unbounded queues, compiled to code and explored by a systematic tester. Synchronous dataflow languages such as Lustre [12] and SCADE do the same for control software: a program is verified as written and compiled by a qualified generator, over a clocked schedule and without shared-memory communication between components. Mimosa [18, 19] gives a formal semantics to time-triggered processes over FIFO buffers and compiles them to real-time tasks; Lingua Franca [23] makes reactor programs deterministic by construction through logical time; on seL4, Kalas [27] compiles a global program to verified code, and Tower [14] generates the communication between Ivory tasks. Code generation from a verified model [10, 11, 34] goes the other way, from a written model to code, keeping the two in step by construction. Each formalises the program on a communication model of its own, none on bounded buffers that drop when full, and in each the formalisation is either not automated or leaves out the platform’s scheduler. We present CoreFi, a core calculus that takes this approach on the platform’s own model, derived from Communicating Sequential Processes (CSP) [15].1 A component’s orchestration is a process term that sequences computation events, named blocks that call local code, with sends and receives on channels, under guards over the component’s store; the computation stays in the language it is already written in. For the program to be the model of the system, the semantics must be the platform’s: asynchronous channels are bounded, a send to a full buffer dropping its value rather than blocking, synchronous channels are rendezvous, computation is not silent, and a kernel decides when a component runs. We instantiate the calculus on the verified microkernel seL4 [20] and its MicroKit framework [32], whose isolated address spaces, channels and memory mappings are the components, channels and regions of the calculus, and whose scheduler supplies the platform’s rule. Our contributions are: • A calculus with no silent steps (§3): a guard fires atomically with the event it guards, since a silent step would resolve a choice invisibly, and termination is a predicate on states rather than an event, so every transition of a component’s local labelled transition system (llts) carries an observable label, computation events included. • The platform as a rule (§4): the global labelled transition system (glts) composes the lltses directly over a shared channel store, reading each component’s current invocation, a fresh body once the previous run has terminated, from an initial configuration the platform’s boot leaves; the process term has no scheduler loop and the composition no parallel operator, and instantiating the calculus on a platform, as we do for seL4 MicroKit, means supplying this rule and that configuration. • Properties by construction (§5): every system keeps its buffers within capacity, and two structural conditions, acyclic dependency and choice partition, make every well-formed system deadlock-free, in an open-system form that tolerates waiting on the environment, and deterministic, each label leading from any reachable configuration to at most one successor, without exploring its state space. • Abstraction beside the composition (§6): since a computation event changes only its component’s local state, an abstraction of each llts that absorbs computation into big steps (alts) 1 In memory of Sir Tony Hoare (1934–2026), inventor of CSP and Turing Award laureate.
2
Guarantee One-way Data Flow
Public Network
eth outer pri = 99
o2d
DataDiode pri = 150
d2i
eth inner pri = 199
Private Network
Fig. 1. The data diode.
has the same channel traces, and the composition of the abstractions has those of the glts, so a trace property checked on the smaller model holds of the system, while determinism, which is not a trace property, is proved of the system itself. All of the above is mechanised in Lean 4 [25] with CSLib [5], developed with the assistance of a coding agent; the development accompanies the paper [8]. §2 introduces the running example, a network data diode, §7 discusses related work and §8 concludes. 2
Running Example: Data Diode
A network data diode is a hardware-enforced security device that allows data to flow in only one direction—from an untrusted public network to a trusted private network—preventing any reverse channel.2 We build a software one, and we build it twice: in C, as embedded developers write it today, and in CoreFi. The system has three components (Figure 1): eth outer drives the network card on the public side, eth inner the one on the private side, and the diode component dd sits between them. Two one-way channels connect them, o2d from eth outer to dd and d2i from dd to eth inner, each a ring of packet slots in a memory region shared by its two ends. The diode forwards every packet it finds on o2d to d2i, and drops it when d2i is full rather than wait, so that a slow private side can never hold up the public one. The diode in C. Figure 2 is the diode component as MicroKit’s ethernet example writes it [31], forwarding direction only, debug output elided and identifiers shortened; the example’s full sources, the two ethernet drivers included, are public. The C function notified runs whenever a channel fires (§4.2 returns to this platform contract) and walks the upstream ring until it finds a free slot. For each occupied slot it computes the slot’s address from a base address and an index, wraps the index by hand, tests the downstream slot’s flag, copies the packet and sets the flag, or drops the packet, and finally clears the upstream flag to hand the slot back. None of this is the diode’s decision; it is the ring protocol, and both ethernet drivers repeat it for each ring they touch. Nothing in the C states that the flow is one way, either: it is one way because no component happens to write to o2d from the private side. The diode in CoreFi. §3 introduces CoreFi by writing the same component, one construct at a time. The ring protocol becomes the meaning of two channel events, and the one-way flow becomes a fact of the channel declarations. 3
The CoreFi Calculus
A CoreFi program consists of channel declarations and one component program per component, which orchestrates the component’s local computation and its communication over the channels. CoreFi is designed to be an executable language rather than a declarative specification; following Roscoe’s process algebra for CSP [29], each construct comes with its step-by-step operational 2 https://owlcyberdefense.com/products/data-diode-products/
3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
# define BUFFER_SIZE (2 * 1024) # define DATA_OFFSET 64 # define BUFFER_MAX 1024 struct buffer_descriptor { uint16_t data_length ; uint16_t flags ; }; unsigned in_idx = 0 , out_idx = 0; uintptr_t IN , OUT ; /* bases */ volatile struct buffer_descriptor *bd , * obd ; volatile void * pkt , * opkt ; void init ( void ) { /* debug output only */ }
16 void notified ( microkit_channel ch ) { 17 switch ( ch ) { 18 case OUTER_INPUT_CH : 19 for (;;) { 20 bd = ( void *) ( IN + BUFFER_SIZE * in_idx ) ; 21 pkt = ( void *) bd + DATA_OFFSET ; 22 if ( bd - > flags == 0) break ; 23 in_idx = ( in_idx + 1) % BUFFER_MAX ; 24 obd = ...; opkt = ...; /* as above , OUT */ 25 if ( obd - > flags == 1) { 26 /* no space downstream : drop */ 27 } else { 28 obd - > data_length = bd - > data_length ; 29 mycpy ( opkt , pkt , bd - > data_length ) ; 30 obd - > flags = 1; 31 microkit_notify ( INNER_OUTPUT_CH ) ; 32 out_idx = ( out_idx + 1) % BUFFER_MAX ; 33 } 34 bd - > flags = 0; 35 } 36 break ; 37 } 38 }
/* eth .c , the driver : transmit a frame on the NIC 's ring ( debug output elided ) */ static void send_frame ( uint8_t *d , unsigned int length ) { uint16_t flags = tbd [ tbd_index ]. flags ; if ( flags & (1 << 15) ) { return ; } /* ran out of tx buffers */ void * packet = ( void *) ( uintptr_t ) ( packet_buffer_vaddr + (( RBD_COUNT + tbd_index ) * PACKET_BUFFER_SIZE ) ) ; mycpy ( packet , d , length ) ; seL4_ARM_VSpace_CleanInvalidate_Data (3 , ( uintptr_t ) packet , (( uintptr_t ) packet ) + length ) ; flags = (1 << 15) /* ready */ | (1 << 11) /* last in frame */ | (1 << 10) ; /* transmit crc */ if ( tbd_index == TBD_COUNT - 1) { flags |= (1 << 13) ; } /* wrap */ tbd [ tbd_index ]. data_length = length ; tbd [ tbd_index ]. flags = flags ; eth -> tdar = (1 << 24) ; /* SEND */ tbd_index ++; if ( tbd_index == TBD_COUNT ) { tbd_index = 0; } }
Fig. 2. The diode component in C, and the driver’s transmit function.
semantics, given here beside its syntax. The process language follows CSP [15], extended with guards over data, assignments and calls into local code, as CSP# [30] and Promela [16] are; guarded processes and external choices encode conditionals, and recursion encodes loops. One deliberate departure from vanilla CSP is the omission of internal choice: non-determinism is undesirable in a program, and restricting to external choice is a prerequisite for the determinism result while preserving CSP’s compositional reasoning power. We introduce each construct by writing the diode component with it; the program grows construct by construct. Programs are written in an ASCII rendering of the abstract syntax: -> for →, [] for 2, and named process definitions for recursion. 3.1
Channels
Components communicate only through declared channels. All CoreFi channels are single-producer single-consumer—a well-established practice in embedded systems enabling lock-free, low-overhead, 4
race-free communication—and a channel names its sender and receiver, so that events need no location annotations. 𝑁 𝑝 𝑐 F 𝑝 →𝑚 asynchronous channel with buffer region 𝑚 and capacity 𝑁 ≥ 1 | 𝑝 1 ↣ 𝑝 2 synchronous channel; no buffer 𝑁 ) are bounded: they buffer up to 𝑁 values in a FIFO, 𝑁 for channel Asynchronous channels (→𝑚 𝑐 𝑐, a send to a full buffer drops its value rather than blocking, and a receive blocks when the buffer is empty—unlike most process models, which assume unbounded channels or block a sender at capacity. Synchronous channels (↣) rendezvous directly, with no buffer. Every channel runs between two components, except an interrupt channel, which wraps a hardware interrupt and has the environment at its other end: a receive on it is the interrupt’s delivery, which the environment may send at any time, and a send on it is the acknowledgement, which the environment never refuses, so it never blocks.
Declaration. A channel is declared by one of two rules: an asynchronous channel needs two distinct endpoints and a fresh buffer region, which the platform maps into both; a synchronous channel needs only two distinct endpoints, a platform possibly constraining them further: Chan-Async
𝑁 𝑐 ≜ (𝑝 1 →𝑚 𝑝2 )
𝑐 ∉𝐶 𝐶, 𝑀
Chan-Sync
𝐶
𝑝1 ≠ 𝑝2
𝑁 ≥1
𝑚∈𝑀
𝑚 ∉ 𝑀𝐶
⊢ 𝑐 ; 𝐶 ∪ {𝑐 }, 𝑀 ∪ {𝑚} 𝐶
𝑐 ≜ (𝑝 1 ↣ 𝑝 2 ) 𝑐 ∉𝐶 𝐶 ⊢ 𝑐 ; 𝐶 ∪ {𝑐 }
𝑝1 ≠ 𝑝2
Buffer semantics. The buffer of an asynchronous channel 𝑐 is a FIFO queue 𝑞 ∈ Val ≤𝑁𝑐 , the front being the next value to leave and the back where the next value arrives. Two operations define it: ( 𝑞 · 𝑣 |𝑞| < 𝑁𝑐 enq(𝑞, 𝑣) = deq(𝑣 · 𝑞 ′ ) = (𝑣, 𝑞 ′ ), 𝑞 |𝑞| = 𝑁𝑐 so an enqueue to a full buffer drops the value and leaves the buffer unchanged, and a dequeue is defined only on a non-empty buffer; a send is an enqueue and a receive a dequeue. Concretely the platform realises 𝑞 as a ring of 𝑁𝑐 flagged slots over 𝑚: a write index and a read index advance modulo 𝑁𝑐 , enq returns at once when the slot at the write index is flagged occupied, and deq clears the flag of the slot at the read index after taking its value. That ring is what the C of Figure 2 operates by hand; a CoreFi program never touches it, only sends and receives. A synchronous channel has no buffer: its send and receive meet in a rendezvous, which is a rule of the composition, not of the component. In the diode. The diode’s two channels are asynchronous, each over a buffer region of the C’s buffer_descriptors; the capacity is not stated but computed, the region’s size over the descriptor’s, 1024 for the C’s 2 MiB regions and 2 KiB descriptors: chan o2d = eth_outer -> dd chan d2i = dd -> eth_inner
via m_o2d < buffer_descriptor > via m_d2i < buffer_descriptor >
The two lines replace the C’s ring layout, its indices and its base addresses (lines 1–8), and the system configuration that maps each ring into its two ends. The direction is part of the declaration: dd can only receive on o2d and only send on d2i, and no declaration lets eth inner reach eth outer. 3.2
Stores
A component computes on a local store, private memory no other component can reach. What is shared is the channel buffers, which live in memory regions mapped into both endpoints: the 5
system holds each buffer once, in the global channel store, and a component holds a view of the buffers of its channels. A local state pairs the process term with the two. Definition 3.1 (Local State Configuration). The local state configuration of component 𝑝 is the triple 𝑠 𝑝 = ⟨𝜌 𝑝 , 𝜎 𝑝 , 𝛾 𝑝 ⟩ where: • 𝜌 𝑝 is the current process term; • 𝜎 𝑝 : N ⇀ Val is the local store, the component’s private memory as a partial map from slot addresses to values, which no other component can reach; and • 𝛾 𝑝 : 𝐶𝑝 ⇀ Val ∗ is the channel buffer view, a per-channel FIFO queue over the async channels of 𝑝, where 𝐶𝑝 = { 𝑐 ∈ 𝐶 async | 𝑝 ∈ sender (𝑐) ∪ receiver (𝑐) }. We write 𝑆 𝑝 for the set of all such triples, the state space of 𝑝. Definition 3.2 (Global Channel Store). The global channel store Γ : 𝐶 async → Val ∗ maps each asynchronous channel 𝑐 to the finite sequence Γ(𝑐) ∈ Val ≤𝑁𝑐 of values currently held in its FIFO buffer; the front of Γ(𝑐) is the next value to be dequeued and the back is where the next enqueue appends. Synchronous channels have no buffer and are not in the domain of Γ. The view 𝛾 𝑝 of a component is not a copy: it is read off the store as 𝛾 𝑝 = Γ|𝐶𝑝 . Since all endpoints of 𝑐 map the same physical region (Coh, §4.2), the view of every endpoint agrees with the store: ∀ 𝑐 ∈ 𝐶 async , ∀ 𝑝 ∈ sender (𝑐) ∪ receiver (𝑐). 𝛾 𝑝 (𝑐) = Γ(𝑐)
(G-Coh)
A local rule changes a component’s view; the composition writes the changed view back to Γ, so (G-Coh) is kept by construction. 3.3
Events
A component program has two parts: computation events, named statement blocks of assignments and function calls, and processes, which sequence computation events and channel events into the 𝑝 𝑝 component’s execution flow. The event alphabet of 𝑝 is Σ𝑝 = Σ𝛼 ∪ Σ𝑐 : the computation events 𝑝 𝑝 Σ𝛼 = {𝛼 1, 𝛼 2, . . .}, each fired atomically as one step, and the communication events Σ𝑐 = { 𝑐!𝑣 | 𝑝 ∈ sender (𝑐), 𝑣 ∈ Val } ∪ { 𝑐?𝑣 | 𝑝 ∈ receiver (𝑐), 𝑣 ∈ Val }. A guarded event [𝑏] ℓ is an event ℓ ∈ Σ𝑝 annotated with the guard under which it fired (Guard-T); the guard is an execution-time constraint, not a distinct observable, and [𝑏] ℓ and ℓ are indistinguishable in traces. Notation. We write ⟦𝑒⟧𝜎 for the evaluation of expression 𝑒 in local store 𝜎, and 𝑠 [𝑥 ↦→ 𝑣] for the store 𝑠 updated to map 𝑥 to 𝑣; a program variable 𝑥 is a slot address of 𝜎. For a guard 𝑏 and a label ℓ ∈ Λ𝑝 , the guard merge [𝑏] · ℓ annotates ℓ with 𝑏, flattening nested guards by conjunction: [𝑏] · ℓ = [𝑏] ℓ
if ℓ ∈ Σ𝑝 ,
[𝑏] · ( [𝑏 ′ ] ℓ0 ) = [𝑏 ∧ 𝑏 ′ ] ℓ0 .
3.3.1 Communication Events. A channel event is a single communication action on a declared channel 𝑐 ∈ 𝐶: a send 𝑐!𝑒 by the channel’s sender or a receive 𝑐?𝑥 by its receiver. On an asynchronous channel the two are the buffer operations applied to the component’s view 𝛾 (Table 1). Send and Loss are enq, with room and at capacity, and Recv is deq, binding the head value to 𝑥. On an empty buffer no rule applies: the component has no transition until a send on 𝑐 fills it, which is the only way a component blocks short of a rendezvous. On a synchronous channel 𝑐 from 𝑝 1 to 𝑝 2 the two meet in a rendezvous, which is never within one component: Sync relates the pair (𝑠 𝑝 1 , 𝑠 𝑝 2 ) of the sender’s and the receiver’s local states, exchanging the value in one step labelled 𝑐.𝑣 and touching no buffer; the composition applies it to the two components’ current states. A term contains 𝑐!𝑒 or 𝑐?𝑥 only if 𝑝 is the declared sender or receiver of 𝑐, so the rules’ endpoint assumptions hold by construction. 6
Table 1. Communication event rules 𝑐 ∈ dom(𝛾 )
𝑣 = ⟦𝑒⟧𝜎
|𝛾 (𝑐 ) | < 𝑁𝑐
𝑐 ∈ dom(𝛾 )
Send
𝑣 = ⟦𝑒⟧𝜎
|𝛾 (𝑐 ) | = 𝑁𝑐
Loss 𝑐!𝑣
𝑐!𝑣
⟨𝑐!𝑒 → 𝜌, 𝜎, 𝛾 ⟩ −−→ ⟨𝜌, 𝜎, 𝛾 [𝑐 ↦→ 𝛾 (𝑐 ) · 𝑣 ] ⟩
⟨𝑐!𝑒 → 𝜌, 𝜎, 𝛾 ⟩ −−→ ⟨𝜌, 𝜎, 𝛾 ⟩
𝑐 ∈ dom(𝛾 ) 𝛾 (𝑐 ) = 𝑣 · 𝑞
′
Recv 𝑐?𝑣
⟨𝑐?𝑥 → 𝜌, 𝜎, 𝛾 ⟩ −−→ ⟨𝜌, 𝜎 [𝑥 ↦→ 𝑣 ], 𝛾 [𝑐 ↦→ 𝑞 ′ ] ⟩
Sync
𝑐 ≜ (𝑝 1 ↣ 𝑝 2 ) 𝑠 𝑝 1 = ⟨𝑐!𝑒 → 𝜌 1 , 𝜎1 , 𝛾 1 ⟩ 𝑠 𝑝 2 = ⟨𝑐?𝑥 → 𝜌 2 , 𝜎2 , 𝛾 2 ⟩
𝑣 = ⟦𝑒⟧𝜎1
𝑐.𝑣
(𝑠 𝑝 1 , 𝑠 𝑝 2 ) −−→ ( ⟨𝜌 1 , 𝜎1 , 𝛾 1 ⟩, ⟨𝜌 2 , 𝜎2 [𝑥 ↦→ 𝑣 ], 𝛾 2 ⟩)
Table 2. Computation event rules
Evt-Assign 𝜎0 = 𝜎
Evt-Seq
𝑣 = ⟦𝑒⟧𝜎 effect (𝑥 ← 𝑒, 𝜎, 𝛾 ) = 𝜎 [𝑥 ↦→ 𝑣 ]
Evt-Call
∀ 𝑖 ∈ 1..𝑛. effect (𝛼𝑖 , 𝜎𝑖 −1 , 𝛾 ) = 𝜎𝑖 effect (𝛼 1 ; · · · ; 𝛼𝑛 , 𝜎, 𝛾 ) = 𝜎𝑛
Evt
¯ 𝜎) 𝜎 ′ = ⟦𝑔⟧(𝑥, effect (call (𝑔, 𝑥¯ ), 𝜎, 𝛾 ) = 𝜎 ′ 𝛼 ∈ Σ𝛼
effect (𝛼, 𝜎, 𝛾 ) = 𝜎 ′ 𝛼
⟨𝛼 → 𝜌, 𝜎, 𝛾 ⟩ − → ⟨𝜌, 𝜎 ′ , 𝛾 ⟩
3.3.2 Computation Events. A computation event 𝛼 is a sequence of assignments and external function calls; what it computes is opaque to the calculus, which records only its effect on the local store, possibly none. Block 𝛼 F 𝑥 ← 𝑒 assignment of expression 𝑒 to variable 𝑥 ¯ | call(𝑔, 𝑥) function call with arguments 𝑥¯ | 𝛼; 𝛼 a sequence of assignments and calls where 𝑔 names a function of the external implementation, imported from its header and called by its qualified name, such as eth.send_frame, and 𝑥¯ are slot addresses passed by reference. Expressions 𝑒 are those of a common expression language over constants and the slots of the local store, and a guard 𝑏 is a boolean combination of comparisons between expressions; neither calls a function, and neither reads a channel: a component sees a message only by receiving it. Table 2 gives the rules. The effect function computes the store update: Evt-Assign evaluates and writes to 𝜎; Evt-Call passes the slot addresses 𝑥¯ to 𝑔 by reference, 𝑔 being opaque to the calculus and updating only those slots; Evt-Seq threads stores left-to-right through a sequence of statements. The big-step rule Evt is the transitive closure of the statement-level steps, firing the entire event atomically as a single 𝛼-labelled transition and hiding all intermediate stores from the environment. In the diode. The diode computes nothing: forwarding a packet is a send. The drivers do: eth inner hands each packet it receives on d2i to its network card through an event whose block calls the C function the ethernet example already has (Figure 2, line 40), which copies the frame into the transmit ring, cleans the cache, fills the descriptor and kicks the device, computation of a kind the calculus leaves to C: import " eth . h " as eth evt tx ( x ) = eth . send_frame ( x )
The diode has no guard; the drivers’ guards, whether a frame was polled and what it is, are tests over the local store their polling event fills. 7
3.4
Processes
A process sequences events; a channel event is written the same way on both kinds of channel, the declared channel 𝑐 determining whether the communication is synchronous or asynchronous. evt F 𝛼 computation event (a named statement block) | 𝑐 ? 𝑥 channel receive, binding the received value to variable 𝑥 | 𝑐 !𝑒 channel send, writing expression 𝑒 to channel 𝑐 𝑃𝑟𝑜𝑐𝑒𝑠𝑠 𝜌
F | | | | | | |
Ω 𝑆𝑘𝑖𝑝 evt → 𝜌 [𝑏] 𝜌 𝜌1 2 𝜌2 (𝜌 1 2 𝜌 2 ) default 𝜌𝑑 𝜌1 ; 𝜌2 𝜇 𝑋. 𝜌
divergence (≜ 𝜇𝑋 . 𝑋 ) successful termination of a process event prefixing guarded process external choice default external choice sequential composition recursion with process variable 𝑋
Divergence Ω ≜ 𝜇𝑋 . 𝑋 is the embedded failure mode: a component hangs on error rather than terminate, keeping shared state intact. Skip is a terminal term: it performs no event, and termination is a predicate on states, defined below. Recursion is otherwise required to be guarded: in 𝜇𝑋 . 𝜌, every occurrence of 𝑋 in 𝜌 lies under an event prefix, so each unfolding performs at least one event before recurring; a prefix on the left of 𝜌 1 ; 𝜌 2 does not guard 𝜌 2 , so a loop is written prefix-headed, 𝜇𝑋 . evt → (· · · ; 𝑋 ). Recursion is moreover tail recursion: a recursion variable occurs only in tail position and refers to its own innermost loop. Ω is the sole unguarded exception, with its own dedicated rule. The variable 𝑋 is not surface syntax: it occurs only bound by 𝜇𝑋 . Named process definitions and calls, as in the running example, are surface sugar for recursion. The default external choice (𝜌 1 2 𝜌 2 ) default 𝜌𝑑 guarantees progress: 𝜌𝑑 is taken when neither 𝜌 1 nor 𝜌 2 is enabled, ensuring the process always progresses. When 𝜌 1 2 𝜌 2 is a sequence of guarded processes of the form [𝑏 1 ]𝜌 1 2 · · · 2 [𝑏𝑛 ]𝜌𝑛 , the implicit guard of 𝜌𝑑 is ¬(𝑏 1 ∨ · · · ∨ 𝑏𝑛 ), making the full partition complete by the law of excluded middle. In particular, (𝜌 1 2 𝜌 2 ) default 𝑆𝑘𝑖𝑝 ends the current run of the body when nothing is enabled—the idiomatic “yield” of an event-driven component. A choice of one branch, [𝑏] 𝜌 default 𝜌𝑑 , abbreviates ( [𝑏] 𝜌 2 [⊥] 𝜌) default 𝜌𝑑 , with ⊥ the guard that never holds. Bodies. A component program declares one body 𝜌 body , a process term whose run either terminates or diverges, Ω spinning on the event hang (Div) and never returning to the platform; the component’s initial local store is given, produced by whatever initialisation the platform runs before any communication. How often a terminating body runs, and what runs it, is the platform’s decision, not the term’s: the process language has no top-level loop, and inner recursion is ordinary guarded 𝜇𝑋 . 𝜌 and may exit freely. A body is receive-headed: its head, through the left operand of ; and through 𝜇, is an external choice of receive prefixes, one per channel the component reacts to. This is what makes a component reactive: a body runs because a message or an interrupt arrived, and its first act is to consume it; a polling loop is receive-headed on its device channel, a time-triggered task on its timer channel, and a component with nothing to wait on is not a component of this kind. Receive-headedness keeps a quiet component always waiting on some channel, never silently quiescent, which the deadlock-freedom argument turns on. Concurrency. Compared to classic CSP, we remove the parallel (𝜌 1 ∥ 𝛼 𝜌 2 ) and interleave (𝜌 1 ||| 𝜌 2 ) compositions. We assume no concurrency within a component, consistent with the restriction of the platform we target; this remains a natural future extension. 8
Since the alphabet has no termination event, successful completion is a property of a local state, defined by structural descent on the process term: Definition 3.3 (Termination). The predicate term(𝜌, 𝜎, 𝛾) holds exactly in the following cases: term(Skip, 𝜎, 𝛾) term( [𝑏] 𝜌, 𝜎, 𝛾) term(𝜌 1 ; 𝜌 2, 𝜎, 𝛾) term((𝜌 1 2 𝜌 2 ) default 𝜌𝑑 , 𝜎, 𝛾) term(𝜇𝑋 . 𝜌, 𝜎, 𝛾)
iff iff iff iff iff
always; ⟦𝑏⟧𝜎 = true ∧ term(𝜌, 𝜎, 𝛾); term(𝜌 1, 𝜎, 𝛾) ∧ term(𝜌 2, 𝜎, 𝛾); ⟨𝜌 1, 𝜎, 𝛾⟩ → ̸− ∧ ⟨𝜌 2, 𝜎, 𝛾⟩ → ̸− ∧ term(𝜌𝑑 , 𝜎, 𝛾); term(𝜌, 𝜎, 𝛾);
and is false for all other process forms (Ω, event prefixes, plain external choice, and 𝑋 ). A terminated state is quiet by success: termination and enabledness are disjoint (a terminated process has no transitions), so Seq and Seq-Term below never overlap. A default Skip choice is terminated precisely when neither branch is enabled, the “nothing to do” exit of a run of the body, after which the component is parked (MK-Restart); plain external choice never terminates. The negative premises here and in Ext-Default are decided by the same structural descent, which guardedness of recursion keeps well-founded; the recursion clause descends into the body without unfolding. Concretely, ⟨𝜌, 𝜎, 𝛾⟩ → ̸− abbreviates that 𝜌 is not enabled, where enabledness is defined by structural descent alongside term: Skip and a bound variable are not enabled, Ω is; a computation prefix is always enabled, a send when its channel is declared asynchronous (Send or Loss), a receive when its buffer is non-empty; [𝑏] 𝜌 when 𝑏 holds and 𝜌 is enabled; a choice, default or not, when a branch is, a default choice also when 𝜌𝑑 is; 𝜌 1 ; 𝜌 2 when 𝜌 1 is enabled, or 𝜌 1 is terminated and 𝜌 2 is enabled; and 𝜇𝑋 . 𝜌 when 𝜌 is. The 𝜌 1 -terminated clause is the mutual recursion between enabledness and termination that the stratification orders. Table 3. Process rules hang ∈ Σ𝛼
Div
[𝑏 ] ·ℓ
hang
⟨ [𝑏 ] 𝜌, 𝜎, 𝛾 ⟩ −−−→ ⟨𝜌 ′ , 𝜎 ′ , 𝛾 ′ ⟩
⟨Ω, 𝜎, 𝛾 ⟩ −−−→ ⟨Ω, 𝜎, 𝛾 ⟩ ℓ
ExtL
ℓ
⟨𝜌, 𝜎, 𝛾 ⟩ → − ⟨𝜌 ′ , 𝜎 ′ , 𝛾 ′ ⟩
⟦𝑏⟧𝜎 = true
Guard-T ℓ
⟨𝜌 1 , 𝜎, 𝛾 ⟩ → − ⟨𝜌 1′ , 𝜎 ′ , 𝛾 ′ ⟩
⟨𝜌 2 , 𝜎, 𝛾 ⟩ → − ⟨𝜌 2′ , 𝜎 ′ , 𝛾 ′ ⟩
ExtR
ℓ
ℓ
⟨𝜌 1 2 𝜌 2 , 𝜎, 𝛾 ⟩ → − ⟨𝜌 1′ , 𝜎 ′ , 𝛾 ′ ⟩
⟨𝜌 1 2 𝜌 2 , 𝜎, 𝛾 ⟩ → − ⟨𝜌 2′ , 𝜎 ′ , 𝛾 ′ ⟩
ℓ
ExtDefault-L
ℓ
⟨𝜌 1 , 𝜎, 𝛾 ⟩ → − ⟨𝜌 1′ , 𝜎 ′ , 𝛾 ′ ⟩
ExtDefault-R
ℓ
ℓ
⟨ 𝜒, 𝜎, 𝛾 ⟩ → − ⟨𝜌 1′ , 𝜎 ′ , 𝛾 ′ ⟩ ⟨𝜌 1 , 𝜎, 𝛾 ⟩ → ̸−
⟨ 𝜒, 𝜎, 𝛾 ⟩ → − ⟨𝜌 2′ , 𝜎 ′ , 𝛾 ′ ⟩ ℓ
⟨𝜌𝑑 , 𝜎, 𝛾 ⟩ → − ⟨𝜌𝑑′ , 𝜎 ′ , 𝛾 ′ ⟩
⟨𝜌 2 , 𝜎, 𝛾 ⟩ → ̸−
Ext-Default ℓ
term(𝜌 1 , 𝜎, 𝛾 )
ℓ
Seq
⟨𝜌 1 , 𝜎, 𝛾 ⟩ → − ⟨𝜌 1′ , 𝜎 ′ , 𝛾 ′ ⟩ ℓ
⟨ 𝜒, 𝜎, 𝛾 ⟩ → − ⟨𝜌𝑑′ , 𝜎 ′ , 𝛾 ′ ⟩
Seq-Term
⟨𝜌 2 , 𝜎, 𝛾 ⟩ → − ⟨𝜌 2′ , 𝜎 ′ , 𝛾 ′ ⟩
⟨𝜌 1 ; 𝜌 2 , 𝜎, 𝛾 ⟩ → − ⟨𝜌 1′ ; 𝜌 2 , 𝜎 ′ , 𝛾 ′ ⟩
ℓ
⟨𝜌 2 , 𝜎, 𝛾 ⟩ → − ⟨𝜌 2′ , 𝜎 ′ , 𝛾 ′ ⟩ ℓ
ℓ
⟨𝜌 [𝜇𝑋 . 𝜌/𝑋 ], 𝜎, 𝛾 ⟩ → − ⟨𝜌 ′ , 𝜎 ′ , 𝛾 ′ ⟩
Rec ℓ
⟨𝜌 1 ; 𝜌 2 , 𝜎, 𝛾 ⟩ → − ⟨𝜌 2′ , 𝜎 ′ , 𝛾 ′ ⟩
⟨𝜇𝑋 . 𝜌, 𝜎, 𝛾 ⟩ → − ⟨𝜌 ′ , 𝜎 ′ , 𝛾 ′ ⟩
Rules. Table 3 gives the rules, writing 𝜒 for the default choice (𝜌 1 2 𝜌 2 ) default 𝜌𝑑 . Structural reductions—sequential termination, recursion unfolding, guard evaluation and default fallthrough— are each combined with the first event of the continuation into a single step (Seq-Term, Rec, GuardT, Ext-Default), eliminating the intermediate 𝜏-transitions of standard CCS/CSP presentations; Skip has no rule, and Ω spins on hang (Div). The atomicity of Guard-T is essential, not cosmetic. The classical presentation emits a 𝜏-step once the guard evaluates to true, leaving the body enabled; 9
in a choice between guarded branches that 𝜏-step resolves the choice, silently and before any event is observed, so two branches whose guards both hold make the choice internal. Evaluating the guard and firing the event in one step keeps the resolution on the visible label, which is what the determinism of §5, at most one successor per label, and the absence of 𝜏 rest on; nested guards, as arise when a guarded branch has a guarded body, flatten by the guard merge, so every label of Λ𝑝 bears at most one guard. External choice is resolved by the first event of either branch (ExtL/ExtR), with no ℓ ≠ 𝜏 side condition since 𝜏 ∉ Σ𝑝 ; a default choice resolves likewise (ExtDefault-L/R), and when neither branch is enabled Ext-Default fires the first event of 𝜌𝑑 , the structural dual of the priority operator of Cleaveland and Hennessy [4]. Its negative premises are well-defined under stratified SOS [3]: stuckness is decided by the structural descent above, on strictly smaller terms, and guardedness forbids a recursion variable at a branch head, so no derivation cycles through the rule’s own negation. Seq runs the left process, and Seq-Term fires the first event of the right once the left is terminated, a property of the state rather than a syntactic match on Skip; Rec unfolds and fires the first event of the unfolding in one step. In the diode. The diode’s work on one packet is a receive followed by a send, o2d?𝑥 → d2i!𝑥 → Skip. The receive takes the oldest value off o2d and blocks while there is none; the send appends 𝑥 to d2i and, when d2i is full, drops it and carries on (Send and Loss). The C’s full test, its drop branch, its copy and its flag updates (lines 25–32 and 34) are exactly these two events. That is the whole component program, the C’s init (line 13) having nothing to initialise: component dd body = o2d ? x -> d2i ! x -> Skip
The C’s for loop, which moves every packet present when the handler is called, has no counterpart, and needs none: a body that has terminated is run again whenever a packet is there to receive, which is the platform’s rule rather than the program’s (§4.2), so one packet per run drains the ring; the C loops because one notification may stand for several packets, a fact of the platform that the program should not have to know. The body starts with a receive where the C starts with switch (ch) (line 17): a component with several input channels starts with a choice of receives, one per channel. The inner driver reacts to two channels, the frames on d2i and its network card’s interrupt; it transmits a frame through the event tx of §3.3.2, and serves an interrupt before acknowledging it to the device: component eth_inner body = d2i ? x -> tx ( x ) -> Skip [] irq ? n -> handle_irq -> irq ! n -> Skip
The C’s outer for and break are gone, and so are the indices, the flags and the addresses; what is left is the diode’s one decision, forward or drop, and the drop is the channel’s. Ω has a C counterpart in the same example: on a zero-length packet, the ethernet driver stops in for (;;){ }. 3.5
Local Labelled Transition System
The rules above define, for each component, a transition system over its local states; a component is a self-contained process that operates independently unless communication arises, channel events being left as blocking points that the composition resolves. Definition 3.4 (Local Labelled Transition System). The local labelled transition system (𝑙𝑙𝑡𝑠) of 𝑝 component 𝑝 is the tuple (𝑆 𝑝 , Σ𝑝 , →, 𝑠 0 ) where: • 𝑆 𝑝 is the set of local states ⟨𝜌 𝑝 , 𝜎 𝑝 , 𝛾 𝑝 ⟩; • Σ𝑝 is the event alphabet, which contains no unobservable event: neither 𝜏 nor a termination marker ✓; 10
dd eth inner 𝑜2𝑑?𝑥
𝜌 body
Forward
Handle eth
𝑠1
𝑠1
Rearm
handle irq 𝑠0
𝑠2 irq? 78
𝑑2𝑖!𝑥
8 irq!7
𝑠0 ?𝑥 𝑑 2𝑖 Notified
tx (𝑥
𝑠3
)
Deliver
eth outer Next pkt
Handle eth
handle irq 𝑠1
𝑠2 tx (reply)
irq?79
[rx ∧ pass] 𝑜2𝑑!pkt
poll
Handle rx
𝑠0
start
𝑠3 [¬rx ] irq!79
𝑠5 [rx ∧ ¬pass ∧ reply ] handle ping
Notified
Reply
[rx ∧ ¬pass ∧ ¬reply ] poll
Fig. 3. STGs of the diode components.
• → ⊆ 𝑆 𝑝 × Λ𝑝 × 𝑆 𝑝 is the transition relation defined by the rules of Tables 1–3, where Λ𝑝 = Σ𝑝 ∪ { [𝑏] ℓ | ℓ ∈ Σ𝑝 , 𝑏 a boolean guard } closes the alphabet under guard annotation; and 𝑝 𝑝 𝑝 • 𝑠 0 = ⟨Skip, 𝜎0 , 𝛾 0 ⟩ is the initial state: the component is parked between runs of its body, 𝑝 its residual terminated, and its first step is the first step of 𝜌 body under the platform’s rule (MK-Restart); 𝜎0 is the component’s initial store and 𝛾 0 = Γ0 |𝐶𝑝 its view of the initial buffers, both given with the initial configuration. 𝑝
𝑝
Example: Data Diode Application. Figure 3 draws each component as a symbolic transition graph (STG) [13]—a finite graph whose nodes are process terms and whose edges carry (possibly guarded) events—derived from the component programs of the running example (the diode’s is the program assembled above). The STG is the finite, syntax-level picture; interpreting it over the data state generates the concrete llts, the object our results are stated on, and all LTS figures in this paper follow this convention; the term-to-STG construction is standard for value-passing calculi [13, 21] and not a contribution here. dd receives on 𝑜2𝑑 and forwards on 𝑑2𝑖, the send dropping when the downstream buffer is full; the two ethernet components serve interrupts and their device rings in the same receive-then-act shape. State names are illustrative; the guards of the ethernet components read rx, a frame was polled, pass, foreign traffic to forward, and reply, ARP or ICMP addressed to this host, and the diode has none. 4 4.1
System Semantics Global Composition
A system is the interleaving of its component processes, each described by its llts, over the shared channel buffers: a component’s computation events and asynchronous channel events are lifted to the global level as they are, and a rendezvous is Sync applied to two components. The interleaving is parameterised on the platform in two places, which process a component offers next, its invocation inv(𝑠 𝑝 ), and the configuration the system starts from, G0 ; the next subsection supplies both for 11
inv (𝑠 𝑝 ) → − 𝑠𝑝 ′ 𝜆
𝜆 ∈ { ℓ, [𝑏 ] ℓ }
Ileave ℓ
⟨S, Γ⟩ → − ⟨S[𝑝 ↦→ 𝑠
𝑝′
ℓ ∈ Σ𝑝
], Γ ⊕ 𝛾 ⟩ 𝑝′
𝑝1
G-Sync
inv (𝑠 ) = ⟨ [𝑏 1 ] 𝜌 1 , 𝜎1 , 𝛾 1 ⟩ inv (𝑠 𝑝 2 ) = ⟨ [𝑏 2 ] 𝜌 2 , 𝜎2 , 𝛾 2 ⟩ 𝑐.𝑣 ⟦𝑏 1 ⟧𝜎1 = true ⟦𝑏 2 ⟧𝜎2 = true ( ⟨𝜌 1 , 𝜎1 , 𝛾 1 ⟩, ⟨𝜌 2 , 𝜎2 , 𝛾 2 ⟩) −−→ (𝑠 1′ , 𝑠 2′ )
( Sync )
𝑐.𝑣
⟨S, Γ⟩ −−→ ⟨S[𝑝 1 ↦→ 𝑠 1′ , 𝑝 2 ↦→ 𝑠 2′ ], Γ⟩
Table 4. Global transition rules.
seL4 MicroKit. Per-component alphabets are pairwise disjoint, an event name being qualified by its component, so a lifted label identifies the component that fired it. Definition 4.1 (Global Configuration). A global configuration is a pair ⟨S, Γ⟩ with S = (𝑠 𝑝 )𝑝 ∈𝑃 one local state per component and Γ the global channel store, the view of every component read off the store, (G-Coh); the initial configuration G0 = ⟨S0, Γ0 ⟩ is given with the system: every component 𝑝 𝑝 parked, 𝑠 0 = ⟨Skip, 𝜎0 , Γ0 |𝐶𝑝 ⟩, over initial stores and buffers within capacity. The invocation inv(𝑠 𝑝 ) is the residual while it has not terminated and a fresh body once it has (MK-Restart below), so running the body again is not a transition of its own but is folded into the component’s next step, exactly as Seq-Term and Rec fold a structural reduction into the next event within a term, and a parked component offers what its fresh body offers. Definition 4.2 (Global LTS). The glts 𝜁 ≜ ||| 𝑝 ∈𝑃 llts𝑝 is the LTS (G, Σ𝑔 , →𝑔 , G0 ) where G is the Ð set of global configurations satisfying (G-Coh); the global alphabet Σ𝑔 = 𝑝 ∈𝑃 Σ𝑝 ∪ { 𝑐.𝑣 | 𝑐 ∈ 𝐶 sync , 𝑣 ∈ Val } comprises the local events of every component together with the rendezvous labels 𝑐.𝑣 of synchronous channels; and →𝑔 is the least relation closed under the rules of Table 4. Ileave lifts any local step of the invocation of a component 𝑝—a computation event, an asynchronous send (Send or Loss) or receive—to the global level; Γ ⊕ 𝛾 𝑝′ is Γ updated on 𝐶𝑝 to the new buffer view of 𝑝, so that (G-Coh) is maintained by construction. A guard is checked at the moment its event fires and is not an observable of its own, so Ileave lifts [𝑏] ℓ as ℓ: the traces of 𝜁 are sequences over Σ𝑔 alone. G-Sync applies Sync to the invocations of the two endpoints when both guards hold (unguarded case: 𝑏 1 = 𝑏 2 = ⊤); it is shown for the head-normal case, and in general the two offers are matched at the enabled frontiers of the two invocations. Computation events remain labels of 𝜁 rather than being hidden behind 𝜏: no other component synchronises on them, the results of §5 are stated on 𝜁 as defined, and keeping them visible keeps the composition at the granularity of the program; hiding them, the classical CSP route to a smaller state space [29], is the abstraction of §6, a refinement beside this composition rather than a step of it. 4.2
The Platform: seL4 MicroKit
We instantiate the calculus on the verified microkernel seL4 [20] and its MicroKit development framework [32]. MicroKit exports seL4’s guarantees as four abstractions: the protection domain, an isolated process; the channel, wrapping inter-process communication and shared memory; the memory region; and the mapping of a region into a protection domain with access rights. It provides only this static configuration, every behaviour being written in C, and leaves the mappings unrestricted: a developer can grant a third party access to a buffer meant for two communicating domains. Memory regions and mappings. A memory region 𝑚 = (size, pbase) declares a page-aligned byte size and a base physical address, user provided or allocated at boot. Each component declares its 12
component 𝑝 1 (𝜇 𝑝 1 , 𝜔 1 = {𝑟, 𝑤 } )
component 𝑝 2 (𝜇 𝑝 2 , 𝜔 2 = {𝑟 } )
𝑖
𝑖
vbase1
vbase2 MMU 𝑝 1
MMU 𝑝 2 region 𝑚 (slots of size slotsize (𝑚) )
𝑖 pbase (𝑚) paddr (𝑚, 𝑖 ) 𝜇 𝑝 1 (𝑖 )
= 𝜇 𝑝 2 (𝑖 ) = 𝑚 (𝑖 )
(Coh)
Fig. 4. The memory model.
mappings M 𝑝 , each 𝜇 = (𝑚, vaddr, 𝜔, slotsize) binding a region at a virtual base address with access rights 𝜔 ⊆ {r, w, x} and a slot granularity, as global variables of its events and processes; the mechanisation abstracts a mapping to the region it grants, the rest being the platform’s to enforce. The diode declares no mapping, touching only its two channel buffers, which the platform maps into both ends; a driver maps its network card’s registers. That mapping of a buffer region, with write access for the sender and read access for the receiver, is what Chan-Async leaves to the platform: Chan-Map
𝑁 𝑐 ≜ (𝑝 1 →𝑚 𝑝2 ) ∈ 𝐶
𝜇1 = (𝑚, vaddr 1 , {r, w } )
𝜇2 = (𝑚, vaddr 2 , {r } )
M 𝑝 1 , M 𝑝 2 ⊢ 𝑐 ; Map (𝜇 1 , 𝑝 1 ), Map (𝜇 2 , 𝑝 2 )
In the running example, neither ethernet component maps the other’s channel buffer. Memory model. Memory is a set 𝑀 of regions, each a partial function 𝑚 : N ⇀ Val from slot index to value, slot 𝑖 of 𝑚 having the physical address paddr (𝑚, 𝑖). A component 𝑝 maps the regions it may access, at most one mapping per region; they are its accessible regions 𝑀 𝑝 , split into its private regions and the buffers 𝑀 𝐶 of the channels it is an endpoint of. The memory-management unit translates every mapping of a region to the same physical slots (Figure 4), and two invariants follow, which are all the semantics uses: the mappings of one component do not overlap, and every endpoint of a channel sees the same buffer, ∀ 𝜇 ≠ 𝜇 ′ ∈ M 𝑝 . range(𝜇) ∩ range(𝜇 ′ ) = ∅
(Disj)
𝜇 𝑝 1 (𝑖) = 𝜇 𝑝 2 (𝑖) = 𝑚(𝑖)
(Coh)
where 𝜇 𝑝 1 and 𝜇 𝑝 2 map the same region 𝑚. Protection domains as components. A protection domain is a component of the calculus: an address space, the component’s private store with the regions it maps; a priority 𝑝.pri, distinct from every other’s; and its channels and mappings. Mappings and rights are fixed at boot and enforced by seL4’s capabilities; CoreFi declares the grants and never checks them. A hardware interrupt is an interrupt channel between the device and its protection domain, delivered as a notification and acknowledged by microkit_irq_ack. A synchronous channel is MicroKit’s protected procedure call, allowed only to a domain of strictly higher priority, the further constraint Chan-Sync leaves to the platform: Chan-Call
𝑐 ≜ (𝑝 1 ↣ 𝑝 2 ) ∈ 𝐶 𝑝 1 .pri < 𝑝 2 .pri 𝑐 ; ok
Since priorities are totally ordered, Chan-Call alone excludes every cycle of synchronous calls; the cycles that mix channel kinds are (Wf1)’s to exclude. 13
Entry points. A protection domain has two entry points: init(), run once before any notification, which produces the domain’s initial store and is not modelled beyond that, and notified(), which is the body 𝜌 body , each run of which is one invocation, re-run by the kernel on the next notification once it has terminated; a diverging body never returns. The notified(channel) contract, that an invocation exists only because a channel fired, is receive-headedness: a top-level guard would make the wake-up conditional and a top-level default would poll, where MicroKit parks an idle domain, so guards, computation events, sends and default escapes appear only after the initial receive. The scheduler. A protection domain’s process term is the residual of its current invocation of notified; when that residual is terminated the domain has returned to the kernel, and its next step
is the first step of a fresh run of its body: ( 𝑝 ⟨𝜌 body , 𝜎 𝑝 , 𝛾 𝑝 ⟩ inv(𝑠 𝑝 ) ≜ 𝑠𝑝
if term(𝜌 𝑝 , 𝜎 𝑝 , 𝛾 𝑝 ) otherwise.
This is the rule MK-Restart. The initial configuration G0 is what MicroKit’s boot leaves: it runs the init() of every domain in decreasing priority order from empty buffers, after which every domain is parked over the store its init() produced; we take G0 as given, every component parked and the buffers within capacity, which such a boot guarantees. The system composition. A MicroKit system is declared by a system description, which lists the memory regions, the protection domains and the channels, and composes the protection domains by interleaving, 𝜁 = ||| 𝑝 ∈𝑃 𝑝: CSP’s interleaving without handshaking, every interaction being through a declared channel, whose semantics is the global composition of §4.1 with the invocation and the initial configuration just defined. 4.3
Beyond MicroKit
Nothing in the global composition is MicroKit’s but the two parameters it reads, the invocation inv and the initial configuration G0 ; another platform is another pair. The results of §5 use two facts about the pair, that an invocation is a fresh body or the residual of one, and that the initial configuration satisfies the buffer invariant; a platform whose pair has them inherits the theorems, and the mechanisation proves them for MicroKit’s. A framework with the same run-to-completion handlers but a different entry-point discipline changes only the contracts on its bodies; a cooperative scheduler that lets a body yield mid-run supplies an inv that returns the residual at the yield rather than at termination; a time-triggered platform, as Mimosa’s is [19], supplies an invocation keyed to a clock, where a timing extension would start. The invocation can also be written as a term over the component bodies with the composition operators CSP already has: MicroKit’s steady 𝑝 state is the interleaving of the bodies under iteration, ||| 𝑝 ∈𝑃 ∗𝜌 body , where ∗𝜌 restarts 𝜌 once it has terminated; a round-robin scheduler is a sequential cycle of the bodies instead, and a preemptive one a prioritised choice between them [4]. We keep the scheduler as a rule rather than a term because the rule is what the proofs read, and because a term would put the platform inside the components’ process language, where a component could express a scheduling decision that is not its to make. 5
Properties
We prove three properties: every system keeps its channel buffers within capacity, and every well-formed system is deadlock-free and deterministic. Deadlock freedom is a baseline requirement for any communication-based system—a stuck component can hang an entire embedded system 14
indefinitely. Determinism makes a run reproducible from its labels, which testing and certification rely on. Both follow from a single structural discipline, well-formedness. 5.1
Well-formedness
Well-formedness is a set of structural conditions on the system. Each channel has a designated sender and receiver, both components except on an interrupt channel, whose other end is the environment. Beyond these declaration facts, two conditions—acyclicity and choice partition—must hold, and the definition also bundles the grammar and declaration facts on which the theorems rely. Definition 5.1 (Well-formed system). For an external choice 𝜒 let br ( 𝜒) = {(𝑏𝑖 , ℓ𝑖 → 𝜌𝑖 )}𝑖 be its flattened branches, those of the choices nested in its branches included, nested guards merged by conjunction and 𝑏𝑖 = ⊤ for unguarded branches; and write |= 𝜑 when 𝜑 holds in every store 𝜎. A system is well-formed iff the following two conditions hold, together with the grammar and declaration facts listed below. (Wf1) Acyclic dependency. ∀ 𝑝 ∈ 𝑃 . ¬ (𝑝 ;+ 𝑝), where 𝑝 ; 𝑞 ⇔ ∃ 𝑐 ∈ 𝐶. 𝑝 = 𝑝𝑟 (𝑐) ∧ 𝑞 = 𝑝𝑠 (𝑐) ∨ 𝑐 ∈ 𝐶 sync ∧ 𝑝 = 𝑝𝑠 (𝑐) ∧ 𝑞 = 𝑝𝑟 (𝑐) . (Wf2) Choice partition. Every guard is a branch of an external choice, every branch is eventheaded, and for every choice 𝜒: • branch disjointness: ∀ 𝑖 ≠ 𝑗 . head (ℓ𝑖 ) = head Ô (ℓ 𝑗 ) ⇒ |= ¬(𝑏𝑖 ∧ 𝑏 𝑗 ); • exhaustiveness: if 𝜒 is a plain choice, |= 𝑖 𝑏𝑖 ; • locally decidable defaults: if 𝜒 is a default choice, every ℓ𝑖 is a computation event or an asynchronous send, and 𝜌𝑑 is partitioned; where head (ℓ) is the name of a computation event and the channel together with the direction of a channel event, values ignored, and Ω as a branch heads the computation event hang. The grammar and declaration facts bundled with the two conditions are: every body is closed, guarded in its recursion, and tail-recursive, with inner loops recurring only to themselves; every body is receive-headed and every channel other than an interrupt channel runs between two components; and every body sends only on channels it is the declared sender of and receives only on those it is the declared receiver of. Remark: what each condition guards against. (Wf1) reads 𝑝 ; 𝑞 as “𝑝 may have to wait for 𝑞”: every receiver waits for its sender, and a synchronous sender additionally waits for its receiver, because a rendezvous needs both parties. The sender-side edges are not optional: buffered sends never block (Send with room, Loss at capacity), but a synchronous send is a third blocking primitive, and a cycle that threads a sender-wait through receiver-waits is invisible to the receiver-side edges alone. For example, 𝑝 1 ≜ 𝑐 1 ?𝑥 → 𝑐 2 !𝑚 → · · · and 𝑝 2 ≜ 𝑐 2 ?𝑦 → 𝑐 1 !𝑛 → · · · , with 𝑐 1 asynchronous from 𝑝 2 to 𝑝 1 and 𝑐 2 synchronous from 𝑝 1 to 𝑝 2 , deadlock: 𝑝 1 blocks on 𝑐 1 ?𝑥 waiting for 𝑝 2 , while 𝑝 2 blocks on 𝑐 2 ?𝑦 waiting for 𝑝 1 —a genuine deadlock surfaced by the Lean mechanisation of deadlock freedom over the full rule set. On a platform that orders synchronous calls, as MicroKit does by priority (Chan-Call), cycles whose synchronous edges all point one way are excluded already; the mixed cycles are what acyclicity rules out. (Wf2) rests on two shape requirements. A standalone guard [𝑏] 𝜌 would block for ever once 𝑏 is false, with no rule to rescue it, so guards occur only as branches. Branches are event-headed, of the shape [𝑏] evt → 𝜌 (nested choices of event-headed branches allowed), so that “branches offering the same event” is well-defined; this also excludes bare recursion-variable branches such as 𝜇𝑋 . 𝛼 → (𝑋 2 𝛼 → 𝑋 ), which are genuinely 15
non-deterministic after one unfolding—a hole surfaced by the Lean mechanisation of determinism. Since Guard-T fires a guard and its event in one step, every branch offers its head event under its guard, which is what the labels [𝑏] ℓ of Λ𝑝 record; disjointness then says that for a given event at most one branch is enabled, while branches offering distinct events impose no constraint, since the environment selects which event fires. Exhaustiveness is required of plain choices only: a default choice is exhaustive by construction via 𝜌𝑑 . The last clause exists because Ext-Default’s negative premises ask whether the branches are stuck: a computation event or an asynchronous send is always enabled, so its stuckness is decided by the guard alone, whereas a receive depends on the buffer and a synchronous event on the rendezvous partner’s state, and without the clause the escape could fire while a rendezvous stood ready, silently discarding it. The clause constrains only the branches directly under a default; the dispatch head of a body is a plain choice, so dispatch on several channels, including synchronous receives at the receive head of a body, is unaffected. Both conditions can be checked statically, from the channel declarations and program text alone. (Wf2) does two jobs: branch disjointness makes the fired event determine the branch, which is what determinism needs, and exhaustiveness keeps some branch of a plain choice enabled, which is what deadlock freedom needs. 5.2
Preservation
Throughout this section, a global configuration is reachable if it is obtainable from the initial configuration G0 by a finite sequence of global transitions; the deadlock-freedom and determinism theorems are properties of this reachable state space, not of arbitrary configurations. The invariants of the memory model, (Disj) and (Coh), are static: no global transition changes a mapping, so they hold at every configuration once they hold at the declarations. Coherence of the views, (G-Coh), holds by construction, since a component’s view is the restriction of Γ read at the moment it steps. What a transition can disturb is the channel store itself, and preservation is about that. Definition 5.2 (Buffer invariant). A channel store Γ satisfies (Γ-BufWf) when its domain is exactly the asynchronous channels, so a synchronous channel carries no buffer, and |Γ(𝑐)| ≤ 𝑁𝑐 for every asynchronous channel 𝑐. Theorem 5.3 (Preservation). If ⟨S, Γ⟩ →𝑔 ⟨S′, Γ ′ ⟩ and Γ satisfies (Γ-BufWf), then so does Γ ′ . Consequently every reachable configuration satisfies it, since G0 satisfies it. Proof sketch. By case analysis on the global rule. G-Sync leaves Γ unchanged. Ileave writes back the stepping component’s view, which differs from Γ by at most one local channel step: a computation event or Loss leaves it unchanged; Send appends one value to Γ(𝑐) under the premise |Γ(𝑐)| < 𝑁𝑐 , so the bound is kept; Recv removes the head of Γ(𝑐), which only shortens it. All three keep dom(Γ), since they update an existing entry. Along a run from G0 the invariant is carried by induction on the run’s length; at G0 it holds by assumption, as a boot from empty buffers whose sends are Send or Loss steps guarantees. □ The theorem needs neither well-formedness nor reachability: it is a property of every transition. Its use is in the theorems that follow, which read the kind of a channel off the store—a buffered channel is asynchronous, a declared channel with no buffer is synchronous—so that a component waiting on a channel is known to wait on the right kind of primitive. 5.3
Deadlock Freedom
A component is never finished: when the residual of its invocation has terminated, its invocation is a fresh body, and a fresh body is receive-headed, so it is never terminated. There is thus no terminated global configuration to exempt from the progress obligation; what remains to distinguish from 16
deadlock is the idle system. The environment is not modelled, so a receive on a channel whose sender is the environment—an interrupt—cannot be rendered as “always enabled”. The open-system assumption is therefore stated in the conclusion of the theorem rather than as an environment transition rule, which would make the theorem trivially true whenever an interrupt channel exists. Definition 5.4 (Waiting on the environment). A component 𝑝 waits on the environment in ⟨S, Γ⟩ when its invocation inv(𝑠 𝑝 ) offers a receive on a declared channel 𝑐 at its enabled frontier, the sender of 𝑐 is not a component, and Γ holds no message on 𝑐. The enabled frontier of a process is where its next event is decided: through guards that hold, through the left operand of ; once terminated, and through the branches of a choice, by the same structural descent as enabledness. Theorem 5.5 (Deadlock Freedom). If the system is well-formed and has at least one component, then every reachable global configuration has an enabled global transition, or contains a component that waits on the environment. Corollary 5.6 (Progress of closed systems). If moreover every channel has a component as its sender, every reachable configuration has an enabled global transition. Proof sketch. The argument has four steps, which the mechanisation follows. Blocked trichotomy. For a guarded process whose choices satisfy (Wf2), and each of whose send channels is either buffered within capacity or has no buffer entry, one of the following holds in a given state: it is enabled, it is terminated, it has a ready receive offer at its enabled frontier, or it holds a ready send on a bufferless channel, a blocked rendezvous sender; a process that is not enabled with a ready receive offer waits, its buffer being empty. Computation events, Ω and buffered sends are always enabled (Send or Loss), and a plain choice has an enabled branch by exhaustiveness, so the blocking primitives are an empty-buffer receive and a bufferless send; guarded recursion reaches the frontier in finitely many structural steps. The invocation. Along every run the residual of a declared component keeps the structural well-formedness bundle (subject reduction), and so does its invocation, the residual or the fresh body once the residual has terminated (MK-Restart); an invocation is never terminated, as a fresh body is receive-headed. Channel mentions. A residual mentions only channels its declared body mentions, so a wait on 𝑐 certifies that 𝑐 is declared, and the kind of 𝑐 is read off the buffer invariant (preservation): buffered means asynchronous, bufferless means synchronous. Core. Suppose no global transition is enabled. Then no invocation is enabled, since an enabled local step lifts to an Ileave step, and by the trichotomy every declared component waits: receive-side with no message, or at a synchronous send with no buffer. If some receive-wait faces the environment, the second disjunct holds. Otherwise every wait yields an edge of the (Wf1) dependency graph inside the declared components: a receive-wait points at the channel’s declared sender, declared since the wait does not face the environment, and a synchronous send-wait at its declared receiver, declared by the endpoint facts of well-formedness. A finite set in which every node has an outgoing edge contains a cycle, contradicting acyclicity. The corollary follows because the second disjunct names an environment-sourced channel. The full proof is the mechanised one. □ Remarks. The theorem rests on well-formedness, the initial configuration, the existence of one component, and reachability; the mechanisation carries the structural bundle of every residual and the buffer invariant along runs and discharges both at the initial configuration. Fairness of the platform’s scheduler is outside the formalism, and we do not assume it. 17
5.4
Determinism
We show that the global LTS 𝜁 is deterministic: for any reachable configuration and any label ℓ ∈ Σ𝑔 , there is at most one ℓ-successor. The glts deliberately retains the nondeterminism inherent to concurrency—which component the (unmodelled) scheduler runs next, and when the environment raises an interrupt or delivers a message; the theorem states that this is the only nondeterminism: it resides entirely in the choice of the next label, never within one. By induction over a run this yields replay determinism: the same sequence of labels reproduces the same configurations, a routine induction we do not mechanise. It does not yield the stronger “same inputs, same outputs”: which enabled label fires next is the scheduler’s choice, so two schedules of the same external inputs may produce different output sequences; that stronger property would need every component to run an invocation to completion before another is scheduled, a run-to-completion assumption that is itself too strong for a system whose scheduler is outside the formalism. Because computation events are labels of 𝜁 , the theorem covers them as well as communication: the same event fired from the same configuration has one effect. Determinism is not a trace property and is not transferred by the refinement of the next section; it is proved of 𝜁 directly. Theorem 5.7 (Determinism). If the system is well-formed, then for every reachable global configuration ⟨S, Γ⟩ and every label ℓ ∈ Σ𝑔 , there is at most one configuration ⟨S′, Γ ′ ⟩ such that ℓ
⟨S, Γ⟩ → − ⟨S′, Γ ′ ⟩. Proof sketch. Two ingredients: routing, which pins the label to one stepping component or endpoint pair, and local determinism, which pins that component’s step. Local determinism from (Wf2). A step of a term whose choices satisfy (Wf2) fires exactly one of the flattened branches of the choice it goes through: the branch’s merged guard holds and its head is the step’s event. Two steps from one choice with the same underlying event, guard annotations aside, therefore reach the same branch, or two branches that disjointness makes exclusive; by induction on the derivation, two local steps with the same underlying event from one local state agree on the residual, the store and the view. The ingredient applies to the invocation a reachable configuration gives a component, a fresh body or the residual of one, both of which carry the bundle (subject reduction); the default clause likewise survives steps and offers, so a residual’s rendezvous offers are disciplined too, and a component outside the declarations stays at Skip along every run, both discharged at G0 like the bundle. Computation event (𝑝, 𝛼). The label names the component; two Ileave steps with this label are two local steps of 𝑝’s invocation with the same underlying event, which agree by local determinism. Async send 𝑐!𝑣 and receive 𝑐?𝑣. A channel-labelled local step starts from a term that mentions that channel, and a residual mentions only channels its declared body mentions, so the stepping component is the declared endpoint of 𝑐, unique by the declarations; a component outside the declarations sits at Skip and has no step. Within that component, local determinism applies; the sent value is ⟦𝑒⟧𝜎 of the active branch, and the received value is the head of Γ(𝑐). Sync rendezvous 𝑐.𝑣. G-Sync matches a send offer and a receive offer on 𝑐 at the enabled frontiers of the two endpoints’ invocations. Offers are determined like steps: at most one send offer and one receive offer on 𝑐 per term, by disjointness over the flattened branches together with the default clause of (Wf2), which keeps every synchronous event out of the branches of a default choice, so that a rendezvous passes such a choice only through its escape 𝜌𝑑 and never through Ext-Default’s negative premises; the endpoints are the declared ones, and 𝑣 is the sender’s evaluated expression. In all cases the transition is fixed by a unique component or endpoint pair, a unique branch, and a unique value, so at most one ℓ-successor exists. □ 18
6
Abstraction: the Abstracted Local LTS
The glts carries every computation event of every component, so a property of the system’s communication is checked over a state space that computation inflates. The separation of computation from communication gives the way out. A computation event changes only its component’s local store 𝜎 and never the global channel store Γ, so the local state changes between two channel events can be absorbed into one big step, and the abstracted components composed into a smaller model of the global behaviour. This section defines that abstraction: each llts is abstracted into an abstracted local LTS (alts) by hiding its computation events—re-labelling each as the conventional silent event 𝜏, invisible to other components—and collapsing the resulting 𝜏-chains, so that only channel events and the guards that resolve choices remain visible. Its purpose is the verification of channel-level trace properties, such as the diode’s one-way flow, on the smaller model: the alts of a component has exactly the channel traces of its llts, and the composition of the altses exactly those of the glts, both proved below, so a trace property established on the abstracted global state space holds of the complete one, and a counterexample found there is a behaviour of the system. Determinism, which is not a trace property, is proved on the glts itself. As for the llts, the figures draw an alts as an STG, but the object defined and mechanised is a transition system over the same states as the llts: no rule removes a state, and every rule adds a big-step edge between existing states. So the alts keeps every state: a big-step of 𝑛 computation steps between two communication events is one transition, but the states it spans remain, since each is a global interleaving point at which another component may step. Write Λ𝑐 = Σ𝑐 ∪ { [𝑏] ℓ | ℓ ∈ Σ𝑐 } for the possibly-guarded channel labels, ranged over by 𝜆: Guard-T emits guarded channel events [𝑏] ℓ directly (e.g. from every guarded receive branch of a choice), so the absorption rules must accept a guarded label wherever a bare channel event may appear. Absorption is moreover canonical, in two respects. First, it is leading-only: a 𝜏-chain is absorbed into the channel event that follows it, never into the one that precedes it, so a trailing chain becomes the leading chain of the next event’s big-step. Second, an absorbed hidden step must be committed—every move enabled at its source is silent and leads to the same state—written (cm) in the rules: absorbing a hidden step never resolves a choice. A choice-resolving hidden step 𝜏 remains an explicit big-step ⇒ = (Collapse), which is where the choice visibly resolves. Without canonicity one channel event would admit several big-steps differing only in the silent progress bundled with it, and a label of the composition would lead to several successors. Table 5 gives the two re-labellings and the four big-step rules: Hide/Hide-G re-label a computation event as 𝜏/[𝑏]𝜏; Collapse/Collapse-G contract 𝜏-chains to big-steps; Seq-Pre absorbs a leading 𝜏 ∗ -chain into the following channel label 𝜆 ∈ Λ𝑐 ; and Seq-G merges a guarded [𝑏]𝜏 with the following channel label via the guard merge; the view 𝛾 of a state is Γ by construction (G-Coh). The result is a clean alts in 𝜏 = , or a channel label 𝜆 ∈ Λ𝑐 which every transition is either a big-step (possibly guarded) 𝜏-chain ⇒ with its leading 𝜏-steps absorbed. Example: Data Diode Abstracted LTS. Applying the abstraction rules to the lltses generated from the STGs of Figure 3 yields the altses of Figure 5, again drawn as STGs: computation events are hidden, then absorbed into the following channel event where committed, or kept as explicit guarded big-steps 𝜏ˆ where they resolve a choice; interrupt notifications are channel events and are never hidden. The drawing omits an interior state whose only incoming big-step is an absorbed chain and whose only outgoing one is the channel event that absorbed it, a convention of the figures and not a step of the abstraction, which keeps every state. The diode computes nothing, so its alts is its llts. Two states the drawing keeps illustrate the two limits of absorption: a choice point 19
𝛼
𝛼 ∈ Σ𝛼
⟨𝜌, 𝜎, 𝛾 ⟩ − → ⟨𝜌 ′ , 𝜎 ′ , 𝛾 ⟩
Hide 𝜏
[𝑏 ]𝛼
𝛼 ∈ Σ𝛼
⟨𝜌, 𝜎, 𝛾 ⟩ −−−→ ⟨𝜌 ′ , 𝜎 ′ , 𝛾 ⟩
(G-Coh)
Hide-G
⟨𝜌, 𝜎, Γ⟩ → − ⟨𝜌 , 𝜎 , Γ⟩ ′
′
[𝑏 ]𝜏
(G-Coh)
⟨𝜌, 𝜎, Γ⟩ −−−→ ⟨𝜌 , 𝜎 , Γ⟩
𝜏 +
⟨𝜌, 𝜎, 𝛾 ⟩ → − ⟨𝜌 ′ , 𝜎 ′ , 𝛾 ⟩
′
′
[𝑏 ]𝜏
⟨𝜌, 𝜎, 𝛾 ⟩ −−−→ ⟨𝜌 ′ , 𝜎 ′ , 𝛾 ⟩ 𝜏 ∗ ⟨𝜌 , 𝜎 ′ , 𝛾 ⟩ → − ⟨𝜌 ′′ , 𝜎 ′′ , 𝛾 ⟩ (G-Coh)
(G-Coh)
Collapse
′
𝜏
⟨𝜌, 𝜎, Γ⟩ = ⇒ ⟨𝜌 ′ , 𝜎 ′ , Γ⟩
Collapse-G [𝑏 ]𝜏
⟨𝜌, 𝜎, Γ⟩ ====⇒ ⟨𝜌 ′′ , 𝜎 ′′ , Γ⟩ 𝜏 ∗
[𝑏 ]𝜏
⟨𝜌, 𝜎, 𝛾 ⟩ → − ⟨𝜌 ′ , 𝜎 ′ , 𝛾 ⟩ ′
Seq-Pre
𝜆
′
′′
′′
⟨𝜌, 𝜎, 𝛾 ⟩ −−−→ ⟨𝜌 ′ , 𝜎 ′ , 𝛾 ⟩
′
′
⟨𝜌 , 𝜎 , 𝛾 ⟩ → − ⟨𝜌 , 𝜎 , 𝛾 ⟩ 𝜆 ∈ Λ𝑐 (G-Coh) (cm)
Seq-G
𝜆
′
⟨𝜌 , 𝜎 , 𝛾 ⟩ → − ⟨𝜌 ′′ , 𝜎 ′′ , 𝛾 ′ ⟩ 𝜆 ∈ Λ𝑐 (G-Coh) (cm)
𝜆
[𝑏 ] ·𝜆
⟨𝜌, 𝜎, Γ⟩ = ⇒ ⟨𝜌 ′′ , 𝜎 ′′ , Γ ′ ⟩
⟨𝜌, 𝜎, Γ⟩ =====⇒ ⟨𝜌 ′′ , 𝜎 ′′ , Γ ′ ⟩
Table 5. Abstraction rules.
Add
Aeth inner
Aeth outer
irq?78
irq?79
𝑜2𝑑?𝑥 𝑠0
[rx ∧ pass] 𝑜2𝑑!pkt
𝑠1 Notified
𝑑2𝑖!𝑥 𝜌 body
Handle eth
Idle
𝑠1
𝑠0
Forward
𝑠0
[rx ∧ ¬pass ∧ reply ] 𝜏ˆ
𝑠1
irq!78
[¬rx ] irq!79
Handle rx
[rx ∧ ¬pass ∧ ¬reply ] 𝜏ˆ
𝑑2𝑖?𝑥
Fig. 5. The abstracted STGs A𝑝 of the diode components. [𝑏 2 ] 𝜏ˆ
start ⟨ Idle, Notified, Handle eth ⟩
⟨ Handle rx, Forward, Notified ⟩
irq?78 [𝑏 1 ] 𝑜2𝑑.𝑣
irq?79
𝑔𝑖
𝑔0
𝑔1
𝑔2
[¬𝑟𝑥 ] irq!79
irq!78
𝑑2𝑖.𝑣 Notified ⟩ ⟨ Handle rx, Notified,
⟨ Idle, Notified, Notified ⟩
Fig. 6. Composition of the abstracted diode components (partial).
(eth outer’s Handle rx) is where a hidden step would resolve a choice and so stays an explicit big-step, and a state between two channel events (eth inner’s Handle eth) has nothing hidden left to absorb—absorption fuses hidden steps into a channel event, never one channel event into another. 6.1
Composing the Abstractions
The composition of the altses applies the two rules of Table 4 to alts big-steps of the invocations in place of llts steps, a silent big-step being a silent step of the composition, and G-Sync verbatim, since it matches the process terms of the two endpoints, which the abstraction does not change. Example: Global Composition. Figure 6 shows the core forwarding behaviour of the composition of the altses of Figure 5, annotated with ⟨eth outer, dd, eth inner⟩ control states; its Σ𝑐 -traces are those of 𝜁 , which admits further interleavings. A label 𝑐.𝑣 on an asynchronous channel abbreviates 20
the matched pair (𝑐!𝑣, 𝑐?𝑣), two independent Ileave steps drawn as one edge; 𝑏 1 ≜ rx ∧ pass and 𝑏 2 ≜ rx ∧ ¬pass. No transition in 𝜁 sends on 𝑑2𝑖 from eth outer or receives on 𝑜2𝑑 from eth inner: the declarations (Chan-Async, Chan-Sync) ensure those transitions are absent. 6.2
Refinement
The composition of the altses loses and adds no channel behaviour of the system; the result rests on one fact per component, that each alts has the channel traces of its llts, proved first. The sequence of observable events along an execution is a trace, and we compare processes by standard CSP trace refinement [29]: 𝑃 ⊒T 𝑄 when every observable trace of 𝑄 is also a trace of 𝑃, so safety properties established over the traces of 𝑃 carry over to 𝑄. Hiding alone preserves traces: Hide and Hide-G re-label each computation step as a 𝜏-step and leave channel steps unchanged, so the Σ𝑐 -traces of the hidden llts 𝑝 𝜏 are those of 𝑝. Lemma 6.1 (Refinement). The Σ𝑐 -traces of A𝑝 , obtained from 𝑝 𝜏 by Collapse, Collapse-G, Seq-Pre and Seq-G, are exactly the Σ𝑐 -traces of 𝑝; in particular 𝑝 ⊒T A𝑝 . Proof sketch. Each big-step of A𝑝 unfolds to an llts run with the same Σ𝑐 -projection: Collapse and Collapse-G to a chain of hidden computation steps, which project to nothing, and Seq-Pre and Seq-G to the absorbed chain followed by the channel step, the guard merge leaving the projection unchanged. Concatenating the unfoldings of a run of A𝑝 gives a run of 𝑝 with the same Σ𝑐 -trace, which is 𝑝 ⊒T A𝑝 ; the converse inclusion is the next lemma. □ Lemma 6.2 (Completeness). Every llts step is a big-step of A𝑝 at its hidden label, from the same state to the same state; consequently every finite Σ𝑐 -trace of 𝑝 is a Σ𝑐 -trace of A𝑝 . Proof. Every llts step has a big-step counterpart with the same Σ𝑐 -projection: a hidden compu[𝑏 ]𝜏
𝜏
tation event becomes ⇒ = (Collapse with a one-step chain) or ====⇒ (Collapse-G with an empty 𝜆
chain), and a channel label 𝜆 ∈ Λ𝑐 becomes = ⇒ (Seq-Pre with zero absorbed steps). Every state of the llts is a state of the alts, so the counterparts compose, replaying any llts path big-step by big-step with an identical Σ𝑐 -projection. □ Theorem 6.3 (Composition refinement). For a well-formed system and a reachable configuration G, the Σ𝑐 -traces of the composition of the altses from G are exactly the Σ𝑐 -traces of the glts 𝜁 from G; in particular 𝜁 ⊒T ||| 𝑝 ∈𝑃 A𝑝 . The inclusion of the traces of 𝜁 holds at every configuration, and from the initial configuration well-formedness alone suffices. Proof sketch. The inclusion of the glts needs no hypothesis: an llts step is an alts big-step at its hidden label (the single-step fact above), so every step of 𝜁 is a step of the composition of the altses whose label is the Σ𝑐 -projection of its own, a computation event projecting to a silent step. For the converse, a big-step of the composition is realised by a non-empty llts run of one component with the same Σ𝑐 -projection (the refinement lemma), which lifts step by step through Ileave under that component: the first step reads the component’s invocation, and every later state of the run is a residual that still steps and is therefore not terminated, so it is its own invocation. That a stepping residual is not terminated holds of guarded terms, which is where well-formedness and reachability enter: the structural bundle that every residual of a well-formed system carries along runs (subject reduction), with undeclared components parked at Skip, supplies the guardedness. A rendezvous is one step of both compositions. □ 21
7
Related Work
Programs as models. Model checkers for process calculi and timed automata, SPIN [16], FDR [9], UPPAAL [2] and PAT [30], verify a model written beside the code, whose communication is by rendezvous or over queues that never drop and whose computation is absent or silent; CoreFi’s program is the model, and its channels and computation are the platform’s. The P language [6] makes the program the model: state machines exchanging events over unbounded queues, compiled to executable code and explored by a systematic tester, and ModP [7] composes such machines by assume-guarantee reasoning. CoreFi shares the thesis and changes the abstraction: bounded and synchronous channels instead of unbounded queues, shared buffers instead of no shared memory, local code entered through named events rather than opaque foreign functions, and guarantees by construction rather than by exploration. Ivy [26] decides safety of parameterised protocols in a restricted logic, and code generation from verified specifications—PGo [10, 11] from PlusCal and TLA+, Liu et al. [22] from Maude, AutoMan [34] with refinement proofs for hand optimisation—carries a verified design to code; in each, the communication model is the specification’s, not the platform’s. Synchronous languages such as Lustre [12] and SCADE make the program the model for clocked control software, verified as written and compiled by qualified generators; their components communicate by synchronous dataflow within one clock, where CoreFi’s run as separate components over buffers in shared memory. BIP [1] builds systems from atomic components with ports, glued by connectors and coordinated by priorities, and is the closest component model to CoreFi’s; its correctness-by-construction results concern the glue, whereas CoreFi’s conditions concern the components’ choices and their channel dependencies. Deadlock freedom by typing. Multiparty session types [17] guarantee progress for well-typed sessions by projecting a global protocol onto its participants, over reliable, typically unbounded channels. CoreFi’s conditions are checked on the components as written, with no global protocol, and hold for bounded channels that drop; acyclicity of the wait relation and partition of choices replace the protocol’s structure. Embedded systems. MIMOS [33] and Mimosa [18, 19] give deterministic models and languages for embedded real-time software in which determinism follows from the communication discipline; CoreFi obtains determinism of the composed system, at most one successor for each label, from choice partition and keeps the platform’s scheduling choice as its only nondeterminism. Lingua Franca [23] obtains determinism from logical timestamps on reactor events, a discipline over the coordination rather than the components’ choices. For seL4 [20], Tower [14] coordinates tasks written in the Ivory DSL over channels and was flown on seL4 in SMACCMPilot, Kalas [27] compiles global programs to verified code with CakeML over unbounded channels, an idealisation CoreFi does not make, and Pancake [28] is a verified systems language for the local code CoreFi’s computation events call. The scheduler of seL4’s mixed-criticality extension [24] is what a timed version of the platform rule would model. 8
Conclusion
We have presented CoreFi, a core calculus for embedded systems whose components compute on private state and communicate over bounded channels in shared memory. Its local semantics has no silent transition; the platform that runs the components enters as one rule of the composition, the invocation, and an initial configuration, which is all an instantiation must supply, and we have supplied them for seL4 MicroKit. Every system keeps its buffers within capacity, and two structural well-formedness conditions make every well-formed system deadlock-free in an open-system form and deterministic, each label of the composed system leading to at most one successor; an 22
abstraction that hides computation has the channel traces of each component, and the composition of the abstractions those of the system. The semantics, the platform rule, the theorems and the refinements are mechanised in Lean 4. Three lines of work follow. The first is the implementation: a compiler for the language that checks well-formedness and emits an executable image for seL4 MicroKit, and case studies of practical systems written in it beyond the diode. The second is the correspondence between that implementation and the mechanisation, so that what runs is what the theorems speak about, in the manner of certified compilation. The third is verification: properties beyond the structural ones, checked over the global state space or over the abstracted one that §6 shows to have the same channel traces, and the question of how far either scales to the state spaces of practical embedded systems. Last, seL4’s mixed-criticality scheduler [24], which gives each component a budget and a period, is the natural next instance of the platform rule, bringing timing and fairness into the formalism. Data-Availability Statement The artifact is the Lean 4 development that mechanises the semantics and the theorems of this paper; it is released as open source [8]. References [1] Ananda Basu, Marius Bozga, and Joseph Sifakis. 2006. Modeling Heterogeneous Real-time Components in BIP. In SEFM. 3–12. [2] Gerd Behrmann, Alexandre David, Kim Guldstrand Larsen, Paul Pettersson, and Wang Yi. 2011. Developing UPPAAL over 15 years. Software, Practice & Experience 41, 2 (2011), 133–142. doi:10.1002/spe.1006 [3] Ronald Bol and Jan Friso Groote. 1996. The Meaning of Negative Premises in Transition System Specifications. J. ACM 43, 5 (1996), 863–914. doi:10.1145/234752.234756 [4] Rance Cleaveland and Matthew Hennessy. 1990. Priorities in Process Algebras. Information and Computation 87, 1–2 (1990), 58–77. doi:10.1016/0890-5401(90)90059-Q [5] CSLib 2025. CSLib: The Lean Computer Science Library. https://github.com/leanprover/cslib. https://github.com/ leanprover/cslib [6] Ankush Desai, Vivek Gupta, Ethan Jackson, Shaz Qadeer, Sriram Rajamani, and Damien Zufferey. 2013. P: safe asynchronous event-driven programming. In Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation (Seattle, Washington, USA) (PLDI ’13). Association for Computing Machinery, New York, NY, USA, 321–332. doi:10.1145/2491956.2462184 [7] Ankush Desai, Amar Phanishayee, Shaz Qadeer, and Sanjit A. Seshia. 2018. Compositional Programming and Testing of Dynamic Distributed Systems. Proc. ACM Program. Lang. 2, OOPSLA, Article 159 (2018). doi:10.1145/3276529 [8] fidus 2026. fidus: A Lean 4 Formalisation of the Fiducia Language. https://github.com/fiducia-lang/fidus. https: //github.com/fiducia-lang/fidus [9] Thomas Gibson-Robinson, Philip Armstrong, Alexandre Boulgakov, and Andrew W. Roscoe. 2014. FDR3 — A Modern Refinement Checker for CSP. In Tools and Algorithms for the Construction and Analysis of Systems (TACAS). Springer Berlin Heidelberg, Berlin, Heidelberg, 187–201. doi:10.1007/978-3-642-54862-8_13 [10] Finn Hackett and Ivan Beschastnikh. 2025. TraceLinking Implementations with Their Verified Designs. Proc. ACM Program. Lang. 9, OOPSLA2, Article 350 (Oct. 2025), 28 pages. doi:10.1145/3763128 [11] Finn Hackett, Shayan Hosseini, Renato Costa, Matthew Do, and Ivan Beschastnikh. 2023. Compiling Distributed System Models with PGo. In Proceedings of the 28th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Volume 2 (Vancouver, BC, Canada) (ASPLOS 2023). Association for Computing Machinery, New York, NY, USA, 159–175. doi:10.1145/3575693.3575695 [12] Nicolas Halbwachs, Paul Caspi, Pascal Raymond, and Daniel Pilaud. 1991. The Synchronous Data Flow Programming Language LUSTRE. Proc. IEEE 79, 9 (1991), 1305–1320. doi:10.1109/5.97300 [13] Matthew Hennessy and Huimin Lin. 1995. Symbolic Bisimulations. Theoretical Computer Science 138, 2 (1995), 353–389. doi:10.1016/0304-3975(94)00172-F [14] Patrick C. Hickey, Lee Pike, Trevor Elliott, James Bielman, and John Launchbury. 2014. Building Embedded Systems with Embedded DSLs. In Proceedings of the 19th ACM SIGPLAN International Conference on Functional Programming (ICFP 2014). 3–9. doi:10.1145/2628136.2628146
23
[15] C. A. R. Hoare. 1985. Communicating Sequential Processes. Prentice Hall, Englewood Cliffs, NJ. Originally published as an article in Communications of the ACM, 21(8):666–677, 1978. [16] Gerard J. Holzmann. 1997. The Model Checker SPIN. IEEE Transactions on Software Engineering 23, 5 (1997), 279–295. [17] Kohei Honda, Nobuko Yoshida, and Marco Carbone. 2016. Multiparty Asynchronous Session Types. J. ACM 63, 1 (2016), 1–67. [18] Nikolaus Huber, Susanne Graf, Philipp Rümmer, and Wang Yi. 2025. Compiling the Mimosa Programming Language to RTOS Tasks. (2025). doi:10.48550/arXiv.2510.20547 [19] Nikolaus Huber, Susanne Graf, Philipp Rümmer, and Wang Yi. 2025. Mimosa: A Language for Asynchronous Implementation of Embedded Systems Software. In Coordination Models and Languages (COORDINATION 2025) (Lille, France). Springer-Verlag, Berlin, Heidelberg, 90–113. doi:10.1007/978-3-031-95589-1_5 [20] Gerwin Klein, Kevin Elphinstone, Gernot Heiser, June Andronick, David Cock, Philip Derrin, Dhammika Elkaduwe, Kai Engelhardt, Rafal Kolanski, Michael Norrish, Thomas Sewell, Harvey Tuch, and Simon Winwood. 2009. seL4: Formal Verification of an OS Kernel. In Proceedings of the 22nd ACM Symposium on Operating Systems Principles (SOSP). ACM, New York, NY, USA, 207–220. doi:10.1145/1629575.1629596 [21] Huimin Lin. 1996. Symbolic Transition Graph with Assignment. In Concurrency Theory (CONCUR) (LNCS, Vol. 1119). Springer, 50–65. doi:10.1007/3-540-61604-7_47 [22] Si Liu, Atul Sandur, José Meseguer, Peter Csaba Ölveczky, and Qi Wang. 2020. Generating Correct-by-Construction Distributed Implementations from Formal Maude Designs. In NASA Formal Methods (NFM 2020) (Moffett Field, CA, USA). Springer-Verlag, Berlin, Heidelberg, 22–40. doi:10.1007/978-3-030-55754-6_2 [23] Marten Lohstroh, Christian Menard, Soroush Bateni, and Edward A. Lee. 2021. Toward a Lingua Franca for Deterministic Concurrent Systems. ACM Transactions on Embedded Computing Systems 20, 4 (2021), 91:1–91:27. doi:10.1145/3448128 [24] Anna Lyons, Kent McLeod, Hesham Almatary, and Gernot Heiser. 2018. Scheduling-Context Capabilities: A Principled, Light-Weight Operating-System Mechanism for Managing Time. In Proceedings of the Thirteenth EuroSys Conference (EuroSys ’18). Association for Computing Machinery, Porto, Portugal, Article 26. doi:10.1145/3190508.3190539 [25] Leonardo de Moura and Sebastian Ullrich. 2021. The Lean 4 Theorem Prover and Programming Language. In Automated Deduction – CADE 28. Springer-Verlag, Berlin, Heidelberg, 625–635. doi:10.1007/978-3-030-79876-5_37 [26] Oded Padon, Kenneth L. McMillan, Aurojit Panda, Mooly Sagiv, and Sharon Shoham. 2016. Ivy: Safety Verification by Interactive Generalization. In Proceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI). ACM, 614–630. doi:10.1145/2908080.2908118 [27] Johannes Åman Pohjola, Alejandro Gómez-Londoño, James Shaker, Michael Norrish, June Andronick, and Leonardo de Moura. 2022. Kalas: A Verified, End-To-End Compiler for a Choreographic Language. In Interactive Theorem Proving (ITP) (LIPIcs, Vol. 237). Schloss Dagstuhl – Leibniz-Zentrum für Informatik, Dagstuhl, Germany, 27:1–27:25. doi:10.4230/LIPICS.ITP.2022.27 [28] Johannes Åman Pohjola, Hira Taqdees Syeda, Miki Tanaka, Krishnan Winter, Tsun Wang Sau, Benjamin Nott, Tiana Tsang Ung, Craig McLaughlin, Remy Seassau, Magnus O. Myreen, Michael Norrish, and Gernot Heiser. 2023. Pancake: Verified Systems Programming Made Sweeter. In Proceedings of the 12th Workshop on Programming Languages and Operating Systems (Koblenz, Germany) (PLOS ’23). Association for Computing Machinery, New York, NY, USA, 1–9. doi:10.1145/3623759.3624544 [29] A. W. Roscoe. 2010. Understanding Concurrent Systems. Springer London, London. doi:10.1007/978-1-84882-258-0 [30] Jun Sun, Yang Liu, Jin Song Dong, and Jun Pang. 2009. PAT: Towards Flexible Verification under Fairness. In Proceedings of the 21st International Conference on Computer Aided Verification (Grenoble, France) (CAV ’09). Springer-Verlag, Berlin, Heidelberg, 709–714. doi:10.1007/978-3-642-02658-4_59 [31] UNSW Trustworthy Systems. [n. d.]. MicroKit Ethernet Example. https://github.com/au-ts/microkit/tree/main/ example/ethernet. [32] Trudy Weibel, Zoltan A. Kocsis, Mathieu Paturel, Robert Sison, Isitha Subasinghe, and Gernot Heiser. 2024. Verified libmicrokit and CapDL Mapping. Technical Report. Trustworthy Systems, UNSW Sydney. https://trustworthy.systems/ projects/microkit/gordian-report.pdf [33] Wang Yi, Morteza Mohaqeqi, and Susanne Graf. 2022. MIMOS: A Deterministic Model for the Design and Update of Real-Time Systems. In Coordination Models and Languages (COORDINATION). Springer Nature Switzerland, Cham, 17–34. doi:10.1007/978-3-031-08143-9_2 [34] Zihao Zhang, Ti Zhou, Christa Jenkins, Omar Chowdhury, and Shuai Mu. 2025. AutoMan: Facilitating Verified Distributed Systems Development Through Automatic Code Generation and Manual Optimizations. In Proceedings of the ACM SIGOPS 31st Symposium on Operating Systems Principles (Lotte Hotel World, Seoul, Republic of Korea) (SOSP ’25). Association for Computing Machinery, New York, NY, USA, 768–785. doi:10.1145/3731569.3764822
24
Related documents
- CoreFi: A Core Calculus for Embedded Systems with Bounded Shared-Memory Channels#1820689
- Embedded Systems Under Resource Limits / Peter Wägemann ; Gutachter: Jan Reineke, Marcus Völp ; Rüdiger Kapitza, Wolfgang Schröder-Preikschat, Felix Freiling, Michael Engel#1154289
- Fundamentals of Program Analysis#3648
- Fearless Concurrency on the GPU#1034745
- Microarchitectural comparison, in-core modeling, and memory hierarchy analysis of state-of-the-art CPUs: Grace, Sapphire Rapids, and Genoa / Jan Laukemann, Georg Hager, Gerhard Wellein#1078603
Retrieved via Conceptio: every document is proof-bundled with source, license, and retrieval metadata.
Read the Docs → · View CLI source on GitHub · Conceptio Open Knowledge Archive