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";
30 const bool kGoMode
= false;
31 const bool kCppMode
= true;
32 const char *const kTsanOptionsEnv
= "TSAN_OPTIONS";
35 const int kTidBits
= 13;
36 const unsigned kMaxTid
= 1 << kTidBits
;
37 const unsigned kMaxTidInClock
= kMaxTid
* 2; // This includes msb 'freed' bit.
38 const int kClkBits
= 43;
40 const int kShadowStackSize
= 4 * 1024;
41 const int kTraceStackSize
= 256;
44 #ifdef TSAN_SHADOW_COUNT
45 # if TSAN_SHADOW_COUNT == 2 \
46 || TSAN_SHADOW_COUNT == 4 || TSAN_SHADOW_COUNT == 8
47 const uptr kShadowCnt
= TSAN_SHADOW_COUNT
;
49 # error "TSAN_SHADOW_COUNT must be one of 2,4,8"
52 // Count of shadow values in a shadow cell.
53 const uptr kShadowCnt
= 4;
56 // That many user bytes are mapped onto a single shadow cell.
57 const uptr kShadowCell
= 8;
59 // Size of a single shadow value (u64).
60 const uptr kShadowSize
= 8;
62 // Shadow memory is kShadowMultiplier times larger than user memory.
63 const uptr kShadowMultiplier
= kShadowSize
* kShadowCnt
/ kShadowCell
;
65 #if defined(TSAN_COLLECT_STATS) && TSAN_COLLECT_STATS
66 const bool kCollectStats
= true;
68 const bool kCollectStats
= false;
71 // The following "build consistency" machinery ensures that all source files
72 // are built in the same configuration. Inconsistent builds lead to
73 // hard to debug crashes.
75 void build_consistency_debug();
77 void build_consistency_release();
80 #if TSAN_COLLECT_STATS
81 void build_consistency_stats();
83 void build_consistency_nostats();
86 #if TSAN_SHADOW_COUNT == 1
87 void build_consistency_shadow1();
88 #elif TSAN_SHADOW_COUNT == 2
89 void build_consistency_shadow2();
90 #elif TSAN_SHADOW_COUNT == 4
91 void build_consistency_shadow4();
93 void build_consistency_shadow8();
96 static inline void USED
build_consistency() {
98 build_consistency_debug();
100 build_consistency_release();
102 #if TSAN_COLLECT_STATS
103 build_consistency_stats();
105 build_consistency_nostats();
107 #if TSAN_SHADOW_COUNT == 1
108 build_consistency_shadow1();
109 #elif TSAN_SHADOW_COUNT == 2
110 build_consistency_shadow2();
111 #elif TSAN_SHADOW_COUNT == 4
112 build_consistency_shadow4();
114 build_consistency_shadow8();
120 return a
< b
? a
: b
;
125 return a
> b
? a
: b
;
129 T
RoundUp(T p
, u64 align
) {
130 DCHECK_EQ(align
& (align
- 1), 0);
131 return (T
)(((u64
)p
+ align
- 1) & ~(align
- 1));
135 T
RoundDown(T p
, u64 align
) {
136 DCHECK_EQ(align
& (align
- 1), 0);
137 return (T
)((u64
)p
& ~(align
- 1));
142 bool operator==(const MD5Hash
&other
) const;
145 MD5Hash
md5_hash(const void *data
, uptr size
);
148 struct ThreadContext
;
156 } // namespace __tsan
158 #endif // TSAN_DEFS_H