diff options
author | Alexey Samsonov <vonosmas@gmail.com> | 2014-12-19 20:35:50 +0000 |
---|---|---|
committer | Alexey Samsonov <vonosmas@gmail.com> | 2014-12-19 20:35:50 +0000 |
commit | 262ebb726c15f7d11fe24566b6486fe4422b97a4 (patch) | |
tree | a4775895c1a440cc87ee4730647d588be8ea7a7c /lib/sanitizer_common/sanitizer_quarantine.h | |
parent | 88f8290d1d938390cce86b9a579bd46e64e5d04d (diff) | |
download | compiler-rt-262ebb726c15f7d11fe24566b6486fe4422b97a4.tar.gz |
[Sanitizer] Make Quarantine::Init slightly safer.
ASan Quarantine can be reinitialized at activation/deactivation.
Make max_size_/min_size_ atomic.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@224613 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_quarantine.h')
-rw-r--r-- | lib/sanitizer_common/sanitizer_quarantine.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/sanitizer_common/sanitizer_quarantine.h b/lib/sanitizer_common/sanitizer_quarantine.h index db4eb7450..c04dc6fac 100644 --- a/lib/sanitizer_common/sanitizer_quarantine.h +++ b/lib/sanitizer_common/sanitizer_quarantine.h @@ -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); } |