Rust std on the native ABI
(Milestone 27. The first wall an application hits on nife was "no std": you could write a
no_std binary against crates/user_mode_runtime, and nothing else. This milestone makes ordinary Rust,
Vec and String and println! and Instant, compile and run on the capability ABI. See
DECISIONS §22 for the decision and why; notes/abi.md for the ABI it binds to.)
The shape is Hermit's, not Redox's. Hermit implements std's platform layer directly on a
non-POSIX unikernel ABI; Redox writes a POSIX C library (relibc) first and puts std on top of that.
We took the native road: no errno, no fd table, no open, no fork under our sys backend,
because the OS lacks them and std does not need them for a workload that stays off files and
sockets. That is why the native ABI came first, per DECISIONS §14 (the project's direction) and §15 (the native ABI): std widens "runs real workloads" from hand-built no_std binaries to most of
crates.io, without smuggling in the POSIX assumptions the ABI deliberately excludes.
What a std program is given
A std program is an ordinary nife ELF (notes/abi.md §3): entered at _start, linked at
0x6000_0000 (notes/address-space-map.md), capability table populated by its parent. std's runtime contract needs two things, and the ABI's
out-of-band convention (notes/abi.md §4) grants them at fixed slots:
- slot 0: an untyped budget. The global allocator draws heap pages from it lazily via
untyped::MAP, one page per invoke, at0x4000_0000. It is the heap theallocator_exerciserworkload proved, its policy restated because std cannot depend on an out-of-tree crate. - slot 1: an endpoint with WRITE.
stdoutandstderrSEND here, 16 bytes per message (w0 = byte count, w1|w2 = the bytes, little-endian). std's ownLineWriterbatches user writes; the receiver reassembles.
Three more slots exist, and a program holds each only if it was given the thing behind it
(milestone 27 phase two, the std::net and std::fs bindings below):
- slot 2: a
Stackendpoint with WRITE.std::netspeaks net_stack's socket contract over it. - slot 3: an untyped budget the net PAL mints each socket's shared frame from.
- slot 4: an FS-service endpoint with WRITE, which is a directory capability, plus the page it
shares with the FS server mapped at
0x1100_0000.std::fsspeaks the §27 file contract over it. - slot 5: a
PageFramecapability naming the clock page, withREAD, plus a read-only mapping of it at0x1200_0000.SystemTime::now()is the offset it finds there plus the ambient counter (milestone 51, §43). - slot 6: the entropy service's request endpoint, with WRITE (milestone 56, §44). It means "you
may obtain randomness" and names no device; no mapping comes with it, because randomness is
obtained by asking, not reading.
std::random::SystemRngis aCALLon it.
A program never touches the slots it does not use. The absence of slots 2 and 3 is what "no
ambient network" feels like from inside a process, and the absence of slot 4 is "no ambient
filesystem": each returns Unsupported because there is no capability to reach, not because the
code was compiled out. A program can hold
one and not the other, so slots do not fill contiguously; section 4 of notes/abi.md records how the kernel
places slot 4 while leaving 2 and 3 empty, and why the gap matters.
The PAL surface, and what each piece binds to
The backend lives in patches/std-nife/overlay/std/src/sys/ and is materialized into a patched
std by cargo xtask std-src. Each file binds one std concept to the ABI:
| std concept | nife binding |
|---|---|
GlobalAlloc |
untyped::MAP from slot 0, grow-on-demand (sys/alloc/nife) |
stdout / stderr |
endpoint::SEND on slot 1 (sys/stdio/nife.rs) |
stdin |
RECEIVE on slot 30 when the line redirected or piped a stream into the program; otherwise the console's line, slot 29, for a program granted it; otherwise end of input (sys/stdio/nife.rs) |
Instant, SystemTime |
the virtual counter, CNTVCT_EL0 / rdtime (sys/time/nife.rs) |
panic! |
print, then brk/ebreak: a fault the kernel attributes. No unwinding. |
thread::spawn |
a TCB joined to the program's own process, slots 10 to 12 (threads) |
net (TcpStream, outbound UdpSocket) |
net_stack's socket contract on slots 2/3 (sys/net/connection/nife.rs), or Unsupported when not granted |
fs (File, metadata, read/write) |
the FS service's file contract on slot 4 (sys/fs/nife.rs), or Unsupported when no directory was granted |
std::random::SystemRng |
the entropy service's endpoint on slot 6 (sys/random/nife.rs), or a panic when not granted |
HashMap seed |
the same service when granted; splitmix64 from the counter when not, and labeled |
std::env::consts::OS |
"nife" (patched into env_consts.rs) |
std::env::var / vars / set_var |
a process-local table (sys/env/nife.rs), seeded only with TZ/LANG/TERM from a granted inert-configuration page (slot 7, milestone 47, DECISIONS §111) if one exists; otherwise empty at start |
std::env::temp_dir / split_paths / join_paths |
TMPDIR or /, and a :-separated list (sys/paths/nife.rs) |
std::env::current_dir |
/, the root of this process's own namespace (milestone 47); Unsupported when it holds no directory. current_exe and chdir refuse, home_dir is None |
std::process::id |
0, because this system issues no process identifier (sys/process/nife.rs); everything else in std::process refuses |
The system call glue (sys/pal/nife/rt.rs) deliberately twins crates/user_mode_runtime's
svc/ecall wrappers, because std cannot depend on the crate. The ABI constants are not restated: abi.rs is generated verbatim from nifeos/moho_abi by std-src, so the numbers cannot
drift. The heap is talc/, the core of vendor/talc. So too netproto.rs from crates/socket_contract/src/lib.rs, and fsproto.rs from
crates/file_system_contract. Every wire format the PAL speaks has exactly one definition, and it
lives with the server that answers it.
A crate root may keep a module in its own file (pub mod fs;), as file_system_contract has since
milestone 845 (the filesystem-protocol crate root is split along its seams). It is copied with that
file inlined as pub mod fs { ... }, so std still builds one file.
The slot numbers and page addresses themselves (rt::FS_DIR_SLOT, rt::CLOCK_PAGE and the rest)
come the same way, as runtimeproto.rs from crates/std_runtime_contract, since milestone 595
(provisional) made the progenitor a loader of std programs too.
The toolchain: build-std against a patched rust-src
There is no crate to adopt; the deliverable IS the PAL, plus the machinery to build it.
-Zbuild-std compiles std from the sysroot of the rustc it invokes, so a patched std means a
patched sysroot. cargo xtask std-src
builds one:
- Hardlink-clone the real nightly (
cp -alofbinandlib), which costs almost no disk. rustc resolves this directory as its sysroot (it derives the sysroot from the location oflibrustc_driver; a symlink farm resolves back to the real toolchain, as measured). - Replace the
srcsubtree with a real copy (independent inodes), so patching it never touches the shared rustup toolchain. - Patch that copy: drop in the overlay PAL files, generate
abi.rs/talc/, and insert atarget_os = "nife"arm into std'scfg_select!dispatchers (pal, alloc, stdio, random, thread, time, io/error, thread_local storage and guard) plusenv_constsand therestricted_stdchain in std'sbuild.rs. - Link it as this worktree's own toolchain,
nife-dev-<directory>-<hash>(rustup toolchain link; the next section says why the name is per worktree).
cargo xtask std-exerciser then builds the std_exerciser demo for both custom targets against it,
setting RUSTUP_TOOLCHAIN=<farm> rather than +<name>. The cargo proxy that launched xtask already
exports RUSTUP_TOOLCHAIN=nightly, which would override a + selector
and silently build std from the unpatched sysroot.
std-src is idempotent: a stamp of all inputs (the toolchain version, the ABI/heap crates, the
target specs, every overlay file, and a patch-logic version) guards the rebuild, so only a PAL
change forces std to recompile.
Each worktree has its own toolchain name
The farm is per worktree, and since 2026-10-10 so is its name: std-src links
nife-dev-<directory>-<hash of the worktree's path> (provisional; calef has not ruled on it) and
prints it. rustup toolchain link writes one symlink per name for the whole account, so a name
that two worktrees shared was a name they fought over. Until that day every worktree linked the
same nife-dev, and each script/test took it from whichever lane had it last.
- 2026-07-31: a pruned worktree left
nife-devdangling, and unrelated builds failed far from the cause withoverride toolchain 'nife-dev' is not installed. - 2026-08-18: lane
55-durabilityrelinked mid-run and lane64-more'sstd_exerciserbuilt against 55's farm, caught only by a person reading theCompiling stdpath.std_srcthen learned to relink loudly on the warm path, which made the theft visible and did not stop it. - 2026-09-30: three sites of evidence in one evening. Main-soak's
std-abortsaborted on dep-info naming another worktree's farm; the 1377 lane built the unpatched std twice underCARGO_TARGET_DIR=$PWD/target;rustc --print sysrootin a fresh worktree named another worktree's farm. Every build this tree owns has named the farm by path since, because a path this checkout computed and checked is the only selector with one owner. - 2026-10-10: three false alarms in a day from lanes relinking each other, though no result was wrong, since the builds already used paths. A name nothing built through still churned.
So nothing in the tree builds through a name. The per-worktree link is for a person typing
cargo +<name>, and it cannot be taken: no other worktree computes it. std-src also removes
every nife-dev-* link whose farm is gone, which is what a pruned worktree leaves, so nobody has
to remember to. The workaround from the lane for milestone 57 (partitioning a real drive) still
works: symlink a worktree's target/nife-farm at the main checkout's farm once cargo xtask std-stamp shows the stamps match, and std_src() early-returns instead of rebuilding a second copy.
The legacy nife-dev link is still written by lanes cut before 2026-10-10 until they rebase,
and nothing here reads, writes or deletes it. Once no open lane predates the change, the maintainer
removes it once with rustup toolchain uninstall nife-dev.
std-exerciser also pins CARGO_TARGET_DIR to std_exerciser/target and prints the override.
An export used to separate a build from its evidence: the sweep judged the previous run's
dep-info, so a wrong-sysroot build passed green. Both shapes were reproduced host-side.
The target specs
targets/{aarch64,riscv64,x86_64}-unknown-nife.json, built with -Zbuild-std and
-Zjson-target-spec. x86_64 joined at milestone 184.
The load-bearing fields:
"os": "nife"selects oursysbackend through every dispatcher."panic-strategy": "abort"means unwinding machinery is never linked;panic!prints and faults."singlethread": falsesince milestone 812 (std::thread::spawnruns real threads in one address space): address wait locks, key-based thread-locals through the thread pointer, and real threads. The threads appendix has the PAL.- softfloat (aarch64
-neon, riscvlp64, x86_64-mmx,-sse...,+soft-floatwith"rustc-abi": "softfloat") matches EL0/U-mode/ring 3 with no FP save area, the same choice theno_stdprograms make. On x86_64 this is a correctness requirement, not a preference:kernel/src/arch/x86_64/saves no FPU or SSE state on a context switch. A std program that let LLVM emit SSE would have itsxmmregisters overwritten by whichever thread ran next.
The reasoning of milestone 184 (extend the std port to x86_64) for each field, the probe showing no
SSE leaked in, and the entry stub that fixes the stack offset are in the x86_64 spec
appendix.
std::net and std::fs
Both are clients of a frozen contract. Their wire constants are generated verbatim by std-src
(netproto.rs and fsproto.rs), so they cannot drift from the server's.
std::netbindsTcpStream,TcpListenerand outboundUdpSocketto net_stack's socket contract on slots 2 and 3, under §25 (socket identity). Each socket gets its own shared frame; a listener gets none. Errors map by meaning, not by errno: a refused connect isConnectionRefused, and a port outside the listen grant isPermissionDenied. The full mapping is in the net appendix.std::fsbindsFileand the namespace verbs to the FS server's file contract on slot 4, under §27 (the filesystem service). A path resolves under the one granted directory, so/motdandmotdare one file. Any..is refused withInvalidFilename, because no capability designates what is above the grant. A nested path is a chain ofOPENDIRdescents since milestone 122 (a directory handlestdcan hold). The mapping is in the fs appendix, the walk andstd::fs::Dirare in the descent appendix, and file times are in their own appendix.
A program granted neither gets Unsupported from both, because there is no capability to reach.
What still ends a nife process
The dangerous std call is not one that returns Unsupported, but one that compiles and then kills
the process. Milestone 64 (enough std to run somebody else's crate) found five on
2026-08-18: env::vars, env::temp_dir, env::split_paths, process::id and process::exit. All
five now answer or exit cleanly. A gap list built from Unsupported answers could never show them,
so a check now greps the sys/ sources the compiler built for bodies that end a process. Each hit is compared against ABORTS_ACCEPTED in xtask/src/farm.rs, which
carries a reason per entry.
cargo xtask std-aborts # on its own, against whatever the farm last built
script/test # runs it too: `std-exerciser` ends with it
The five calls, how the check works and its own BUGS are in the std-aborts appendix.
EXAMPLES
Build the patched toolchain and the demo, then check that this worktree's farm matches the main checkout's before borrowing it:
cargo xtask std-src # patch rust-src and link it as this worktree's nife-dev-<dir>-<hash>
cargo xtask std-exerciser # build std_exerciser for the nife targets against it
cargo xtask std-stamp # run in both checkouts; equal output means the farms match
Find this worktree's toolchain name and use it by hand:
rustup toolchain list -v | grep "$(pwd)/target/nife-farm"
cargo +nife-dev-nife-1a2b3c4d build ... # the name the line above printed
What a program granted a directory sees, as std_exerciser runs it:
let text = std::fs::read_to_string("/motd")?; // the same file as "motd"
let err = std::fs::File::open("../motd").unwrap_err();
assert_eq!(err.kind(), std::io::ErrorKind::InvalidFilename); // nothing is above the grant
std::fs::write("f", b"x")?; // CREATE or TRUNCATE, then WRITE
And a clean abort sweep:
$ cargo xtask std-aborts
std-aborts: 26 process-ending bodies across 79 compiled std sources, all accounted for
The proof
std_exerciser is an ordinary Rust program with no no_std and no unsafe: one binary with three
behaviors, chosen by the authority it was granted. With a directory it walks the std::fs
surface; with the network it runs a UDP DNS query and a TCP echo; with neither it runs Vec,
String, HashMap and Instant and checks that fs and net refuse. Three kernel tests spawn it
and compare its output byte for byte on both ISAs. What each branch asserts is in
the proof appendix.
BUGS
One line each. The full entry is in the caveats appendix unless another link is given.
- A spawned thread's stack has no guard page, and a timed wait spins on
yield. See the threads appendix. std::process::exitexits cleanly, but the kernel drops the code. A supervisor can tell exit from crash and cannot tellexit(0)fromexit(1). §301 (exit status and output) decided how it travels; milestone 172 (a capability-native subprocess primitive) builds it.SystemTime::now()andstd::randompanic when the process holds no clock or entropy grant, because neither call has an error channel.HashMap's seed is the one caller that degrades.- The environment holds only what a grant seeded (
TZ,LANG,TERM) plus what the program sets.current_exeandchdirrefuse,home_dirisNone, andprocess::id()is0. nethas no non-blocking mode or timeouts, no DNS throughlookup_host, and no IPv6. A listener's backlog is one connection. A socket's local port follows its id, so fast churn can reuse a port slirp has not cleared (the net appendix).fshas nocanonicalize, links, permissions, locks orFile::duplicate. A revoked FS endpoint reads asPermissionDenied, because the wire's errno space overlaps the kernel's invoke errors (the fs appendix). The rights discipline is tested only under a full-rights grant (the descent appendix).- A file written on nife reads as early 1970, since the FS server holds no clock. A write never moves a real timestamp, times are whole seconds, and the handle-shaped time calls refuse (file times).
- stdout and stderr share one endpoint, so they interleave by 16-byte chunk.
- The
std-srcpatches are string-anchored to the pinned nightly. A bump that reshapes a dispatcher fails with "anchor not found", which is the intended tripwire. - The legacy
nife-devlink stays until the maintainer removes it (above);+nife-devgets whichever lane wrote it last. - The pin names a nightly by date, not digest, and the farm never hashes the
rust-srcit patches (caveats). std-abortscoverssys/only, and proves a body reachable, never a call. A stale or foreign build understd_exerciser/target(left from before a nightly bump) surfaces as a defect or an abort, or compiles the nightly's unpatched std even withRUSTUP_TOOLCHAINset (the farm's hard-linkedrustc, since fixed, caveats). The fix isrm -rf std_exerciser/target(appendix). An exportedCARGO_TARGET_DIRused to blind the check;std-exercisernow pins and prints it.
Appendices
| appendix | what it holds |
|---|---|
| x86-64-target | the x86_64 spec field by field, and the SSE probe |
| net | std::net over the socket contract |
| fs | std::fs over the file contract, and what stays Unsupported |
| file-times | modified and set_times, with their own BUGS |
| fs-descent | nested paths, std::fs::Dir, and the write-path correction |
| caveats | the full caveat list behind BUGS above |
| std-aborts | the calls that ended a process, and the check that finds them |
| allocation | the heap under threads: a cache per thread, the allocators surveyed, the measurement |
| the-proof | what std_exerciser asserts under each grant |