[sanitizer] Lock/Unlock stack store on fork
authorVitaly Buka <vitalybuka@google.com>
Tue, 7 Dec 2021 01:58:52 +0000 (17:58 -0800)
committerVitaly Buka <vitalybuka@google.com>
Tue, 7 Dec 2021 19:17:16 +0000 (11:17 -0800)
Reviewed By: dvyukov

Differential Revision: https://reviews.llvm.org/D115210

compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp

index 20826cc..4791a3a 100644 (file)
@@ -108,6 +108,14 @@ uptr StackStore::Pack(Compression type) {
   return res;
 }
 
+void StackStore::LockAll() {
+  for (BlockInfo &b : blocks_) b.Lock();
+}
+
+void StackStore::UnlockAll() {
+  for (BlockInfo &b : blocks_) b.Unlock();
+}
+
 void StackStore::TestOnlyUnmap() {
   for (BlockInfo &b : blocks_) b.TestOnlyUnmap(this);
   internal_memset(this, 0, sizeof(*this));
index 14b1f43..1bfad81 100644 (file)
@@ -46,6 +46,9 @@ class StackStore {
   // Returns the number of released bytes.
   uptr Pack(Compression type);
 
+  void LockAll();
+  void UnlockAll();
+
   void TestOnlyUnmap();
 
  private:
@@ -106,6 +109,8 @@ class StackStore {
     void TestOnlyUnmap(StackStore *store);
     bool Stored(uptr n);
     bool IsPacked() const;
+    void Lock() NO_THREAD_SAFETY_ANALYSIS { mtx_.Lock(); }
+    void Unlock() NO_THREAD_SAFETY_ANALYSIS { mtx_.Unlock(); }
   };
 
   BlockInfo blocks_[kBlockCount] = {};
index af107b3..1d3ac5c 100644 (file)
@@ -113,9 +113,11 @@ StackTrace StackDepotGet(u32 id) {
 
 void StackDepotLockAll() {
   theDepot.LockAll();
+  stackStore.LockAll();
 }
 
 void StackDepotUnlockAll() {
+  stackStore.UnlockAll();
   theDepot.UnlockAll();
 }