code wiki / (root) / nx_proc_gate.nx

nx_proc_gate.nx source

↩ module page · 35 lines · 1769 B

1// nx_proc_gate.nx -- gates the process primitive: fork spawns a child, wait4 reaps it, the exit code propagates. 2// Turns the fork/exec/wait axis from LIVE-proven to GATE-proven. license_tier: ORIGINAL 3import "nx_syscalls.nx" 4import "nx_gate.nx" 5import "nx_gate_verdict.nx" 6 7func main() -> i64 { 8 gw("=== nx_proc_gate: fork + wait4 (spawn + reap + exit code) ===\n" as *u8) 9 var pass: i64=0; var tot: i64=0 10 11 let pid: i64 = sys_fork() 12 if pid == 0 { sys_exit(42) } // child: exit with a known code 13 tot=tot+1; if pid > 0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 14 gw("T1 fork -> child pid>0 (pid=" as *u8); gn(pid); gw(")\n" as *u8) 15 16 let st: *i64 = sys_mmap(16) as *i64 17 let reaped: i64 = sys_wait4(pid, st, 0) 18 tot=tot+1; if reaped==pid { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 19 gw("T2 wait4 reaps the child\n" as *u8) 20 21 let code: i64 = (st[0] >> 8) & 0xff 22 tot=tot+1; if code==42 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } 23 gw("T3 child exit code == 42 (got " as *u8); gn(code); gw(")\n" as *u8) 24 25 gw("\n=== nx_proc_gate " as *u8); gn(pass); gw("/" as *u8); gn(tot); gw(" ===\n" as *u8) 26 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 27 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 28 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 29 let ctr__dry: *i64 = gv_ctr() 30 ctr__dry[0] = pass 31 ctr__dry[1] = tot 32 let rc__dry: i64 = gv_verdict("PROC-GATE" as *u8, ctr__dry, "fork spawns, wait4 reaps, exit code propagates" as *u8) 33 sys_exit(rc__dry) 34 return rc__dry 35}