annotate libsanitizer/sanitizer_common/sanitizer_deadlock_detector_interface.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 //===-- sanitizer_deadlock_detector_interface.h -----------------*- C++ -*-===//
kono
parents:
diff changeset
2 //
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
1830386684a0 gcc-9.2.0
anatofuz
parents: 111
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
111
kono
parents:
diff changeset
6 //
kono
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
8 //
kono
parents:
diff changeset
9 // This file is a part of Sanitizer runtime.
kono
parents:
diff changeset
10 // Abstract deadlock detector interface.
kono
parents:
diff changeset
11 // FIXME: this is work in progress, nothing really works yet.
kono
parents:
diff changeset
12 //
kono
parents:
diff changeset
13 //===----------------------------------------------------------------------===//
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 #ifndef SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H
kono
parents:
diff changeset
16 #define SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H
kono
parents:
diff changeset
17
kono
parents:
diff changeset
18 #ifndef SANITIZER_DEADLOCK_DETECTOR_VERSION
kono
parents:
diff changeset
19 # define SANITIZER_DEADLOCK_DETECTOR_VERSION 1
kono
parents:
diff changeset
20 #endif
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 #include "sanitizer_internal_defs.h"
kono
parents:
diff changeset
23 #include "sanitizer_atomic.h"
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 namespace __sanitizer {
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 // dd - deadlock detector.
kono
parents:
diff changeset
28 // lt - logical (user) thread.
kono
parents:
diff changeset
29 // pt - physical (OS) thread.
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 struct DDPhysicalThread;
kono
parents:
diff changeset
32 struct DDLogicalThread;
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 struct DDMutex {
kono
parents:
diff changeset
35 #if SANITIZER_DEADLOCK_DETECTOR_VERSION == 1
kono
parents:
diff changeset
36 uptr id;
kono
parents:
diff changeset
37 u32 stk; // creation stack
kono
parents:
diff changeset
38 #elif SANITIZER_DEADLOCK_DETECTOR_VERSION == 2
kono
parents:
diff changeset
39 u32 id;
kono
parents:
diff changeset
40 u32 recursion;
kono
parents:
diff changeset
41 atomic_uintptr_t owner;
kono
parents:
diff changeset
42 #else
kono
parents:
diff changeset
43 # error "BAD SANITIZER_DEADLOCK_DETECTOR_VERSION"
kono
parents:
diff changeset
44 #endif
kono
parents:
diff changeset
45 u64 ctx;
kono
parents:
diff changeset
46 };
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 struct DDFlags {
kono
parents:
diff changeset
49 bool second_deadlock_stack;
kono
parents:
diff changeset
50 };
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 struct DDReport {
kono
parents:
diff changeset
53 enum { kMaxLoopSize = 20 };
kono
parents:
diff changeset
54 int n; // number of entries in loop
kono
parents:
diff changeset
55 struct {
kono
parents:
diff changeset
56 u64 thr_ctx; // user thread context
kono
parents:
diff changeset
57 u64 mtx_ctx0; // user mutex context, start of the edge
kono
parents:
diff changeset
58 u64 mtx_ctx1; // user mutex context, end of the edge
kono
parents:
diff changeset
59 u32 stk[2]; // stack ids for the edge
kono
parents:
diff changeset
60 } loop[kMaxLoopSize];
kono
parents:
diff changeset
61 };
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 struct DDCallback {
kono
parents:
diff changeset
64 DDPhysicalThread *pt;
kono
parents:
diff changeset
65 DDLogicalThread *lt;
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 virtual u32 Unwind() { return 0; }
kono
parents:
diff changeset
68 virtual int UniqueTid() { return 0; }
kono
parents:
diff changeset
69 };
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 struct DDetector {
kono
parents:
diff changeset
72 static DDetector *Create(const DDFlags *flags);
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 virtual DDPhysicalThread* CreatePhysicalThread() { return nullptr; }
kono
parents:
diff changeset
75 virtual void DestroyPhysicalThread(DDPhysicalThread *pt) {}
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 virtual DDLogicalThread* CreateLogicalThread(u64 ctx) { return nullptr; }
kono
parents:
diff changeset
78 virtual void DestroyLogicalThread(DDLogicalThread *lt) {}
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 virtual void MutexInit(DDCallback *cb, DDMutex *m) {}
kono
parents:
diff changeset
81 virtual void MutexBeforeLock(DDCallback *cb, DDMutex *m, bool wlock) {}
kono
parents:
diff changeset
82 virtual void MutexAfterLock(DDCallback *cb, DDMutex *m, bool wlock,
kono
parents:
diff changeset
83 bool trylock) {}
kono
parents:
diff changeset
84 virtual void MutexBeforeUnlock(DDCallback *cb, DDMutex *m, bool wlock) {}
kono
parents:
diff changeset
85 virtual void MutexDestroy(DDCallback *cb, DDMutex *m) {}
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 virtual DDReport *GetReport(DDCallback *cb) { return nullptr; }
kono
parents:
diff changeset
88 };
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 } // namespace __sanitizer
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 #endif // SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H