pub struct Loader<M = DefaultMmap, H = (), D = (), Tls = DefaultTlsResolver>{ /* private fields */ }Expand description
The ELF object loader.
Loader is responsible for orchestrating the loading of ELF objects into memory.
It supports customization through various with_* methods for memory mapping,
hooks, user data, and TLS resolution.
§Examples
use elf_loader::{Loader, input::ElfBinary};
let mut loader = Loader::new();
let bytes = std::fs::read("liba.so").unwrap();
let lib = loader.load_dylib(ElfBinary::new("liba.so", &bytes)).unwrap();Implementations§
Source§impl<M, H, D, Tls> Loader<M, H, D, Tls>
impl<M, H, D, Tls> Loader<M, H, D, Tls>
Sourcepub fn load_dylib<'a, I>(&mut self, input: I) -> Result<RawDylib<D>>where
I: IntoElfReader<'a>,
pub fn load_dylib<'a, I>(&mut self, input: I) -> Result<RawDylib<D>>where
I: IntoElfReader<'a>,
Loads a dynamic library into memory and prepares it for relocation.
§Examples
use elf_loader::{Loader, input::ElfBinary};
let mut loader = Loader::new();
let bytes = &[]; // ELF file bytes
let lib = loader.load_dylib(ElfBinary::new("liba.so", bytes)).unwrap();Source§impl<M, H, D, Tls> Loader<M, H, D, Tls>
impl<M, H, D, Tls> Loader<M, H, D, Tls>
Sourcepub fn load_exec<'a, I>(&mut self, input: I) -> Result<RawExec<D>>where
I: IntoElfReader<'a>,
pub fn load_exec<'a, I>(&mut self, input: I) -> Result<RawExec<D>>where
I: IntoElfReader<'a>,
Loads an executable file into memory and prepares it for relocation.
§Examples
use elf_loader::{Loader, input::ElfBinary};
let mut loader = Loader::new();
let bytes = &[]; // ELF executable bytes
let exec = loader.load_exec(ElfBinary::new("my_exec", bytes)).unwrap();Source§impl<M, H, D, Tls> Loader<M, H, D, Tls>
impl<M, H, D, Tls> Loader<M, H, D, Tls>
Sourcepub fn load_object<'a, I>(&mut self, input: I) -> Result<RawObject<D>>where
I: IntoElfReader<'a>,
pub fn load_object<'a, I>(&mut self, input: I) -> Result<RawObject<D>>where
I: IntoElfReader<'a>,
Loads a relocatable object file into memory and prepares it for relocation.
§Examples
use elf_loader::{Loader, input::ElfBinary};
let mut loader = Loader::new();
let bytes = &[]; // Relocatable ELF bytes
let rel = loader.load_object(ElfBinary::new("liba.o", bytes)).unwrap();Source§impl<M, H, D, Tls> Loader<M, H, D, Tls>
impl<M, H, D, Tls> Loader<M, H, D, Tls>
Sourcepub fn with_init<F>(self, init_fn: F) -> Selfwhere
F: LifecycleHandler + 'static,
pub fn with_init<F>(self, init_fn: F) -> Selfwhere
F: LifecycleHandler + 'static,
Sets the initialization function handler.
This handler is responsible for calling the initialization functions
(e.g., .init and .init_array) of the loaded ELF object.
Note: glibc passes argc, argv, and envp to functions in .init_array
as a non-standard extension.
Sourcepub fn with_fini<F>(self, fini_fn: F) -> Selfwhere
F: LifecycleHandler + 'static,
pub fn with_fini<F>(self, fini_fn: F) -> Selfwhere
F: LifecycleHandler + 'static,
Sets the finalization function handler.
This handler is responsible for calling the finalization functions
(e.g., .fini and .fini_array) of the loaded ELF object.
Sourcepub fn with_context<NewD>(self) -> Loader<M, H, NewD, Tls>where
NewD: Default + 'static,
pub fn with_context<NewD>(self) -> Loader<M, H, NewD, Tls>where
NewD: Default + 'static,
Consumes the current loader and returns a new one with the specified context data type.
Sourcepub fn with_context_loader<NewD>(
self,
loader: impl Fn(&UserDataLoaderContext<'_>) -> NewD + 'static,
) -> Loader<M, H, NewD, Tls>where
NewD: 'static,
pub fn with_context_loader<NewD>(
self,
loader: impl Fn(&UserDataLoaderContext<'_>) -> NewD + 'static,
) -> Loader<M, H, NewD, Tls>where
NewD: 'static,
Consumes the current loader and returns a new one with the specified user data generator.
Sourcepub fn with_hook<NewHook>(self, hook: NewHook) -> Loader<M, NewHook, D, Tls>where
NewHook: LoadHook,
pub fn with_hook<NewHook>(self, hook: NewHook) -> Loader<M, NewHook, D, Tls>where
NewHook: LoadHook,
Consumes the current loader and returns a new one with the specified hook.
Sourcepub fn with_mmap<NewMmap: Mmap>(self) -> Loader<NewMmap, H, D, Tls>
pub fn with_mmap<NewMmap: Mmap>(self) -> Loader<NewMmap, H, D, Tls>
Returns a new loader with a custom Mmap implementation.
Sourcepub fn with_tls_resolver<NewTls>(self) -> Loader<M, H, D, NewTls>where
NewTls: TlsResolver,
pub fn with_tls_resolver<NewTls>(self) -> Loader<M, H, D, NewTls>where
NewTls: TlsResolver,
Consumes the current loader and returns a new one with the specified TLS resolver.
Sourcepub fn with_default_tls_resolver(self) -> Loader<M, H, D, DefaultTlsResolver>
pub fn with_default_tls_resolver(self) -> Loader<M, H, D, DefaultTlsResolver>
Consumes the current loader and returns a new one with the default TLS resolver.
Sourcepub fn with_static_tls(self, enabled: bool) -> Self
pub fn with_static_tls(self, enabled: bool) -> Self
Sets whether to force static TLS for all loaded modules.