Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sanitizer] Intercept __pthread_mutex_lock and __pthread_mutex_unlock
Reviewers: eugenis, dvyukov Subscribers: srhines, kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D46793 llvm-svn: 332268
- Loading branch information
1 parent
5e0feea
commit e5bd326
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
compiler-rt/test/sanitizer_common/TestCases/Linux/pthread_mutex.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |