[compiler-rt] [scudo] allocation_ring_buffer_size <= 0 disables buffer (PR #71791)

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 02:48:56 PST 2023


https://github.com/fmayer updated https://github.com/llvm/llvm-project/pull/71791

>From 78c1ff55a3d230e87681c2a2dcc64d4184ba0a81 Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer at google.com>
Date: Thu, 9 Nov 2023 02:28:19 -0800
Subject: [PATCH 1/3] allocation_ring_buffer_size <= 0 disables buffer

Prevent a null pointer exception for allocation_ring_buffer_size < 0.
---
 compiler-rt/lib/scudo/standalone/combined.h | 2 +-
 compiler-rt/lib/scudo/standalone/flags.inc  | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index b1700e5ecef7f5b..cb48c8c1e3a1e77 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -886,7 +886,7 @@ class Allocator {
 
   void setTrackAllocationStacks(bool Track) {
     initThreadMaybe();
-    if (getFlags()->allocation_ring_buffer_size == 0) {
+    if (getFlags()->allocation_ring_buffer_size <= 0) {
       DCHECK(!Primary.Options.load().get(OptionBit::TrackAllocationStacks));
       return;
     }
diff --git a/compiler-rt/lib/scudo/standalone/flags.inc b/compiler-rt/lib/scudo/standalone/flags.inc
index 60aeb1f1df570ac..f5a2bab5057ae13 100644
--- a/compiler-rt/lib/scudo/standalone/flags.inc
+++ b/compiler-rt/lib/scudo/standalone/flags.inc
@@ -47,4 +47,5 @@ SCUDO_FLAG(int, release_to_os_interval_ms, SCUDO_ANDROID ? INT32_MIN : 5000,
            "memory to the OS. Negative values disable the feature.")
 
 SCUDO_FLAG(int, allocation_ring_buffer_size, 32768,
-           "Entries to keep in the allocation ring buffer for scudo.")
+           "Entries to keep in the allocation ring buffer for scudo. "
+           "Values less or equal to zero disable the buffer.")

>From cc4fe20d691658d7792eeb9237cbe341179bdcf9 Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer at google.com>
Date: Thu, 9 Nov 2023 02:46:32 -0800
Subject: [PATCH 2/3] consistency

---
 compiler-rt/lib/scudo/standalone/combined.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index cb48c8c1e3a1e77..5391469f7cafcb0 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -886,7 +886,7 @@ class Allocator {
 
   void setTrackAllocationStacks(bool Track) {
     initThreadMaybe();
-    if (getFlags()->allocation_ring_buffer_size <= 0) {
+    if (getFlags()->allocation_ring_buffer_size < 1) {
       DCHECK(!Primary.Options.load().get(OptionBit::TrackAllocationStacks));
       return;
     }

>From 4d68dfd626dd413f5729b764ea51f1e8ad1280fb Mon Sep 17 00:00:00 2001
From: Florian Mayer <fmayer at google.com>
Date: Thu, 9 Nov 2023 02:48:36 -0800
Subject: [PATCH 3/3] fixup

---
 compiler-rt/lib/scudo/standalone/combined.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index 5391469f7cafcb0..3326917e5a3e79c 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -1490,10 +1490,10 @@ class Allocator {
   }
 
   void mapAndInitializeRingBuffer() {
+    if (getFlags()->allocation_ring_buffer_size < 1)
+      return;
     u32 AllocationRingBufferSize =
         static_cast<u32>(getFlags()->allocation_ring_buffer_size);
-    if (AllocationRingBufferSize < 1)
-      return;
     MemMapT MemMap;
     MemMap.map(
         /*Addr=*/0U,



More information about the llvm-commits mailing list