[sanitizer] Make destructors protected
authorVitaly Buka <vitalybuka@google.com>
Tue, 3 Nov 2020 00:42:20 +0000 (16:42 -0800)
committerVitaly Buka <vitalybuka@google.com>
Tue, 3 Nov 2020 02:00:43 +0000 (18:00 -0800)
compiler-rt/lib/asan/asan_thread.h
compiler-rt/lib/lsan/lsan_posix.h
compiler-rt/lib/lsan/lsan_thread.h
compiler-rt/lib/memprof/memprof_thread.h
compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector1.cpp
compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector2.cpp
compiler-rt/lib/sanitizer_common/sanitizer_deadlock_detector_interface.h
compiler-rt/lib/sanitizer_common/sanitizer_thread_registry.h
compiler-rt/lib/sanitizer_common/tests/sanitizer_thread_registry_test.cpp
compiler-rt/lib/tsan/rtl/tsan_rtl.h

index c503f50..ea58de4 100644 (file)
@@ -35,7 +35,7 @@ class AsanThread;
 
 // These objects are created for every thread and are never deleted,
 // so we can find them by tid even if the thread is long dead.
-class AsanThreadContext : public ThreadContextBase {
+class AsanThreadContext final : public ThreadContextBase {
  public:
   explicit AsanThreadContext(int tid)
       : ThreadContextBase(tid), announced(false),
index 840e427..b1265f2 100644 (file)
@@ -27,7 +27,7 @@ struct DTLS;
 
 namespace __lsan {
 
-class ThreadContext : public ThreadContextLsanBase {
+class ThreadContext final : public ThreadContextLsanBase {
  public:
   explicit ThreadContext(int tid);
   void OnStarted(void *arg) override;
index e876f9f..a64c19a 100644 (file)
@@ -32,6 +32,7 @@ class ThreadContextLsanBase : public ThreadContextBase {
                           void *onstarted_arg);
 
  protected:
+  ~ThreadContextLsanBase(){};
   uptr stack_begin_ = 0;
   uptr stack_end_ = 0;
   uptr cache_begin_ = 0;
index 4049805..2e1a8bb 100644 (file)
@@ -34,7 +34,7 @@ class MemprofThread;
 
 // These objects are created for every thread and are never deleted,
 // so we can find them by tid even if the thread is long dead.
-struct MemprofThreadContext : public ThreadContextBase {
+struct MemprofThreadContext final : public ThreadContextBase {
   explicit MemprofThreadContext(int tid)
       : ThreadContextBase(tid), announced(false),
         destructor_iterations(GetPthreadDestructorIterations()), stack_id(0),
index d4a325b..2c924f5 100644 (file)
@@ -32,7 +32,7 @@ struct DDLogicalThread {
   bool report_pending;
 };
 
-struct DD : public DDetector {
+struct DD final : public DDetector {
   SpinMutex mtx;
   DeadlockDetector<DDBV> dd;
   DDFlags flags;
index 4026739..e3f8e1b 100644 (file)
@@ -80,7 +80,7 @@ struct Mutex {
   Link link[kMaxLink];
 };
 
-struct DD : public DDetector {
+struct DD final : public DDetector {
   explicit DD(const DDFlags *flags);
 
   DDPhysicalThread* CreatePhysicalThread();
index a4722b0..eda7c32 100644 (file)
@@ -85,6 +85,9 @@ struct DDetector {
   virtual void MutexDestroy(DDCallback *cb, DDMutex *m) {}
 
   virtual DDReport *GetReport(DDCallback *cb) { return nullptr; }
+
+ protected:
+  ~DDetector(){};
 };
 
 } // namespace __sanitizer
index 493aa98..85c522a 100644 (file)
@@ -39,8 +39,6 @@ enum class ThreadType {
 class ThreadContextBase {
  public:
   explicit ThreadContextBase(u32 tid);
-  ~ThreadContextBase();  // Should never be called.
-
   const u32 tid;  // Thread ID. Main thread should have tid = 0.
   u64 unique_id;  // Unique thread ID.
   u32 reuse_count;  // Number of times this tid was reused.
@@ -80,6 +78,9 @@ class ThreadContextBase {
   virtual void OnCreated(void *arg) {}
   virtual void OnReset() {}
   virtual void OnDetached(void *arg) {}
+
+ protected:
+  ~ThreadContextBase();
 };
 
 typedef ThreadContextBase* (*ThreadContextFactory)(u32 tid);
index 6c380f1..af314b7 100644 (file)
@@ -162,7 +162,7 @@ struct RunThreadArgs {
   uptr shard;  // started from 1.
 };
 
-class TestThreadContext : public ThreadContextBase {
+class TestThreadContext final : public ThreadContextBase {
  public:
   explicit TestThreadContext(int tid) : ThreadContextBase(tid) {}
   void OnJoined(void *arg) {
index efdc53a..04d474e 100644 (file)
@@ -477,7 +477,7 @@ inline void cur_thread_finalize() { }
 #endif  // SANITIZER_MAC || SANITIZER_ANDROID
 #endif  // SANITIZER_GO
 
-class ThreadContext : public ThreadContextBase {
+class ThreadContext final : public ThreadContextBase {
  public:
   explicit ThreadContext(int tid);
   ~ThreadContext();