8000 failed to initiate panic, error code END_OF_STACK · Issue #45 · nbdd0121/unwinding · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

failed to initiate panic, error code END_OF_STACK #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tsatke opened this issue Mar 28, 2025 · 3 comments
Open

failed to initiate panic, error code END_OF_STACK #45

tsatke opened this issue Mar 28, 2025 · 3 comments

Comments

@tsatke
Copy link
tsatke commented Mar 28, 2025

Hi,

I'm compiling my bare-metal project (x86_64) with panic = "unwind", however, when I try to begin_panic, it just returns with 5.

My code (basically the code in panic_handler.rs but without the stack trace):

fn main() {
    // bare-metal setup, logging, heap etc.

    let res = unwinding::panic::catch_unwind(|| {
        panic!("test panic");
    });
    info!("res: {res:?}");
}

#[panic_handler]
fn rust_panic(info: &core::panic::PanicInfo) -> ! {
    let location = info.location().unwrap();
    error!(
        "kernel panicked at {}:{}:{}:\n{}",
        location.file(),
        location.line(),
        location.column(),
        info.message(),
    );

    struct NoPayload;
    do_panic(Box::new(NoPayload))
}

fn do_panic(msg: Box<dyn Any + Send>) -> ! {
    let code = unwinding::panic::begin_panic(Box::new(msg));
    error!("failed to initiate panic, error {}", code.0);
    abort()
}

Cargo.toml:

unwinding = { version = "0.2", default-features = false, features = ["unwinder", "fde-static", "personality", "panic"] }

config.toml (more panic=unwind = better)

[target.x86_64-unknown-none]
rustflags = [
    "-C", "link-arg=-z",
    "-C", "link-arg=nostart-stop-gc",
    "-C", "force-frame-pointers=yes",
    "-C", "force-unwind-tables=yes",
    "-C", "relocation-model=static",
    "-C", "panic=unwind",
    "-g"
]

[profile.dev]
panic = "unwind"

[profile.release]
panic = "unwind"

The executable is non-relocatable, __eh_frame and __etext exist, and the stack trace code from panic_handler.rs also prints output for me, it just reaches from stack_trace() up to with_context(|...| ...), but I'm not sure if that's the same problem.

I'd like to understand why it doesn't start to unwind. I've debugged through and it goes through the loop in _Unwind_RaiseException a few times, but ultimately returns from it with END_OF_STACK. What is it looking for, and if it finds the stack frames, why doesn't it unwind?

@tsatke
Copy link
Author
tsatke commented Mar 28, 2025

When I call begin_panic directly in catch_unwind, the with_context loop finds a personality in the end and it correctly unwinds. If I call it as in the above code though, no personality is found ever (I don't know why).

@nbdd0121
Copy link
Owner

Are you using pre-compiled libcore? If so, try using build-std as there'll be a libcore frame on stack which doesn't have unwind info.

@tsatke
Copy link
Author
tsatke commented Apr 9, 2025

Makes sense, created rust-lang/cargo#15365 , as soon as that works or I manage to work around that I'll update this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0