use crate::{
arch::NativeArch,
elf::{ElfHeader, ElfLayout, ElfPhdr, ElfProgramType, NativeElfLayout},
image::RawDynamic,
input::{ElfReader, Path},
memory::{HostRegion, RegionAccess},
relocation::RelocationArch,
tls::TlsResolver,
};
pub struct BeforeLoadEvent<'a, D: 'static, L: ElfLayout = NativeElfLayout> {
path: &'a Path,
reader: &'a dyn ElfReader,
ehdr: &'a ElfHeader<L>,
phdrs: &'a [ElfPhdr<L>],
user_data: &'a mut D,
}
impl<'a, D: 'static, L: ElfLayout> BeforeLoadEvent<'a, D, L> {
#[inline]
pub(crate) const fn new(
path: &'a Path,
reader: &'a dyn ElfReader,
ehdr: &'a ElfHeader<L>,
phdrs: &'a [ElfPhdr<L>],
user_data: &'a mut D,
) -> Self {
Self {
path,
reader,
ehdr,
phdrs,
user_data,
}
}
#[inline]
pub const fn path(&self) -> &Path {
self.path
}
#[inline]
pub const fn reader(&self) -> &dyn ElfReader {
self.reader
}
#[inline]
pub const fn ehdr(&self) -> &ElfHeader<L> {
self.ehdr
}
#[inline]
pub const fn phdrs(&self) -> &[ElfPhdr<L>] {
self.phdrs
}
#[inline]
pub fn is_dynamic(&self) -> bool {
self.phdrs
.iter()
.any(|phdr| phdr.program_type() == ElfProgramType::DYNAMIC)
}
#[inline]
pub const fn user_data(&self) -> &D {
self.user_data
}
#[inline]
pub fn user_data_mut(&mut self) -> &mut D {
self.user_data
}
}
pub struct AfterDynamicLoadEvent<
'a,
D: 'static,
Arch: RelocationArch = NativeArch,
R: RegionAccess = HostRegion,
Tls: TlsResolver<Arch> = (),
> {
raw: &'a mut RawDynamic<D, Arch, R, Tls>,
}
impl<'a, D: 'static, Arch, R, Tls> AfterDynamicLoadEvent<'a, D, Arch, R, Tls>
where
Arch: RelocationArch,
R: RegionAccess,
Tls: TlsResolver<Arch>,
{
#[inline]
pub(crate) const fn new(raw: &'a mut RawDynamic<D, Arch, R, Tls>) -> Self {
Self { raw }
}
#[inline]
pub const fn raw(&self) -> &RawDynamic<D, Arch, R, Tls> {
self.raw
}
#[inline]
pub fn raw_mut(&mut self) -> &mut RawDynamic<D, Arch, R, Tls> {
self.raw
}
}