[PATCH] D94207: [NFC] Refactor `IgnoreObjectLocked`

Dan Liew via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 6 17:38:45 PST 2021


delcypher created this revision.
delcypher added reviewers: kubamracek, yln, kcc, dvyukov, eugenis, vitalybuka, cryptoad, earthdok.
delcypher requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.

This refactors the chunk look up code into a static inlined function
called `LookUpValidChunk()`.

This is in preparation for introducing functions that are the inverse
of the `IgnoreObjectLocked()` functions. These will be added in
a subsequent patch.

rdar://problem/63537240


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94207

Files:
  compiler-rt/lib/asan/asan_allocator.cpp
  compiler-rt/lib/lsan/lsan_allocator.cpp


Index: compiler-rt/lib/lsan/lsan_allocator.cpp
===================================================================
--- compiler-rt/lib/lsan/lsan_allocator.cpp
+++ compiler-rt/lib/lsan/lsan_allocator.cpp
@@ -295,19 +295,26 @@
   allocator.ForEachChunk(callback, arg);
 }
 
-IgnoreObjectResult IgnoreObjectLocked(const void *p) {
+static ALWAYS_INLINE ChunkMetadata *LookUpValidChunk(const void *p) {
   void *chunk = allocator.GetBlockBegin(p);
-  if (!chunk || p < chunk) return kIgnoreObjectInvalid;
+  if (!chunk || p < chunk)
+    return nullptr;
   ChunkMetadata *m = Metadata(chunk);
   CHECK(m);
   if (m->allocated && (uptr)p < (uptr)chunk + m->requested_size) {
-    if (m->tag == kIgnored)
-      return kIgnoreObjectAlreadyIgnored;
-    m->tag = kIgnored;
-    return kIgnoreObjectSuccess;
-  } else {
-    return kIgnoreObjectInvalid;
+    return m;
   }
+  return nullptr;
+}
+
+IgnoreObjectResult IgnoreObjectLocked(const void *p) {
+  ChunkMetadata *m = LookUpValidChunk(p);
+  if (!m)
+    return kIgnoreObjectInvalid;
+  if (m->tag == kIgnored)
+    return kIgnoreObjectAlreadyIgnored;
+  m->tag = kIgnored;
+  return kIgnoreObjectSuccess;
 }
 } // namespace __lsan
 
Index: compiler-rt/lib/asan/asan_allocator.cpp
===================================================================
--- compiler-rt/lib/asan/asan_allocator.cpp
+++ compiler-rt/lib/asan/asan_allocator.cpp
@@ -1169,15 +1169,22 @@
   __asan::get_allocator().ForEachChunk(callback, arg);
 }
 
-IgnoreObjectResult IgnoreObjectLocked(const void *p) {
+static ALWAYS_INLINE __asan::AsanChunk *LookUpValidChunk(const void *p) {
   uptr addr = reinterpret_cast<uptr>(p);
   __asan::AsanChunk *m = __asan::instance.GetAsanChunkByAddr(addr);
   if (!m ||
       (atomic_load(&m->chunk_state, memory_order_acquire) !=
        __asan::CHUNK_ALLOCATED) ||
       !m->AddrIsInside(addr)) {
-    return kIgnoreObjectInvalid;
+    return nullptr;
   }
+  return m;
+}
+
+IgnoreObjectResult IgnoreObjectLocked(const void *p) {
+  __asan::AsanChunk *m = LookUpValidChunk(p);
+  if (!m)
+    return kIgnoreObjectInvalid;
   if (m->lsan_tag == kIgnored)
     return kIgnoreObjectAlreadyIgnored;
   m->lsan_tag = __lsan::kIgnored;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94207.315030.patch
Type: text/x-patch
Size: 2192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210107/6445dcc4/attachment.bin>


More information about the llvm-commits mailing list