mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 05:08:19 +00:00
Merge branch 'master' into fix/host-func-env-memory-leak
This commit is contained in:
@@ -27,10 +27,7 @@ use wasmer_vm::{
|
||||
pub struct NativeFunc<Args = (), Rets = ()> {
|
||||
definition: FunctionDefinition,
|
||||
store: Store,
|
||||
address: *const VMFunctionBody,
|
||||
vmctx: VMFunctionEnvironment,
|
||||
arg_kind: VMFunctionKind,
|
||||
// exported: ExportFunction,
|
||||
exported: ExportFunction,
|
||||
_phantom: PhantomData<(Args, Rets)>,
|
||||
}
|
||||
|
||||
@@ -43,20 +40,28 @@ where
|
||||
{
|
||||
pub(crate) fn new(
|
||||
store: Store,
|
||||
address: *const VMFunctionBody,
|
||||
vmctx: VMFunctionEnvironment,
|
||||
arg_kind: VMFunctionKind,
|
||||
exported: ExportFunction,
|
||||
definition: FunctionDefinition,
|
||||
) -> Self {
|
||||
Self {
|
||||
definition,
|
||||
store,
|
||||
address,
|
||||
vmctx,
|
||||
arg_kind,
|
||||
exported,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn vmctx(&self) -> VMFunctionEnvironment {
|
||||
self.exported.vm_function.vmctx
|
||||
}
|
||||
|
||||
pub(crate) fn address(&self) -> *const VMFunctionBody {
|
||||
self.exported.vm_function.address
|
||||
}
|
||||
|
||||
pub(crate) fn arg_kind(&self) -> VMFunctionKind {
|
||||
self.exported.vm_function.kind
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -84,19 +89,7 @@ where
|
||||
Rets: WasmTypeList,
|
||||
{
|
||||
fn from(other: &NativeFunc<Args, Rets>) -> Self {
|
||||
let signature = FunctionType::new(Args::wasm_types(), Rets::wasm_types());
|
||||
Self {
|
||||
// TODO:
|
||||
metadata: None,
|
||||
vm_function: VMExportFunction {
|
||||
address: other.address,
|
||||
vmctx: other.vmctx,
|
||||
signature,
|
||||
kind: other.arg_kind,
|
||||
call_trampoline: None,
|
||||
instance_allocator: None,
|
||||
},
|
||||
}
|
||||
other.exported.clone()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,22 +99,10 @@ where
|
||||
Rets: WasmTypeList,
|
||||
{
|
||||
fn from(other: NativeFunc<Args, Rets>) -> Self {
|
||||
let signature = FunctionType::new(Args::wasm_types(), Rets::wasm_types());
|
||||
Self {
|
||||
store: other.store,
|
||||
definition: other.definition,
|
||||
exported: ExportFunction {
|
||||
// TODO:
|
||||
metadata: None,
|
||||
vm_function: VMExportFunction {
|
||||
address: other.address,
|
||||
vmctx: other.vmctx,
|
||||
signature,
|
||||
kind: other.arg_kind,
|
||||
call_trampoline: None,
|
||||
instance_allocator: None,
|
||||
},
|
||||
},
|
||||
exported: other.exported.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,9 +139,9 @@ macro_rules! impl_native_traits {
|
||||
};
|
||||
unsafe {
|
||||
wasmer_vm::wasmer_call_trampoline(
|
||||
self.vmctx,
|
||||
self.vmctx(),
|
||||
trampoline,
|
||||
self.address,
|
||||
self.address(),
|
||||
args_rets.as_mut_ptr() as *mut u8,
|
||||
)
|
||||
}?;
|
||||
@@ -182,7 +163,7 @@ macro_rules! impl_native_traits {
|
||||
//
|
||||
// let results = unsafe {
|
||||
// wasmer_vm::catch_traps_with_result(self.vmctx, || {
|
||||
// let f = std::mem::transmute::<_, unsafe extern "C" fn( *mut VMContext, $( $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
|
||||
// f( self.vmctx, $( $x, )* )
|
||||
// }).map_err(RuntimeError::from_trap)?
|
||||
@@ -193,12 +174,12 @@ macro_rules! impl_native_traits {
|
||||
FunctionDefinition::Host(HostFunctionDefinition {
|
||||
has_env
|
||||
}) => {
|
||||
match self.arg_kind {
|
||||
match self.arg_kind() {
|
||||
VMFunctionKind::Static => {
|
||||
let results = catch_unwind(AssertUnwindSafe(|| unsafe {
|
||||
let f = std::mem::transmute::<_, unsafe extern "C" fn( VMFunctionEnvironment, $( $x, )*) -> Rets::CStruct>(self.address);
|
||||
let f = std::mem::transmute::<_, unsafe extern "C" fn( VMFunctionEnvironment, $( $x, )*) -> Rets::CStruct>(self.address());
|
||||
// We always pass the vmctx
|
||||
f( self.vmctx, $( $x, )* )
|
||||
f( self.vmctx(), $( $x, )* )
|
||||
})).map_err(|e| RuntimeError::new(format!("{:?}", e)))?;
|
||||
Ok(Rets::from_c_struct(results))
|
||||
},
|
||||
@@ -207,13 +188,13 @@ macro_rules! impl_native_traits {
|
||||
let results = if !has_env {
|
||||
type VMContextWithoutEnv = VMDynamicFunctionContext<DynamicFunctionWithoutEnv>;
|
||||
unsafe {
|
||||
let ctx = self.vmctx.host_env as *mut VMContextWithoutEnv;
|
||||
let ctx = self.vmctx().host_env as *mut VMContextWithoutEnv;
|
||||
(*ctx).ctx.call(¶ms_list)?
|
||||
}
|
||||
} else {
|
||||
type VMContextWithEnv = VMDynamicFunctionContext<DynamicFunctionWithEnv<std::ffi::c_void>>;
|
||||
unsafe {
|
||||
let ctx = self.vmctx.host_env as *mut VMContextWithEnv;
|
||||
let ctx = self.vmctx().host_env as *mut VMContextWithEnv;
|
||||
(*ctx).ctx.call(¶ms_list)?
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user