code wiki / _hdl_build / nx_hostop_law_gate.nx

nx_hostop_law_gate.nx source

↩ module page · 40 lines · 3392 B

1// nx_hostop_law_gate.nx -- R4 PROOF: the NO-DIRECT-HOST law. Workstreams must NOT apply to the live host directly; 2// the host-apply + host-transport primitives are host-operator/hosting-internal. Call-aware (strips // comments, 3// matches symbol+'(' = real call, not a mention). File-based. license_tier: ORIGINAL expect_exit: 0 4import "nx_syscalls.nx" 5import "nx_hostop.nx" 6import "nx_runpath.nx" 7 8func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 9func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 } 10func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" " as *u8); g_w(id); g_w(": " as *u8); if ok==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) } return 0 } 11func sv_write(path: *u8, content: *u8) -> i64 { let fd: i64 = sys_openat_wr(path, 0x1a4); if fd<0 { return 0 } var n: i64=0; while content[n]!=(0 as u8){n=n+1} sys_write(fd, content, n); sys_close(fd); return 1 } 12func mkf(D: *u8, name: *u8, content: *u8) -> *u8 { let p: *u8 = sys_mmap(700); pub_join(D, name, p); sv_write(p, content); return p } 13 14func main() -> i64 { 15 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0 16 g_w("=== NX-HOSTOP-LAW GATE (no workstream applies to the live host except via the host-operator) ===\n" as *u8) 17 let wsid: *u8 = sys_mmap(64); rp_wsid(wsid); rp_ensure(wsid) 18 let D: *u8 = sys_mmap(512); rp_path(wsid, "hol" as *u8, D); __syscall(83, D as i64, 493, 0, 0, 0, 0) 19 20 let f_apply: *u8 = mkf(D, "ws_apply.nx" as *u8, "func ship(){ hostop_apply(src, host, dest) }\n" as *u8) 21 let f_tr: *u8 = mkf(D, "ws_tr.nx" as *u8, "func ship(){ nx_aw_send(host, path, bytes) }\n" as *u8) 22 let f_clean: *u8 = mkf(D, "ws_clean.nx" as *u8, "func gen(){ write_local_html() }\n" as *u8) 23 let f_comment: *u8 = mkf(D, "ws_cm.nx" as *u8, "// host deploy is via hostop_apply(...) -- do not call directly\nfunc gen(){ write_local() }\n" as *u8) 24 25 let flag_apply: i64 = hostop_audit_file(f_apply, 0) 26 let flag_tr: i64 = hostop_audit_file(f_tr, 0) 27 let clean: i64 = hostop_audit_file(f_clean, 0) 28 let cm: i64 = hostop_audit_file(f_comment, 0) 29 let op_allow: i64 = hostop_audit_file(f_apply, 1) // the host-operator itself (allowlisted) 30 31 g_w(" flagged: hostop_apply=" as *u8); g_n(flag_apply); g_w(" nx_aw_send=" as *u8); g_n(flag_tr); g_w(" clean=" as *u8); g_n((clean==0) as i64); g_w(" comment=" as *u8); g_n((cm==0) as i64); g_w(" operator_allowlisted=" as *u8); g_n((op_allow==0) as i64); g_w("\n" as *u8) 32 g_row("FLAG a workstream that calls hostop_apply / nx_aw_send directly (host bypass)" as *u8, flag_apply & flag_tr, pass) 33 g_row("CLEAN: a workstream that only generates local content (no host call)" as *u8, (clean==0) as i64, pass) 34 g_row("LIAR-KILL: a COMMENT mention is NOT a bypass (call-aware)" as *u8, (cm==0) as i64, pass) 35 g_row("the host-operator itself (allowlisted) is clean despite calling host primitives" as *u8, (op_allow==0) as i64, pass) 36 37 g_w("NX-HOSTOP-LAW rows=4 pass=" as *u8); g_n(pass[0]) 38 if pass[0]==4 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 } 39 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1 40}