Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/vm/stack_switching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ pub fn cont_new(
/// executing themselves, but are an ancestor of the currently executing
/// stack), we have the following: All the fields in the stack's
/// `VMStackLimits` are valid, describing the stack's stack limit, and
/// pointers where executing for that stack entered and exited WASM.
/// pointers where executing for that stack entered and exited Wasm.
///
/// Suspended continuations: For suspended continuations (including their
/// ancestors), we have the following. Note that the initial stack can never
Expand Down
23 changes: 22 additions & 1 deletion crates/wasmtime/src/runtime/vm/traphandlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub use self::signals::*;
use crate::ThrownException;
use crate::runtime::module::lookup_code;
use crate::runtime::store::{ExecutorRef, StoreOpaque};
use crate::runtime::vm::stack_switching::VMStackChain;
use crate::runtime::vm::sys::traphandlers;
use crate::runtime::vm::{InterpreterRef, VMContext, VMStore, VMStoreContext, f32x4, f64x2, i8x16};
use crate::{EntryStoreContext, prelude::*};
Expand Down Expand Up @@ -866,8 +867,28 @@ impl CallThreadState {

pub(crate) fn entry_trap_handler(&self) -> Handler {
unsafe {
fn running_on_continuation(stack_chain: *const VMStackChain) -> bool {
unsafe {
match *stack_chain {
VMStackChain::Continuation(_) => true,
_ => false,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to be simplified slightly to just matches!(*stack_chain, VMStackChain::Continuation(_))

}
}
let vm_store_context = self.vm_store_context.as_ref();
let fp = *vm_store_context.last_wasm_entry_fp.get();
let vm_stack_chain = vm_store_context.stack_chain.get();
// The effects of trapping should not be delimited by the
// continuation stack segment we are running on, but
// rather the initial continuation stack segment, i.e. the
// toplevel part of the program. Therefore we must
// retrieve the entry fp of the initial stack.
let fp = if running_on_continuation(vm_stack_chain) {
let initial_stack_limits =
(*vm_stack_chain).clone().into_stack_limits_iter().last();
(*initial_stack_limits.unwrap_or_else(|| panic!("Attempting to find the stack limits of the initial stacks from within a suspended continuation."))).last_wasm_entry_fp
} else {
*vm_store_context.last_wasm_entry_fp.get()
};
let sp = *vm_store_context.last_wasm_entry_sp.get();
let pc = *vm_store_context.last_wasm_entry_trap_handler.get();
Handler { pc, sp, fp }
Expand Down
16 changes: 16 additions & 0 deletions tests/misc_testsuite/stack-switching/trap.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
;;! stack_switching = true
;;! reference_types = true

(module
(type $ft (func))
(type $ct (cont $ft))

(func $fn
(unreachable))

(func $run_fn (export "run_fn")
(resume $ct (cont.new $ct (ref.func $fn))))

(elem declare func $fn)
)
(assert_trap (invoke "run_fn") "unreachable")