nx_planescan.nx
buildroot/runtime/nx_planescan.nx
about
nx_planescan.nx -- SOVEREIGN SCALABLE PLANE ENUMERATION (the storage-foundation primitive).
THE GAP (measured 2026-07-24): seg-store planes written by nx_sqlite_rows carry NO ids-index, so a plane
is fetchable ONLY by exact key -- you cannot count, list, or search it. And the naive workaround (loop
ss_get over guessed keys) LEAKS ~O(segments) mmaps per call (ss_get returns pointers INTO each segment's
mmap and never frees them) -> ~87k maps on a 93-seg plane -> vm.max_map_count crash (filed seq750).
This is the leak-free primitive: read the manifest, map EACH segment .docs exactly ONCE, walk its records
in memory, munmap it. O(total-bytes) time, O(1) resident, ~1 mmap per segment (all freed). Record framing
= [kind:u8][klen:u32be][key][vlen:u32be][val] (ss_w32 big-endian); every offset bounded to the mapping.
Turns every plane into something you can count / search / paginate at scale. Importable (no main besides
selftest). Also the CANONICAL home of the hardened NXR1 field reader (was 3 copies; seq751).
license_tier: ORIGINAL Read-only over the plane, no hw writes (Rule 26).
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_seg_store.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 16 | const PS_MAGIC_1024: i64 = 1024 |
| 17 | const PS_MAGIC_4096: i64 = 4096 |
| 74 | const PS_OP_COUNT: i64 = 0 |
| 75 | const PS_OP_FIND: i64 = 1 |
functions
| 19 | func ps_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } |
| 20 | func ps_cat(d: *u8, o: i64, s: *u8) -> i64 { var p: i64=o; var i: i64=0; while s[i]!=(0 as u8){ d[p]=s[i]; p=p+1; i=i+1 } return p } called by 1: ps_scan |
| 21 | func ps_r32(p: *u8, o: i64) -> i64 { let a: i64=p[o]; let b: i64=p[o+1]; let c: i64=p[o+2]; let d: i64=p[o+3]; return (((((a<<8)|b)<<8)|c)<<8)|d } |
| 22 | func ps_eq(a: *u8, b: *u8) -> i64 { var i: i64=0; while 1==1 { if a[i]!=b[i] { return 0 } if a[i]==(0 as u8) { return 1 } i=i+1 } return 0 } |
| 24 | func ps_key_has_prefix(key: *u8, kl: i64, prefix: *u8) -> i64 |
| 34 | func ps_nxr1_field(rec: *u8, reclen: i64, key: *u8, out: *u8, maxout: i64) -> i64 |
| 79 | func ps_walk_seg(b: *u8, sz: i64, keyprefix: *u8, st: *i64) -> i64 |
| 127 | func ps_scan(prefix: *u8, keyprefix: *u8, st: *i64) -> i64 called by 2: ps_countps_find_field calls 6: sys_mmapps_catsys_read_filesys_map_fileps_walk_segsys_munmap |
| 163 | func ps_count(prefix: *u8, keyprefix: *u8) -> i64 |
| 171 | func ps_find_field(prefix: *u8, keyprefix: *u8, field: *u8, val: *u8, outbuf: *u8, outcap: i64, outkey: *u8) -> i64 |
| 179 | func ps_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 180 | func ps_udec(v: i64) -> i64 { let d: *u8=sys_mmap(32); var m: i64=v; var k: i64=0; if m==0{d[0]=48;k=1}; let t: *u8=sys_mmap(32); while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var o: *u8=sys_mmap(32); var i: i64=0; while i<k{o[i]=t[k-1-i];i=i+1}; sys_write(1,o,k); return 0 } |
| 182 | func ps_selftest() -> i64 |
| 230 | func main(argc: i64, argv: *i64) -> i64 |