roadmap PARTIAL

784. Reuse what the tree wrote: which first-party code an existing library should replace

Written by the research lane lane/reuse-audit on 2026-10-04 (UTC) at base 7da1a9f29. It answers calef's question of the same day: under the §46 (thin primitives or whole subsystems) amendment, what that we already have in the tree would be a better candidate for reuse? The ruling: outside the kernel and the crates Kani proves, the default is to take or adapt existing code, and writing our own needs a recorded reason. Title and slug are drafts. Every crate the table below does not weigh is weighed in the rest of the tree.

This is a proposal, not a decision: every replacement below adds a dependency, an architect's call under §46. Items (a), (d), (e), (f2), (g) and (i) are built, on calef's approvals of httparse (2026-10-18 UTC), r-efi and pulldown-cmark (both 2026-10-20 UTC), talc and object (both 2026-10-21 UTC), and uuid (2026-10-22 UTC). Items (c1) to (c4), (f) and (h) are refused. The device_tree_blob row stays ours: ruled 2026-11-25 (UTC), nife keeps device_tree_blob, releases it on its own and stops working toward dtoolkit (1085).

Method, and what the numbers mean

Take, adapt, fork, vendor or write

Rule 6 of the codebase rules governs. For a crate we cannot take unmodified, calef's fork test and AI-submissions criterion (2026-10-22 UTC) are in take, fork, vendor or write, measured in an appendix.

The inventory, grouped by why it stays or goes

Kernel, or used by the kernel for more than shared constants, keep by default (rule 3 and the amendment's exemption). The crates: paging (2,866 lines, 36 Kani), capability, inter_process_communication, machine_discovery (5,714 lines, 16 Kani, ACPI included), pci, non_volatile_memory_express, direct_memory_access_validator. Also page_frames, generational_table, address_space_identifier, intrusive_fifo, the five loom-checked crates, the two JH7110 drivers, firmware_configuration, screen_console, compositor, measured_boot, and the kernel's own 35,186 lines.

Kani-proved and outside the kernel, keep unless a proof is no longer worth having. The crates, with lines and Kani proofs: calendar (1,089, 11), timetable (2,884, 10), globally_unique_identifier_partition_table (2,219, 9), elf (1,173, 8, also kernel), network_time_protocol (684, 7). Also glob (650, 6), capability_plan (1,248, 5), subtree_scope (384, 5), device_tree_blob (1,814, 4, also kernel; measured, reports), credential_contract (322, 3), file_system_contract (2,636, 3), package_archive (677, 2), capability_manifest_note (607, 2), nifefs (354, 2).

The ABI, a capability, or one of the 19 *_protocol crates (rule 3). The crates: every *_protocol crate, moho_abi, grant_plan (6,405), swish (3,404 plus the 3,690-line program), system_initializer (2,972), supervision_contract, hot_swap_contract. Also user_mode_runtime, system_log (1,214), the process-tools programs (ps, pgrep, pmap, top, free, vmstat, slabtop, uptime, about 1,700 together, all reading nife's own statistics ABI), login, credentialer (already takes argon2).

Not kernel, not proved, not protocol: the candidates. Surprise: the kernel lists video_terminal and line_editor as dependencies, but reads only their wire constants (video_terminal::status, line_editor::proto). Their engines are userspace code.

Ours Lines Untrusted input Tier Candidate License; build, and what blocks it Downloads, last release Advisories
http_response head parser 294 (about 70 non-test in the parser) network base httparse 1.10.1 MIT/Apache, no_std, no deps 762M, 2025-03 none
video_terminal escape parser 2,523 crate every program's output base vte 0.15.0 MIT/Apache, no_std (arrayvec, memchr) 80M, 2025-02 none
virtio + gpu_driver + keyboard_driver + virtual_io_net_transport 715 + 303 + 215 + 251 device base virtio-drivers 0.13.0 MIT, no_std 387k, 2026-03 none
user_mode_heap 272 every allocation base talc 5.1.1 MIT, no_std 2.1M, 2026-09 none (linked_list_allocator has RUSTSEC-2022-0063)
uefi_loader/src/efi.rs 307 firmware base r-efi 7.1.0 MIT/Apache/LGPL, take MIT; no_std, no deps 382M, 2026-08 none
stick_maker plist.rs 335 host OS output conveyed host program plist 1.10.1 MIT, std 74M, 2026-09 none
portable_executable 778 our own ELF host (xtask) object 0.40.0 write::pe::Writer MIT/Apache 640M, 2026-08 none
serial_console port.rs part of 3,418 none host rustix or libc termios MIT/Apache (from memory) very wide none checked
coreutils programs wc, rm, printenv, date 87 + 199 + 110 + 145 user base uutils uu_* 0.12.0 MIT, std 130k each, 2026-09 none
file_allocation_table (writer) 512 none (writes our own) base fatfs 0.3.6 MIT; std builds with no threads or async, no_std only through core_io; system_installer is a no_std program today 1.6M, 2023-01 none
documentation markdown renderer (used by mdr) 802 of 2,587 shipped docs base pulldown-cmark 0.13.4 MIT; std (lib.rs uses std::fmt), no threads, no async, deps bitflags, memchr, unicase; mdr is no_std today and could be a std program 166M, 2026-05 none
xHCI, unbuilt (milestone 242 (USB host and HID)) 0 device base rust-osdev xhci 0.9.2 MIT/Apache 107k, 2023-07, last push 2024-09 none

Ranked: trust gained per cost

  1. BUILT: http_response reads its head through httparse 1.10.1 (default features off: no_std, no allocator, no dependencies, no advisory). It serves rung 3a of milestone 198 (a package manager, and the trivial install that makes a second customer possible). Response::parse and its Partial status replace the hand-written scan and line parser. The request writer, the 2 KiB head cap, the Content-Length policy (no close-delimited body) and strict CRLF stay in the crate. The host tests and fuzz target pass unchanged. httparse's fuzzing now vouches for the grammar; the unfinished Kani harness is gone.

  2. Adapt video_terminal to vte for parsing, keeping our grid. Every program that writes to a terminal feeds this parser, so it is the widest untrusted-input surface in userspace that nothing proves. Our parser has four states on purpose: "a VT's full state machine has a dozen states". vte is that full machine (Paul Williams' DEC parser, from memory the one Alacritty ships) behind a Perform trait our grid can implement. Cost: medium; the engine is 2,523 lines and the lane must measure how much of it is parser rather than grid before claiming a number. Loss: none proved; two widely used crates (arrayvec, memchr) in the base graph.

  3. REFUSED: the virtio drivers stay nife's own, items (c1) to (c4); see the virtio drivers stay ours.

  4. BUILT: talc replaces user_mode_heap, item (d); see Follow-on.

  5. BUILT: uefi_loader binds UEFI through r-efi 7.1.0, item (e); see Follow-on.

  6. REFUSED: stick_maker's plist.rs stays, item (f); see Follow-on.

  7. BUILT: xtask reads ELF and writes PE through object 0.40.0, item (g); see Follow-on.

  8. REFUSED for base: the coreutils programs stay ours, and uutils is a basalt package candidate, item (h); see Follow-on.

  9. Editor: the tree ships none. kibi (MIT/Apache, a Rust editor inspired by kilo) needs libc termios and raw stdin, which the PAL does not bind. GNU nano is the GPL-as-package path (milestone 170 (nano: a real, full-featured screen editor)), and either arrives as an optional package without touching base.

9a. BUILT: mdr is a std program parsing with pulldown-cmark, item (f2); see Follow-on.

  1. xHCI, when milestone 242 starts: adapt rust-osdev xhci for register and TRB definitions. Write the driver logic; take the definitions. The crate is dormant (release 2023-07), so it fails the fork test and is vendored if it needs a patch, under §34 (RedoxFS is the primary filesystem, on three conditions)'s "we must patch it" trigger.

Not ranked: serial_console's port.rs could take rustix termios (host-only). DNS is surveyed separately in pull request #1638.

Needing std is not, by itself, a reason to refuse a crate

calef asked on 2026-10-04 (UTC) why std blocked reuse. It should not, for a component that runs as a userspace program. nife has its own std port, the nife-dev toolchain with a nife PAL (notes/std.md), with std::fs and std::net bound to granted capabilities and real sleep and yield, and ripgrep runs on it unmodified. The real blockers are narrower, and a refusal must name one of them:

Rechecked under this rule, reading each crate's source for threads and runtimes:

Crate Serves That component Threads, async, OS APIs Verdict
pulldown-cmark 0.13.4 mdr no_std program, could be std none unblocked: candidate 9a
fatfs 0.3.6 system_installer base no_std program none measured in an appendix, with the options; ruled 2026-10-22 (UTC) on #2580: build our own, and fatfs stays the test oracle outside the base graph
rustyline 18.0.0 line_editor engine used by the terminal service no threads; libc and nix termios blocked on the PAL, and the engine sits under the console
uutils uucore 0.12.0 coreutils base programs, could be std std::thread in test modules only; libc in its feature modules unchanged: survey which uu_* build
gptman 3.1.1 GPT proved crate not the issue unchanged: kept for its 9 Kani harnesses
hickory-resolver 0.26.3 DNS, milestone 384 (in a capability system the resolver is a grant) its own program tokio's reactor blocked by the reactor, not by std; said on pull request #1638

Running another OS's drivers unmodified

calef asked that this path be noted. Read for this proposal:

Either means a C toolchain and a large shim. Survey further only when a driver nobody has in Rust is on the customer path.

The seven questions, for the top five

  1. Considered and lost. uefi lost to r-efi (uefi is 23k lines, ours needs the bindings only). fatfs waits because system_installer is no_std and the crate has not released since 2023-01. pulldown-cmark no longer loses: needing std was the wrong test. noline, fdt and serialport lost on license (MPL-2.0, not in deny.toml). goblin, cole14's elf and object lost to our Kani-proved elf (calef, 2026-10-22 UTC; measured), and xmas-elf has RUSTSEC-2025-0018, an out-of-bounds read on a malformed ELF.
  2. What the tree already does. smoltcp is taken whole and unpatched, and argon2 and RustCrypto are ordinary dependencies; httparse, vte and r-efi fit that shape. virtio-drivers does not: it lays out its own virtqueues, which nife's confinement refuses (calef, 2026-10-24 UTC).
  3. Prior art. In the tables above.
  4. Is the premise true? Mostly; the kernel's exemption does not cover the two engines (above).
  5. Cost. Lines retired are measured above; lane time is estimated. Candidate 3's input device was measured on the crate and cost more (below); candidate 4's heap numbers are in the appendix.
  6. Reversibility. Each replacement is reversible code; adding a crate to the base graph is §46's expensive category, and each was ruled before it was built.
  7. Same cost? Yes for 1, 2, 5 and 6: at equal effort the exposed library wins on trust. Nothing here is recommended because it is less work.

Proposed milestones, one replacement each

Recorded reasons for what stays

Each component that stays has a Reuse: line ready to paste, to be conformed to the amendment's landed wording: recorded-reasons.md.

The virtio drivers stay ours

calef, 2026-10-24 (UTC): option D, refused, for (c1) to (c4). virtio-drivers assumes a driver lays out its own virtqueues; nife's kernel builds every ring itself, so no driver can aim device DMA. The options set aside, the trial and the unused numbers 947 to 950 are in an appendix.

The measured-boot SHA-256 stays ours

calef, 2026-10-22 (UTC), on #2548: "Keep our SHA-256." measured_boot keeps its hand-written SHA-256, checked against the FIPS 180-4 vectors. For it, §46's rule 3 (the kernel writes) wins over rule 4 (crypto is taken), so sha2, an ordinary dependency of cryptography_provider, stays out of the measured-boot trusted base.

Follow-on

Index row

Under the 2026-10-04 amendment to §46, taking existing code is the default outside the kernel and the crates Kani proves. This survey names which first-party code an existing library should replace, with measured candidates, licenses and advisories, and each replacement waits on its own dependency ruling.