mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-22 13:11:32 +00:00
Add implementations for typed func errors to cranelift and llvm
This commit is contained in:
@ -2,12 +2,13 @@ use crate::relocation::{TrapData, TrapSink};
|
||||
use crate::trampoline::Trampolines;
|
||||
use hashbrown::HashSet;
|
||||
use libc::c_void;
|
||||
use std::{any::Any, cell::Cell, sync::Arc};
|
||||
use std::{any::Any, cell::Cell, ptr::NonNull, sync::Arc};
|
||||
use wasmer_runtime_core::{
|
||||
backend::{ProtectedCaller, Token, UserTrapper},
|
||||
error::RuntimeResult,
|
||||
export::Context,
|
||||
module::{ExportIndex, ModuleInfo, ModuleInner},
|
||||
typed_func::{Wasm, WasmTrapInfo},
|
||||
types::{FuncIndex, FuncSig, LocalOrImport, SigIndex, Type, Value},
|
||||
vm::{self, ImportBacking},
|
||||
};
|
||||
@ -148,6 +149,46 @@ impl ProtectedCaller for Caller {
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn get_wasm_trampoline(&self, module: &ModuleInner, sig_index: SigIndex) -> Option<Wasm> {
|
||||
unsafe extern "C" fn invoke(
|
||||
trampoline: unsafe extern "C" fn(*mut vm::Ctx, NonNull<vm::Func>, *const u64, *mut u64),
|
||||
ctx: *mut vm::Ctx,
|
||||
func: NonNull<vm::Func>,
|
||||
args: *const u64,
|
||||
rets: *mut u64,
|
||||
trap_info: *mut WasmTrapInfo,
|
||||
invoke_env: Option<NonNull<c_void>>,
|
||||
) -> bool {
|
||||
let handler_data = &*invoke_env.unwrap().cast().as_ptr();
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
let res = call_protected(handler_data, || unsafe {
|
||||
// Leap of faith.
|
||||
trampoline(ctx, func, args, rets);
|
||||
})
|
||||
.is_ok();
|
||||
|
||||
// the trampoline is called from C on windows
|
||||
#[cfg(target_os = "windows")]
|
||||
let res = call_protected(handler_data, trampoline, ctx, func, args, rets).is_ok();
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
let trampoline = self
|
||||
.trampolines
|
||||
.lookup(sig_index)
|
||||
.expect("that trampoline doesn't exist");
|
||||
|
||||
Some(unsafe {
|
||||
Wasm::from_raw_parts(
|
||||
trampoline,
|
||||
invoke,
|
||||
Some(NonNull::from(&self.handler_data).cast()),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn get_early_trapper(&self) -> Box<dyn UserTrapper> {
|
||||
Box::new(Trapper)
|
||||
}
|
||||
@ -157,7 +198,7 @@ fn get_func_from_index<'a>(
|
||||
module: &'a ModuleInner,
|
||||
import_backing: &ImportBacking,
|
||||
func_index: FuncIndex,
|
||||
) -> (*const vm::Func, Context, &'a FuncSig, SigIndex) {
|
||||
) -> (NonNull<vm::Func>, Context, &'a FuncSig, SigIndex) {
|
||||
let sig_index = *module
|
||||
.info
|
||||
.func_assoc
|
||||
@ -170,14 +211,13 @@ fn get_func_from_index<'a>(
|
||||
.func_resolver
|
||||
.get(&module, local_func_index)
|
||||
.expect("broken invariant, func resolver not synced with module.exports")
|
||||
.cast()
|
||||
.as_ptr() as *const _,
|
||||
.cast(),
|
||||
Context::Internal,
|
||||
),
|
||||
LocalOrImport::Import(imported_func_index) => {
|
||||
let imported_func = import_backing.imported_func(imported_func_index);
|
||||
(
|
||||
imported_func.func as *const _,
|
||||
NonNull::new(imported_func.func as *mut _).unwrap(),
|
||||
Context::External(imported_func.vmctx),
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user