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_stack_trace.h" 17 #include "tsan_mutexset.h" 18 19 namespace __tsan { 20 21 const int kTracePartSizeBits = 13; 22 const int kTracePartSize = 1 << kTracePartSizeBits; 23 const int kTraceParts = 2 * 1024 * 1024 / kTracePartSize; 24 const int kTraceSize = kTracePartSize * kTraceParts; 25 26 // Must fit into 3 bits. 27 enum 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. 40 typedef u64 Event; 41 42 const uptr kEventPCBits = 61; 43 44 struct TraceHeader { 45 #if !SANITIZER_GO 46 BufferedStackTrace stack0; // Start stack for the trace. 47 #else 48 VarSizeStackTrace stack0; 49 #endif 50 u64 epoch0; // Start epoch for the trace. 51 MutexSet mset0; 52 53 TraceHeader() : stack0(), epoch0() {} 54 }; 55 56 struct Trace { 57 Mutex mtx; 58 #if !SANITIZER_GO 59 // Must be last to catch overflow as paging fault. 60 // Go shadow stack is dynamically allocated. 61 uptr shadow_stack[kShadowStackSize]; 62 #endif 63 // Must be the last field, because we unmap the unused part in 64 // CreateThreadContext. 65 TraceHeader headers[kTraceParts]; 66 67 Trace() : mtx(MutexTypeTrace) {} 68 }; 69 70 } // namespace __tsan 71 72 #endif // TSAN_TRACE_H 73