[compiler-rt] 81f9dc8 - [sanitizer] Lock/Unlock stack store on fork

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 7 11:17:25 PST 2021


Author: Vitaly Buka
Date: 2021-12-07T11:17:16-08:00
New Revision: 81f9dc8eee3b9319d911583a01b0060b5bce6018

URL: https://github.com/llvm/llvm-project/commit/81f9dc8eee3b9319d911583a01b0060b5bce6018
DIFF: https://github.com/llvm/llvm-project/commit/81f9dc8eee3b9319d911583a01b0060b5bce6018.diff

LOG: [sanitizer] Lock/Unlock stack store on fork

Reviewed By: dvyukov

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

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
index 20826cc319b73..4791a3a35bdb3 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.cpp
@@ -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));

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h b/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
index 14b1f43d3cc87..1bfad811f712d 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stack_store.h
@@ -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] = {};

diff  --git a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
index af107b3980a58..1d3ac5cc778a7 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stackdepot.cpp
@@ -113,9 +113,11 @@ StackTrace StackDepotGet(u32 id) {
 
 void StackDepotLockAll() {
   theDepot.LockAll();
+  stackStore.LockAll();
 }
 
 void StackDepotUnlockAll() {
+  stackStore.UnlockAll();
   theDepot.UnlockAll();
 }
 


        


More information about the llvm-commits mailing list