1 //===-- tsan_defs.h ---------------------------------------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
10 //===----------------------------------------------------------------------===//
15 #include "sanitizer_common/sanitizer_internal_defs.h"
16 #include "sanitizer_common/sanitizer_libc.h"
17 #include "tsan_stat.h"
26 const bool kGoMode
= true;
27 const bool kCppMode
= false;
28 const char *const kTsanOptionsEnv
= "GORACE";
29 // Go linker does not support weak symbols.
32 const bool kGoMode
= false;
33 const bool kCppMode
= true;
34 const char *const kTsanOptionsEnv
= "TSAN_OPTIONS";
38 const int kTidBits
= 13;
39 const unsigned kMaxTid
= 1 << kTidBits
;
40 const unsigned kMaxTidInClock
= kMaxTid
* 2; // This includes msb 'freed' bit.
41 const int kClkBits
= 42;
42 const uptr kShadowStackSize
= 64 * 1024;
43 const uptr kTraceStackSize
= 256;
45 #ifdef TSAN_SHADOW_COUNT
46 # if TSAN_SHADOW_COUNT == 2 \
47 || TSAN_SHADOW_COUNT == 4 || TSAN_SHADOW_COUNT == 8
48 const uptr kShadowCnt
= TSAN_SHADOW_COUNT
;
50 # error "TSAN_SHADOW_COUNT must be one of 2,4,8"
53 // Count of shadow values in a shadow cell.
54 const uptr kShadowCnt
= 4;
57 // That many user bytes are mapped onto a single shadow cell.
58 const uptr kShadowCell
= 8;
60 // Size of a single shadow value (u64).
61 const uptr kShadowSize
= 8;
63 // Shadow memory is kShadowMultiplier times larger than user memory.
64 const uptr kShadowMultiplier
= kShadowSize
* kShadowCnt
/ kShadowCell
;
66 #if defined(TSAN_COLLECT_STATS) && TSAN_COLLECT_STATS
67 const bool kCollectStats
= true;
69 const bool kCollectStats
= false;
72 // The following "build consistency" machinery ensures that all source files
73 // are built in the same configuration. Inconsistent builds lead to
74 // hard to debug crashes.
76 void build_consistency_debug();
78 void build_consistency_release();
81 #if TSAN_COLLECT_STATS
82 void build_consistency_stats();
84 void build_consistency_nostats();
87 #if TSAN_SHADOW_COUNT == 1
88 void build_consistency_shadow1();
89 #elif TSAN_SHADOW_COUNT == 2
90 void build_consistency_shadow2();
91 #elif TSAN_SHADOW_COUNT == 4
92 void build_consistency_shadow4();
94 void build_consistency_shadow8();
97 static inline void USED
build_consistency() {
99 build_consistency_debug();
101 build_consistency_release();
103 #if TSAN_COLLECT_STATS
104 build_consistency_stats();
106 build_consistency_nostats();
108 #if TSAN_SHADOW_COUNT == 1
109 build_consistency_shadow1();
110 #elif TSAN_SHADOW_COUNT == 2
111 build_consistency_shadow2();
112 #elif TSAN_SHADOW_COUNT == 4
113 build_consistency_shadow4();
115 build_consistency_shadow8();
121 return a
< b
? a
: b
;
126 return a
> b
? a
: b
;
130 T
RoundUp(T p
, u64 align
) {
131 DCHECK_EQ(align
& (align
- 1), 0);
132 return (T
)(((u64
)p
+ align
- 1) & ~(align
- 1));
136 T
RoundDown(T p
, u64 align
) {
137 DCHECK_EQ(align
& (align
- 1), 0);
138 return (T
)((u64
)p
& ~(align
- 1));
141 // Zeroizes high part, returns 'bits' lsb bits.
143 T
GetLsb(T v
, int bits
) {
144 return (T
)((u64
)v
& ((1ull << bits
) - 1));
149 bool operator==(const MD5Hash
&other
) const;
152 MD5Hash
md5_hash(const void *data
, uptr size
);
163 } // namespace __tsan
165 #endif // TSAN_DEFS_H