forked from OSchip/llvm-project
tsan: support sigsuspend() call
Intercepting it makes it process pending signal before return. llvm-svn: 186400
This commit is contained in:
parent
82ec87dbdb
commit
1a0c76fa55
|
@ -0,0 +1,38 @@
|
|||
// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static bool signal_handler_ran = false;
|
||||
|
||||
void do_nothing_signal_handler(int signum) {
|
||||
write(1, "HANDLER\n", 8);
|
||||
signal_handler_ran = true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
const int kSignalToTest = SIGSYS;
|
||||
assert(SIG_ERR != signal(kSignalToTest, do_nothing_signal_handler));
|
||||
sigset_t empty_set;
|
||||
assert(0 == sigemptyset(&empty_set));
|
||||
sigset_t one_signal = empty_set;
|
||||
assert(0 == sigaddset(&one_signal, kSignalToTest));
|
||||
sigset_t old_set;
|
||||
assert(0 == sigprocmask(SIG_BLOCK, &one_signal, &old_set));
|
||||
raise(kSignalToTest);
|
||||
assert(!signal_handler_ran);
|
||||
sigset_t all_but_one;
|
||||
assert(0 == sigfillset(&all_but_one));
|
||||
assert(0 == sigdelset(&all_but_one, kSignalToTest));
|
||||
sigsuspend(&all_but_one);
|
||||
assert(signal_handler_ran);
|
||||
|
||||
// Restore the original set.
|
||||
assert(0 == sigprocmask(SIG_SETMASK, &old_set, NULL));
|
||||
printf("DONE");
|
||||
}
|
||||
|
||||
// CHECK: HANDLER
|
||||
// CHECK: DONE
|
|
@ -1707,6 +1707,11 @@ TSAN_INTERCEPTOR(sighandler_t, signal, int sig, sighandler_t h) {
|
|||
return old.sa_handler;
|
||||
}
|
||||
|
||||
TSAN_INTERCEPTOR(int, sigsuspend, const sigset_t *mask) {
|
||||
SCOPED_TSAN_INTERCEPTOR(sigsuspend, mask);
|
||||
return REAL(sigsuspend)(mask);
|
||||
}
|
||||
|
||||
TSAN_INTERCEPTOR(int, raise, int sig) {
|
||||
SCOPED_TSAN_INTERCEPTOR(raise, sig);
|
||||
SignalContext *sctx = SigCtx(thr);
|
||||
|
@ -2071,6 +2076,7 @@ void InitializeInterceptors() {
|
|||
|
||||
TSAN_INTERCEPT(sigaction);
|
||||
TSAN_INTERCEPT(signal);
|
||||
TSAN_INTERCEPT(sigsuspend);
|
||||
TSAN_INTERCEPT(raise);
|
||||
TSAN_INTERCEPT(kill);
|
||||
TSAN_INTERCEPT(pthread_kill);
|
||||
|
|
|
@ -257,6 +257,7 @@ void StatOutput(u64 *stat) {
|
|||
name[StatInt_poll] = " poll ";
|
||||
name[StatInt_sigaction] = " sigaction ";
|
||||
name[StatInt_signal] = " signal ";
|
||||
name[StatInt_sigsuspend] = " sigsuspend ";
|
||||
name[StatInt_raise] = " raise ";
|
||||
name[StatInt_kill] = " kill ";
|
||||
name[StatInt_pthread_kill] = " pthread_kill ";
|
||||
|
|
|
@ -252,6 +252,7 @@ enum StatType {
|
|||
StatInt_poll,
|
||||
StatInt_sigaction,
|
||||
StatInt_signal,
|
||||
StatInt_sigsuspend,
|
||||
StatInt_raise,
|
||||
StatInt_kill,
|
||||
StatInt_pthread_kill,
|
||||
|
|
Loading…
Reference in New Issue