]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
If a thread is waiting on a mutex or condition variable when a signal is
authorTom Hughes <tom@compton.nu>
Sat, 16 Oct 2004 16:17:06 +0000 (16:17 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 16 Oct 2004 16:17:06 +0000 (16:17 +0000)
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

coregrind/vg_scheduler.c
coregrind/vg_signals.c
coregrind/x86/signal.c

index 1252f7df5aba0998f2f8a8c0e51d8dda6582722b..39ad8372f052e6510e2358159653b1a4de8f945f 100644 (file)
@@ -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) {
index 57c146810e6a64d4a33455ad359034705e87b637..6d49be55882a5e14cbf90bde5afc19ef93dcb57d 100644 (file)
@@ -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;
index 4a90714d8e6eebed8cbec19f7194ba47e909edda..c77d20c2342f92d576287957edfef51056a90adb 100644 (file)
@@ -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