1 //===-- allocator_config.h --------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef SCUDO_ALLOCATOR_CONFIG_H_
10 #define SCUDO_ALLOCATOR_CONFIG_H_
14 #include "condition_variable.h"
16 #include "primary32.h"
17 #include "primary64.h"
18 #include "secondary.h"
19 #include "size_class_map.h"
20 #include "tsd_exclusive.h"
21 #include "tsd_shared.h"
23 // To import a custom configuration, define `SCUDO_USE_CUSTOM_CONFIG` and
24 // aliasing the `Config` like:
27 // // The instance of Scudo will be initiated with `Config`.
28 // typedef CustomConfig Config;
29 // // Aliasing as default configuration to run the tests with this config.
30 // typedef CustomConfig DefaultConfig;
31 // } // namespace scudo
33 // Put them in the header `custom_scudo_config.h` then you will be using the
34 // custom configuration and able to run all the tests as well.
35 #ifdef SCUDO_USE_CUSTOM_CONFIG
36 #include "custom_scudo_config.h"
41 // Scudo uses a structure as a template argument that specifies the
42 // configuration options for the various subcomponents of the allocator. See the
43 // following configs as examples and check `allocator_config.def` for all the
46 #ifndef SCUDO_USE_CUSTOM_CONFIG
48 // Default configurations for various platforms. Note this is only enabled when
49 // there's no custom configuration in the build system.
50 struct DefaultConfig
{
51 static const bool MaySupportMemoryTagging
= true;
52 template <class A
> using TSDRegistryT
= TSDRegistryExT
<A
>; // Exclusive
55 using SizeClassMap
= DefaultSizeClassMap
;
56 #if SCUDO_CAN_USE_PRIMARY64
57 static const uptr RegionSizeLog
= 32U;
58 static const uptr GroupSizeLog
= 21U;
59 typedef uptr CompactPtrT
;
60 static const uptr CompactPtrScale
= 0;
61 static const bool EnableRandomOffset
= true;
62 static const uptr MapSizeIncrement
= 1UL << 18;
64 static const uptr RegionSizeLog
= 19U;
65 static const uptr GroupSizeLog
= 19U;
66 typedef uptr CompactPtrT
;
68 static const s32 MinReleaseToOsIntervalMs
= INT32_MIN
;
69 static const s32 MaxReleaseToOsIntervalMs
= INT32_MAX
;
71 #if SCUDO_CAN_USE_PRIMARY64
72 template <typename Config
> using PrimaryT
= SizeClassAllocator64
<Config
>;
74 template <typename Config
> using PrimaryT
= SizeClassAllocator32
<Config
>;
79 static const u32 EntriesArraySize
= 32U;
80 static const u32 QuarantineSize
= 0U;
81 static const u32 DefaultMaxEntriesCount
= 32U;
82 static const uptr DefaultMaxEntrySize
= 1UL << 19;
83 static const s32 MinReleaseToOsIntervalMs
= INT32_MIN
;
84 static const s32 MaxReleaseToOsIntervalMs
= INT32_MAX
;
86 template <typename Config
> using CacheT
= MapAllocatorCache
<Config
>;
89 template <typename Config
> using SecondaryT
= MapAllocator
<Config
>;
92 #endif // SCUDO_USE_CUSTOM_CONFIG
94 struct AndroidConfig
{
95 static const bool MaySupportMemoryTagging
= true;
97 using TSDRegistryT
= TSDRegistrySharedT
<A
, 8U, 2U>; // Shared, max 8 TSDs.
100 using SizeClassMap
= AndroidSizeClassMap
;
101 #if SCUDO_CAN_USE_PRIMARY64
102 static const uptr RegionSizeLog
= 28U;
103 typedef u32 CompactPtrT
;
104 static const uptr CompactPtrScale
= SCUDO_MIN_ALIGNMENT_LOG
;
105 static const uptr GroupSizeLog
= 20U;
106 static const bool EnableRandomOffset
= true;
107 static const uptr MapSizeIncrement
= 1UL << 18;
109 static const uptr RegionSizeLog
= 18U;
110 static const uptr GroupSizeLog
= 18U;
111 typedef uptr CompactPtrT
;
113 static const s32 MinReleaseToOsIntervalMs
= 1000;
114 static const s32 MaxReleaseToOsIntervalMs
= 1000;
116 #if SCUDO_CAN_USE_PRIMARY64
117 template <typename Config
> using PrimaryT
= SizeClassAllocator64
<Config
>;
119 template <typename Config
> using PrimaryT
= SizeClassAllocator32
<Config
>;
124 static const u32 EntriesArraySize
= 256U;
125 static const u32 QuarantineSize
= 32U;
126 static const u32 DefaultMaxEntriesCount
= 32U;
127 static const uptr DefaultMaxEntrySize
= 2UL << 20;
128 static const s32 MinReleaseToOsIntervalMs
= 0;
129 static const s32 MaxReleaseToOsIntervalMs
= 1000;
131 template <typename Config
> using CacheT
= MapAllocatorCache
<Config
>;
134 template <typename Config
> using SecondaryT
= MapAllocator
<Config
>;
137 #if SCUDO_CAN_USE_PRIMARY64
138 struct FuchsiaConfig
{
139 static const bool MaySupportMemoryTagging
= false;
141 using TSDRegistryT
= TSDRegistrySharedT
<A
, 8U, 4U>; // Shared, max 8 TSDs.
144 using SizeClassMap
= FuchsiaSizeClassMap
;
146 // Support 39-bit VMA for riscv-64
147 static const uptr RegionSizeLog
= 28U;
148 static const uptr GroupSizeLog
= 19U;
149 static const bool EnableContiguousRegions
= false;
151 static const uptr RegionSizeLog
= 30U;
152 static const uptr GroupSizeLog
= 21U;
154 typedef u32 CompactPtrT
;
155 static const bool EnableRandomOffset
= true;
156 static const uptr MapSizeIncrement
= 1UL << 18;
157 static const uptr CompactPtrScale
= SCUDO_MIN_ALIGNMENT_LOG
;
158 static const s32 MinReleaseToOsIntervalMs
= INT32_MIN
;
159 static const s32 MaxReleaseToOsIntervalMs
= INT32_MAX
;
161 template <typename Config
> using PrimaryT
= SizeClassAllocator64
<Config
>;
164 template <typename Config
> using CacheT
= MapAllocatorNoCache
<Config
>;
166 template <typename Config
> using SecondaryT
= MapAllocator
<Config
>;
169 struct TrustyConfig
{
170 static const bool MaySupportMemoryTagging
= true;
172 using TSDRegistryT
= TSDRegistrySharedT
<A
, 1U, 1U>; // Shared, max 1 TSD.
175 using SizeClassMap
= TrustySizeClassMap
;
176 static const uptr RegionSizeLog
= 28U;
177 static const uptr GroupSizeLog
= 20U;
178 typedef u32 CompactPtrT
;
179 static const bool EnableRandomOffset
= false;
180 static const uptr MapSizeIncrement
= 1UL << 12;
181 static const uptr CompactPtrScale
= SCUDO_MIN_ALIGNMENT_LOG
;
182 static const s32 MinReleaseToOsIntervalMs
= INT32_MIN
;
183 static const s32 MaxReleaseToOsIntervalMs
= INT32_MAX
;
185 template <typename Config
> using PrimaryT
= SizeClassAllocator64
<Config
>;
188 template <typename Config
> using CacheT
= MapAllocatorNoCache
<Config
>;
191 template <typename Config
> using SecondaryT
= MapAllocator
<Config
>;
195 #ifndef SCUDO_USE_CUSTOM_CONFIG
198 typedef AndroidConfig Config
;
200 typedef FuchsiaConfig Config
;
202 typedef TrustyConfig Config
;
204 typedef DefaultConfig Config
;
207 #endif // SCUDO_USE_CUSTOM_CONFIG
211 #endif // SCUDO_ALLOCATOR_CONFIG_H_