code wiki / (root) / nx_pabi_gate.nx

nx_pabi_gate.nx source

↩ module page · 116 lines · 8613 B

1// nx_pabi_gate.nx -- gate for the portable syscall-ABI seam (R1 kernel: one forge file op, two OSes). 2// T1 LINUX roundtrip: write "FORGE-PABI-2026" -> read back byte-exact (host kernel path). 3// T2 NISHIOS roundtrip: same op in a fresh sovereign block-VFS image -> read back byte-exact 4// (NO Linux kernel -- the NishiOS-native path via nx_vfsblock_lib). 5// T3 ★CROSS-SUBSTRATE IDENTITY: the LINUX result and the NISHIOS result are BYTE-IDENTICAL -- 6// the SAME forge-level file operation produced the SAME bytes on the host kernel AND on 7// NishiOS. This is the portability seam PROVEN: forge is no longer bound to one OS. 8// T4 NEG: read an absent path on NISHIOS -> -1 (no fabricated content). 9// license_tier: ORIGINAL expect_exit: 0 10import "nx_pabi.nx" 11import "nx_gate_verdict.nx" 12 13func pg_eq(a: *u8, an: i64, b: *u8, bn: i64) -> i64 { 14 if an != bn { return 0 } 15 var i: i64 = 0 16 while i < an { if a[i] != b[i] { return 0 } i = i + 1 } 17 return 1 18} 19 20func main(argc: i64, argv: *i64) -> i64 { 21 std_putln("PABI-GATE: one forge file op, two substrates (linux-host + nishios-vfs), byte-identical" as *u8) 22 let payload: *u8 = "FORGE-PABI-2026" as *u8 23 let plen: i64 = 15 24 let lx: *u8 = sys_mmap(4096) as *u8 25 let ns: *u8 = sys_mmap(4096) as *u8 26 var pass: i64 = 0 27 // T1 LINUX 28 let w1: i64 = pabi_write(PABI_LINUX, 0 as *u8, "/tmp/pabi_lx.bin" as *u8, payload, plen) 29 let n1: i64 = pabi_read(PABI_LINUX, 0 as *u8, "/tmp/pabi_lx.bin" as *u8, lx, 4096) 30 if w1 == 0 && pg_eq(lx, n1, payload, plen) == 1 { pass = pass + 1; std_putln("T1 PASS linux-host roundtrip byte-exact" as *u8) } 31 if w1 != 0 || pg_eq(lx, n1, payload, plen) == 0 { std_puts("T1 FAIL n=" as *u8); std_pdec(n1); std_puts("\n" as *u8) } 32 // T2 NISHIOS 33 let img: *u8 = pabi_nishios_new() 34 let w2: i64 = pabi_write(PABI_NISHIOS, img, "/pabi_ns" as *u8, payload, plen) 35 let n2: i64 = pabi_read(PABI_NISHIOS, img, "/pabi_ns" as *u8, ns, 4096) 36 if w2 == 0 && pg_eq(ns, n2, payload, plen) == 1 { pass = pass + 1; std_putln("T2 PASS nishios-vfs roundtrip byte-exact (no linux kernel)" as *u8) } 37 if w2 != 0 || pg_eq(ns, n2, payload, plen) == 0 { std_puts("T2 FAIL w=" as *u8); std_pdec(w2); std_puts(" n=" as *u8); std_pdec(n2); std_puts("\n" as *u8) } 38 // T3 CROSS-SUBSTRATE IDENTITY 39 if pg_eq(lx, n1, ns, n2) == 1 { pass = pass + 1; std_putln("T3 PASS cross-substrate byte-identical (portability seam PROVEN)" as *u8) } 40 if pg_eq(lx, n1, ns, n2) == 0 { std_putln("T3 FAIL linux != nishios bytes" as *u8) } 41 // T4 NEG absent 42 let n4: i64 = pabi_read(PABI_NISHIOS, img, "/never_written" as *u8, ns, 4096) 43 if n4 < 0 { pass = pass + 1; std_putln("T4 PASS NEG absent nishios path -> -1 (no fabricated content)" as *u8) } 44 if n4 >= 0 { std_putln("T4 FAIL absent returned content" as *u8) } 45 // T5 mkdir + exists cross-substrate (block-VFS dir model vs host FS) 46 let mkl: i64 = pabi_mkdir(PABI_LINUX, 0 as *u8, "/tmp/pabi_dir_lx" as *u8) 47 let exl: i64 = pabi_exists(PABI_LINUX, 0 as *u8, "/tmp/pabi_dir_lx" as *u8) 48 let mkn: i64 = pabi_mkdir(PABI_NISHIOS, img, "/pabi_dir_ns" as *u8) 49 let exn: i64 = pabi_exists(PABI_NISHIOS, img, "/pabi_dir_ns" as *u8) 50 // mkdir may already exist on the host from a prior run (mkl<0 tolerated); exists must be 1 on both 51 if exl == 1 && mkn == 0 && exn == 1 { pass = pass + 1; std_putln("T5 PASS mkdir+exists cross-substrate (vfs-dir == host-dir)" as *u8) } 52 if exl != 1 || mkn != 0 || exn != 1 { std_puts("T5 FAIL exl="); std_pdec(exl); std_puts(" mkn="); std_pdec(mkn); std_puts(" exn="); std_pdec(exn); std_puts("\n" as *u8) } 53 // T6 NEG exists on an absent dir -> 0 on nishios 54 let exn0: i64 = pabi_exists(PABI_NISHIOS, img, "/no_such_dir" as *u8) 55 if exn0 == 0 { pass = pass + 1; std_putln("T6 PASS NEG absent dir -> exists 0" as *u8) } 56 if exn0 != 0 { std_putln("T6 FAIL absent dir reported present" as *u8) } 57 // T7/T8/T9 EXEC backend: the judge's execute-and-get-a-verdict, both OS-native mechanisms. 58 let ex_lx: i64 = pabi_exec(PABI_LINUX, 7) // fork child -> exit(7+100)=107 59 let ex_ns: i64 = pabi_exec(PABI_NISHIOS, 7) // nxe machine code 7+100=107 (verified, in-process) 60 if ex_lx == 107 { pass = pass + 1; std_putln("T7 PASS linux exec (fork+wait4 subprocess) -> verdict 107" as *u8) } 61 if ex_lx != 107 { std_puts("T7 FAIL ex_lx="); std_pdec(ex_lx); std_puts("\n" as *u8) } 62 if ex_ns == 107 { pass = pass + 1; std_putln("T8 PASS nishios exec (nxe verified machine-code, no linux) -> verdict 107" as *u8) } 63 if ex_ns != 107 { std_puts("T8 FAIL ex_ns="); std_pdec(ex_ns); std_puts("\n" as *u8) } 64 if ex_lx == ex_ns { pass = pass + 1; std_putln("T9 PASS cross-substrate exec IDENTITY (subprocess == verified-machine-code verdict)" as *u8) } 65 if ex_lx != ex_ns { std_putln("T9 FAIL exec verdicts differ across OS" as *u8) } 66 // T10-T13 THE PORTABLE FORGE JUDGE: execute candidate -> capture output -> byte-compare, both OSes. 67 let jl: i64 = pabi_judge(PABI_LINUX, 0 as *u8, 7, "107" as *u8, 3) // produce 107, capture, matches -> GREEN 68 let jn: i64 = pabi_judge(PABI_NISHIOS, img, 7, "107" as *u8, 3) // same, via nxe + VFS -> GREEN 69 if jl == 1 { pass = pass + 1; std_putln("T10 PASS linux forge judge GREEN (execute->capture->byte-compare)" as *u8) } 70 if jl != 1 { std_puts("T10 FAIL jl="); std_pdec(jl); std_puts("\n" as *u8) } 71 if jn == 1 { pass = pass + 1; std_putln("T11 PASS nishios forge judge GREEN (no linux kernel: nxe + block-VFS)" as *u8) } 72 if jn != 1 { std_puts("T11 FAIL jn="); std_pdec(jn); std_puts("\n" as *u8) } 73 if jl == jn { pass = pass + 1; std_putln("T12 PASS cross-substrate JUDGE identity (forge exceed-lever runs on both OSes)" as *u8) } 74 if jl != jn { std_putln("T12 FAIL judge verdict differs across OS" as *u8) } 75 // T14 SPAWN a REAL external program (/bin/echo SPAWN-OK) + capture its stdout via pabi (the 76 // judge's ACTUAL fork+execve+dup3+wait4 mechanism, proven on a real ELF -- not toy in-process). 77 let av: *i64 = sys_mmap(64) as *i64 78 let ep: *i64 = sys_mmap(32) as *i64 79 av[0] = "/bin/echo" as *u8 as i64 80 av[1] = "SPAWN-OK" as *u8 as i64 81 av[2] = 0 82 ep[0] = "PATH=/usr/bin:/bin" as *u8 as i64 83 ep[1] = 0 84 let sp: i64 = pabi_spawn(PABI_LINUX, 0 as *u8, av, ep, "/tmp/pabi_spawn_out" as *u8) 85 let spb: *u8 = sys_mmap(64) as *u8 86 let spn: i64 = pabi_read(PABI_LINUX, 0 as *u8, "/tmp/pabi_spawn_out" as *u8, spb, 64) 87 // echo appends a newline -> expect "SPAWN-OK\n" (9 bytes) 88 var t14: i64 = 0 89 if sp == 0 && spn == 9 { if spb[0] == (83 as u8) && spb[7] == (75 as u8) && spb[8] == (10 as u8) { t14 = 1 } } 90 if t14 == 1 { pass = pass + 1; std_putln("T14 PASS real-ELF spawn+capture (fork+execve+dup3+wait4, the judge mechanism)" as *u8) } 91 if t14 == 0 { std_puts("T14 FAIL sp="); std_pdec(sp); std_puts(" n="); std_pdec(spn); std_puts("\n" as *u8) } 92 // T15 NEG: spawn a nonexistent program -> child execve fails -> exit 127 93 av[0] = "/nonexistent/prog" as *u8 as i64 94 av[1] = 0 95 let spn2: i64 = pabi_spawn(PABI_LINUX, 0 as *u8, av, ep, "/tmp/pabi_spawn_neg" as *u8) 96 if spn2 == 127 { pass = pass + 1; std_putln("T15 PASS NEG missing program -> exit 127 (execve-fail signalled)" as *u8) } 97 if spn2 != 127 { std_puts("T15 FAIL spn2="); std_pdec(spn2); std_puts("\n" as *u8) } 98 // T13 NEG: wrong expected -> RED (the byte-exact judge REJECTS, no fabricated GREEN). 99 // FRESH vfs image: the block-VFS is additive-only (rule 13) -> each judge run needs a clean 100 // output path (real forge truncates host temp files; the NishiOS judge uses a fresh VFS session). 101 let img2: *u8 = pabi_nishios_new() 102 let jneg: i64 = pabi_judge(PABI_NISHIOS, img2, 7, "999" as *u8, 3) 103 if jneg == 0 { pass = pass + 1; std_putln("T13 PASS NEG wrong-expected -> RED (judge rejects, cheat-proof)" as *u8) } 104 if jneg != 0 { std_puts("T13 FAIL jneg="); std_pdec(jneg); std_puts("\n" as *u8) } 105 std_puts("PABI-GATE pass=" as *u8) 106 std_pdec(pass) 107 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 108 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 109 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 110 let ctr__dry: *i64 = gv_ctr() 111 ctr__dry[0] = pass 112 ctr__dry[1] = 15 113 let rc__dry: i64 = gv_verdict("PABI-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 114 sys_exit(rc__dry) 115 return rc__dry 116}