Skip to content

Commit

Permalink
Remove unneeded wasmtime_call_trampoline shim
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Mar 19, 2020
1 parent 0689e8a commit 0b8ed35
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 44 deletions.
15 changes: 8 additions & 7 deletions crates/api/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ 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,
catch_traps, raise_lib_trap, raise_user_trap, Trap,
};
pub use crate::vmcontext::{
VMCallerCheckedAnyfunc, VMContext, VMFunctionBody, VMFunctionImport, VMGlobalDefinition,
Expand Down
48 changes: 12 additions & 36 deletions crates/runtime/src/traphandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,27 +61,27 @@ 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<dyn Error + Send + Sync>) -> ! {
tls::with(|info| info.unwrap().unwind_with(UnwindReason::UserTrap(data)))
}

/// 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)))
}
Expand All @@ -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<dyn Any + Send>) -> ! {
tls::with(|info| info.unwrap().unwind_with(UnwindReason::Panic(payload)))
}
Expand Down Expand Up @@ -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`.
///
Expand Down

0 comments on commit 0b8ed35

Please sign in to comment.