P1: before the tag
An appendix to the milestone.
P1: before the first tag
-
initializeis safe, takes no state into account, and a caller can call it again after allocations. DONE (initializereturnsResult<(), WiringRefusal>, is#[must_use], refuses a second call, a misaligned base, a cap under one page and a range that overflows; every caller wraps it inuser_mode_runtime::require;a_second_initialize_changes_nothing). Finding: a second call resetscommittedto zero and sets a newbase, but leaves talc'sheap_endas it was. The nextgrowmaps pages at the new base and calls `talc::extend(end, run- bytes)
, which registers one free gap from the old heap's top to the new run's end, across the unmapped hole between them. A later allocation can be handed memory in that hole and fault. With the same base, the second call makes every laterMAPland on an already-mapped address, which the kernel refuses withBadPointerafter spending a page of the budget (the kernel's own comment; unverified by a run). No caller in the tree calls it twice. The API lets a stranger. Evidence:src/lib.rslines 100 to 107 and 188 to 193.vendor/talc/src/base/mod.rs,extend.kernel/src/system_call/memory_region.rslines 71 to 76. Change: make the second call inert and visible: returnboolorResult<(), AlreadyWired>and refuse whenheap_end.is_some()orcommitted > 0, and say "once" in the doc comment. The alternative, anunsafe fnwith the contract in# Safety`, moves the burden to every caller for nothing: the check costs one compare on a path taken once. Door: two-way until the tag (a signature change on a public method is one-way after it). Effort: XS.
- bytes)
-
growreports success for a request of zero bytes after mapping nothing, soalloccan spin. DONE (the success test is the purerun_succeeded,got > 0 && got >= need_pages; the Kani harnessa_grow_at_the_maximum_is_a_refusaland the host testa_grow_of_nothing_at_the_maximum_is_a_refusalcover it, and an allocation at the cap returns null). Finding: whenshortfallreturns 0 and the heap has hit the cap,growcomputesneed_pages = 0,want_pages = 0, maps nothing and returnsgot >= need_pages, which is0 >= 0.alloc's loop then callstry_allocateagain with the same heap and the same answer, forever. Today the case is unreachable, becauseshortfallrestates talc'srequired_chunk_sizeand talc's bin search finds any top gap at least that large (read fromtry_allocateandsize_to_bin_ceil; unverified by a proof). The doc comment at lines 211 to 212 promises the opposite failure mode ("a short grow is followed by another, which doubles, until the cap refuses"). At the cap, the code does not refuse, it succeeds vacuously. Evidence:src/lib.rslines 147 to 198 and 246 to 254. Change:growreturnsfalsewhenneed == 0, or the last line becomesgot > 0 && got >= need_pages. A host test (item 8) that drivesallocat a reached cap with a fake page source and asserts a null return, not a hang. Door: two-way. Effort: XS. -
The crate reads every nonzero kernel result as "budget spent", and some of them cost a page each time. DONE (
Refusalcarries the kernel's code; anything butOutOfMemorystops growth for good;last_refusalreads it; a spent budget is retried). Finding:growbreaks on any nonzero return with the comment "budget spent (OutOfMemory)". The kernel also returnsBadPointerfor a misaligned, non-user or already-mapped address andNotPermittedfor a slot withoutWRITE, and an already-mapped address spends a page of the region before the refusal (the kernel's comment; unverified by a run). A program whose heap band collides with another mapping therefore loses one page per failed allocation, with no way to see why, and a program with a misalignedbasefails every allocation with no diagnosis. Evidence:src/lib.rslines 166 to 178.kernel/src/system_call/memory_region.rslines 71 to 110.crates/moho_abi/src/lib.rsline 327. Change: keep the kernel's last error inInnerand stop growing for good on anything butOutOfMemory(one page lost, not one per allocation). Expose it through one accessor the README names, so a stranger's first failed boot has a number to read.initializechecksbase.is_multiple_of(PAGE_BYTES)and refuses otherwise (item 5's return type carries it). Door: two-way until the tag. Effort: S. -
The growth policy has no host test, no proof, and exists three times. DONE (the seam, 16 host tests and three Kani harnesses with falsification patches; std generates
heap_growth.rsfromsrc/growth.rs, andsecond_mountruns on the crate). Finding:[lib] test = false. The only test is the QEMU exerciser, which reports one integer (committed bytes) and asserts it is positive, page-aligned and under the cap. There is no Kani harness. The std overlay restates the policy line for line (patches/std-nife/overlay/std/src/sys/alloc/nife/heap.rs), and the host toolredoxfs_server/src/bin/second_mount.rsrestatesgrowand sizes its request assize + align + 2 * CHUNK_UNIT"asMemoryRegionHeap::allocsizes it", which is no longer howshortfallsizes it: the third copy has drifted. The mutation census of milestone 0955 (mutation testing reaches the kernel and its programs under QEMU, a diff and a slice at a time) groups this crate with two others at 346 mutants. No per-crate outcome exists on record (unverified). Evidence:Cargo.tomllines 11 to 14.system_tests/src/user/heap_tests.rs.patches/std-nife/overlay/std/src/sys/alloc/nife/heap.rslines 67 to 123.redoxfs_server/src/bin/second_mount.rslines 63 to 66 and 154 to 156.design/roadmap/0955-the-kernel-and-its-programs-are-mutated-under-qemu.mdline 37. Change: a page-source seam, asdlmalloc'sAllocator,rlsf'sFlexSourceand talc's ownSourcehave one. It istrait PageSource { fn map_page(&mut self, virtual_address: u64) -> Result<(), Error>; }andMemoryRegionHeap<S: PageSource = MemoryRegionPages>, with the system call in the default. Then add host tests (doubling from 8 pages, the cap, exactness at a power-of-two cap,reallocin place and by copy, zero-size layouts, item 5's second call, item 6's reached cap, item 7's refused address). Add Kani harnesses on the arithmetic that talc cannot be in (committednever exceedsmaximumand stays page-aligned for any sequence of grows and any failing page;growof zero isfalse;shortfalldoes not overflow for any validLayout). Each harness gets a falsification patch.cargo xtask std-srcgenerates the policy module into std as it already generates talc andallocation_cache.second_mountconsumes the crate with a host page source instead of a copy. The template'stestsandcoveragejobs then measure something. Door: two-way until the tag. The generic parameter is public API after it. Effort: M. -
The documentation does not survive a reader who has not read nife. DONE (the crate docs gloss "untyped", state the minimum cap, pin 1,575 bytes in
the_first_heap_fits_in_one_page, and name the spinlock; the README's host example compiles as a doctest). Finding: the crate says "untyped" (lines 1, 42, 94 and the module docs) and "memory region" (the crate name, the slot's name, themoho_abimodule) for one thing, and defines neither. The only example carriesignoreand never compiles. Nothing states the minimum useful cap. talc's first heap needsmin_first_heap_size::<DefaultBinning>(), 1,575 bytes on a 64-bit target by hand fromBIN_COUNT = 191(unverified by a test), plus the first chunk.commit_allunder that cap mapsrestpages, seesclaimreturnNone, and strands them withcommittedadvanced.initializeroundsmaximum_bytesdown to a page silently, so a cap of 4,095 is a cap of zero. The doc ofcommitted_bytescites "the demo workload".MemoryRegionHeapisSyncand the doc never says the lock is a spinlock or what a preempted holder costs. Evidence:src/lib.rslines 1 to 12, 24 to 29, 94 to 131, 185 to 187.vendor/talc/src/lib.rslines 58 to 66.vendor/talc/src/base/binning.rslines 115 to 119. Change: one vocabulary (the crate name's) and a one-sentence gloss of "untyped" with the term the kernel uses. Add a README with a snippet that compiles against the host page source of item 8. State the minimum cap and pin the figure with a test. Makeinitializeeither round up or refuse a cap under one page and under the minimum. Name the spinlock in the type's doc. Door: two-way. Effort: S.