code wiki / (root) / nx_craft_mip_fit_t241.nx

nx_craft_mip_fit_t241.nx source

↩ module page · 254 lines · 16841 B

1// ORIGINAL. Private generated-page observation; never calls either publishing main. 2import "nx_craft_mip_emit_t241.nx" 3import "nx_estate_path.nx" 4import "nx_readcap_lib.nx" 5import "nx_wasm_memory_lib.nx" 6import "nx_gate_verdict.nx" 7import "nx_glsl_tok_lib.nx" 8const PFG_CANARY: i64 = 173 // Test poison, not a product threshold. 9func pfg_private(path: *u8) -> i64 { 10 let prefix: *u8 = "/tmp/" as *u8 11 var i: i64 = 0 12 while i<5 { if path[i]!=prefix[i] { return 0 };i=i+1 } 13 if path[i]==(0 as u8) { return 0 } 14 while path[i]!=(0 as u8) { 15 if path[i]==(47 as u8) { return 0 } 16 if path[i]==(46 as u8) { if path[i+1]==(46 as u8) { return 0 } } 17 i=i+1 18 } 19 return 1 20} 21func pfg_read(path: *u8,out: *u8,state: *i64) -> i64 { 22 let fd: i64=sys_openat_rd(path) 23 if fd<0 { return 0-1 } 24 let n: i64=rc_fill_file(fd,out,GPE_WASM_CAP,state) 25 let closed: i64=sys_close(fd) 26 if rc_complete(state)!=1||closed!=0 { return 0-1 } 27 return n 28} 29func pfg_extent(text:*u8)->i64 { 30 var value:i64=0;var i:i64=0 31 while text[i]!=(0 as u8) { 32 let c:i64=text[i] as i64 33 if c<48||c>57 {return -1} 34 let digit:i64=c-48 35 if value>(9223372036854775807-digit)/10 {return -1} 36 value=value*10+digit;i=i+1 37 } 38 if i==0||value<=0{return -1} 39 return value 40} 41// Whole-shader canonical references retain incumbent features. Fragment reference only distributes 42// the existing authored guard over its six branches and applies the separately reviewed sun correction. 43func pfg_stage_parity(buf:*u8,n:i64,reference:*u8,rn:i64,begin:*u8,end:*u8)->i64 { 44 let span:*i64=sys_mmap(16) as *i64 45 if rk_world_span(buf,n,begin,end,span)!=1 {sys_munmap(span as *u8,16);return -1} 46 let verdict:*i64=sys_mmap(GT_R_SLOTS*8) as *i64 47 let rc:i64=gt_diff_canon(reference,rn,(buf as i64+span[0]) as *u8,span[1]-span[0],verdict) 48 sys_munmap(span as *u8,16);sys_munmap(verdict as *u8,GT_R_SLOTS*8) 49 return rc 50} 51func pfg_skin_lowered(buf:*u8,n:i64)->i64 { 52 let span:*i64=sys_mmap(16) as *i64 53 if (span as i64)<=0{return 0} 54 if rk_world_span(buf,n,RK_CAST_FS_BEGIN,RK_CAST_FS_END,span)!=1{sys_munmap(span as *u8,16);return 0} 55 let text:*u8=(buf as i64+span[0]) as *u8;let bytes:i64=span[1]-span[0] 56 var valid:i64=1 57 if rk_find(text,bytes,0,"texture(")>=0{valid=0} 58 if rk_find(text,bytes,0,"textureSample(uAtl,uAtl_s,vin.vUV).a")<0{valid=0} 59 if rk_find(text,bytes,0,"textureSample(uNrm,uNrm_s,vin.vUV).a")<0{valid=0} 60 sys_munmap(span as *u8,16);return valid 61} 62 63func pfg_capture_retain(path:*u8,current:*u8,n:i64)->i64 { 64 let box:*i64=sys_mmap(8) as *i64 65 if (box as i64)<=0 {return 0} 66 let existing:*u8=sys_read_file(path,box) 67 if (existing as i64)>0 { 68 let same:i64=gpa_same(current,n,existing,box[0]) 69 sys_munmap(existing,box[0]);sys_munmap(box,8) 70 return same 71 } 72 sys_munmap(box,8) 73 if fxc_create(path,current,n)==n {return 1} 74 return 0 75} 76// Allocation extent follows the verified rk_cast_glsl serialization, not a shader byte ceiling. 77func pfg_js_extent(src:*u8,n:i64)->i64 { 78 if n<0{return -1};var total:i64=2;var i:i64=0 79 while i<n { 80 let c:i64=src[i] as i64;var step:i64=1 81 if c==13{step=0}else{if c==10||c==34||c==92{step=2}} 82 if total>9223372036854775807-step{return -1} 83 total=total+step;i=i+1 84 };return total 85} 86func pfg_glsl_extent(buf:*u8,n:i64)->i64 { 87 var vs:i64=0;var ve:i64=0;var fs:i64=0;var fe:i64=0 88 let spans:*i64=sys_mmap_try(4*__size_of(i64)) as *i64 89 if (spans as i64)<=0{return -1} 90 let valid:i64=rk_world_span(buf,n,RK_CAST_GLSL_VS_BEGIN,RK_CAST_GLSL_VS_END,spans)&rk_world_span(buf,n,RK_CAST_GLSL_FS_BEGIN,RK_CAST_GLSL_FS_END,(spans as i64+2*__size_of(i64)) as *i64) 91 vs=spans[0];ve=spans[1];fs=spans[2];fe=spans[3] 92 sys_munmap_direct(spans as *u8,4*__size_of(i64)) 93 if valid!=1{return -1} 94 let v:i64=pfg_js_extent((buf as i64+vs) as *u8,ve-vs) 95 let f:i64=pfg_js_extent((buf as i64+fs) as *u8,fe-fs) 96 if v<0||f<0||v>9223372036854775807-f{return -1} 97 var total:i64=v+f 98 // Two SHA256 hexadecimal digests and the actual consumer's literal metadata. 99 let fixed:i64=GPA_SHA_HEX+GPA_SHA_HEX+rk_slen("const MVS=")+rk_slen(";const MFS=")+rk_slen(";\nwindow.__nx_shader_identity.cast.glsl={vertex_sha256:'")+rk_slen("',fragment_sha256:'")+rk_slen("',vertex_consumer:'MVS',fragment_consumer:'MFS',association:'selected capture emitted to WebGL program inputs; actual program review pending'};window.__nx_shader_identity.cast.wgsl={vertex_sha256:window.__nx_shader_identity.cast.vertex_sha256,fragment_sha256:window.__nx_shader_identity.cast.fragment_sha256,vertex_consumer:'WGSL_CASTV',fragment_consumer:'WGSL_CASTF',association:'same selected capture emitted to WebGPU pipeline inputs; actual pipeline review pending'};\n") 100 if total>9223372036854775807-fixed{return -1};return total+fixed 101} 102func pfg_cast_contract(ctr:*i64)->i64 { 103 let vp:*u8="buildroot/knowledge/gates/cast-material-vertex-reference-t181.glsl" 104 let fp:*u8="buildroot/knowledge/gates/cast-lit-stable-fragment-reference-t181.glsl" 105 let bp:*u8="buildroot/knowledge/gates/skin-sun-t127-cast.txt" 106 let cp:*u8="buildroot/knowledge/gates/skin-sun-authored-t129-cast.txt" 107 let refs:i64=gsb_artifact_matches(vp,"1bd6278b2ed6ebacbb6460b872a4424b31865452d0fa2fdc286353c155323eed",8796)&gsb_artifact_matches(fp,"83facfce008e4aa8859a44a79ecbe690389d59959676545a6c4fc5bc40efe659",20344) 108 let negatives:i64=gsb_artifact_matches(bp,"f26004e497d5c1be6a0ff74306a4fed482b9db4f039253a0128f3af0d8c8cbba",49988)&gsb_artifact_matches(cp,"6a907f759e1fe151b676c2eb3277f33906da12657b8fa699a6e37b37f3e6b60e",50168) 109 gv_check("shader reference and known-negative identities verified",refs==1&&negatives==1,ctr) 110 if refs!=1||negatives!=1 {return 0} 111 var vn:i64=0;var fn:i64=0;var bn:i64=0;var cn:i64=0 112 let v:*u8=sys_read_file(vp,&vn);let f:*u8=sys_read_file(fp,&fn);let bad:*u8=sys_read_file(bp,&bn);let old:*u8=sys_read_file(cp,&cn) 113 let owned:*NxBufOwned=rk_owned_new() 114 if (owned as i64)<=0 {sys_free_file(v,vn);sys_free_file(f,fn);sys_free_file(bad,bn);sys_free_file(old,cn);return 0} 115 let capture:i64=gsb_capture_selected_owned(gpe_cast_path,gpe_cast_expected,gpe_cast_expected_bytes,"cast",owned,RK_WGSL_TMO_MS,0) 116 let current:*u8=owned.buf;let n:i64=owned.len 117 gv_check("exact selected shader producer captured for contract",capture==0&&n>0,ctr) 118 if capture!=0||n<=0 {rk_owned_close(owned);sys_free_file(v,vn);sys_free_file(f,fn);sys_free_file(bad,bn);sys_free_file(old,cn);return 0} 119 gv_check("skin texture operations lowered to WGSL sampler primitive",pfg_skin_lowered(current,n)==1,ctr) 120 var broken_n:i64=0;let broken:*u8=sys_read_file("/tmp/skin-cast-full-t138.txt",&broken_n) 121 gv_check("actual prior generic texture failure refused",(broken as i64)>0&&broken_n>0&&pfg_skin_lowered(broken,broken_n)==0,ctr) 122 if (broken as i64)>0{sys_free_file(broken,broken_n)} 123 gv_check("complete cast capture newly retained or exact prior bytes",pfg_capture_retain("/tmp/visitors-cast-lit-stable-qualified-t181.txt",current,n)==1,ctr) 124 let pv:i64=pfg_stage_parity(current,n,v,vn,RK_CAST_GLSL_VS_BEGIN,RK_CAST_GLSL_VS_END) 125 let pf:i64=pfg_stage_parity(current,n,f,fn,RK_CAST_GLSL_FS_BEGIN,RK_CAST_GLSL_FS_END) 126 gv_check("whole generated vertex matches reviewed additive LBS reference",pv==GT_V_IDENTICAL,ctr) 127 gv_check("whole generated fragment matches additive lit candidate reference",pf==GT_V_IDENTICAL,ctr) 128 gv_check("known b9e6 capture without authored guards is refused",pfg_stage_parity(bad,bn,f,fn,RK_CAST_GLSL_FS_BEGIN,RK_CAST_GLSL_FS_END)==GT_V_DIFFERS,ctr) 129 gv_check("known c17f capture without face relief is refused",pfg_stage_parity(old,cn,v,vn,RK_CAST_GLSL_VS_BEGIN,RK_CAST_GLSL_VS_END)==GT_V_DIFFERS,ctr) 130 gv_check("truncated shader capture cannot satisfy fragment contract",pfg_stage_parity(current,WM_HEADER,f,fn,RK_CAST_GLSL_FS_BEGIN,RK_CAST_GLSL_FS_END)==-1,ctr) 131 let output_bytes:i64=pfg_glsl_extent(current,n) 132 if output_bytes<=0{rk_owned_close(owned);sys_free_file(v,vn);sys_free_file(f,fn);sys_free_file(bad,bn);sys_free_file(old,cn);return 0} 133 let output:*u8=sys_mmap_try(output_bytes) 134 if (output as i64)<=0{rk_owned_close(owned);sys_free_file(v,vn);sys_free_file(f,fn);sys_free_file(bad,bn);sys_free_file(old,cn);return 0} 135 let emitted:i64=rk_cast_glsl(output,0,current,n) 136 gv_check("selected GLSL capture binds both actual consumer constants",emitted>0&&gsb_failed==0&&rk_find(output,emitted,0,"const MVS=")>=0&&rk_find(output,emitted,0,"const MFS=")>=0,ctr) 137 gv_check("GLSL escaped allocation equals actual emitted extent",emitted==output_bytes,ctr) 138 let count_at:i64=rk_find(current,n,0,"cast_glsl_rc=") 139 if count_at<0 {sys_munmap_direct(output,output_bytes);rk_owned_close(owned);sys_free_file(v,vn);sys_free_file(f,fn);sys_free_file(bad,bn);sys_free_file(old,cn);return 0} 140 let digit_at:i64=count_at+rk_slen("cast_glsl_rc=") 141 let saved:u8=current[digit_at] 142 current[digit_at]=57 as u8 143 let refused:i64=rk_cast_glsl(output,0,current,n) 144 gv_check("mismatched producer byte count refuses GLSL emission",refused==0&&gsb_failed==1,ctr) 145 current[digit_at]=saved;gsb_failed=0 146 sys_munmap_direct(output,output_bytes) 147 sys_free_file(v,vn);sys_free_file(f,fn);sys_free_file(bad,bn);sys_free_file(old,cn);rk_owned_close(owned) 148 if pv!=GT_V_IDENTICAL||pf!=GT_V_IDENTICAL {return 0} 149 return 1 150} 151 152func pfg_catalogue_contract(ctr:*i64)->i64{ 153 let oldpath:*u8=gpe_prepared_path;let oldsha:*u8=gpe_prepared_sha;let oldbytes:i64=gpe_prepared_bytes;let oldfailed:i64=gsb_failed 154 gpe_prepared_path="buildroot/knowledge/gates/prepared-catalogue-utf8-fixture-t181.json";gpe_prepared_sha="b6025fc9ea5995129fc9cf16cee362268dffcafd2e006d023f1591e70b76f650";gpe_prepared_bytes=73 155 let out:*u8=sys_mmap(GPE_OUT_CAP);gsb_failed=0;let n:i64=gpe_prepared_catalogue(out,0) 156 gv_check("native catalogue retains UTF8 fixture for browser decode",n>0&&gsb_failed==0&&fsx_write("/tmp/prepared-catalogue-utf8-t181.js",out,n)==n,ctr) 157 gpe_prepared_sha="0000000000000000000000000000000000000000000000000000000000000000";gsb_failed=0;gpe_prepared_catalogue(out,0) 158 gv_check("catalogue identity mismatch refuses emission",gsb_failed!=0,ctr) 159 sys_munmap(out,GPE_OUT_CAP);gpe_prepared_path=oldpath;gpe_prepared_sha=oldsha;gpe_prepared_bytes=oldbytes;gsb_failed=oldfailed 160 return 1 161} 162func main(argc: i64,argv: *i64) -> i64 { 163 if argc!=7&&argc!=10 { gv_puts("usage: private-page-fit <plain.wasm> <shared.wasm-or-dash> <recipe-key> </tmp/new-basename.html> <plain-sha256> <shared-sha256-or-dash> [world-producer-path world-sha256 world-bytes]\n" as *u8);return 3 } 164 if pfg_private(argv[4] as *u8)!=1 { return 3 } 165 if ep_anchor()<0 { return 3 } 166 let ctr: *i64=gv_ctr();gv_head("PRIVATE-GENERATED-PAGE-FIT" as *u8) 167 var world_path:*u8=GSB_STAGED 168 var world_sha:*u8="6a63a26f84a4ba353da798e121a1690a89bf4cac3e59f1dd9e7babe948f33139" 169 var world_bytes:i64=1250264 170 if argc==10 {world_path=argv[7] as *u8;world_sha=argv[8] as *u8;world_bytes=pfg_extent(argv[9] as *u8)} 171 let selected:i64=gsb_select_at(world_path,world_sha,world_bytes) 172 gpe_cast_path="/volume1/homes/elderwesto/nishihost/buildroot/_build/nx_cast_lit_stable_expanded_t181.sov.elf" as *u8 173 gpe_cast_expected="4e243b4af570aadc78655a6b4bd73acee1f840319e72a9479aa8b718c14cefd2" as *u8 174 gpe_cast_expected_bytes=407582 175 gpe_prepared_path="buildroot/knowledge/gates/character-rig-joints-prepared-manifest-t230.json";gpe_prepared_sha="64bb8bda61cab45c7a4d8ab2177fb79d69b44d254c8e93664c457cf35a2689a5";gpe_prepared_bytes=1153 176 gpe_eye_path="/volume1/homes/elderwesto/nishihost/buildroot/_build/nx_wgsl_eye_t138.sov.elf" as *u8 177 gpe_eye_expected="bf62b1efcc8bf8ef6864664dc3b24ce2eff7633bfc514f366505d08be854d60d" as *u8 178 gpe_eye_expected_bytes=1206958 179 gv_check("declared eye-only producer identity verified" as *u8,gsb_artifact_matches(gpe_eye_path,gpe_eye_expected,gpe_eye_expected_bytes)==1,ctr) 180 gv_check("declared cast-only producer identity verified" as *u8,gsb_artifact_matches(gpe_cast_path,gpe_cast_expected,gpe_cast_expected_bytes)==1,ctr) 181 gv_check("declared staged shader producer selected" as *u8,selected==1,ctr) 182 if selected!=1 { return 3 } 183 gv_puts("shader_backend_path=");gv_puts(world_path);gv_puts(" shader_backend_sha256=");gv_puts(world_sha);gv_kv("shader_backend_bytes",world_bytes) 184 pfg_catalogue_contract(ctr) 185 if pfg_cast_contract(ctr)!=1 {return 3} 186 let wasm: *u8=sys_mmap(GPE_WASM_CAP) 187 let state: *i64=sys_mmap(3*__size_of(i64)) as *i64 188 let digest: *u8=sys_mmap(GPA_SHA_HEX+1) 189 let limits: *i64=sys_mmap(WM_FIELDS*__size_of(i64)) as *i64 190 let recipes: *i64=sys_mmap(GPR_MAXW*8*8) as *i64 191 let controls: *u8=sys_mmap(CE_EV_CAP) 192 // The second full output-capacity span observes contiguous overruns in this isolated gate. 193 // It is not a general capacity fix for production gpe_ap. 194 let out: *u8=sys_mmap(GPE_OUT_CAP+GPE_OUT_CAP) 195 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 } 196 let wn: i64=pfg_read(argv[1] as *u8,wasm,state) 197 gv_check("whole plain artifact read" as *u8,wn>WM_HEADER,ctr) 198 if wn<=WM_HEADER { return 3 } 199 gpa_sha(wasm,wn,digest) 200 gv_check("plain identity equals requested SHA256" as *u8,fsx_seq(digest,argv[5] as *u8)==1,ctr) 201 if fsx_seq(digest,argv[5] as *u8)!=1 { return 3 } 202 gpe_mt_pages=0;gpe_mt_max=0;gpe_mt_sha=0 as *u8;gpe_mt_url=0 as *u8;gpe_mt_bytes=0 203 if fsx_seq(argv[2] as *u8,"-" as *u8)!=1 { 204 let twin: *u8=sys_mmap(GPE_WASM_CAP) 205 if (twin as i64)<=0 { return 3 } 206 let tn: i64=pfg_read(argv[2] as *u8,twin,state) 207 if tn<=WM_HEADER { return 3 } 208 gpa_sha(twin,tn,digest) 209 gv_check("shared identity equals requested SHA256" as *u8,fsx_seq(digest,argv[6] as *u8)==1,ctr) 210 if fsx_seq(digest,argv[6] as *u8)!=1 { return 3 } 211 let mr: i64=wmem_read(twin,tn,limits) 212 gv_check("actual shared descriptor admitted" as *u8,mr==0&&limits[2]==1&&limits[3]==1&&limits[0]>0&&limits[1]>=limits[0],ctr) 213 if mr!=0||limits[2]!=1||limits[3]!=1||limits[0]<1||limits[1]<limits[0] { return 3 } 214 gv_check("shared identity declaration accepted",gpe_mt_declare(twin,tn,0 as *u8,limits[0],limits[1])==1,ctr) 215 if gpe_mt_pages<1 {return 3} 216 sys_munmap(twin,GPE_WASM_CAP) 217 } 218 let nr: i64=gpe_recipes_load("knowledge/world_recipes.conf" as *u8,recipes) 219 if nr<1 { return 3 } 220 var row: i64=0-1;var i: i64=0;var matches: i64=0 221 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 } 222 gv_check("one actual recipe selected" as *u8,matches==1,ctr) 223 if matches!=1 { return 3 } 224 ce_evidence(recipes[row+5] as *u8,controls) 225 i=GPE_OUT_CAP 226 while i<GPE_OUT_CAP+GPE_OUT_CAP { out[i]=PFG_CANARY as u8;i=i+1 } 227 var 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) 228 if gpe_mt_pages>0 { 229 let declared:*u8=sys_mmap(GPE_OUT_CAP) 230 let dn:i64=gpa_declare_shared(out,n,gpe_mt_url,declared,GPE_OUT_CAP) 231 gv_check("shared runtime manifest derives from verified artifact" as *u8,dn>0&&dn<=GPE_OUT_CAP,ctr) 232 if dn<=0||dn>GPE_OUT_CAP {return 3} 233 var at:i64=0;while at<dn {out[at]=declared[at];at=at+1};n=dn 234 sys_munmap(declared,GPE_OUT_CAP) 235 } 236 var intact: i64=1;i=GPE_OUT_CAP 237 while i<GPE_OUT_CAP+GPE_OUT_CAP { if out[i]!=(PFG_CANARY as u8) { intact=0 };i=i+1 } 238 gv_check("full adjacent capacity span unchanged" as *u8,intact==1,ctr) 239 gv_check("actual returned page length fits production allocation" as *u8,n>0&&n<=GPE_OUT_CAP,ctr) 240 gv_check("shader capture owner reports success" as *u8,gsb_failed==0,ctr) 241 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) 242 gv_kv("twin_minimum_pages" as *u8,gpe_mt_pages);gv_kv("twin_maximum_pages" as *u8,gpe_mt_max) 243 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) } 244 gpa_sha(out,n,digest);gv_puts("page_sha256=" as *u8);gv_puts(digest);gv_puts("\n" as *u8) 245 let wrote: i64=fxc_create(argv[4] as *u8,out,n) 246 gv_check("private output exclusively created" as *u8,wrote==n,ctr) 247 if wrote==n { 248 let box: *i64=sys_mmap(__size_of(i64)) as *i64 249 if (box as i64)<=0 { return 3 } 250 let actual: *u8=sys_read_file(argv[4] as *u8,box) 251 gv_check("private output readback equals generated bytes" as *u8,(actual as i64)>0&&gpa_same(out,n,actual,box[0])==1,ctr) 252 } 253 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) 254}