diff options
author | Kostya Serebryany <kcc@google.com> | 2013-10-21 08:36:10 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2013-10-21 08:36:10 +0000 |
commit | a650de81e9ce919edc876728fce7c1f4cdc4abcc (patch) | |
tree | 12ac2861f0d13bf34a8885a4c30fb6f233f82a47 /lib/sanitizer_common/sanitizer_quarantine.h | |
parent | 3e5c47d7ad275493bb895ff3d6b36174d3c90322 (diff) |
[asan] count the size of QuarantineBatch in the total Quarantine size; make QuarantineBatch fit into 8K, fix a MSVC compile warning
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@193072 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_quarantine.h')
-rw-r--r-- | lib/sanitizer_common/sanitizer_quarantine.h | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/sanitizer_common/sanitizer_quarantine.h b/lib/sanitizer_common/sanitizer_quarantine.h index b21ab23a7..db4eb7450 100644 --- a/lib/sanitizer_common/sanitizer_quarantine.h +++ b/lib/sanitizer_common/sanitizer_quarantine.h @@ -26,13 +26,15 @@ namespace __sanitizer { template<typename Node> class QuarantineCache; struct QuarantineBatch { - static const uptr kSize = 1024; + static const uptr kSize = 1021; QuarantineBatch *next; uptr size; uptr count; void *batch[kSize]; }; +COMPILER_CHECK(sizeof(QuarantineBatch) <= (1 << 13)); // 8Kb. + // The callback interface is: // void Callback::Recycle(Node *ptr); // void *cb.Allocate(uptr size); @@ -123,8 +125,10 @@ class QuarantineCache { } void Enqueue(Callback cb, void *ptr, uptr size) { - if (list_.empty() || list_.back()->count == QuarantineBatch::kSize) + if (list_.empty() || list_.back()->count == QuarantineBatch::kSize) { AllocBatch(cb); + size += sizeof(QuarantineBatch); // Count the batch in Quarantine size. + } QuarantineBatch *b = list_.back(); b->batch[b->count++] = ptr; b->size += size; @@ -147,9 +151,7 @@ class QuarantineCache { return 0; QuarantineBatch *b = list_.front(); list_.pop_front(); - // FIXME: should probably add SizeSub method? - // See https://code.google.com/p/thread-sanitizer/issues/detail?id=20 - SizeAdd(0 - b->size); + SizeSub(b->size); return b; } @@ -160,6 +162,9 @@ class QuarantineCache { void SizeAdd(uptr add) { atomic_store(&size_, Size() + add, memory_order_relaxed); } + void SizeSub(uptr sub) { + atomic_store(&size_, Size() - sub, memory_order_relaxed); + } NOINLINE QuarantineBatch* AllocBatch(Callback cb) { QuarantineBatch *b = (QuarantineBatch *)cb.Allocate(sizeof(*b)); |