[compiler-rt] [scudo] [MTE] resize stack depot for allocation ring buffer (PR #74515)

Florian Mayer via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 23 16:03:41 PST 2024


================
@@ -1504,6 +1529,28 @@ class Allocator {
       return;
     u32 AllocationRingBufferSize =
         static_cast<u32>(getFlags()->allocation_ring_buffer_size);
+    // We store alloc and free stacks for each entry.
+    constexpr auto kStacksPerRingBufferEntry = 2;
+    u32 TabSize = static_cast<u32>(roundUpPowerOfTwo(kStacksPerRingBufferEntry *
+                                                     AllocationRingBufferSize));
+    constexpr auto kFramesPerStack = 8;
+    static_assert(isPowerOfTwo(kFramesPerStack));
+    u32 RingSize = static_cast<u32>(TabSize * kFramesPerStack);
+    DCHECK(isPowerOfTwo(RingSize));
+    static_assert(sizeof(StackDepot) % alignof(atomic_u64) == 0);
+
+    StackDepotSize = sizeof(StackDepot) + sizeof(atomic_u64) * RingSize +
+                     sizeof(atomic_u32) * TabSize;
+    MemMapT DepotMap;
+    DepotMap.map(
+        /*Addr=*/0U, roundUp(StackDepotSize, getPageSizeCached()),
+        "scudo:stack_depot");
+    RawStackDepot = reinterpret_cast<char *>(DepotMap.getBase());
+    auto *Depot = reinterpret_cast<StackDepot *>(DepotMap.getBase());
+    Depot->init(RingSize, TabSize);
+    DCHECK(Depot->isValid(StackDepotSize));
----------------
fmayer wrote:

I thought I replied to this, not sure if GitHub problem or I actually didn't:

I don't understand the problem with adding this DCHECK. This makes sure that the logic for `isValid` and for `init` are consistent, which is a good thing to check in debug builds. If it fails it's always something wrong with the code of either of them, because it should not fail by construction of the code.

> I don't need to verify if std::vector<int>(4, 0) gives me 4 elements and all of them are zero.

I don't think that's a correct analogy. If I was the implementer of std::vector then I might want to add some debug checks about the internal state of std::vector.

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


More information about the llvm-commits mailing list