Skip to content

_Unwind_GetIP returns 0x0, and then jumps to it. #31

@lylythechosenone

Description

@lylythechosenone

In certain cases (I'm not sure exactly which), _Unwind_GetIP inside of _Unwind_Backtrace is returning a null pointer, and then jumping to it after the callback completes. This is my code:

fn stack_trace() -> heapless::Vec<usize, 512> {
    extern "C" fn callback(
        unwind_ctx: &unwinding::abi::UnwindContext<'_>,
        arg: *mut core::ffi::c_void,
    ) -> unwinding::abi::UnwindReasonCode {
        let data = unsafe { &mut *arg.cast::<heapless::Vec<usize, 512>>() };
        let _ = data.push(_Unwind_GetIP(unwind_ctx));
        unwinding::abi::UnwindReasonCode::NO_REASON
    }

    let mut trace = heapless::Vec::new();
    _Unwind_Backtrace(callback, core::ptr::addr_of_mut!(trace).cast());
    trace
}

It's pretty much copied from panic_handler.rs, but pushed to a vec instead of immediately printed.

An example panic results in:

[ERROR] (panic) Panic! panicked at src/init.rs:148:5:
       │ oops
       │ 
       │ Stack trace:
       │   4: 0xffffffff80002eec
       │   3: 0xffffffff8001d338
       │   2: 0xffffffff80007804
       │   1: 0xffffffff800074dc
       │   0: 0x0000000000000000

Followed by a prefetch data abort when trying to read from 0x0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions