Skip to content

Commit cdda336

Browse files
authored
[Stack Switching] Ignore attempts to stash resume info for suspends without a continuation (#7819)
When there is no continuation (we are not running in one), then a suspend will lead to a trap on the host side, of "unhandled suspend". We do need to make sure not to error on the way, so any attempt to save resume info must be skipped. Spec tests did not catch this because they did not have an enclosing block, and the block tries to save resume info.
1 parent 3b4856e commit cdda336

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/wasm-interpreter.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,19 @@ class ExpressionRunner : public OverriddenVisitor<SubType, Flow> {
463463
// Add an entry to help us resume this continuation later. Instructions call
464464
// this as we unwind.
465465
void pushResumeEntry(const Literals& entry, const char* what) {
466+
auto currContinuation = getCurrContinuationOrNull();
467+
if (!currContinuation) {
468+
// We are suspending outside of a continuation. This will trap as an
469+
// unhandled suspension when we reach the host, so we don't need to save
470+
// any resume entries (it would be simpler to just trap when we suspend in
471+
// such a situation, but spec tests want to differentiate traps from
472+
// suspends).
473+
return;
474+
}
466475
#if WASM_INTERPRETER_DEBUG
467476
std::cout << indent() << "push resume entry [" << what << "]: " << entry
468477
<< "\n";
469478
#endif
470-
auto currContinuation = getCurrContinuation();
471479
currContinuation->resumeInfo.push_back(entry);
472480
}
473481

test/lit/exec/cont_simple.wast

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,4 +864,14 @@
864864
;; This will be reached.
865865
(call $log (i32.const 42))
866866
)
867+
868+
;; CHECK: [fuzz-exec] calling suspend-unhandled-block
869+
;; CHECK-NEXT: [exception thrown: unhandled suspend]
870+
(func $suspend-unhandled-block (export "suspend-unhandled-block")
871+
;; The nop here means that we are inside a block. The block will try to save
872+
;; resume data, but we should skip that without erroring, and just report an
873+
;; unhandled suspend.
874+
(suspend $more)
875+
(nop)
876+
)
867877
)

0 commit comments

Comments
 (0)