[PATCH] D57876: Implement pthread_exit() interceptor for Thread sanitizer
Yuri Per via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 6 23:49:56 PST 2019
yuri created this revision.
yuri added a reviewer: dvyukov.
yuri added a project: Sanitizers.
Herald added subscribers: Sanitizers, llvm-commits, jfb, kubamracek.
Herald added a project: LLVM.
This change is preparation for fiber support.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D57876
Files:
lib/tsan/rtl/tsan_interceptors.cc
test/tsan/thread_exit.c
Index: test/tsan/thread_exit.c
===================================================================
--- /dev/null
+++ test/tsan/thread_exit.c
@@ -0,0 +1,25 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+#include "test.h"
+
+int var;
+
+void *Thread(void *x) {
+ pthread_exit(&var);
+ return 0;
+}
+
+int main() {
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ void *retval = 0;
+ pthread_join(t, &retval);
+ if (retval != &var) {
+ fprintf(stderr, "Unexpected return value\n");
+ exit(1);
+ }
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: PASS
Index: lib/tsan/rtl/tsan_interceptors.cc
===================================================================
--- lib/tsan/rtl/tsan_interceptors.cc
+++ lib/tsan/rtl/tsan_interceptors.cc
@@ -1050,6 +1050,11 @@
return res;
}
+TSAN_INTERCEPTOR(void, pthread_exit, void *retval) {
+ SCOPED_TSAN_INTERCEPTOR(pthread_exit, retval);
+ REAL(pthread_exit)(retval);
+}
+
#if SANITIZER_LINUX
TSAN_INTERCEPTOR(int, pthread_tryjoin_np, void *th, void **ret) {
SCOPED_TSAN_INTERCEPTOR(pthread_tryjoin_np, th, ret);
@@ -2677,6 +2682,7 @@
TSAN_INTERCEPT(pthread_create);
TSAN_INTERCEPT(pthread_join);
TSAN_INTERCEPT(pthread_detach);
+ TSAN_INTERCEPT(pthread_exit);
#if SANITIZER_LINUX
TSAN_INTERCEPT(pthread_tryjoin_np);
TSAN_INTERCEPT(pthread_timedjoin_np);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57876.185710.patch
Type: text/x-patch
Size: 1413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190207/05c5e683/attachment.bin>
More information about the llvm-commits
mailing list