[compiler-rt] r224613 - [Sanitizer] Make Quarantine::Init slightly safer.

Alexey Samsonov vonosmas at gmail.com
Fri Dec 19 12:35:50 PST 2014


Author: samsonov
Date: Fri Dec 19 14:35:50 2014
New Revision: 224613

URL: http://llvm.org/viewvc/llvm-project?rev=224613&view=rev
Log:
[Sanitizer] Make Quarantine::Init slightly safer.

ASan Quarantine can be reinitialized at activation/deactivation.
Make max_size_/min_size_ atomic.

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h?rev=224613&r1=224612&r2=224613&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_quarantine.h Fri Dec 19 14:35:50 2014
@@ -49,11 +49,14 @@ class Quarantine {
   }
 
   void Init(uptr size, uptr cache_size) {
-    max_size_ = size;
-    min_size_ = size / 10 * 9;  // 90% of max size.
+    atomic_store(&max_size_, size, memory_order_release);
+    atomic_store(&min_size_, size / 10 * 9,
+                 memory_order_release); // 90% of max size.
     max_cache_size_ = cache_size;
   }
 
+  uptr GetSize() const { return atomic_load(&max_size_, memory_order_acquire); }
+
   void Put(Cache *c, Callback cb, Node *ptr, uptr size) {
     c->Enqueue(cb, ptr, size);
     if (c->Size() > max_cache_size_)
@@ -65,15 +68,15 @@ class Quarantine {
       SpinMutexLock l(&cache_mutex_);
       cache_.Transfer(c);
     }
-    if (cache_.Size() > max_size_ && recycle_mutex_.TryLock())
+    if (cache_.Size() > GetSize() && recycle_mutex_.TryLock())
       Recycle(cb);
   }
 
  private:
   // Read-only data.
   char pad0_[kCacheLineSize];
-  uptr max_size_;
-  uptr min_size_;
+  atomic_uintptr_t max_size_;
+  atomic_uintptr_t min_size_;
   uptr max_cache_size_;
   char pad1_[kCacheLineSize];
   SpinMutex cache_mutex_;
@@ -83,9 +86,10 @@ class Quarantine {
 
   void NOINLINE Recycle(Callback cb) {
     Cache tmp;
+    uptr min_size = atomic_load(&min_size_, memory_order_acquire);
     {
       SpinMutexLock l(&cache_mutex_);
-      while (cache_.Size() > min_size_) {
+      while (cache_.Size() > min_size) {
         QuarantineBatch *b = cache_.DequeueBatch();
         tmp.EnqueueBatch(b);
       }





More information about the llvm-commits mailing list