Skip to content

Commit

Permalink
Auto merge of rust-lang#102460 - flba-eb:fix_85261_prevent_alloc_afte…
Browse files Browse the repository at this point in the history
…r_fork, r=thomcc

Prevent UB in child process after calling libc::fork

After calling libc::fork, the child process tried to access a TLS variable when processing a panic. This caused a memory allocation which is UB in the child.
To prevent this from happening, the panic handler will not access the TLS variable in case `panic::always_abort` was called before.

Fixes rust-lang#85261 (not only on Android systems, but also on Linux/QNX with TLS disabled, see issue for more details)

Main drawbacks of this fix:
* Panic messages can incorrectly omit `core::panic::PanicInfo` struct in case several panics (of multiple threads) occur at the same time. The handler cannot distinguish between multiple panics in different threads or recursive ones in the same thread, but the message will contain a hint about the uncertainty.
* `panic_count::increase()` will be a bit slower as it has an additional `if`, but this should be irrelevant as it is only called in case of a panic.
  • Loading branch information
bors committed Oct 12, 2022
2 parents 636d9e3 + a47b834 commit a0c0085
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit a0c0085

Please sign in to comment.