nx_fcntlprobe.nx source
↩ module page · 47 lines · 1960 B
1// nx_fcntlprobe.nx -- is nx_fcntl actually working on this target?
2// nx_connect_bounded bails with -1 the moment nx_fcntl(fd, F_GETFL) returns <0, and EVERY freshly
3// built organ now fails outbound connect with -2 while an organ built before the bounded-connect
4// change still reaches the same host. This asks the primitive directly instead of inferring.
5// expect_exit: 0 license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_fcntl.nx"
8
9func fq_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
10func fq_puts(s: *u8) -> i64 { sys_write(1, s, fq_len(s)); return 0 }
11func fq_putn(v: i64) -> i64 {
12 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
13 var m: i64 = v
14 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
15 let d: *u8 = sys_mmap(24)
16 var k: i64 = 0
17 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
18 var j: i64 = k - 1
19 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 }
20 return 0
21}
22
23func main() -> i64 {
24 fq_puts("NX_SYS_FCNTL const compiled in = " as *u8)
25 fq_putn(NX_SYS_FCNTL)
26 fq_puts(" (x86_64 wants 72, riscv wants 25)\n" as *u8)
27
28 // fd 1 is stdout and always open, so F_GETFL must succeed on any sane target.
29 let fl: i64 = nx_fcntl(1, NX_F_GETFL, 0)
30 fq_puts("nx_fcntl(1, F_GETFL) = " as *u8)
31 fq_putn(fl)
32 if fl < 0 { fq_puts(" <-- BROKEN: every bounded connect returns -1 on this\n" as *u8) } else { fq_puts(" OK\n" as *u8) }
33
34 // and on a real socket, which is what connect actually uses
35 let s: i64 = sys_socket(2, 1, 0)
36 fq_puts("sys_socket(AF_INET,SOCK_STREAM) = " as *u8)
37 fq_putn(s)
38 fq_puts("\n" as *u8)
39 if s >= 0 {
40 let fl2: i64 = nx_fcntl(s, NX_F_GETFL, 0)
41 fq_puts("nx_fcntl(sock, F_GETFL) = " as *u8)
42 fq_putn(fl2)
43 if fl2 < 0 { fq_puts(" <-- BROKEN\n" as *u8) } else { fq_puts(" OK\n" as *u8) }
44 sys_close(s)
45 }
46 return 0
47}