1//===-- allocator_config.def ------------------------------------*- 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// This file defines all the flags and types supported in Scudo. For optional
10// flags and types, only explicitly define them when interested (i.e., unused
11// optional flags or types can be skipped).
12
13#ifndef BASE_REQUIRED_TEMPLATE_TYPE
14#define BASE_REQUIRED_TEMPLATE_TYPE(...)
15#endif
16#ifndef BASE_OPTIONAL
17#define BASE_OPTIONAL(...)
18#endif
19#ifndef PRIMARY_REQUIRED_TYPE
20#define PRIMARY_REQUIRED_TYPE(...)
21#endif
22#ifndef PRIMARY_REQUIRED
23#define PRIMARY_REQUIRED(...)
24#endif
25#ifndef PRIMARY_OPTIONAL
26#define PRIMARY_OPTIONAL(...)
27#endif
28#ifndef PRIMARY_OPTIONAL_TYPE
29#define PRIMARY_OPTIONAL_TYPE(...)
30#endif
31#ifndef SECONDARY_REQUIRED_TEMPLATE_TYPE
32#define SECONDARY_REQUIRED_TEMPLATE_TYPE(...)
33#endif
34#ifndef SECONDARY_OPTIONAL
35#define SECONDARY_OPTIONAL(...)
36#endif
37#ifndef SECONDARY_CACHE_OPTIONAL
38#define SECONDARY_CACHE_OPTIONAL(...)
39#endif
40
41// BASE_REQUIRED_TEMPLATE_TYPE(NAME)
42//
43// Thread-Specific Data Registry used, shared or exclusive.
44BASE_REQUIRED_TEMPLATE_TYPE(TSDRegistryT)
45
46// Defines the type of Primary allocator to use.
47BASE_REQUIRED_TEMPLATE_TYPE(PrimaryT)
48
49// Defines the type of Secondary allocator to use.
50BASE_REQUIRED_TEMPLATE_TYPE(SecondaryT)
51
52// BASE_OPTIONAL(TYPE, NAME, DEFAULT)
53//
54// Indicates possible support for Memory Tagging.
55BASE_OPTIONAL(const bool, MaySupportMemoryTagging, false)
56
57// Disable the quarantine code.
58BASE_OPTIONAL(const bool, QuarantineDisabled, false)
59
60// If set to true, malloc_usable_size returns the exact size of the allocation.
61// If set to false, return the total available size in the allocation.
62BASE_OPTIONAL(const bool, ExactUsableSize, true)
63
64// If set to true, zero-filling occurs in deallocate instead of allocate
65// when FillContents is set to ZeroFill. Quarantine is not supported yet.
66BASE_OPTIONAL(const bool, DeallocZeroFill, false)
67
68#if SCUDO_FUCHSIA
69// Writes zeros to the memory slot when a allocation is returned to
70// the allocator. This decommits memory on operating systems that
71// detects pages full of zero."
72BASE_OPTIONAL(const bool, EnableZeroOnDealloc, false)
73#endif
74
75// Abort if there is a mismatch between the function type that allocates memory
76// and the function type that deallocates memory.
77// These conditions will abort with an error message:
78// new/any C free operation
79// any C allocation operation/any delete operation
80// new/delete[]
81// new[]/delete
82// aligned alloc/free_sized
83// non-aligned alloc/free_aligned_sized
84BASE_OPTIONAL(const bool, AbortOnDeallocTypeMismatch, true)
85
86// Abort if there is free function that takes a size value but that size
87// does not match the allocation size.
88BASE_OPTIONAL(const bool, AbortOnDeallocSizeMismatch, true)
89
90// Abort if there is free function that takes an alignment value but that
91// alignment does not match the allocation alignment.
92BASE_OPTIONAL(const bool, AbortOnDeallocAlignmentMismatch, true)
93
94// PRIMARY_REQUIRED_TYPE(NAME)
95//
96// SizeClassMap to use with the Primary.
97PRIMARY_REQUIRED_TYPE(SizeClassMap)
98
99// PRIMARY_REQUIRED(TYPE, NAME)
100//
101// Log2 of the size of a size class region, as used by the Primary.
102PRIMARY_REQUIRED(const uptr, RegionSizeLog)
103
104// Conceptually, a region will be divided into groups based on the address
105// range. Each allocation consumes blocks in the same group until exhaustion
106// then it pops out blocks in a new group. Therefore, `GroupSizeLog` is always
107// smaller or equal to `RegionSizeLog`. Note that `GroupSizeLog` needs to be
108// equal to `RegionSizeLog` for SizeClassAllocator32 because of certain
109// constraints.
110PRIMARY_REQUIRED(const uptr, GroupSizeLog)
111
112// Call map for user memory with at least this size. Only used with primary64.
113PRIMARY_REQUIRED(const uptr, MapSizeIncrement)
114
115// Defines the minimal & maximal release interval that can be set.
116PRIMARY_REQUIRED(const s32, MinReleaseToOsIntervalMs)
117PRIMARY_REQUIRED(const s32, MaxReleaseToOsIntervalMs)
118
119// PRIMARY_OPTIONAL(TYPE, NAME, DEFAULT)
120//
121
122// Enables/disables primary block caching. Batch class still caches.
123PRIMARY_OPTIONAL(const bool, EnableBlockCache, true)
124
125// The scale of a compact pointer. E.g., Ptr = Base + (CompactPtr << Scale).
126PRIMARY_OPTIONAL(const uptr, CompactPtrScale, SCUDO_MIN_ALIGNMENT_LOG)
127
128// Indicates support for offsetting the start of a region by a random number of
129// pages. This is only used if `EnableContiguousRegions` is enabled.
130PRIMARY_OPTIONAL(const bool, EnableRandomOffset, false)
131PRIMARY_OPTIONAL(const s32, DefaultReleaseToOsIntervalMs, INT32_MIN)
132
133// When `EnableContiguousRegions` is true, all regions will be be arranged in
134// adjacency. This will reduce the fragmentation caused by region allocations
135// but may require a huge amount of contiguous pages at initialization.
136PRIMARY_OPTIONAL(const bool, EnableContiguousRegions, true)
137
138// PRIMARY_OPTIONAL_TYPE(NAME, DEFAULT)
139//
140// Use condition variable to shorten the waiting time of refillment of
141// freelist. Note that this depends on the implementation of condition
142// variable on each platform and the performance may vary so that it does not
143// guarantee a performance benefit.
144PRIMARY_OPTIONAL_TYPE(ConditionVariableT, ConditionVariableDummy)
145
146// Defines the type and scale of a compact pointer. A compact pointer can
147// be understood as the offset of a pointer within the region it belongs
148// to, in increments of a power-of-2 scale. See `CompactPtrScale` also.
149PRIMARY_OPTIONAL_TYPE(CompactPtrT, uptr)
150
151// SECONDARY_REQUIRED_TEMPLATE_TYPE(NAME)
152//
153// Defines the type of Secondary Cache to use.
154SECONDARY_REQUIRED_TEMPLATE_TYPE(CacheT)
155
156// SECONDARY_OPTIONAL(TYPE, NAME, DEFAULT)
157//
158// Add one guard page at the front and back for each allocation.
159SECONDARY_OPTIONAL(const bool, EnableGuardPages, true)
160
161// SECONDARY_CACHE_OPTIONAL(TYPE, NAME, DEFAULT)
162//
163// Defines the type of cache used by the Secondary. Some additional
164// configuration entries can be necessary depending on the Cache.
165SECONDARY_CACHE_OPTIONAL(const u32, EntriesArraySize, 0)
166SECONDARY_CACHE_OPTIONAL(const u32, QuarantineSize, 0)
167SECONDARY_CACHE_OPTIONAL(const u32, DefaultMaxEntriesCount, 0)
168SECONDARY_CACHE_OPTIONAL(const uptr, DefaultMaxEntrySize, 0)
169SECONDARY_CACHE_OPTIONAL(const uptr, DefaultMaxCacheResidentBytes, 0)
170SECONDARY_CACHE_OPTIONAL(const s32, MinReleaseToOsIntervalMs, INT32_MIN)
171SECONDARY_CACHE_OPTIONAL(const s32, MaxReleaseToOsIntervalMs, INT32_MAX)
172SECONDARY_CACHE_OPTIONAL(const s32, DefaultReleaseToOsIntervalMs, INT32_MIN)
173
174#undef SECONDARY_CACHE_OPTIONAL
175#undef SECONDARY_OPTIONAL
176#undef SECONDARY_REQUIRED_TEMPLATE_TYPE
177#undef PRIMARY_OPTIONAL_TYPE
178#undef PRIMARY_OPTIONAL
179#undef PRIMARY_REQUIRED
180#undef PRIMARY_REQUIRED_TYPE
181#undef BASE_OPTIONAL
182#undef BASE_REQUIRED_TEMPLATE_TYPE
183