decisions DECIDED

102. A Frame names a run of pages

Raised 2026-08-19 by milestone 29 (framebuffer, virtio-gpu, and a foreign component)'s lane, which found that the terminal font (§100's gohufont-14) cannot ship without a bigger scanout, and a bigger scanout is 469 capabilities in a sixteen-slot cspace. Decided 2026-08-20 by calef: option 1, a Frame names a run.

This decision is still unbuilt (see milestone 142's own text: "nobody is building it"), and DECISIONS §113's rename (milestone 158, 2026-08-23/24) postdates it: every Frame below is now PageFrame in the tree's current code, and cspace/CSPACE_SLOTS are now capability table/ CAPABILITY_TABLE_SLOTS. Left as originally written, period-accurate to when it was decided, the same way design/decisions/0113-*.md's own record does; a future implementer should read every identifier below through that mapping.

What is blocked: milestone 29's terminal font. The scanout grows to 800x608 (475 frames) and gohufont-14 ships on it. This decision is the prerequisite.

What is being decided

Whether Object::Frame carries a page count, so a single Frame capability names a contiguous run of physical pages rather than exactly one. frame::MAP maps the whole run; frame::REVOKE unmaps it. Existing callers pass count = 1 and get the same behavior.

Why

A DMA region is a run of pages in every dimension the hardware cares about: contiguous in physics, contiguous in the virtual address space, covered as a single range by the IOMMU domain the kernel programmed for it. Representing it as N separate capabilities is an artifact of Object::Frame's current definition, not a design choice with a reason.

This project's own principle is that a name is a claim (§39). A Frame that names one page is making the wrong claim about a run of pages. The capability should name what the hardware names.

The constraint that made it acute: CSPACE_SLOTS is 16, and the virtio-gpu driver's nine-page DMA region already fills 9 of them. An 800x608 scanout is 475 frames, and the build-time guard (DRIVER_SLOT_DMA + DMA_FRAMES <= abi::fault::FAULT_EP_SLOT) fires. Growing CSPACE_SLOTS works but doesn't fix the underlying mismatch; it buys room for the wrong representation.

What changes

The object

pub enum Object {
    // ...
    /// A contiguous run of physical pages. `count` is at least 1.
    /// A single-page frame is `Frame(phys, 1)`, and every existing caller passes 1.
    Frame(phys: u64, count: u64),
    // ...
}

The kernel constructor

pub fn frame_cap(phys: u64, count: u64, rights: Rights) -> Cap {
    Cap { object: Object::Frame(phys, count), rights }
}

Existing callers pass count: 1. grant_run passes count and grants one capability instead of N, which is the whole point: 475 capabilities, 475 system calls, and 475 mapping records collapse into one of each.

frame::MAP

invoke(cap, MAP, va, writable, untyped_slot) maps the run starting at va. The page tables come from the untyped, same as today. The mapping is recorded for revocation, one record per page. The revocation table is per-page, not per-capability, and that doesn't change. Corrected 2026-08-27: it did change. This section did not anticipate two capabilities naming overlapping runs, which §132 found is exactly what the display driver's wiring does. §132 made PageFrame::REVOKE capability-scoped: each record still exists one-per-page, but now also carries which capability's authority produced it, so revoking one capability no longer touches a mapping a different, overlapping capability made. See §132 for the full reasoning and the one imprecision it knowingly left (two capabilities sharing a base but not a length are still one record).

The signature is additive: the count lives on the capability, not in the system call arguments, so MAP's argument shape doesn't change. A caller that holds a Frame(phys, 475) calls MAP once and gets 475 pages mapped contiguously.

frame::REVOKE

invoke(cap, REVOKE, _, _, _) unmaps the run from every address space and deletes every capability to it. Same semantics, applied to the whole run. The revocation table walk is one entry per page, same as today.

What does NOT change

Surface cost

Area Cost
Object::Frame Gains a count: u64 field. The enum variant grows by 8 bytes.
frame_cap Gains a count parameter. Existing callers pass 1.
frame::MAP dispatch Loops over count, mapping each page and recording each mapping.
frame::REVOKE dispatch Loops over count, revoking each page.
grant_run Collapses to one grant_at call with one capability.
ABI No new system call, no new method, no new constant. frame::MAP and frame::REVOKE keep their opcodes; the count rides on the capability.
Kani proofs The capability crate's invariant on Object carries through; the Frame variant's equality is (phys, count) rather than phys.

What this retires

What this does NOT decide

Why not the alternatives

Grow CSPACE_SLOTS (option 2)

One number, paid in TCB size: 24 bytes a slot, so 512 slots is 12 KiB of cspace per thread against today's 384 bytes, times MAX_THREADS = 128. Also moves abi::fault::FAULT_EP_SLOT (`CSPACE_SLOTS

Buys the pixels and none of the elegance. The 475 MAP calls and 475 mapping records stay. It's brute force that doesn't fix the underlying mismatch: the capability model names one page when the hardware names a run.

aspace::MAP_INTO at spawn (option 3)

The spawner holds the client's Aspace, maps each frame into it, and deletes its own cap between iterations. One slot serves the whole run; the client holds no frame capability at all. No model change, no new method.

Works for the display driver, which has no use for delegating its own surface. But it removes the client's ability to manage its own memory, which is a step backward for the capability model, and it's still 475 kernel-side map operations. This is a valid short-term move but not the right long-term answer.

seL4's approach

seL4 retypes N frames and you hold N capabilities. Its cspaces are radix trees rather than fixed-size arrays, so N capabilities is cheap. This kernel uses fixed-size sixteen-slot cspaces for a reason (TCB size, static analysis, Kani-reachable bounds). The representation should match the container: a fixed-size cspace wants fewer, fatter capabilities, not more of them.

Sequencing

  1. This decision (§102): Object::Frame gains a count, frame::MAP and frame::REVOKE operate on the run.
  2. Milestone 29's lane: grows the scanout to 800x608, puts gohufont-14 on it, and ships the terminal font. The grant_run loop collapses to one call; the cspace fits.
  3. Retrofit: other DMA-region holders (disk driver, network driver) take Frame(phys, count) instead of N separate capabilities. This is mechanical and can land in the same lane or a follow-up.