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 char *const kTsanOptionsEnv
= "GORACE";
28 const char *const kTsanOptionsEnv
= "TSAN_OPTIONS";
31 const int kTidBits
= 13;
32 const unsigned kMaxTid
= 1 << kTidBits
;
33 const unsigned kMaxTidInClock
= kMaxTid
* 2; // This includes msb 'freed' bit.
34 const int kClkBits
= 43;
36 const int kShadowStackSize
= 4 * 1024;
37 const int kTraceStackSize
= 256;
40 #ifdef TSAN_SHADOW_COUNT
41 # if TSAN_SHADOW_COUNT == 2 \
42 || TSAN_SHADOW_COUNT == 4 || TSAN_SHADOW_COUNT == 8
43 const uptr kShadowCnt
= TSAN_SHADOW_COUNT
;
45 # error "TSAN_SHADOW_COUNT must be one of 2,4,8"
48 // Count of shadow values in a shadow cell.
49 const uptr kShadowCnt
= 4;
52 // That many user bytes are mapped onto a single shadow cell.
53 const uptr kShadowCell
= 8;
55 // Size of a single shadow value (u64).
56 const uptr kShadowSize
= 8;
58 // Shadow memory is kShadowMultiplier times larger than user memory.
59 const uptr kShadowMultiplier
= kShadowSize
* kShadowCnt
/ kShadowCell
;
61 #if defined(TSAN_COLLECT_STATS) && TSAN_COLLECT_STATS
62 const bool kCollectStats
= true;
64 const bool kCollectStats
= false;
67 // The following "build consistency" machinery ensures that all source files
68 // are built in the same configuration. Inconsistent builds lead to
69 // hard to debug crashes.
71 void build_consistency_debug();
73 void build_consistency_release();
76 #if TSAN_COLLECT_STATS
77 void build_consistency_stats();
79 void build_consistency_nostats();
82 #if TSAN_SHADOW_COUNT == 1
83 void build_consistency_shadow1();
84 #elif TSAN_SHADOW_COUNT == 2
85 void build_consistency_shadow2();
86 #elif TSAN_SHADOW_COUNT == 4
87 void build_consistency_shadow4();
89 void build_consistency_shadow8();
92 static inline void USED
build_consistency() {
94 build_consistency_debug();
96 build_consistency_release();
98 #if TSAN_COLLECT_STATS
99 build_consistency_stats();
101 build_consistency_nostats();
103 #if TSAN_SHADOW_COUNT == 1
104 build_consistency_shadow1();
105 #elif TSAN_SHADOW_COUNT == 2
106 build_consistency_shadow2();
107 #elif TSAN_SHADOW_COUNT == 4
108 build_consistency_shadow4();
110 build_consistency_shadow8();
116 return a
< b
? a
: b
;
121 return a
> b
? a
: b
;
125 T
RoundUp(T p
, int align
) {
126 DCHECK_EQ(align
& (align
- 1), 0);
127 return (T
)(((u64
)p
+ align
- 1) & ~(align
- 1));
132 bool operator==(const MD5Hash
&other
) const;
135 MD5Hash
md5_hash(const void *data
, uptr size
);
138 struct ThreadContext
;
146 } // namespace __tsan
148 #endif // TSAN_DEFS_H