summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/tsan/dd/dd_interceptors.cc
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2014-03-05 08:10:27 +0000
committerDmitry Vyukov <dvyukov@google.com>2014-03-05 08:10:27 +0000
commit19126f9075902a7c3b6b966290bbf742ce8b86b7 (patch)
treeeb6224e7d762a2f809891fc42eef47869e5ce4ae /compiler-rt/lib/tsan/dd/dd_interceptors.cc
parent8548299aa8c3af313407cb42250e812f55b80b38 (diff)
downloadbcm5719-llvm-19126f9075902a7c3b6b966290bbf742ce8b86b7.tar.gz
bcm5719-llvm-19126f9075902a7c3b6b966290bbf742ce8b86b7.zip
tsan: add interceptors for pthread_spinlock_t and ptread_rwlock_t for deadlock detector
llvm-svn: 202947
Diffstat (limited to 'compiler-rt/lib/tsan/dd/dd_interceptors.cc')
-rw-r--r--compiler-rt/lib/tsan/dd/dd_interceptors.cc109
1 files changed, 102 insertions, 7 deletions
diff --git a/compiler-rt/lib/tsan/dd/dd_interceptors.cc b/compiler-rt/lib/tsan/dd/dd_interceptors.cc
index 18494908a25..3374a40bfab 100644
--- a/compiler-rt/lib/tsan/dd/dd_interceptors.cc
+++ b/compiler-rt/lib/tsan/dd/dd_interceptors.cc
@@ -28,17 +28,14 @@ static void InitThread() {
INTERCEPTOR(int, pthread_mutex_destroy, pthread_mutex_t *m) {
InitThread();
- int res = REAL(pthread_mutex_destroy)(m);
MutexDestroy(thr, (uptr)m);
- return res;
+ return REAL(pthread_mutex_destroy)(m);
}
INTERCEPTOR(int, pthread_mutex_lock, pthread_mutex_t *m) {
InitThread();
- int res = REAL(pthread_mutex_lock)(m);
- if (res == 0)
- MutexLock(thr, (uptr)m, true, false);
- return res;
+ MutexLock(thr, (uptr)m, true, false);
+ return REAL(pthread_mutex_lock)(m);
}
INTERCEPTOR(int, pthread_mutex_trylock, pthread_mutex_t *m) {
@@ -52,10 +49,94 @@ INTERCEPTOR(int, pthread_mutex_trylock, pthread_mutex_t *m) {
INTERCEPTOR(int, pthread_mutex_unlock, pthread_mutex_t *m) {
InitThread();
MutexUnlock(thr, (uptr)m, true);
- int res = REAL(pthread_mutex_unlock)(m);
+ return REAL(pthread_mutex_unlock)(m);
+}
+
+INTERCEPTOR(int, pthread_spin_destroy, pthread_spinlock_t *m) {
+ InitThread();
+ int res = REAL(pthread_spin_destroy)(m);
+ MutexDestroy(thr, (uptr)m);
return res;
}
+INTERCEPTOR(int, pthread_spin_lock, pthread_spinlock_t *m) {
+ InitThread();
+ MutexLock(thr, (uptr)m, true, false);
+ return REAL(pthread_spin_lock)(m);
+}
+
+INTERCEPTOR(int, pthread_spin_trylock, pthread_spinlock_t *m) {
+ InitThread();
+ int res = REAL(pthread_spin_trylock)(m);
+ if (res == 0)
+ MutexLock(thr, (uptr)m, true, true);
+ return res;
+}
+
+INTERCEPTOR(int, pthread_spin_unlock, pthread_spinlock_t *m) {
+ InitThread();
+ MutexUnlock(thr, (uptr)m, true);
+ return REAL(pthread_spin_unlock)(m);
+}
+
+INTERCEPTOR(int, pthread_rwlock_destroy, pthread_rwlock_t *m) {
+ InitThread();
+ MutexDestroy(thr, (uptr)m);
+ return REAL(pthread_rwlock_destroy)(m);
+}
+
+INTERCEPTOR(int, pthread_rwlock_rdlock, pthread_rwlock_t *m) {
+ InitThread();
+ MutexLock(thr, (uptr)m, false, false);
+ return REAL(pthread_rwlock_rdlock)(m);
+}
+
+INTERCEPTOR(int, pthread_rwlock_tryrdlock, pthread_rwlock_t *m) {
+ InitThread();
+ int res = REAL(pthread_rwlock_tryrdlock)(m);
+ if (res == 0)
+ MutexLock(thr, (uptr)m, false, true);
+ return res;
+}
+
+INTERCEPTOR(int, pthread_rwlock_timedrdlock, pthread_rwlock_t *m,
+ const timespec *abstime) {
+ InitThread();
+ int res = REAL(pthread_rwlock_timedrdlock)(m, abstime);
+ if (res == 0)
+ MutexLock(thr, (uptr)m, false, true);
+ return res;
+}
+
+INTERCEPTOR(int, pthread_rwlock_wrlock, pthread_rwlock_t *m) {
+ InitThread();
+ MutexLock(thr, (uptr)m, true, false);
+ return REAL(pthread_rwlock_wrlock)(m);
+}
+
+INTERCEPTOR(int, pthread_rwlock_trywrlock, pthread_rwlock_t *m) {
+ InitThread();
+ int res = REAL(pthread_rwlock_trywrlock)(m);
+ if (res == 0)
+ MutexLock(thr, (uptr)m, true, true);
+ return res;
+}
+
+INTERCEPTOR(int, pthread_rwlock_timedwrlock, pthread_rwlock_t *m,
+ const timespec *abstime) {
+ InitThread();
+ int res = REAL(pthread_rwlock_timedwrlock)(m, abstime);
+ if (res == 0)
+ MutexLock(thr, (uptr)m, true, true);
+ return res;
+}
+
+INTERCEPTOR(int, pthread_rwlock_unlock, pthread_rwlock_t *m) {
+ InitThread();
+ MutexUnlock(thr, (uptr)m, true); // note: not necessary write unlock
+ return REAL(pthread_rwlock_unlock)(m);
+}
+
namespace __dsan {
void InitializeInterceptors() {
@@ -63,6 +144,20 @@ void InitializeInterceptors() {
INTERCEPT_FUNCTION(pthread_mutex_lock);
INTERCEPT_FUNCTION(pthread_mutex_trylock);
INTERCEPT_FUNCTION(pthread_mutex_unlock);
+
+ INTERCEPT_FUNCTION(pthread_spin_destroy);
+ INTERCEPT_FUNCTION(pthread_spin_lock);
+ INTERCEPT_FUNCTION(pthread_spin_trylock);
+ INTERCEPT_FUNCTION(pthread_spin_unlock);
+
+ INTERCEPT_FUNCTION(pthread_rwlock_destroy);
+ INTERCEPT_FUNCTION(pthread_rwlock_rdlock);
+ INTERCEPT_FUNCTION(pthread_rwlock_tryrdlock);
+ INTERCEPT_FUNCTION(pthread_rwlock_timedrdlock);
+ INTERCEPT_FUNCTION(pthread_rwlock_wrlock);
+ INTERCEPT_FUNCTION(pthread_rwlock_trywrlock);
+ INTERCEPT_FUNCTION(pthread_rwlock_timedwrlock);
+ INTERCEPT_FUNCTION(pthread_rwlock_unlock);
}
} // namespace __dsan
OpenPOWER on IntegriCloud