Skip to content

Commit

Permalink
macOS: Don't inspect dead threadtls during exception handling. (Julia…
Browse files Browse the repository at this point in the history
…Lang#50871)

Otherwise we may end up with the state of a dead thread, as the system
IDs can alias. This can lead to an early return from the exception
handler, resulting in e.g. safepoint exceptions being actually delivered
to user code.

---------

Co-authored-by: Jameson Nash <[email protected]>
Co-authored-by: Cody Tapscott <[email protected]>
  • Loading branch information
3 people authored Aug 11, 2023
1 parent 5db443a commit cda570e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/signals-mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,16 @@ kern_return_t catch_mach_exception_raise(
int nthreads = jl_atomic_load_acquire(&jl_n_threads);
for (tid = 0; tid < nthreads; tid++) {
jl_ptls_t _ptls2 = jl_atomic_load_relaxed(&jl_all_tls_states)[tid];
if (jl_atomic_load_relaxed(&_ptls2->current_task) == NULL) {
// this thread is dead
continue;
}
if (pthread_mach_thread_np(_ptls2->system_id) == thread) {
ptls2 = _ptls2;
break;
}
}
if (!ptls2 || ptls2->current_task == NULL) {
if (!ptls2) {
// We don't know about this thread, let the kernel try another handler
// instead. This shouldn't actually happen since we only register the
// handler for the threads we know about.
Expand Down

0 comments on commit cda570e

Please sign in to comment.