From 9486199ea519305b2920efe42cd1d245411cc8ce Mon Sep 17 00:00:00 2001 From: Paul Osborne Date: Mon, 9 Jun 2025 21:29:31 +0000 Subject: [PATCH] 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. --- .../src/runtime/vm/traphandlers/backtrace.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs b/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs index 97008c10d7c2..ab6c80152213 100644 --- a/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs +++ b/crates/wasmtime/src/runtime/vm/traphandlers/backtrace.rs @@ -262,24 +262,17 @@ impl Backtrace { // are continuations, due to the initial stack having one, too. assert_eq!(stack_limits_vec.len(), continuations_vec.len() + 1); - for (conts, &parent_limits) in continuations_vec - .chunks(2) - .zip(stack_limits_vec.iter().skip(1)) - { + for i in 0..continuations_vec.len() { // The continuation whose control context we want to // access, to get information about how to continue // execution in its parent. - let continuation = conts[0]; - let continuation = unsafe { &*continuation }; + let continuation = unsafe { &*continuations_vec[i] }; // The stack limits describing the parent of `continuation`. - let parent_limits = unsafe { &*parent_limits }; + let parent_limits = unsafe { &*stack_limits_vec[i + 1] }; - // The parent of `continuation`, if the parent is itself a - // continuation. Otherwise, if `continuation` is the last - // continuation (i.e., its parent is the initial stack), this is - // None. - let parent_continuation = conts.get(1).map(|&p| unsafe { &*p }); + // The parent of `continuation` if present not the last in the chain. + let parent_continuation = continuations_vec.get(i + 1).map(|&c| unsafe { &*c }); let fiber_stack = continuation.fiber_stack(); let resume_pc = fiber_stack.control_context_instruction_pointer();