Skip to main content

Module system

Module system 

Source
Expand description

The static face: declare the system, and the geometry is the declaration.

crate::typed made one object safe to hold — a Queue<T, N> that moves Ts and cannot be minted from an integer. This makes the whole system safe to declare. You write down the tasks and queues an application has; the macro writes the kernel’s geometry from them and hands back a struct whose fields are those tasks and queues, by name and by type.

ⓘ
rusty_rtos_kernel_core::system! {
    mod blinky use PosixDemoConfig;
    tasks { consumer: 2, producer: 2 }
    queues { data: u16; 10 }
}

§What that buys, and why each part of it is a compile-time thing

Exact .bss by construction. The geometry const generics — TASKS, ITEMS, LISTS, QUEUES, SLOTS — are computed from the declaration rather than picked by hand and rounded up. SLOTS is the sum of the declared queue lengths, not a guess; TASKS is what you declared plus the two the kernel makes for itself. A kernel sized this way holds exactly the system and nothing else, and blinky::Kernel::<..>::SIZE is a number you can put in a footprint table rather than an allowance you hope covers it.

No create-failure path an application can reach. Every way queue_create and create_task can answer Err is eliminated before the program runs:

how a create failswhy it cannot here
the task arena is fullTASKS is the declared count plus the kernel’s two
the queue arena is fullQUEUES is the declared count
the item slots are exhaustedSLOTS is the sum of the declared lengths
a list is missingLISTS is lists_for over the same numbers
the priority is out of rangea const assertion per task, so it is a compile error

[System::build] still answers Result, because the kernel calls it makes do and this crate may not panic — but the Err arm is now unreachable by construction rather than merely unlikely, and the table above says which construction makes each one unreachable. That is the difference between a runtime check and a proof, and it is the whole point of the exercise.

The handles never enter the application. build is the only place that touches a create call, and it happens once, at startup. Afterwards the application holds system.data — a Queue<u16, 10> — and there is no constructor anywhere that invents one from an integer. That is what makes the four Kani harnesses that pass a symbolic handle into a kernel call unwritable against this face: the state they explore has no way to come into being (docs/LEDGER.md, “The topology work, measured”).