* include/bits/allocator.h (operator==, operator!=): Add exception
[official-gcc.git] / libsanitizer / tsan / tsan_defs.h
blob3f20797ff4bcfad3a3e88d1dac244df9a55559dd
1 //===-- tsan_defs.h ---------------------------------------------*- C++ -*-===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of ThreadSanitizer (TSan), a race detector.
9 //
10 //===----------------------------------------------------------------------===//
12 #ifndef TSAN_DEFS_H
13 #define TSAN_DEFS_H
15 #include "sanitizer_common/sanitizer_internal_defs.h"
16 #include "sanitizer_common/sanitizer_libc.h"
17 #include "tsan_stat.h"
19 #ifndef TSAN_DEBUG
20 #define TSAN_DEBUG 0
21 #endif // TSAN_DEBUG
23 namespace __tsan {
25 #ifdef TSAN_GO
26 const bool kGoMode = true;
27 const bool kCppMode = false;
28 const char *const kTsanOptionsEnv = "GORACE";
29 // Go linker does not support weak symbols.
30 #define CPP_WEAK
31 #else
32 const bool kGoMode = false;
33 const bool kCppMode = true;
34 const char *const kTsanOptionsEnv = "TSAN_OPTIONS";
35 #define CPP_WEAK WEAK
36 #endif
38 const int kTidBits = 13;
39 const unsigned kMaxTid = 1 << kTidBits;
40 const unsigned kMaxTidInClock = kMaxTid * 2; // This includes msb 'freed' bit.
41 const int kClkBits = 42;
42 const uptr kShadowStackSize = 64 * 1024;
43 const uptr kTraceStackSize = 256;
45 #ifdef TSAN_SHADOW_COUNT
46 # if TSAN_SHADOW_COUNT == 2 \
47 || TSAN_SHADOW_COUNT == 4 || TSAN_SHADOW_COUNT == 8
48 const uptr kShadowCnt = TSAN_SHADOW_COUNT;
49 # else
50 # error "TSAN_SHADOW_COUNT must be one of 2,4,8"
51 # endif
52 #else
53 // Count of shadow values in a shadow cell.
54 const uptr kShadowCnt = 4;
55 #endif
57 // That many user bytes are mapped onto a single shadow cell.
58 const uptr kShadowCell = 8;
60 // Size of a single shadow value (u64).
61 const uptr kShadowSize = 8;
63 // Shadow memory is kShadowMultiplier times larger than user memory.
64 const uptr kShadowMultiplier = kShadowSize * kShadowCnt / kShadowCell;
66 #if defined(TSAN_COLLECT_STATS) && TSAN_COLLECT_STATS
67 const bool kCollectStats = true;
68 #else
69 const bool kCollectStats = false;
70 #endif
72 // The following "build consistency" machinery ensures that all source files
73 // are built in the same configuration. Inconsistent builds lead to
74 // hard to debug crashes.
75 #if TSAN_DEBUG
76 void build_consistency_debug();
77 #else
78 void build_consistency_release();
79 #endif
81 #if TSAN_COLLECT_STATS
82 void build_consistency_stats();
83 #else
84 void build_consistency_nostats();
85 #endif
87 #if TSAN_SHADOW_COUNT == 1
88 void build_consistency_shadow1();
89 #elif TSAN_SHADOW_COUNT == 2
90 void build_consistency_shadow2();
91 #elif TSAN_SHADOW_COUNT == 4
92 void build_consistency_shadow4();
93 #else
94 void build_consistency_shadow8();
95 #endif
97 static inline void USED build_consistency() {
98 #if TSAN_DEBUG
99 build_consistency_debug();
100 #else
101 build_consistency_release();
102 #endif
103 #if TSAN_COLLECT_STATS
104 build_consistency_stats();
105 #else
106 build_consistency_nostats();
107 #endif
108 #if TSAN_SHADOW_COUNT == 1
109 build_consistency_shadow1();
110 #elif TSAN_SHADOW_COUNT == 2
111 build_consistency_shadow2();
112 #elif TSAN_SHADOW_COUNT == 4
113 build_consistency_shadow4();
114 #else
115 build_consistency_shadow8();
116 #endif
119 template<typename T>
120 T min(T a, T b) {
121 return a < b ? a : b;
124 template<typename T>
125 T max(T a, T b) {
126 return a > b ? a : b;
129 template<typename T>
130 T RoundUp(T p, u64 align) {
131 DCHECK_EQ(align & (align - 1), 0);
132 return (T)(((u64)p + align - 1) & ~(align - 1));
135 template<typename T>
136 T RoundDown(T p, u64 align) {
137 DCHECK_EQ(align & (align - 1), 0);
138 return (T)((u64)p & ~(align - 1));
141 // Zeroizes high part, returns 'bits' lsb bits.
142 template<typename T>
143 T GetLsb(T v, int bits) {
144 return (T)((u64)v & ((1ull << bits) - 1));
147 struct MD5Hash {
148 u64 hash[2];
149 bool operator==(const MD5Hash &other) const;
152 MD5Hash md5_hash(const void *data, uptr size);
154 struct ThreadState;
155 class ThreadContext;
156 struct Context;
157 struct ReportStack;
158 class ReportDesc;
159 class RegionAlloc;
160 class StackTrace;
161 struct MBlock;
163 } // namespace __tsan
165 #endif // TSAN_DEFS_H