Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
59be3e8
Stabilized Option::unzip()
Kixiron Jun 17, 2022
df8a62d
Use `CURRENT_RUSTC_VERSION`
Kixiron Sep 7, 2022
093b075
rustc: Use `unix_sigpipe` instead of `rustc_driver::set_sigpipe_handler`
Enselic Oct 2, 2022
7280f3d
Truncate thread names on Linux and Apple targets
cuviper Oct 22, 2022
12e4584
Move truncation next to other thread tests for tidy
cuviper Oct 22, 2022
8f8f74d
Name impl trait in region bound suggestion
compiler-errors Oct 22, 2022
4bd9844
remove misc_cast and validate types
ouz-a Oct 16, 2022
15cfeb3
Only test pthread_getname_np on linux-gnu
cuviper Oct 23, 2022
e521a8d
Prevent foreign Rust exceptions from being caught
nbdd0121 Oct 5, 2022
86c65d2
Implement Rust foreign exception protection for EMCC and SEH
nbdd0121 Oct 5, 2022
daf3063
Add test case for foreign Rust exceptions
nbdd0121 Oct 5, 2022
979d1a2
Apply suggestion
nbdd0121 Oct 11, 2022
4e6d60c
Fix alloc size
nbdd0121 Oct 12, 2022
c9cca33
Fix windows compilation
nbdd0121 Oct 23, 2022
03bd9c9
Rollup merge of #98204 - Kixiron:stable-unzip, r=thomcc
Dylan-DPC Oct 25, 2022
7459409
Rollup merge of #102587 - Enselic:rustc-unix_sigpipe, r=jackh726
Dylan-DPC Oct 25, 2022
7665f3c
Rollup merge of #102721 - nbdd0121:panic, r=Amanieu
Dylan-DPC Oct 25, 2022
1c8201c
Rollup merge of #103122 - ouz-a:mir-technical-debt, r=oli-obk
Dylan-DPC Oct 25, 2022
d0d9c86
Rollup merge of #103379 - cuviper:truncate-thread-name, r=thomcc
Dylan-DPC Oct 25, 2022
d6d6cb7
Rollup merge of #103416 - compiler-errors:rpit-named, r=cjgillot
Dylan-DPC Oct 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Prevent foreign Rust exceptions from being caught
  • Loading branch information
nbdd0121 committed Oct 23, 2022
commit e521a8d46b4437f94ba1bb85826bb7d00ba13436
30 changes: 27 additions & 3 deletions library/panic_unwind/src/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,23 @@

use alloc::boxed::Box;
use core::any::Any;
use core::ptr;

use unwind as uw;

// In case where multiple copies of std is compiled into a single binary,
// we use address of this static variable to distinguish an exception raised by
// this copy and some other copy (which needs to be treated as foreign exception).
static CANARY: u8 = 0;

// NOTE(nbdd0121)
// Once `c_unwind` feature is stabilized, there will be ABI stability requirement
// on this struct. The first two field must be `_Unwind_Exception` and `canary`,
// as it may be accessed by a different version of the std with a different compiler.
#[repr(C)]
struct Exception {
_uwe: uw::_Unwind_Exception,
canary: *const u8,
cause: Box<dyn Any + Send>,
}

Expand All @@ -54,6 +65,7 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
exception_cleanup,
private: [0; uw::unwinder_private_data_size],
},
canary: &CANARY,
cause: data,
});
let exception_param = Box::into_raw(exception) as *mut uw::_Unwind_Exception;
Expand All @@ -75,10 +87,22 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
if (*exception).exception_class != rust_exception_class() {
uw::_Unwind_DeleteException(exception);
super::__rust_foreign_exception();
} else {
let exception = Box::from_raw(exception as *mut Exception);
exception.cause
}

let exception = exception.cast::<Exception>();
// Just access the canary field, avoid accessing the entire `Exception` as
// it can be a foreign Rust exception.
let canary = ptr::addr_of!((*exception).canary).read();
if !ptr::eq(canary, &CANARY) {
// A foreign Rust exception, treat it slightly differently from other
// foreign exceptions, because call into `_Unwind_DeleteException` will
// call into `__rust_drop_panic` which produces a confusing
// "Rust panic must be rethrown" message.
super::__rust_foreign_exception();
}

let exception = Box::from_raw(exception as *mut Exception);
exception.cause
}

// Rust's exception class identifier. This is used by personality routines to
Expand Down