tsan_defs.h revision a05fcc1e3e045097f2f1a20798cbe038bbb1d6a9
1//===-- tsan_defs.h ---------------------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file is a part of ThreadSanitizer (TSan), a race detector. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef TSAN_DEFS_H 15#define TSAN_DEFS_H 16 17#include "sanitizer_common/sanitizer_internal_defs.h" 18#include "sanitizer_common/sanitizer_libc.h" 19#include "tsan_stat.h" 20 21#ifndef TSAN_DEBUG 22#define TSAN_DEBUG 0 23#endif // TSAN_DEBUG 24 25namespace __tsan { 26 27const int kTidBits = 13; 28const unsigned kMaxTid = 1 << kTidBits; 29const unsigned kMaxTidInClock = kMaxTid * 2; // This includes msb 'freed' bit. 30const int kClkBits = 43; 31#ifndef TSAN_GO 32const int kShadowStackSize = 4 * 1024; 33const int kTraceStackSize = 256; 34#endif 35 36#ifdef TSAN_SHADOW_COUNT 37# if TSAN_SHADOW_COUNT == 2 \ 38 || TSAN_SHADOW_COUNT == 4 || TSAN_SHADOW_COUNT == 8 39const uptr kShadowCnt = TSAN_SHADOW_COUNT; 40# else 41# error "TSAN_SHADOW_COUNT must be one of 2,4,8" 42# endif 43#else 44// Count of shadow values in a shadow cell. 45const uptr kShadowCnt = 8; 46#endif 47 48// That many user bytes are mapped onto a single shadow cell. 49const uptr kShadowCell = 8; 50 51// Size of a single shadow value (u64). 52const uptr kShadowSize = 8; 53 54// Shadow memory is kShadowMultiplier times larger than user memory. 55const uptr kShadowMultiplier = kShadowSize * kShadowCnt / kShadowCell; 56 57#if defined(TSAN_COLLECT_STATS) && TSAN_COLLECT_STATS 58const bool kCollectStats = true; 59#else 60const bool kCollectStats = false; 61#endif 62 63// The following "build consistency" machinery ensures that all source files 64// are built in the same configuration. Inconsistent builds lead to 65// hard to debug crashes. 66#if TSAN_DEBUG 67void build_consistency_debug(); 68#else 69void build_consistency_release(); 70#endif 71 72#if TSAN_COLLECT_STATS 73void build_consistency_stats(); 74#else 75void build_consistency_nostats(); 76#endif 77 78#if TSAN_SHADOW_COUNT == 1 79void build_consistency_shadow1(); 80#elif TSAN_SHADOW_COUNT == 2 81void build_consistency_shadow2(); 82#elif TSAN_SHADOW_COUNT == 4 83void build_consistency_shadow4(); 84#else 85void build_consistency_shadow8(); 86#endif 87 88static inline void USED build_consistency() { 89#if TSAN_DEBUG 90 build_consistency_debug(); 91#else 92 build_consistency_release(); 93#endif 94#if TSAN_COLLECT_STATS 95 build_consistency_stats(); 96#else 97 build_consistency_nostats(); 98#endif 99#if TSAN_SHADOW_COUNT == 1 100 build_consistency_shadow1(); 101#elif TSAN_SHADOW_COUNT == 2 102 build_consistency_shadow2(); 103#elif TSAN_SHADOW_COUNT == 4 104 build_consistency_shadow4(); 105#else 106 build_consistency_shadow8(); 107#endif 108} 109 110template<typename T> 111T min(T a, T b) { 112 return a < b ? a : b; 113} 114 115template<typename T> 116T max(T a, T b) { 117 return a > b ? a : b; 118} 119 120template<typename T> 121T RoundUp(T p, int align) { 122 DCHECK_EQ(align & (align - 1), 0); 123 return (T)(((u64)p + align - 1) & ~(align - 1)); 124} 125 126struct MD5Hash { 127 u64 hash[2]; 128 bool operator==(const MD5Hash &other) const; 129}; 130 131MD5Hash md5_hash(const void *data, uptr size); 132 133struct ThreadState; 134struct ThreadContext; 135struct Context; 136struct ReportStack; 137class ReportDesc; 138class RegionAlloc; 139class StackTrace; 140struct MBlock; 141 142} // namespace __tsan 143 144#endif // TSAN_DEFS_H 145