1//===-- tsan_trace.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//===----------------------------------------------------------------------===// 11#ifndef TSAN_TRACE_H 12#define TSAN_TRACE_H 13 14#include "tsan_defs.h" 15#include "tsan_mutex.h" 16#include "tsan_stack_trace.h" 17#include "tsan_mutexset.h" 18 19namespace __tsan { 20 21const int kTracePartSizeBits = 14; 22const int kTracePartSize = 1 << kTracePartSizeBits; 23const int kTraceParts = 4 * 1024 * 1024 / kTracePartSize; 24const int kTraceSize = kTracePartSize * kTraceParts; 25 26// Must fit into 3 bits. 27enum EventType { 28 EventTypeMop, 29 EventTypeFuncEnter, 30 EventTypeFuncExit, 31 EventTypeLock, 32 EventTypeUnlock, 33 EventTypeRLock, 34 EventTypeRUnlock 35}; 36 37// Represents a thread event (from most significant bit): 38// u64 typ : 3; // EventType. 39// u64 addr : 61; // Associated pc. 40typedef u64 Event; 41 42struct TraceHeader { 43#ifndef TSAN_GO 44 BufferedStackTrace stack0; // Start stack for the trace. 45#else 46 VarSizeStackTrace stack0; 47#endif 48 u64 epoch0; // Start epoch for the trace. 49 MutexSet mset0; 50 51 TraceHeader() : stack0(), epoch0() {} 52}; 53 54struct Trace { 55 TraceHeader headers[kTraceParts]; 56 Mutex mtx; 57#ifndef TSAN_GO 58 // Must be last to catch overflow as paging fault. 59 // Go shadow stack is dynamically allocated. 60 uptr shadow_stack[kShadowStackSize]; 61#endif 62 63 Trace() 64 : mtx(MutexTypeTrace, StatMtxTrace) { 65 } 66}; 67 68} // namespace __tsan 69 70#endif // TSAN_TRACE_H 71