code wiki / (root) / nx_natfu_probe.nx

nx_natfu_probe.nx source

↩ module page · 41 lines · 1495 B

1// nx_natfu_probe.nx -- NATIVE futex-roundtrip probe for the 11-import HAL. 2// Spawns one thread via sys_thread_create (CreateThread); worker spins ~50M 3// then stores flag=1 + sys_futex_wake (WakeByAddressAll); main futex_waits 4// (WaitOnAddress) until the flag flips, prints FUTEXOK. Race-safe both 5// orders: WaitOnAddress returns immediately when *addr != compare. 6// If the 11-import layout broke the wait/wake IAT binding, this HANGS -- 7// reproducing the LLM-gate deadlock in a 1-second probe. 8// license_tier: ORIGINAL expect_exit: 0 9import "nx_syscalls.nx" 10import "nx_tier.nx" 11import "nx_atom.nx" 12import "nx_thread.nx" 13import "nx_thread_pool.nx" 14const K_MAGIC_50000000: i64 = 50000000 15 16func fu_worker(arg: *u8) -> i64 { 17 let f: *i64 = arg as *i64 18 var i: i64 = 0 19 while i < K_MAGIC_50000000 { i = i + 1 } // ~30-60ms: let main reach WaitOnAddress 20 nx_atom_store_i64(f, 1, NX_MO_SEQ_CST) 21 sys_futex_wake(f as i64) 22 return 0 23} 24 25func main() -> i64 { 26 let f: *i64 = sys_mmap(64) as *i64 27 f[0] = 0 28 let sargp: *i64 = sys_mmap(16) as *i64 29 sargp[0] = fu_worker as i64 30 sargp[1] = f as i64 31 let tid: i64 = sys_thread_create(sargp as i64) 32 if tid <= 0 { sys_write(1, "SPAWNFAIL\n" as *u8, 10); sys_exit(2) } 33 var seen: i64 = nx_atom_load_i64(f, NX_MO_SEQ_CST) 34 while seen == 0 { 35 sys_futex_wait(f as i64, 0) 36 seen = nx_atom_load_i64(f, NX_MO_SEQ_CST) 37 } 38 sys_write(1, "FUTEXOK\n" as *u8, 8) 39 sys_exit(0) 40 return 0 41}