1//===-- dd_rtl.h ----------------------------------------------------------===//
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#ifndef DD_RTL_H
10#define DD_RTL_H
11
12#include "sanitizer_common/sanitizer_internal_defs.h"
13#include "sanitizer_common/sanitizer_deadlock_detector_interface.h"
14#include "sanitizer_common/sanitizer_flags.h"
15#include "sanitizer_common/sanitizer_allocator_internal.h"
16#include "sanitizer_common/sanitizer_addrhashmap.h"
17#include "sanitizer_common/sanitizer_mutex.h"
18
19namespace __dsan {
20
21struct Flags : CommonFlags, DDFlags {
22};
23
24struct Mutex {
25  DDMutex dd;
26};
27
28struct Thread {
29  DDPhysicalThread *dd_pt;
30  DDLogicalThread *dd_lt;
31
32  bool ignore_interceptors;
33};
34
35struct Callback : DDCallback {
36  Thread *thr;
37
38  Callback(Thread *thr);
39  virtual u32 Unwind();
40};
41
42typedef AddrHashMap<Mutex, 31051> MutexHashMap;
43
44struct Context {
45  DDetector *dd;
46
47  BlockingMutex report_mutex;
48  MutexHashMap mutex_map;
49};
50
51inline Flags* flags() {
52  static Flags flags;
53  return &flags;
54}
55
56void Initialize();
57void InitializeInterceptors();
58
59void ThreadInit(Thread *thr);
60void ThreadDestroy(Thread *thr);
61
62void MutexBeforeLock(Thread *thr, uptr m, bool writelock);
63void MutexAfterLock(Thread *thr, uptr m, bool writelock, bool trylock);
64void MutexBeforeUnlock(Thread *thr, uptr m, bool writelock);
65void MutexDestroy(Thread *thr, uptr m);
66
67}  // namespace __dsan
68#endif  // DD_RTL_H
69