mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-24 22:21:32 +00:00
feat(runtime-core) Feed imported functions with vm::Ctx
again.
… and look for the associated `vm::FuncCtx`. This way, we don't break the rule: “all functions receive a vmctx pointer as first argument.”.
This commit is contained in:
@ -502,7 +502,7 @@ macro_rules! impl_traits {
|
||||
// able to unwind through this function.
|
||||
#[cfg_attr(nightly, unwind(allowed))]
|
||||
extern fn wrap<$( $x, )* Rets, Trap, FN>(
|
||||
func_ctx: &mut vm::FuncCtx $( , $x: <$x as WasmExternType>::Native )*
|
||||
vmctx: &vm::Ctx $( , $x: <$x as WasmExternType>::Native )*
|
||||
) -> Rets::CStruct
|
||||
where
|
||||
$( $x: WasmExternType, )*
|
||||
@ -510,6 +510,25 @@ macro_rules! impl_traits {
|
||||
Trap: TrapEarly<Rets>,
|
||||
FN: Fn(&mut vm::Ctx, $( $x, )*) -> Trap,
|
||||
{
|
||||
// Get the pointer to this `wrap` function.
|
||||
let self_pointer = wrap::<$( $x, )* Rets, Trap, FN> as *const vm::Func;
|
||||
|
||||
// Get the collection of imported functions.
|
||||
let vm_imported_functions = unsafe { &(*vmctx.import_backing).vm_functions };
|
||||
|
||||
// Retrieve the `vm::FuncCtx`.
|
||||
let mut func_ctx: NonNull<vm::FuncCtx> = vm_imported_functions
|
||||
.iter()
|
||||
.find_map(|(_, imported_func)| {
|
||||
if imported_func.func == self_pointer {
|
||||
Some(imported_func.func_ctx)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.expect("Import backing is not well-formed, cannot find `func_ctx`.");
|
||||
let func_ctx = unsafe { func_ctx.as_mut() };
|
||||
|
||||
// Extract `vm::Ctx` from `vm::FuncCtx`. The
|
||||
// pointer is always non-null.
|
||||
let vmctx = unsafe { func_ctx.vmctx.as_mut() };
|
||||
@ -598,7 +617,7 @@ macro_rules! impl_traits {
|
||||
// able to unwind through this function.
|
||||
#[cfg_attr(nightly, unwind(allowed))]
|
||||
extern fn wrap<$( $x, )* Rets, Trap, FN>(
|
||||
func_ctx: &mut vm::FuncCtx $( , $x: <$x as WasmExternType>::Native )*
|
||||
vmctx: &vm::Ctx $( , $x: <$x as WasmExternType>::Native )*
|
||||
) -> Rets::CStruct
|
||||
where
|
||||
$( $x: WasmExternType, )*
|
||||
@ -606,6 +625,25 @@ macro_rules! impl_traits {
|
||||
Trap: TrapEarly<Rets>,
|
||||
FN: Fn($( $x, )*) -> Trap,
|
||||
{
|
||||
// Get the pointer to this `wrap` function.
|
||||
let self_pointer = wrap::<$( $x, )* Rets, Trap, FN> as *const vm::Func;
|
||||
|
||||
// Get the collection of imported functions.
|
||||
let vm_imported_functions = unsafe { &(*vmctx.import_backing).vm_functions };
|
||||
|
||||
// Retrieve the `vm::FuncCtx`.
|
||||
let mut func_ctx: NonNull<vm::FuncCtx> = vm_imported_functions
|
||||
.iter()
|
||||
.find_map(|(_, imported_func)| {
|
||||
if imported_func.func == self_pointer {
|
||||
Some(imported_func.func_ctx)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.expect("Import backing is not well-formed, cannot find `func_ctx`.");
|
||||
let func_ctx = unsafe { func_ctx.as_mut() };
|
||||
|
||||
// Extract `vm::Ctx` from `vm::FuncCtx`. The
|
||||
// pointer is always non-null.
|
||||
let vmctx = unsafe { func_ctx.vmctx.as_mut() };
|
||||
|
Reference in New Issue
Block a user