Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 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" |
Dynamic Tools Team | d29271f | 2019-10-31 10:31:49 -0700 | [diff] [blame] | 17 | #include "secondary.h" |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 18 | #include "size_class_map.h" |
| 19 | #include "tsd_exclusive.h" |
| 20 | #include "tsd_shared.h" |
| 21 | |
| 22 | namespace scudo { |
| 23 | |
Kostya Kortchinsky | c936954 | 2021-02-10 10:17:18 -0800 | [diff] [blame^] | 24 | // The combined allocator uses a structure as a template argument that |
| 25 | // specifies the configuration options for the various subcomponents of the |
| 26 | // allocator. |
| 27 | // |
| 28 | // struct ExampleConfig { |
| 29 | // // SizeClasMmap to use with the Primary. |
| 30 | // using SizeClassMap = DefaultSizeClassMap; |
| 31 | // // Indicates possible support for Memory Tagging. |
| 32 | // static const bool MaySupportMemoryTagging = false; |
| 33 | // // Defines the Primary allocator to use. |
| 34 | // typedef SizeClassAllocator64<ExampleConfig> Primary; |
| 35 | // // Log2 of the size of a size class region, as used by the Primary. |
| 36 | // static const uptr PrimaryRegionSizeLog = 30U; |
| 37 | // // Defines the type and scale of a compact pointer. A compact pointer can |
| 38 | // // be understood as the offset of a pointer within the region it belongs |
| 39 | // // to, in increments of a power-of-2 scale. |
| 40 | // // eg: Ptr = Base + (CompactPtr << Scale). |
| 41 | // typedef u32 PrimaryCompactPtrT; |
| 42 | // static const uptr PrimaryCompactPtrScale = SCUDO_MIN_ALIGNMENT_LOG; |
| 43 | // // Defines the minimal & maximal release interval that can be set. |
| 44 | // static const s32 PrimaryMinReleaseToOsIntervalMs = INT32_MIN; |
| 45 | // static const s32 PrimaryMaxReleaseToOsIntervalMs = INT32_MAX; |
| 46 | // // Defines the type of cache used by the Secondary. Some additional |
| 47 | // // configuration entries can be necessary depending on the Cache. |
| 48 | // typedef MapAllocatorNoCache SecondaryCache; |
| 49 | // // Thread-Specific Data Registry used, shared or exclusive. |
| 50 | // template <class A> using TSDRegistryT = TSDRegistrySharedT<A, 8U, 4U>; |
| 51 | // }; |
| 52 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 53 | // Default configurations for various platforms. |
| 54 | |
| 55 | struct DefaultConfig { |
| 56 | using SizeClassMap = DefaultSizeClassMap; |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 57 | static const bool MaySupportMemoryTagging = false; |
| 58 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 59 | #if SCUDO_CAN_USE_PRIMARY64 |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 60 | typedef SizeClassAllocator64<DefaultConfig> Primary; |
Kostya Kortchinsky | c936954 | 2021-02-10 10:17:18 -0800 | [diff] [blame^] | 61 | static const uptr PrimaryRegionSizeLog = 32U; |
| 62 | typedef uptr PrimaryCompactPtrT; |
| 63 | static const uptr PrimaryCompactPtrScale = 0; |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 64 | #else |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 65 | typedef SizeClassAllocator32<DefaultConfig> Primary; |
| 66 | static const uptr PrimaryRegionSizeLog = 19U; |
Kostya Kortchinsky | c936954 | 2021-02-10 10:17:18 -0800 | [diff] [blame^] | 67 | typedef uptr PrimaryCompactPtrT; |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 68 | #endif |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 69 | static const s32 PrimaryMinReleaseToOsIntervalMs = INT32_MIN; |
| 70 | static const s32 PrimaryMaxReleaseToOsIntervalMs = INT32_MAX; |
| 71 | |
Peter Collingbourne | 7488a17 | 2020-12-14 13:57:59 -0800 | [diff] [blame] | 72 | typedef MapAllocatorCache<DefaultConfig> SecondaryCache; |
| 73 | static const u32 SecondaryCacheEntriesArraySize = 32U; |
Peter Collingbourne | 3f9de81 | 2020-12-21 18:39:03 -0800 | [diff] [blame] | 74 | static const u32 SecondaryCacheQuarantineSize = 0U; |
Peter Collingbourne | 7488a17 | 2020-12-14 13:57:59 -0800 | [diff] [blame] | 75 | static const u32 SecondaryCacheDefaultMaxEntriesCount = 32U; |
| 76 | static const uptr SecondaryCacheDefaultMaxEntrySize = 1UL << 19; |
| 77 | static const s32 SecondaryCacheMinReleaseToOsIntervalMs = INT32_MIN; |
| 78 | static const s32 SecondaryCacheMaxReleaseToOsIntervalMs = INT32_MAX; |
| 79 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 80 | template <class A> using TSDRegistryT = TSDRegistryExT<A>; // Exclusive |
| 81 | }; |
| 82 | |
| 83 | struct AndroidConfig { |
| 84 | using SizeClassMap = AndroidSizeClassMap; |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 85 | static const bool MaySupportMemoryTagging = true; |
| 86 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 87 | #if SCUDO_CAN_USE_PRIMARY64 |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 88 | typedef SizeClassAllocator64<AndroidConfig> Primary; |
| 89 | static const uptr PrimaryRegionSizeLog = 28U; |
Kostya Kortchinsky | c936954 | 2021-02-10 10:17:18 -0800 | [diff] [blame^] | 90 | typedef u32 PrimaryCompactPtrT; |
| 91 | static const uptr PrimaryCompactPtrScale = SCUDO_MIN_ALIGNMENT_LOG; |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 92 | #else |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 93 | typedef SizeClassAllocator32<AndroidConfig> Primary; |
| 94 | static const uptr PrimaryRegionSizeLog = 18U; |
Kostya Kortchinsky | c936954 | 2021-02-10 10:17:18 -0800 | [diff] [blame^] | 95 | typedef uptr PrimaryCompactPtrT; |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 96 | #endif |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 97 | static const s32 PrimaryMinReleaseToOsIntervalMs = 1000; |
| 98 | static const s32 PrimaryMaxReleaseToOsIntervalMs = 1000; |
| 99 | |
Peter Collingbourne | 7488a17 | 2020-12-14 13:57:59 -0800 | [diff] [blame] | 100 | typedef MapAllocatorCache<AndroidConfig> SecondaryCache; |
| 101 | static const u32 SecondaryCacheEntriesArraySize = 256U; |
Peter Collingbourne | 3f9de81 | 2020-12-21 18:39:03 -0800 | [diff] [blame] | 102 | static const u32 SecondaryCacheQuarantineSize = 32U; |
Peter Collingbourne | 7488a17 | 2020-12-14 13:57:59 -0800 | [diff] [blame] | 103 | static const u32 SecondaryCacheDefaultMaxEntriesCount = 32U; |
| 104 | static const uptr SecondaryCacheDefaultMaxEntrySize = 2UL << 20; |
| 105 | static const s32 SecondaryCacheMinReleaseToOsIntervalMs = 0; |
| 106 | static const s32 SecondaryCacheMaxReleaseToOsIntervalMs = 1000; |
| 107 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 108 | template <class A> |
Kostya Kortchinsky | c72ca56 | 2020-07-27 09:13:42 -0700 | [diff] [blame] | 109 | using TSDRegistryT = TSDRegistrySharedT<A, 8U, 2U>; // Shared, max 8 TSDs. |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | struct AndroidSvelteConfig { |
| 113 | using SizeClassMap = SvelteSizeClassMap; |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 114 | static const bool MaySupportMemoryTagging = false; |
| 115 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 116 | #if SCUDO_CAN_USE_PRIMARY64 |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 117 | typedef SizeClassAllocator64<AndroidSvelteConfig> Primary; |
| 118 | static const uptr PrimaryRegionSizeLog = 27U; |
Kostya Kortchinsky | c936954 | 2021-02-10 10:17:18 -0800 | [diff] [blame^] | 119 | typedef u32 PrimaryCompactPtrT; |
| 120 | static const uptr PrimaryCompactPtrScale = SCUDO_MIN_ALIGNMENT_LOG; |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 121 | #else |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 122 | typedef SizeClassAllocator32<AndroidSvelteConfig> Primary; |
| 123 | static const uptr PrimaryRegionSizeLog = 16U; |
Kostya Kortchinsky | c936954 | 2021-02-10 10:17:18 -0800 | [diff] [blame^] | 124 | typedef uptr PrimaryCompactPtrT; |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 125 | #endif |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 126 | static const s32 PrimaryMinReleaseToOsIntervalMs = 1000; |
| 127 | static const s32 PrimaryMaxReleaseToOsIntervalMs = 1000; |
| 128 | |
Peter Collingbourne | 7488a17 | 2020-12-14 13:57:59 -0800 | [diff] [blame] | 129 | typedef MapAllocatorCache<AndroidSvelteConfig> SecondaryCache; |
| 130 | static const u32 SecondaryCacheEntriesArraySize = 16U; |
Peter Collingbourne | 3f9de81 | 2020-12-21 18:39:03 -0800 | [diff] [blame] | 131 | static const u32 SecondaryCacheQuarantineSize = 32U; |
Peter Collingbourne | 7488a17 | 2020-12-14 13:57:59 -0800 | [diff] [blame] | 132 | static const u32 SecondaryCacheDefaultMaxEntriesCount = 4U; |
| 133 | static const uptr SecondaryCacheDefaultMaxEntrySize = 1UL << 18; |
| 134 | static const s32 SecondaryCacheMinReleaseToOsIntervalMs = 0; |
| 135 | static const s32 SecondaryCacheMaxReleaseToOsIntervalMs = 0; |
| 136 | |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 137 | template <class A> |
Kostya Kortchinsky | c72ca56 | 2020-07-27 09:13:42 -0700 | [diff] [blame] | 138 | using TSDRegistryT = TSDRegistrySharedT<A, 2U, 1U>; // Shared, max 2 TSDs. |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
Dynamic Tools Team | c910695 | 2019-12-13 09:43:51 -0800 | [diff] [blame] | 141 | #if SCUDO_CAN_USE_PRIMARY64 |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 142 | struct FuchsiaConfig { |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 143 | using SizeClassMap = DefaultSizeClassMap; |
| 144 | static const bool MaySupportMemoryTagging = false; |
| 145 | |
| 146 | typedef SizeClassAllocator64<FuchsiaConfig> Primary; |
| 147 | static const uptr PrimaryRegionSizeLog = 30U; |
Kostya Kortchinsky | c936954 | 2021-02-10 10:17:18 -0800 | [diff] [blame^] | 148 | typedef u32 PrimaryCompactPtrT; |
| 149 | static const uptr PrimaryCompactPtrScale = SCUDO_MIN_ALIGNMENT_LOG; |
Peter Collingbourne | 6be4919 | 2020-12-15 14:26:10 -0800 | [diff] [blame] | 150 | static const s32 PrimaryMinReleaseToOsIntervalMs = INT32_MIN; |
| 151 | static const s32 PrimaryMaxReleaseToOsIntervalMs = INT32_MAX; |
| 152 | |
Peter Collingbourne | 7488a17 | 2020-12-14 13:57:59 -0800 | [diff] [blame] | 153 | typedef MapAllocatorNoCache SecondaryCache; |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 154 | template <class A> |
Kostya Kortchinsky | c72ca56 | 2020-07-27 09:13:42 -0700 | [diff] [blame] | 155 | using TSDRegistryT = TSDRegistrySharedT<A, 8U, 4U>; // Shared, max 8 TSDs. |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 156 | }; |
Dynamic Tools Team | c910695 | 2019-12-13 09:43:51 -0800 | [diff] [blame] | 157 | #endif |
Dynamic Tools Team | 517193e | 2019-09-11 14:48:41 +0000 | [diff] [blame] | 158 | |
| 159 | #if SCUDO_ANDROID |
| 160 | typedef AndroidConfig Config; |
| 161 | #elif SCUDO_FUCHSIA |
| 162 | typedef FuchsiaConfig Config; |
| 163 | #else |
| 164 | typedef DefaultConfig Config; |
| 165 | #endif |
| 166 | |
| 167 | } // namespace scudo |
| 168 | |
| 169 | #endif // SCUDO_ALLOCATOR_CONFIG_H_ |