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"
18 #include "ubsan/ubsan_platform.h"
20 // Setup defaults for compile definitions.
21 #ifndef TSAN_NO_HISTORY
22 # define TSAN_NO_HISTORY 0
25 #ifndef TSAN_COLLECT_STATS
26 # define TSAN_COLLECT_STATS 0
29 #ifndef TSAN_CONTAINS_UBSAN
30 # define TSAN_CONTAINS_UBSAN (CAN_SANITIZE_UB && !defined(SANITIZER_GO))
36 const bool kGoMode
= true;
37 const bool kCppMode
= false;
38 const char *const kTsanOptionsEnv
= "GORACE";
39 // Go linker does not support weak symbols.
42 const bool kGoMode
= false;
43 const bool kCppMode
= true;
44 const char *const kTsanOptionsEnv
= "TSAN_OPTIONS";
48 const int kTidBits
= 13;
49 const unsigned kMaxTid
= 1 << kTidBits
;
51 const unsigned kMaxTidInClock
= kMaxTid
* 2; // This includes msb 'freed' bit.
53 const unsigned kMaxTidInClock
= kMaxTid
; // Go does not track freed memory.
55 const int kClkBits
= 42;
56 const unsigned kMaxTidReuse
= (1 << (64 - kClkBits
)) - 1;
57 const uptr kShadowStackSize
= 64 * 1024;
59 // Count of shadow values in a shadow cell.
60 const uptr kShadowCnt
= 4;
62 // That many user bytes are mapped onto a single shadow cell.
63 const uptr kShadowCell
= 8;
65 // Size of a single shadow value (u64).
66 const uptr kShadowSize
= 8;
68 // Shadow memory is kShadowMultiplier times larger than user memory.
69 const uptr kShadowMultiplier
= kShadowSize
* kShadowCnt
/ kShadowCell
;
71 // That many user bytes are mapped onto a single meta shadow cell.
72 // Must be less or equal to minimal memory allocator alignment.
73 const uptr kMetaShadowCell
= 8;
75 // Size of a single meta shadow value (u32).
76 const uptr kMetaShadowSize
= 4;
79 const bool kCollectHistory
= false;
81 const bool kCollectHistory
= true;
84 const unsigned kInvalidTid
= (unsigned)-1;
86 // The following "build consistency" machinery ensures that all source files
87 // are built in the same configuration. Inconsistent builds lead to
88 // hard to debug crashes.
90 void build_consistency_debug();
92 void build_consistency_release();
95 #if TSAN_COLLECT_STATS
96 void build_consistency_stats();
98 void build_consistency_nostats();
101 static inline void USED
build_consistency() {
103 build_consistency_debug();
105 build_consistency_release();
107 #if TSAN_COLLECT_STATS
108 build_consistency_stats();
110 build_consistency_nostats();
116 return a
< b
? a
: b
;
121 return a
> b
? a
: b
;
125 T
RoundUp(T p
, u64 align
) {
126 DCHECK_EQ(align
& (align
- 1), 0);
127 return (T
)(((u64
)p
+ align
- 1) & ~(align
- 1));
131 T
RoundDown(T p
, u64 align
) {
132 DCHECK_EQ(align
& (align
- 1), 0);
133 return (T
)((u64
)p
& ~(align
- 1));
136 // Zeroizes high part, returns 'bits' lsb bits.
138 T
GetLsb(T v
, int bits
) {
139 return (T
)((u64
)v
& ((1ull << bits
) - 1));
144 bool operator==(const MD5Hash
&other
) const;
147 MD5Hash
md5_hash(const void *data
, uptr size
);
156 // Descriptor of user's memory block.
163 COMPILER_CHECK(sizeof(MBlock
) == 16);
165 } // namespace __tsan
167 #endif // TSAN_DEFS_H