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 loading program_headers(elf_data, &header).collect() β Vec
, Vec::new() for interp_phdrs, etc. The kernel uses alloc so itβs normal, but allocation errors are not handled (no try_collect, no fallible GlobalAlloc). -
Fix TODO : find_free_vma_range : fallback hardcoded 0x1000_0000 If PIE_BASE_ADDR (0x1_0000_0000) fails, fallback to 0x1000_0000. This value is arbitrary and could overlap existing mappings if many libraries are loaded.
Security:
- User stack has a guard page (USER_STACK_BASE - 4096) that is intentionally left unmapped. Stack underflows hit it and page-fault.
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 π
- PF_R π
- PF_W π
- PF_X π
- PIE_
BASE_ πADDR - Preferred base when placing ET_DYN (PIE) images.
- PT_
DYNAMIC π - PT_
INTERP π - PT_LOAD π
- PT_TLS π
- R_
X86_ π64_ 64 - R_
X86_ π64_ COPY - 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_
STACK_ BASE - User stack location (below the non-canonical gap).
- USER_
STACK_ GUARD - Guard page below the user stack : unmapped, catches stack underflows.
- USER_
STACK_ PAGES - Number of 4 KiB pages for the user stack (16 pages = 64 KiB).
- USER_
STACK_ TOP - Top of the user stack (stack grows down).
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_
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.
- 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.
- 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.