code wiki / _hdl_build / nx_craft_save_input_gate_t21.nx
nx_craft_save_input_gate_t21.nx source
↩ module page · 26 lines · 1892 B
1import "nx_wasm_craft_journal_index_t21.nx"
2import "nx_gate_verdict.nx"
3func sg_copy(a: *u8,b: *u8,n: i64) -> i64 { var i: i64=0;while i<n { a[i]=b[i];i=i+1 };return n }
4func sg_equal(a: *u8,b: *u8,n: i64) -> i64 { var i: i64=0;while i<n { if a[i]!=b[i] { return 0 };i=i+1 };return 1 }
5func sg_refuse(base: i64,copy: *u8,n: i64) -> i64 {
6 sg_copy(copy,base as *u8,CRAFT_EXT_TOTAL)
7 return wc_save_apply_bytes(base,n)==SAVE_RC_LENGTH&&sg_equal(copy,base as *u8,CRAFT_EXT_TOTAL)==1
8}
9func main() -> i64 {
10 let arena: *u8=sys_mmap(CRAFT_EXT_TOTAL);let copy: *u8=sys_mmap(CRAFT_EXT_TOTAL)
11 if (arena as i64)<=0||(copy as i64)<=0 { return 3 }
12 let base: i64=arena as i64;let ctr: *i64=gv_ctr()
13 gv_head("SAVE INPUT LENGTH / actual engine boundary" as *u8)
14 init_impl_v(base,2,123);wc_save_build(base)
15 gv_check("negative empty and partial header refuse without any arena mutation" as *u8,sg_refuse(base,copy,0-1)&&sg_refuse(base,copy,0)&&sg_refuse(base,copy,SAVE_HDR-1),ctr)
16 gv_check("short body and oversized input refuse before stale body consumption" as *u8,sg_refuse(base,copy,SAVE_HDR)&&sg_refuse(base,copy,SAVE_LEN-1)&&sg_refuse(base,copy,SAVE_LEN+1),ctr)
17 gv_check("exact v6 remains accepted through bounded door" as *u8,wc_save_apply_bytes(base,SAVE_LEN)==0,ctr)
18 wc_save_build(base)
19 let hd: *i64=(base+O_SAVE) as *i64
20 hd[1]=SAVE_VER5;hd[11]=wc_save_ck_v5(base)
21 gv_check("v5 padded to v6 length refuses without mutation" as *u8,sg_refuse(base,copy,SAVE_LEN),ctr)
22 gv_check("exact v5 remains accepted through bounded door" as *u8,wc_save_apply_bytes(base,SAVE_HDR+SAVE_BODY_V5)==0,ctr)
23 gv_check("capacity export describes existing save reservation" as *u8,save_capacity()==SAVE_LEN,ctr)
24 sys_munmap(arena,CRAFT_EXT_TOTAL);sys_munmap(copy,CRAFT_EXT_TOTAL)
25 return gv_verdict("SAVE-INPUT-LENGTH" as *u8,ctr,"caller must bound copy before apply; legacy save_apply ABI retained" as *u8)
26}