• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_
6 #define BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_
7 
8 #include "base/base_export.h"
9 #include "base/compiler_specific.h"
10 #include "base/feature_list.h"
11 #include "base/metrics/field_trial_params.h"
12 #include "base/time/time.h"
13 #include "build/build_config.h"
14 #include "partition_alloc/buildflags.h"
15 #include "partition_alloc/partition_alloc_base/time/time.h"
16 #include "partition_alloc/partition_root.h"
17 
18 namespace base {
19 namespace features {
20 
21 namespace internal {
22 
23 enum class PAFeatureEnabledProcesses {
24   // Enabled only in the browser process.
25   kBrowserOnly,
26   // Enabled only in the browser and renderer processes.
27   kBrowserAndRenderer,
28   // Enabled in all processes, except renderer.
29   kNonRenderer,
30   // Enabled only in renderer processes.
31   kRendererOnly,
32   // Enabled in all child processes, except zygote.
33   kAllChildProcesses,
34   // Enabled in all processes.
35   kAllProcesses,
36 };
37 
38 }  // namespace internal
39 
40 extern const BASE_EXPORT Feature kPartitionAllocUnretainedDanglingPtr;
41 enum class UnretainedDanglingPtrMode {
42   kCrash,
43   kDumpWithoutCrashing,
44 };
45 extern const BASE_EXPORT base::FeatureParam<UnretainedDanglingPtrMode>
46     kUnretainedDanglingPtrModeParam;
47 
48 // See /docs/dangling_ptr.md
49 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDanglingPtr);
50 enum class DanglingPtrMode {
51   // Crash immediately after detecting a dangling raw_ptr.
52   kCrash,  // (default)
53 
54   // Log the signature of every occurrences without crashing. It is used by
55   // bots.
56   // Format "[DanglingSignature]\t<1>\t<2>\t<3>\t<4>"
57   // 1. The function which freed the memory while it was still referenced.
58   // 2. The task in which the memory was freed.
59   // 3. The function which released the raw_ptr reference.
60   // 4. The task in which the raw_ptr was released.
61   kLogOnly,
62 
63   // Note: This will be extended with a single shot DumpWithoutCrashing.
64 };
65 extern const BASE_EXPORT base::FeatureParam<DanglingPtrMode>
66     kDanglingPtrModeParam;
67 enum class DanglingPtrType {
68   // Act on any dangling raw_ptr released after being freed.
69   kAll,  // (default)
70 
71   // Detect when freeing memory and releasing the dangling raw_ptr happens in
72   // a different task. Those are more likely to cause use after free.
73   kCrossTask,
74 
75   // Note: This will be extended with LongLived
76 };
77 extern const BASE_EXPORT base::FeatureParam<DanglingPtrType>
78     kDanglingPtrTypeParam;
79 
80 using PartitionAllocWithAdvancedChecksEnabledProcesses =
81     internal::PAFeatureEnabledProcesses;
82 
83 #if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
84 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeThreadCacheSize);
85 BASE_EXPORT int GetPartitionAllocLargeThreadCacheSizeValue();
86 BASE_EXPORT int GetPartitionAllocLargeThreadCacheSizeValueForLowRAMAndroid();
87 
88 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeEmptySlotSpanRing);
89 
90 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocWithAdvancedChecks);
91 extern const BASE_EXPORT
92     base::FeatureParam<PartitionAllocWithAdvancedChecksEnabledProcesses>
93         kPartitionAllocWithAdvancedChecksEnabledProcessesParam;
94 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocSchedulerLoopQuarantine);
95 // Scheduler Loop Quarantine's per-thread capacity in bytes.
96 extern const BASE_EXPORT base::FeatureParam<int>
97     kPartitionAllocSchedulerLoopQuarantineBranchCapacity;
98 
99 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocZappingByFreeFlags);
100 
101 // Eventually zero out most PartitionAlloc memory. This is not meant as a
102 // security guarantee, but to increase the compression ratio of PartitionAlloc's
103 // fragmented super pages.
104 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocEventuallyZeroFreedMemory);
105 #endif  // PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
106 
107 using BackupRefPtrEnabledProcesses = internal::PAFeatureEnabledProcesses;
108 
109 enum class BackupRefPtrMode {
110   // BRP is disabled across all partitions. Equivalent to the Finch flag being
111   // disabled.
112   kDisabled,
113 
114   // BRP is enabled in the main partition, as well as certain Renderer-only
115   // partitions (if enabled in Renderer at all).
116   kEnabled,
117 };
118 
119 enum class MemtagMode {
120   // memtagMode will be SYNC.
121   kSync,
122   // memtagMode will be ASYNC.
123   kAsync,
124 };
125 
126 enum class RetagMode {
127   // Allocations are retagged by incrementing the current tag.
128   kIncrement,
129 
130   // Allocations are retagged with a random tag.
131   kRandom,
132 };
133 
134 using MemoryTaggingEnabledProcesses = internal::PAFeatureEnabledProcesses;
135 
136 enum class BucketDistributionMode : uint8_t {
137   kDefault,
138   kDenser,
139 };
140 
141 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtr);
142 extern const BASE_EXPORT base::FeatureParam<BackupRefPtrEnabledProcesses>
143     kBackupRefPtrEnabledProcessesParam;
144 extern const BASE_EXPORT base::FeatureParam<BackupRefPtrMode>
145     kBackupRefPtrModeParam;
146 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocMemoryTagging);
147 extern const BASE_EXPORT base::FeatureParam<MemtagMode> kMemtagModeParam;
148 extern const BASE_EXPORT base::FeatureParam<RetagMode> kRetagModeParam;
149 extern const BASE_EXPORT base::FeatureParam<MemoryTaggingEnabledProcesses>
150     kMemoryTaggingEnabledProcessesParam;
151 // Kill switch for memory tagging. Skips any code related to memory tagging when
152 // enabled.
153 BASE_EXPORT BASE_DECLARE_FEATURE(kKillPartitionAllocMemoryTagging);
154 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPermissiveMte);
155 extern const BASE_EXPORT base::FeatureParam<bool>
156     kBackupRefPtrAsanEnableDereferenceCheckParam;
157 extern const BASE_EXPORT base::FeatureParam<bool>
158     kBackupRefPtrAsanEnableExtractionCheckParam;
159 extern const BASE_EXPORT base::FeatureParam<bool>
160     kBackupRefPtrAsanEnableInstantiationCheckParam;
161 extern const BASE_EXPORT base::FeatureParam<BucketDistributionMode>
162     kPartitionAllocBucketDistributionParam;
163 
164 BASE_EXPORT BASE_DECLARE_FEATURE(kLowerPAMemoryLimitForNonMainRenderers);
165 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocUseDenserDistribution);
166 
167 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocMemoryReclaimer);
168 extern const BASE_EXPORT base::FeatureParam<TimeDelta>
169     kPartitionAllocMemoryReclaimerInterval;
170 BASE_EXPORT BASE_DECLARE_FEATURE(
171     kPartitionAllocStraightenLargerSlotSpanFreeLists);
172 extern const BASE_EXPORT
173     base::FeatureParam<partition_alloc::StraightenLargerSlotSpanFreeListsMode>
174         kPartitionAllocStraightenLargerSlotSpanFreeListsMode;
175 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocSortSmallerSlotSpanFreeLists);
176 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocSortActiveSlotSpans);
177 
178 #if BUILDFLAG(IS_WIN)
179 BASE_EXPORT BASE_DECLARE_FEATURE(kPageAllocatorRetryOnCommitFailure);
180 #endif
181 
182 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
183 extern const base::FeatureParam<bool>
184     kPartialLowEndModeExcludePartitionAllocSupport;
185 #endif
186 
187 BASE_EXPORT BASE_DECLARE_FEATURE(kEnableConfigurableThreadCacheMultiplier);
188 BASE_EXPORT double GetThreadCacheMultiplier();
189 BASE_EXPORT double GetThreadCacheMultiplierForAndroid();
190 
191 BASE_EXPORT BASE_DECLARE_FEATURE(kEnableConfigurableThreadCachePurgeInterval);
192 extern const partition_alloc::internal::base::TimeDelta
193 GetThreadCacheMinPurgeInterval();
194 extern const partition_alloc::internal::base::TimeDelta
195 GetThreadCacheMaxPurgeInterval();
196 extern const partition_alloc::internal::base::TimeDelta
197 GetThreadCacheDefaultPurgeInterval();
198 
199 BASE_EXPORT BASE_DECLARE_FEATURE(
200     kEnableConfigurableThreadCacheMinCachedMemoryForPurging);
201 BASE_EXPORT int GetThreadCacheMinCachedMemoryForPurgingBytes();
202 
203 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDisableBRPInBufferPartition);
204 
205 // This feature is additionally gated behind a buildflag because
206 // pool offset freelists cannot be represented when PartitionAlloc uses
207 // 32-bit pointers.
208 #if PA_BUILDFLAG(USE_FREELIST_DISPATCHER)
209 BASE_EXPORT BASE_DECLARE_FEATURE(kUsePoolOffsetFreelists);
210 #endif
211 
212 // When set, partitions use a larger ring buffer and free memory less
213 // aggressively when in the foreground.
214 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocAdjustSizeWhenInForeground);
215 
216 // When enabled, uses a more nuanced heuristic to determine if slot
217 // spans can be treated as "single-slot."
218 //
219 // See also: https://crbug.com/333443437
220 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocUseSmallSingleSlotSpans);
221 
222 #if PA_CONFIG(ENABLE_SHADOW_METADATA)
223 using ShadowMetadataEnabledProcesses = internal::PAFeatureEnabledProcesses;
224 
225 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocShadowMetadata);
226 extern const BASE_EXPORT base::FeatureParam<ShadowMetadataEnabledProcesses>
227     kShadowMetadataEnabledProcessesParam;
228 #endif  // PA_CONFIG(ENABLE_SHADOW_METADATA)
229 
230 }  // namespace features
231 }  // namespace base
232 
233 #endif  // BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_
234