mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 13:48:26 +00:00
Remove VMContext port to union, split into #1753
This commit is contained in:
22
lib/api/src/externals/function.rs
vendored
22
lib/api/src/externals/function.rs
vendored
@@ -11,8 +11,8 @@ use std::cmp::max;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use wasmer_vm::{
|
use wasmer_vm::{
|
||||||
raise_user_trap, resume_panic, wasmer_call_trampoline, Export, ExportFunction,
|
raise_user_trap, resume_panic, wasmer_call_trampoline, Export, ExportFunction,
|
||||||
FunctionExtraData, VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext, VMFunctionBody,
|
VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext, VMFunctionBody, VMFunctionKind,
|
||||||
VMFunctionKind, VMTrampoline,
|
VMTrampoline,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A function defined in the Wasm module
|
/// A function defined in the Wasm module
|
||||||
@@ -85,9 +85,7 @@ impl Function {
|
|||||||
// The engine linker will replace the address with one pointing to a
|
// The engine linker will replace the address with one pointing to a
|
||||||
// generated dynamic trampoline.
|
// generated dynamic trampoline.
|
||||||
let address = std::ptr::null() as *const VMFunctionBody;
|
let address = std::ptr::null() as *const VMFunctionBody;
|
||||||
let vmctx = FunctionExtraData {
|
let vmctx = Box::into_raw(Box::new(dynamic_ctx)) as *mut VMContext;
|
||||||
host_env: Box::into_raw(Box::new(dynamic_ctx)) as *mut _,
|
|
||||||
};
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
store: store.clone(),
|
store: store.clone(),
|
||||||
@@ -142,9 +140,7 @@ impl Function {
|
|||||||
// The engine linker will replace the address with one pointing to a
|
// The engine linker will replace the address with one pointing to a
|
||||||
// generated dynamic trampoline.
|
// generated dynamic trampoline.
|
||||||
let address = std::ptr::null() as *const VMFunctionBody;
|
let address = std::ptr::null() as *const VMFunctionBody;
|
||||||
let vmctx = FunctionExtraData {
|
let vmctx = Box::into_raw(Box::new(dynamic_ctx)) as *mut VMContext;
|
||||||
host_env: Box::into_raw(Box::new(dynamic_ctx)) as *mut _,
|
|
||||||
};
|
|
||||||
// TODO: look into removing transmute by changing API type signatures
|
// TODO: look into removing transmute by changing API type signatures
|
||||||
let function_ptr = Some(unsafe { std::mem::transmute::<fn(_, _), fn(_, _)>(Env::finish) });
|
let function_ptr = Some(unsafe { std::mem::transmute::<fn(_, _), fn(_, _)>(Env::finish) });
|
||||||
//dbg!(function_ptr);
|
//dbg!(function_ptr);
|
||||||
@@ -189,9 +185,7 @@ impl Function {
|
|||||||
{
|
{
|
||||||
let function = inner::Function::<Args, Rets>::new(func);
|
let function = inner::Function::<Args, Rets>::new(func);
|
||||||
let address = function.address() as *const VMFunctionBody;
|
let address = function.address() as *const VMFunctionBody;
|
||||||
let vmctx = FunctionExtraData {
|
let vmctx = std::ptr::null_mut() as *mut VMContext;
|
||||||
host_env: std::ptr::null_mut() as *mut _,
|
|
||||||
};
|
|
||||||
let signature = function.ty();
|
let signature = function.ty();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@@ -252,9 +246,7 @@ impl Function {
|
|||||||
// In the case of Host-defined functions `VMContext` is whatever environment
|
// In the case of Host-defined functions `VMContext` is whatever environment
|
||||||
// the user want to attach to the function.
|
// the user want to attach to the function.
|
||||||
let box_env = Box::new(env);
|
let box_env = Box::new(env);
|
||||||
let vmctx = FunctionExtraData {
|
let vmctx = Box::into_raw(box_env) as *mut VMContext;
|
||||||
host_env: Box::into_raw(box_env) as *mut _,
|
|
||||||
};
|
|
||||||
// TODO: look into removing transmute by changing API type signatures
|
// TODO: look into removing transmute by changing API type signatures
|
||||||
let function_ptr = Some(unsafe { std::mem::transmute::<fn(_, _), fn(_, _)>(Env::finish) });
|
let function_ptr = Some(unsafe { std::mem::transmute::<fn(_, _), fn(_, _)>(Env::finish) });
|
||||||
//dbg!(function_ptr as usize);
|
//dbg!(function_ptr as usize);
|
||||||
@@ -393,7 +385,7 @@ impl Function {
|
|||||||
Self {
|
Self {
|
||||||
store: store.clone(),
|
store: store.clone(),
|
||||||
definition: FunctionDefinition::Host(HostFunctionDefinition {
|
definition: FunctionDefinition::Host(HostFunctionDefinition {
|
||||||
has_env: !unsafe { wasmer_export.vmctx.host_env.is_null() },
|
has_env: !wasmer_export.vmctx.is_null(),
|
||||||
}),
|
}),
|
||||||
exported: wasmer_export,
|
exported: wasmer_export,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ use crate::{FromToNativeWasmType, Function, FunctionType, RuntimeError, Store, W
|
|||||||
use std::panic::{catch_unwind, AssertUnwindSafe};
|
use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||||
use wasmer_types::NativeWasmType;
|
use wasmer_types::NativeWasmType;
|
||||||
use wasmer_vm::{
|
use wasmer_vm::{
|
||||||
ExportFunction, FunctionExtraData, VMContext, VMDynamicFunctionContext, VMFunctionBody,
|
ExportFunction, VMContext, VMDynamicFunctionContext, VMFunctionBody, VMFunctionKind,
|
||||||
VMFunctionKind,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A WebAssembly function that can be called natively
|
/// A WebAssembly function that can be called natively
|
||||||
@@ -27,7 +26,7 @@ pub struct NativeFunc<'a, Args = (), Rets = ()> {
|
|||||||
definition: FunctionDefinition,
|
definition: FunctionDefinition,
|
||||||
store: Store,
|
store: Store,
|
||||||
address: *const VMFunctionBody,
|
address: *const VMFunctionBody,
|
||||||
vmctx: FunctionExtraData,
|
vmctx: *mut VMContext,
|
||||||
arg_kind: VMFunctionKind,
|
arg_kind: VMFunctionKind,
|
||||||
// exported: ExportFunction,
|
// exported: ExportFunction,
|
||||||
_phantom: PhantomData<(&'a (), Args, Rets)>,
|
_phantom: PhantomData<(&'a (), Args, Rets)>,
|
||||||
@@ -43,7 +42,7 @@ where
|
|||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
store: Store,
|
store: Store,
|
||||||
address: *const VMFunctionBody,
|
address: *const VMFunctionBody,
|
||||||
vmctx: FunctionExtraData,
|
vmctx: *mut VMContext,
|
||||||
arg_kind: VMFunctionKind,
|
arg_kind: VMFunctionKind,
|
||||||
definition: FunctionDefinition,
|
definition: FunctionDefinition,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@@ -170,7 +169,7 @@ macro_rules! impl_native_traits {
|
|||||||
match self.arg_kind {
|
match self.arg_kind {
|
||||||
VMFunctionKind::Static => {
|
VMFunctionKind::Static => {
|
||||||
let results = catch_unwind(AssertUnwindSafe(|| unsafe {
|
let results = catch_unwind(AssertUnwindSafe(|| unsafe {
|
||||||
let f = std::mem::transmute::<_, unsafe extern "C" fn( FunctionExtraData, $( $x, )*) -> Rets::CStruct>(self.address);
|
let f = std::mem::transmute::<_, unsafe extern "C" fn( *mut VMContext, $( $x, )*) -> Rets::CStruct>(self.address);
|
||||||
// We always pass the vmctx
|
// We always pass the vmctx
|
||||||
f( self.vmctx, $( $x, )* )
|
f( self.vmctx, $( $x, )* )
|
||||||
})).map_err(|e| RuntimeError::new(format!("{:?}", e)))?;
|
})).map_err(|e| RuntimeError::new(format!("{:?}", e)))?;
|
||||||
@@ -180,16 +179,12 @@ macro_rules! impl_native_traits {
|
|||||||
let params_list = [ $( $x.to_native().to_value() ),* ];
|
let params_list = [ $( $x.to_native().to_value() ),* ];
|
||||||
let results = if !has_env {
|
let results = if !has_env {
|
||||||
type VMContextWithoutEnv = VMDynamicFunctionContext<VMDynamicFunctionWithoutEnv>;
|
type VMContextWithoutEnv = VMDynamicFunctionContext<VMDynamicFunctionWithoutEnv>;
|
||||||
unsafe {
|
let ctx = self.vmctx as *mut VMContextWithoutEnv;
|
||||||
let ctx = self.vmctx.host_env as *mut VMContextWithoutEnv;
|
unsafe { (*ctx).ctx.call(¶ms_list)? }
|
||||||
(*ctx).ctx.call(¶ms_list)?
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
type VMContextWithEnv = VMDynamicFunctionContext<VMDynamicFunctionWithEnv<std::ffi::c_void>>;
|
type VMContextWithEnv = VMDynamicFunctionContext<VMDynamicFunctionWithEnv<std::ffi::c_void>>;
|
||||||
unsafe {
|
let ctx = self.vmctx as *mut VMContextWithEnv;
|
||||||
let ctx = self.vmctx.host_env as *mut VMContextWithEnv;
|
unsafe { (*ctx).ctx.call(¶ms_list)? }
|
||||||
(*ctx).ctx.call(¶ms_list)?
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let mut rets_list_array = Rets::empty_array();
|
let mut rets_list_array = Rets::empty_array();
|
||||||
let mut_rets = rets_list_array.as_mut() as *mut [i128] as *mut i128;
|
let mut_rets = rets_list_array.as_mut() as *mut [i128] as *mut i128;
|
||||||
|
|||||||
@@ -56,9 +56,7 @@ impl ValFuncRef for Val {
|
|||||||
Self::ExternRef(ExternRef::Null) => wasmer_vm::VMCallerCheckedAnyfunc {
|
Self::ExternRef(ExternRef::Null) => wasmer_vm::VMCallerCheckedAnyfunc {
|
||||||
func_ptr: ptr::null(),
|
func_ptr: ptr::null(),
|
||||||
type_index: wasmer_vm::VMSharedSignatureIndex::default(),
|
type_index: wasmer_vm::VMSharedSignatureIndex::default(),
|
||||||
vmctx: wasmer_vm::FunctionExtraData {
|
vmctx: ptr::null_mut(),
|
||||||
host_env: ptr::null_mut(),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Self::FuncRef(f) => f.checked_anyfunc(),
|
Self::FuncRef(f) => f.checked_anyfunc(),
|
||||||
_ => return Err(RuntimeError::new("val is not funcref")),
|
_ => return Err(RuntimeError::new("val is not funcref")),
|
||||||
|
|||||||
@@ -112,10 +112,7 @@ pub trait Artifact: Send + Sync + Upcastable {
|
|||||||
.cloned()
|
.cloned()
|
||||||
.zip(imports.functions.values())
|
.zip(imports.functions.values())
|
||||||
{
|
{
|
||||||
let host_env = unsafe {
|
let host_env = func.vmctx as _;
|
||||||
//dbg!(func.extra_data.host_env);
|
|
||||||
func.extra_data.host_env
|
|
||||||
};
|
|
||||||
thunks.push((func_init, host_env));
|
thunks.push((func_init, host_env));
|
||||||
}
|
}
|
||||||
// ------------
|
// ------------
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ pub fn resolve_imports(
|
|||||||
};
|
};
|
||||||
function_imports.push(VMFunctionImport {
|
function_imports.push(VMFunctionImport {
|
||||||
body: address,
|
body: address,
|
||||||
extra_data: f.vmctx,
|
vmctx: f.vmctx,
|
||||||
});
|
});
|
||||||
|
|
||||||
host_function_env_initializers.push(f.function_ptr);
|
host_function_env_initializers.push(f.function_ptr);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ pub struct ExportFunction {
|
|||||||
/// The address of the native-code function.
|
/// The address of the native-code function.
|
||||||
pub address: *const VMFunctionBody,
|
pub address: *const VMFunctionBody,
|
||||||
/// Pointer to the containing `VMContext`.
|
/// Pointer to the containing `VMContext`.
|
||||||
pub vmctx: crate::vmcontext::FunctionExtraData,
|
pub vmctx: *mut VMContext,
|
||||||
/// temp code to set vmctx for host functions
|
/// temp code to set vmctx for host functions
|
||||||
pub function_ptr: Option<fn(*mut std::ffi::c_void, *const std::ffi::c_void)>,
|
pub function_ptr: Option<fn(*mut std::ffi::c_void, *const std::ffi::c_void)>,
|
||||||
/// The function type, used for compatibility checking.
|
/// The function type, used for compatibility checking.
|
||||||
|
|||||||
@@ -317,15 +317,13 @@ impl Instance {
|
|||||||
if let Some(def_index) = self.module.local_func_index(*index) {
|
if let Some(def_index) = self.module.local_func_index(*index) {
|
||||||
(
|
(
|
||||||
self.functions[def_index].0 as *const _,
|
self.functions[def_index].0 as *const _,
|
||||||
crate::vmcontext::FunctionExtraData {
|
self.vmctx_ptr(),
|
||||||
vmctx: self.vmctx_ptr(),
|
|
||||||
},
|
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let import = self.imported_function(*index);
|
let import = self.imported_function(*index);
|
||||||
let initializer = self.imported_function_env_initializer(*index);
|
let initializer = self.imported_function_env_initializer(*index);
|
||||||
(import.body, import.extra_data, initializer)
|
(import.body, import.vmctx, initializer)
|
||||||
};
|
};
|
||||||
let call_trampoline = Some(self.function_call_trampolines[*sig_index]);
|
let call_trampoline = Some(self.function_call_trampolines[*sig_index]);
|
||||||
let signature = self.module.signatures[*sig_index].clone();
|
let signature = self.module.signatures[*sig_index].clone();
|
||||||
@@ -404,27 +402,21 @@ impl Instance {
|
|||||||
.get(local_index)
|
.get(local_index)
|
||||||
.expect("function index is out of bounds")
|
.expect("function index is out of bounds")
|
||||||
.0;
|
.0;
|
||||||
(
|
(body as *const _, self.vmctx_ptr())
|
||||||
body as *const _,
|
|
||||||
crate::FunctionExtraData {
|
|
||||||
vmctx: self.vmctx_ptr(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
assert_lt!(start_index.index(), self.module.num_imported_functions);
|
assert_lt!(start_index.index(), self.module.num_imported_functions);
|
||||||
let import = self.imported_function(start_index);
|
let import = self.imported_function(start_index);
|
||||||
(import.body, import.extra_data)
|
(import.body, import.vmctx)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Make the call.
|
// Make the call.
|
||||||
unsafe {
|
unsafe {
|
||||||
catch_traps(callee_extra_data, || {
|
catch_traps(callee_extra_data, || {
|
||||||
mem::transmute::<
|
mem::transmute::<*const VMFunctionBody, unsafe extern "C" fn(*mut VMContext)>(
|
||||||
*const VMFunctionBody,
|
callee_address,
|
||||||
unsafe extern "C" fn(crate::FunctionExtraData),
|
)(callee_extra_data)
|
||||||
>(callee_address)(callee_extra_data)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -594,15 +586,10 @@ impl Instance {
|
|||||||
let type_index = self.signature_id(sig);
|
let type_index = self.signature_id(sig);
|
||||||
|
|
||||||
let (func_ptr, vmctx) = if let Some(def_index) = self.module.local_func_index(index) {
|
let (func_ptr, vmctx) = if let Some(def_index) = self.module.local_func_index(index) {
|
||||||
(
|
(self.functions[def_index].0 as *const _, self.vmctx_ptr())
|
||||||
self.functions[def_index].0 as *const _,
|
|
||||||
crate::FunctionExtraData {
|
|
||||||
vmctx: self.vmctx_ptr(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
let import = self.imported_function(index);
|
let import = self.imported_function(index);
|
||||||
(import.body, import.extra_data)
|
(import.body, import.vmctx)
|
||||||
};
|
};
|
||||||
VMCallerCheckedAnyfunc {
|
VMCallerCheckedAnyfunc {
|
||||||
func_ptr,
|
func_ptr,
|
||||||
|
|||||||
@@ -48,10 +48,10 @@ pub use crate::sig_registry::SignatureRegistry;
|
|||||||
pub use crate::table::{LinearTable, Table, TableStyle};
|
pub use crate::table::{LinearTable, Table, TableStyle};
|
||||||
pub use crate::trap::*;
|
pub use crate::trap::*;
|
||||||
pub use crate::vmcontext::{
|
pub use crate::vmcontext::{
|
||||||
FunctionExtraData, VMBuiltinFunctionIndex, VMCallerCheckedAnyfunc, VMContext,
|
VMBuiltinFunctionIndex, VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext,
|
||||||
VMDynamicFunctionContext, VMFunctionBody, VMFunctionImport, VMFunctionKind, VMGlobalDefinition,
|
VMFunctionBody, VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport,
|
||||||
VMGlobalImport, VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition,
|
VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport,
|
||||||
VMTableImport, VMTrampoline,
|
VMTrampoline,
|
||||||
};
|
};
|
||||||
pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMOffsets};
|
pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMOffsets};
|
||||||
|
|
||||||
|
|||||||
@@ -429,13 +429,13 @@ impl Trap {
|
|||||||
/// Wildly unsafe because it calls raw function pointers and reads/writes raw
|
/// Wildly unsafe because it calls raw function pointers and reads/writes raw
|
||||||
/// function pointers.
|
/// function pointers.
|
||||||
pub unsafe fn wasmer_call_trampoline(
|
pub unsafe fn wasmer_call_trampoline(
|
||||||
vmctx: crate::FunctionExtraData,
|
vmctx: *mut VMContext,
|
||||||
trampoline: VMTrampoline,
|
trampoline: VMTrampoline,
|
||||||
callee: *const VMFunctionBody,
|
callee: *const VMFunctionBody,
|
||||||
values_vec: *mut u8,
|
values_vec: *mut u8,
|
||||||
) -> Result<(), Trap> {
|
) -> Result<(), Trap> {
|
||||||
catch_traps(vmctx, || {
|
catch_traps(vmctx, || {
|
||||||
mem::transmute::<_, extern "C" fn(crate::FunctionExtraData, *const VMFunctionBody, *mut u8)>(
|
mem::transmute::<_, extern "C" fn(*mut VMContext, *const VMFunctionBody, *mut u8)>(
|
||||||
trampoline,
|
trampoline,
|
||||||
)(vmctx, callee, values_vec)
|
)(vmctx, callee, values_vec)
|
||||||
})
|
})
|
||||||
@@ -447,7 +447,7 @@ pub unsafe fn wasmer_call_trampoline(
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// Highly unsafe since `closure` won't have any destructors run.
|
/// Highly unsafe since `closure` won't have any destructors run.
|
||||||
pub unsafe fn catch_traps<F>(vmctx: crate::FunctionExtraData, mut closure: F) -> Result<(), Trap>
|
pub unsafe fn catch_traps<F>(vmctx: *mut VMContext, mut closure: F) -> Result<(), Trap>
|
||||||
where
|
where
|
||||||
F: FnMut(),
|
F: FnMut(),
|
||||||
{
|
{
|
||||||
@@ -481,7 +481,7 @@ where
|
|||||||
///
|
///
|
||||||
/// Check [`catch_traps`].
|
/// Check [`catch_traps`].
|
||||||
pub unsafe fn catch_traps_with_result<F, R>(
|
pub unsafe fn catch_traps_with_result<F, R>(
|
||||||
vmctx: crate::FunctionExtraData,
|
vmctx: *mut VMContext,
|
||||||
mut closure: F,
|
mut closure: F,
|
||||||
) -> Result<R, Trap>
|
) -> Result<R, Trap>
|
||||||
where
|
where
|
||||||
@@ -501,7 +501,7 @@ pub struct CallThreadState {
|
|||||||
jmp_buf: Cell<*const u8>,
|
jmp_buf: Cell<*const u8>,
|
||||||
reset_guard_page: Cell<bool>,
|
reset_guard_page: Cell<bool>,
|
||||||
prev: Option<*const CallThreadState>,
|
prev: Option<*const CallThreadState>,
|
||||||
vmctx: crate::FunctionExtraData,
|
vmctx: *mut VMContext,
|
||||||
handling_trap: Cell<bool>,
|
handling_trap: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,7 +518,7 @@ enum UnwindReason {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CallThreadState {
|
impl CallThreadState {
|
||||||
fn new(vmctx: crate::FunctionExtraData) -> Self {
|
fn new(vmctx: *mut VMContext) -> Self {
|
||||||
Self {
|
Self {
|
||||||
unwind: Cell::new(UnwindReason::None),
|
unwind: Cell::new(UnwindReason::None),
|
||||||
vmctx,
|
vmctx,
|
||||||
@@ -561,7 +561,7 @@ impl CallThreadState {
|
|||||||
|
|
||||||
fn any_instance(&self, func: impl Fn(&InstanceHandle) -> bool) -> bool {
|
fn any_instance(&self, func: impl Fn(&InstanceHandle) -> bool) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
if func(&InstanceHandle::from_vmctx(self.vmctx.vmctx)) {
|
if func(&InstanceHandle::from_vmctx(self.vmctx)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
match self.prev {
|
match self.prev {
|
||||||
|
|||||||
@@ -15,29 +15,6 @@ use std::ptr::{self, NonNull};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::u32;
|
use std::u32;
|
||||||
|
|
||||||
/// We stop lying about what this daat is
|
|
||||||
/// TODO:
|
|
||||||
#[derive(Copy, Clone)]
|
|
||||||
pub union FunctionExtraData {
|
|
||||||
/// Wasm function, it has a real VMContext:
|
|
||||||
pub vmctx: *mut VMContext,
|
|
||||||
/// Host functions can have custom environments
|
|
||||||
pub host_env: *mut std::ffi::c_void,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Debug for FunctionExtraData {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
||||||
write!(f, "FunctionExtarData union")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::cmp::PartialEq for FunctionExtraData {
|
|
||||||
fn eq(&self, rhs: &Self) -> bool {
|
|
||||||
// TODO
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An imported function.
|
/// An imported function.
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@@ -46,7 +23,7 @@ pub struct VMFunctionImport {
|
|||||||
pub body: *const VMFunctionBody,
|
pub body: *const VMFunctionBody,
|
||||||
|
|
||||||
/// A pointer to the `VMContext` that owns the function or host data.
|
/// A pointer to the `VMContext` that owns the function or host data.
|
||||||
pub extra_data: FunctionExtraData,
|
pub vmctx: *mut VMContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -69,7 +46,7 @@ mod test_vmfunction_import {
|
|||||||
usize::from(offsets.vmfunction_import_body())
|
usize::from(offsets.vmfunction_import_body())
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
offset_of!(VMFunctionImport, extra_data),
|
offset_of!(VMFunctionImport, vmctx),
|
||||||
usize::from(offsets.vmfunction_import_vmctx())
|
usize::from(offsets.vmfunction_import_vmctx())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -752,7 +729,7 @@ pub struct VMCallerCheckedAnyfunc {
|
|||||||
/// Function signature id.
|
/// Function signature id.
|
||||||
pub type_index: VMSharedSignatureIndex,
|
pub type_index: VMSharedSignatureIndex,
|
||||||
/// Function `VMContext`.
|
/// Function `VMContext`.
|
||||||
pub vmctx: FunctionExtraData,
|
pub vmctx: *mut VMContext,
|
||||||
// If more elements are added here, remember to add offset_of tests below!
|
// If more elements are added here, remember to add offset_of tests below!
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -791,9 +768,7 @@ impl Default for VMCallerCheckedAnyfunc {
|
|||||||
Self {
|
Self {
|
||||||
func_ptr: ptr::null_mut(),
|
func_ptr: ptr::null_mut(),
|
||||||
type_index: Default::default(),
|
type_index: Default::default(),
|
||||||
vmctx: FunctionExtraData {
|
vmctx: ptr::null_mut(),
|
||||||
vmctx: ptr::null_mut(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user