diff options
author | Vitaly Buka <vitalybuka@google.com> | 2018-05-14 18:03:34 +0000 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2018-05-14 18:03:34 +0000 |
commit | 0a425a4b904f244b2b34edf971e405cbc5c7203a (patch) | |
tree | cd46e872419f0f88f590f9a16f16eb7d4c1c50ac /test | |
parent | 7bb5a5d2e5f6c07afefd5fde2d7f858663b3da08 (diff) |
[sanitizer] Intercept __pthread_mutex_lock and __pthread_mutex_unlock
Reviewers: eugenis, dvyukov
Subscribers: srhines, kubamracek, llvm-commits
Differential Revision: https://reviews.llvm.org/D46793
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@332268 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/sanitizer_common/TestCases/Linux/pthread_mutex.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/sanitizer_common/TestCases/Linux/pthread_mutex.cc b/test/sanitizer_common/TestCases/Linux/pthread_mutex.cc new file mode 100644 index 000000000..610958143 --- /dev/null +++ b/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; +} |