[compiler-rt] 849da03 - [scudo] Shuffle the regions
Chia-hung Duan via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 8 14:59:23 PST 2023
Author: Chia-hung Duan
Date: 2023-03-08T22:58:08Z
New Revision: 849da03202530601c1c7d6a284e905b1ba6a4485
URL: https://github.com/llvm/llvm-project/commit/849da03202530601c1c7d6a284e905b1ba6a4485
DIFF: https://github.com/llvm/llvm-project/commit/849da03202530601c1c7d6a284e905b1ba6a4485.diff
LOG: [scudo] Shuffle the regions
Shuffle the regions' base address so that the layout of all regions is
less predictable.
Reviewed By: cferris, cryptoad
Differential Revision: https://reviews.llvm.org/D145407
Added:
Modified:
compiler-rt/lib/scudo/standalone/primary64.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/primary64.h b/compiler-rt/lib/scudo/standalone/primary64.h
index 3df8749898484..7868111bfc5c2 100644
--- a/compiler-rt/lib/scudo/standalone/primary64.h
+++ b/compiler-rt/lib/scudo/standalone/primary64.h
@@ -65,6 +65,7 @@ template <typename Config> class SizeClassAllocator64 {
void init(s32 ReleaseToOsInterval) NO_THREAD_SAFETY_ANALYSIS {
DCHECK(isAligned(reinterpret_cast<uptr>(this), alignof(ThisT)));
DCHECK_EQ(PrimaryBase, 0U);
+
// Reserve the space required for the Primary.
PrimaryBase = reinterpret_cast<uptr>(map(
nullptr, PrimarySize, "scudo:primary_reserve", MAP_NOACCESS, &Data));
@@ -78,13 +79,15 @@ template <typename Config> class SizeClassAllocator64 {
RegionInfo *Region = getRegionInfo(I);
// The actual start of a region is offset by a random number of pages
// when PrimaryEnableRandomOffset is set.
- Region->RegionBeg = getRegionBaseByClassId(I) +
+ Region->RegionBeg = (PrimaryBase + (I << Config::PrimaryRegionSizeLog)) +
(Config::PrimaryEnableRandomOffset
? ((getRandomModN(&Seed, 16) + 1) * PageSize)
: 0);
Region->RandState = getRandomU32(&Seed);
Region->ReleaseInfo.LastReleaseAtNs = Time;
}
+ shuffle(RegionInfoArray, NumClasses, &Seed);
+
setOption(Option::ReleaseInterval, static_cast<sptr>(ReleaseToOsInterval));
}
@@ -420,8 +423,10 @@ template <typename Config> class SizeClassAllocator64 {
return &RegionInfoArray[ClassId];
}
- uptr getRegionBaseByClassId(uptr ClassId) const {
- return PrimaryBase + (ClassId << Config::PrimaryRegionSizeLog);
+ uptr getRegionBaseByClassId(uptr ClassId) {
+ return roundDown(getRegionInfo(ClassId)->RegionBeg - PrimaryBase,
+ RegionSize) +
+ PrimaryBase;
}
static CompactPtrT compactPtrInternal(uptr Base, uptr Ptr) {
More information about the llvm-commits
mailing list