code wiki / _hdl_build / _flock_active_probe.nx
_flock_active_probe.nx source
↩ module page · 25 lines · 1371 B
1// _flock_active_probe.nx -- DISCRIMINATING proof + durable evidence that flock(2) is live in the
2// compiler that built this binary (X-SYSXLATE-FLOCK). flock(fd, LOCK_EX) on a fresh lockfile fd:
3// a compiler with the rv64->x86_64 map fix (32->73) emits a real flock -> returns 0. The OLD
4// compiler fell through 32 -> x86_64 32 = dup2(fd, 2) -> returns 2 (the new fd). exit 0 == flock
5// ACTIVE; appends a durable verdict to knowledge/status/flock_deploy.log so reconcile can close
6// X-SYSXLATE-FLOCK. license_tier: ORIGINAL
7import "nx_syscalls.nx"
8
9func fp_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
10
11func main() -> i64 {
12 let fd: i64 = sys_openat_wr("/tmp/_flock_active_probe.lock" as *u8, 420)
13 if fd < 0 { return 10 }
14 let r: i64 = __syscall(32, fd, 2, 0, 0, 0, 0) // flock(fd, LOCK_EX=2)
15 sys_close(fd)
16 let lf: i64 = sys_openat_append("knowledge/status/flock_deploy.log" as *u8, 420)
17 if lf >= 0 {
18 if r == 0 { fp_w(lf, "FLOCK-DEPLOY authored=organ probe=flock(LOCK_EX) syscall=rv64-32->x86_64-73 flock_ret=0 active=YES verdict=GREEN\n" as *u8) }
19 if r != 0 { fp_w(lf, "FLOCK-DEPLOY authored=organ probe=flock(LOCK_EX) flock_ret=nonzero active=NO verdict=RED\n" as *u8) }
20 sys_close(lf)
21 }
22 if r == 0 { return 0 }
23 if r == 2 { return 2 }
24 return 1
25}