diff --git a/compiler-rt/lib/scudo/standalone/allocator_config.h b/compiler-rt/lib/scudo/standalone/allocator_config.h --- a/compiler-rt/lib/scudo/standalone/allocator_config.h +++ b/compiler-rt/lib/scudo/standalone/allocator_config.h @@ -140,7 +140,7 @@ #if SCUDO_CAN_USE_PRIMARY64 struct FuchsiaConfig { - using SizeClassMap = DefaultSizeClassMap; + using SizeClassMap = FuchsiaSizeClassMap; static const bool MaySupportMemoryTagging = false; typedef SizeClassAllocator64 Primary; diff --git a/compiler-rt/lib/scudo/standalone/size_class_map.h b/compiler-rt/lib/scudo/standalone/size_class_map.h --- a/compiler-rt/lib/scudo/standalone/size_class_map.h +++ b/compiler-rt/lib/scudo/standalone/size_class_map.h @@ -64,12 +64,10 @@ static const u8 S = Config::NumBits - 1; static const uptr M = (1UL << S) - 1; - static const uptr SizeDelta = Chunk::getHeaderSize(); - public: static const u32 MaxNumCachedHint = Config::MaxNumCachedHint; - static const uptr MaxSize = (1UL << Config::MaxSizeLog) + SizeDelta; + static const uptr MaxSize = (1UL << Config::MaxSizeLog) + Config::SizeDelta; static const uptr NumClasses = MidClass + ((Config::MaxSizeLog - Config::MidSizeLog) << S) + 1; static_assert(NumClasses <= 256, ""); @@ -79,24 +77,22 @@ static uptr getSizeByClassId(uptr ClassId) { DCHECK_NE(ClassId, BatchClassId); if (ClassId <= MidClass) - return (ClassId << Config::MinSizeLog) + SizeDelta; + return (ClassId << Config::MinSizeLog) + Config::SizeDelta; ClassId -= MidClass; const uptr T = MidSize << (ClassId >> S); - return T + (T >> S) * (ClassId & M) + SizeDelta; + return T + (T >> S) * (ClassId & M) + Config::SizeDelta; } static u8 getSizeLSBByClassId(uptr ClassId) { return u8(getLeastSignificantSetBitIndex(getSizeByClassId(ClassId))); } - static constexpr bool usesCompressedLSBFormat() { - return false; - } + static constexpr bool usesCompressedLSBFormat() { return false; } static uptr getClassIdBySize(uptr Size) { - if (Size <= SizeDelta + (1 << Config::MinSizeLog)) + if (Size <= Config::SizeDelta + (1 << Config::MinSizeLog)) return 1; - Size -= SizeDelta; + Size -= Config::SizeDelta; DCHECK_LE(Size, MaxSize); if (Size <= MidSize) return (Size + MinSize - 1) >> Config::MinSizeLog; @@ -223,15 +219,27 @@ }; struct DefaultSizeClassConfig { + static const uptr NumBits = 3; + static const uptr MinSizeLog = 5; + static const uptr MidSizeLog = 8; + static const uptr MaxSizeLog = 17; + static const u32 MaxNumCachedHint = 14; + static const uptr MaxBytesCachedLog = 10; + static const uptr SizeDelta = 0; +}; + +struct FuchsiaSizeClassConfig { static const uptr NumBits = 3; static const uptr MinSizeLog = 5; static const uptr MidSizeLog = 8; static const uptr MaxSizeLog = 17; static const u32 MaxNumCachedHint = 10; static const uptr MaxBytesCachedLog = 10; + static const uptr SizeDelta = Chunk::getHeaderSize(); }; typedef FixedSizeClassMap DefaultSizeClassMap; +typedef FixedSizeClassMap FuchsiaSizeClassMap; struct AndroidSizeClassConfig { #if SCUDO_WORDSIZE == 64U @@ -285,6 +293,7 @@ static const uptr MaxSizeLog = 14; static const u32 MaxNumCachedHint = 13; static const uptr MaxBytesCachedLog = 10; + static const uptr SizeDelta = Chunk::getHeaderSize(); #else static const uptr NumBits = 4; static const uptr MinSizeLog = 3; @@ -292,6 +301,7 @@ static const uptr MaxSizeLog = 14; static const u32 MaxNumCachedHint = 14; static const uptr MaxBytesCachedLog = 10; + static const uptr SizeDelta = Chunk::getHeaderSize(); #endif }; diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp @@ -497,6 +497,7 @@ static const scudo::uptr MaxSizeLog = 13; static const scudo::u32 MaxNumCachedHint = 4; static const scudo::uptr MaxBytesCachedLog = 12; + static const scudo::uptr SizeDelta = 0; }; static const scudo::uptr DeathRegionSizeLog = 20U; diff --git a/compiler-rt/lib/scudo/standalone/tests/size_class_map_test.cpp b/compiler-rt/lib/scudo/standalone/tests/size_class_map_test.cpp --- a/compiler-rt/lib/scudo/standalone/tests/size_class_map_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/size_class_map_test.cpp @@ -35,6 +35,7 @@ static const scudo::uptr MaxSizeLog = 5; static const scudo::u32 MaxNumCachedHint = 0; static const scudo::uptr MaxBytesCachedLog = 0; + static const scudo::uptr SizeDelta = 0; }; TEST(ScudoSizeClassMapTest, OneClassSizeClassMap) { @@ -49,6 +50,7 @@ static const scudo::uptr MaxSizeLog = 63; static const scudo::u32 MaxNumCachedHint = 128; static const scudo::uptr MaxBytesCachedLog = 16; + static const scudo::uptr SizeDelta = 0; }; TEST(ScudoSizeClassMapTest, LargeMaxSizeClassMap) {