Skip to content

Commit ab27a43

Browse files
maleadtvtjnashtopolarity
committed
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 <vtjnash@gmail.com> Co-authored-by: Cody Tapscott <topolarity@tapscott.me>
1 parent 025ef93 commit ab27a43

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
@@ -276,12 +276,16 @@ kern_return_t catch_mach_exception_raise(
276276
int nthreads = jl_atomic_load_acquire(&jl_n_threads);
277277
for (tid = 0; tid < nthreads; tid++) {
278278
jl_ptls_t _ptls2 = jl_atomic_load_relaxed(&jl_all_tls_states)[tid];
279+
if (jl_atomic_load_relaxed(&_ptls2->current_task) == NULL) {
280+
// this thread is dead
281+
continue;
282+
}
279283
if (pthread_mach_thread_np(_ptls2->system_id) == thread) {
280284
ptls2 = _ptls2;
281285
break;
282286
}
283287
}
284-
if (!ptls2 || ptls2->current_task == NULL) {
288+
if (!ptls2) {
285289
// We don't know about this thread, let the kernel try another handler
286290
// instead. This shouldn't actually happen since we only register the
287291
// handler for the threads we know about.

0 commit comments

Comments
 (0)