[compiler-rt] r341501 - [hwasan] simplify the code, NFC
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 5 16:22:39 PDT 2018
Author: kcc
Date: Wed Sep 5 16:22:38 2018
New Revision: 341501
URL: http://llvm.org/viewvc/llvm-project?rev=341501&view=rev
Log:
[hwasan] simplify the code, NFC
Modified:
compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc
compiler-rt/trunk/lib/hwasan/hwasan_allocator.h
compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
compiler-rt/trunk/lib/hwasan/hwasan_thread.h
Modified: compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc?rev=341501&r1=341500&r2=341501&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc Wed Sep 5 16:22:38 2018
@@ -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 *
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,
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)});
Modified: compiler-rt/trunk/lib/hwasan/hwasan_allocator.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_allocator.h?rev=341501&r1=341500&r2=341501&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_allocator.h (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_allocator.h Wed Sep 5 16:22:38 2018
@@ -64,14 +64,8 @@ typedef LargeMmapAllocator<HwasanMapUnma
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:
Modified: compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_thread.cc?rev=341501&r1=341500&r2=341501&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_thread.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_thread.cc Wed Sep 5 16:22:38 2018
@@ -114,7 +114,7 @@ void Thread::ClearShadowForThreadStackAn
void Thread::Destroy() {
if (flags()->verbose_threads)
Print("Destroying: ");
- malloc_storage().CommitBack();
+ AllocatorSwallowThreadLocalCache(allocator_cache());
ClearShadowForThreadStackAndTLS();
RemoveFromThreadList(this);
uptr size = RoundUpTo(sizeof(Thread), GetPageSizeCached());
Modified: compiler-rt/trunk/lib/hwasan/hwasan_thread.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_thread.h?rev=341501&r1=341500&r2=341501&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_thread.h (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_thread.h Wed Sep 5 16:22:38 2018
@@ -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);
More information about the llvm-commits
mailing list