1 //===-- sanitizer_deadlock_detector_interface.h -----------------*- C++ -*-===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // This file is a part of Sanitizer runtime.
9 // Abstract deadlock detector interface.
10 // FIXME: this is work in progress, nothing really works yet.
12 //===----------------------------------------------------------------------===//
14 #ifndef SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H
15 #define SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H
17 #ifndef SANITIZER_DEADLOCK_DETECTOR_VERSION
18 # define SANITIZER_DEADLOCK_DETECTOR_VERSION 1
21 #include "sanitizer_internal_defs.h"
22 #include "sanitizer_atomic.h"
24 namespace __sanitizer
{
26 // dd - deadlock detector.
27 // lt - logical (user) thread.
28 // pt - physical (OS) thread.
30 struct DDPhysicalThread
;
31 struct DDLogicalThread
;
34 #if SANITIZER_DEADLOCK_DETECTOR_VERSION == 1
36 u32 stk
; // creation stack
37 #elif SANITIZER_DEADLOCK_DETECTOR_VERSION == 2
40 atomic_uintptr_t owner
;
42 # error "BAD SANITIZER_DEADLOCK_DETECTOR_VERSION"
48 bool second_deadlock_stack
;
52 enum { kMaxLoopSize
= 20 };
53 int n
; // number of entries in loop
55 u64 thr_ctx
; // user thread context
56 u64 mtx_ctx0
; // user mutex context, start of the edge
57 u64 mtx_ctx1
; // user mutex context, end of the edge
58 u32 stk
[2]; // stack ids for the edge
66 virtual u32
Unwind() { return 0; }
67 virtual int UniqueTid() { return 0; }
71 static DDetector
*Create(const DDFlags
*flags
);
73 virtual DDPhysicalThread
* CreatePhysicalThread() { return nullptr; }
74 virtual void DestroyPhysicalThread(DDPhysicalThread
*pt
) {}
76 virtual DDLogicalThread
* CreateLogicalThread(u64 ctx
) { return nullptr; }
77 virtual void DestroyLogicalThread(DDLogicalThread
*lt
) {}
79 virtual void MutexInit(DDCallback
*cb
, DDMutex
*m
) {}
80 virtual void MutexBeforeLock(DDCallback
*cb
, DDMutex
*m
, bool wlock
) {}
81 virtual void MutexAfterLock(DDCallback
*cb
, DDMutex
*m
, bool wlock
,
83 virtual void MutexBeforeUnlock(DDCallback
*cb
, DDMutex
*m
, bool wlock
) {}
84 virtual void MutexDestroy(DDCallback
*cb
, DDMutex
*m
) {}
86 virtual DDReport
*GetReport(DDCallback
*cb
) { return nullptr; }
89 } // namespace __sanitizer
91 #endif // SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H