`funcref`s are implemented as `NonNull<VMCallerCheckedAnyfunc>`. This should be more efficient than using a `VMExternRef` that points at a `VMCallerCheckedAnyfunc` because it gets rid of an indirection, dynamic allocation, and some reference counting. Note that the null function reference is *NOT* a null pointer; it is a `VMCallerCheckedAnyfunc` that has a null `func_ptr` member. Part of #929
90 lines
2.3 KiB
Rust
90 lines
2.3 KiB
Rust
use crate::vmcontext::{
|
|
VMCallerCheckedAnyfunc, VMContext, VMGlobalDefinition, VMMemoryDefinition, VMTableDefinition,
|
|
};
|
|
use std::ptr::NonNull;
|
|
use wasmtime_environ::wasm::Global;
|
|
use wasmtime_environ::{MemoryPlan, TablePlan};
|
|
|
|
/// The value of an export passed from one instance to another.
|
|
#[derive(Debug, Clone)]
|
|
pub enum Export {
|
|
/// A function export value.
|
|
Function(ExportFunction),
|
|
|
|
/// A table export value.
|
|
Table(ExportTable),
|
|
|
|
/// A memory export value.
|
|
Memory(ExportMemory),
|
|
|
|
/// A global export value.
|
|
Global(ExportGlobal),
|
|
}
|
|
|
|
/// A function export value.
|
|
#[derive(Debug, Clone)]
|
|
pub struct ExportFunction {
|
|
/// The `VMCallerCheckedAnyfunc` for this exported function.
|
|
///
|
|
/// Note that exported functions cannot be a null funcref, so this is a
|
|
/// non-null pointer.
|
|
pub anyfunc: NonNull<VMCallerCheckedAnyfunc>,
|
|
}
|
|
|
|
impl From<ExportFunction> for Export {
|
|
fn from(func: ExportFunction) -> Export {
|
|
Export::Function(func)
|
|
}
|
|
}
|
|
|
|
/// A table export value.
|
|
#[derive(Debug, Clone)]
|
|
pub struct ExportTable {
|
|
/// The address of the table descriptor.
|
|
pub definition: *mut VMTableDefinition,
|
|
/// Pointer to the containing `VMContext`.
|
|
pub vmctx: *mut VMContext,
|
|
/// The table declaration, used for compatibilty checking.
|
|
pub table: TablePlan,
|
|
}
|
|
|
|
impl From<ExportTable> for Export {
|
|
fn from(func: ExportTable) -> Export {
|
|
Export::Table(func)
|
|
}
|
|
}
|
|
|
|
/// A memory export value.
|
|
#[derive(Debug, Clone)]
|
|
pub struct ExportMemory {
|
|
/// The address of the memory descriptor.
|
|
pub definition: *mut VMMemoryDefinition,
|
|
/// Pointer to the containing `VMContext`.
|
|
pub vmctx: *mut VMContext,
|
|
/// The memory declaration, used for compatibilty checking.
|
|
pub memory: MemoryPlan,
|
|
}
|
|
|
|
impl From<ExportMemory> for Export {
|
|
fn from(func: ExportMemory) -> Export {
|
|
Export::Memory(func)
|
|
}
|
|
}
|
|
|
|
/// A global export value.
|
|
#[derive(Debug, Clone)]
|
|
pub struct ExportGlobal {
|
|
/// The address of the global storage.
|
|
pub definition: *mut VMGlobalDefinition,
|
|
/// Pointer to the containing `VMContext`.
|
|
pub vmctx: *mut VMContext,
|
|
/// The global declaration, used for compatibilty checking.
|
|
pub global: Global,
|
|
}
|
|
|
|
impl From<ExportGlobal> for Export {
|
|
fn from(func: ExportGlobal) -> Export {
|
|
Export::Global(func)
|
|
}
|
|
}
|