notes

Supervision: a thread's death becomes a message

The kernel is the only witness to a thread's fault. It is the one that saw the bad load, the illegal instruction, the exit. So it is the one that must pass the news along. Milestone 22 (trusted) builds the one kernel mechanism a userspace supervision tree needs (DECISIONS §26): when a thread faults or exits, the kernel delivers a message to the supervision endpoint its spawner designated. Restart policy stays in userspace, and the kernel never relaunches anything.

This is seL4's fault endpoint, and it is the mechanism half of the mechanism/policy split the whole project runs on. The kernel turns a death into a message; what to do about the death (retry, back off, give up, escalate) is a userspace supervisor's business, layered with ordinary IPC.

What the kernel does, exactly

Three pieces, and the surface cost is zero new system calls and zero new methods.

  1. Designation, at spawn only. A supervised thread is spawned with its supervision endpoint in a reserved capability table slot (moho_abi::fault::FAULT_RENDEZVOUS_SLOT, the last one). At START the kernel reads that slot; a Rendezvous capability there means "supervised," and the kernel records the rendezvous as the thread's fault target (Thread::fault_ep) and clears the slot, so the child holds no authority to send on it. A thread spawned with an empty fault slot is unsupervised and gets the pre-22 behavior: it dies and is reaped immediately, reporting to no one. Supervision is fixed at spawn and cannot change afterward; runtime reattach is deferred (§26.2) until milestone 23's hot-swap work needs it.

  2. Delivery, without blocking the faulting path. When the thread dies (sched::depart, reached from both the arch fault handlers and SYSTEM_CALL_EXIT), the kernel builds the five-word message and delivers it to the fault endpoint. Delivery is the ordinary synchronous-send rendezvous, reused. If a supervisor is already blocked in RECEIVE, hand it the message and wake it. If none is, the corpse itself parks on the endpoint's sender queue with the message in its mailbox, so the notification waits there rather than being lost. This is the same guarantee an ordinary blocked sender gets. It is why a data-carrying death rides the sender queue rather than the data-less interrupt signal count (interrupt_notify): a signal count could say "something died" but not carry the tid, pc, and address. The corpse is never woken: ipc_receive recognizes a Dead sender, takes its message, and leaves it dead, exactly the way it already leaves a CALL caller blocked.

  3. Dead until reaped. After the message, the thread is State::Dead: it never runs again, but its corpse (TCB, address space, memory, and the fault-time registers in its mailbox) persists for postmortem. The scheduler never runs a Dead thread, and the reaper (finish_switch) never collects one; only the supervisor's explicit §16 revocation (MemoryRegion::DESTROY on the child's region) frees it. That is what makes a future resume protocol possible additively: the reserved fifth message word can carry it, because the corpse it would resume is still there.

The message

Five words, delivered to the supervision endpoint's holder through a plain RECEIVE:

  w0  event    fault::EVENT_FAULT or fault::EVENT_EXIT   (crashed vs finished)
  w1  tid      the dead thread's id, kernel-stamped
  w2  pc       the faulting instruction (0 for a clean exit)
  w3  addr     the faulting address (0 for a clean exit)
  w4  reserved 0 today; a fault-reply / resume protocol arrives here additively

RECEIVE returns w0 in the result register and w1..w4 in the next four argument registers. The IPC mailbox widened from three words to five to carry this; ordinary three-word IPC leaves the top two zero, so only a supervisor reads them and no other program's RECEIVE changes.

A sixth word, the child's label, arrives in argument register 5 (x5, a5, r9). It is the badge its builder put on the supervision capability with rendezvous::BADGE before inserting it, kept by the kernel at START (milestone 105 (the two forks), §148 (resolves by asking the kernel)). The kernel writes it only on a death delivered to a plain RECEIVE, so the mailbox stays five words. A receiver zeroes the register first, as receive_message does, so 0 means unbadged or not a death. The child holds no capability carrying its label, and a sender's badge arrives in w3, so a label can be neither learned nor forged. RECEIVE_CAPABILITY and in-kernel receives do not get it. sub_server_supervisor uses it to tell two children apart.

Both events flow because restart policy needs to tell "crashed" from "finished": a crash is a reason to restart, a clean exit is a reason to stop. The tid is trustworthy without a badge because the kernel is the only sender on this path. seL4 solves the general untrusted-sender case with badged capabilities; that machinery returns as its own decision if a supervision endpoint ever needs trustworthy identity from userspace senders.

Why the corpse is a new state, not a reused one

Finished is the state of a thread the reaper should collect right now (a normal exit, or an unsupervised fault). Dead is a thread that has reported and must not be collected until its supervisor says so. Reusing Finished would race the reaper against the supervisor; a distinct Dead state makes "dead until reaped" a property of the type, not of timing. Revocation treats Dead as reapable (unlike a live Ready/Running/Blocked), and the scheduler treats it as never-runnable, so it is dead in every sense but "its memory is gone."

What this is not

It is not restart policy, and it is not automatic. The kernel delivers one message and stops; a userspace supervisor decides everything else. It is not a heartbeat or a liveness check either. This detects death at the exact instant with the exact cause, which polling cannot. A supervisor that wants to catch "alive but wedged" layers its own timeout with ordinary IPC and no kernel help (§26.1).

Proven

The policy half, built on top of this (phase B.2, notes/trusted-init.md): a real userspace supervision tree. A supervisor holding no memory at all applies bounded-retry policy to a sub-server a construction server builds, and the progenitor has deleted the authority it would need to interfere. That is what this mechanism exists for, and it is proven on both ISAs in authority_tests.

And at the interactive prompt (the milestone 22 increment that migrated the boot path): every job the shell spawns is born supervised, and job_undertaker collects the corpse. It is the smallest supervisor in the tree and the one that says most plainly what supervision costs a system. That is one endpoint capability, no memory, no policy, and the job's pages come home to the progenitor's pool rather than to the collector. The restart half is deliberately absent, because a command a person typed has no business being restarted when it ends. system_tests/src/user/job_undertaker_tests.rs proves it with a control (three jobs exhaust a three-job pool when nothing collects) and a claim (twelve go through the same pool when job_undertaker runs); script/swish-check runs eleven through the real boot's six-job pool. See notes/trusted-init.md for what the progenitor gave up and what it still holds.

Cross-ISA kernel tests (system_tests/src/user/supervision_tests.rs): a child built holding a fault endpoint crashes on a null load. The supervisor receives (FAULT, tid, pc, addr) with the right tid and address, and the corpse still holds its fault message after delivery. Revocation reaps it, and a fresh child runs in its place. A second test drives the clean-exit path and asserts the EXIT event. See DECISIONS §26, notes/abi.md (the message format and spawn-slot convention), and notes/object-revocation.md (the reap the supervisor uses).

The reap authority a supervisor actually needs, stated concretely

Milestone 36 (notes/c-seam.md) is the first thing outside milestone 22 to build a supervisor that restarts a real component, and it pinned down the requirement §26's phase-B block left open.

Reaping is MemoryRegion::DESTROY, which needs WRITE on the region. WRITE on a region is also what builds a process from it (RETYPE, RETYPE_OBJECT, SPLIT). So a supervisor that can restart its child is a supervisor that can build processes, unless it proxies the reap through something else.

Resolved: Rendezvous::REAP (DECISIONS §32 (supervisor))

calef ratified it the same day the requirement above was measured, and it is built on both ISAs. The method hangs off the supervision endpoint, not off MemoryRegion: a MemoryRegion method has to name a region, and the whole premise is that the supervisor holds none. Authorization needs no new bookkeeping, because §26 already stores Thread::fault_ep and the kernel already stamps the tid on the death message, so the check is "the named thread's recorded fault endpoint is the endpoint being invoked". No registry, no new capability type, one new method.

Two boundaries, both deliberate:

It also settles the tid-to-handle half of this gap for this case only: the tid is authorized relative to the rendezvous it arrived on, so no Tcb::NAME, no per-child rendezvouses, no builder-reported tid. That is the rendezvous-only naming discipline applied consistently, a name that means something only to the holder of the capability it came through rather than a global handle. Any future operation that needs to name a child is a fresh decision and should try this shape first.

What narrowing the existing supervisors measured

This is the part worth reading, because it says what §32 did and did not buy.

The authorization invariant is machine-checked, not only tested: two Kani harnesses in crates/capability_table cover it, which is the right instrument for "a capability that cannot build cannot be made to build via reap" because it quantifies over rights combinations rather than sampling them.

Where the death goes when the waiter is a shell (milestone 235)

A death reaches one endpoint, and that single fact is what decided milestone 235 (design/roadmap/0235-a-faulted-job-should-reach-the-prompt.md). At the interactive prompt the holder of that endpoint is job_undertaker, whose whole job is collecting. The process that needed to know was swish, blocked in a RECEIVE on the progenitor's result endpoint for an answer a killed thread can never send. So the prompt hung, and only on a fault: an ordinary non-zero exit is a value the child sends before it exits, and a spawn the progenitor could not build already had spawn_protocol::SPAWN_FAILED.

Three couplings were available and two lose to properties recorded on this page.

The residual is a synchronous-send problem rather than a supervision one. That SEND is a rendezvous with no non-blocking form, so it completes only when someone reads the result endpoint. Every ordinary job leaves the shell with a read outstanding there; a screen-narrowed line does not, so a non-tail stage of one faulting parks the undertaker until the next command reads, which then takes the stale word. Closing it needs either a non-blocking send or a receive that waits on two endpoints, and both are the system call surface (§10 (process model: capability-based, microkernel), §16). Recorded in components/src/job_undertaker.rs's BUGS, where the next person to touch that loop will meet it.

A job that hangs without faulting is untouched by any of this. A live thread blocked in a RECEIVE nobody will answer is not dead, so no death message exists to route, and none of the three couplings had anything to say about it. §32's refusal to reap a live thread is the same boundary seen from the other side.

BUGS