pub trait ElfLoader {
// Required methods
fn allocate(
&mut self,
load_headers: LoadableHeaders<'_, '_>,
) -> Result<(), ElfLoaderErr>;
fn load(
&mut self,
flags: Flags,
base: VAddr,
region: &[u8],
) -> Result<(), ElfLoaderErr>;
fn relocate(&mut self, entry: RelocationEntry) -> Result<(), ElfLoaderErr>;
// Provided methods
fn tls(
&mut self,
_tdata_start: VAddr,
_tdata_length: u64,
_total_size: u64,
_align: u64,
) -> Result<(), ElfLoaderErr> { ... }
fn make_readonly(
&mut self,
_base: VAddr,
_size: usize,
) -> Result<(), ElfLoaderErr> { ... }
}Expand description
Implement this trait for customized ELF loading.
The flow of ElfBinary is that it first calls allocate for all regions
that need to be allocated (i.e., the LOAD program headers of the ELF binary),
then load will be called to fill the allocated regions, and finally
relocate is called for every entry in the RELA table.
Required Methods§
Sourcefn allocate(
&mut self,
load_headers: LoadableHeaders<'_, '_>,
) -> Result<(), ElfLoaderErr>
fn allocate( &mut self, load_headers: LoadableHeaders<'_, '_>, ) -> Result<(), ElfLoaderErr>
Allocates a virtual region specified by load_headers.
Sourcefn load(
&mut self,
flags: Flags,
base: VAddr,
region: &[u8],
) -> Result<(), ElfLoaderErr>
fn load( &mut self, flags: Flags, base: VAddr, region: &[u8], ) -> Result<(), ElfLoaderErr>
Copies region into memory starting at base.
The caller makes sure that there was an allocate call previously
to initialize the region.
Sourcefn relocate(&mut self, entry: RelocationEntry) -> Result<(), ElfLoaderErr>
fn relocate(&mut self, entry: RelocationEntry) -> Result<(), ElfLoaderErr>
Request for the client to relocate the given entry
within the loaded ELF file.
Provided Methods§
Sourcefn tls(
&mut self,
_tdata_start: VAddr,
_tdata_length: u64,
_total_size: u64,
_align: u64,
) -> Result<(), ElfLoaderErr>
fn tls( &mut self, _tdata_start: VAddr, _tdata_length: u64, _total_size: u64, _align: u64, ) -> Result<(), ElfLoaderErr>
Inform client about where the initial TLS data is located.
Sourcefn make_readonly(
&mut self,
_base: VAddr,
_size: usize,
) -> Result<(), ElfLoaderErr>
fn make_readonly( &mut self, _base: VAddr, _size: usize, ) -> Result<(), ElfLoaderErr>
In case there is a .data.rel.ro section we instruct the loader
to change the passed offset to read-only (this is called after
the relocate calls are completed).
Note: The default implementation is a no-op since this is not strictly necessary to implement.