code wiki / _hdl_build / _rc6_gate.nx

_rc6_gate.nx source

↩ module page · 86 lines · 4242 B

1// _rc6_gate.nx -- standing REGRESSION GATE for R1-T1-004 (nxasm rc=6 ctx-x-output-path class). 2// Debt-paydown, not skip: the alleged nxasm-codegen cause was dataflow-REFUTED (Doctor: outpath store 3// dominates its read) and is NON-REPRODUCIBLE from the standard sovereign fork+execve spawn (this gate's 4// POS leg, incl. the exact real elfpath nx_sov_build_run mitigates away). So instead of leaving a 5// workaround masking an unverified ghost, this gate makes the invariant CONTINUOUSLY CHECKED: 6// POS : a SOVEREIGN parent assembles ONE real .s to N real output-path strings -> ALL must rc=0 7// (if the ctx-x-path class ever returns, a real path exits 6 here and the gate goes RED). 8// NEG : the SAME .s to a genuinely-unwritable path MUST exit 6 (proves nxasm's open-failure 9// detection + the loud diagnostic stay alive -- no-false-green; if nxasm ever decoded an 10// open-fail as success the gate goes RED). 11// GREEN iff (all POS rc=0) AND (NEG rc=6). Writes a machine-matchable verdict to rc6_gate.log. 12import "nx_syscalls.nx" 13 14func rg_puts(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 } 15func rg_putn(fd: i64, v: i64) -> i64 { 16 let bb: *u8 = sys_mmap(28) 17 var m: i64 = v 18 if m < 0 { sys_write(fd, "-" as *u8, 1); m = 0 - m } 19 let t: *u8 = sys_mmap(28) 20 var k: i64 = 0 21 if m == 0 { t[0] = 48 as u8; k = 1 } 22 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 23 var i: i64 = 0 24 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 25 sys_write(fd, bb, k) 26 return 0 27} 28 29// faithful copy of nx_sov_build_run sbr_run: fork + execve + wait4 + WEXITSTATUS / 128+sig. 30func rg_run(path: *u8, argv: *i64, envp: *i64) -> i64 { 31 let pid: i64 = sys_fork() 32 if pid == 0 { 33 sys_execve(path, argv, envp) 34 sys_exit(127) 35 } 36 let st: *i64 = sys_mmap(16) as *i64 37 sys_wait4(pid, st, 0) 38 let sig: i64 = st[0] & 0x7f 39 if sig != 0 { return 128 + sig } 40 return (st[0] >> 8) & 0xff 41} 42 43func rg_try(asm_tool: *u8, spath: *u8, outpath: *u8, envp: *i64) -> i64 { 44 let aa: *i64 = sys_mmap(8 * 4) as *i64 45 aa[0] = asm_tool as i64; aa[1] = spath as i64; aa[2] = outpath as i64; aa[3] = 0 46 rg_puts(1, " out='" as *u8); rg_puts(1, outpath); rg_puts(1, "' -> rc=" as *u8) 47 let rc: i64 = rg_run(asm_tool, aa, envp) 48 rg_putn(1, rc); rg_puts(1, "\n" as *u8) 49 return rc 50} 51 52func main(argc: i64, argv: *i64) -> i64 { 53 let asm_tool: *u8 = "_offc/nxasm_x86_main.elf" as *u8 54 let spath: *u8 = "/tmp/repro_in.s" as *u8 // a REAL .s pre-built by nx_cc (see runner cmd) 55 let envp: *i64 = sys_mmap(8 * 4) as *i64 56 envp[0] = "PATH=/usr/bin:/bin" as *u8 as i64; envp[1] = 0 57 rg_puts(1, "RC6-GATE R1-T1-004: sovereign parent assembles one .s to varying output paths\n" as *u8) 58 59 // POS: real output-path strings must ALL assemble cleanly. 60 var pos_ok: i64 = 1 61 if rg_try(asm_tool, spath, "/tmp/nx_capability_ladder.sov.elf" as *u8, envp) != 0 { pos_ok = 0 } 62 if rg_try(asm_tool, spath, "_offc/nx_capability_ladder.elf" as *u8, envp) != 0 { pos_ok = 0 } 63 if rg_try(asm_tool, spath, "/tmp/_sbr_asm_out.nx_capability_ladder" as *u8, envp) != 0 { pos_ok = 0 } 64 if rg_try(asm_tool, spath, "/tmp/a.elf" as *u8, envp) != 0 { pos_ok = 0 } 65 66 // NEG/tamper: an unwritable directory MUST surface as rc=6 (open-fail detected + loud). 67 let neg_rc: i64 = rg_try(asm_tool, spath, "/nonexistent_dir_zzz_rc6/out.elf" as *u8, envp) 68 var neg_ok: i64 = 0 69 if neg_rc == 6 { neg_ok = 1 } 70 71 let ok_all: i64 = pos_ok * neg_ok 72 rg_puts(1, "RC6-GATE pos_ok=" as *u8); rg_putn(1, pos_ok) 73 rg_puts(1, " neg_rc=" as *u8); rg_putn(1, neg_rc) 74 rg_puts(1, " neg_ok=" as *u8); rg_putn(1, neg_ok); rg_puts(1, "\n" as *u8) 75 76 let lf: i64 = sys_openat_append("knowledge/status/rc6_gate.log" as *u8, 420) 77 if lf >= 0 { 78 rg_puts(lf, "RC6-GATE R1-T1-004 pos_ok=" as *u8); rg_putn(lf, pos_ok) 79 rg_puts(lf, " neg_rc=" as *u8); rg_putn(lf, neg_rc) 80 if ok_all == 1 { rg_puts(lf, " verdict=GREEN\n" as *u8) } else { rg_puts(lf, " verdict=RED\n" as *u8) } 81 sys_close(lf) 82 } 83 if ok_all == 1 { sys_exit(0) } 84 sys_exit(1) 85 return 1 86}