[compiler-rt] r314384 - tsan: handle signals in pause call
Dmitry Vyukov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 28 00:32:00 PDT 2017
Author: dvyukov
Date: Thu Sep 28 00:32:00 2017
New Revision: 314384
URL: http://llvm.org/viewvc/llvm-project?rev=314384&view=rev
Log:
tsan: handle signals in pause call
Added:
compiler-rt/trunk/test/tsan/signal_pause.cc
Modified:
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=314384&r1=314383&r2=314384&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Sep 28 00:32:00 2017
@@ -371,6 +371,11 @@ TSAN_INTERCEPTOR(int, nanosleep, void *r
return res;
}
+TSAN_INTERCEPTOR(int, pause) {
+ SCOPED_TSAN_INTERCEPTOR(pause);
+ return BLOCK_REAL(pause)();
+}
+
// The sole reason tsan wraps atexit callbacks is to establish synchronization
// between callback setup and callback execution.
struct AtExitCtx {
@@ -2583,6 +2588,7 @@ void InitializeInterceptors() {
TSAN_INTERCEPT(sleep);
TSAN_INTERCEPT(usleep);
TSAN_INTERCEPT(nanosleep);
+ TSAN_INTERCEPT(pause);
TSAN_INTERCEPT(gettimeofday);
TSAN_INTERCEPT(getaddrinfo);
Added: compiler-rt/trunk/test/tsan/signal_pause.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/signal_pause.cc?rev=314384&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/signal_pause.cc (added)
+++ compiler-rt/trunk/test/tsan/signal_pause.cc Thu Sep 28 00:32:00 2017
@@ -0,0 +1,35 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// Test that pause loop handles signals.
+
+#include "test.h"
+#include <signal.h>
+#include <errno.h>
+
+void handler(int signum) {
+ write(2, "DONE\n", 5);
+ _exit(0);
+}
+
+void *thread(void *arg) {
+ for (;;)
+ pause();
+ return 0;
+}
+
+int main(int argc, char** argv) {
+ struct sigaction act = {};
+ act.sa_handler = &handler;
+ if (sigaction(SIGUSR1, &act, 0)) {
+ fprintf(stderr, "sigaction failed %d\n", errno);
+ return 1;
+ }
+ pthread_t th;
+ pthread_create(&th, 0, thread, 0);
+ sleep(1); // give it time to block in pause
+ pthread_kill(th, SIGUSR1);
+ sleep(10); // signal handler must exit the process while we are here
+ return 0;
+}
+
+// CHECK: DONE
More information about the llvm-commits
mailing list