code wiki / (root) / nx_arena_scope.nx

nx_arena_scope.nx

buildroot/runtime/nx_arena_scope.nx

6778 B186 linesdepth 1pulls 1 transitivereach 1 importersview sourcekind librarytopic arena
docsdependenciesstructsconstsfunctions

about

nx_arena_scope.nx -- mark/reset-to-mark wrapper for nx_arena. First substrate primitive shipped under NISHI_PREEMPTIVE_BUG_ ABSORPTION.md. Closes the arena-daemon-memory-growth issue named in NISHI_HONEST_TRADE_OFFS.md section 2. Why this primitive exists: nx_arena already ships full-reset via nx_arena_reset(a). That's sufficient for batch programs (parse pass + reset at end of pass). Long-running daemons (the IoT hub, the video-call server, the browser tab) need SCOPED reset -- a tick of the loop should release everything allocated DURING the tick, but preserve the daemon's long-lived state. Scope pattern (replaces full-reset for nested workloads): let mark: i64 = nx_arena_mark(arena) do_work(arena, ...) // many arena_allocs nx_arena_reset_to_mark(arena, mark) // rewinds to mark Reset-to-mark is O(1) (just rewinds the bump pointer). Caller's stack-discipline determines nesting depth. Sealed-enum verdict for the ceiling-aware variant: NX_ARENA_OK allocation succeeded NX_ARENA_OOM_CEILING refused because would exceed ceiling NX_ARENA_OOM_CAP refused because would exceed arena cap NX_ARENA_BAD_MARK reset-to-mark called with invalid mark NX_ARENA_BAD_ARG null pointer / negative size nx_capability_claims: needs: [pointer_arithmetic] provides: [arena_mark, arena_reset_to_mark, arena_ceiling_check] safety: [no_unchecked_deref, no_floating_point, no_syscall, bit_equal_reproducible, kind_isolated] verdict: [sealed_enum_5_state, no_silent_failure] license: ORIGINAL kind: racing_crew_specialist sss: [S0, S6, S7] (closes arena issue in SSS table row 1)

dependencies 1 imports · 1 importers

nx_arena_types.nx nx_arena_scope.nx nx_arena_scope_test.nx

imports: nx_arena_types.nx

imported by: nx_arena_scope_test.nx

structs

none

consts

58const NX_ARENA_OK: i64 = 0
59const NX_ARENA_OOM_CEILING: i64 = 1
60const NX_ARENA_OOM_CAP: i64 = 2
61const NX_ARENA_BAD_MARK: i64 = 3
62const NX_ARENA_BAD_ARG: i64 = 4
63const NX_ARENA_N: i64 = 5

functions

65func nx_arena_verdict_is_valid(v: i64) -> i64
called by 1: main
78func nx_arena_mark(a: *NxArena) -> i64
called by 1: main
87func nx_arena_reset_to_mark(a: *NxArena, mark: i64,
called by 1: main
124func nx_arena_alloc_under_ceiling(a: *NxArena, n: i64, align: i64,
164func nx_arena_would_fit(a: *NxArena, n: i64, align: i64,
called by 1: main calls 1: nx_arena_align_up
183func nx_arena_headroom_bytes(a: *NxArena) -> i64
called by 1: main