Skip to content
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

Panic in 'safe' extern "C" causes SIGILL #63668

Closed
ralfbiedert opened this issue Aug 17, 2019 · 3 comments
Closed

Panic in 'safe' extern "C" causes SIGILL #63668

ralfbiedert opened this issue Aug 17, 2019 · 3 comments

Comments

@ralfbiedert
Copy link
Contributor

ralfbiedert commented Aug 17, 2019

Investigating a SIGILL in a safe library of ours I could reduce the crash to the following code:

#![deny(unsafe_code)]

extern "C" fn crash() {
    panic!("End of the world");
}

fn main() {
    // This works ...
    std::panic::catch_unwind(|| panic!("Oh no"));

    // This will cause a STATUS_ILLEGAL_INSTRUCTION and crash the app.
    std::panic::catch_unwind(|| crash());

    println!("Still running ...");
}

When running the above with cargo run:

thread 'main' panicked at 'Oh no', src\main.rs:9:33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
thread 'main' panicked at 'End of the world', src\main.rs:4:5
error: process didn't exit successfully: `target\debug\app.exe` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)

Link to playground.

Although one can argue that decorating crash with extern "C" is ugly, observe that there is no unsafe involved in this code. Panicking past the "safe" extern "C" boundary is enough.

I can provoke this with

  • rustc 1.38.0-nightly (83e4eed16 2019-07-14)
  • rustc 1.39.0-nightly (bdfd698f3 2019-08-16)

When compiling with rustc 1.37.0 (eae3437df 2019-08-13) it seems to work.

@sfackler
Copy link
Member

You cannot generally unwind through a C ABI: #58794

@ralfbiedert
Copy link
Contributor Author

ralfbiedert commented Aug 17, 2019

You cannot generally unwind through a C ABI: #58794

But isn't "safe" Rust meant to be free of undefined behavior?

Edit - I'm implying here that the ud2 I'm receiving in gdb signals UB. Nevermind, I just read the other thread, seems like all the arguments have been made there already. Feel free to close this issue as duplicate.

@jonas-schievink
Copy link
Contributor

Closing in favor of #58794

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

3 participants