pub trait InstantiationHook:
Debug
+ Send
+ Sync
+ 'static {
// Provided methods
fn additional_imports(
&self,
module: &Module,
store: &mut StoreMut<'_>,
) -> Result<(Imports, InstantiationState)> { ... }
fn prepare_imports(
&self,
module: &Module,
store: &mut StoreMut<'_>,
imports: &mut Imports,
) -> Result<InstantiationState> { ... }
fn configure_new_instance(
&self,
module: &Module,
store: &mut StoreMut<'_>,
instance: &Instance,
imported_memory: Option<&Memory>,
state: InstantiationState,
) -> Result<()> { ... }
}Expand description
A hook into the instantiation of WASIX module instances.
Registered on PluggableRuntime::with_instantiation_hook or
OverriddenRuntime::with_instantiation_hook, and invoked once per
instance the runtime creates (process bootstrap, thread spawn, dynamically
linked side module).
Every method has a compatible default, so an implementation only needs to provide the phases it cares about.
Provided Methods§
Sourcefn additional_imports(
&self,
module: &Module,
store: &mut StoreMut<'_>,
) -> Result<(Imports, InstantiationState)>
fn additional_imports( &self, module: &Module, store: &mut StoreMut<'_>, ) -> Result<(Imports, InstantiationState)>
Creates additional imports for an instance about to be created in
store.
The returned InstantiationState is handed back to
InstantiationHook::configure_new_instance for the instance built
with these imports. If instantiation fails, the state is dropped.
Sourcefn prepare_imports(
&self,
module: &Module,
store: &mut StoreMut<'_>,
imports: &mut Imports,
) -> Result<InstantiationState>
fn prepare_imports( &self, module: &Module, store: &mut StoreMut<'_>, imports: &mut Imports, ) -> Result<InstantiationState>
Prepares the complete import object immediately before instantiation.
The default implementation preserves the original
InstantiationHook::additional_imports contract by merging its
returned imports without replacing any entry already present in
imports. This includes imports supplied by WASIX and imports inserted
by earlier hooks. Unlike wasmer::Imports::extend, duplicate entries
from additional_imports do not overwrite existing ones. Hooks that
need to inspect or reuse an existing import, such as an imported memory,
can override this method and update imports in place. Overrides must
preserve existing entries.
Sourcefn configure_new_instance(
&self,
module: &Module,
store: &mut StoreMut<'_>,
instance: &Instance,
imported_memory: Option<&Memory>,
state: InstantiationState,
) -> Result<()>
fn configure_new_instance( &self, module: &Module, store: &mut StoreMut<'_>, instance: &Instance, imported_memory: Option<&Memory>, state: InstantiationState, ) -> Result<()>
Configures an instance after successful instantiation and startup.
state is the InstantiationState this hook returned from the
InstantiationHook::prepare_imports call whose imports the
instance was created with.