nx_assert.nx
buildroot/runtime/nx_assert.nx
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
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
structs
| none |
consts
| 40 | const NX_ASSERT_EXIT: i64 = 200 |
functions
| 48 | func nx_puts_err(s: *u8) -> i64 |
| 56 | func nx_puti_err(v: i64) -> i64 |
| 86 | func nx_putx_err(v: i64) -> i64 |
| 105 | func nx_assert(cond: i64, tag: *u8) -> i64 |
| 120 | func nx_assert_ptr(p: *u8, tag: *u8) -> i64 |
| 133 | func nx_assert_lt(idx: i64, cap: i64, tag: *u8) -> i64 |
| 150 | func main() -> i64 |