sanitizer_deadlock_detector_interface.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //===-- sanitizer_deadlock_detector_interface.h -----------------*- C++ -*-===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  6. //===----------------------------------------------------------------------===//
  7. //
  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.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H
  14. #define SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H
  15. #ifndef SANITIZER_DEADLOCK_DETECTOR_VERSION
  16. # define SANITIZER_DEADLOCK_DETECTOR_VERSION 1
  17. #endif
  18. #include "sanitizer_internal_defs.h"
  19. #include "sanitizer_atomic.h"
  20. namespace __sanitizer {
  21. // dd - deadlock detector.
  22. // lt - logical (user) thread.
  23. // pt - physical (OS) thread.
  24. struct DDPhysicalThread;
  25. struct DDLogicalThread;
  26. struct DDMutex {
  27. #if SANITIZER_DEADLOCK_DETECTOR_VERSION == 1
  28. uptr id;
  29. u32 stk; // creation stack
  30. #elif SANITIZER_DEADLOCK_DETECTOR_VERSION == 2
  31. u32 id;
  32. u32 recursion;
  33. atomic_uintptr_t owner;
  34. #else
  35. # error "BAD SANITIZER_DEADLOCK_DETECTOR_VERSION"
  36. #endif
  37. u64 ctx;
  38. };
  39. struct DDFlags {
  40. bool second_deadlock_stack;
  41. };
  42. struct DDReport {
  43. enum { kMaxLoopSize = 8 };
  44. int n; // number of entries in loop
  45. struct {
  46. u64 thr_ctx; // user thread context
  47. u64 mtx_ctx0; // user mutex context, start of the edge
  48. u64 mtx_ctx1; // user mutex context, end of the edge
  49. u32 stk[2]; // stack ids for the edge
  50. } loop[kMaxLoopSize];
  51. };
  52. struct DDCallback {
  53. DDPhysicalThread *pt;
  54. DDLogicalThread *lt;
  55. virtual u32 Unwind() { return 0; }
  56. virtual int UniqueTid() { return 0; }
  57. };
  58. struct DDetector {
  59. static DDetector *Create(const DDFlags *flags);
  60. virtual DDPhysicalThread* CreatePhysicalThread() { return 0; }
  61. virtual void DestroyPhysicalThread(DDPhysicalThread *pt) {}
  62. virtual DDLogicalThread* CreateLogicalThread(u64 ctx) { return 0; }
  63. virtual void DestroyLogicalThread(DDLogicalThread *lt) {}
  64. virtual void MutexInit(DDCallback *cb, DDMutex *m) {}
  65. virtual void MutexBeforeLock(DDCallback *cb, DDMutex *m, bool wlock) {}
  66. virtual void MutexAfterLock(DDCallback *cb, DDMutex *m, bool wlock,
  67. bool trylock) {}
  68. virtual void MutexBeforeUnlock(DDCallback *cb, DDMutex *m, bool wlock) {}
  69. virtual void MutexDestroy(DDCallback *cb, DDMutex *m) {}
  70. virtual DDReport *GetReport(DDCallback *cb) { return 0; }
  71. };
  72. } // namespace __sanitizer
  73. #endif // SANITIZER_DEADLOCK_DETECTOR_INTERFACE_H