nx_craft_rigview_workbench_fit_t342.nx source
↩ module page · 263 lines · 17690 B
1// ORIGINAL. Private generated-page observation; never calls either publishing main.
2import "nx_craft_rigview_workbench_emit_t342.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,fp:*u8,fragment_sha:*u8,fragment_bytes:i64,retained_capture:*u8)->i64 {
103 let vp:*u8="buildroot/knowledge/gates/cast-static-canonical-t335.vert.glsl"
104 let bp:*u8="buildroot/knowledge/gates/skin-sun-t127-cast.txt"
105 let cp:*u8="buildroot/knowledge/gates/skin-sun-authored-t129-cast.txt"
106 let refs:i64=gsb_artifact_matches(vp,"df476514afb6c66fcd18ba1418fdc6b14e67742759d2ee1db0efe0b7542339de",10197)&gsb_artifact_matches(fp,fragment_sha,fragment_bytes)
107 let negatives:i64=gsb_artifact_matches(bp,"f26004e497d5c1be6a0ff74306a4fed482b9db4f039253a0128f3af0d8c8cbba",49988)&gsb_artifact_matches(cp,"6a907f759e1fe151b676c2eb3277f33906da12657b8fa699a6e37b37f3e6b60e",50168)
108 gv_check("shader reference and known-negative identities verified",refs==1&&negatives==1,ctr)
109 if refs!=1||negatives!=1 {return 0}
110 var vn:i64=0;var fn:i64=0;var bn:i64=0;var cn:i64=0
111 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)
112 let owned:*NxBufOwned=rk_owned_new()
113 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}
114 let capture:i64=gsb_capture_selected_owned(gpe_cast_path,gpe_cast_expected,gpe_cast_expected_bytes,"cast",owned,RK_WGSL_TMO_MS,0)
115 let current:*u8=owned.buf;let n:i64=owned.len
116 gv_check("exact selected shader producer captured for contract",capture==0&&n>0,ctr)
117 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}
118 gv_check("skin texture operations lowered to WGSL sampler primitive",pfg_skin_lowered(current,n)==1,ctr)
119 var broken_n:i64=0;let broken:*u8=sys_read_file("/tmp/skin-cast-full-t138.txt",&broken_n)
120 gv_check("actual prior generic texture failure refused",(broken as i64)>0&&broken_n>0&&pfg_skin_lowered(broken,broken_n)==0,ctr)
121 if (broken as i64)>0{sys_free_file(broken,broken_n)}
122 gv_check("complete cast capture newly retained or exact prior bytes",pfg_capture_retain(retained_capture,current,n)==1,ctr)
123 let pv:i64=pfg_stage_parity(current,n,v,vn,RK_CAST_GLSL_VS_BEGIN,RK_CAST_GLSL_VS_END)
124 let pf:i64=pfg_stage_parity(current,n,f,fn,RK_CAST_GLSL_FS_BEGIN,RK_CAST_GLSL_FS_END)
125 gv_check("whole generated vertex matches reviewed static and LBS reference",pv==GT_V_IDENTICAL,ctr)
126 gv_check("whole generated fragment matches additive lit candidate reference",pf==GT_V_IDENTICAL,ctr)
127 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)
128 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)
129 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)
130 let output_bytes:i64=pfg_glsl_extent(current,n)
131 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}
132 let output:*u8=sys_mmap_try(output_bytes)
133 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}
134 let emitted:i64=rk_cast_glsl(output,0,current,n)
135 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)
136 gv_check("GLSL escaped allocation equals actual emitted extent",emitted==output_bytes,ctr)
137 let count_at:i64=rk_find(current,n,0,"cast_glsl_rc=")
138 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}
139 let digit_at:i64=count_at+rk_slen("cast_glsl_rc=")
140 let saved:u8=current[digit_at]
141 if saved==57 as u8{current[digit_at]=56 as u8}else{current[digit_at]=57 as u8}
142 let refused:i64=rk_cast_glsl(output,0,current,n)
143 gv_check("mismatched producer byte count refuses GLSL emission",refused==0&&gsb_failed==1,ctr)
144 current[digit_at]=saved;gsb_failed=0
145 sys_munmap_direct(output,output_bytes)
146 sys_free_file(v,vn);sys_free_file(f,fn);sys_free_file(bad,bn);sys_free_file(old,cn);rk_owned_close(owned)
147 if pv!=GT_V_IDENTICAL||pf!=GT_V_IDENTICAL {return 0}
148 return 1
149}
150
151func pfg_catalogue_contract(ctr:*i64)->i64{
152 let oldpath:*u8=gpe_prepared_path;let oldsha:*u8=gpe_prepared_sha;let oldbytes:i64=gpe_prepared_bytes;let oldfailed:i64=gsb_failed
153 gpe_prepared_path="buildroot/knowledge/gates/prepared-catalogue-utf8-fixture-t181.json";gpe_prepared_sha="b6025fc9ea5995129fc9cf16cee362268dffcafd2e006d023f1591e70b76f650";gpe_prepared_bytes=73
154 let out:*u8=sys_mmap(GPE_OUT_CAP);gsb_failed=0;let n:i64=gpe_prepared_catalogue(out,0)
155 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)
156 gpe_prepared_sha="0000000000000000000000000000000000000000000000000000000000000000";gsb_failed=0;gpe_prepared_catalogue(out,0)
157 gv_check("catalogue identity mismatch refuses emission",gsb_failed!=0,ctr)
158 sys_munmap(out,GPE_OUT_CAP);gpe_prepared_path=oldpath;gpe_prepared_sha=oldsha;gpe_prepared_bytes=oldbytes;gsb_failed=oldfailed
159 return 1
160}
161func main(argc: i64,argv: *i64) -> i64 {
162 if argc!=7&&argc!=10&&argc!=17 { 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 [cast-producer-path cast-sha256 cast-bytes fragment-reference fragment-sha256 fragment-bytes /tmp/capture-reference]]\n" as *u8);return 3 }
163 if pfg_private(argv[4] as *u8)!=1 { return 3 }
164 if ep_anchor()<0 { return 3 }
165 let ctr: *i64=gv_ctr();gv_head("PRIVATE-GENERATED-PAGE-FIT" as *u8)
166 var world_path:*u8=GSB_STAGED
167 var world_sha:*u8="6a63a26f84a4ba353da798e121a1690a89bf4cac3e59f1dd9e7babe948f33139"
168 var world_bytes:i64=1250264
169 if argc==10||argc==17 {world_path=argv[7] as *u8;world_sha=argv[8] as *u8;world_bytes=pfg_extent(argv[9] as *u8)}
170 let selected:i64=gsb_select_at(world_path,world_sha,world_bytes)
171 gpe_cast_path="/volume1/homes/elderwesto/nishihost/buildroot/_build/nx_cast_skin_wrap_t261.sov.elf" as *u8
172 gpe_cast_expected="8a503b9e5273b2923bd33e36f91f3e2479a951b1567538c3150843839fbf6fc7" as *u8
173 gpe_cast_expected_bytes=417021
174 var fragment_path:*u8="buildroot/knowledge/gates/cast-skin-wrap-fragment-t261.glsl"
175 var fragment_sha:*u8="15c0e4ddef58febf45ffb76d535a1c123f54a36d4f24b2bf7ce471037f835c2e"
176 var fragment_bytes:i64=20262
177 var retained_capture:*u8="/tmp/skin-wrap-cast-qualified-t261.txt"
178 if argc==17 {
179 gpe_cast_path=argv[10] as *u8;gpe_cast_expected=argv[11] as *u8;gpe_cast_expected_bytes=pfg_extent(argv[12] as *u8)
180 fragment_path=argv[13] as *u8;fragment_sha=argv[14] as *u8;fragment_bytes=pfg_extent(argv[15] as *u8)
181 retained_capture=argv[16] as *u8
182 if pfg_private(retained_capture)!=1{return 3}
183 }
184 gpe_prepared_path="buildroot/knowledge/gates/character-static-prepared-manifest-t338.json";gpe_prepared_sha="bfad4078d762e28d6f1fa91983fa5506df2be7e64beda1234bd8ff1c10cce2e3";gpe_prepared_bytes=3675
185 gpe_eye_path="/volume1/homes/elderwesto/nishihost/buildroot/_build/nx_wgsl_eye_t138.sov.elf" as *u8
186 gpe_eye_expected="bf62b1efcc8bf8ef6864664dc3b24ce2eff7633bfc514f366505d08be854d60d" as *u8
187 gpe_eye_expected_bytes=1206958
188 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)
189 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)
190 gv_check("declared staged shader producer selected" as *u8,selected==1,ctr)
191 if selected!=1 { return 3 }
192 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)
193 pfg_catalogue_contract(ctr)
194 if pfg_cast_contract(ctr,fragment_path,fragment_sha,fragment_bytes,retained_capture)!=1 {return 3}
195 let wasm: *u8=sys_mmap(GPE_WASM_CAP)
196 let state: *i64=sys_mmap(3*__size_of(i64)) as *i64
197 let digest: *u8=sys_mmap(GPA_SHA_HEX+1)
198 let limits: *i64=sys_mmap(WM_FIELDS*__size_of(i64)) as *i64
199 let recipes: *i64=sys_mmap(GPR_MAXW*8*8) as *i64
200 let controls: *u8=sys_mmap(CE_EV_CAP)
201 // The second full output-capacity span observes contiguous overruns in this isolated gate.
202 // It is not a general capacity fix for production gpe_ap.
203 let out: *u8=sys_mmap(GPE_OUT_CAP+GPE_OUT_CAP)
204 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 }
205 let wn: i64=pfg_read(argv[1] as *u8,wasm,state)
206 gv_check("whole plain artifact read" as *u8,wn>WM_HEADER,ctr)
207 if wn<=WM_HEADER { return 3 }
208 gpa_sha(wasm,wn,digest)
209 gv_check("plain identity equals requested SHA256" as *u8,fsx_seq(digest,argv[5] as *u8)==1,ctr)
210 if fsx_seq(digest,argv[5] as *u8)!=1 { return 3 }
211 gpe_mt_pages=0;gpe_mt_max=0;gpe_mt_sha=0 as *u8;gpe_mt_url=0 as *u8;gpe_mt_bytes=0
212 if fsx_seq(argv[2] as *u8,"-" as *u8)!=1 {
213 let twin: *u8=sys_mmap(GPE_WASM_CAP)
214 if (twin as i64)<=0 { return 3 }
215 let tn: i64=pfg_read(argv[2] as *u8,twin,state)
216 if tn<=WM_HEADER { return 3 }
217 gpa_sha(twin,tn,digest)
218 gv_check("shared identity equals requested SHA256" as *u8,fsx_seq(digest,argv[6] as *u8)==1,ctr)
219 if fsx_seq(digest,argv[6] as *u8)!=1 { return 3 }
220 let mr: i64=wmem_read(twin,tn,limits)
221 gv_check("actual shared descriptor admitted" as *u8,mr==0&&limits[2]==1&&limits[3]==1&&limits[0]>0&&limits[1]>=limits[0],ctr)
222 if mr!=0||limits[2]!=1||limits[3]!=1||limits[0]<1||limits[1]<limits[0] { return 3 }
223 gv_check("shared identity declaration accepted",gpe_mt_declare(twin,tn,0 as *u8,limits[0],limits[1])==1,ctr)
224 if gpe_mt_pages<1 {return 3}
225 sys_munmap(twin,GPE_WASM_CAP)
226 }
227 let nr: i64=gpe_recipes_load("knowledge/world_recipes.conf" as *u8,recipes)
228 if nr<1 { return 3 }
229 var row: i64=0-1;var i: i64=0;var matches: i64=0
230 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 }
231 gv_check("one actual recipe selected" as *u8,matches==1,ctr)
232 if matches!=1 { return 3 }
233 ce_evidence(recipes[row+5] as *u8,controls)
234 i=GPE_OUT_CAP
235 while i<GPE_OUT_CAP+GPE_OUT_CAP { out[i]=PFG_CANARY as u8;i=i+1 }
236 var n: i64=gpe_build_context_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,"buildroot/knowledge/workspace-context-rigview-t342.json")
237 if gpe_mt_pages>0 {
238 let declared:*u8=sys_mmap(GPE_OUT_CAP)
239 let dn:i64=gpa_declare_shared(out,n,gpe_mt_url,declared,GPE_OUT_CAP)
240 gv_check("shared runtime manifest derives from verified artifact" as *u8,dn>0&&dn<=GPE_OUT_CAP,ctr)
241 if dn<=0||dn>GPE_OUT_CAP {return 3}
242 var at:i64=0;while at<dn {out[at]=declared[at];at=at+1};n=dn
243 sys_munmap(declared,GPE_OUT_CAP)
244 }
245 var intact: i64=1;i=GPE_OUT_CAP
246 while i<GPE_OUT_CAP+GPE_OUT_CAP { if out[i]!=(PFG_CANARY as u8) { intact=0 };i=i+1 }
247 gv_check("full adjacent capacity span unchanged" as *u8,intact==1,ctr)
248 gv_check("actual returned page length fits production allocation" as *u8,n>0&&n<=GPE_OUT_CAP,ctr)
249 gv_check("shader capture owner reports success" as *u8,gsb_failed==0,ctr)
250 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)
251 gv_kv("twin_minimum_pages" as *u8,gpe_mt_pages);gv_kv("twin_maximum_pages" as *u8,gpe_mt_max)
252 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) }
253 gpa_sha(out,n,digest);gv_puts("page_sha256=" as *u8);gv_puts(digest);gv_puts("\n" as *u8)
254 let wrote: i64=fxc_create(argv[4] as *u8,out,n)
255 gv_check("private output exclusively created" as *u8,wrote==n,ctr)
256 if wrote==n {
257 let box: *i64=sys_mmap(__size_of(i64)) as *i64
258 if (box as i64)<=0 { return 3 }
259 let actual: *u8=sys_read_file(argv[4] as *u8,box)
260 gv_check("private output readback equals generated bytes" as *u8,(actual as i64)>0&&gpa_same(out,n,actual,box[0])==1,ctr)
261 }
262 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)
263}