[PATCH] D46793: [sanitizer] Intercept __pthread_mutex_lock and __pthread_mutex_unlock
Vitaly Buka via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat May 12 22:42:20 PDT 2018
vitalybuka updated this revision to Diff 146497.
vitalybuka added a comment.
use alias
Repository:
rL LLVM
https://reviews.llvm.org/D46793
Files:
compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/test/sanitizer_common/TestCases/Linux/pthread_mutex.cc
Index: compiler-rt/test/sanitizer_common/TestCases/Linux/pthread_mutex.cc
===================================================================
--- /dev/null
+++ compiler-rt/test/sanitizer_common/TestCases/Linux/pthread_mutex.cc
@@ -0,0 +1,34 @@
+// RUN: %clangxx -O1 %s -o %t && %run %t
+// RUN: %clangxx -O1 -DUSE_GLIBC %s -o %t && %run %t
+// UNSUPPORTED: android
+
+#include <pthread.h>
+
+#ifdef USE_GLIBC
+extern "C" int __pthread_mutex_lock(pthread_mutex_t *__mutex);
+extern "C" int __pthread_mutex_unlock(pthread_mutex_t *__mutex);
+#define LOCK __pthread_mutex_lock
+#define UNLOCK __pthread_mutex_unlock
+#else
+#define LOCK pthread_mutex_lock
+#define UNLOCK pthread_mutex_unlock
+#endif
+
+pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
+int x;
+
+static void *Start(void *arg) {
+ LOCK(&m);
+ ++x;
+ UNLOCK(&m);
+ return nullptr;
+}
+
+int main() {
+ pthread_t threads[2] = {};
+ for (pthread_t &t : threads)
+ pthread_create(&t, 0, &Start, 0);
+ for (pthread_t &t : threads)
+ pthread_join(t, 0);
+ return 0;
+}
Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -365,6 +365,7 @@
(SI_LINUX || SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_MAC || SI_SOLARIS)
#define SANITIZER_INTERCEPT_PTHREAD_MUTEX SI_POSIX
+#define SANITIZER_INTERCEPT___PTHREAD_MUTEX SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_PTHREAD_SETNAME_NP \
(SI_FREEBSD || SI_NETBSD || SI_OPENBSD || SI_LINUX_NOT_ANDROID || SI_SOLARIS)
#define SANITIZER_INTERCEPT_PTHREAD_GETNAME_NP \
Index: compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
+++ compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.inc
@@ -4054,13 +4054,23 @@
#define INIT_PTHREAD_MUTEX_UNLOCK
#endif
+#if SANITIZER_INTERCEPT___PTHREAD_MUTEX
+INTERCEPTOR(int, __pthread_mutex_lock, void *m)
+ALIAS(WRAPPER_NAME(pthread_mutex_lock));
+
+INTERCEPTOR(int, __pthread_mutex_unlock, void *m)
+ALIAS(WRAPPER_NAME(pthread_mutex_unlock));
+#endif
+
#if SANITIZER_NETBSD
-INTERCEPTOR(int, __libc_mutex_lock, void *m) \
- ALIAS(WRAPPER_NAME(pthread_mutex_lock));
-INTERCEPTOR(int, __libc_mutex_unlock, void *m) \
- ALIAS(WRAPPER_NAME(pthread_mutex_unlock));
-INTERCEPTOR(int, __libc_thr_setcancelstate, int state, int *oldstate) \
- ALIAS(WRAPPER_NAME(pthread_setcancelstate));
+INTERCEPTOR(int, __libc_mutex_lock, void *m)
+ALIAS(WRAPPER_NAME(pthread_mutex_lock));
+
+INTERCEPTOR(int, __libc_mutex_unlock, void *m)
+ALIAS(WRAPPER_NAME(pthread_mutex_unlock));
+
+INTERCEPTOR(int, __libc_thr_setcancelstate, int state, int *oldstate)
+ALIAS(WRAPPER_NAME(pthread_setcancelstate));
#endif
#if SANITIZER_INTERCEPT_GETMNTENT || SANITIZER_INTERCEPT_GETMNTENT_R
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46793.146497.patch
Type: text/x-patch
Size: 3027 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180513/f4a97819/attachment.bin>
More information about the llvm-commits
mailing list