[compiler-rt] r192876 - [Sanitizer] Move pthread_cond_signal and pthread_cond_broadcast to common interceptors
Alexey Samsonov
samsonov at google.com
Thu Oct 17 02:24:03 PDT 2013
Author: samsonov
Date: Thu Oct 17 04:24:03 2013
New Revision: 192876
URL: http://llvm.org/viewvc/llvm-project?rev=192876&view=rev
Log:
[Sanitizer] Move pthread_cond_signal and pthread_cond_broadcast to common interceptors
Modified:
compiler-rt/trunk/lib/msan/tests/msan_test.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=192876&r1=192875&r2=192876&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Thu Oct 17 04:24:03 2013
@@ -2313,12 +2313,16 @@ namespace {
struct SignalCondArg {
pthread_cond_t* cond;
pthread_mutex_t* mu;
+ bool broadcast;
};
void *SignalCond(void *param) {
SignalCondArg *arg = reinterpret_cast<SignalCondArg *>(param);
pthread_mutex_lock(arg->mu);
- pthread_cond_signal(arg->cond);
+ if (arg->broadcast)
+ pthread_cond_broadcast(arg->cond);
+ else
+ pthread_cond_signal(arg->cond);
pthread_mutex_unlock(arg->mu);
return 0;
}
@@ -2327,16 +2331,25 @@ void *SignalCond(void *param) {
TEST(MemorySanitizer, pthread_cond_wait) {
pthread_cond_t cond;
pthread_mutex_t mu;
- SignalCondArg args = {&cond, &mu};
+ SignalCondArg args = {&cond, &mu, false};
pthread_cond_init(&cond, 0);
pthread_mutex_init(&mu, 0);
-
pthread_mutex_lock(&mu);
+
+ // signal
pthread_t thr;
pthread_create(&thr, 0, SignalCond, &args);
int res = pthread_cond_wait(&cond, &mu);
assert(!res);
pthread_join(thr, 0);
+
+ // broadcast
+ args.broadcast = true;
+ pthread_create(&thr, 0, SignalCond, &args);
+ res = pthread_cond_wait(&cond, &mu);
+ assert(!res);
+ pthread_join(thr, 0);
+
pthread_mutex_unlock(&mu);
pthread_mutex_destroy(&mu);
pthread_cond_destroy(&cond);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc?rev=192876&r1=192875&r2=192876&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors.inc Thu Oct 17 04:24:03 2013
@@ -2243,13 +2243,33 @@ INTERCEPTOR(int, pthread_cond_init, void
return REAL(pthread_cond_init)(c, a);
}
+INTERCEPTOR(int, pthread_cond_signal, void *c) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, pthread_cond_signal, c);
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, c, pthread_cond_t_sz);
+ return REAL(pthread_cond_signal)(c);
+}
+
+INTERCEPTOR(int, pthread_cond_broadcast, void *c) {
+ void *ctx;
+ COMMON_INTERCEPTOR_ENTER(ctx, pthread_cond_broadcast, c);
+ COMMON_INTERCEPTOR_READ_RANGE(ctx, c, pthread_cond_t_sz);
+ return REAL(pthread_cond_broadcast)(c);
+}
+
#define INIT_PTHREAD_COND_WAIT \
INTERCEPT_FUNCTION_VER(pthread_cond_wait, GLIBC_2.3.2)
#define INIT_PTHREAD_COND_INIT \
INTERCEPT_FUNCTION_VER(pthread_cond_init, GLIBC_2.3.2)
+#define INIT_PTHREAD_COND_SIGNAL \
+ INTERCEPT_FUNCTION_VER(pthread_cond_signal, GLIBC_2.3.2)
+#define INIT_PTHREAD_COND_BROADCAST \
+ INTERCEPT_FUNCTION_VER(pthread_cond_broadcast, GLIBC_2.3.2)
#else
#define INIT_PTHREAD_COND_WAIT
#define INIT_PTHREAD_COND_INIT
+#define INIT_PTHREAD_COND_SIGNAL
+#define INIT_PTHREAD_COND_BROADCAST
#endif
#define SANITIZER_COMMON_INTERCEPTORS_INIT \
@@ -2334,4 +2354,6 @@ INTERCEPTOR(int, pthread_cond_init, void
INIT_PTHREAD_MUTEX_UNLOCK; \
INIT_PTHREAD_COND_WAIT; \
INIT_PTHREAD_COND_INIT; \
+ INIT_PTHREAD_COND_SIGNAL; \
+ INIT_PTHREAD_COND_BROADCAST; \
/**/
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=192876&r1=192875&r2=192876&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Thu Oct 17 04:24:03 2013
@@ -1093,20 +1093,6 @@ TSAN_INTERCEPTOR(int, pthread_cond_destr
return res;
}
-TSAN_INTERCEPTOR(int, pthread_cond_signal, void *c) {
- SCOPED_TSAN_INTERCEPTOR(pthread_cond_signal, c);
- MemoryRead(thr, pc, (uptr)c, kSizeLog1);
- int res = REAL(pthread_cond_signal)(c);
- return res;
-}
-
-TSAN_INTERCEPTOR(int, pthread_cond_broadcast, void *c) {
- SCOPED_TSAN_INTERCEPTOR(pthread_cond_broadcast, c);
- MemoryRead(thr, pc, (uptr)c, kSizeLog1);
- int res = REAL(pthread_cond_broadcast)(c);
- return res;
-}
-
TSAN_INTERCEPTOR(int, pthread_cond_timedwait, void *c, void *m,
void *abstime) {
SCOPED_TSAN_INTERCEPTOR(pthread_cond_timedwait, c, m, abstime);
@@ -2091,8 +2077,6 @@ void InitializeInterceptors() {
TSAN_INTERCEPT(pthread_rwlock_unlock);
INTERCEPT_FUNCTION_VER(pthread_cond_destroy, GLIBC_2.3.2);
- INTERCEPT_FUNCTION_VER(pthread_cond_signal, GLIBC_2.3.2);
- INTERCEPT_FUNCTION_VER(pthread_cond_broadcast, GLIBC_2.3.2);
INTERCEPT_FUNCTION_VER(pthread_cond_timedwait, GLIBC_2.3.2);
TSAN_INTERCEPT(pthread_barrier_init);
More information about the llvm-commits
mailing list