pub struct ExportFunctionMetadata {
pub host_env: *mut c_void,
pub import_init_function_ptr: Option<ImportInitializerFuncPtr>,
pub host_env_clone_fn: fn(_: *mut c_void) -> *mut c_void,
pub host_env_drop_fn: unsafe fn(_: *mut c_void),
}
Expand description
Extra metadata about ExportFunction
s.
The metadata acts as a kind of manual virtual dispatch. We store the
user-supplied WasmerEnv
as a void pointer and have methods on it
that have been adapted to accept a void pointer.
This struct owns the original host_env
, thus when it gets dropped
it calls the drop
function on it.
Fields§
§host_env: *mut c_void
This field is stored here to be accessible by Drop
.
At the time it was added, it’s not accessed anywhere outside of
the Drop
implementation. This field is the “master copy” of the env,
that is, the original env passed in by the user. Every time we create
an Instance
we clone this with the host_env_clone_fn
field.
Thus, we only bother to store the master copy at all here so that we can free it.
See wasmer_vm::export::VMFunction::vmctx
for the version of
this pointer that is used by the VM when creating an Instance
.
import_init_function_ptr: Option<ImportInitializerFuncPtr>
Function pointer to WasmerEnv::init_with_instance(&mut self, instance: &Instance)
.
This function is called to finish setting up the environment after
we create the api::Instance
.
host_env_clone_fn: fn(_: *mut c_void) -> *mut c_void
A function analogous to Clone::clone
that returns a leaked Box
.
host_env_drop_fn: unsafe fn(_: *mut c_void)
The destructor to free the host environment.
§Safety
- This function should only be called in when properly synchronized.
For example, in the
Drop
implementation of this type.
Implementations§
Source§impl ExportFunctionMetadata
impl ExportFunctionMetadata
Sourcepub unsafe fn new(
host_env: *mut c_void,
import_init_function_ptr: Option<ImportInitializerFuncPtr>,
host_env_clone_fn: fn(_: *mut c_void) -> *mut c_void,
host_env_drop_fn: fn(_: *mut c_void),
) -> Self
pub unsafe fn new( host_env: *mut c_void, import_init_function_ptr: Option<ImportInitializerFuncPtr>, host_env_clone_fn: fn(_: *mut c_void) -> *mut c_void, host_env_drop_fn: fn(_: *mut c_void), ) -> Self
Create an ExportFunctionMetadata
type with information about
the exported function.
§Safety
- the
host_env
must beSend
. - all function pointers must work on any thread.
Trait Implementations§
Source§impl Debug for ExportFunctionMetadata
impl Debug for ExportFunctionMetadata
Source§impl Drop for ExportFunctionMetadata
impl Drop for ExportFunctionMetadata
Source§impl PartialEq for ExportFunctionMetadata
impl PartialEq for ExportFunctionMetadata
impl Send for ExportFunctionMetadata
This can be Send
because host_env
comes from WasmerEnv
which is
Send
. Therefore all operations should work on any thread.
impl StructuralPartialEq for ExportFunctionMetadata
impl Sync for ExportFunctionMetadata
This data may be shared across threads, drop
is an unsafe function
pointer, so care must be taken when calling it.