Before writing any implementation, write down what must always be true about the system. These are your invariants. Then build the implementation to enforce them — not to hope they hold.

Cerberus-OS invariants (explicit, written before first line of code):

  1. The highest-priority runnable task is always executing
  2. A task in U-mode can never access memory outside its PMP regions
  3. A mutex holder's priority is always >= any waiter's priority
  4. The ready bitmap and task state are always consistent
  5. Interrupt handlers never allocate

Each invariant maps to an enforcement mechanism:

  • (1) → O(1) scheduler with priority bitmap
  • (2) → PMP configuration on every context switch
  • (3) → Priority inheritance mutex implementation
  • (4) → Atomic update of bitmap and state together
  • (5) → #[no_alloc] lint (planned, via SafetyMacro)

When the borrow checker rejects your implementation, the question is: which invariant does this design violate? In all four redesigns of the priority inheritance mutex, the borrow checker was pointing at a real inconsistency in the invariants — not a language limitation to work around.