1 //===-- tsan_trace.h --------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file is a part of ThreadSanitizer (TSan), a race detector. 10 // 11 //===----------------------------------------------------------------------===// 12 #ifndef TSAN_TRACE_H 13 #define TSAN_TRACE_H 14 15 #include "tsan_defs.h" 16 #include "tsan_mutex.h" 17 #include "tsan_stack_trace.h" 18 #include "tsan_mutexset.h" 19 20 namespace __tsan { 21 22 const int kTracePartSizeBits = 13; 23 const int kTracePartSize = 1 << kTracePartSizeBits; 24 const int kTraceParts = 2 * 1024 * 1024 / kTracePartSize; 25 const int kTraceSize = kTracePartSize * kTraceParts; 26 27 // Must fit into 3 bits. 28 enum EventType { 29 EventTypeMop, 30 EventTypeFuncEnter, 31 EventTypeFuncExit, 32 EventTypeLock, 33 EventTypeUnlock, 34 EventTypeRLock, 35 EventTypeRUnlock 36 }; 37 38 // Represents a thread event (from most significant bit): 39 // u64 typ : 3; // EventType. 40 // u64 addr : 61; // Associated pc. 41 typedef u64 Event; 42 43 const uptr kEventPCBits = 61; 44 45 struct TraceHeader { 46 #if !SANITIZER_GO 47 BufferedStackTrace stack0; // Start stack for the trace. 48 #else 49 VarSizeStackTrace stack0; 50 #endif 51 u64 epoch0; // Start epoch for the trace. 52 MutexSet mset0; 53 TraceHeaderTraceHeader54 TraceHeader() : stack0(), epoch0() {} 55 }; 56 57 struct Trace { 58 Mutex mtx; 59 #if !SANITIZER_GO 60 // Must be last to catch overflow as paging fault. 61 // Go shadow stack is dynamically allocated. 62 uptr shadow_stack[kShadowStackSize]; 63 #endif 64 // Must be the last field, because we unmap the unused part in 65 // CreateThreadContext. 66 TraceHeader headers[kTraceParts]; 67 TraceTrace68 Trace() 69 : mtx(MutexTypeTrace, StatMtxTrace) { 70 } 71 }; 72 73 } // namespace __tsan 74 75 #endif // TSAN_TRACE_H 76