Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//===-- dd_interceptors.cc ------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "dd_rtl.h"
#include "interception/interception.h"
#include <pthread.h>
using namespace __dsan;
extern "C" void *__libc_malloc(uptr size);
extern "C" void __libc_free(void *ptr);
static __thread Thread *thr;
static void InitThread() {
if (thr != 0)
return;
thr = (Thread*)InternalAlloc(sizeof(*thr));
internal_memset(thr, 0, sizeof(*thr));
ThreadInit(thr);
}
INTERCEPTOR(int, pthread_mutex_destroy, pthread_mutex_t *m) {
InitThread();
int res = REAL(pthread_mutex_destroy)(m);
MutexDestroy(thr, (uptr)m);
return res;
}
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;
}
INTERCEPTOR(int, pthread_mutex_trylock, pthread_mutex_t *m) {
InitThread();
int res = REAL(pthread_mutex_trylock)(m);
if (res == 0)
MutexLock(thr, (uptr)m, true, true);
return res;
}
INTERCEPTOR(int, pthread_mutex_unlock, pthread_mutex_t *m) {
InitThread();
MutexUnlock(thr, (uptr)m, true);
int res = REAL(pthread_mutex_unlock)(m);
return res;
}
namespace __dsan {
void InitializeInterceptors() {
INTERCEPT_FUNCTION(pthread_mutex_destroy);
INTERCEPT_FUNCTION(pthread_mutex_lock);
INTERCEPT_FUNCTION(pthread_mutex_trylock);
INTERCEPT_FUNCTION(pthread_mutex_unlock);
}
} // namespace __dsan