code wiki / _hdl_build / nx_nxe_exec_probe.nx

nx_nxe_exec_probe.nx

buildroot/runtime/_hdl_build/nx_nxe_exec_probe.nx

2093 B32 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind probetopic nxe
docsdependenciesstructsconstsfunctions

about

nx_nxe_exec_probe.nx -- PROBE (cardinal rule 2: verify the runtime primitive before building on it). Question: can we (a) mmap RWX memory, (b) write raw x86_64 machine code into it, (c) cast the raw address to a typed function pointer and CALL it -- i.e. genuinely EXECUTE loaded code on this machine? If yes, the native NXE loader can verify-then-execute. Payload = int64 f(int64 x){ return x*x + 1; } in SysV ABI (arg rdi, ret rax): 48 89 f8 mov rax, rdi 48 0f af c7 imul rax, rdi 48 ff c0 inc rax c3 ret f(7) must be 50. expect_exit: 0

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_nxe_exec_probe.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main g_puts sys_write mmap_rwx sys_exit g_pn sys_mmap sys_write ↻

structs

none

consts

11const K_MAGIC_4096: i64 = 4096

functions

13func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
14func g_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; if x<0{b[0]=45;sys_write(1,b,1);x=0-x} if x==0{b[0]=48;sys_write(1,b,1);return 0} var d: i64=0; var y: i64=x; while y>0{d=d+1;y=y/10} var i: i64=d-1; y=x; while i>=0{b[i]=(48+(y%10)) as u8;y=y/10;i=i-1} sys_write(1,b,d); return 0 }
called by 1: main calls 2: sys_mmapsys_write
17func mmap_rwx(size: i64) -> *u8 { let r: i64 = __syscall(SYS_MMAP, 0, size, 7, 0x22, -1, 0); return r as *u8 }
called by 1: main
19func main() -> i64