nx_argv.nx
buildroot/runtime/nx_argv.nx
about
nx_argv.nx -- Linux RV64 entry-stack builder.
At program entry the Linux kernel hands the runtime a stack
laid out per System V ABI:
sp -> argc (i64)
argv[0] (pointer to NUL-terminated string)
argv[1]
...
argv[argc-1]
NULL
envp[0]
envp[1]
...
envp[K-1]
NULL
auxv entries (Elf64_auxv_t = i64 a_type, i64 a_un.a_val)
AT_NULL terminator (a_type=0, a_un=0)
(string area: argv/envp string bodies)
Without this layout, a simulated program crashes the moment it
reads its first argument. Setting it up correctly lets us pass
arguments through nxc_native_wrap to the simulated program, which
is required for any meaningful test harness.
Pairs with nx_rv64_sim (consumes the stack via sp register) +
nxc_native_wrap (wires this in front of nx_rv64_run).
Reference: System V ABI for RV64, "Process Initialization" section
(https://github.com/riscv-non-isa/riscv-elf-psabi-doc).
dependencies 2 imports · 0 importers
imports: syscalls.nxruntime.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 40 | const NX_MAGIC_4096: i64 = 4096 |
| 41 | const NX_MAGIC_1048576: i64 = 1048576 |
| 44 | const NX_AT_NULL: i64 = 0 // end-of-vector marker |
| 45 | const NX_AT_PHDR: i64 = 3 // address of program headers |
| 46 | const NX_AT_PHENT: i64 = 4 // size of one phdr entry |
| 47 | const NX_AT_PHNUM: i64 = 5 // count of phdrs |
| 48 | const NX_AT_PAGESZ: i64 = 6 // system page size |
| 49 | const NX_AT_BASE: i64 = 7 // dynamic linker base addr |
| 50 | const NX_AT_FLAGS: i64 = 8 // (always 0 in our case) |
| 51 | const NX_AT_ENTRY: i64 = 9 // program entry point |
| 52 | const NX_AT_UID: i64 = 11 |
| 53 | const NX_AT_EUID: i64 = 12 |
| 54 | const NX_AT_GID: i64 = 13 |
| 55 | const NX_AT_EGID: i64 = 14 |
| 56 | const NX_AT_HWCAP: i64 = 16 // CPU feature bits |
| 57 | const NX_AT_CLKTCK: i64 = 17 // clock_t per second |
| 58 | const NX_AT_RANDOM: i64 = 25 // 16-byte random seed (stack canary) |
functions
| 95 | func nx_argv_build_stack( |
| 209 | func nx_argv_build_single(mem: *u8, mem_size: i64, load_base: i64, argv0: *u8, entry: i64) -> i64 calls 1: nx_argv_build_stack |
| 220 | func main() -> i64 calls 1: nx_argv_build_stack |