[compiler-rt] [scudo] Allow to resize allocation ring buffer (PR #82683)

via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 11 17:39:24 PDT 2024


================
@@ -1594,12 +1600,33 @@ class Allocator {
     RB->StackDepotSize = StackDepotSize;
     RB->RawStackDepotMap = DepotMap;
 
-    atomic_store(&RingBufferAddress, reinterpret_cast<uptr>(RB),
-                 memory_order_release);
+    swapOutRingBuffer(RB);
     static_assert(sizeof(AllocationRingBuffer) %
                           alignof(typename AllocationRingBuffer::Entry) ==
                       0,
                   "invalid alignment");
+    return true;
+  }
+
+  void swapOutRingBuffer(AllocationRingBuffer *NewRB) {
+    // To allow resizeRingBuffer to be called in a multi-threaded context by apps,
+    // we do not actually unmap, but only madvise(DONTNEED) the pages. That way,
+    // straggler threads will not crash.
----------------
ChiaHungDuan wrote:

I would think something like for apps don't need to change the buffer size, they adopt the default behavior. Otherwise, they need to set the buffer size and call `malloc_set_track_allocation_stacks` themselves.

Before the app starts, I think there some places we can call `malloc_set_track_allocation_stacks` and maybe we can read the `AndroidManifest.xml` to determine if we want to change the default ring buffer size (Sorry I'm not familiar with app, not sure if AndroidManifest.xml can be used for this purpose)

We need some changes for native processes as well (like a different place to call `malloc_set_track_allocation_stacks`)

Overall, I would guess it's still doable but may require some additional works in Android. I can ask around to see other's opinions.

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


More information about the llvm-commits mailing list