nx_fnptr_kat.nx source
↩ module page · 23 lines · 1043 B
1// KAT for stage 1 (func type + function-address). Expect: AMP_OK / BARE_OK / SAME_OK.
2// Proves &fn and a BARE function name both yield the function's real (non-zero) code address,
3// and they agree -- the fix for __thread_clone's NULL-entry SIGSEGV.
4import "nx_syscalls.nx"
5
6func worker(x: i64) -> i64 { return x * 2 }
7
8func main() -> i64 {
9 let a: i64 = (&worker) as i64 // &fn -> VK_FUNC_ADDR
10 if a != 0 { sys_write(1, "AMP_OK\n" as *u8, 7) } else { sys_write(1, "AMP_ZERO\n" as *u8, 9) }
11
12 let b: i64 = worker as i64 // bare fn name as a value (the load-bearing path)
13 if b != 0 { sys_write(1, "BARE_OK\n" as *u8, 8) } else { sys_write(1, "BARE_ZERO\n" as *u8, 10) }
14
15 if a == b { sys_write(1, "SAME_OK\n" as *u8, 8) } else { sys_write(1, "DIFF\n" as *u8, 5) }
16
17 // a func-typed local holds the address too
18 let f: func(i64) -> i64 = &worker
19 let c: i64 = f as i64
20 if c == a { sys_write(1, "LOCAL_OK\n" as *u8, 9) } else { sys_write(1, "LOCAL_BAD\n" as *u8, 10) }
21
22 sys_exit(0); return 0
23}