code wiki / _hdl_build / nx_watemit_ws_register.nx

nx_watemit_ws_register.nx source

↩ module page · 51 lines · 2790 B

1// nx_watemit_ws_register.nx -- file the WAT-emitter 16-ARGUMENT CAP bug into the WMS SSOT for the toolchain 2// empire (safe read-modify-write; seed NOT rerun). THE BUG (found 2026-07-02 via nx_mineworld_wasm_vet): 3// a call to a >16-param function emits only 16 operands at the call site -- silently. Native x86 is fine, so 4// every native gate passes; the WASM is INVALID: browsers reject the module at VALIDATION (the /mineworld 5// light-blue box) and the sovereign VM underflows its operand stack (VM-TRAP code=3 op=0x10). Repro: any 6// .nx fn with >16 params -> nx_compile_wat -> count operands before its `call` in the .wat. Games ship-path 7// works around it (fill_zt packs uv pairs = exactly 16 params); the ROOT fix + an emitter ARITY GATE (call-site 8// operand count == callee type param count, whole-module) belongs to E-NXC2. license_tier: ORIGINAL expect_exit: 0 9import "nx_workstream_store.nx" 10import "nx_seg_store.nx" 11import "nx_syscalls.nx" 12const K_MAGIC_262144: i64 = 262144 13 14func wer_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 15func wer_len(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 16func wer_addid(idsbuf: *u8, olenp: *i64, id: *u8) -> i64 { 17 if ws_member(idsbuf, olenp[0], id) == 1 { return 0 } 18 var o: i64 = olenp[0] 19 if o > 0 { idsbuf[o] = 9 as u8; o = o + 1 } 20 var i: i64 = 0 21 while id[i] != (0 as u8) { idsbuf[o] = id[i]; o = o + 1; i = i + 1 } 22 olenp[0] = o 23 return 1 24} 25 26func main() -> i64 { 27 let w: *i64 = ss_begin() 28 let pq: *i64 = sys_mmap(16) as *i64 29 let lq: *i64 = sys_mmap(16) as *i64 30 let idsbuf: *u8 = sys_mmap(K_MAGIC_262144) 31 let olenp: *i64 = sys_mmap(8) as *i64 32 olenp[0] = 0 33 if ws_get("ws:ids\x00" as *u8, pq, lq) == 1 { 34 let src: *u8 = pq[0] as *u8 35 let n: i64 = lq[0] 36 var i: i64 = 0 37 while i < n { idsbuf[i] = src[i]; i = i + 1 } 38 olenp[0] = n 39 } 40 wer_addid(idsbuf, olenp, "TOOLCHAIN-WAT-ARGCAP16\x00" as *u8) 41 ss_add(w, 1, "ws:ids\x00" as *u8, idsbuf, olenp[0]) 42 let rec: *u8 = "TOOLCHAIN-WAT-ARGCAP16\tE-NXC2\tQUEUED\t0\tnishi-wasm-vm-hardening-2026-07-02.md\truntime/nx_compile_wat.nx\tGAME-BROWSER-FLAGSHIP\x00" as *u8 43 ss_add(w, 1, "ws:TOOLCHAIN-WAT-ARGCAP16\x00" as *u8, rec, wer_len(rec)) 44 let segid: i64 = ws_seg_next(WS_PREFIX) 45 if ss_commit(WS_PREFIX, w, segid) != 0 { wer_w("nx_watemit_ws_register: COMMIT FAILED\n\x00" as *u8); return 1 } 46 var ver: i64 = 0 47 if ws_get("ws:TOOLCHAIN-WAT-ARGCAP16\x00" as *u8, pq, lq) == 1 { ver = 1 } 48 if ver == 1 { wer_w("nx_watemit_ws_register: TOOLCHAIN-WAT-ARGCAP16 registered (E-NXC2, QUEUED) + ws:ids updated\n\x00" as *u8); return 0 } 49 wer_w("nx_watemit_ws_register: verify FAILED\n\x00" as *u8) 50 return 1 51}