9 #include "sanitizer_common/print_address.h"
11 #include <sanitizer/tsan_interface.h>
14 #include <mach/mach_time.h>
17 #ifndef TSAN_VECTORIZE
18 # define TSAN_VECTORIZE __SSE4_2__
22 # include <emmintrin.h>
23 # include <smmintrin.h>
26 unsigned long long x
[2];
30 // TSan-invisible barrier.
31 // Tests use it to establish necessary execution order in a way that does not
32 // interfere with tsan (does not establish synchronization between threads).
33 typedef unsigned invisible_barrier_t
;
38 void __tsan_testonly_barrier_init(invisible_barrier_t
*barrier
,
40 void __tsan_testonly_barrier_wait(invisible_barrier_t
*barrier
);
41 unsigned long __tsan_testonly_shadow_stack_current_size();
46 static inline void barrier_init(invisible_barrier_t
*barrier
, unsigned count
) {
47 __tsan_testonly_barrier_init(barrier
, count
);
50 static inline void barrier_wait(invisible_barrier_t
*barrier
) {
51 __tsan_testonly_barrier_wait(barrier
);
54 // Default instance of the barrier, but a test can declare more manually.
55 invisible_barrier_t barrier
;
58 unsigned long long monotonic_clock_ns() {
59 static mach_timebase_info_data_t timebase_info
;
60 if (timebase_info
.denom
== 0) mach_timebase_info(&timebase_info
);
61 return (mach_absolute_time() * timebase_info
.numer
) / timebase_info
.denom
;
64 unsigned long long monotonic_clock_ns() {
66 clock_gettime(CLOCK_MONOTONIC
, &t
);
67 return (unsigned long long)t
.tv_sec
* 1000000000ull + t
.tv_nsec
;
71 //The const kPCInc must be in sync with StackTrace::GetPreviousInstructionPc
72 #if defined(__s390__) || defined(__i386__) || defined(__x86_64__)
74 #elif defined(__sparc__) || defined(__mips__)
84 void AnnotateThreadName(const char *f
, int l
, const char *name
);
86 void AnnotateRWLockCreate(const char *f
, int l
, void *m
);
87 void AnnotateRWLockCreateStatic(const char *f
, int l
, void *m
);
88 void AnnotateRWLockDestroy(const char *f
, int l
, void *m
);
89 void AnnotateRWLockAcquired(const char *f
, int l
, void *m
, long is_w
);
90 void AnnotateRWLockReleased(const char *f
, int l
, void *m
, long is_w
);
92 void AnnotateIgnoreReadsBegin(const char *f
, int l
);
93 void AnnotateIgnoreReadsEnd(const char *f
, int l
);
94 void AnnotateIgnoreWritesBegin(const char *f
, int l
);
95 void AnnotateIgnoreWritesEnd(const char *f
, int l
);
97 void AnnotateIgnoreSyncBegin(const char *f
, int l
);
98 void AnnotateIgnoreSyncEnd(const char *f
, int l
);
100 void AnnotateHappensBefore(const char *f
, int l
, void *addr
);
101 void AnnotateHappensAfter(const char *f
, int l
, void *addr
);
103 void AnnotateBenignRaceSized(const char *f
, int l
, const volatile void *mem
,
104 unsigned int size
, const char *desc
);
105 void WTFAnnotateBenignRaceSized(const char *f
, int l
, const volatile void *mem
,
106 unsigned int size
, const char *desc
);
112 #define ANNOTATE_RWLOCK_CREATE(m) \
113 AnnotateRWLockCreate(__FILE__, __LINE__, m)
114 #define ANNOTATE_RWLOCK_CREATE_STATIC(m) \
115 AnnotateRWLockCreateStatic(__FILE__, __LINE__, m)
116 #define ANNOTATE_RWLOCK_DESTROY(m) \
117 AnnotateRWLockDestroy(__FILE__, __LINE__, m)
118 #define ANNOTATE_RWLOCK_ACQUIRED(m, is_w) \
119 AnnotateRWLockAcquired(__FILE__, __LINE__, m, is_w)
120 #define ANNOTATE_RWLOCK_RELEASED(m, is_w) \
121 AnnotateRWLockReleased(__FILE__, __LINE__, m, is_w)
122 #define ANNOTATE_HAPPENS_BEFORE(addr) \
123 AnnotateHappensBefore(__FILE__, __LINE__, (void *)(addr))
124 #define ANNOTATE_HAPPENS_AFTER(addr) \
125 AnnotateHappensAfter(__FILE__, __LINE__, (void *)(addr))
126 #define ANNOTATE_BENIGN_RACE(var) \
127 AnnotateBenignRaceSized(__FILE__, __LINE__, &(var), sizeof(var), #var)
128 #define WTF_ANNOTATE_BENIGN_RACE(var) \
129 WTFAnnotateBenignRaceSized(__FILE__, __LINE__, &(var), sizeof(var), #var)
132 #define ASM_SYMBOL(symbol) "_" #symbol
134 #define ASM_SYMBOL(symbol) #symbol