code wiki / (root) / nx_argv.nx

nx_argv.nx

buildroot/runtime/nx_argv.nx

10545 B284 linesdepth 4pulls 4 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

syscalls.nx runtime.nx nx_argv.nx

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

main nx_argv_build_stack strlen

structs

none

consts

40const NX_MAGIC_4096: i64 = 4096
41const NX_MAGIC_1048576: i64 = 1048576
44const NX_AT_NULL: i64 = 0 // end-of-vector marker
45const NX_AT_PHDR: i64 = 3 // address of program headers
46const NX_AT_PHENT: i64 = 4 // size of one phdr entry
47const NX_AT_PHNUM: i64 = 5 // count of phdrs
48const NX_AT_PAGESZ: i64 = 6 // system page size
49const NX_AT_BASE: i64 = 7 // dynamic linker base addr
50const NX_AT_FLAGS: i64 = 8 // (always 0 in our case)
51const NX_AT_ENTRY: i64 = 9 // program entry point
52const NX_AT_UID: i64 = 11
53const NX_AT_EUID: i64 = 12
54const NX_AT_GID: i64 = 13
55const NX_AT_EGID: i64 = 14
56const NX_AT_HWCAP: i64 = 16 // CPU feature bits
57const NX_AT_CLKTCK: i64 = 17 // clock_t per second
58const NX_AT_RANDOM: i64 = 25 // 16-byte random seed (stack canary)

functions

95func nx_argv_build_stack(
called by 2: nx_argv_build_singlemain calls 1: strlen
209func nx_argv_build_single(mem: *u8, mem_size: i64, load_base: i64, argv0: *u8, entry: i64) -> i64
220func main() -> i64