Skip to main content

Module stack_pool

Module stack_pool 

Source
Expand description

Preemptive task stack pool (plan.md §3).

All preemptive task stacks live in one contiguous, power-of-two-aligned .task_stacks section. Stacks are carved from it at spawn time with size-aligned addresses (sizes must be powers of two), which is exactly what the CM3 MPU (per-switch current-stack region) and the RISC-V PMP (NAPOT guard bands at the low end of each stack) require.

__task_stacks_start/__task_stacks_end are part of the linker contract every board’s linker script provides (documented in docs/porting.md) — not an arch/board API call, just fixed symbol names, the same on every real target. The host test backend has no linker-provided pool at all (gated on the host-port feature, not target_arch: the distinction is “is there a real linker script”, which is unrelated to which arch a real target happens to be); there, alloc_stack always returns None and callers fall back to their own static stacks.

Functions§

alloc_stack
Allocate a size-aligned stack of size bytes from the pool, with a guard band (usually 64 bytes — see [guard_size]) at its low end (plan.md §3.2). size must be a power of two (the MPU/PMP region alignment requires it) and at least as large as the guard band.
contains
Is address addr inside the task-stack pool?
pool_bounds
Pool bounds (base, len) on embedded targets; (0, 0) on the host test backend.
release_stack
Release a stack back to the pool (plan.md §5.4 despawn/respawn). The slice is refilled with 0xAA so watermarking keeps working after the stack is reused. No-op if the slice did not come from the pool.