• 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/allocator/partition_allocator/src/partition_alloc/partition_alloc_base/time/time.h"
9 #include "base/allocator/partition_allocator/src/partition_alloc/partition_alloc_buildflags.h"
10 #include "base/allocator/partition_allocator/src/partition_alloc/partition_root.h"
11 #include "base/base_export.h"
12 #include "base/compiler_specific.h"
13 #include "base/feature_list.h"
14 #include "base/metrics/field_trial_params.h"
15 #include "base/strings/string_piece.h"
16 #include "base/time/time.h"
17 #include "build/build_config.h"
18 
19 namespace base {
20 namespace features {
21 
22 extern const BASE_EXPORT Feature kPartitionAllocUnretainedDanglingPtr;
23 enum class UnretainedDanglingPtrMode {
24   kCrash,
25   kDumpWithoutCrashing,
26 };
27 extern const BASE_EXPORT base::FeatureParam<UnretainedDanglingPtrMode>
28     kUnretainedDanglingPtrModeParam;
29 
30 // See /docs/dangling_ptr.md
31 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDanglingPtr);
32 enum class DanglingPtrMode {
33   // Crash immediately after detecting a dangling raw_ptr.
34   kCrash,  // (default)
35 
36   // Log the signature of every occurrences without crashing. It is used by
37   // bots.
38   // Format "[DanglingSignature]\t<1>\t<2>\t<3>\t<4>"
39   // 1. The function which freed the memory while it was still referenced.
40   // 2. The task in which the memory was freed.
41   // 3. The function which released the raw_ptr reference.
42   // 4. The task in which the raw_ptr was released.
43   kLogOnly,
44 
45   // Note: This will be extended with a single shot DumpWithoutCrashing.
46 };
47 extern const BASE_EXPORT base::FeatureParam<DanglingPtrMode>
48     kDanglingPtrModeParam;
49 enum class DanglingPtrType {
50   // Act on any dangling raw_ptr released after being freed.
51   kAll,  // (default)
52 
53   // Detect when freeing memory and releasing the dangling raw_ptr happens in
54   // a different task. Those are more likely to cause use after free.
55   kCrossTask,
56 
57   // Note: This will be extended with LongLived
58 };
59 extern const BASE_EXPORT base::FeatureParam<DanglingPtrType>
60     kDanglingPtrTypeParam;
61 
62 #if BUILDFLAG(USE_STARSCAN)
63 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScan);
64 #endif
65 #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
66 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanBrowserOnly);
67 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanRendererOnly);
68 
69 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeThreadCacheSize);
70 BASE_EXPORT int GetPartitionAllocLargeThreadCacheSizeValue();
71 BASE_EXPORT int GetPartitionAllocLargeThreadCacheSizeValueForLowRAMAndroid();
72 
73 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeEmptySlotSpanRing);
74 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocSchedulerLoopQuarantine);
75 extern const BASE_EXPORT base::FeatureParam<int>
76     kPartitionAllocSchedulerLoopQuarantineCapacity;
77 
78 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocZappingByFreeFlags);
79 #endif  // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
80 
81 enum class BackupRefPtrEnabledProcesses {
82   // BRP enabled only in the browser process.
83   kBrowserOnly,
84   // BRP enabled only in the browser and renderer processes.
85   kBrowserAndRenderer,
86   // BRP enabled in all processes, except renderer.
87   kNonRenderer,
88   // BRP enabled in all processes.
89   kAllProcesses,
90 };
91 
92 enum class BackupRefPtrMode {
93   // BRP is disabled across all partitions. Equivalent to the Finch flag being
94   // disabled.
95   kDisabled,
96 
97   // BRP is enabled in the main partition, as well as certain Renderer-only
98   // partitions (if enabled in Renderer at all).
99   // This entails splitting the main partition.
100   kEnabled,
101 
102   // BRP is disabled, but the main partition is split out, as if BRP was enabled
103   // in the "previous slot" mode.
104   kDisabledButSplitPartitions2Way,
105 
106   // BRP is disabled, but the main partition *and* aligned partition are split
107   // out, as if BRP was enabled in the "before allocation" mode.
108   kDisabledButSplitPartitions3Way,
109 };
110 
111 // Decides the amount of memory uses for BRP ref-count. The actual ref-count may
112 // be smaller, in which case extra padding is added.
113 enum class BackupRefPtrRefCountSize {
114   // Whatever sizeof(PartitionRefCount) happens to be, which is influence by
115   // buildflags.
116   // The remaining options require sizeof(PartitionRefCount) not to exceed the
117   // desired size, which will be asserted.
118   kNatural,
119   // 4 bytes.
120   k4B,
121   // 8 bytes
122   k8B,
123   // 16 bytes.
124   k16B,
125 };
126 
127 enum class MemtagMode {
128   // memtagMode will be SYNC.
129   kSync,
130   // memtagMode will be ASYNC.
131   kAsync,
132 };
133 
134 enum class MemoryTaggingEnabledProcesses {
135   // Memory tagging enabled only in the browser process.
136   kBrowserOnly,
137   // Memory tagging enabled in all processes, except renderer.
138   kNonRenderer,
139   // Memory tagging enabled in all processes.
140   kAllProcesses,
141 };
142 
143 enum class BucketDistributionMode : uint8_t {
144   kDefault,
145   kDenser,
146 };
147 
148 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtr);
149 extern const BASE_EXPORT base::FeatureParam<BackupRefPtrEnabledProcesses>
150     kBackupRefPtrEnabledProcessesParam;
151 extern const BASE_EXPORT base::FeatureParam<BackupRefPtrMode>
152     kBackupRefPtrModeParam;
153 extern const BASE_EXPORT base::FeatureParam<BackupRefPtrRefCountSize>
154     kBackupRefPtrRefCountSizeParam;
155 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocMemoryTagging);
156 extern const BASE_EXPORT base::FeatureParam<MemtagMode> kMemtagModeParam;
157 extern const BASE_EXPORT base::FeatureParam<MemoryTaggingEnabledProcesses>
158     kMemoryTaggingEnabledProcessesParam;
159 // Kill switch for memory tagging. Skips any code related to memory tagging when
160 // enabled.
161 BASE_EXPORT BASE_DECLARE_FEATURE(kKillPartitionAllocMemoryTagging);
162 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPermissiveMte);
163 extern const BASE_EXPORT base::FeatureParam<bool>
164     kBackupRefPtrAsanEnableDereferenceCheckParam;
165 extern const BASE_EXPORT base::FeatureParam<bool>
166     kBackupRefPtrAsanEnableExtractionCheckParam;
167 extern const BASE_EXPORT base::FeatureParam<bool>
168     kBackupRefPtrAsanEnableInstantiationCheckParam;
169 extern const BASE_EXPORT base::FeatureParam<BucketDistributionMode>
170     kPartitionAllocBucketDistributionParam;
171 
172 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtrForAsh);
173 
174 BASE_EXPORT BASE_DECLARE_FEATURE(kLowerPAMemoryLimitForNonMainRenderers);
175 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanMUAwareScheduler);
176 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanStackScanning);
177 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDCScan);
178 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanImmediateFreeing);
179 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanEagerClearing);
180 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocUseDenserDistribution);
181 
182 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocMemoryReclaimer);
183 extern const BASE_EXPORT base::FeatureParam<TimeDelta>
184     kPartitionAllocMemoryReclaimerInterval;
185 BASE_EXPORT BASE_DECLARE_FEATURE(
186     kPartitionAllocStraightenLargerSlotSpanFreeLists);
187 extern const BASE_EXPORT
188     base::FeatureParam<partition_alloc::StraightenLargerSlotSpanFreeListsMode>
189         kPartitionAllocStraightenLargerSlotSpanFreeListsMode;
190 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocSortSmallerSlotSpanFreeLists);
191 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocSortActiveSlotSpans);
192 
193 #if BUILDFLAG(IS_WIN)
194 BASE_EXPORT BASE_DECLARE_FEATURE(kPageAllocatorRetryOnCommitFailure);
195 #endif
196 
197 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_CHROMEOS)
198 extern const base::FeatureParam<bool>
199     kPartialLowEndModeExcludePartitionAllocSupport;
200 #endif
201 
202 // Name of the synthetic trial associated with forcibly enabling BRP in
203 // all processes.
204 inline constexpr base::StringPiece kRendererLiveBRPSyntheticTrialName =
205     "BackupRefPtrRendererLive";
206 
207 BASE_EXPORT BASE_DECLARE_FEATURE(kEnableConfigurableThreadCacheMultiplier);
208 BASE_EXPORT double GetThreadCacheMultiplier();
209 BASE_EXPORT double GetThreadCacheMultiplierForAndroid();
210 
211 BASE_EXPORT BASE_DECLARE_FEATURE(kEnableConfigurableThreadCachePurgeInterval);
212 extern const partition_alloc::internal::base::TimeDelta
213 GetThreadCacheMinPurgeInterval();
214 extern const partition_alloc::internal::base::TimeDelta
215 GetThreadCacheMaxPurgeInterval();
216 extern const partition_alloc::internal::base::TimeDelta
217 GetThreadCacheDefaultPurgeInterval();
218 
219 BASE_EXPORT BASE_DECLARE_FEATURE(
220     kEnableConfigurableThreadCacheMinCachedMemoryForPurging);
221 BASE_EXPORT int GetThreadCacheMinCachedMemoryForPurgingBytes();
222 
223 BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDisableBRPInBufferPartition);
224 
225 // This feature is additionally gated behind a buildflag because
226 // pool offset freelists cannot be represented when PartitionAlloc uses
227 // 32-bit pointers.
228 #if BUILDFLAG(USE_FREELIST_POOL_OFFSETS)
229 BASE_EXPORT BASE_DECLARE_FEATURE(kUsePoolOffsetFreelists);
230 #endif
231 
232 }  // namespace features
233 }  // namespace base
234 
235 #endif  // BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_
236