code wiki / (root) / nx_rv64_const_probe.nx

nx_rv64_const_probe.nx source

↩ module page · 39 lines · 2010 B

1// nx_rv64_const_probe.nx -- verify the RV64/asm-generic CONST syscall forms my organs must migrate 2// to (const __syscall numbers are RV64-form by convention; the x86 backend translates. Raw x86 forms 3// only work when the number is absent from the translation table = landmine). Checks, each printed: 4// gp172 getpid (RV64 172) expect > 0 5// gp39 getpid (x86 39, COLLISION) expect broken (documents the live miscompile) 6// fd56 openat (RV64 56) /proc/self/stat RDONLY expect >= 0 7// ul35 unlinkat (RV64 35) on a file created via 56 expect 0, then reopen fails 8// sk198 socket (RV64 198) AF_INET SOCK_STREAM expect >= 0 9// so208 setsockopt (RV64 208) SO_REUSEADDR expect 0 10// license_tier: ORIGINAL expect_exit: 0 11import "nx_model_lane_core.nx" 12 13func main(argc: i64, argv: *i64) -> i64 { 14 std_puts("gp172=" as *u8); std_pdec(__syscall(172, 0, 0, 0, 0, 0, 0)) 15 std_puts(" gp39=" as *u8); std_pdec(__syscall(39, 0, 0, 0, 0, 0, 0)) 16 let fd: i64 = __syscall(56, AT_FDCWD, "/proc/self/stat" as *u8 as i64, 0, 0, 0, 0) 17 std_puts(" fd56=" as *u8); std_pdec(fd) 18 if fd >= 0 { sys_close(fd) } 19 let p: *u8 = "/tmp/nx_rv64probe.tmp" as *u8 20 let cfd: i64 = __syscall(56, AT_FDCWD, p as i64, 0x41, 0x1a4, 0, 0) 21 std_puts(" create56=" as *u8); std_pdec(cfd) 22 if cfd >= 0 { sys_close(cfd) } 23 let ul: i64 = __syscall(35, AT_FDCWD, p as i64, 0, 0, 0, 0) 24 std_puts(" ul35=" as *u8); std_pdec(ul) 25 let gone: i64 = __syscall(56, AT_FDCWD, p as i64, 0, 0, 0, 0) 26 std_puts(" reopen_gone=" as *u8); std_pdec(gone) 27 if gone >= 0 { sys_close(gone) } 28 let sk: i64 = __syscall(198, 2, 1, 0, 0, 0, 0) 29 std_puts(" sk198=" as *u8); std_pdec(sk) 30 let one: *i64 = sys_mmap(8) as *i64 31 one[0] = 1 32 var so: i64 = 0 - 99 33 if sk >= 0 { so = __syscall(208, sk, 1, 2, one as i64, 4, 0) } 34 std_puts(" so208=" as *u8); std_pdec(so) 35 if sk >= 0 { sys_close(sk) } 36 std_puts("\n" as *u8) 37 sys_exit(0) 38 return 0 39}