notes

The native ABI

(Milestone 19e, "Decision 2". The contract a nife program runs against: how it starts, how it makes system calls, and how it meets its capabilities. nifeos/moho_abi is the machine-readable half; this note is the prose half. See DECISIONS §10 for why the model is capability-based, and §14 for why "native ABI" and not Linux-compat.)

The big fork was already settled at milestone 7 (§10): the process model is capability-based, not Unix. So this is not a decision about fork versus capabilities. It is the smaller, still-open question the 19f split forced into the open: now that we deliver and run distinct programs, what is the contract between a program and the system? Three parts: the system call convention, the object surface reached through it, and how a program meets its world at startup.

The decision here is to write down and commit the convention we already run, rather than build a self-describing environment (a BootInfo page). Hardcoded, out-of-band agreement on the initial capability layout between a parent and the children it builds is the normal microkernel pattern. seL4 hands a BootInfo only to its root task; every other task gets caps placed by its parent per a private layout. Our progenitor is that parent. A BootInfo mechanism earns its keep when a loader must start programs whose layout it cannot know in advance, which is milestone 23 (live component replacement), with competing vendors, not now. See "What is deliberately deferred".

1. The system call convention

One instruction, svc #0. The kernel reads the registers, does the work, and returns.

register on entry on return
x8 the system call number unchanged
x0 first argument the i64 result
x1–x4 further arguments (see the specific system call)

Five system call numbers , and that is the whole width of the trap:

x8 name meaning
0 SYSTEM_CALL_EXIT end the calling thread's process, every thread in it. Never returns.
1 SYSTEM_CALL_YIELD give up the CPU voluntarily.
2 SYSTEM_CALL_INVOKE invoke a capability. This one carries the entire capability world (see section 2 below).
3 SYSTEM_CALL_CAPABILITY_DELETE drop the capability in a capability table slot, so the slot can be reused.
4 SYSTEM_CALL_EXIT_THREAD end the calling thread alone, clearing and waking a joiner's word (§276 (the thread system calls as built)).

That narrowness is deliberate (DECISIONS rule 3: the system call surface stays a boundary, not a habit). Everything a program can do to another object goes through the single SYSTEM_CALL_INVOKE door; adding a capability type or a method does not widen the trap, it adds a row to a table the kernel already dispatches. crates/user_mode_runtime is the userspace side of this: invoke, and send/receive/exit built on it.

2. The object surface, reached through SYSTEM_CALL_INVOKE

invoke(cap, method, a0, a1, a2): cap names a capability in the calling thread's capability table (a small integer, like a file descriptor), method selects an operation on the object that capability points at, and a0..a2 are the operation's arguments. The kernel checks that the slot holds a capability, that its rights permit the method, and that the object's type understands it. The method numbers live per object type in nifeos/moho_abi:

A program never sees a raw pointer to any of these. It sees a slot number, and the kernel is the only thing that can turn that number into the object. That is the §10 thesis in one sentence.

3. The entry contract

A program is an ordinary aarch64 ELF, linked in the low half (TTBR0, at 0x6000_0000; see notes/address-space-map.md). The loader lays out its segments, gives it a stack, populates its capability table (§4), and enters it at the ELF's e_entry with three register arguments:

_start(x0, x1, x2) -> !

START (the TCB method) is what hands those three words to the new EL0 thread; the kernel routes them through Thread::start_args into x0/x1/x2 at first entry (milestone 19e widened START from one argument to three; see notes/thread-control-block.md). Their meaning is the program's to define, with one reserved case:

A program never returns from _start. It runs until it calls SYSTEM_CALL_EXIT (a least_authority_demo, when its job is done) or loops forever serving requests (a driver). Returning would fall off the end of the world; there is no runtime to catch it.

There is no libc, no argv/envp array, no dynamic loader, no main wrapper. _start is the program. What a C runtime would do before main (zero .bss, set up the stack) is either done by the loader (the stack) or unnecessary (a freshly mapped frame is already zero; .bss is a fresh frame).

4. How a program meets its capabilities

Before START, the program's loader (the progenitor, or the kernel's own service wiring) has placed the capabilities the program needs into low capability table slots, and mapped any shared pages it needs at agreed virtual addresses. The program hardcodes which slot holds what and which VA is which. That agreement is the contract, and it is per program, published in that program's own source:

This is out-of-band agreement, not discovery: the program does not ask "what am I holding," it knows by the contract it was built to. That is the same shape seL4 uses for every task below the root, and it is honest to call it a convention rather than dress it up as an API. The convention is the ABI; writing it down (here, and in each program's header comment) is what milestone 19e commits.

5. The fault endpoint: a thread's death as a message (milestone 22)

A supervised thread's death is delivered to its supervisor as an ordinary endpoint message, so restart policy lives in userspace and the kernel never relaunches anything (DECISIONS §26). Two conventions make it work, and neither adds a system call or a method: a spawn-slot convention and a message-format convention (both in nifeos/moho_abi, module fault).

The spawn-slot convention. A supervised child is spawned with its supervision endpoint in the reserved fault slot, moho_abi::fault::FAULT_RENDEZVOUS_SLOT (the last capability table slot, CAPABILITY_TABLE_SLOTS - 1, 63 now). A supervisor building a child through the TCB surface places it there with ThreadControlBlock::CAPABILITY_INSERT's explicit target argument (invoke(tcb, CAPABILITY_INSERT, capability_slot, rights, target), where target is slot + 1 and 0 keeps the original first-free behavior). At START the kernel reads the fault slot. If it holds a Rendezvous capability the thread is supervised. The kernel records that endpoint as the thread's fault target and clears the slot, so the child cannot forge fault messages on it. An empty fault slot means the thread is unsupervised and gets the pre-milestone-22 behavior: it dies and is reaped immediately, reporting to no one. The reserved slot is the last one precisely so an ordinary child, whose grants fill the low slots from zero upward, never lands a working endpoint there by accident and gets mistaken for supervised.

The message-format convention. When a supervised thread faults or exits, the kernel delivers one five-word message to its supervision endpoint, taken by a plain RECEIVE:

  w0  event    fault::EVENT_FAULT (1) or fault::EVENT_EXIT (2)
  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 system call's result register and w1..w4 in the next four argument registers (x1..x4 on aarch64, a1..a4 on riscv). On an ordinary message w3 carries the badge of the sender's capability (milestone 613 (a system log service)), and w4 is written only by the kernel, so a death is told apart by its first word. The tid is trustworthy because the kernel is the only sender on this path. A sixth word, the child's label, rides in argument register 5; notes/supervision.md has it (milestone 105 (the two forks)).

The userspace side of that is two functions rather than one, and the split is not an ABI difference: user_mode_runtime::receive reads three words and user_mode_runtime::receive_message reads all five, both from the same RECEIVE. The five-word read arrived with milestone 36 (notes/c-seam.md), the first program to want w3. A restart policy needs the event and the tid, but a checker needs the faulting address, because that is the only word that says where the dead thread actually pointed.

The corpse is dead until reaped: after the message, the thread never runs again, but its TCB, address space, and memory persist for postmortem until the supervisor reaps them with §16 revocation (MemoryRegion::DESTROY on the child's region). That is why the reserved w4 can carry a resume protocol later without a format change: the corpse it would resume is still there.

The one ambient thing: reading the clock (milestone 19e / the primitive suite)

§10 says no ambient authority, and the object surface honors it: everything a program can do goes through a capability. There is exactly one deliberate exception, and it is a read, not a do: EL0 can read the virtual counter (CNTVCT_EL0) and its frequency (CNTFRQ_EL0), via user_mode_runtime::now and user_mode_runtime::counter_hertz, no system call. The kernel opens this in timer::initialize (CNTKCTL_EL1.EL0VCTEN); without it the read traps.

It is an exception made with eyes open. A monotonic counter grants no authority to affect anything, only to observe the passage of time, so it does not mint the kind of ambient authority §10 rejects (which was about reaching resources you were not handed). What it does cost is a timing side channel, and that is a real cost every OS offering userspace timing accepts (Linux exposes the same counter to its vDSO). We accept it too, knowingly, because the cross-OS primitive suite needs userspace self-timing to be comparable to lmbench, which measures from userspace. The physical counter and the timer control registers stay trapped; only the virtual counter opens. A stricter build could revoke even this and route time through a capability; we have not, and this note is the record of why.

The fine counter is not ambient, and that took a decision (milestone 229)

The cycle counter is roughly 160x finer than the coarse counter (0.25 ns against 41 ns), so it is not ambient on aarch64 or riscv64. DECISIONS 139 (who may read the cycle counter, and by what authority) decided it. The kernel closes it by default on every core, and a thread may be granted it only as an embryo; the context switch enforces the grant. There is deliberately no system call method to set it yet, because a method number is irreversible and its successor is already foreseeable. On x86_64 rdtsc stays ambient, a stated position rather than a gap, because closing it takes out now() itself. The grant is compiled only into test and measurement builds. None of this is timing confinement: what it buys is accountable authority. The decision's parts, the per-ISA table and what the build gate does not cover are in abi/cycle-counter-grant.md.

What is deliberately deferred

Recorded-accepted by milestone 94's sweep (2026-08-04). Both items below are deferrals with a recorded trigger rather than work waiting for someone to notice it, so an audit may pass over them. See notes/untracked-work-sweep.md for the inventory, and §71 for what would promote either one to a roadmap row.