pub struct Linker {
linker_state: Arc<RwLock<LinkerState>>,
instance_group_state: Arc<Mutex<Option<InstanceGroupState>>>,
dl_operation_pending: Arc<AtomicBool>,
}
Expand description
The linker is responsible for loading and linking dynamic modules at runtime, and managing the shared memory and indirect function table. Each linker instance represents a specific instance group. Cloning a linker instance does not create a new instance group though; the clone will refer to the same group as the original.
Fields§
§linker_state: Arc<RwLock<LinkerState>>
§instance_group_state: Arc<Mutex<Option<InstanceGroupState>>>
§dl_operation_pending: Arc<AtomicBool>
Implementations§
Source§impl Linker
impl Linker
Sourcepub fn new(
main_module: &Module,
store: &mut StoreMut<'_>,
memory: Option<Memory>,
func_env: &mut WasiFunctionEnv,
stack_size: u64,
) -> Result<(Self, LinkedMainModule), LinkError>
pub fn new( main_module: &Module, store: &mut StoreMut<'_>, memory: Option<Memory>, func_env: &mut WasiFunctionEnv, stack_size: u64, ) -> Result<(Self, LinkedMainModule), LinkError>
Creates a new linker for the given main module. The module is expected to be a PIE executable. Imports for the module will be fulfilled, so that it can start running, and a Linker instance is returned which can then be used for the loading/linking of further side modules.
pub fn create_instance_group( &self, parent_ctx: &mut FunctionEnvMut<'_, WasiEnv>, store: &mut StoreMut<'_>, func_env: &mut WasiFunctionEnv, ) -> Result<(Self, LinkedMainModule), LinkError>
pub fn shutdown_instance_group( &self, ctx: &mut FunctionEnvMut<'_, WasiEnv>, ) -> Result<(), LinkError>
Sourcepub fn load_module(
&self,
module_path: impl AsRef<Path>,
library_path: &[impl AsRef<Path>],
ctx: &mut FunctionEnvMut<'_, WasiEnv>,
) -> Result<ModuleHandle, LinkError>
pub fn load_module( &self, module_path: impl AsRef<Path>, library_path: &[impl AsRef<Path>], ctx: &mut FunctionEnvMut<'_, WasiEnv>, ) -> Result<ModuleHandle, LinkError>
Loads a side module from the given path, linking it against the existing module tree
and instantiating it. Symbols from the module can then be retrieved by calling
Linker::resolve_export
.
fn finalize_link_operation( &self, group_state_guard: MutexGuard<'_, Option<InstanceGroupState>>, linker_state: &mut LinkerState, store: &mut impl AsStoreMut, link_state: InProgressLinkState, ) -> Result<(), LinkError>
Sourcepub fn resolve_export(
&self,
ctx: &mut FunctionEnvMut<'_, WasiEnv>,
module_handle: Option<ModuleHandle>,
symbol: &str,
) -> Result<ResolvedExport, ResolveError>
pub fn resolve_export( &self, ctx: &mut FunctionEnvMut<'_, WasiEnv>, module_handle: Option<ModuleHandle>, symbol: &str, ) -> Result<ResolvedExport, ResolveError>
Resolves an export from the module corresponding to the given module handle. Only functions and globals can be resolved.
If the symbol is a global, the returned value will be the absolute address of the data corresponding to that global within the shared linear memory.
If it’s a function, it’ll be placed into the indirect function table, which creates a “function pointer” that can be used from WASM code.
pub fn is_handle_valid( &self, handle: ModuleHandle, ctx: &mut FunctionEnvMut<'_, WasiEnv>, ) -> Result<bool, LinkError>
fn synchronize_link_operation( &self, op: DlOperation, linker_state_write_lock: RwLockWriteGuard<'_, LinkerState>, group_state: &mut InstanceGroupState, wasi_process: &WasiProcess, self_thread_id: WasiThreadId, )
pub(crate) fn do_pending_link_operations( &self, ctx: &mut FunctionEnvMut<'_, WasiEnv>, fast: bool, ) -> Result<(), LinkError>
fn do_pending_link_operations_internal( &self, group_state: &mut InstanceGroupState, store: &mut impl AsStoreMut, env: &FunctionEnv<WasiEnv>, ) -> Result<(), LinkError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Linker
impl RefUnwindSafe for Linker
impl Send for Linker
impl Sync for Linker
impl Unpin for Linker
impl UnwindSafe for Linker
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more