summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2014-12-19 20:35:50 +0000
committerAlexey Samsonov <vonosmas@gmail.com>2014-12-19 20:35:50 +0000
commit30f330b39b29cf391fccb7b46b27011010e7dbfb (patch)
treef972684815bed2fb14031fc7d53a69b178242e48
parent0f850bde0e5c2866c0c03de7f6f9254d24ae1e38 (diff)
downloadbcm5719-llvm-30f330b39b29cf391fccb7b46b27011010e7dbfb.tar.gz
bcm5719-llvm-30f330b39b29cf391fccb7b46b27011010e7dbfb.zip
[Sanitizer] Make Quarantine::Init slightly safer.
ASan Quarantine can be reinitialized at activation/deactivation. Make max_size_/min_size_ atomic. llvm-svn: 224613
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h16
1 files changed, 10 insertions, 6 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h b/compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h
index db4eb74505f..c04dc6fac23 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_quarantine.h
+++ b/compiler-rt/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);
}
OpenPOWER on IntegriCloud