code wiki / _hdl_build / nx_srcguard.nx

nx_srcguard.nx

buildroot/runtime/_hdl_build/nx_srcguard.nx

21569 B411 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_srcguard.nx -- CANONICAL-SOURCE REVERT DETECTOR (seq1439 sev9, the work-destroyer's last mile). THE WOUND: on 2026-07-30 canonical daemon sources were silently reverted THREE times, each revert erasing EATEN debts across three lanes with no error anywhere. seq1379 closed the two SOVEREIGN write paths (nx_fs_write compare-and-swap; nx_treepack refuse-to-backdate) and both hold -- but the third path is RAW scp/rsync over ssh, which never touches an API, so no API-side guard can ever see it. ★You cannot gate a door you do not own. What you CAN do is make the damage IMPOSSIBLE TO MISS. ★★★THE RULER IS SYMBOLS, NOT BYTES (v2, 2026-07-30 -- this organ's OWN first field failure). v1 alarmed on any byte-count DECREASE. Within a day of shipping it, it fired twice and was WRONG BOTH TIMES: once on a file sampled mid-rewrite (a truncate-then-write window read as 0 bytes, and I reported the supervisor source as annihilated when it settled to 279688), and once on a sibling's legitimate refactor of nx_hostctl.nx that removed 1294 bytes while keeping ALL 212 top-level symbols. A shrink is not a revert. Dead code gets deleted, comments get tightened, duplication gets folded -- all of that is the tree getting BETTER, and a guard that calls it destruction trains everyone to ignore the guard. What actually distinguishes a revert is that WORK DISAPPEARS: a func/const/struct that existed is GONE. So the verdict is symbol-set containment -- recorded symbols must all still be present, BY NAME. Growth is silent, refactors are silent, and only a real loss speaks. Same instrument the sibling arrived at independently in nx_treepack (REFUSED-WOULD-DROP-SYMBOLS, seq1467). HONEST LIMITATION, stated because an unstated one is a lie: this tracks symbol EXISTENCE, not symbol BODIES. Gutting a function while keeping its name is invisible here. Byte deltas are still reported (advisory) precisely so that case has a signal to be noticed by -- but it is NOT claimed as covered. WHY A STANDALONE ORGAN: measured in the incident forensics, the CASUALTIES were long-lived shared daemon sources while every NEWLY CREATED file SURVIVED every revert. A guard living inside the file it guards would be reverted with it. This one is clobber-resistant BY CONSTRUCTION. nx_srcguard record [listfile] [statefile] [symsfile] -- snapshot the watched set at a known-good state nx_srcguard check [listfile] [statefile] [symsfile] -- exit 0 clean · 4 = WORK LOST (named symbols) Data-driven (rule 11): the watched set is knowledge/registry/srcguard.list, one path per line. license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_srcguard.nx

imports: nx_syscalls.nxnx_itoa_lib.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap sg_read sys_openat_rd sys_read sys_close sg_w sys_write sys_exit sg_eq sys_openat_wr sg_line sg_stat sys_mmap ↻ sg_syms_of sg_read ↻ sg_starts sg_isid sg_emit_i nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap sys_write ↻ sg_set_has sg_eq ↻ sg_recorded sys_mmap ↻ sg_line ↻ sg_eq ↻ sys_sleep_ms sys_mmap ↻ sys_munmap ↻ sys_close ↻ sg_n nxi_out nxi_fd ↻

structs

none

consts

36const SG_AT_FDCWD: i64 = 0 - 100
37const SG_SYS_NEWFSTATAT: i64 = 262
38const SG_STATBUF: i64 = 256
39const SG_OFF_SIZE: i64 = 48
40const SG_OFF_MTIME: i64 = 88
42const SG_CAP: i64 = 65536
43const SG_PATHCAP: i64 = 512
47const SG_FCAP: i64 = 4194304
49const SG_SYMSET_CAP: i64 = 262144
51const SG_SYMSTATE_CAP: i64 = 2097152
54const SG_SETTLE_MS: i64 = 400
57const SG_NAME_CAP: i64 = 24

functions

59func sg_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 1: main calls 1: sys_write
64func sg_n(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
65func sg_eq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 }
68func sg_stat(path: *u8, outs: *i64) -> i64
called by 1: main calls 1: sys_mmap
78func sg_read(path: *u8, buf: *u8, cap: i64) -> i64
89func sg_line(buf: *u8, ls: i64, le: i64, dst: *u8, cap: i64) -> i64
called by 2: sg_recordedmain
97func sg_isid(c: i64) -> i64
called by 1: sg_syms_of
106func sg_starts(buf: *u8, i: i64, le: i64, kw: *u8) -> i64
called by 1: sg_syms_of
117func sg_set_has(set: *u8, setlen: i64, name: *u8) -> i64
called by 1: main calls 1: sg_eq
133func sg_syms_of(path: *u8, fb: *u8, out: *u8, ocap: i64, outs: *i64) -> i64
called by 1: main calls 3: sg_readsg_startssg_isid
170func sg_recorded(state: *u8, sn: i64, path: *u8, outs: *i64) -> i64
called by 1: main calls 3: sys_mmapsg_linesg_eq
205func sg_emit_i(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 1: main calls 1: nxi_fd
207func main(argc: i64, argv: *i64) -> i64