From b29d42ee31832406dc8ab100935209e1f457458b Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 5 Sep 2018 23:22:38 +0000 Subject: [PATCH] [hwasan] simplify the code, NFC llvm-svn: 341501 --- compiler-rt/lib/hwasan/hwasan_allocator.cc | 15 ++++----------- compiler-rt/lib/hwasan/hwasan_allocator.h | 8 +------- compiler-rt/lib/hwasan/hwasan_thread.cc | 2 +- compiler-rt/lib/hwasan/hwasan_thread.h | 4 ++-- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cc b/compiler-rt/lib/hwasan/hwasan_allocator.cc index 3b0859a..c54117b 100644 --- a/compiler-rt/lib/hwasan/hwasan_allocator.cc +++ b/compiler-rt/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(tagged_ptr), alloc_context_id, free_context_id, static_cast(orig_size)}); diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.h b/compiler-rt/lib/hwasan/hwasan_allocator.h index 4235c4f..8e58085 100644 --- a/compiler-rt/lib/hwasan/hwasan_allocator.h +++ b/compiler-rt/lib/hwasan/hwasan_allocator.h @@ -64,14 +64,8 @@ typedef LargeMmapAllocator SecondaryAllocator; typedef CombinedAllocator 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/compiler-rt/lib/hwasan/hwasan_thread.cc b/compiler-rt/lib/hwasan/hwasan_thread.cc index ce19e16..0a93b43 100644 --- a/compiler-rt/lib/hwasan/hwasan_thread.cc +++ b/compiler-rt/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/compiler-rt/lib/hwasan/hwasan_thread.h b/compiler-rt/lib/hwasan/hwasan_thread.h index f1d79c7..451baf3 100644 --- a/compiler-rt/lib/hwasan/hwasan_thread.h +++ b/compiler-rt/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); -- 2.7.4