Skip to content

Commit 9486199

Browse files
committed
stack-switching: fix continuation stack walking
A refactor during the stack switching runtime changes introduced a defect not present in the base stack switching code. The `chunks` iterator call ends up skipping elements and the `windows` call would require pulling in something like `itertools::zip_longest` to work, so I just restored an impl closer to the original implementation (but with more fine-grained unsafe calls). This code has coverage but only in the final round of stack swithching changes.
1 parent a80dd80 commit 9486199

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,24 +262,17 @@ impl Backtrace {
262262
// are continuations, due to the initial stack having one, too.
263263
assert_eq!(stack_limits_vec.len(), continuations_vec.len() + 1);
264264

265-
for (conts, &parent_limits) in continuations_vec
266-
.chunks(2)
267-
.zip(stack_limits_vec.iter().skip(1))
268-
{
265+
for i in 0..continuations_vec.len() {
269266
// The continuation whose control context we want to
270267
// access, to get information about how to continue
271268
// execution in its parent.
272-
let continuation = conts[0];
273-
let continuation = unsafe { &*continuation };
269+
let continuation = unsafe { &*continuations_vec[i] };
274270

275271
// The stack limits describing the parent of `continuation`.
276-
let parent_limits = unsafe { &*parent_limits };
272+
let parent_limits = unsafe { &*stack_limits_vec[i + 1] };
277273

278-
// The parent of `continuation`, if the parent is itself a
279-
// continuation. Otherwise, if `continuation` is the last
280-
// continuation (i.e., its parent is the initial stack), this is
281-
// None.
282-
let parent_continuation = conts.get(1).map(|&p| unsafe { &*p });
274+
// The parent of `continuation` if present not the last in the chain.
275+
let parent_continuation = continuations_vec.get(i + 1).map(|&c| unsafe { &*c });
283276

284277
let fiber_stack = continuation.fiber_stack();
285278
let resume_pc = fiber_stack.control_context_instruction_pointer();

0 commit comments

Comments
 (0)