Skip to content

Commit cda570e

Browse files
maleadtvtjnashtopolarity
authored
macOS: Don't inspect dead threadtls during exception handling. (#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]>
1 parent 5db443a commit cda570e

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/signals-mach.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,16 @@ kern_return_t catch_mach_exception_raise(
279279
int nthreads = jl_atomic_load_acquire(&jl_n_threads);
280280
for (tid = 0; tid < nthreads; tid++) {
281281
jl_ptls_t _ptls2 = jl_atomic_load_relaxed(&jl_all_tls_states)[tid];
282+
if (jl_atomic_load_relaxed(&_ptls2->current_task) == NULL) {
283+
// this thread is dead
284+
continue;
285+
}
282286
if (pthread_mach_thread_np(_ptls2->system_id) == thread) {
283287
ptls2 = _ptls2;
284288
break;
285289
}
286290
}
287-
if (!ptls2 || ptls2->current_task == NULL) {
291+
if (!ptls2) {
288292
// We don't know about this thread, let the kernel try another handler
289293
// instead. This shouldn't actually happen since we only register the
290294
// handler for the threads we know about.

0 commit comments

Comments
 (0)