Skip to content

Pulley and s390x don't correctly handle the youngest frame in a stack-overflow trace #14597

Closed

Description

@alexcrichton

This test:

#[wasmtime_test]
fn test_trap_stack_overflow_mutual_recursion(config: &mut Config) -> Result<()> {
    let max_frames = NonZeroUsize::new(32).unwrap();
    let wat = r#"
        (module $rec_mod
            (func $even (export "even") (call $odd))
            (func $odd (call $even))
        )
    "#;

    config.wasm_backtrace_max_frames(Some(max_frames));
    let engine = Engine::new(&config)?;
    let module = Module::new(&engine, wat)?;
    let mut store = Store::new(&engine, ());
    let instance = Instance::new(&mut store, &module, &[])?;
    let even = instance.get_typed_func::<(), ()>(&mut store, "even")?;

    let e = even.call(&mut store, ()).unwrap_err();

    // No frame may be skipped, so the frames must alternate between the two
    // functions.
    let trace = e.downcast_ref::<WasmBacktrace>().unwrap().frames();
    assert_eq!(trace.len(), max_frames.get());
    for pair in trace.windows(2) {
        assert_ne!(pair[0].func_index(), pair[1].func_index(), "{trace:?}");
    }
    assert_eq!(e.downcast::<Trap>()?, Trap::StackOverflow);

    Ok(())
}

passes on all platforms except s390x and Pulley. Neither of them handle stack overflow in such a way where the final frame on the stack is the frame that actually caused the stack overflow. This is a relatively minor issue, but it'd be nice to fix to help for attribution of stack overflows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior in the current implementation that needs fixingcranelift:area:s390xIssues related to Cranelift's s390x backendpulleyIssues related to the Pulley interpreter

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions