2012-05-10 21:48:04 +08:00
|
|
|
//===-- tsan_rtl.h ----------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
|
|
//
|
|
|
|
// Main internal TSan header file.
|
|
|
|
//
|
|
|
|
// Ground rules:
|
|
|
|
// - C++ run-time should not be used (static CTORs, RTTI, exceptions, static
|
|
|
|
// function-scope locals)
|
|
|
|
// - All functions/classes/etc reside in namespace __tsan, except for those
|
|
|
|
// declared in tsan_interface.h.
|
|
|
|
// - Platform-specific files should be used instead of ifdefs (*).
|
|
|
|
// - No system headers included in header files (*).
|
|
|
|
// - Platform specific headres included only into platform-specific files (*).
|
|
|
|
//
|
|
|
|
// (*) Except when inlining is critical for performance.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef TSAN_RTL_H
|
|
|
|
#define TSAN_RTL_H
|
|
|
|
|
2012-12-05 18:09:15 +08:00
|
|
|
#include "sanitizer_common/sanitizer_allocator.h"
|
2013-03-15 21:48:44 +08:00
|
|
|
#include "sanitizer_common/sanitizer_common.h"
|
|
|
|
#include "sanitizer_common/sanitizer_thread_registry.h"
|
2012-05-10 21:48:04 +08:00
|
|
|
#include "tsan_clock.h"
|
|
|
|
#include "tsan_defs.h"
|
|
|
|
#include "tsan_flags.h"
|
|
|
|
#include "tsan_sync.h"
|
|
|
|
#include "tsan_trace.h"
|
|
|
|
#include "tsan_vector.h"
|
|
|
|
#include "tsan_report.h"
|
2012-11-28 18:35:31 +08:00
|
|
|
#include "tsan_platform.h"
|
2012-12-06 20:16:15 +08:00
|
|
|
#include "tsan_mutexset.h"
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2012-12-04 23:13:30 +08:00
|
|
|
#if SANITIZER_WORDSIZE != 64
|
|
|
|
# error "ThreadSanitizer is supported only on 64-bit platforms"
|
|
|
|
#endif
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
namespace __tsan {
|
|
|
|
|
2012-08-15 23:35:15 +08:00
|
|
|
// Descriptor of user's memory block.
|
|
|
|
struct MBlock {
|
2013-03-19 03:47:36 +08:00
|
|
|
/*
|
|
|
|
u64 mtx : 1; // must be first
|
|
|
|
u64 lst : 44;
|
|
|
|
u64 stk : 31; // on word boundary
|
|
|
|
u64 tid : kTidBits;
|
|
|
|
u64 siz : 128 - 1 - 31 - 44 - kTidBits; // 39
|
|
|
|
*/
|
|
|
|
u64 raw[2];
|
|
|
|
|
|
|
|
void Init(uptr siz, u32 tid, u32 stk) {
|
|
|
|
raw[0] = raw[1] = 0;
|
|
|
|
raw[1] |= (u64)siz << ((1 + 44 + 31 + kTidBits) % 64);
|
|
|
|
raw[1] |= (u64)tid << ((1 + 44 + 31) % 64);
|
|
|
|
raw[0] |= (u64)stk << (1 + 44);
|
|
|
|
raw[1] |= (u64)stk >> (64 - 44 - 1);
|
|
|
|
DCHECK_EQ(Size(), siz);
|
|
|
|
DCHECK_EQ(Tid(), tid);
|
|
|
|
DCHECK_EQ(StackId(), stk);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 Tid() const {
|
|
|
|
return GetLsb(raw[1] >> ((1 + 44 + 31) % 64), kTidBits);
|
|
|
|
}
|
|
|
|
|
|
|
|
uptr Size() const {
|
|
|
|
return raw[1] >> ((1 + 31 + 44 + kTidBits) % 64);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 StackId() const {
|
|
|
|
return (raw[0] >> (1 + 44)) | GetLsb(raw[1] << (64 - 44 - 1), 31);
|
|
|
|
}
|
|
|
|
|
|
|
|
SyncVar *ListHead() const {
|
|
|
|
return (SyncVar*)(GetLsb(raw[0] >> 1, 44) << 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListPush(SyncVar *v) {
|
|
|
|
SyncVar *lst = ListHead();
|
|
|
|
v->next = lst;
|
|
|
|
u64 x = (u64)v ^ (u64)lst;
|
|
|
|
x = (x >> 3) << 1;
|
|
|
|
raw[0] ^= x;
|
|
|
|
DCHECK_EQ(ListHead(), v);
|
|
|
|
}
|
|
|
|
|
|
|
|
SyncVar *ListPop() {
|
|
|
|
SyncVar *lst = ListHead();
|
|
|
|
SyncVar *nxt = lst->next;
|
|
|
|
lst->next = 0;
|
|
|
|
u64 x = (u64)lst ^ (u64)nxt;
|
|
|
|
x = (x >> 3) << 1;
|
|
|
|
raw[0] ^= x;
|
|
|
|
DCHECK_EQ(ListHead(), nxt);
|
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ListReset() {
|
|
|
|
SyncVar *lst = ListHead();
|
|
|
|
u64 x = (u64)lst;
|
|
|
|
x = (x >> 3) << 1;
|
|
|
|
raw[0] ^= x;
|
|
|
|
DCHECK_EQ(ListHead(), 0);
|
2012-12-06 20:16:15 +08:00
|
|
|
}
|
2013-03-19 03:47:36 +08:00
|
|
|
|
|
|
|
void Lock();
|
|
|
|
void Unlock();
|
|
|
|
typedef GenericScopedLock<MBlock> ScopedLock;
|
2012-08-15 23:35:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef TSAN_GO
|
|
|
|
#if defined(TSAN_COMPAT_SHADOW) && TSAN_COMPAT_SHADOW
|
2012-08-16 21:27:25 +08:00
|
|
|
const uptr kAllocatorSpace = 0x7d0000000000ULL;
|
2012-08-15 23:35:15 +08:00
|
|
|
#else
|
|
|
|
const uptr kAllocatorSpace = 0x7d0000000000ULL;
|
|
|
|
#endif
|
|
|
|
const uptr kAllocatorSize = 0x10000000000ULL; // 1T.
|
|
|
|
|
2013-03-18 18:32:21 +08:00
|
|
|
struct MapUnmapCallback;
|
2012-08-15 23:35:15 +08:00
|
|
|
typedef SizeClassAllocator64<kAllocatorSpace, kAllocatorSize, sizeof(MBlock),
|
2013-03-18 18:32:21 +08:00
|
|
|
DefaultSizeClassMap, MapUnmapCallback> PrimaryAllocator;
|
2012-12-04 22:15:17 +08:00
|
|
|
typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
|
2013-03-18 18:32:21 +08:00
|
|
|
typedef LargeMmapAllocator<MapUnmapCallback> SecondaryAllocator;
|
2012-08-15 23:35:15 +08:00
|
|
|
typedef CombinedAllocator<PrimaryAllocator, AllocatorCache,
|
|
|
|
SecondaryAllocator> Allocator;
|
2012-08-30 21:02:30 +08:00
|
|
|
Allocator *allocator();
|
2012-08-15 23:35:15 +08:00
|
|
|
#endif
|
|
|
|
|
2012-09-11 17:44:48 +08:00
|
|
|
void TsanCheckFailed(const char *file, int line, const char *cond,
|
|
|
|
u64 v1, u64 v2);
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2013-03-20 18:31:53 +08:00
|
|
|
const u64 kShadowRodata = (u64)-1; // .rodata shadow marker
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
// FastState (from most significant bit):
|
2012-11-28 18:49:27 +08:00
|
|
|
// ignore : 1
|
2012-05-10 21:48:04 +08:00
|
|
|
// tid : kTidBits
|
|
|
|
// epoch : kClkBits
|
2012-05-17 22:17:51 +08:00
|
|
|
// unused : -
|
2012-11-28 20:19:50 +08:00
|
|
|
// history_size : 3
|
2012-05-10 21:48:04 +08:00
|
|
|
class FastState {
|
|
|
|
public:
|
|
|
|
FastState(u64 tid, u64 epoch) {
|
2012-05-17 22:17:51 +08:00
|
|
|
x_ = tid << kTidShift;
|
|
|
|
x_ |= epoch << kClkShift;
|
2012-11-28 18:49:27 +08:00
|
|
|
DCHECK_EQ(tid, this->tid());
|
|
|
|
DCHECK_EQ(epoch, this->epoch());
|
|
|
|
DCHECK_EQ(GetIgnoreBit(), false);
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
explicit FastState(u64 x)
|
|
|
|
: x_(x) {
|
|
|
|
}
|
|
|
|
|
2012-08-16 23:08:49 +08:00
|
|
|
u64 raw() const {
|
|
|
|
return x_;
|
|
|
|
}
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
u64 tid() const {
|
2012-12-01 04:02:11 +08:00
|
|
|
u64 res = (x_ & ~kIgnoreBit) >> kTidShift;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 TidWithIgnore() const {
|
2012-05-17 22:17:51 +08:00
|
|
|
u64 res = x_ >> kTidShift;
|
2012-05-10 21:48:04 +08:00
|
|
|
return res;
|
|
|
|
}
|
2012-05-17 22:17:51 +08:00
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
u64 epoch() const {
|
2012-05-17 22:17:51 +08:00
|
|
|
u64 res = (x_ << (kTidBits + 1)) >> (64 - kClkBits);
|
2012-05-10 21:48:04 +08:00
|
|
|
return res;
|
2012-05-17 22:17:51 +08:00
|
|
|
}
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
void IncrementEpoch() {
|
2012-05-17 22:17:51 +08:00
|
|
|
u64 old_epoch = epoch();
|
|
|
|
x_ += 1 << kClkShift;
|
2012-05-21 18:20:53 +08:00
|
|
|
DCHECK_EQ(old_epoch + 1, epoch());
|
2012-05-17 22:17:51 +08:00
|
|
|
(void)old_epoch;
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
2012-05-17 22:17:51 +08:00
|
|
|
|
|
|
|
void SetIgnoreBit() { x_ |= kIgnoreBit; }
|
|
|
|
void ClearIgnoreBit() { x_ &= ~kIgnoreBit; }
|
2012-11-28 18:49:27 +08:00
|
|
|
bool GetIgnoreBit() const { return (s64)x_ < 0; }
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2012-11-28 20:19:50 +08:00
|
|
|
void SetHistorySize(int hs) {
|
|
|
|
CHECK_GE(hs, 0);
|
|
|
|
CHECK_LE(hs, 7);
|
|
|
|
x_ = (x_ & ~7) | hs;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetHistorySize() const {
|
|
|
|
return (int)(x_ & 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClearHistorySize() {
|
|
|
|
x_ &= ~7;
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 GetTracePos() const {
|
|
|
|
const int hs = GetHistorySize();
|
|
|
|
// When hs == 0, the trace consists of 2 parts.
|
|
|
|
const u64 mask = (1ull << (kTracePartSizeBits + hs + 1)) - 1;
|
|
|
|
return epoch() & mask;
|
|
|
|
}
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
private:
|
|
|
|
friend class Shadow;
|
2012-05-17 22:17:51 +08:00
|
|
|
static const int kTidShift = 64 - kTidBits - 1;
|
|
|
|
static const int kClkShift = kTidShift - kClkBits;
|
2012-11-28 18:49:27 +08:00
|
|
|
static const u64 kIgnoreBit = 1ull << 63;
|
2012-05-17 22:17:51 +08:00
|
|
|
static const u64 kFreedBit = 1ull << 63;
|
2012-05-10 21:48:04 +08:00
|
|
|
u64 x_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Shadow (from most significant bit):
|
2012-05-17 22:17:51 +08:00
|
|
|
// freed : 1
|
2012-05-10 21:48:04 +08:00
|
|
|
// tid : kTidBits
|
|
|
|
// epoch : kClkBits
|
2013-02-01 17:42:06 +08:00
|
|
|
// is_atomic : 1
|
2013-02-01 18:02:55 +08:00
|
|
|
// is_read : 1
|
2012-05-10 21:48:04 +08:00
|
|
|
// size_log : 2
|
|
|
|
// addr0 : 3
|
2012-06-28 00:05:06 +08:00
|
|
|
class Shadow : public FastState {
|
2012-05-10 21:48:04 +08:00
|
|
|
public:
|
2012-11-28 20:19:50 +08:00
|
|
|
explicit Shadow(u64 x)
|
|
|
|
: FastState(x) {
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2012-11-28 20:19:50 +08:00
|
|
|
explicit Shadow(const FastState &s)
|
|
|
|
: FastState(s.x_) {
|
|
|
|
ClearHistorySize();
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
void SetAddr0AndSizeLog(u64 addr0, unsigned kAccessSizeLog) {
|
|
|
|
DCHECK_EQ(x_ & 31, 0);
|
|
|
|
DCHECK_LE(addr0, 7);
|
|
|
|
DCHECK_LE(kAccessSizeLog, 3);
|
|
|
|
x_ |= (kAccessSizeLog << 3) | addr0;
|
|
|
|
DCHECK_EQ(kAccessSizeLog, size_log());
|
|
|
|
DCHECK_EQ(addr0, this->addr0());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetWrite(unsigned kAccessIsWrite) {
|
2013-02-01 18:02:55 +08:00
|
|
|
DCHECK_EQ(x_ & kReadBit, 0);
|
|
|
|
if (!kAccessIsWrite)
|
|
|
|
x_ |= kReadBit;
|
2013-02-01 17:42:06 +08:00
|
|
|
DCHECK_EQ(kAccessIsWrite, IsWrite());
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
2013-02-01 17:42:06 +08:00
|
|
|
void SetAtomic(bool kIsAtomic) {
|
|
|
|
DCHECK(!IsAtomic());
|
|
|
|
if (kIsAtomic)
|
|
|
|
x_ |= kAtomicBit;
|
|
|
|
DCHECK_EQ(IsAtomic(), kIsAtomic);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsAtomic() const {
|
|
|
|
return x_ & kAtomicBit;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsZero() const {
|
|
|
|
return x_ == 0;
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2012-05-23 02:07:45 +08:00
|
|
|
static inline bool TidsAreEqual(const Shadow s1, const Shadow s2) {
|
2012-05-17 22:17:51 +08:00
|
|
|
u64 shifted_xor = (s1.x_ ^ s2.x_) >> kTidShift;
|
2012-12-01 04:02:11 +08:00
|
|
|
DCHECK_EQ(shifted_xor == 0, s1.TidWithIgnore() == s2.TidWithIgnore());
|
2012-05-10 21:48:04 +08:00
|
|
|
return shifted_xor == 0;
|
|
|
|
}
|
2012-05-23 02:07:45 +08:00
|
|
|
|
|
|
|
static inline bool Addr0AndSizeAreEqual(const Shadow s1, const Shadow s2) {
|
2012-05-10 21:48:04 +08:00
|
|
|
u64 masked_xor = (s1.x_ ^ s2.x_) & 31;
|
|
|
|
return masked_xor == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool TwoRangesIntersect(Shadow s1, Shadow s2,
|
|
|
|
unsigned kS2AccessSize) {
|
|
|
|
bool res = false;
|
|
|
|
u64 diff = s1.addr0() - s2.addr0();
|
|
|
|
if ((s64)diff < 0) { // s1.addr0 < s2.addr0 // NOLINT
|
|
|
|
// if (s1.addr0() + size1) > s2.addr0()) return true;
|
|
|
|
if (s1.size() > -diff) res = true;
|
|
|
|
} else {
|
|
|
|
// if (s2.addr0() + kS2AccessSize > s1.addr0()) return true;
|
|
|
|
if (kS2AccessSize > diff) res = true;
|
|
|
|
}
|
|
|
|
DCHECK_EQ(res, TwoRangesIntersectSLOW(s1, s2));
|
|
|
|
DCHECK_EQ(res, TwoRangesIntersectSLOW(s2, s1));
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The idea behind the offset is as follows.
|
|
|
|
// Consider that we have 8 bool's contained within a single 8-byte block
|
|
|
|
// (mapped to a single shadow "cell"). Now consider that we write to the bools
|
|
|
|
// from a single thread (which we consider the common case).
|
|
|
|
// W/o offsetting each access will have to scan 4 shadow values at average
|
|
|
|
// to find the corresponding shadow value for the bool.
|
|
|
|
// With offsetting we start scanning shadow with the offset so that
|
|
|
|
// each access hits necessary shadow straight off (at least in an expected
|
|
|
|
// optimistic case).
|
|
|
|
// This logic works seamlessly for any layout of user data. For example,
|
|
|
|
// if user data is {int, short, char, char}, then accesses to the int are
|
|
|
|
// offsetted to 0, short - 4, 1st char - 6, 2nd char - 7. Hopefully, accesses
|
|
|
|
// from a single thread won't need to scan all 8 shadow values.
|
|
|
|
unsigned ComputeSearchOffset() {
|
|
|
|
return x_ & 7;
|
|
|
|
}
|
|
|
|
u64 addr0() const { return x_ & 7; }
|
|
|
|
u64 size() const { return 1ull << size_log(); }
|
2013-02-01 18:02:55 +08:00
|
|
|
bool IsWrite() const { return !IsRead(); }
|
|
|
|
bool IsRead() const { return x_ & kReadBit; }
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2012-05-17 22:17:51 +08:00
|
|
|
// The idea behind the freed bit is as follows.
|
|
|
|
// When the memory is freed (or otherwise unaccessible) we write to the shadow
|
|
|
|
// values with tid/epoch related to the free and the freed bit set.
|
|
|
|
// During memory accesses processing the freed bit is considered
|
|
|
|
// as msb of tid. So any access races with shadow with freed bit set
|
|
|
|
// (it is as if write from a thread with which we never synchronized before).
|
|
|
|
// This allows us to detect accesses to freed memory w/o additional
|
|
|
|
// overheads in memory access processing and at the same time restore
|
|
|
|
// tid/epoch of free.
|
|
|
|
void MarkAsFreed() {
|
|
|
|
x_ |= kFreedBit;
|
|
|
|
}
|
|
|
|
|
2013-02-01 22:41:58 +08:00
|
|
|
bool IsFreed() const {
|
|
|
|
return x_ & kFreedBit;
|
|
|
|
}
|
|
|
|
|
2012-05-17 22:17:51 +08:00
|
|
|
bool GetFreedAndReset() {
|
|
|
|
bool res = x_ & kFreedBit;
|
|
|
|
x_ &= ~kFreedBit;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-02-01 17:42:06 +08:00
|
|
|
bool IsBothReadsOrAtomic(bool kIsWrite, bool kIsAtomic) const {
|
2013-02-01 18:02:55 +08:00
|
|
|
// analyzes 5-th bit (is_read) and 6-th bit (is_atomic)
|
|
|
|
bool v = x_ & u64(((kIsWrite ^ 1) << kReadShift)
|
|
|
|
| (kIsAtomic << kAtomicShift));
|
2013-02-01 17:42:06 +08:00
|
|
|
DCHECK_EQ(v, (!IsWrite() && !kIsWrite) || (IsAtomic() && kIsAtomic));
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsRWNotWeaker(bool kIsWrite, bool kIsAtomic) const {
|
2013-02-01 18:02:55 +08:00
|
|
|
bool v = ((x_ >> kReadShift) & 3)
|
2013-02-01 17:42:06 +08:00
|
|
|
<= u64((kIsWrite ^ 1) | (kIsAtomic << 1));
|
|
|
|
DCHECK_EQ(v, (IsAtomic() < kIsAtomic) ||
|
|
|
|
(IsAtomic() == kIsAtomic && !IsWrite() <= !kIsWrite));
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsRWWeakerOrEqual(bool kIsWrite, bool kIsAtomic) const {
|
2013-02-01 18:02:55 +08:00
|
|
|
bool v = ((x_ >> kReadShift) & 3)
|
2013-02-01 17:42:06 +08:00
|
|
|
>= u64((kIsWrite ^ 1) | (kIsAtomic << 1));
|
|
|
|
DCHECK_EQ(v, (IsAtomic() > kIsAtomic) ||
|
|
|
|
(IsAtomic() == kIsAtomic && !IsWrite() >= !kIsWrite));
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
private:
|
2013-02-01 18:02:55 +08:00
|
|
|
static const u64 kReadShift = 5;
|
|
|
|
static const u64 kReadBit = 1ull << kReadShift;
|
2013-02-01 17:42:06 +08:00
|
|
|
static const u64 kAtomicShift = 6;
|
|
|
|
static const u64 kAtomicBit = 1ull << kAtomicShift;
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
u64 size_log() const { return (x_ >> 3) & 3; }
|
2012-05-23 02:07:45 +08:00
|
|
|
|
|
|
|
static bool TwoRangesIntersectSLOW(const Shadow s1, const Shadow s2) {
|
|
|
|
if (s1.addr0() == s2.addr0()) return true;
|
|
|
|
if (s1.addr0() < s2.addr0() && s1.addr0() + s1.size() > s2.addr0())
|
|
|
|
return true;
|
|
|
|
if (s2.addr0() < s1.addr0() && s2.addr0() + s2.size() > s1.addr0())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
};
|
|
|
|
|
2012-06-28 00:05:06 +08:00
|
|
|
struct SignalContext;
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2013-03-25 18:10:44 +08:00
|
|
|
struct JmpBuf {
|
|
|
|
uptr sp;
|
|
|
|
uptr mangled_sp;
|
|
|
|
uptr *shadow_stack_pos;
|
|
|
|
};
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
// This struct is stored in TLS.
|
|
|
|
struct ThreadState {
|
|
|
|
FastState fast_state;
|
|
|
|
// Synch epoch represents the threads's epoch before the last synchronization
|
|
|
|
// action. It allows to reduce number of shadow state updates.
|
|
|
|
// For example, fast_synch_epoch=100, last write to addr X was at epoch=150,
|
|
|
|
// if we are processing write to X from the same thread at epoch=200,
|
|
|
|
// we do nothing, because both writes happen in the same 'synch epoch'.
|
|
|
|
// That is, if another memory access does not race with the former write,
|
|
|
|
// it does not race with the latter as well.
|
|
|
|
// QUESTION: can we can squeeze this into ThreadState::Fast?
|
|
|
|
// E.g. ThreadState::Fast is a 44-bit, 32 are taken by synch_epoch and 12 are
|
|
|
|
// taken by epoch between synchs.
|
|
|
|
// This way we can save one load from tls.
|
|
|
|
u64 fast_synch_epoch;
|
|
|
|
// This is a slow path flag. On fast path, fast_state.GetIgnoreBit() is read.
|
|
|
|
// We do not distinguish beteween ignoring reads and writes
|
|
|
|
// for better performance.
|
|
|
|
int ignore_reads_and_writes;
|
|
|
|
uptr *shadow_stack_pos;
|
|
|
|
u64 *racy_shadow_addr;
|
|
|
|
u64 racy_state[2];
|
2012-07-17 00:44:47 +08:00
|
|
|
#ifndef TSAN_GO
|
|
|
|
// C/C++ uses embed shadow stack of fixed size.
|
2012-05-10 21:48:04 +08:00
|
|
|
uptr shadow_stack[kShadowStackSize];
|
2012-07-17 00:44:47 +08:00
|
|
|
#else
|
|
|
|
// Go uses satellite shadow stack with dynamic size.
|
|
|
|
uptr *shadow_stack;
|
|
|
|
uptr *shadow_stack_end;
|
|
|
|
#endif
|
2012-12-06 20:16:15 +08:00
|
|
|
MutexSet mset;
|
2012-05-10 21:48:04 +08:00
|
|
|
ThreadClock clock;
|
2012-08-15 23:35:15 +08:00
|
|
|
#ifndef TSAN_GO
|
|
|
|
AllocatorCache alloc_cache;
|
2013-03-25 18:10:44 +08:00
|
|
|
Vector<JmpBuf> jmp_bufs;
|
2012-08-15 23:35:15 +08:00
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
u64 stat[StatCnt];
|
|
|
|
const int tid;
|
2012-08-30 21:02:30 +08:00
|
|
|
const int unique_id;
|
2012-05-10 21:48:04 +08:00
|
|
|
int in_rtl;
|
2013-01-29 21:03:07 +08:00
|
|
|
bool in_symbolizer;
|
2012-06-29 02:07:46 +08:00
|
|
|
bool is_alive;
|
2013-02-01 22:41:58 +08:00
|
|
|
bool is_freeing;
|
2013-03-21 23:37:39 +08:00
|
|
|
bool is_vptr_access;
|
2012-05-10 21:48:04 +08:00
|
|
|
const uptr stk_addr;
|
|
|
|
const uptr stk_size;
|
|
|
|
const uptr tls_addr;
|
|
|
|
const uptr tls_size;
|
|
|
|
|
|
|
|
DeadlockDetector deadlock_detector;
|
|
|
|
|
|
|
|
bool in_signal_handler;
|
2012-06-28 00:05:06 +08:00
|
|
|
SignalContext *signal_ctx;
|
|
|
|
|
2012-09-01 01:27:49 +08:00
|
|
|
#ifndef TSAN_GO
|
|
|
|
u32 last_sleep_stack_id;
|
|
|
|
ThreadClock last_sleep_clock;
|
|
|
|
#endif
|
|
|
|
|
2012-06-22 19:08:55 +08:00
|
|
|
// Set in regions of runtime that must be signal-safe and fork-safe.
|
|
|
|
// If set, malloc must not be called.
|
|
|
|
int nomalloc;
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2012-08-30 21:02:30 +08:00
|
|
|
explicit ThreadState(Context *ctx, int tid, int unique_id, u64 epoch,
|
2012-05-10 21:48:04 +08:00
|
|
|
uptr stk_addr, uptr stk_size,
|
|
|
|
uptr tls_addr, uptr tls_size);
|
|
|
|
};
|
|
|
|
|
|
|
|
Context *CTX();
|
|
|
|
|
2012-07-06 00:18:28 +08:00
|
|
|
#ifndef TSAN_GO
|
|
|
|
extern THREADLOCAL char cur_thread_placeholder[];
|
2012-05-10 21:48:04 +08:00
|
|
|
INLINE ThreadState *cur_thread() {
|
|
|
|
return reinterpret_cast<ThreadState *>(&cur_thread_placeholder);
|
|
|
|
}
|
2012-07-06 00:18:28 +08:00
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2013-03-15 21:48:44 +08:00
|
|
|
class ThreadContext : public ThreadContextBase {
|
|
|
|
public:
|
|
|
|
explicit ThreadContext(int tid);
|
2013-03-18 18:10:15 +08:00
|
|
|
~ThreadContext();
|
2012-05-10 21:48:04 +08:00
|
|
|
ThreadState *thr;
|
2013-03-18 17:02:27 +08:00
|
|
|
#ifdef TSAN_GO
|
2013-03-15 21:48:44 +08:00
|
|
|
StackTrace creation_stack;
|
2013-03-18 17:02:27 +08:00
|
|
|
#else
|
|
|
|
u32 creation_stack_id;
|
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
SyncClock sync;
|
|
|
|
// Epoch at which the thread had started.
|
|
|
|
// If we see an event from the thread stamped by an older epoch,
|
|
|
|
// the event is from a dead thread that shared tid with this thread.
|
|
|
|
u64 epoch0;
|
|
|
|
u64 epoch1;
|
|
|
|
|
2013-03-15 21:48:44 +08:00
|
|
|
// Override superclass callbacks.
|
|
|
|
void OnDead();
|
|
|
|
void OnJoined(void *arg);
|
|
|
|
void OnFinished();
|
|
|
|
void OnStarted(void *arg);
|
|
|
|
void OnCreated(void *arg);
|
2013-03-19 20:25:48 +08:00
|
|
|
void OnReset();
|
2012-05-10 21:48:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RacyStacks {
|
|
|
|
MD5Hash hash[2];
|
|
|
|
bool operator==(const RacyStacks &other) const {
|
|
|
|
if (hash[0] == other.hash[0] && hash[1] == other.hash[1])
|
|
|
|
return true;
|
|
|
|
if (hash[0] == other.hash[1] && hash[1] == other.hash[0])
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RacyAddress {
|
|
|
|
uptr addr_min;
|
|
|
|
uptr addr_max;
|
|
|
|
};
|
|
|
|
|
2012-10-05 23:51:32 +08:00
|
|
|
struct FiredSuppression {
|
|
|
|
ReportType type;
|
|
|
|
uptr pc;
|
2013-03-28 01:59:57 +08:00
|
|
|
Suppression *supp;
|
2012-10-05 23:51:32 +08:00
|
|
|
};
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
struct Context {
|
|
|
|
Context();
|
|
|
|
|
|
|
|
bool initialized;
|
|
|
|
|
|
|
|
SyncTab synctab;
|
|
|
|
|
|
|
|
Mutex report_mtx;
|
|
|
|
int nreported;
|
|
|
|
int nmissed_expected;
|
2013-03-21 15:02:36 +08:00
|
|
|
atomic_uint64_t last_symbolize_time_ns;
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2013-03-15 21:48:44 +08:00
|
|
|
ThreadRegistry *thread_registry;
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
Vector<RacyStacks> racy_stacks;
|
|
|
|
Vector<RacyAddress> racy_addresses;
|
2012-10-05 23:51:32 +08:00
|
|
|
Vector<FiredSuppression> fired_suppressions;
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
Flags flags;
|
|
|
|
|
|
|
|
u64 stat[StatCnt];
|
|
|
|
u64 int_alloc_cnt[MBlockTypeCount];
|
|
|
|
u64 int_alloc_siz[MBlockTypeCount];
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScopedInRtl {
|
|
|
|
public:
|
|
|
|
ScopedInRtl();
|
|
|
|
~ScopedInRtl();
|
|
|
|
private:
|
|
|
|
ThreadState*thr_;
|
|
|
|
int in_rtl_;
|
|
|
|
int errno_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScopedReport {
|
|
|
|
public:
|
|
|
|
explicit ScopedReport(ReportType typ);
|
|
|
|
~ScopedReport();
|
|
|
|
|
|
|
|
void AddStack(const StackTrace *stack);
|
2012-12-06 20:16:15 +08:00
|
|
|
void AddMemoryAccess(uptr addr, Shadow s, const StackTrace *stack,
|
|
|
|
const MutexSet *mset);
|
2012-05-10 21:48:04 +08:00
|
|
|
void AddThread(const ThreadContext *tctx);
|
|
|
|
void AddMutex(const SyncVar *s);
|
|
|
|
void AddLocation(uptr addr, uptr size);
|
2012-09-01 01:27:49 +08:00
|
|
|
void AddSleep(u32 stack_id);
|
2013-03-22 00:55:17 +08:00
|
|
|
void SetCount(int count);
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
const ReportDesc *GetReport() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Context *ctx_;
|
|
|
|
ReportDesc *rep_;
|
|
|
|
|
2012-12-06 20:16:15 +08:00
|
|
|
void AddMutex(u64 id);
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
ScopedReport(const ScopedReport&);
|
|
|
|
void operator = (const ScopedReport&);
|
|
|
|
};
|
|
|
|
|
2012-12-06 20:16:15 +08:00
|
|
|
void RestoreStack(int tid, const u64 epoch, StackTrace *stk, MutexSet *mset);
|
2012-08-16 23:08:49 +08:00
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
void StatAggregate(u64 *dst, u64 *src);
|
|
|
|
void StatOutput(u64 *stat);
|
2013-03-29 02:52:40 +08:00
|
|
|
void ALWAYS_INLINE StatInc(ThreadState *thr, StatType typ, u64 n = 1) {
|
2012-05-10 21:48:04 +08:00
|
|
|
if (kCollectStats)
|
|
|
|
thr->stat[typ] += n;
|
|
|
|
}
|
2013-03-29 02:52:40 +08:00
|
|
|
void ALWAYS_INLINE StatSet(ThreadState *thr, StatType typ, u64 n) {
|
2013-03-15 21:48:44 +08:00
|
|
|
if (kCollectStats)
|
|
|
|
thr->stat[typ] = n;
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2012-11-07 00:00:16 +08:00
|
|
|
void MapShadow(uptr addr, uptr size);
|
2012-12-13 16:14:02 +08:00
|
|
|
void MapThreadTrace(uptr addr, uptr size);
|
2013-03-18 23:49:07 +08:00
|
|
|
void DontNeedShadowFor(uptr addr, uptr size);
|
2012-05-10 21:48:04 +08:00
|
|
|
void InitializeShadowMemory();
|
|
|
|
void InitializeInterceptors();
|
|
|
|
void InitializeDynamicAnnotations();
|
|
|
|
|
|
|
|
void ReportRace(ThreadState *thr);
|
2012-10-05 23:51:32 +08:00
|
|
|
bool OutputReport(Context *ctx,
|
|
|
|
const ScopedReport &srep,
|
2013-01-24 21:50:32 +08:00
|
|
|
const ReportStack *suppress_stack1 = 0,
|
|
|
|
const ReportStack *suppress_stack2 = 0);
|
2012-10-05 23:51:32 +08:00
|
|
|
bool IsFiredSuppression(Context *ctx,
|
|
|
|
const ScopedReport &srep,
|
|
|
|
const StackTrace &trace);
|
2012-05-10 21:48:04 +08:00
|
|
|
bool IsExpectedReport(uptr addr, uptr size);
|
2013-03-29 00:21:19 +08:00
|
|
|
void PrintMatchedBenignRaces();
|
2013-02-06 22:24:00 +08:00
|
|
|
bool FrameIsInternal(const ReportStack *frame);
|
2013-02-07 00:28:05 +08:00
|
|
|
ReportStack *SkipTsanInternalFrames(ReportStack *ent);
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
#if defined(TSAN_DEBUG_OUTPUT) && TSAN_DEBUG_OUTPUT >= 1
|
2012-11-02 20:17:51 +08:00
|
|
|
# define DPrintf Printf
|
2012-05-10 21:48:04 +08:00
|
|
|
#else
|
|
|
|
# define DPrintf(...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(TSAN_DEBUG_OUTPUT) && TSAN_DEBUG_OUTPUT >= 2
|
2012-11-02 20:17:51 +08:00
|
|
|
# define DPrintf2 Printf
|
2012-05-10 21:48:04 +08:00
|
|
|
#else
|
|
|
|
# define DPrintf2(...)
|
|
|
|
#endif
|
|
|
|
|
2012-09-01 01:27:49 +08:00
|
|
|
u32 CurrentStackId(ThreadState *thr, uptr pc);
|
2012-09-01 20:13:18 +08:00
|
|
|
void PrintCurrentStack(ThreadState *thr, uptr pc);
|
2013-01-29 22:20:12 +08:00
|
|
|
void PrintCurrentStackSlow(); // uses libunwind
|
2012-09-01 01:27:49 +08:00
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
void Initialize(ThreadState *thr);
|
|
|
|
int Finalize(ThreadState *thr);
|
|
|
|
|
2012-12-21 01:29:34 +08:00
|
|
|
SyncVar* GetJavaSync(ThreadState *thr, uptr pc, uptr addr,
|
|
|
|
bool write_lock, bool create);
|
|
|
|
SyncVar* GetAndRemoveJavaSync(ThreadState *thr, uptr pc, uptr addr);
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
void MemoryAccess(ThreadState *thr, uptr pc, uptr addr,
|
2013-02-01 17:42:06 +08:00
|
|
|
int kAccessSizeLog, bool kAccessIsWrite, bool kIsAtomic);
|
2012-05-10 21:48:04 +08:00
|
|
|
void MemoryAccessImpl(ThreadState *thr, uptr addr,
|
2013-02-01 17:42:06 +08:00
|
|
|
int kAccessSizeLog, bool kAccessIsWrite, bool kIsAtomic,
|
2012-05-10 21:48:04 +08:00
|
|
|
u64 *shadow_mem, Shadow cur);
|
|
|
|
void MemoryAccessRange(ThreadState *thr, uptr pc, uptr addr,
|
2013-02-01 17:42:06 +08:00
|
|
|
uptr size, bool is_write);
|
2013-02-13 21:05:36 +08:00
|
|
|
void MemoryAccessRangeStep(ThreadState *thr, uptr pc, uptr addr,
|
|
|
|
uptr size, uptr step, bool is_write);
|
2013-04-30 19:56:56 +08:00
|
|
|
void UnalignedMemoryAccess(ThreadState *thr, uptr pc, uptr addr,
|
|
|
|
int size, bool kAccessIsWrite, bool kIsAtomic);
|
2013-02-01 17:42:06 +08:00
|
|
|
|
|
|
|
const int kSizeLog1 = 0;
|
|
|
|
const int kSizeLog2 = 1;
|
|
|
|
const int kSizeLog4 = 2;
|
|
|
|
const int kSizeLog8 = 3;
|
|
|
|
|
2013-03-29 02:52:40 +08:00
|
|
|
void ALWAYS_INLINE MemoryRead(ThreadState *thr, uptr pc,
|
2013-02-01 17:42:06 +08:00
|
|
|
uptr addr, int kAccessSizeLog) {
|
|
|
|
MemoryAccess(thr, pc, addr, kAccessSizeLog, false, false);
|
|
|
|
}
|
|
|
|
|
2013-03-29 02:52:40 +08:00
|
|
|
void ALWAYS_INLINE MemoryWrite(ThreadState *thr, uptr pc,
|
2013-02-01 17:42:06 +08:00
|
|
|
uptr addr, int kAccessSizeLog) {
|
|
|
|
MemoryAccess(thr, pc, addr, kAccessSizeLog, true, false);
|
|
|
|
}
|
|
|
|
|
2013-03-29 02:52:40 +08:00
|
|
|
void ALWAYS_INLINE MemoryReadAtomic(ThreadState *thr, uptr pc,
|
2013-02-01 17:42:06 +08:00
|
|
|
uptr addr, int kAccessSizeLog) {
|
|
|
|
MemoryAccess(thr, pc, addr, kAccessSizeLog, false, true);
|
|
|
|
}
|
|
|
|
|
2013-03-29 02:52:40 +08:00
|
|
|
void ALWAYS_INLINE MemoryWriteAtomic(ThreadState *thr, uptr pc,
|
2013-02-01 17:42:06 +08:00
|
|
|
uptr addr, int kAccessSizeLog) {
|
|
|
|
MemoryAccess(thr, pc, addr, kAccessSizeLog, true, true);
|
|
|
|
}
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
void MemoryResetRange(ThreadState *thr, uptr pc, uptr addr, uptr size);
|
|
|
|
void MemoryRangeFreed(ThreadState *thr, uptr pc, uptr addr, uptr size);
|
2012-08-16 00:52:19 +08:00
|
|
|
void MemoryRangeImitateWrite(ThreadState *thr, uptr pc, uptr addr, uptr size);
|
2012-05-10 21:48:04 +08:00
|
|
|
void IgnoreCtl(ThreadState *thr, bool write, bool begin);
|
|
|
|
|
|
|
|
void FuncEntry(ThreadState *thr, uptr pc);
|
|
|
|
void FuncExit(ThreadState *thr);
|
|
|
|
|
|
|
|
int ThreadCreate(ThreadState *thr, uptr pc, uptr uid, bool detached);
|
2012-10-02 20:58:14 +08:00
|
|
|
void ThreadStart(ThreadState *thr, int tid, uptr os_id);
|
2012-05-10 21:48:04 +08:00
|
|
|
void ThreadFinish(ThreadState *thr);
|
|
|
|
int ThreadTid(ThreadState *thr, uptr pc, uptr uid);
|
|
|
|
void ThreadJoin(ThreadState *thr, uptr pc, int tid);
|
|
|
|
void ThreadDetach(ThreadState *thr, uptr pc, int tid);
|
|
|
|
void ThreadFinalize(ThreadState *thr);
|
2012-12-04 23:46:05 +08:00
|
|
|
void ThreadSetName(ThreadState *thr, const char *name);
|
2012-11-08 00:41:57 +08:00
|
|
|
int ThreadCount(ThreadState *thr);
|
2012-11-16 01:40:49 +08:00
|
|
|
void ProcessPendingSignals(ThreadState *thr);
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2012-08-16 21:29:41 +08:00
|
|
|
void MutexCreate(ThreadState *thr, uptr pc, uptr addr,
|
|
|
|
bool rw, bool recursive, bool linker_init);
|
2012-05-10 21:48:04 +08:00
|
|
|
void MutexDestroy(ThreadState *thr, uptr pc, uptr addr);
|
2013-05-17 20:03:46 +08:00
|
|
|
void MutexLock(ThreadState *thr, uptr pc, uptr addr, int rec = 1);
|
|
|
|
int MutexUnlock(ThreadState *thr, uptr pc, uptr addr, bool all = false);
|
2012-05-10 21:48:04 +08:00
|
|
|
void MutexReadLock(ThreadState *thr, uptr pc, uptr addr);
|
|
|
|
void MutexReadUnlock(ThreadState *thr, uptr pc, uptr addr);
|
|
|
|
void MutexReadOrWriteUnlock(ThreadState *thr, uptr pc, uptr addr);
|
|
|
|
|
|
|
|
void Acquire(ThreadState *thr, uptr pc, uptr addr);
|
2012-11-07 23:08:20 +08:00
|
|
|
void AcquireGlobal(ThreadState *thr, uptr pc);
|
2012-05-10 21:48:04 +08:00
|
|
|
void Release(ThreadState *thr, uptr pc, uptr addr);
|
2012-07-28 23:27:41 +08:00
|
|
|
void ReleaseStore(ThreadState *thr, uptr pc, uptr addr);
|
2012-09-01 01:27:49 +08:00
|
|
|
void AfterSleep(ThreadState *thr, uptr pc);
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
// The hacky call uses custom calling convention and an assembly thunk.
|
|
|
|
// It is considerably faster that a normal call for the caller
|
|
|
|
// if it is not executed (it is intended for slow paths from hot functions).
|
|
|
|
// The trick is that the call preserves all registers and the compiler
|
|
|
|
// does not treat it as a call.
|
|
|
|
// If it does not work for you, use normal call.
|
|
|
|
#if TSAN_DEBUG == 0
|
|
|
|
// The caller may not create the stack frame for itself at all,
|
|
|
|
// so we create a reserve stack frame for it (1024b must be enough).
|
|
|
|
#define HACKY_CALL(f) \
|
2012-09-02 19:24:07 +08:00
|
|
|
__asm__ __volatile__("sub $1024, %%rsp;" \
|
|
|
|
"/*.cfi_adjust_cfa_offset 1024;*/" \
|
2012-11-26 22:20:26 +08:00
|
|
|
".hidden " #f "_thunk;" \
|
2012-05-10 21:48:04 +08:00
|
|
|
"call " #f "_thunk;" \
|
2012-09-02 19:24:07 +08:00
|
|
|
"add $1024, %%rsp;" \
|
|
|
|
"/*.cfi_adjust_cfa_offset -1024;*/" \
|
|
|
|
::: "memory", "cc");
|
2012-05-10 21:48:04 +08:00
|
|
|
#else
|
|
|
|
#define HACKY_CALL(f) f()
|
|
|
|
#endif
|
|
|
|
|
2012-07-06 00:18:28 +08:00
|
|
|
void TraceSwitch(ThreadState *thr);
|
2012-11-28 18:35:31 +08:00
|
|
|
uptr TraceTopPC(ThreadState *thr);
|
2012-11-28 20:19:50 +08:00
|
|
|
uptr TraceSize();
|
2012-12-04 20:19:53 +08:00
|
|
|
uptr TraceParts();
|
2013-03-20 18:31:53 +08:00
|
|
|
Trace *ThreadTrace(int tid);
|
2012-07-06 00:18:28 +08:00
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
extern "C" void __tsan_trace_switch();
|
2013-03-29 02:52:40 +08:00
|
|
|
void ALWAYS_INLINE TraceAddEvent(ThreadState *thr, FastState fs,
|
2012-12-06 20:16:15 +08:00
|
|
|
EventType typ, u64 addr) {
|
|
|
|
DCHECK_GE((int)typ, 0);
|
|
|
|
DCHECK_LE((int)typ, 7);
|
|
|
|
DCHECK_EQ(GetLsb(addr, 61), addr);
|
2012-05-10 21:48:04 +08:00
|
|
|
StatInc(thr, StatEvents);
|
2012-11-28 21:01:32 +08:00
|
|
|
u64 pos = fs.GetTracePos();
|
|
|
|
if (UNLIKELY((pos % kTracePartSize) == 0)) {
|
2012-07-06 00:18:28 +08:00
|
|
|
#ifndef TSAN_GO
|
2012-05-10 21:48:04 +08:00
|
|
|
HACKY_CALL(__tsan_trace_switch);
|
2012-07-06 00:18:28 +08:00
|
|
|
#else
|
|
|
|
TraceSwitch(thr);
|
|
|
|
#endif
|
|
|
|
}
|
2012-11-28 18:35:31 +08:00
|
|
|
Event *trace = (Event*)GetThreadTrace(fs.tid());
|
2012-11-28 21:01:32 +08:00
|
|
|
Event *evp = &trace[pos];
|
2012-05-10 21:48:04 +08:00
|
|
|
Event ev = (u64)addr | ((u64)typ << 61);
|
|
|
|
*evp = ev;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace __tsan
|
|
|
|
|
|
|
|
#endif // TSAN_RTL_H
|