code wiki / _hdl_build / nx_static_field_probe.nx
nx_static_field_probe.nx source
↩ module page · 51 lines · 2520 B
1// nx_static_field_probe.nx -- is "read struct FIELD through a STATIC pointer" a general nx_cc trap
2// (pre-existing) or something specific? Minimal: a struct, a static pointer to a heap instance, write
3// fields, then read the SAME field through the static ptr vs a local copy. If they disagree, the trap is
4// general + pre-existing (unrelated to the sext bless, which touched only subword-load signedness).
5// expect_exit: 0 license_tier: ORIGINAL
6import "nx_syscalls.nx"
7
8struct SFP { a: i64, b: i64, c: i64, d: i64 }
9
10static g_sfp: *SFP
11
12func p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
13func pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
14
15func main() -> i64 {
16 g_sfp = sys_mmap(64) as *SFP
17 g_sfp.a = 111
18 g_sfp.b = 222
19 g_sfp.c = 333
20 g_sfp.d = 444
21 // read through the STATIC pointer directly
22 let sa: i64 = g_sfp.a
23 let sb: i64 = g_sfp.b
24 let sc: i64 = g_sfp.c
25 let sd: i64 = g_sfp.d
26 // read through a LOCAL copy of the static pointer
27 let loc: *SFP = g_sfp
28 let la: i64 = loc.a
29 let lb: i64 = loc.b
30 let lc: i64 = loc.c
31 let ld: i64 = loc.d
32 p(" STATIC reads: a="); pn(sa); p(" b="); pn(sb); p(" c="); pn(sc); p(" d="); pn(sd); p("\n")
33 p(" LOCAL reads: a="); pn(la); p(" b="); pn(lb); p(" c="); pn(lc); p(" d="); pn(ld); p("\n")
34 var stat_ok: i64 = 1
35 if sa!=111 { stat_ok=0 }
36 if sb!=222 { stat_ok=0 }
37 if sc!=333 { stat_ok=0 }
38 if sd!=444 { stat_ok=0 }
39 var loc_ok: i64 = 1
40 if la!=111 { loc_ok=0 }
41 if lb!=222 { loc_ok=0 }
42 if lc!=333 { loc_ok=0 }
43 if ld!=444 { loc_ok=0 }
44 p(" static-field-read correct: "); pn(stat_ok); p(" local-field-read correct: "); pn(loc_ok); p("\n")
45 // STRICT regression gate (2026-07-10 static-field root fix): every field written through the static
46 // base must read back correctly through BOTH the static base and a local copy. Pre-fix: writes
47 // collapsed to offset 0 and static reads returned the raw pointer.
48 if stat_ok==1 { if loc_ok==1 { p("NX-STATIC-FIELD-PROBE verdict=GREEN (struct fields via STATIC pointer: writes offset correctly, reads dereference)\n"); return 0 } }
49 p("NX-STATIC-FIELD-PROBE verdict=RED (static-base member access miscompiled)\n")
50 return 1
51}