1084. current_cpu_contract: what an outside maintainer would fix before it leaves
Raised by a read-only review lane that met crates/current_cpu_contract as a stranger would: the
crate, every caller in the tree, the naming rules, the standalone gate and the partsfoundry/crate-workflows
template. It changes nothing; it lists what the lanes that move the crate change, and the two
one-way doors that need the architect.
The review package is notes/crate-reviews/current-cpu-contract.md,
written after this review. The review took its baseline from the crate itself,
notes/current-cpu-page.md, the sibling package
counter-frequency-contract.md, §204
(how userspace asks where a thread runs), milestone 1017 (the contract crates leave in this order)
and design/naming.md. Nothing below reopens:
- the mechanism (a per-thread read-only page, §204), the
Relaxedstore and load with the scheduler's handoff as the ordering argument, or the fixed address beside the stack; - the identity values a published program already compares:
MAGICCURRCPU1,VERSION1, andINTERFACE_ID10 in milestone 956 (the linked interfaces carry checkable versions)'s table (the values are not reopened); - the deliberate
!Sendand!SyncofCurrentCpuPage, which the sibling package records as a difference fromCounterFrequencyPage; - the two renames the page-contract family rule already settles (
design/naming/crates.md), whichhelpers/name_release.py --draft current_cpu_contractprints as pre-ruled:PAGE_BYTEStoPAGE_CONTENT_BYTESandPAGE_VAtoPAGE_VIRTUAL_ADDRESS; - the dependency on
address_space_layout, which milestone 1017 step 3 orders ahead of this crate.
Reuse: script/crate-standalone, helpers/name_release.py, helpers/lint_externalized_crates.py,
helpers/template_report_gates.py, Miri, the template's scaffold/ and sample/. No new tool.
Finding status
- 1, the manifest is nife's (P0): At the move. The license, lints,
rust-version, description, docs.rs targets and the pinnedaddress_space_layoutdependency are the crate's own (#3657); the move commit addsrepository. - 2, README and license files (P0): Done, #3657.
- 3, docs cite nife and quote the decider (P0): Done, #3657.
- 4, names that lack ratification (P0): Done, #3953.
Every public item carries a ratified
Name:block, and the tests spellvirtual_addressout. - 5,
cpu()returns an id past the bound (P1): Done, #3542. - 6,
allowance()truncates on narrow targets (P1): Done, #3565. - 7, the reader reaches its word through an integer (P1): Done, #3565.
- 8, unsafe entry points check nothing in debug builds (P1): Done, #3565.
- 9, the builder and the readers disagree on unknown (P1): Done, #3657.
- 10, nothing machine-checked (P1): Done, #3657.
- 11, a stale BUGS section (P1): Done, #3657.
- 12, the single-file constraint (P1): Done, #3953.
The README and
BUGSsentence are in #3657, and the farm refuses a copied file that names a source file the copy leaves behind. - 13,
cfg_attr(not(test), no_std)(P2): Done, #3565. - 14, the type of
CPU_OFFSET_BYTES(P2): Will not fix, ruled 2026-11-19. It staysu64. - 15, the kernel's safety comment says 16 bytes (P2): Done, #3565.
- 16, two notes that do not link (P2): Done, #3565.
- Decision A, the CPU id bound is part of the identity: Done, #3542.
- Decision B, the names: Done, #3657, ratified as built (ruled 2026-11-19).
- Review package: Done, #3782.
Goal
A stranger who finds current_cpu_contract in its own repository can tell in one screen what the
page is, who writes it, who reads it, and what each of the three words means when it is absent. The
same stranger can build and test it from the README alone, on the host and on the three bare-metal
targets, and trust that every id the reader hands back can index the array the crate tells them to
size. The repository's gates are green for the crate's own reasons.
What was checked, and how
The tools run, the sources read and what was not run are in the appendix.
Prior art
The comparison with nearby work is in the appendix.
The items
Effort: XS is under an hour for a lane, S is half a day, M is a day or two. A door is one-way when somebody outside the repository acts on it after the move (a public name, a published behavior, a layout, an identity, a dependency); everything else is two-way and the maintainer decides it.
P0: the standalone gate fails on each of these; the move cannot start
-
The manifest is nife's, not a crate's. Finding:
license.workspace = trueand[lints] workspace = trueinherit from a workspace the copy does not have. There is norust-version, nodescription, norepository, no[package.metadata.docs.rs] targets. Thepublish = falsecomment sends a reader tocrates/publish-allowlist.txt, a nife path. The package comment names the architect and a ruling by date. The dependency onaddress_space_layoutis by path. Evidence:crates/current_cpu_contract/Cargo.tomllines 1 to 21. Change: inlinelicense = "MIT OR Apache-2.0";[lints.rust]carryingunsafe_op_in_unsafe_fnandmissing_docs;rust-version = "1.88"as the family states, after one build proves it. Add a one-sentencedescription,repository, and the three bare-metal targets under[package.metadata.docs.rs]. Write apublish = falsecomment a stranger can act on ("set totrueonly in the release that publishes"). Depend onaddress_space_layoutby version once it has left. Door: two-way (the license is the family's, already ruled). Effort: S. -
The files a stranger needs are missing. Finding: no README, no
LICENSE-MIT, noLICENSE-APACHE. The sibling crates incrates/carry all three; this one carries onlyCargo.tomlandsrc/lib.rs. Evidence:ls crates/current_cpu_contract. Change: both license files with theirSPDX-License-Identifierlines, and a README with the template's required headings in its order: the title and summary,## EXAMPLES,## What is proven,## BUGS,## Minimum Rust version,## License. The README states, in the crate's own words, what the page is. It says that a kernel maps it read-only atPAGE_VIRTUAL_ADDRESSin every process and writes the CPU word at every switch-in on the destination core. It says that the reader may be stale one instruction later. It says that the three words readNonefor a frame without the magic,Nonefor a thread that never ran, andNonefor an allowance or tick of zero. It says that the page type is deliberately neitherSendnorSync. It says that the layout grows only by appending a word that reads zero where a kernel never wrote it. It says that the crate ships one source file (item 12). Door: two-way. Effort: S. -
The documentation cites what a stranger cannot open, and quotes the decider. Finding: the standalone gate counts 3 architect-name lines, 7 milestone citations, 7 section citations and 8 paths into the nife tree. The externalization lint counts 3 consumer-name hits. The crate docs name
basalt,rg,user_mode_runtime,counter_frequency_contract,clock_contract,crates/cpu_set,script/undefined-behavior-check,AGENTS.md rule 7, a pull request number andnotes/current-cpu-page.md. Two doc comments quote the decider by name (UNSCHEDULED,tick_hertz) and the crate doc'sName:block quotes the ratifying word. The docs useTCBwithout expansion. Evidence:src/lib.rslines 1 to 21, 27 to 34, 53 to 54, 75 to 77, 110 to 111, 117 to 120, 135 to 140, 259 to 265, 289 to 293, 437 to 439;Cargo.tomllines 8 to 14. Change: rewrite every doc comment in the crate's own terms. Sentences that today cite a section or a note carry the argument itself (the ordering argument is four sentences; the stale-reader caveat is one). Describe consumers by role ("the kernel", "a runtime", "a published program's standard library"), never by name. The two quotations become statements of the rule ("zero is a valid CPU id, so the unset state is not zero").TCBbecomes "thread control block" at first use, or the sentence goes. The move commit stripsName:blocks, so they need no edit here. Door: two-way. Effort: M. -
Eighteen names lack ratification, and six carry the abbreviation
va. Finding:name_release.pylists 14 public items with noName:block and 4 provisional ones; the standalone gate refuses the crate until every block readsratified. The template's abbreviation gate flagsthread_page_va,PAGE_VA, the parameterpage_vaofpublish, the parametervaofnew, and two test helpers, all for the componentva, whichdesign/naming.mdspells out everywhere.PAGE_VAandPAGE_BYTESare already pre-ruled by the page-contract family rule. Evidence:src/lib.rslines 35, 42, 51, 73, 98, 108, 115, 121, 127, 141, 149, 159, 179, 211, 228, 255, 269, 277; the gate's output. Change: the--drafttable, built and ratified. One rename lane applies those spellings in the crate, the kernel (six sites), the runtime, the fixtures, the system tests andxtask/src/farm. Ratified names get their blocks in the commit that applies them; the move commit strips them. Door: two-way before the first tag (Decision B). Effort: S for the rename lane.
P2: later
The P2 items are in the appendix.
P1: before the tag
The P1 items are in the appendix.
Decisions for the architect
Decision A, the type of CPU_OFFSET_BYTES, the public names and the review clearance have rulings,
which are the rules in force.
Decision A. The bound on CPU ids is part of this page's identity
Ruled 2026-11-12 (UTC), option A. A change to CPU_ID_BOUND re-mints MAGIC and bumps VERSION
in the same change, and the constant's documentation says so. cpu() answers None for a
published id at or past the bound. The documentation of machine_statistics_contract's re-export
states that its identity follows the same rule. Tests cover an id one below the bound (accepted)
and an id at the bound (refused).
The reason. Every program that reads this page sizes its per-CPU arrays by CPU_ID_BOUND, a
constant compiled into it, which equals the kernel's MAXIMUM_CPUS. Once the crate is in its own
repository, the kernel and a published program may pin different versions, and the page's layout
does not change when the bound does. Without the rule, a kernel with a bound of 16 writes a page a
program built for 8 accepts, and the program indexes past its array. This is the restrictive
option; loosening it later is compatible, tightening it later is not.
Prior art: Linux's rseq publishes a u32 with no bound and leaves sizing to a run-time query, so
the mistake is the reader's own. FreeBSD compiles MAXCPU into the kernel and exposes the run-time
mp_maxid (recalled, unverified).
Concrete example. A kernel with a bound of 16 publishes CPU 9 to a program built with 8. The
kernel's crate carries a new magic, the program reads None for every word, and its standard
library walks on one thread, which is the degradation the crate documents for a magic mismatch.
The published type of CPU_OFFSET_BYTES
Ruled 2026-11-19 (UTC), option A. CPU_OFFSET_BYTES is published as u64 and stays u64. The
constant exists for address arithmetic: its one caller in the tree, the x86 test program in the
kernel, adds it to PAGE_VIRTUAL_ADDRESS, also a u64, and socket_contract publishes its page
offsets as u64 too. The crate's private offsets stay usize, so a Rust reader slicing the page
writes as usize. A published constant's type is part of the API every caller compiles against,
so this is a one-way door.
Prior art. Linux's rseq user ABI describes the area as a C struct with fixed-width fields and
leaves offsets to offsetof, which yields a size_t, the C analogue of usize (from memory, not
re-read). The tree has both: socket_contract publishes u64 offsets and
domain_name_resolution_contract a usize one. Concrete example: the x86 program computes
(PAGE_VIRTUAL_ADDRESS + CPU_OFFSET_BYTES) as u32 for a 32-bit absolute load; a usize constant
would make that line (PAGE_VIRTUAL_ADDRESS + CPU_OFFSET_BYTES as u64) as u32.
The public names
Ruled 2026-11-19 (UTC), option A. Every public name stands as built. These are PAGE_CONTENT_BYTES,
PAGE_VIRTUAL_ADDRESS, thread_page_virtual_address, build_page_with, CPU_OFFSET_BYTES (the
family-wide <FIELD>_OFFSET_BYTES form), and the parameters page_virtual_address and
virtual_address. MAGIC, VERSION, INTERFACE_ID, UNSCHEDULED, CPU_ID_BOUND (kept over
MAXIMUM_CPUS, since it bounds ids and is not a count), THREAD_PAGE_SLOTS, build_page,
publish, CurrentCpuPage, new, cpu, allowance and tick_hertz keep their spellings. No
alias carries an old name. Each name follows a ruled rule: the page-contract family pattern, units
and virtual_address spelled out, and no alias for an old nife spelling. The names become permanent
at the first publish, so this is a one-way door. The Name: blocks in the crate source follow in a
later change.
Prior art. Linux's rseq calls the unscheduled state RSEQ_CPU_ID_UNINITIALIZED, and the sibling
counter_frequency_contract ratified its 13 names in one pull request with the same table. nife
differs by spelling every abbreviation out. Concrete example: a runtime's one line reads
CurrentCpuPage::new(PAGE_VIRTUAL_ADDRESS), the sibling's shape to the word.
The review clearance and the move
Ruled 2026-11-19 (UTC), option A. With the review package
written, the review of this crate is clear, and that clearance is the go to create
nifeos/current_cpu_contract and move the crate there.
No tag is part of this ruling, and nothing is published. A public repository is one-way: others see
and clone it once it exists, and nobody can withdraw its history.
Prior art. Servo moved crates it shared with others, such as url, into repositories of their own
(from memory, not re-read). nife differs by having one person clear a written review package before
the repository exists. Concrete example: counter_frequency_contract, this crate's sibling, follows
the same order of milestone 1017.
Done when
The checks are in the appendix.
BUGS
- The review's baseline is its own reading, since the review package came after it. Where the two disagree, the package wins.
- Item 6 came from reading: no 32-bit build has run. The
rust-versionof 1.88 is checked by one build of the crate on that toolchain. - The farm check of item 12 runs in nife, not in the crate's own repository, so a second source file there fails at the next pin bump rather than in the crate's own pull request.
- The template's behavior on a crate with zero harnesses was not exercised; the sibling's package left the same question open.
- The prior-art rows marked "recalled" were not read in their sources during this review.
- The review ran no mutation census and found none recorded for this crate; the first run in the crate's own repository is the first figure.
Follow-on
- Milestone 1017. The contract crates leave in its order, and this crate is ready to move. The
move commit adds item 1's
repositorykey.
Index row
An outside review of current_cpu_contract before it leaves. Four P0 items are the standalone gate's thirteen failures (manifest, files, citations, names). Eight P1 items come before the first tag, and one of them is a reader that hands back an id the consumer cannot index. Four P2 items remain. The CPU id
bound is part of the page's identity (ruled); the published type of CPU_OFFSET_BYTES stays u64 (ruled); the public names stand as built (ruled).