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