code wiki / (root) / nx_budget_alloc.nx

nx_budget_alloc.nx

buildroot/runtime/nx_budget_alloc.nx

6988 B176 linesdepth 3pulls 3 transitivereach 1 importersview sourcekind librarytopic budget
docsdependenciesstructsconstsfunctions

about

nx_budget_alloc.nx -- bits-up sovereign memory-ceiling enforcement. THIS is the Nishi way to make nx_budget's ceiling claim load-bearing. NO Linux cgroups dependency. NO kernel delegation. The substrate IS the enforcement. Replaces direct sys_mmap calls from cell-resident code with nx_budget_mmap, which composes nx_budget_request + sys_mmap: 1. Reserve bytes from the cell's declared budget 2. Only if reservation succeeded, actually call sys_mmap 3. Over-ceiling -> NULL; never reaches sys_mmap 4. sys_mmap failure (rare) -> release the reservation + return NULL This pattern works IDENTICALLY on: - Linux (any version; no cgroups needed) - Windows (when nx_os_windows ships; same code) - macOS (when nx_os_darwin ships) - bare metal (when nx_os_baremetal ships) - WASM because the enforcement is in the substrate, not the host kernel. Per [[feedback-bits-up-exceed-never-match]] we never delegate enforcement to a third-party (host kernel cgroups counts as third-party; the substrate is sovereign). Distinct from nx_cgroup_v2_probe.nx which is INSPECTION-ONLY for diagnostic visibility on Linux hosts. cgroups probe tells the operator "this host CAN delegate to kernel cgroups if you want"; THIS primitive is what the substrate actually USES, and the answer is "the substrate enforces itself, never delegates." Driver cardinal (verbatim from operator 2026-05-20): "make sure we are building bits up nishi not linux or whatever" genealogy_id: cardinal_2026-05-19_cooperative_resource_arbitration + cardinal_2026-05-20_bits_up_nishi_not_linux + nx_budget_v1 lineage_id: substrate_budget_alloc_v1 nx_capability_manifest:

dependencies 2 imports · 1 importers

nx_syscalls.nx nx_budget.nx nx_budget_alloc.nx nx_budget_alloc_test.nx

imports: nx_syscalls.nxnx_budget.nx

imported by: nx_budget_alloc_test.nx

structs

none

consts

72const NX_BUDGET_ALLOC_OK: i64 = 0
73const NX_BUDGET_ALLOC_OVER: i64 = 1
74const NX_BUDGET_ALLOC_BAD_INPUT: i64 = 2
75const NX_BUDGET_ALLOC_SYSCALL_FAIL: i64 = 3
76const NX_BUDGET_ALLOC_BAD_KIND: i64 = 4
77const NX_BUDGET_ALLOC_N: i64 = 5

functions

79func nx_budget_alloc_verdict_is_valid(v: i64) -> i64
called by 1: main
89func nx_budget_mmap(budget: *NxBudget, kind: nx_int, size: nx_size) -> *u8
109func nx_budget_mmap_with_verdict(
160func nx_budget_release_logical(
called by 1: main calls 1: nx_budget_release
173func nx_budget_alloc_remaining(budget: *NxBudget, kind: nx_int) -> nx_size
called by 1: main calls 1: nx_budget_remaining