1238901Sandrew//===-- tsan_report.h -------------------------------------------*- C++ -*-===//
2238901Sandrew//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6238901Sandrew//
7238901Sandrew//===----------------------------------------------------------------------===//
8238901Sandrew//
9238901Sandrew// This file is a part of ThreadSanitizer (TSan), a race detector.
10238901Sandrew//
11238901Sandrew//===----------------------------------------------------------------------===//
12238901Sandrew#ifndef TSAN_REPORT_H
13238901Sandrew#define TSAN_REPORT_H
14238901Sandrew
15276789Sdim#include "sanitizer_common/sanitizer_symbolizer.h"
16353358Sdim#include "sanitizer_common/sanitizer_thread_registry.h"
17327952Sdim#include "sanitizer_common/sanitizer_vector.h"
18238901Sandrew#include "tsan_defs.h"
19238901Sandrew
20238901Sandrewnamespace __tsan {
21238901Sandrew
22238901Sandrewenum ReportType {
23238901Sandrew  ReportTypeRace,
24251034Sed  ReportTypeVptrRace,
25238901Sandrew  ReportTypeUseAfterFree,
26276789Sdim  ReportTypeVptrUseAfterFree,
27321369Sdim  ReportTypeExternalRace,
28238901Sandrew  ReportTypeThreadLeak,
29238901Sandrew  ReportTypeMutexDestroyLocked,
30276789Sdim  ReportTypeMutexDoubleLock,
31309124Sdim  ReportTypeMutexInvalidAccess,
32276789Sdim  ReportTypeMutexBadUnlock,
33276789Sdim  ReportTypeMutexBadReadLock,
34276789Sdim  ReportTypeMutexBadReadUnlock,
35238901Sandrew  ReportTypeSignalUnsafe,
36276789Sdim  ReportTypeErrnoInSignal,
37276789Sdim  ReportTypeDeadlock
38238901Sandrew};
39238901Sandrew
40238901Sandrewstruct ReportStack {
41276789Sdim  SymbolizedStack *frames;
42276789Sdim  bool suppressable;
43276789Sdim  static ReportStack *New();
44276789Sdim
45276789Sdim private:
46276789Sdim  ReportStack();
47238901Sandrew};
48238901Sandrew
49245614Sandrewstruct ReportMopMutex {
50245614Sandrew  u64 id;
51245614Sandrew  bool write;
52245614Sandrew};
53245614Sandrew
54238901Sandrewstruct ReportMop {
55238901Sandrew  int tid;
56238901Sandrew  uptr addr;
57238901Sandrew  int size;
58238901Sandrew  bool write;
59251034Sed  bool atomic;
60321369Sdim  uptr external_tag;
61245614Sandrew  Vector<ReportMopMutex> mset;
62238901Sandrew  ReportStack *stack;
63245614Sandrew
64245614Sandrew  ReportMop();
65238901Sandrew};
66238901Sandrew
67238901Sandrewenum ReportLocationType {
68238901Sandrew  ReportLocationGlobal,
69238901Sandrew  ReportLocationHeap,
70238901Sandrew  ReportLocationStack,
71245614Sandrew  ReportLocationTLS,
72245614Sandrew  ReportLocationFD
73238901Sandrew};
74238901Sandrew
75238901Sandrewstruct ReportLocation {
76238901Sandrew  ReportLocationType type;
77276789Sdim  DataInfo global;
78276789Sdim  uptr heap_chunk_start;
79276789Sdim  uptr heap_chunk_size;
80321369Sdim  uptr external_tag;
81238901Sandrew  int tid;
82245614Sandrew  int fd;
83276789Sdim  bool suppressable;
84238901Sandrew  ReportStack *stack;
85276789Sdim
86276789Sdim  static ReportLocation *New(ReportLocationType type);
87276789Sdim private:
88276789Sdim  explicit ReportLocation(ReportLocationType type);
89238901Sandrew};
90238901Sandrew
91238901Sandrewstruct ReportThread {
92238901Sandrew  int id;
93321369Sdim  tid_t os_id;
94238901Sandrew  bool running;
95353358Sdim  ThreadType thread_type;
96238901Sandrew  char *name;
97321369Sdim  u32 parent_tid;
98238901Sandrew  ReportStack *stack;
99238901Sandrew};
100238901Sandrew
101238901Sandrewstruct ReportMutex {
102245614Sandrew  u64 id;
103276789Sdim  uptr addr;
104245614Sandrew  bool destroyed;
105238901Sandrew  ReportStack *stack;
106238901Sandrew};
107238901Sandrew
108238901Sandrewclass ReportDesc {
109238901Sandrew public:
110238901Sandrew  ReportType typ;
111321369Sdim  uptr tag;
112238901Sandrew  Vector<ReportStack*> stacks;
113238901Sandrew  Vector<ReportMop*> mops;
114238901Sandrew  Vector<ReportLocation*> locs;
115238901Sandrew  Vector<ReportMutex*> mutexes;
116238901Sandrew  Vector<ReportThread*> threads;
117276789Sdim  Vector<int> unique_tids;
118245614Sandrew  ReportStack *sleep;
119251034Sed  int count;
120238901Sandrew
121238901Sandrew  ReportDesc();
122238901Sandrew  ~ReportDesc();
123238901Sandrew
124238901Sandrew private:
125238901Sandrew  ReportDesc(const ReportDesc&);
126238901Sandrew  void operator = (const ReportDesc&);
127238901Sandrew};
128238901Sandrew
129238901Sandrew// Format and output the report to the console/log. No additional logic.
130238901Sandrewvoid PrintReport(const ReportDesc *rep);
131245614Sandrewvoid PrintStack(const ReportStack *stack);
132238901Sandrew
133238901Sandrew}  // namespace __tsan
134238901Sandrew
135238901Sandrew#endif  // TSAN_REPORT_H
136