[compiler-rt] 94a391b - [scudo] Calling iterateOverChunks requires holding lock
Chia-hung Duan via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 15 15:46:48 PST 2023
Author: Chia-hung Duan
Date: 2023-02-15T23:44:44Z
New Revision: 94a391b94972b68db03320f27ebf2e279051b3e6
URL: https://github.com/llvm/llvm-project/commit/94a391b94972b68db03320f27ebf2e279051b3e6
DIFF: https://github.com/llvm/llvm-project/commit/94a391b94972b68db03320f27ebf2e279051b3e6.diff
LOG: [scudo] Calling iterateOverChunks requires holding lock
Ensure the allocator is disabled before visiting all chunks.
Reviewed By: cferris
Differential Revision: https://reviews.llvm.org/D142157
Added:
Modified:
compiler-rt/lib/scudo/standalone/primary32.h
compiler-rt/lib/scudo/standalone/primary64.h
compiler-rt/lib/scudo/standalone/secondary.h
compiler-rt/lib/scudo/standalone/wrappers_c.inc
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/primary32.h b/compiler-rt/lib/scudo/standalone/primary32.h
index 544f0ee98797..2a204ca40f96 100644
--- a/compiler-rt/lib/scudo/standalone/primary32.h
+++ b/compiler-rt/lib/scudo/standalone/primary32.h
@@ -204,11 +204,14 @@ template <typename Config> class SizeClassAllocator32 {
}
}
- template <typename F>
- void iterateOverBlocks(F Callback) NO_THREAD_SAFETY_ANALYSIS {
+ template <typename F> void iterateOverBlocks(F Callback) {
uptr MinRegionIndex = NumRegions, MaxRegionIndex = 0;
for (uptr I = 0; I < NumClasses; I++) {
SizeClassInfo *Sci = getSizeClassInfo(I);
+ // TODO: The call of `iterateOverBlocks` requires disabling
+ // SizeClassAllocator32. We may consider locking each region on demand
+ // only.
+ Sci->Mutex.assertHeld();
if (Sci->MinRegionIndex < MinRegionIndex)
MinRegionIndex = Sci->MinRegionIndex;
if (Sci->MaxRegionIndex > MaxRegionIndex)
diff --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h
index 1c9c6159f19b..3c53c03a6d19 100644
--- a/compiler-rt/lib/scudo/standalone/primary64.h
+++ b/compiler-rt/lib/scudo/standalone/primary64.h
@@ -226,12 +226,15 @@ template <typename Config> class SizeClassAllocator64 {
}
}
- template <typename F>
- void iterateOverBlocks(F Callback) NO_THREAD_SAFETY_ANALYSIS {
+ template <typename F> void iterateOverBlocks(F Callback) {
for (uptr I = 0; I < NumClasses; I++) {
if (I == SizeClassMap::BatchClassId)
continue;
RegionInfo *Region = getRegionInfo(I);
+ // TODO: The call of `iterateOverBlocks` requires disabling
+ // SizeClassAllocator64. We may consider locking each region on demand
+ // only.
+ Region->Mutex.assertHeld();
const uptr BlockSize = getSizeByClassId(I);
const uptr From = Region->RegionBeg;
const uptr To = From + Region->AllocatedUser;
diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index e98e02094167..3a11c4778862 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -456,8 +456,9 @@ template <typename Config> class MapAllocator {
Mutex.unlock();
}
- template <typename F>
- void iterateOverBlocks(F Callback) const NO_THREAD_SAFETY_ANALYSIS {
+ template <typename F> void iterateOverBlocks(F Callback) const {
+ Mutex.assertHeld();
+
for (const auto &H : InUseBlocks) {
uptr Ptr = reinterpret_cast<uptr>(&H) + LargeBlock::getHeaderSize();
if (allocatorSupportsMemoryTagging<Config>())
diff --git a/compiler-rt/lib/scudo/standalone/wrappers_c.inc b/compiler-rt/lib/scudo/standalone/wrappers_c.inc
index bbe3617dd0d6..6c4f10d2d898 100644
--- a/compiler-rt/lib/scudo/standalone/wrappers_c.inc
+++ b/compiler-rt/lib/scudo/standalone/wrappers_c.inc
@@ -238,7 +238,10 @@ INTERFACE WEAK int SCUDO_PREFIX(malloc_info)(UNUSED int options, FILE *stream) {
if (size < max_size)
sizes[size]++;
};
+
+ SCUDO_ALLOCATOR.disable();
SCUDO_ALLOCATOR.iterateOverChunks(0, -1ul, callback, sizes);
+ SCUDO_ALLOCATOR.enable();
fputs("<malloc version=\"scudo-1\">\n", stream);
for (scudo::uptr i = 0; i != max_size; ++i)
More information about the llvm-commits
mailing list