[compiler-rt] [scudo] Handle failed mmap for allocation ring buffer (PR #71817)

via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 07:41:01 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Florian Mayer (fmayer)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/71817.diff


1 Files Affected:

- (modified) compiler-rt/lib/scudo/standalone/combined.h (+9-2) 


``````````diff
diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index b1700e5ecef7f5b..088e27eeb4c7439 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -1281,7 +1281,8 @@ class Allocator {
 
   void storeSecondaryAllocationStackMaybe(const Options &Options, void *Ptr,
                                           uptr Size) {
-    if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)))
+    if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)) ||
+        RawRingBuffer == nullptr)
       return;
 
     u32 Trace = collectStackTrace();
@@ -1296,7 +1297,8 @@ class Allocator {
 
   void storeDeallocationStackMaybe(const Options &Options, void *Ptr,
                                    u8 PrevTag, uptr Size) {
-    if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)))
+    if (!UNLIKELY(Options.get(OptionBit::TrackAllocationStacks)) ||
+        RawRingBuffer == nullptr)
       return;
 
     auto *Ptr32 = reinterpret_cast<u32 *>(Ptr);
@@ -1501,6 +1503,11 @@ class Allocator {
                 getPageSizeCached()),
         "scudo:ring_buffer");
     RawRingBuffer = reinterpret_cast<char *>(MemMap.getBase());
+    if (RawRingBuffer == nullptr) {
+      Printf("Failed to allocate allocation ring buffer of size %d",
+             getFlags()->allocation_ring_buffer_size);
+      return;
+    }
     auto *RingBuffer = reinterpret_cast<AllocationRingBuffer *>(RawRingBuffer);
     RingBuffer->MemMap = MemMap;
     RingBuffer->Size = AllocationRingBufferSize;

``````````

</details>


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


More information about the llvm-commits mailing list