1 //===-- sanitizer_deadlock_detector_interface.h -----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of Sanitizer runtime.
11 // Abstract deadlock detector interface.
12 // FIXME: this is work in progress, nothing really works yet.
14 //===----------------------------------------------------------------------===//
16 #ifndef SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H
17 #define SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H
19 #ifndef SANITIZER_DEADLOCK_DETECTOR_VERSION
20 # define SANITIZER_DEADLOCK_DETECTOR_VERSION 1
23 #include "sanitizer_internal_defs.h"
24 #include "sanitizer_atomic.h"
26 namespace __sanitizer {
28 // dd - deadlock detector.
29 // lt - logical (user) thread.
30 // pt - physical (OS) thread.
32 struct DDPhysicalThread;
33 struct DDLogicalThread;
36 #if SANITIZER_DEADLOCK_DETECTOR_VERSION == 1
38 u32 stk; // creation stack
39 #elif SANITIZER_DEADLOCK_DETECTOR_VERSION == 2
42 atomic_uintptr_t owner;
44 # error "BAD SANITIZER_DEADLOCK_DETECTOR_VERSION"
50 bool second_deadlock_stack;
54 enum { kMaxLoopSize = 20 };
55 int n; // number of entries in loop
57 u64 thr_ctx; // user thread context
58 u64 mtx_ctx0; // user mutex context, start of the edge
59 u64 mtx_ctx1; // user mutex context, end of the edge
60 u32 stk[2]; // stack ids for the edge
68 virtual u32 Unwind() { return 0; }
69 virtual int UniqueTid() { return 0; }
73 static DDetector *Create(const DDFlags *flags);
75 virtual DDPhysicalThread* CreatePhysicalThread() { return nullptr; }
76 virtual void DestroyPhysicalThread(DDPhysicalThread *pt) {}
78 virtual DDLogicalThread* CreateLogicalThread(u64 ctx) { return nullptr; }
79 virtual void DestroyLogicalThread(DDLogicalThread *lt) {}
81 virtual void MutexInit(DDCallback *cb, DDMutex *m) {}
82 virtual void MutexBeforeLock(DDCallback *cb, DDMutex *m, bool wlock) {}
83 virtual void MutexAfterLock(DDCallback *cb, DDMutex *m, bool wlock,
85 virtual void MutexBeforeUnlock(DDCallback *cb, DDMutex *m, bool wlock) {}
86 virtual void MutexDestroy(DDCallback *cb, DDMutex *m) {}
88 virtual DDReport *GetReport(DDCallback *cb) { return nullptr; }
91 } // namespace __sanitizer
93 #endif // SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H