1 //===-- allocator_config.h --------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef SCUDO_ALLOCATOR_CONFIG_H_ 10 #define SCUDO_ALLOCATOR_CONFIG_H_ 11 12 #include "combined.h" 13 #include "common.h" 14 #include "flags.h" 15 #include "primary32.h" 16 #include "primary64.h" 17 #include "secondary.h" 18 #include "size_class_map.h" 19 #include "tsd_exclusive.h" 20 #include "tsd_shared.h" 21 22 namespace scudo { 23 24 // Default configurations for various platforms. 25 26 struct DefaultConfig { 27 using SizeClassMap = DefaultSizeClassMap; 28 static const bool MaySupportMemoryTagging = false; 29 30 #if SCUDO_CAN_USE_PRIMARY64 31 typedef SizeClassAllocator64<DefaultConfig> Primary; 32 static const uptr PrimaryRegionSizeLog = 30U; 33 #else 34 typedef SizeClassAllocator32<DefaultConfig> Primary; 35 static const uptr PrimaryRegionSizeLog = 19U; 36 #endif 37 static const s32 PrimaryMinReleaseToOsIntervalMs = INT32_MIN; 38 static const s32 PrimaryMaxReleaseToOsIntervalMs = INT32_MAX; 39 40 typedef MapAllocatorCache<DefaultConfig> SecondaryCache; 41 static const u32 SecondaryCacheEntriesArraySize = 32U; 42 static const u32 SecondaryCacheDefaultMaxEntriesCount = 32U; 43 static const uptr SecondaryCacheDefaultMaxEntrySize = 1UL << 19; 44 static const s32 SecondaryCacheMinReleaseToOsIntervalMs = INT32_MIN; 45 static const s32 SecondaryCacheMaxReleaseToOsIntervalMs = INT32_MAX; 46 47 template <class A> using TSDRegistryT = TSDRegistryExT<A>; // Exclusive 48 }; 49 50 struct AndroidConfig { 51 using SizeClassMap = AndroidSizeClassMap; 52 static const bool MaySupportMemoryTagging = true; 53 54 #if SCUDO_CAN_USE_PRIMARY64 55 typedef SizeClassAllocator64<AndroidConfig> Primary; 56 static const uptr PrimaryRegionSizeLog = 28U; 57 #else 58 typedef SizeClassAllocator32<AndroidConfig> Primary; 59 static const uptr PrimaryRegionSizeLog = 18U; 60 #endif 61 static const s32 PrimaryMinReleaseToOsIntervalMs = 1000; 62 static const s32 PrimaryMaxReleaseToOsIntervalMs = 1000; 63 64 typedef MapAllocatorCache<AndroidConfig> SecondaryCache; 65 static const u32 SecondaryCacheEntriesArraySize = 256U; 66 static const u32 SecondaryCacheDefaultMaxEntriesCount = 32U; 67 static const uptr SecondaryCacheDefaultMaxEntrySize = 2UL << 20; 68 static const s32 SecondaryCacheMinReleaseToOsIntervalMs = 0; 69 static const s32 SecondaryCacheMaxReleaseToOsIntervalMs = 1000; 70 71 template <class A> 72 using TSDRegistryT = TSDRegistrySharedT<A, 8U, 2U>; // Shared, max 8 TSDs. 73 }; 74 75 struct AndroidSvelteConfig { 76 using SizeClassMap = SvelteSizeClassMap; 77 static const bool MaySupportMemoryTagging = false; 78 79 #if SCUDO_CAN_USE_PRIMARY64 80 typedef SizeClassAllocator64<AndroidSvelteConfig> Primary; 81 static const uptr PrimaryRegionSizeLog = 27U; 82 #else 83 typedef SizeClassAllocator32<AndroidSvelteConfig> Primary; 84 static const uptr PrimaryRegionSizeLog = 16U; 85 #endif 86 static const s32 PrimaryMinReleaseToOsIntervalMs = 1000; 87 static const s32 PrimaryMaxReleaseToOsIntervalMs = 1000; 88 89 typedef MapAllocatorCache<AndroidSvelteConfig> SecondaryCache; 90 static const u32 SecondaryCacheEntriesArraySize = 16U; 91 static const u32 SecondaryCacheDefaultMaxEntriesCount = 4U; 92 static const uptr SecondaryCacheDefaultMaxEntrySize = 1UL << 18; 93 static const s32 SecondaryCacheMinReleaseToOsIntervalMs = 0; 94 static const s32 SecondaryCacheMaxReleaseToOsIntervalMs = 0; 95 96 template <class A> 97 using TSDRegistryT = TSDRegistrySharedT<A, 2U, 1U>; // Shared, max 2 TSDs. 98 }; 99 100 #if SCUDO_CAN_USE_PRIMARY64 101 struct FuchsiaConfig { 102 using SizeClassMap = DefaultSizeClassMap; 103 static const bool MaySupportMemoryTagging = false; 104 105 typedef SizeClassAllocator64<FuchsiaConfig> Primary; 106 static const uptr PrimaryRegionSizeLog = 30U; 107 static const s32 PrimaryMinReleaseToOsIntervalMs = INT32_MIN; 108 static const s32 PrimaryMaxReleaseToOsIntervalMs = INT32_MAX; 109 110 typedef MapAllocatorNoCache SecondaryCache; 111 template <class A> 112 using TSDRegistryT = TSDRegistrySharedT<A, 8U, 4U>; // Shared, max 8 TSDs. 113 }; 114 #endif 115 116 #if SCUDO_ANDROID 117 typedef AndroidConfig Config; 118 #elif SCUDO_FUCHSIA 119 typedef FuchsiaConfig Config; 120 #else 121 typedef DefaultConfig Config; 122 #endif 123 124 } // namespace scudo 125 126 #endif // SCUDO_ALLOCATOR_CONFIG_H_ 127