diff options
author | Kostya Serebryany <kcc@google.com> | 2018-08-31 05:55:18 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2018-08-31 05:55:18 +0000 |
commit | e01a321f594089051c46eb413baa5c2e512a8a32 (patch) | |
tree | 1c88d9a9cd69d3641c6faf3ce1e0c2cfae5153b1 /lib/hwasan | |
parent | c855fffef50b46f9e3c52061a42d7c6f1c59a64d (diff) | |
download | compiler-rt-e01a321f594089051c46eb413baa5c2e512a8a32.tar.gz |
[hwasan] simplify the code, NFC
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@341166 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/hwasan')
-rw-r--r-- | lib/hwasan/hwasan_allocator.cc | 22 | ||||
-rw-r--r-- | lib/hwasan/hwasan_allocator.h | 1 |
2 files changed, 6 insertions, 17 deletions
diff --git a/lib/hwasan/hwasan_allocator.cc b/lib/hwasan/hwasan_allocator.cc index 0c541679b..f6bfabe40 100644 --- a/lib/hwasan/hwasan_allocator.cc +++ b/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<Metadata *>(allocator.GetMetaData(allocated)); - meta->state = CHUNK_ALLOCATED; meta->requested_size = static_cast<u32>(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<Metadata *>(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/lib/hwasan/hwasan_allocator.h b/lib/hwasan/hwasan_allocator.h index b2059d03b..ed265444f 100644 --- a/lib/hwasan/hwasan_allocator.h +++ b/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 |