[compiler-rt] r341166 - [hwasan] simplify the code, NFC

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 30 22:55:19 PDT 2018


Author: kcc
Date: Thu Aug 30 22:55:18 2018
New Revision: 341166

URL: http://llvm.org/viewvc/llvm-project?rev=341166&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

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=341166&r1=341165&r2=341166&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_allocator.cc Thu Aug 30 22:55:18 2018
@@ -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 *
   }
   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,
   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();

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=341166&r1=341165&r2=341166&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_allocator.h (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_allocator.h Thu Aug 30 22:55:18 2018
@@ -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




More information about the llvm-commits mailing list