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
21typedef DDFlags Flags;
22
23struct Mutex {
24  DDMutex dd;
25};
26
27struct Thread {
28  DDPhysicalThread *dd_pt;
29  DDLogicalThread *dd_lt;
30
31  bool ignore_interceptors;
32};
33
34struct Callback : DDCallback {
35  Thread *thr;
36
37  Callback(Thread *thr);
38  u32 Unwind() override;
39};
40
41typedef AddrHashMap<Mutex, 31051> MutexHashMap;
42
43struct Context {
44  DDetector *dd;
45
46  BlockingMutex report_mutex;
47  MutexHashMap mutex_map;
48};
49
50inline Flags* flags() {
51  static Flags flags;
52  return &flags;
53}
54
55void Initialize();
56void InitializeInterceptors();
57
58void ThreadInit(Thread *thr);
59void ThreadDestroy(Thread *thr);
60
61void MutexBeforeLock(Thread *thr, uptr m, bool writelock);
62void MutexAfterLock(Thread *thr, uptr m, bool writelock, bool trylock);
63void MutexBeforeUnlock(Thread *thr, uptr m, bool writelock);
64void MutexDestroy(Thread *thr, uptr m);
65
66}  // namespace __dsan
67#endif  // DD_RTL_H
68