Expand description
ELF64 loader for Strat9-OS.
Parses ELF64 headers and loads PT_LOAD segments into a user address space, then creates a kernel task that trampolines into Ring 3 via IRETQ.
Supports :
- ET_EXEC
- ET_DYN (PIE/static-PIE)
- ELF64 little-endian x86_64 binaries.
Does not support (or need future fix) :
-
Fix TODO : allocation heap during ELF loadingPARTIALLY DONE (#67) : program-header vectors and boot-stack argv pointers now usetry_reserve_exact-based fallible collection and fail the load with an error instead of aborting. Full rollback of already-mapped segments still requires a fallible GlobalAlloc. -
Fix TODO : find_free_vma_range : fallback hardcoded 0x1000_0000DONE : the fallback was removed; a failed search now fails the load with โNo virtual range for ET_DYN imageโ.
Security:
- User stack has a guard page (user_stack_base() - 4096) that is intentionally left unmapped. Stack underflows hit it and page-fault.
Macrosยง
- elf_
trace ๐
Structsยง
- Elf64
Dyn ๐ - Elf64
Header ๐ - Parsed ELF64 file header (copy-friendly, no borrows).
- Elf64
Phdr ๐ - Parsed ELF64 program header (copy-friendly, packed for raw byte reading).
- Elf64
Rela ๐ - Elf64
Sym ๐ - Loaded
ElfInfo - Result of loading an ELF image into an address space.
Constantsยง
- AT_BASE ๐
- AT_
ENTRY ๐ - AT_
PAGESZ ๐ - AT_PHDR ๐
- AT_
PHENT ๐ - AT_
PHNUM ๐ - AT_
RANDOM ๐ - DT_
JMPREL ๐ - DT_NULL ๐
- DT_
PLTREL ๐ - DT_
PLTRELSZ ๐ - DT_RELA ๐
- DT_
RELACOUNT ๐ - DT_
RELAENT ๐ - DT_
RELASZ ๐ - DT_RELR ๐
- DT_
RELRENT ๐ - DT_
RELRSZ ๐ - DT_
STRTAB ๐ - DT_
SYMENT ๐ - DT_
SYMTAB ๐ - ET_DYN ๐
- ET_EXEC ๐
- MAX_
INTERP_ ๐PATH_ LEN - Maximum PT_INTERP path length we accept.
- PF_R ๐
- PF_W ๐
- PF_X ๐
- PT_
DYNAMIC ๐ - PT_
GNU_ ๐RELRO - PT_
GNU_ ๐STACK - PT_
INTERP ๐ - PT_LOAD ๐
- PT_TLS ๐
- R_
X86_ ๐64_ 64 - R_
X86_ ๐64_ COPY - R_
X86_ ๐64_ DTPMO D64 - R_
X86_ ๐64_ DTPOF F64 - R_
X86_ ๐64_ GLOB_ DAT - R_
X86_ ๐64_ IRELATIVE - R_
X86_ ๐64_ JUMP_ SLOT - R_
X86_ ๐64_ RELATIVE - R_
X86_ ๐64_ TPOF F64 - USER_
ADDR_ MAX - Maximum virtual address we accept for user-space mappings.
- USER_
RFLAGS ๐ - Standard user-mode RFLAGS: IF=1, reserved bit 1 set.
- USER_
STACK_ MAX_ PAGES - Upper bound on a per-process user stack (2048 pages = 8 MiB), to keep a buggy or hostile caller from exhausting the user address space / frames.
- USER_
STACK_ MIN_ PAGES - Lower bound on a per-process user stack (4 pages = 16 KiB): the boot stack layout alone (argv/envp/auxv + guard margins) needs at least one page, and tiny stacks would fault immediately.
- USER_
STACK_ PAGES - Number of 4 KiB pages for the user stack (16 pages = 64 KiB).
Functionsยง
- apply_
dynamic_ ๐relocations - Performs the apply dynamic relocations operation.
- apply_
relr_ ๐relocations - Performs the apply relr relocations operation.
- apply_
segment_ ๐permissions - Performs the apply segment permissions operation.
- call_
ifunc_ ๐resolver - Calls a user-space IFUNC resolver function and returns its result.
- compute_
load_ ๐bias_ and_ entry - Compute load bias and relocated entry for ET_EXEC / ET_DYN.
- compute_
load_ ๐bounds - Compute total mapped bounds for all PT_LOAD segments.
- elf_
flags_ ๐to_ vma - Convert ELF p_flags to VmaFlags.
- elf_
ring3_ ๐trampoline - Parameters for the Ring 3 trampoline, stored in a static so the Trampoline that switches to user address space and does IRETQ to Ring 3.
- find_
relocated_ ๐phdr_ vaddr - Performs the find relocated phdr vaddr operation.
- generate_
aux_ ๐random_ seed - load_
and_ run_ elf - Load an ELF64 binary and schedule it as a Ring 3 user task.
- load_
and_ run_ elf_ with_ args - Load an ELF64 binary with command-line arguments and schedule it as a Ring 3 task.
- load_
and_ run_ elf_ with_ caps - Performs the load and run elf with caps operation.
- load_
and_ run_ elf_ with_ stack - Load an ELF64 binary with an explicit per-process user stack size.
- load_
elf_ image - Load an ELF binary into the provided address space. Returns the entry point address.
- load_
elf_ ๐task_ inner - Internal ELF task builder used by all public loading APIs.
extra_argsare written to the user stack as argv[1..] after the program name. - load_
elf_ task_ with_ caps - Thin public wrapper that keeps the existing API stable.
- load_
segment ๐ - Load a single PT_LOAD segment into the given address space.
- parse_
header ๐ - Parse and validate the ELF64 file header from raw bytes.
- parse_
interp_ ๐path - Parses interp path.
- pie_
base ๐ - Get the randomized PIE base address for ELF loading.
- program_
headers ๐ - Iterate over program headers in the ELF.
- push_
auxv ๐ - Performs the push auxv operation.
- read_
elf_ ๐from_ vfs - Reads elf from vfs.
- read_
user_ ๐mapped_ bytes - Reads user mapped bytes.
- read_
user_ mapped_ bytes_ pub - Reads user mapped bytes pub.
- read_
user_ ๐u64 - Reads user u64.
- setup_
boot_ ๐user_ stack - Performs the setup boot user stack operation. Sets up the initial user-space stack for a freshly loaded ELF task.
- try_
collect_ ๐exact - Collects an exact-size-hint iterator into a
Vec, failing cleanly on allocation failure instead of aborting (issue #67). - user_
stack_ ๐base - Get the randomized user stack base address.
- user_
stack_ ๐guard - Get the guard page address below the user stack.
- user_
stack_ ๐top - Get the randomized user stack top address.
- write_
user_ ๐mapped_ bytes - Writes user mapped bytes.
- write_
user_ mapped_ bytes_ pub - Writes user mapped bytes pub.
- write_
user_ ๐u64 - Writes user u64.
- write_
user_ u64_ pub - Writes user u64 pub.