summaryrefslogtreecommitdiff
path: root/lib/hwasan
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2018-09-05 23:22:38 +0000
committerKostya Serebryany <kcc@google.com>2018-09-05 23:22:38 +0000
commitfa9b5b44c7b5638ef84008855287ca8b74869ecb (patch)
treee202ab3a82eb4af3eb79e2c973b9701c5c50d618 /lib/hwasan
parenteed7437a9290dbee98da9fee6e41eb44389e9177 (diff)
downloadcompiler-rt-fa9b5b44c7b5638ef84008855287ca8b74869ecb.tar.gz
[hwasan] simplify the code, NFC
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@341501 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/hwasan')
-rw-r--r--lib/hwasan/hwasan_allocator.cc15
-rw-r--r--lib/hwasan/hwasan_allocator.h8
-rw-r--r--lib/hwasan/hwasan_thread.cc2
-rw-r--r--lib/hwasan/hwasan_thread.h4
4 files changed, 8 insertions, 21 deletions
diff --git a/lib/hwasan/hwasan_allocator.cc b/lib/hwasan/hwasan_allocator.cc
index 3b0859a4f..c54117b3e 100644
--- a/lib/hwasan/hwasan_allocator.cc
+++ b/lib/hwasan/hwasan_allocator.cc
@@ -55,13 +55,8 @@ void HwasanAllocatorInit() {
allocator.Init(common_flags()->allocator_release_to_os_interval_ms);
}
-AllocatorCache *GetAllocatorCache(HwasanThreadLocalMallocStorage *ms) {
- CHECK(ms);
- return &ms->allocator_cache;
-}
-
-void HwasanThreadLocalMallocStorage::CommitBack() {
- allocator.SwallowCache(GetAllocatorCache(this));
+void AllocatorSwallowThreadLocalCache(AllocatorCache *cache) {
+ allocator.SwallowCache(cache);
}
static uptr TaggedSize(uptr size) {
@@ -85,8 +80,7 @@ static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment,
Thread *t = GetCurrentThread();
void *allocated;
if (t) {
- AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
- allocated = allocator.Allocate(cache, size, alignment);
+ allocated = allocator.Allocate(t->allocator_cache(), size, alignment);
} else {
SpinMutexLock l(&fallback_mutex);
AllocatorCache *cache = &fallback_allocator_cache;
@@ -154,8 +148,7 @@ void HwasanDeallocate(StackTrace *stack, void *tagged_ptr) {
TagMemoryAligned((uptr)untagged_ptr, TaggedSize(orig_size),
t ? t->GenerateRandomTag() : kFallbackFreeTag);
if (t) {
- AllocatorCache *cache = GetAllocatorCache(&t->malloc_storage());
- allocator.Deallocate(cache, untagged_ptr);
+ allocator.Deallocate(t->allocator_cache(), untagged_ptr);
if (auto *ha = t->heap_allocations())
ha->push({reinterpret_cast<uptr>(tagged_ptr), alloc_context_id,
free_context_id, static_cast<u32>(orig_size)});
diff --git a/lib/hwasan/hwasan_allocator.h b/lib/hwasan/hwasan_allocator.h
index 4235c4fd8..8e5808508 100644
--- a/lib/hwasan/hwasan_allocator.h
+++ b/lib/hwasan/hwasan_allocator.h
@@ -64,14 +64,8 @@ typedef LargeMmapAllocator<HwasanMapUnmapCallback> SecondaryAllocator;
typedef CombinedAllocator<PrimaryAllocator, AllocatorCache,
SecondaryAllocator> Allocator;
-struct HwasanThreadLocalMallocStorage {
- AllocatorCache allocator_cache;
- void CommitBack();
- private:
- // These objects are allocated via mmap() and are zero-initialized.
- HwasanThreadLocalMallocStorage() {}
-};
+void AllocatorSwallowThreadLocalCache(AllocatorCache *cache);
class HwasanChunkView {
public:
diff --git a/lib/hwasan/hwasan_thread.cc b/lib/hwasan/hwasan_thread.cc
index ce19e16d3..0a93b4354 100644
--- a/lib/hwasan/hwasan_thread.cc
+++ b/lib/hwasan/hwasan_thread.cc
@@ -114,7 +114,7 @@ void Thread::ClearShadowForThreadStackAndTLS() {
void Thread::Destroy() {
if (flags()->verbose_threads)
Print("Destroying: ");
- malloc_storage().CommitBack();
+ AllocatorSwallowThreadLocalCache(allocator_cache());
ClearShadowForThreadStackAndTLS();
RemoveFromThreadList(this);
uptr size = RoundUpTo(sizeof(Thread), GetPageSizeCached());
diff --git a/lib/hwasan/hwasan_thread.h b/lib/hwasan/hwasan_thread.h
index f1d79c750..451baf3c0 100644
--- a/lib/hwasan/hwasan_thread.h
+++ b/lib/hwasan/hwasan_thread.h
@@ -46,7 +46,7 @@ class Thread {
void EnterInterceptorScope() { in_interceptor_scope_++; }
void LeaveInterceptorScope() { in_interceptor_scope_--; }
- HwasanThreadLocalMallocStorage &malloc_storage() { return malloc_storage_; }
+ AllocatorCache *allocator_cache() { return &allocator_cache_; }
HeapAllocationsRingBuffer *heap_allocations() {
return heap_allocations_;
}
@@ -93,7 +93,7 @@ class Thread {
u32 random_state_;
u32 random_buffer_;
- HwasanThreadLocalMallocStorage malloc_storage_;
+ AllocatorCache allocator_cache_;
HeapAllocationsRingBuffer *heap_allocations_;
static void InsertIntoThreadList(Thread *t);