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