code wiki / (root) / nx_assert.nx

nx_assert.nx

buildroot/runtime/nx_assert.nx

5507 B170 linesdepth 2pulls 2 transitivereach 128 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_assert.nx -- runtime self-check primitives. Phase 1 of the detection stack (feedback-three-disciplines.md and the bootstrap_proof debug session of 2026-04-24 shipped the first ad-hoc guards; this file factors them out so any runtime code can assert cheaply). Pattern mirrors ASAN's FAIL_FAST: if (!INVARIANT) { sys_write(2, "tag: msg\n", N); exit(200); } Exit code 200 is "assertion failed". Distinct from 0 (success), 1-127 (typed failures), 124/137/139 (qemu timeout/SIGKILL/SIGSEGV) so debug harnesses can grep for it. Tradeoffs: * Every assert is a branch + call. Negligible perf on the success path -- branch predictor pins the not-taken leg and there are zero data-dependent loads. * Error messages emitted directly via sys_write so the assert fires even when a heap allocator is the thing that broke. Later: a release-mode compile-time flag elides the checks. The release build is expected to run the check code only in debug CI / bootstrap_proof diagnostic passes.

dependencies 1 imports · 24 importers

nx_syscalls.nx nx_assert.nx memcap.nx nx_arena.nx nx_assert_fire_test.nx nx_avail_map_gate.nx nx_cert_autorenew_gate.nx nx_cert_monitor_gate.nx nx_cms_mfa_gate.nx nx_cms_session_gate.nx nx_endgame_gate.nx nx_gallery_gateway_smoke.nx

diagram shows first 10 each side; +0 more imports, +14 more importers in the complete lists below.

imports: nx_syscalls.nx

imported by: memcap.nxnx_arena.nxnx_assert_fire_test.nxnx_avail_map_gate.nxnx_cert_autorenew_gate.nxnx_cert_monitor_gate.nxnx_cms_mfa_gate.nxnx_cms_session_gate.nxnx_endgame_gate.nxnx_gallery_gateway_smoke.nxnx_health_probe_gate.nxnx_hostctl_supervise_gate.nxnx_ir.nxnx_memcap.nxnx_mfa_gate.nxnx_opaque_login_gate.nxnx_opaque_login_smoke.nxnx_restart_guard_gate.nxnx_session_ttl_gate.nxnx_site_monitor_gate.nxnx_studio_gate_smoke.nxnx_torrent_stream_gate.nxnx_zombie_audit_gate.nxprop_test.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap nx_assert sys_write nx_puts_err sys_write ↻ nx_assert_ptr sys_write ↻ nx_puts_err ↻ nx_assert_lt sys_write ↻ nx_puti_err sys_mmap ↻ sys_write ↻ nx_puts_err ↻

structs

none

consts

40const NX_ASSERT_EXIT: i64 = 200

functions

48func nx_puts_err(s: *u8) -> i64
56func nx_puti_err(v: i64) -> i64
86func nx_putx_err(v: i64) -> i64
called by 1: prop_report calls 2: sys_mmapsys_write
105func nx_assert(cond: i64, tag: *u8) -> i64
120func nx_assert_ptr(p: *u8, tag: *u8) -> i64
133func nx_assert_lt(idx: i64, cap: i64, tag: *u8) -> i64
150func main() -> i64