From bca94773b7423914a3b1321a656edcf5c826dd27 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Fri, 31 Aug 2018 05:55:18 +0000 Subject: [PATCH] [hwasan] simplify the code, NFC llvm-svn: 341166 --- compiler-rt/lib/hwasan/hwasan_allocator.cc | 22 ++++++---------------- compiler-rt/lib/hwasan/hwasan_allocator.h | 1 - 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cc b/compiler-rt/lib/hwasan/hwasan_allocator.cc index 0c54167..f6bfabe 100644 --- a/compiler-rt/lib/hwasan/hwasan_allocator.cc +++ b/compiler-rt/lib/hwasan/hwasan_allocator.cc @@ -28,24 +28,15 @@ namespace __hwasan { -enum { - CHUNK_INVALID = 0, - CHUNK_FREE = 1, - CHUNK_ALLOCATED = 2 -}; - struct Metadata { - u64 state : 2; - u64 requested_size : 31; // sizes are < 4G. - u32 alloc_context_id : 31; + u32 requested_size; // sizes are < 4G. + u32 alloc_context_id; }; -bool HwasanChunkView::IsValid() const { - return metadata_ && metadata_->state != CHUNK_INVALID; -} bool HwasanChunkView::IsAllocated() const { - return metadata_ && metadata_->state == CHUNK_ALLOCATED; + return metadata_ && metadata_->alloc_context_id && metadata_->requested_size; } + uptr HwasanChunkView::Beg() const { return block_; } @@ -151,7 +142,6 @@ static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment, } Metadata *meta = reinterpret_cast(allocator.GetMetaData(allocated)); - meta->state = CHUNK_ALLOCATED; meta->requested_size = static_cast(orig_size); meta->alloc_context_id = StackDepotPut(*stack); if (zeroise) { @@ -191,10 +181,10 @@ void HwasanDeallocate(StackTrace *stack, void *tagged_ptr) { Metadata *meta = reinterpret_cast(allocator.GetMetaData(untagged_ptr)); uptr size = meta->requested_size; - meta->state = CHUNK_FREE; - meta->requested_size = 0; u32 free_context_id = StackDepotPut(*stack); u32 alloc_context_id = meta->alloc_context_id; + meta->requested_size = 0; + meta->alloc_context_id = 0; // This memory will not be reused by anyone else, so we are free to keep it // poisoned. Thread *t = GetCurrentThread(); diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.h b/compiler-rt/lib/hwasan/hwasan_allocator.h index b2059d0..ed26544 100644 --- a/compiler-rt/lib/hwasan/hwasan_allocator.h +++ b/compiler-rt/lib/hwasan/hwasan_allocator.h @@ -36,7 +36,6 @@ class HwasanChunkView { HwasanChunkView() : block_(0), metadata_(nullptr) {} HwasanChunkView(uptr block, Metadata *metadata) : block_(block), metadata_(metadata) {} - bool IsValid() const; // Checks if it points to a valid allocated chunk bool IsAllocated() const; // Checks if the memory is currently allocated uptr Beg() const; // First byte of user memory uptr End() const; // Last byte of user memory -- 2.7.4