Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Channel Declarations

ChannelDecl       ::= SyncChannelDecl | AsyncChannelDecl

SyncChannelDecl   ::= 'Sync' 'Chan' ('<' Type '>')? ident '=' ident '-->' ident ';'?

AsyncChannelDecl  ::= 'Async'? 'Chan' ident '=' ident '-->' ident ViaClause? ';'?
                    | 'Async'? 'Chan' ident '=' ident '<->' ident ';'?

ViaClause         ::= 'via' ident '<' Type (',' Capacity)? '>'
Capacity          ::= int | ident          -- a literal or a const

A channel declaration introduces one named communication endpoint between two protection domains. Channels live in .fis system files; the .fi files reference them by name only, in the channel events of a process.

A channel is one of two kinds:

  • a signalling channel carries no value: a send c! wakes the other side, and a receive c? waits for it;
  • a message-passing channel carries values of a type: a send c!e passes the value of e, and a receive c?x binds it to x: the buffered channel, and the synchronised channel Sync Chan<T>.
DeclarationKindDirection
Chan c = a --> b;signallinga to b
Chan c = a <-> b;signallingboth ways; see WF2
Sync Chan c = a --> b;signallinga to b, a of lower priority
Sync Chan<T> c = a --> b;message passinga to b, a of lower priority, a T per call
Chan c = a --> b via region<T>;message passinga to b, values of T

The Async keyword may be omitted — a Chan without a leading Sync is asynchronous. The arrow is always written: Sync channels and buffered channels take --> only. Only a Sync channel names a type after Chan: Chan<T> on an async channel is an error, since its values go in a buffer, via region<T>. The trailing semicolon is optional.

Fields

  • Name — snake_case identifier. The same name appears in process expressions on the LHS of ? / !.
  • Endpoints — two distinct protection-domain names. Both must be declared in the same .fis file. A Sync channel’s sender must have a strictly lower priority than its receiver (seL4 protected procedure calls run low to high).
  • Buffer (optional, after via; --> channels only) — the MemoryRegion that holds the channel’s values and the type of a value: via packet_buffer_outer<int>, a declared data-layer struct (via eth_outer_output<Slot>), or raw bytes, via ring<byte>. The type is a struct or a scalar, never an array, and has at least one byte; it is the value the channel carries, Σ(c). A struct is the channel’s communication type, and the C backend types receive binders from it (o2d?pkt declares static struct Slot pkt;). via on a <-> or Sync channel is a parse error.

Signalling channels

A signalling channel is a Microkit notification: a pure synchronisation point. c! notifies the other end; c? is enabled when the PD was notified on c. Notifications do not queue: several sends before the receiver runs wake it once.

A Sync channel is a protected procedure call from the lower-priority PD to the higher: c! is microkit_ppcall, and the sender waits while the receiver’s @bind(microkit.protected) process handles c? and runs to its end (see Entry Points). The sender’s end is marked pp in the SDF. A Sync Chan<T> carries a value with the call (see Synchronised channels); the reply is empty. init makes no such call. In the UPPAAL model a call is two handshakes: the receiver enters protected from where its notified waits, the sender waits until protected ends and answers, and the receiver goes back to where it was.

Examples

// Signalling, one way.
Chan tick = timer --> worker;

// Signalling, both ways — `Async` is the default, can be omitted.
Chan d2i = dd <-> eth_inner;
Async Chan s2o = simulate <-> eth_outer;

// Signalling, synchronous: the lower-priority eth_outer calls dd.
Sync Chan call = eth_outer --> dd;

// Message passing: buffered, a value of a declared struct.
Chan o2d = eth_outer --> dd via eth_outer_output<Slot>;

// Message passing: buffered, raw bytes.
Chan ring = eth_outer --> eth_inner via ring_buffer_outer<byte>;

Buffered channels

A channel declared Chan c = a --> b via region<T>; is a FIFO queue of T values from a to b, held in region as a ring: Lamport’s single-producer single-consumer queue, which needs no lock because each index has one writer (the sender moves the tail, the receiver the head).

  • Layout. A 16-byte header holding the two indices and a signal word, then N slots of T, packed. N is the channel’s capacity: via r<T, N> declares it (a literal or a const), and it must be at least 1 and fit in the region after the header, else an error at the channel; without it, N is as many as fit, ⌊(size − 16) / sizeof(T)⌋, or 2³¹ − 1 if that is smaller (the indices’ bound), with a warning that the rest of the region is unused.
  • Order. Values are received in the order they were sent, each once.
  • Send, c!e. Copies the value of e into the next slot, and notifies the receiver if the receiver asked. A send to a full ring is lost: the sender goes on and no notification is sent.
  • Receive, c?x. Copies the oldest value into x. A receive waits while the ring is empty, and is enabled whenever the ring holds a value, whatever notification woke the PD, so a receiver drains everything that is queued. A receive that finds the ring empty asks to be notified (sDDF’s signalling protocol), so a receiver that is still draining costs the sender no system call.
  • By copy. Values cross by copy, in both directions; neither PD holds a reference into the region.
  • The region. It is mapped into both endpoint PDs by fic (rw, cached, at addresses fic chooses): it must not also appear in a Mapping, and it backs one channel only. Only fic’s runtime reaches it: the generated unit exports no symbol for the region.

Synchronised channels

A Sync Chan<T> passes a T in the protected procedure call itself: c!e copies the value of e into the message registers and calls, and the receiver’s protected process binds it with c?x. There is no shared memory and no queue: one value per call, by copy, and the sender waits until the receiver’s process has run.

struct Req { a: int32; b: int64; }
Sync Chan<Req> ask = client --> server;

// client.fi
evt fill: r = mk.req_make();
@bind(microkit.notified)
proc Notified() { fill -> ask!r -> Skip; }

// server.fi
@bind(microkit.protected)
proc Serve() { ask?q -> show.q -> Serve(); }
  • It fits in one seL4 message. The value goes in the message registers, up to seL4’s seL4_MsgMaxLength, 120 words of 8 bytes; the kernel passes the first 4 in hardware registers on AArch64 and the rest through the IPC buffer. A T of more than 960 bytes is an error at the channel, naming its size.
  • A value both ways. c!e and c?x are required on a Sync Chan<T>, and rejected on a Sync Chan with no type, as on any channel that carries no value.

Channel events in process bodies

Inside a process, channel events are written chan_name '?' ident (receive) and chan_name '!' expr (send) on a message-passing channel, and chan_name '?' and chan_name '!' on a signalling one. The names must match exactly; typing resolves each event back to the declared ChannelDecl and checks that the PD is one of its endpoints, that it may send or receive there (either end may do both on a <-> channel), and that the value matches the payload type.

Channel events are the only way to a channel. Imported C or Pancake cannot call the ring behind a buffered channel: in a .c import the ring is not yet declared, and a separate driver or Pancake object that calls it fails to link.

See Event Declarations → Channel events for the inline event grammar and Process Definitions for how channel events sit in a process expression.

WF2 and bidirectional channels

fic checks that the channel dependency graph is acyclic (WF2): a PD that receives from another waits for it, and a cycle is a circular wait. A bidirectional channel adds the edge in both directions, so every <-> channel is a cycle. fic --check and the image build warn on one and still build; --allow-wf2-cycles (or allow_wf2_cycles = true in fire.toml) silences the warning, deferring deadlock-freedom to an external authority such as fire verify. The other --emit modes do not run WF2. The demos pingpong and pingpongpan use <-> this way. See Well-Formedness for the check and its warning.

Limitations

  • The Sync modifier rejects bidirectional <-> syntactically; sync bidirectional channels would require a richer call/reply protocol than the current implementation supports.