nx_craft_visitors_lit_fit_t181.nx source
↩ module page · 222 lines · 14148 B
1// ORIGINAL. Private generated-page observation; never calls either publishing main.
2import "nx_craft_visitors_canonical_emit_t142.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}
76func pfg_cast_contract(ctr:*i64)->i64 {
77 let vp:*u8="buildroot/knowledge/gates/cast-material-vertex-reference-t181.glsl"
78 let fp:*u8="buildroot/knowledge/gates/cast-lit-fragment-reference-t181.glsl"
79 let bp:*u8="buildroot/knowledge/gates/skin-sun-t127-cast.txt"
80 let cp:*u8="buildroot/knowledge/gates/skin-sun-authored-t129-cast.txt"
81 let refs:i64=gsb_artifact_matches(vp,"1bd6278b2ed6ebacbb6460b872a4424b31865452d0fa2fdc286353c155323eed",8796)&gsb_artifact_matches(fp,"f0240c0ad5a5f0da89813609476e93390345bc8d19d5980182229a0c5b519f7d",19973)
82 let negatives:i64=gsb_artifact_matches(bp,"f26004e497d5c1be6a0ff74306a4fed482b9db4f039253a0128f3af0d8c8cbba",49988)&gsb_artifact_matches(cp,"6a907f759e1fe151b676c2eb3277f33906da12657b8fa699a6e37b37f3e6b60e",50168)
83 gv_check("shader reference and known-negative identities verified",refs==1&&negatives==1,ctr)
84 if refs!=1||negatives!=1 {return 0}
85 var vn:i64=0;var fn:i64=0;var bn:i64=0;var cn:i64=0
86 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)
87 let current:*u8=sys_mmap(RK_WGSL_CAP);var n:i64=0
88 let capture:i64=gsb_capture_selected(gpe_cast_path,gpe_cast_expected,gpe_cast_expected_bytes,"cast",current,RK_WGSL_CAP,&n,RK_WGSL_TMO_MS)
89 gv_check("exact selected shader producer captured for contract",capture==0&&n>0,ctr)
90 if capture!=0||n<=0 {return 0}
91 gv_check("skin texture operations lowered to WGSL sampler primitive",pfg_skin_lowered(current,n)==1,ctr)
92 var broken_n:i64=0;let broken:*u8=sys_read_file("/tmp/skin-cast-full-t138.txt",&broken_n)
93 gv_check("actual prior generic texture failure refused",(broken as i64)>0&&broken_n>0&&pfg_skin_lowered(broken,broken_n)==0,ctr)
94 if (broken as i64)>0{sys_free_file(broken,broken_n)}
95 gv_check("complete cast capture newly retained or exact prior bytes",pfg_capture_retain("/tmp/visitors-cast-lit-qualified-t181.txt",current,n)==1,ctr)
96 let pv:i64=pfg_stage_parity(current,n,v,vn,RK_CAST_GLSL_VS_BEGIN,RK_CAST_GLSL_VS_END)
97 let pf:i64=pfg_stage_parity(current,n,f,fn,RK_CAST_GLSL_FS_BEGIN,RK_CAST_GLSL_FS_END)
98 gv_check("whole generated vertex matches reviewed additive LBS reference",pv==GT_V_IDENTICAL,ctr)
99 gv_check("whole generated fragment matches additive lit candidate reference",pf==GT_V_IDENTICAL,ctr)
100 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)
101 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)
102 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)
103 let output:*u8=sys_mmap(RK_WGSL_CAP*2)
104 let emitted:i64=rk_cast_glsl(output,0,current,n)
105 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)
106 let count_at:i64=rk_find(current,n,0,"cast_glsl_rc=")
107 if count_at<0 {return 0}
108 let digit_at:i64=count_at+rk_slen("cast_glsl_rc=")
109 let saved:u8=current[digit_at]
110 current[digit_at]=57 as u8
111 let refused:i64=rk_cast_glsl(output,0,current,n)
112 gv_check("mismatched producer byte count refuses GLSL emission",refused==0&&gsb_failed==1,ctr)
113 current[digit_at]=saved;gsb_failed=0
114 sys_munmap(output,RK_WGSL_CAP*2)
115 sys_free_file(v,vn);sys_free_file(f,fn);sys_free_file(bad,bn);sys_free_file(old,cn);sys_munmap(current,RK_WGSL_CAP)
116 if pv!=GT_V_IDENTICAL||pf!=GT_V_IDENTICAL {return 0}
117 return 1
118}
119
120func pfg_catalogue_contract(ctr:*i64)->i64{
121 let oldpath:*u8=gpe_prepared_path;let oldsha:*u8=gpe_prepared_sha;let oldbytes:i64=gpe_prepared_bytes;let oldfailed:i64=gsb_failed
122 gpe_prepared_path="buildroot/knowledge/gates/prepared-catalogue-utf8-fixture-t181.json";gpe_prepared_sha="b6025fc9ea5995129fc9cf16cee362268dffcafd2e006d023f1591e70b76f650";gpe_prepared_bytes=73
123 let out:*u8=sys_mmap(GPE_OUT_CAP);gsb_failed=0;let n:i64=gpe_prepared_catalogue(out,0)
124 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)
125 gpe_prepared_sha="0000000000000000000000000000000000000000000000000000000000000000";gsb_failed=0;gpe_prepared_catalogue(out,0)
126 gv_check("catalogue identity mismatch refuses emission",gsb_failed!=0,ctr)
127 sys_munmap(out,GPE_OUT_CAP);gpe_prepared_path=oldpath;gpe_prepared_sha=oldsha;gpe_prepared_bytes=oldbytes;gsb_failed=oldfailed
128 return 1
129}
130func main(argc: i64,argv: *i64) -> i64 {
131 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 }
132 if pfg_private(argv[4] as *u8)!=1 { return 3 }
133 if ep_anchor()<0 { return 3 }
134 let ctr: *i64=gv_ctr();gv_head("PRIVATE-GENERATED-PAGE-FIT" as *u8)
135 var world_path:*u8=GSB_STAGED
136 var world_sha:*u8="6a63a26f84a4ba353da798e121a1690a89bf4cac3e59f1dd9e7babe948f33139"
137 var world_bytes:i64=1250264
138 if argc==10 {world_path=argv[7] as *u8;world_sha=argv[8] as *u8;world_bytes=pfg_extent(argv[9] as *u8)}
139 let selected:i64=gsb_select_at(world_path,world_sha,world_bytes)
140 gpe_cast_path="/volume1/homes/elderwesto/nishihost/buildroot/_build/nx_cast_lit_expanded_t181.sov.elf" as *u8
141 gpe_cast_expected="047a6265017295ba571eb5abd6db9083a96f51c298cb3150fb5851a77e1905ad" as *u8
142 gpe_cast_expected_bytes=405520
143 gpe_prepared_path="buildroot/knowledge/gates/character-lit-prepared-manifest-t181.json";gpe_prepared_sha="d57d9c571d638940667224d7739d38002f0e7c496eaae2a9cb1817ea8602195e";gpe_prepared_bytes=1153
144 gpe_eye_path="/volume1/homes/elderwesto/nishihost/buildroot/_build/nx_wgsl_eye_t138.sov.elf" as *u8
145 gpe_eye_expected="bf62b1efcc8bf8ef6864664dc3b24ce2eff7633bfc514f366505d08be854d60d" as *u8
146 gpe_eye_expected_bytes=1206958
147 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)
148 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)
149 gv_check("declared staged shader producer selected" as *u8,selected==1,ctr)
150 if selected!=1 { return 3 }
151 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)
152 pfg_catalogue_contract(ctr)
153 if pfg_cast_contract(ctr)!=1 {return 3}
154 let wasm: *u8=sys_mmap(GPE_WASM_CAP)
155 let state: *i64=sys_mmap(3*__size_of(i64)) as *i64
156 let digest: *u8=sys_mmap(GPA_SHA_HEX+1)
157 let limits: *i64=sys_mmap(WM_FIELDS*__size_of(i64)) as *i64
158 let recipes: *i64=sys_mmap(GPR_MAXW*8*8) as *i64
159 let controls: *u8=sys_mmap(CE_EV_CAP)
160 // The second full output-capacity span observes contiguous overruns in this isolated gate.
161 // It is not a general capacity fix for production gpe_ap.
162 let out: *u8=sys_mmap(GPE_OUT_CAP+GPE_OUT_CAP)
163 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 }
164 let wn: i64=pfg_read(argv[1] as *u8,wasm,state)
165 gv_check("whole plain artifact read" as *u8,wn>WM_HEADER,ctr)
166 if wn<=WM_HEADER { return 3 }
167 gpa_sha(wasm,wn,digest)
168 gv_check("plain identity equals requested SHA256" as *u8,fsx_seq(digest,argv[5] as *u8)==1,ctr)
169 if fsx_seq(digest,argv[5] as *u8)!=1 { return 3 }
170 gpe_mt_pages=0;gpe_mt_max=0;gpe_mt_sha=0 as *u8;gpe_mt_url=0 as *u8;gpe_mt_bytes=0
171 if fsx_seq(argv[2] as *u8,"-" as *u8)!=1 {
172 let twin: *u8=sys_mmap(GPE_WASM_CAP)
173 if (twin as i64)<=0 { return 3 }
174 let tn: i64=pfg_read(argv[2] as *u8,twin,state)
175 if tn<=WM_HEADER { return 3 }
176 gpa_sha(twin,tn,digest)
177 gv_check("shared identity equals requested SHA256" as *u8,fsx_seq(digest,argv[6] as *u8)==1,ctr)
178 if fsx_seq(digest,argv[6] as *u8)!=1 { return 3 }
179 let mr: i64=wmem_read(twin,tn,limits)
180 gv_check("actual shared descriptor admitted" as *u8,mr==0&&limits[2]==1&&limits[3]==1&&limits[0]>0&&limits[1]>=limits[0],ctr)
181 if mr!=0||limits[2]!=1||limits[3]!=1||limits[0]<1||limits[1]<limits[0] { return 3 }
182 gv_check("shared identity declaration accepted",gpe_mt_declare(twin,tn,0 as *u8,limits[0],limits[1])==1,ctr)
183 if gpe_mt_pages<1 {return 3}
184 sys_munmap(twin,GPE_WASM_CAP)
185 }
186 let nr: i64=gpe_recipes_load("knowledge/world_recipes.conf" as *u8,recipes)
187 if nr<1 { return 3 }
188 var row: i64=0-1;var i: i64=0;var matches: i64=0
189 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 }
190 gv_check("one actual recipe selected" as *u8,matches==1,ctr)
191 if matches!=1 { return 3 }
192 ce_evidence(recipes[row+5] as *u8,controls)
193 i=GPE_OUT_CAP
194 while i<GPE_OUT_CAP+GPE_OUT_CAP { out[i]=PFG_CANARY as u8;i=i+1 }
195 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)
196 if gpe_mt_pages>0 {
197 let declared:*u8=sys_mmap(GPE_OUT_CAP)
198 let dn:i64=gpa_declare_shared(out,n,gpe_mt_url,declared,GPE_OUT_CAP)
199 gv_check("shared runtime manifest derives from verified artifact" as *u8,dn>0&&dn<=GPE_OUT_CAP,ctr)
200 if dn<=0||dn>GPE_OUT_CAP {return 3}
201 var at:i64=0;while at<dn {out[at]=declared[at];at=at+1};n=dn
202 sys_munmap(declared,GPE_OUT_CAP)
203 }
204 var intact: i64=1;i=GPE_OUT_CAP
205 while i<GPE_OUT_CAP+GPE_OUT_CAP { if out[i]!=(PFG_CANARY as u8) { intact=0 };i=i+1 }
206 gv_check("full adjacent capacity span unchanged" as *u8,intact==1,ctr)
207 gv_check("actual returned page length fits production allocation" as *u8,n>0&&n<=GPE_OUT_CAP,ctr)
208 gv_check("shader capture owner reports success" as *u8,gsb_failed==0,ctr)
209 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)
210 gv_kv("twin_minimum_pages" as *u8,gpe_mt_pages);gv_kv("twin_maximum_pages" as *u8,gpe_mt_max)
211 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) }
212 gpa_sha(out,n,digest);gv_puts("page_sha256=" as *u8);gv_puts(digest);gv_puts("\n" as *u8)
213 let wrote: i64=fxc_create(argv[4] as *u8,out,n)
214 gv_check("private output exclusively created" as *u8,wrote==n,ctr)
215 if wrote==n {
216 let box: *i64=sys_mmap(__size_of(i64)) as *i64
217 if (box as i64)<=0 { return 3 }
218 let actual: *u8=sys_read_file(argv[4] as *u8,box)
219 gv_check("private output readback equals generated bytes" as *u8,(actual as i64)>0&&gpa_same(out,n,actual,box[0])==1,ctr)
220 }
221 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)
222}