use crate::{
Result,
elf::{ElfDyn, ElfPhdr},
image::{ElfCore, LoadedCore, RawDynamic},
input::Path,
relocation::{Relocatable, RelocateArgs, RelocationArch, RelocationHandler, Relocator},
tls::{TlsModuleId, TlsTpOffset},
};
use core::{fmt::Debug, ptr::NonNull};
pub struct RawDylib<D, Arch = crate::arch::NativeArch>
where
D: 'static,
Arch: RelocationArch,
{
pub(crate) inner: RawDynamic<D, Arch>,
}
impl<D, Arch: RelocationArch> Debug for RawDylib<D, Arch> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_struct("RawDylib")
.field("name", &self.inner.name())
.field("needed_libs", &self.inner.needed_libs())
.finish()
}
}
impl<D: 'static, Arch: RelocationArch> Relocatable<D> for RawDylib<D, Arch> {
type Output = LoadedCore<D, Arch>;
type Arch = Arch;
fn relocate<PreH, PostH>(
self,
args: RelocateArgs<'_, D, Arch, PreH, PostH>,
) -> Result<Self::Output>
where
PreH: RelocationHandler<Arch> + ?Sized,
PostH: RelocationHandler<Arch> + ?Sized,
{
Relocatable::relocate(self.inner, args)
}
}
impl<D, Arch: RelocationArch> RawDylib<D, Arch> {
#[inline]
pub fn from_dynamic(inner: RawDynamic<D, Arch>) -> Self {
Self { inner }
}
#[inline]
pub fn into_dynamic(self) -> RawDynamic<D, Arch> {
self.inner
}
#[inline]
pub fn entry(&self) -> usize {
self.inner.entry()
}
#[inline]
pub fn core_ref(&self) -> &ElfCore<D, Arch> {
self.inner.core_ref()
}
#[inline]
pub fn core(&self) -> ElfCore<D, Arch> {
self.inner.core()
}
#[inline]
pub fn into_core(self) -> ElfCore<D, Arch> {
self.inner.into_core()
}
#[inline]
pub fn is_lazy(&self) -> bool {
self.inner.is_lazy()
}
pub fn tls_mod_id(&self) -> Option<TlsModuleId> {
self.inner.tls_mod_id()
}
pub fn tls_tp_offset(&self) -> Option<TlsTpOffset> {
self.inner.tls_tp_offset()
}
#[inline]
pub fn rpath(&self) -> Option<&str> {
self.inner.rpath()
}
#[inline]
pub fn runpath(&self) -> Option<&str> {
self.inner.runpath()
}
#[inline]
pub fn soname(&self) -> Option<&str> {
self.inner.soname()
}
#[inline]
pub fn interp(&self) -> Option<&str> {
self.inner.interp()
}
#[inline]
pub fn path(&self) -> &Path {
self.inner.path()
}
#[inline]
pub fn name(&self) -> &str {
self.inner.name()
}
pub fn phdrs(&self) -> &[ElfPhdr<Arch::Layout>] {
self.inner.phdrs()
}
pub fn base(&self) -> usize {
self.inner.base()
}
pub fn mapped_len(&self) -> usize {
self.inner.mapped_len()
}
pub(crate) fn mapped_base(&self) -> usize {
self.inner.mapped_base()
}
pub fn contains_addr(&self, addr: usize) -> bool {
self.inner.contains_addr(addr)
}
pub fn needed_libs(&self) -> &[&str] {
self.inner.needed_libs()
}
pub fn dynamic_ptr(&self) -> Option<NonNull<ElfDyn<Arch::Layout>>> {
self.inner.dynamic_ptr()
}
pub fn user_data(&self) -> &D {
self.inner.user_data()
}
#[inline]
pub fn user_data_mut(&mut self) -> Option<&mut D> {
self.inner.user_data_mut()
}
pub fn relocator(self) -> Relocator<Self, (), (), D, Arch> {
Relocator::new().with_object(self)
}
}