Module elf_loader

Module elf_loader 

Source
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 file
  • ProgramHeader: Represents a program header which describes a segment in the ELF file
  • LoadedSegment: 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 space
  • map_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
ElfHeaderParseError
ElfLoaderError
LoadElfResult
Result of ELF loading analysis
LoadStrategy
Binary loading strategy (format-agnostic)
LoadedSegment
ProgramHeader
ProgramHeaderParseError
ProgramHeadersInfo
Program headers information for auxiliary vector

Enums§

ElfHeaderParseErrorKind
ExecutionMode
Execution mode determined by ELF analysis
LoadTarget
Target type for ELF loading (determines base address strategy)
ProgramHeaderParseErrorKind

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 🔒
ELFCLASS64 🔒
ELFDATA2LSB 🔒
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