-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Prevent foreign Rust exceptions from being caught #102721
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e521a8d
Prevent foreign Rust exceptions from being caught
nbdd0121 86c65d2
Implement Rust foreign exception protection for EMCC and SEH
nbdd0121 daf3063
Add test case for foreign Rust exceptions
nbdd0121 979d1a2
Apply suggestion
nbdd0121 4e6d60c
Fix alloc size
nbdd0121 c9cca33
Fix windows compilation
nbdd0121 bfac2da
Ignore test on mingw32
nbdd0121 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/test/run-make-fulldeps/foreign-rust-exceptions/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ignore-i686-pc-windows-gnu | ||
|
||
# This test doesn't work on 32-bit MinGW as cdylib has its own copy of unwinder | ||
# so cross-DLL unwinding does not work. | ||
|
||
include ../tools.mk | ||
|
||
all: | ||
$(RUSTC) bar.rs --crate-type=cdylib | ||
$(RUSTC) foo.rs | ||
$(call RUN,foo) 2>&1 | $(CGREP) "Rust cannot catch foreign exceptions" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#![crate_type = "cdylib"] | ||
#![feature(c_unwind)] | ||
|
||
#[no_mangle] | ||
extern "C-unwind" fn panic() { | ||
panic!(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![feature(c_unwind)] | ||
|
||
#[cfg_attr(not(windows), link(name = "bar"))] | ||
#[cfg_attr(windows, link(name = "bar.dll"))] | ||
extern "C-unwind" { | ||
fn panic(); | ||
} | ||
|
||
fn main() { | ||
let _ = std::panic::catch_unwind(|| { | ||
unsafe { panic() }; | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change this to avoid unsoundness in combination with older rust versions? Same for the exception type for the other unwinding mechanisms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth mentioning that catching a foreign unwind in Rust is UB. We are providing guards against this but it's not part of guarantee.
Currently there are no ways to hit this on stable, and if you hit this using nightly you are already in UB territory. So we can change this string (and the exception class), but we don't have to.