]>
git.proxmox.com Git - rustc.git/blob - src/compiler-rt/lib/tsan/rtl/tsan_defs.h
1 //===-- tsan_defs.h ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of ThreadSanitizer (TSan), a race detector.
12 //===----------------------------------------------------------------------===//
17 #include "sanitizer_common/sanitizer_internal_defs.h"
18 #include "sanitizer_common/sanitizer_libc.h"
19 #include "tsan_stat.h"
20 #include "ubsan/ubsan_platform.h"
22 // Setup defaults for compile definitions.
23 #ifndef TSAN_NO_HISTORY
24 # define TSAN_NO_HISTORY 0
27 #ifndef TSAN_COLLECT_STATS
28 # define TSAN_COLLECT_STATS 0
31 #ifndef TSAN_CONTAINS_UBSAN
32 # if CAN_SANITIZE_UB && !SANITIZER_GO
33 # define TSAN_CONTAINS_UBSAN 1
35 # define TSAN_CONTAINS_UBSAN 0
41 const int kTidBits
= 13;
42 const unsigned kMaxTid
= 1 << kTidBits
;
44 const unsigned kMaxTidInClock
= kMaxTid
* 2; // This includes msb 'freed' bit.
46 const unsigned kMaxTidInClock
= kMaxTid
; // Go does not track freed memory.
48 const int kClkBits
= 42;
49 const unsigned kMaxTidReuse
= (1 << (64 - kClkBits
)) - 1;
50 const uptr kShadowStackSize
= 64 * 1024;
52 // Count of shadow values in a shadow cell.
53 const uptr kShadowCnt
= 4;
55 // That many user bytes are mapped onto a single shadow cell.
56 const uptr kShadowCell
= 8;
58 // Size of a single shadow value (u64).
59 const uptr kShadowSize
= 8;
61 // Shadow memory is kShadowMultiplier times larger than user memory.
62 const uptr kShadowMultiplier
= kShadowSize
* kShadowCnt
/ kShadowCell
;
64 // That many user bytes are mapped onto a single meta shadow cell.
65 // Must be less or equal to minimal memory allocator alignment.
66 const uptr kMetaShadowCell
= 8;
68 // Size of a single meta shadow value (u32).
69 const uptr kMetaShadowSize
= 4;
72 const bool kCollectHistory
= false;
74 const bool kCollectHistory
= true;
77 const unsigned kInvalidTid
= (unsigned)-1;
79 // The following "build consistency" machinery ensures that all source files
80 // are built in the same configuration. Inconsistent builds lead to
81 // hard to debug crashes.
83 void build_consistency_debug();
85 void build_consistency_release();
88 #if TSAN_COLLECT_STATS
89 void build_consistency_stats();
91 void build_consistency_nostats();
94 static inline void USED
build_consistency() {
96 build_consistency_debug();
98 build_consistency_release();
100 #if TSAN_COLLECT_STATS
101 build_consistency_stats();
103 build_consistency_nostats();
109 return a
< b
? a
: b
;
114 return a
> b
? a
: b
;
118 T
RoundUp(T p
, u64 align
) {
119 DCHECK_EQ(align
& (align
- 1), 0);
120 return (T
)(((u64
)p
+ align
- 1) & ~(align
- 1));
124 T
RoundDown(T p
, u64 align
) {
125 DCHECK_EQ(align
& (align
- 1), 0);
126 return (T
)((u64
)p
& ~(align
- 1));
129 // Zeroizes high part, returns 'bits' lsb bits.
131 T
GetLsb(T v
, int bits
) {
132 return (T
)((u64
)v
& ((1ull << bits
) - 1));
137 bool operator==(const MD5Hash
&other
) const;
140 MD5Hash
md5_hash(const void *data
, uptr size
);
150 // Descriptor of user's memory block.
157 COMPILER_CHECK(sizeof(MBlock
) == 16);
159 } // namespace __tsan
161 #endif // TSAN_DEFS_H