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 # if CAN_SANITIZE_UB && !SANITIZER_GO
31 # define TSAN_CONTAINS_UBSAN 1
33 # define TSAN_CONTAINS_UBSAN 0
39 const int kTidBits
= 13;
40 const unsigned kMaxTid
= 1 << kTidBits
;
42 const unsigned kMaxTidInClock
= kMaxTid
* 2; // This includes msb 'freed' bit.
44 const unsigned kMaxTidInClock
= kMaxTid
; // Go does not track freed memory.
46 const int kClkBits
= 42;
47 const unsigned kMaxTidReuse
= (1 << (64 - kClkBits
)) - 1;
48 const uptr kShadowStackSize
= 64 * 1024;
50 // Count of shadow values in a shadow cell.
51 const uptr kShadowCnt
= 4;
53 // That many user bytes are mapped onto a single shadow cell.
54 const uptr kShadowCell
= 8;
56 // Size of a single shadow value (u64).
57 const uptr kShadowSize
= 8;
59 // Shadow memory is kShadowMultiplier times larger than user memory.
60 const uptr kShadowMultiplier
= kShadowSize
* kShadowCnt
/ kShadowCell
;
62 // That many user bytes are mapped onto a single meta shadow cell.
63 // Must be less or equal to minimal memory allocator alignment.
64 const uptr kMetaShadowCell
= 8;
66 // Size of a single meta shadow value (u32).
67 const uptr kMetaShadowSize
= 4;
70 const bool kCollectHistory
= false;
72 const bool kCollectHistory
= true;
75 const unsigned kInvalidTid
= (unsigned)-1;
77 // The following "build consistency" machinery ensures that all source files
78 // are built in the same configuration. Inconsistent builds lead to
79 // hard to debug crashes.
81 void build_consistency_debug();
83 void build_consistency_release();
86 #if TSAN_COLLECT_STATS
87 void build_consistency_stats();
89 void build_consistency_nostats();
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();
107 return a
< b
? a
: b
;
112 return a
> b
? a
: b
;
116 T
RoundUp(T p
, u64 align
) {
117 DCHECK_EQ(align
& (align
- 1), 0);
118 return (T
)(((u64
)p
+ align
- 1) & ~(align
- 1));
122 T
RoundDown(T p
, u64 align
) {
123 DCHECK_EQ(align
& (align
- 1), 0);
124 return (T
)((u64
)p
& ~(align
- 1));
127 // Zeroizes high part, returns 'bits' lsb bits.
129 T
GetLsb(T v
, int bits
) {
130 return (T
)((u64
)v
& ((1ull << bits
) - 1));
135 bool operator==(const MD5Hash
&other
) const;
138 MD5Hash
md5_hash(const void *data
, uptr size
);
148 // Descriptor of user's memory block.
155 COMPILER_CHECK(sizeof(MBlock
) == 16);
157 } // namespace __tsan
159 #endif // TSAN_DEFS_H