code wiki / _hdl_build / nx_doc_constscan_run.nx
nx_doc_constscan_run.nx source
↩ module page · 30 lines · 1489 B
1// nx_doc_constscan_run.nx -- Analyzes NX files for const-pointer-direct-index footguns using the LM-030 detector.
2import "nx_gate_gn.nx"
3// nx_doc_constscan_run.nx -- CLI to DOGFOOD the LM-030 const-pointer-direct-index detector on REAL files. Each arg
4// is a source path; it reports the FIRST const[i] footgun per file (or clean). No-arg = usage (build-smoke safe).
5// run: nx_doc_constscan_run.elf <file.nx> [more.nx ...]
6import "nx_syscalls.nx"
7import "nx_doc_constscan.nx"
8
9func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
10
11func main(argc: i64, argv: *i64) -> i64 {
12 if argc < 2 { gp("nx_doc_constscan_run: usage: nx_doc_constscan_run <file.nx> [more...]\n" as *u8); return 0 }
13 let name: *u8 = sys_mmap(64)
14 let pos: *i64 = sys_mmap(16) as *i64
15 var scanned: i64=0; var hits: i64=0
16 var i: i64=1
17 while i < argc {
18 let path: *u8 = argv[i] as *u8
19 let lp: *i64 = sys_mmap(16) as *i64; lp[0]=0
20 let buf: *u8 = sys_read_file(path, lp)
21 if (buf as i64)!=0 {
22 scanned=scanned+1
23 let r: i64 = cs_scan(buf, lp[0], name, pos)
24 if r >= 0 { gp(" HIT " as *u8); gp(path); gp(" @byte=" as *u8); gn(pos[0]); gp(" const `" as *u8); gp(name); gp("` indexed directly (LM-030 silent miscompile)\n" as *u8); hits=hits+1 }
25 }
26 i=i+1
27 }
28 gp("CONSTSCAN-RUN scanned=" as *u8); gn(scanned); gp(" hits=" as *u8); gn(hits); gp("\n" as *u8)
29 return 0
30}