use crate::{
Result,
arch::NativeArch,
image::{LoadedCore, RawDynamic},
lazy::{LazyBinder, SupportLazy},
memory::{HostRegion, RegionAccess},
observer::RelocationObserver,
relocation::{Relocatable, RelocateArgs, RelocationArch},
runtime::DomainId,
tls::TlsResolver,
};
use core::{fmt::Debug, ops::Deref};
pub struct RawDylib<D, Arch = NativeArch, R: RegionAccess = HostRegion, Tls: TlsResolver<Arch> = ()>
where
D: Send + Sync + 'static,
Arch: RelocationArch,
{
pub(crate) inner: RawDynamic<D, Arch, R, Tls>,
}
impl<D: Send + Sync + 'static, Arch: RelocationArch, R: RegionAccess, Tls: TlsResolver<Arch>> Debug
for RawDylib<D, Arch, R, Tls>
{
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: Send + Sync + 'static, Arch: RelocationArch, R: RegionAccess, Tls: TlsResolver<Arch>>
SupportLazy for RawDylib<D, Arch, R, Tls>
{
}
impl<D: Send + Sync + 'static, Arch: RelocationArch, R: RegionAccess, Tls: TlsResolver<Arch>>
Relocatable<D> for RawDylib<D, Arch, R, Tls>
{
type Output = LoadedCore<D, Arch, R, Tls>;
type Arch = Arch;
type Tls = Tls;
#[inline]
fn domain_id(&self) -> DomainId {
self.inner.state().domain_id()
}
fn relocate<Obs, Binder>(
self,
args: RelocateArgs<'_, Arch, Tls, Obs, Binder>,
) -> Result<Self::Output>
where
Obs: RelocationObserver<Arch> + ?Sized,
Binder: LazyBinder<Arch> + ?Sized,
{
Relocatable::relocate(self.inner, args)
}
}
impl<D: Send + Sync + 'static, Arch: RelocationArch, R: RegionAccess, Tls: TlsResolver<Arch>>
RawDylib<D, Arch, R, Tls>
{
#[inline]
pub fn user_data_mut(&mut self) -> Option<&mut D> {
self.inner.user_data_mut()
}
}
impl<D: Send + Sync + 'static, Arch: RelocationArch, R: RegionAccess, Tls: TlsResolver<Arch>> Deref
for RawDylib<D, Arch, R, Tls>
{
type Target = RawDynamic<D, Arch, R, Tls>;
#[inline]
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl<D: Send + Sync + 'static, Arch: RelocationArch, R: RegionAccess, Tls: TlsResolver<Arch>>
From<RawDynamic<D, Arch, R, Tls>> for RawDylib<D, Arch, R, Tls>
{
#[inline]
fn from(inner: RawDynamic<D, Arch, R, Tls>) -> Self {
Self { inner }
}
}
impl<D: Send + Sync + 'static, Arch: RelocationArch, R: RegionAccess, Tls: TlsResolver<Arch>>
From<RawDylib<D, Arch, R, Tls>> for RawDynamic<D, Arch, R, Tls>
{
#[inline]
fn from(dylib: RawDylib<D, Arch, R, Tls>) -> Self {
dylib.inner
}
}