From: Tom Hughes Date: Sat, 16 Oct 2004 16:17:06 +0000 (+0000) Subject: If a thread is waiting on a mutex or condition variable when a signal is X-Git-Tag: svn/VALGRIND_3_0_0~1516 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e531fcba5636c7b44d56cc24a0e32c82cf385a1c;p=thirdparty%2Fvalgrind.git If a thread is waiting on a mutex or condition variable when a signal is delivered that the thread state is temporarily changed from WaitMX or WaitCV to Running while the signal handler is running. The original state is then restored when the handler returns. This patch forces the associated_mx and associated_cv values to be cleared at the same time and the original values restored afterwards. Without this the scheduler state will not be considered sane while the handler is running. This is based on a patch from Kenneth Schalk and fixes a problem he had with posting to a semaphore in a signal handler. It also allows a couple of assertions in the scheduler sanity check to be uncommented. BUG: 72082 git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2778 --- diff --git a/coregrind/vg_scheduler.c b/coregrind/vg_scheduler.c index 1252f7df5a..39ad8372f0 100644 --- a/coregrind/vg_scheduler.c +++ b/coregrind/vg_scheduler.c @@ -3236,10 +3236,8 @@ void scheduler_sanity ( void ) vg_assert(cv != NULL); vg_assert(mx != NULL); } else { - /* Unfortunately these don't hold true when a sighandler is - running. To be fixed. */ - /* vg_assert(cv == NULL); */ - /* vg_assert(mx == NULL); */ + vg_assert(cv == NULL); + vg_assert(mx == NULL); } if (VG_(threads)[i].status != VgTs_Empty) { diff --git a/coregrind/vg_signals.c b/coregrind/vg_signals.c index 57c146810e..6d49be5588 100644 --- a/coregrind/vg_signals.c +++ b/coregrind/vg_signals.c @@ -1595,6 +1595,12 @@ void VG_(deliver_signal) ( ThreadId tid, const vki_ksiginfo_t *info, Bool async break; } + /* Clear the associated mx/cv information as we are no longer + waiting on anything. The original details will be restored + when the signal frame is popped. */ + tst->associated_mx = NULL; + tst->associated_cv = NULL; + /* handler gets the union of the signal's mask and the thread's mask */ handlermask = handler->scss_mask; diff --git a/coregrind/x86/signal.c b/coregrind/x86/signal.c index 4a90714d8e..c77d20c234 100644 --- a/coregrind/x86/signal.c +++ b/coregrind/x86/signal.c @@ -109,6 +109,9 @@ typedef /* Scheduler-private stuff: what was the thread's status prior to delivering this signal? */ ThreadStatus status; + void* /*pthread_mutex_t* */ associated_mx; + void* /*pthread_cond_t* */ associated_cv; + /* Sanity check word. Is the highest-addressed word; do not move!*/ UInt magicE; @@ -268,6 +271,9 @@ void VGA_(push_signal_frame)(ThreadId tid, Addr esp_top_of_frame, frame->status = VgTs_Runnable; else frame->status = tst->status; + + frame->associated_mx = tst->associated_mx; + frame->associated_cv = tst->associated_cv; frame->magicE = 0x27182818; @@ -342,6 +348,9 @@ Int VGA_(pop_signal_frame)(ThreadId tid) was delivered. */ tst->status = frame->status; + tst->associated_mx = frame->associated_mx; + tst->associated_cv = frame->associated_cv; + tst->sig_mask = frame->mask; /* don't use the copy exposed to the handler; it might have changed