mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-25 14:41:32 +00:00
Fix LLVM invoke_trampoline.
This commit is contained in:
@ -59,6 +59,7 @@ enum WasmTrapType {
|
||||
MemoryOutOfBounds = 2,
|
||||
CallIndirectOOB = 3,
|
||||
IllegalArithmetic = 4,
|
||||
MisalignedAtomicAccess = 5,
|
||||
Unknown,
|
||||
};
|
||||
|
||||
@ -285,7 +286,7 @@ void module_delete(WasmModule *module) { delete module; }
|
||||
unsafe_unwind(new BreakpointException(callback));
|
||||
}
|
||||
|
||||
bool invoke_trampoline(trampoline_t trampoline, void *ctx, void *func,
|
||||
bool cxx_invoke_trampoline(trampoline_t trampoline, void *ctx, void *func,
|
||||
void *params, void *results, WasmTrapType *trap_out,
|
||||
box_any_t *user_error, void *invoke_env) noexcept {
|
||||
try {
|
||||
|
@ -24,7 +24,7 @@ use std::{
|
||||
use wasmer_runtime_core::{
|
||||
backend::{
|
||||
sys::{Memory, Protect},
|
||||
CacheGen, RunnableModule,
|
||||
CacheGen, ExceptionCode, RunnableModule,
|
||||
},
|
||||
cache::Error as CacheError,
|
||||
module::ModuleInfo,
|
||||
@ -59,7 +59,21 @@ extern "C" {
|
||||
fn throw_any(data: *mut dyn Any) -> !;
|
||||
|
||||
#[allow(improper_ctypes)]
|
||||
fn invoke_trampoline(
|
||||
fn cxx_invoke_trampoline(
|
||||
trampoline: Trampoline,
|
||||
vmctx_ptr: *mut vm::Ctx,
|
||||
func_ptr: NonNull<vm::Func>,
|
||||
params: *const u64,
|
||||
results: *mut u64,
|
||||
trap_out: *mut i32,
|
||||
error_out: *mut Option<Box<dyn Any + Send>>,
|
||||
invoke_env: Option<NonNull<c_void>>,
|
||||
) -> bool;
|
||||
}
|
||||
|
||||
/// `invoke_trampoline` is a wrapper around `cxx_invoke_trampoline`, for fixing up the obsoleted
|
||||
/// `trap_out` in the C++ part.
|
||||
unsafe extern "C" fn invoke_trampoline(
|
||||
trampoline: Trampoline,
|
||||
vmctx_ptr: *mut vm::Ctx,
|
||||
func_ptr: NonNull<vm::Func>,
|
||||
@ -67,7 +81,31 @@ extern "C" {
|
||||
results: *mut u64,
|
||||
error_out: *mut Option<Box<dyn Any + Send>>,
|
||||
invoke_env: Option<NonNull<c_void>>,
|
||||
) -> bool;
|
||||
) -> bool {
|
||||
let mut trap_out: i32 = -1;
|
||||
let ret = cxx_invoke_trampoline(
|
||||
trampoline,
|
||||
vmctx_ptr,
|
||||
func_ptr,
|
||||
params,
|
||||
results,
|
||||
&mut trap_out,
|
||||
error_out,
|
||||
invoke_env,
|
||||
);
|
||||
// Translate trap code if an error occurred.
|
||||
if !ret && (*error_out).is_none() && trap_out != -1 {
|
||||
*error_out = Some(Box::new(match trap_out {
|
||||
0 => ExceptionCode::Unreachable,
|
||||
1 => ExceptionCode::IncorrectCallIndirectSignature,
|
||||
2 => ExceptionCode::MemoryOutOfBounds,
|
||||
3 => ExceptionCode::CallIndirectOOB,
|
||||
4 => ExceptionCode::IllegalArithmetic,
|
||||
5 => ExceptionCode::MisalignedAtomicAccess,
|
||||
_ => return ret,
|
||||
}));
|
||||
}
|
||||
ret
|
||||
}
|
||||
|
||||
static SIGNAL_HANDLER_INSTALLED: Once = Once::new();
|
||||
|
Reference in New Issue
Block a user