nx_craft_emit_child_fixture.nx source
↩ module page · 24 lines · 1102 B
1// ORIGINAL. Controlled process-status fixture. All descriptors belong to this
2// child; it never signals a PID or changes any parent/live process disposition.
3import "nx_syscalls.nx"
4const CEF_SIGPIPE: i64 = 13
5func main(argc: i64,argv: *i64) -> i64 {
6 if argc != 2 { return 70 }
7 let mode: *u8 = argv[1] as *u8
8 if mode[0] == (122 as u8) { return 0 }
9 if mode[0] == (115 as u8) { return 7 }
10 if mode[0] != (112 as u8) { return 70 }
11 // An inherited SIG_IGN would invalidate the signal witness; restore only
12 // this child. The existing syscall library owns rt_sigaction/pipe ABI.
13 if sys_default_signal(CEF_SIGPIPE) != 0 { return 71 }
14 let fds: *i64 = sys_mmap(8) as *i64
15 if (fds as i64) <= 0 { return 72 }
16 if sys_pipe2(fds,0) != 0 { return 73 }
17 let read_fd: i64 = fds[0]&4294967295
18 let write_fd: i64 = (fds[0]/4294967296)&4294967295
19 if sys_close(read_fd) != 0 { sys_close(write_fd); return 74 }
20 sys_write(write_fd,"x" as *u8,1)
21 // Reaching this return proves the signal fixture did NOT reach its target.
22 sys_close(write_fd)
23 return 75
24}