Summary: | sem_post in thread signal handler => assertion failure | ||
---|---|---|---|
Product: | [Developer tools] valgrind | Reporter: | Kenneth C. Schalk <ken> |
Component: | general | Assignee: | Julian Seward <jseward> |
Status: | RESOLVED FIXED | ||
Severity: | crash | ||
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Compiled Sources | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: | Proposed patch |
Description
Kenneth C. Schalk
2004-01-07 20:45:15 UTC
Created attachment 4051 [details]
Proposed patch
This patch saves and clears a thread's associated_mx and associated_cv before
delivering a signal, and restores them when returning from the signal handler.
So far this seems to fix my problem.
CVS commit by thughes: 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 M +2 -4 vg_scheduler.c 1.188 M +6 -0 vg_signals.c 1.95 M +9 -0 x86/signal.c 1.3 --- valgrind/coregrind/vg_scheduler.c #1.187:1.188 @@ -3237,8 +3237,6 @@ void scheduler_sanity ( void ) 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); } --- valgrind/coregrind/vg_signals.c #1.94:1.95 @@ -1596,4 +1596,10 @@ void VG_(deliver_signal) ( ThreadId tid, } + /* 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 */ --- valgrind/coregrind/x86/signal.c #1.2:1.3 @@ -110,4 +110,7 @@ typedef 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!*/ @@ -270,4 +273,7 @@ void VGA_(push_signal_frame)(ThreadId ti frame->status = tst->status; + frame->associated_mx = tst->associated_mx; + frame->associated_cv = tst->associated_cv; + frame->magicE = 0x27182818; @@ -343,4 +349,7 @@ Int VGA_(pop_signal_frame)(ThreadId tid) tst->status = frame->status; + tst->associated_mx = frame->associated_mx; + tst->associated_cv = frame->associated_cv; + tst->sig_mask = frame->mask; |