# Spec conformance — kido-alloc (2026-10-14)

Against `imports/kido.json` (role: Kido's memory allocation layer; placement: between
kido-mem discovery and kido-sched consumption; honest status: draft) and the module
interfaces (`kido-mem.h` region list, `kido-sched.h` create/init contracts).

## MET

1. **Backing store is the discovery output.** `kido_alloc_init` takes the region list
   explicitly; bare metal passes `kido_mem_regions()` (max 8, validated, overflow-loud).
   Matches kido.json placement: discovery -> allocator -> consumers.
2. **Replaces carving, not the interface.** `kido_sched_create` signature and semantics
   unchanged; the carve block is now `kido_alloc(STACK_SIZE, 16)`. The 34-check scheduler
   self-test passes against the new backing (33 original checks adapted, none weakened).
3. **Loud exhaustion.** `KIDO_ERR_NO_MEMORY` with `*out = NULL`; the scheduler maps it
   straight through. Matches the codebase's loud-failure convention.
4. **Defined loud free.** NULL / double-free / foreign pointer all return
   `KIDO_ERR_EARLY_ENV`, verified by test. No silent corruption path.
5. **Alignment contract.** Power-of-two required, raised to 16 internally, honored
   exactly (tested 1..256). Non-power-of-two and zero are loud `EARLY_ENV`.
6. **Coalescing real.** Free merges address neighbors; accounting test pins
   `total == free + waste` with waste bounded < 64 bytes (the documented C2
   alignment tradeoff, not a leak).
7. **Reservation carve-out real.** `kido_alloc_init` splits regions around a reserved
   range; 64-alloc test proves none land inside. The scheduler passes 0,0 with sched
   D2 (image bounds) documented as the pending wiring.
8. **Portable.** Zero arch assumptions; compiles hosted and ARM64-freestanding with
   `-Wall -Wextra -Werror`, zero warnings both.
9. **Tested for real.** 31-check allocator self-test, all passing — including the
   exhaustion/recovery cycle and the region-bounds churn test.
10. **Approved files respected.** `kido-boot.h/.c`, `kido-hal-arm64.h`, `kido-mem.*`,
    `kido-entry-arm64.*` untouched. Scheduler changes are confined to its own
    allocation path (P7 of this module's deliberation).

## PARTIAL

- None.

## DEFERRED (declared, loud)

1. **Virtual memory / demand paging.** Not in a first kernel; the interface does not
   assume them.
2. **Image-bounds reservation wiring.** Mechanism implemented and tested; the scheduler
   passes 0,0 until the linker script exposes image symbols (sched D2, still open).
3. **Slab fast path for hot allocations.** Deliberation D1 preserves this as a future
   optimization; first-fit is the correct general foundation.
4. **SMP locking.** Uniprocessor kernel (sched SMP law); no locking, stated.

## UNPROVEN (honest limits)

1. Bare-metal region consumption unexercised — the probe stub still fires before any
   allocator call on the QEMU path (same standing limit as the scheduler's carving).
2. Fragmentation behavior under adversarial patterns characterized only by the
   largest_free stat, not by a long-run churn test.
