Skip to content

Commit

Permalink
bug: std::panic::AssertUnwindSafe dangerous in linux
Browse files Browse the repository at this point in the history
  • Loading branch information
uuhan committed Jan 20, 2024
1 parent cbb4666 commit f42721b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,9 @@ use terminate_thread::Thread;
Thread::spawn(|| {}); // ← bus error
```

- [ ] `std::panic::AssertUnwindSafe()` does not work in linux. == v0.3.0

```rust
use terminate_thread::Thread;
Thread::spawn(|| panic!()); // ← FATAL: exception not rethrown
```
17 changes: 13 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,22 @@ impl Thread {
ThreadGuard,
)> = Box::from_raw(xarg as _);

#[allow(unused)]
let (call, panic_info, guard) = *pair;

let call = std::panic::AssertUnwindSafe(call);
#[cfg(target_os = "macos")]
{
let call = std::panic::AssertUnwindSafe(call);

// Store the panic info
if let Err(info) = std::panic::catch_unwind(call) {
panic_info.lock().unwrap().replace(info);
// Store the panic info
if let Err(info) = std::panic::catch_unwind(call) {
panic_info.lock().unwrap().replace(info);
}
}

#[cfg(target_os = "linux")]
{
call();
}

let mut over = guard.1.lock().unwrap();
Expand Down

0 comments on commit f42721b

Please sign in to comment.