From 9f04550d40b2f259adace54b8fc81c9cdee6f96b Mon Sep 17 00:00:00 2001 From: Jordan R Abrahams-Whitehead Date: Sat, 15 Jun 2024 00:11:11 +0000 Subject: [PATCH] [scudo] Add baseline Scudo config for ChromeOS v2 --- .../lib/scudo/standalone/allocator_config.h | 51 +++++++++++++++++++ compiler-rt/lib/scudo/standalone/platform.h | 6 +++ 2 files changed, 57 insertions(+) diff --git a/compiler-rt/lib/scudo/standalone/allocator_config.h b/compiler-rt/lib/scudo/standalone/allocator_config.h index 3c6aa3acb0e4..a2fe943016ef 100644 --- a/compiler-rt/lib/scudo/standalone/allocator_config.h +++ b/compiler-rt/lib/scudo/standalone/allocator_config.h @@ -204,6 +204,55 @@ struct AndroidConfig { template using SecondaryT = MapAllocator; }; +struct ChromeOSConfig { + static const bool MaySupportMemoryTagging = false; + template + using TSDRegistryT = TSDRegistryExT; // Exclusive + + // TODO: Retune configs with more experimentation. + struct Primary { + using SizeClassMap = DefaultSizeClassMap; +#if SCUDO_CAN_USE_PRIMARY64 + static const uptr RegionSizeLog = 29U; + static const uptr GroupSizeLog = 20U; + typedef uptr CompactPtrT; + static const uptr CompactPtrScale = 0; + static const bool EnableRandomOffset = true; + static const uptr MapSizeIncrement = 1UL << 18; +#else + static const uptr RegionSizeLog = 19U; + static const uptr GroupSizeLog = 19U; + typedef uptr CompactPtrT; +#endif + static const s32 MinReleaseToOsIntervalMs = INT32_MIN; + static const s32 MaxReleaseToOsIntervalMs = INT32_MAX; + }; + +#if SCUDO_CAN_USE_PRIMARY64 + template + using PrimaryT = SizeClassAllocator64; +#else + template + using PrimaryT = SizeClassAllocator32; +#endif + + struct Secondary { + struct Cache { + static const u32 EntriesArraySize = 32U; + static const u32 QuarantineSize = 0U; + static const u32 DefaultMaxEntriesCount = 32U; + static const uptr DefaultMaxEntrySize = 1UL << 19; + static const s32 MinReleaseToOsIntervalMs = INT32_MIN; + static const s32 MaxReleaseToOsIntervalMs = INT32_MAX; + }; + template + using CacheT = MapAllocatorCache; + }; + + template + using SecondaryT = MapAllocator; +}; + #if SCUDO_CAN_USE_PRIMARY64 struct FuchsiaConfig { static const bool MaySupportMemoryTagging = false; @@ -265,6 +314,8 @@ struct TrustyConfig { #if SCUDO_ANDROID typedef AndroidConfig Config; +#elif SCUDO_CHROMEOS +typedef ChromeOSConfig Config; #elif SCUDO_FUCHSIA typedef FuchsiaConfig Config; #elif SCUDO_TRUSTY diff --git a/compiler-rt/lib/scudo/standalone/platform.h b/compiler-rt/lib/scudo/standalone/platform.h index b71a86be7669..b8b0287ef0b1 100644 --- a/compiler-rt/lib/scudo/standalone/platform.h +++ b/compiler-rt/lib/scudo/standalone/platform.h @@ -25,6 +25,12 @@ #define SCUDO_ANDROID 0 #endif +#if defined(USE_CHROMEOS_CONFIG) +#define SCUDO_CHROMEOS 1 +#else +#define SCUDO_CHROMEOS 0 +#endif + #if defined(__Fuchsia__) #define SCUDO_FUCHSIA 1 #else -- 2.45.2.627.g7a2c4fd464-goog