code wiki / _hdl_build / nx_janitor_caps.nx

nx_janitor_caps.nx

buildroot/runtime/_hdl_build/nx_janitor_caps.nx

7516 B125 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic janitor
docsdependenciesstructsconstsfunctions

about

nx_janitor_caps.nx -- the JANITOR's MAGIC-NUMBER-CAP detector (the missing X-JAN rule). Finds the SILENT-TRUNCATION cap smell -- the exact bug class that just cost us a "stored-not-served" outage in the seg-store (a hardcoded 256/260-segment array that dropped 680 of 936 segments with NO error). READ-ONLY: it reports candidates; it never edits. The detector CORE lives in nx_cap_detect_lib.nx (shared with the gate); this file is the tree-WALK + report. A file is flagged ONLY when all THREE parts co-occur: (1) a FIXED-COUNT array: sys_mmap( K * <literal-N> ) -- a literal count right after a '*' (2) a FILL/INDEX bound on N: '< N' | '<= N' | '>= N' | '> N' with that SAME literal N (3) an UNBOUNDED source: sys_read( | getdents | fetch | recvfrom | ss_readall in the file Data-driven sizing (a VARIABLE after '*') is invisible to the detector -- only the bare-literal cap flags. nx_janitor_caps [scan_root] default scan_root = runtime license_tier: ORIGINAL | genealogy_id: nishi_janitor_caps_2026_07_15

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_cap_detect_lib.nx nx_janitor_caps.nx

imports: nx_syscalls.nxnx_cap_detect_lib.nx

imported by: nobody (leaf or entry point)

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

main jc_puts sys_write jc_num sys_mmap sys_write ↻ sys_mmap ↻ jc_walk sys_mmap ↻ sys_openat_rd jc_getdents jc_eq jc_join jc_isdir jc_slen jc_ends jc_slen ↻ jc_read sys_openat_rd ↻ sys_read sys_close jc_strip_noncode jc_mmap_scan jc_match_at jc_has_bound jc_lit_after jc_has_src jc_find_sub jc_match_at ↻ jc_puts ↻ jc_num ↻ sys_close ↻

structs

none

consts

16const JC_PATH_SLOT: i64 = 768 // bytes per queued directory path
17const JC_QUEUE_CAP: i64 = 16384 // max directories in the BFS queue
18const JC_DENT_BUF: i64 = 65536 // getdents64 read buffer
19const JC_FILE_CAP: i64 = 4194304 // per-.nx read buffer (reused); a >4MB .nx would truncate (named, honest)
20const JC_DT_OFF: i64 = 16 // d_reclen offset in linux_dirent64
21const JC_NAME_OFF: i64 = 19 // d_name offset in linux_dirent64

functions

23func jc_puts(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 2: jc_walkmain calls 1: sys_write
24func jc_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=(48 as u8);k=1}; while m>0{t[k]=((48+(m%10)) as u8);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
called by 2: jc_walkmain calls 2: sys_mmapsys_write
25func jc_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 2: jc_endsjc_walk
26func jc_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 }
called by 1: jc_walk
27func jc_ends(path: *u8, pl: i64, ext: *u8) -> i64
called by 1: jc_walk calls 1: jc_slen
31func jc_join(dst: *u8, dir: *u8, name: *u8) -> i64
called by 1: jc_walk
38func jc_getdents(fd: i64, buf: *u8, count: i64) -> i64 { return __syscall(SYS_GETDENTS64, fd, buf, count, 0, 0, 0) }
called by 1: jc_walk
39func jc_isdir(path: *u8, st: *u8) -> i64
called by 1: jc_walk
46func jc_read(path: *u8, buf: *u8, cap: i64) -> i64
54func jc_walk(scan_root: *u8, outs: *i64) -> i64
115func main(argc: i64, argv: *i64) -> i64