[compiler-rt] [scudo] Add config option to modify get usable size behavior (PR #158710)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 23 00:20:53 PDT 2025


================
@@ -759,6 +764,22 @@ class Allocator {
     return false;
   }
 
+  ALWAYS_INLINE uptr getUsableSize(const void *Ptr,
+                                   Chunk::UnpackedHeader *Header) {
+    void *BlockBegin = getBlockBegin(Ptr, Header);
+    if (LIKELY(Header->ClassId)) {
+      return SizeClassMap::getSizeByClassId(Header->ClassId) -
+             (reinterpret_cast<uptr>(Ptr) - reinterpret_cast<uptr>(BlockBegin));
+    }
+
+    uptr UntaggedPtr = reinterpret_cast<uptr>(Ptr);
+    if (allocatorSupportsMemoryTagging<AllocatorConfig>()) {
+      UntaggedPtr = untagPointer(UntaggedPtr);
+      BlockBegin = untagPointer(BlockBegin);
+    }
+    return SecondaryT::getBlockEnd(BlockBegin) - UntaggedPtr;
+  }
+
   // Return the usable size for a given chunk. Technically we lie, as we just
----------------
ChiaHungDuan wrote:

Maybe we also want to revise the comment a little bit?

https://github.com/llvm/llvm-project/pull/158710


More information about the llvm-commits mailing list