diff --git a/crates/api/src/func.rs b/crates/api/src/func.rs index f876bb1c1f77..e596caf46dbc 100644 --- a/crates/api/src/func.rs +++ b/crates/api/src/func.rs @@ -527,13 +527,14 @@ impl Func { // Call the trampoline. if let Err(error) = unsafe { - wasmtime_runtime::wasmtime_call_trampoline( - self.export.vmctx, - ptr::null_mut(), - self.trampoline, - self.export.address, - values_vec.as_mut_ptr(), - ) + wasmtime_runtime::catch_traps(self.export.vmctx, || { + (self.trampoline)( + self.export.vmctx, + ptr::null_mut(), + self.export.address, + values_vec.as_mut_ptr(), + ) + }) } { return Err(Trap::from_jit(error)); } diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 212defdff843..4359db4806db 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -45,9 +45,7 @@ pub use crate::sig_registry::SignatureRegistry; pub use crate::table::Table; pub use crate::trap_registry::{TrapDescription, TrapRegistration, TrapRegistry}; pub use crate::traphandlers::resume_panic; -pub use crate::traphandlers::{ - catch_traps, raise_lib_trap, raise_user_trap, wasmtime_call_trampoline, Trap, -}; +pub use crate::traphandlers::{catch_traps, raise_lib_trap, raise_user_trap, Trap}; pub use crate::vmcontext::{ VMCallerCheckedAnyfunc, VMContext, VMFunctionBody, VMFunctionImport, VMGlobalDefinition, VMGlobalImport, VMInvokeArgument, VMMemoryDefinition, VMMemoryImport, VMSharedSignatureIndex, diff --git a/crates/runtime/src/traphandlers.rs b/crates/runtime/src/traphandlers.rs index b239173cc1b3..64a59a9090dc 100644 --- a/crates/runtime/src/traphandlers.rs +++ b/crates/runtime/src/traphandlers.rs @@ -3,7 +3,7 @@ use crate::instance::{InstanceHandle, SignalHandler}; use crate::trap_registry::TrapDescription; -use crate::vmcontext::{VMContext, VMFunctionBody, VMTrampoline}; +use crate::vmcontext::VMContext; use backtrace::Backtrace; use std::any::Any; use std::cell::Cell; @@ -61,13 +61,13 @@ cfg_if::cfg_if! { /// /// This function performs as-if a wasm trap was just executed, only the trap /// has a dynamic payload associated with it which is user-provided. This trap -/// payload is then returned from `wasmtime_call` an `wasmtime_call_trampoline` -/// below. +/// payload is then returned from `catch_traps` below. /// /// # Safety /// -/// Only safe to call when wasm code is on the stack, aka `wasmtime_call` or -/// `wasmtime_call_trampoline` must have been previously called. +/// Only safe to call when wasm code is on the stack, aka `catch_traps` must +/// have been previously called. Additionally no Rust destructors can be on the +/// stack. They will be skipped and not executed. pub unsafe fn raise_user_trap(data: Box) -> ! { tls::with(|info| info.unwrap().unwind_with(UnwindReason::UserTrap(data))) } @@ -75,13 +75,13 @@ pub unsafe fn raise_user_trap(data: Box) -> ! { /// Raises a trap from inside library code immediately. /// /// This function performs as-if a wasm trap was just executed. This trap -/// payload is then returned from `wasmtime_call` and `wasmtime_call_trampoline` -/// below. +/// payload is then returned from `catch_traps` below. /// /// # Safety /// -/// Only safe to call when wasm code is on the stack, aka `wasmtime_call` or -/// `wasmtime_call_trampoline` must have been previously called. +/// Only safe to call when wasm code is on the stack, aka `catch_traps` must +/// have been previously called. Additionally no Rust destructors can be on the +/// stack. They will be skipped and not executed. pub unsafe fn raise_lib_trap(trap: Trap) -> ! { tls::with(|info| info.unwrap().unwind_with(UnwindReason::LibTrap(trap))) } @@ -91,8 +91,9 @@ pub unsafe fn raise_lib_trap(trap: Trap) -> ! { /// /// # Safety /// -/// Only safe to call when wasm code is on the stack, aka `wasmtime_call` or -/// `wasmtime_call_trampoline` must have been previously called. +/// Only safe to call when wasm code is on the stack, aka `catch_traps` must +/// have been previously called. Additionally no Rust destructors can be on the +/// stack. They will be skipped and not executed. pub unsafe fn resume_panic(payload: Box) -> ! { tls::with(|info| info.unwrap().unwind_with(UnwindReason::Panic(payload))) } @@ -153,31 +154,6 @@ impl Trap { } } -/// Call the wasm function pointed to by `callee`. -/// -/// * `vmctx` - the callee vmctx argument -/// * `caller_vmctx` - the caller vmctx argument -/// * `trampoline` - the jit-generated trampoline whose ABI takes 4 values, the -/// callee vmctx, the caller vmctx, the `callee` argument below, and then the -/// `values_vec` argument. -/// * `callee` - the third argument to the `trampoline` function -/// * `values_vec` - points to a buffer which holds the incoming arguments, and to -/// which the outgoing return values will be written. -/// -/// Wildly unsafe because it calls raw function pointers and reads/writes raw -/// function pointers. -pub unsafe fn wasmtime_call_trampoline( - vmctx: *mut VMContext, - caller_vmctx: *mut VMContext, - trampoline: VMTrampoline, - callee: *const VMFunctionBody, - values_vec: *mut u128, -) -> Result<(), Trap> { - catch_traps(vmctx, || { - trampoline(vmctx, caller_vmctx, callee, values_vec) - }) -} - /// Catches any wasm traps that happen within the execution of `closure`, /// returning them as a `Result`. ///