code wiki / (root) / nx_craft_private_knight_fit_t25.nx

nx_craft_private_knight_fit_t25.nx source

↩ module page · 92 lines · 5331 B

1// ORIGINAL. Private generated-page observation; never calls either publishing main. 2import "nx_craft_knight_emit_t25.nx" 3import "nx_estate_path.nx" 4import "nx_readcap_lib.nx" 5import "nx_wasm_memory_lib.nx" 6import "nx_gate_verdict.nx" 7const PFG_CANARY: i64 = 173 // Test poison, not a product threshold. 8func pfg_private(path: *u8) -> i64 { 9 let prefix: *u8 = "/tmp/" as *u8 10 var i: i64 = 0 11 while i<5 { if path[i]!=prefix[i] { return 0 };i=i+1 } 12 if path[i]==(0 as u8) { return 0 } 13 while path[i]!=(0 as u8) { 14 if path[i]==(47 as u8) { return 0 } 15 if path[i]==(46 as u8) { if path[i+1]==(46 as u8) { return 0 } } 16 i=i+1 17 } 18 return 1 19} 20func pfg_read(path: *u8,out: *u8,state: *i64) -> i64 { 21 let fd: i64=sys_openat_rd(path) 22 if fd<0 { return 0-1 } 23 let n: i64=rc_fill_file(fd,out,GPE_WASM_CAP,state) 24 let closed: i64=sys_close(fd) 25 if rc_complete(state)!=1||closed!=0 { return 0-1 } 26 return n 27} 28func main(argc: i64,argv: *i64) -> i64 { 29 if argc!=7 { gv_puts("usage: private-page-fit <plain.wasm> <shared.wasm-or-dash> <recipe-key> </tmp/new-basename.html> <plain-sha256> <shared-sha256-or-dash>\n" as *u8);return 3 } 30 if pfg_private(argv[4] as *u8)!=1 { return 3 } 31 if ep_anchor()<0 { return 3 } 32 let ctr: *i64=gv_ctr();gv_head("PRIVATE-GENERATED-PAGE-FIT" as *u8) 33 let wasm: *u8=sys_mmap(GPE_WASM_CAP) 34 let state: *i64=sys_mmap(3*__size_of(i64)) as *i64 35 let digest: *u8=sys_mmap(GPA_SHA_HEX+1) 36 let limits: *i64=sys_mmap(WM_FIELDS*__size_of(i64)) as *i64 37 let recipes: *i64=sys_mmap(GPR_MAXW*8*8) as *i64 38 let controls: *u8=sys_mmap(CE_EV_CAP) 39 // The second full output-capacity span observes contiguous overruns in this isolated gate. 40 // It is not a general capacity fix for production gpe_ap. 41 let out: *u8=sys_mmap(GPE_OUT_CAP+GPE_OUT_CAP) 42 if (wasm as i64)<=0||(state as i64)<=0||(digest as i64)<=0||(limits as i64)<=0||(recipes as i64)<=0||(controls as i64)<=0||(out as i64)<=0 { return 3 } 43 let wn: i64=pfg_read(argv[1] as *u8,wasm,state) 44 gv_check("whole plain artifact read" as *u8,wn>WM_HEADER,ctr) 45 if wn<=WM_HEADER { return 3 } 46 gpa_sha(wasm,wn,digest) 47 gv_check("plain identity equals requested SHA256" as *u8,fsx_seq(digest,argv[5] as *u8)==1,ctr) 48 if fsx_seq(digest,argv[5] as *u8)!=1 { return 3 } 49 gpe_mt_pages=0;gpe_mt_max=0 50 if fsx_seq(argv[2] as *u8,"-" as *u8)!=1 { 51 let twin: *u8=sys_mmap(GPE_WASM_CAP) 52 if (twin as i64)<=0 { return 3 } 53 let tn: i64=pfg_read(argv[2] as *u8,twin,state) 54 if tn<=WM_HEADER { return 3 } 55 gpa_sha(twin,tn,digest) 56 gv_check("shared identity equals requested SHA256" as *u8,fsx_seq(digest,argv[6] as *u8)==1,ctr) 57 if fsx_seq(digest,argv[6] as *u8)!=1 { return 3 } 58 let mr: i64=wmem_read(twin,tn,limits) 59 gv_check("actual shared descriptor admitted" as *u8,mr==0&&limits[2]==1&&limits[3]==1&&limits[0]>0&&limits[1]>=limits[0],ctr) 60 if mr!=0||limits[2]!=1||limits[3]!=1||limits[0]<1||limits[1]<limits[0] { return 3 } 61 gpe_mt_pages=limits[0];gpe_mt_max=limits[1] 62 sys_munmap(twin,GPE_WASM_CAP) 63 } 64 let nr: i64=gpe_recipes_load("knowledge/world_recipes.conf" as *u8,recipes) 65 if nr<1 { return 3 } 66 var row: i64=0-1;var i: i64=0;var matches: i64=0 67 while i<nr { if fsx_seq(recipes[i*8] as *u8,argv[3] as *u8)==1 { row=i*8;matches=matches+1 };i=i+1 } 68 gv_check("one actual recipe selected" as *u8,matches==1,ctr) 69 if matches!=1 { return 3 } 70 ce_evidence(recipes[row+5] as *u8,controls) 71 i=GPE_OUT_CAP 72 while i<GPE_OUT_CAP+GPE_OUT_CAP { out[i]=PFG_CANARY as u8;i=i+1 } 73 let n: i64=gpe_build_s(wasm,wn,ce_stamp(recipes[row+4] as *u8),CE_NATIVE,controls,recipes[row+1],recipes[row+2],recipes[row+6] as *u8,out) 74 var intact: i64=1;i=GPE_OUT_CAP 75 while i<GPE_OUT_CAP+GPE_OUT_CAP { if out[i]!=(PFG_CANARY as u8) { intact=0 };i=i+1 } 76 gv_check("full adjacent capacity span unchanged" as *u8,intact==1,ctr) 77 gv_check("actual returned page length fits production allocation" as *u8,n>0&&n<=GPE_OUT_CAP,ctr) 78 gv_check("shader capture owner reports success" as *u8,gsb_failed==0,ctr) 79 gv_values_head();gv_kv("page_bytes" as *u8,n);gv_kv("output_capacity" as *u8,GPE_OUT_CAP);gv_kv("headroom_bytes" as *u8,GPE_OUT_CAP-n) 80 gv_kv("twin_minimum_pages" as *u8,gpe_mt_pages);gv_kv("twin_maximum_pages" as *u8,gpe_mt_max) 81 if intact!=1||n<=0||n>GPE_OUT_CAP||gsb_failed!=0 { return gv_verdict("PRIVATE-PAGE-FIT" as *u8,ctr,"private output refused" as *u8) } 82 gpa_sha(out,n,digest);gv_puts("page_sha256=" as *u8);gv_puts(digest);gv_puts("\n" as *u8) 83 let wrote: i64=fxc_create(argv[4] as *u8,out,n) 84 gv_check("private output exclusively created" as *u8,wrote==n,ctr) 85 if wrote==n { 86 let box: *i64=sys_mmap(__size_of(i64)) as *i64 87 if (box as i64)<=0 { return 3 } 88 let actual: *u8=sys_read_file(argv[4] as *u8,box) 89 gv_check("private output readback equals generated bytes" as *u8,(actual as i64)>0&&gpa_same(out,n,actual,box[0])==1,ctr) 90 } 91 return gv_verdict("PRIVATE-PAGE-FIT" as *u8,ctr,"private fixture only; transfer actual bytes for JS syntax; browser and visual acceptance still open" as *u8) 92}