From 9bf0bb0b5c95cd0b99cae18826841b64fc758710 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Mon, 4 Apr 2022 21:05:51 +0300 Subject: Avoid potential signal loss before sigsuspend in suspend_handler if TSan Issue #236 (bdwgc). As comment between sem_post() and sigsuspend() says GC_sig_thr_restart signal should be masked at that point otherwise there could be a race. Thus, this commit removes pthread_sigmask(SIG_UNBLOCK) call before sem_post() one in GC_suspend_handler_inner. * pthread_stop_world.c [!GC_OPENBSD_UTHREADS && !NACL && THREAD_SANITIZER] (GC_suspend_handler_inner): Remove "set" local variable; do not call sigemptyset(), pthread_sigmask(SIG_UNBLOCK), sigaddset(). --- pthread_stop_world.c | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'pthread_stop_world.c') diff --git a/pthread_stop_world.c b/pthread_stop_world.c index ae5bc77b..33470e62 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -392,20 +392,6 @@ STATIC void GC_suspend_handler_inner(ptr_t dummy GC_ATTR_UNUSED, me -> backing_store_ptr = bs_lo + stack_size; # endif -# ifdef THREAD_SANITIZER - /* TSan disables signals around signal handlers. Without */ - /* a pthread_sigmask call, sigsuspend may block forever. */ - { - sigset_t set; - sigemptyset(&set); - GC_ASSERT(GC_sig_suspend != SIGNAL_UNSET); - GC_ASSERT(GC_sig_thr_restart != SIGNAL_UNSET); - sigaddset(&set, GC_sig_suspend); - sigaddset(&set, GC_sig_thr_restart); - if (pthread_sigmask(SIG_UNBLOCK, &set, NULL) != 0) - ABORT("pthread_sigmask failed in suspend handler"); - } -# endif /* Tell the thread that wants to stop the world that this */ /* thread has been stopped. Note that sem_post() is */ /* the only async-signal-safe primitive in LinuxThreads. */ -- cgit v1.2.1