code wiki / _hdl_build / nx_fwdconst_probe.nx

nx_fwdconst_probe.nx source

↩ module page · 51 lines · 2214 B

1// nx_fwdconst_probe.nx -- FAIL-OPEN PROBE for seq360: a module const READ BY A FUNCTION DECLARED 2// ABOVE IT silently resolved to 0 in shipped binaries (VC_EO_PART / VC_EO_T8 were dead since 07-12, 3// AT_FDCWD before that). The reader compiles clean and computes with 0 -- no diagnostic, no crash, 4// just a wrong answer that looks like a deliberate default. That is the fail-OPEN signature. 5// 6// A const that reads as 0 is indistinguishable from a const that IS 0, which is exactly why this 7// class survives so long: every consequence looks like intended behaviour. Known answers below are 8// deliberately non-zero and distinctive so a 0 read can never be mistaken for a pass. 9import "nx_syscalls.nx" 10 11func fc_puts(s: *u8) -> i64 { 12 var n: i64 = 0 13 while s[n] != (0 as u8) { n = n + 1 } 14 sys_write(1, s, n) 15 return 0 16} 17func fc_putn(v: i64) -> i64 { 18 let b: *u8 = sys_mmap(32) 19 var m: i64 = v 20 var k: i64 = 0 21 if m == 0 { b[0] = 48 as u8; sys_write(1, b, 1); return 0 } 22 let t: *u8 = sys_mmap(32) 23 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 24 var i: i64 = 0 25 while i < k { b[i] = t[k - 1 - i]; i = i + 1 } 26 sys_write(1, b, k) 27 return 0 28} 29 30// THE SHAPE UNDER TEST: this function is declared BEFORE the consts it reads. 31func fc_read_a() -> i64 { return FC_ALPHA } 32func fc_read_b() -> i64 { return FC_BRAVO } 33func fc_sum() -> i64 { return FC_ALPHA + FC_BRAVO } 34 35const FC_ALPHA: i64 = 12345 36const FC_BRAVO: i64 = 6789 37 38func main() -> i64 { 39 var bad: i64 = 0 40 fc_puts("fwd const A got=" as *u8); fc_putn(fc_read_a()); fc_puts(" want=12345\n" as *u8) 41 if fc_read_a() != 12345 { bad = bad + 1 } 42 fc_puts("fwd const B got=" as *u8); fc_putn(fc_read_b()); fc_puts(" want=6789\n" as *u8) 43 if fc_read_b() != 6789 { bad = bad + 1 } 44 fc_puts("fwd const A+B got=" as *u8); fc_putn(fc_sum()); fc_puts(" want=19134\n" as *u8) 45 if fc_sum() != 19134 { bad = bad + 1 } 46 fc_puts("FWDCONST-PROBE wrong=" as *u8); fc_putn(bad); fc_puts("\n" as *u8) 47 if bad != 0 { fc_puts("FWDCONST-PROBE verdict=RED (seq360 STILL-LIVE)\n" as *u8); sys_exit(1); return 1 } 48 fc_puts("FWDCONST-PROBE verdict=GREEN\n" as *u8) 49 sys_exit(0) 50 return 0 51}