Expand description
ELF Loading Module
This module provides functionality for loading ELF (Executable and Linkable Format) executables into a task’s memory space. It supports 64-bit ELF files with full dynamic linking capabilities and handles the parsing of ELF headers and program headers, as well as the mapping of loadable segments into memory.
§Components
ElfHeader: Represents the ELF file header which contains metadata about the fileProgramHeader: Represents a program header which describes a segment in the ELF fileLoadedSegment: Represents a segment after it has been loaded into memory- Dynamic linking support for shared libraries and position-independent executables
- Error types for handling various failure scenarios during ELF parsing and loading
§Main Functions
load_elf_into_task: Loads an ELF file from a file object into a task’s memory spacemap_elf_segment: Maps an ELF segment into a task’s virtual memory- Dynamic linker integration for shared library resolution
§Dynamic Linking Support
The module now includes comprehensive dynamic linking capabilities:
- Dynamic symbol resolution
- Shared library loading and linking
- Position-independent executable (PIE) support
- Runtime relocation handling
§Constants
The module defines various constants for ELF parsing, including:
- Magic numbers for identifying ELF files
- ELF class identifiers (64-bit)
- Data encoding formats (little/big endian)
- Program header types and segment flags (Read/Write/Execute)
§Endian Support
The module provides endian-aware data reading functions to correctly parse ELF files regardless of the endianness used in the file.
Structs§
- AuxVec
- Auxiliary Vector entry
- ElfHeader
- ElfHeader
Parse Error - ElfLoader
Error - Load
ElfResult - Result of ELF loading analysis
- Load
Strategy - Binary loading strategy (format-agnostic)
- Loaded
Segment - Program
Header - Program
Header Parse Error - Program
Headers Info - Program headers information for auxiliary vector
Enums§
- ElfHeader
Parse Error Kind - Execution
Mode - Execution mode determined by ELF analysis
- Load
Target - Target type for ELF loading (determines base address strategy)
- Program
Header Parse Error Kind
Constants§
- AT_BASE
- AT_
CLKTCK - AT_EGID
- AT_
ENTRY - AT_EUID
- AT_
EXECFD - AT_
FLAGS - AT_GID
- AT_
HWCAP - AT_
IGNORE - AT_
NOTELF - AT_NULL
- Auxiliary Vector entry type constants
- AT_
PAGESZ - AT_PHDR
- AT_
PHENT - AT_
PHNUM - AT_
PLATFORM - AT_
RANDOM - AT_UID
- EI_
CLASS 🔒 - EI_DATA 🔒
- EI_MAG0 🔒
- EI_MAG1 🔒
- EI_MAG2 🔒
- EI_MAG3 🔒
- ELFCLAS
S64 🔒 - ELFDAT
A2LSB 🔒 - ELFMAG 🔒
- ET_DYN
- ET_EXEC
- MAX_
INTERPRETER_ 🔒DEPTH - Load interpreter (dynamic linker) into task memory
Maximum recursion depth for interpreter loading to prevent infinite loops - PF_R
- PF_W
- PF_X
- PT_
INTERP 🔒 - PT_LOAD 🔒
Functions§
- analyze_
and_ load_ elf - Analyze ELF file and load it with dynamic linking support
- analyze_
and_ load_ elf_ with_ strategy - Analyze ELF file and load it with custom loading strategy
- build_
auxiliary_ vector - Build auxiliary vector for dynamic linking
- find_
interpreter_ 🔒path - Find PT_INTERP segment and extract interpreter path
- for_
each_ 🔒program_ header - Iterate through all program headers and call a closure for each one
- load_
elf_ into_ task - Load an ELF file into a task’s memory space
- load_
elf_ 🔒into_ task_ static - Load ELF using the static linking logic with strategy support
- load_
elf_ 🔒segment_ at_ address - Load a single ELF segment into task memory at the specified address
- load_
elf_ 🔒segments_ for_ interpreter - Load ELF segments for dynamic execution (without executing)
- load_
elf_ 🔒segments_ with_ base - Load ELF segments for interpreter with specified base address
- load_
interpreter 🔒 - load_
interpreter_ 🔒recursive - Recursive interpreter loading with depth limiting
- load_
program_ 🔒headers_ into_ memory - Load program headers into task memory for static executables
- map_
elf_ 🔒segment - read_
program_ 🔒header - Read and parse a program header at the specified index
- read_
u16 🔒 - read_
u32 🔒 - read_
u64 🔒 - setup_
auxiliary_ vector_ on_ stack - Setup auxiliary vector on the task’s stack