nx_mse_scan_gate.nx source
↩ module page · 40 lines · 2610 B
1// nx_mse_scan_gate.nx -- proves mw_recv_scan (the MSE stream-sync primitive) skips an arbitrary-length pad
2// and positions the stream right after the matched pattern -- i.e. the mainstream-peer interop path (real
3// clients send random PadA/PadB before req1/VC). Uses a pipe: write [37-byte pad][20-byte pattern][10 tail],
4// scan for the pattern, then read the tail back. license_tier: ORIGINAL depends: nx_mse_wire
5import "nx_mse_wire.nx"
6import "nx_gate_verdict.nx"
7
8func sg_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
9
10func main() -> i64 {
11 sg_p("MSE-SCAN-GATE authored=organ\n" as *u8)
12 let pb: *i64 = sys_mmap(16) as *i64
13 if sys_pipe2(pb, 0) != 0 { sg_p("pipe2 FAIL verdict=RED\n" as *u8); sys_exit(1); return 1 }
14 let rfd: i64 = pb[0] & 0xFFFFFFFF // packed: read fd = low 32, write fd = high 32
15 let wfd: i64 = (pb[0] >> 32) & 0xFFFFFFFF
16 // pattern (20 bytes, distinct), a 37-byte "pad" (must NOT contain the pattern), a 10-byte tail
17 let pat: *u8 = sys_mmap(24); var i: i64=0; while i<20 { pat[i]=(0xA0 + i) as u8; i=i+1 }
18 let pad: *u8 = sys_mmap(64); i=0; while i<37 { pad[i]=(0x10 + (i%8)) as u8; i=i+1 } // 0x10..0x17 -- never 0xA0..
19 let tail: *u8 = sys_mmap(16); i=0; while i<10 { tail[i]=(0x50 + i) as u8; i=i+1 }
20 // write pad || pattern || tail into the pipe (67 bytes)
21 sys_write(wfd, pad, 37); sys_write(wfd, pat, 20); sys_write(wfd, tail, 10)
22 // scan for the pattern (allow up to 100 skip)
23 let found: i64 = mw_recv_scan(rfd, pat, 20, 100)
24 // the stream must now sit exactly at the tail
25 let got: *u8 = sys_mmap(16); let n: i64 = mw_read_n(rfd, got, 10)
26 var tail_ok: i64=1; i=0; while i<10 { if got[i]!=tail[i] { tail_ok=0; i=10 } else { i=i+1 } }
27 sys_close(rfd); sys_close(wfd)
28 sg_p(" scan_found=" as *u8); if found==1 { sg_p("1" as *u8) } else { sg_p("0" as *u8) }
29 sg_p(" tail_positioned=" as *u8); if n==10 { if tail_ok==1 { sg_p("1" as *u8) } else { sg_p("0" as *u8) } } else { sg_p("0" as *u8) }
30 sg_p("\n" as *u8)
31 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
32 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
33 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
34 let ctr__dry: *i64 = gv_ctr()
35 ctr__dry[0] = found
36 ctr__dry[1] = 1
37 let rc__dry: i64 = gv_verdict("MSE-SCAN-GATE" as *u8, ctr__dry, "skipped a 37-byte pad, matched pattern, stream at tail)" as *u8)
38 sys_exit(rc__dry)
39 return rc__dry
40}