blob: 89b9c761085e1c9e3b067c65bcf3b056546ca3f9 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2020 The Chromium Authors
Takashi Sakamoto0044f2f2020-06-04 04:19:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Takashi Sakamoto1b5312d2021-10-18 08:53:465#ifndef BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_
6#define BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_
Takashi Sakamoto0044f2f2020-06-04 04:19:167
Bartek Nowierskid5d1984a2022-12-18 12:13:158#include "base/allocator/partition_allocator/partition_alloc_buildflags.h"
Takashi Sakamoto0044f2f2020-06-04 04:19:169#include "base/base_export.h"
Hans Wennborg133b1f52021-05-11 19:49:0310#include "base/compiler_specific.h"
Anthony Vallee-Dubois9dbbbda32022-08-26 01:25:3111#include "base/feature_list.h"
Keishi Hattoriaf499ac2021-09-22 23:45:0412#include "base/metrics/field_trial_params.h"
Kalvin Leeac8c71912023-05-17 06:17:2913#include "base/strings/string_piece.h"
Benoit Lize7ebe3d42022-11-24 21:12:0014#include "build/build_config.h"
Takashi Sakamoto3f767cdd2020-08-20 08:37:3115
Takashi Sakamoto0044f2f2020-06-04 04:19:1616namespace base {
Takashi Sakamoto0c9274d2020-10-08 04:17:3717namespace features {
18
Paul Semelb0ce4842022-09-28 08:09:5319extern const BASE_EXPORT Feature kPartitionAllocUnretainedDanglingPtr;
20enum class UnretainedDanglingPtrMode {
21 kCrash,
22 kDumpWithoutCrashing,
23};
24extern const BASE_EXPORT base::FeatureParam<UnretainedDanglingPtrMode>
25 kUnretainedDanglingPtrModeParam;
26
Arthur Sonzognibe6f0132022-07-06 13:54:1227// See /docs/dangling_ptr.md
Daniel Cheng0fff5c232022-09-21 17:43:3428BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDanglingPtr);
Arthur Sonzognibe6f0132022-07-06 13:54:1229enum class DanglingPtrMode {
30 // Crash immediately after detecting a dangling raw_ptr.
31 kCrash, // (default)
32
33 // Log the signature of every occurrences without crashing. It is used by
34 // bots.
Pârise90af2c2023-01-30 14:22:4135 // Format "[DanglingSignature]\t<1>\t<2>\t<3>\t<4>"
36 // 1. The function which freed the memory while it was still referenced.
37 // 2. The task in which the memory was freed.
38 // 3. The function which released the raw_ptr reference.
39 // 4. The task in which the raw_ptr was released.
40 kLogOnly,
Arthur Sonzognibe6f0132022-07-06 13:54:1241
42 // Note: This will be extended with a single shot DumpWithoutCrashing.
43};
44extern const BASE_EXPORT base::FeatureParam<DanglingPtrMode>
45 kDanglingPtrModeParam;
Pârise90af2c2023-01-30 14:22:4146enum class DanglingPtrType {
47 // Act on any dangling raw_ptr released after being freed.
48 kAll, // (default)
49
50 // Detect when freeing memory and releasing the dangling raw_ptr happens in
51 // a different task. Those are more likely to cause use after free.
52 kCrossTask,
53
54 // Note: This will be extended with LongLived
55};
56extern const BASE_EXPORT base::FeatureParam<DanglingPtrType>
57 kDanglingPtrTypeParam;
Arthur Sonzognibe6f0132022-07-06 13:54:1258
Bartek Nowierskibc01b7112023-02-01 14:11:4259#if BUILDFLAG(USE_STARSCAN)
Daniel Cheng0fff5c232022-09-21 17:43:3460BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScan);
Bartek Nowierskibc01b7112023-02-01 14:11:4261#endif
Anton Bikineevdb908de2020-12-08 14:48:1362#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
Daniel Cheng0fff5c232022-09-21 17:43:3463BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanBrowserOnly);
64BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanRendererOnly);
65BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtrControl);
66BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeThreadCacheSize);
67BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeEmptySlotSpanRing);
Sergei Glazunov7afc89b92022-05-31 19:31:2968#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
Keishi Hattoriaf499ac2021-09-22 23:45:0469
70enum class BackupRefPtrEnabledProcesses {
Bartek Nowierskie9ad8a7d2021-11-04 08:37:3971 // BRP enabled only in the browser process.
Keishi Hattoriaf499ac2021-09-22 23:45:0472 kBrowserOnly,
Bartek Nowierskie9ad8a7d2021-11-04 08:37:3973 // BRP enabled only in the browser and renderer processes.
Keishi Hattoriaf499ac2021-09-22 23:45:0474 kBrowserAndRenderer,
Bartek Nowierski76680472021-12-09 17:58:2575 // BRP enabled in all processes, except renderer.
76 kNonRenderer,
Bartek Nowierskie9ad8a7d2021-11-04 08:37:3977 // BRP enabled in all processes.
78 kAllProcesses,
Keishi Hattoriaf499ac2021-09-22 23:45:0479};
Bartek Nowierskie9ad8a7d2021-11-04 08:37:3980
Bartek Nowierskida7d8f1c2021-12-08 19:30:5981enum class BackupRefPtrMode {
Bartek Nowierskiea35aa522021-12-10 07:08:2082 // BRP is disabled across all partitions. Equivalent to the Finch flag being
83 // disabled.
84 kDisabled,
85
Bartek Nowierskida7d8f1c2021-12-08 19:30:5986 // BRP is enabled in the main partition, as well as certain Renderer-only
87 // partitions (if enabled in Renderer at all).
88 // This entails splitting the main partition.
89 kEnabled,
90
Keishi Hattoric384e2f2022-06-16 09:32:5791 // Same as kEnabled but without zapping quarantined objects.
92 kEnabledWithoutZapping,
93
Keishi Hattori73817182023-04-13 07:06:0394 // Same as kEnabled but registers the main partition to memory reclaimer.
95 kEnabledWithMemoryReclaimer,
Keishi Hattoridbf92402023-04-07 12:22:3096
Bartek Nowierskida7d8f1c2021-12-08 19:30:5997 // BRP is disabled, but the main partition is split out, as if BRP was enabled
98 // in the "previous slot" mode.
99 kDisabledButSplitPartitions2Way,
100
Keishi Hattori73817182023-04-13 07:06:03101 // Same as kDisabledButSplitPartitions2Way but registers the main partition to
102 // memory reclaimer.
103 kDisabledButSplitPartitions2WayWithMemoryReclaimer,
104
Bartek Nowierskida7d8f1c2021-12-08 19:30:59105 // BRP is disabled, but the main partition *and* aligned partition are split
106 // out, as if BRP was enabled in the "before allocation" mode.
107 kDisabledButSplitPartitions3Way,
Bartek Nowierskida7d8f1c2021-12-08 19:30:59108};
109
Bartek Nowierskif7264202023-05-17 00:23:52110// Decides the amount of memory uses for BRP ref-count. The actual ref-count may
111// be smaller, in which case extra padding is added.
112enum class BackupRefPtrRefCountSize {
113 // Whatever sizeof(PartitionRefCount) happens to be, which is influence by
114 // buildflags.
115 // The remaining options require sizeof(PartitionRefCount) not to exceed the
116 // desired size, which will be asserted.
117 kNatural,
118 // 4 bytes.
119 k4B,
120 // 8 bytes
121 k8B,
122 // 16 bytes.
123 k16B,
124};
125
Thiabaud Engelbrecht05f8b8112022-09-16 02:18:29126enum class AlternateBucketDistributionMode : uint8_t {
127 kDefault,
Thiabaud Engelbrecht05f8b8112022-09-16 02:18:29128 kDenser,
129};
130
Daniel Cheng0fff5c232022-09-21 17:43:34131BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtr);
Keishi Hattoriaf499ac2021-09-22 23:45:04132extern const BASE_EXPORT base::FeatureParam<BackupRefPtrEnabledProcesses>
133 kBackupRefPtrEnabledProcessesParam;
Bartek Nowierskida7d8f1c2021-12-08 19:30:59134extern const BASE_EXPORT base::FeatureParam<BackupRefPtrMode>
135 kBackupRefPtrModeParam;
Bartek Nowierskif7264202023-05-17 00:23:52136extern const BASE_EXPORT base::FeatureParam<BackupRefPtrRefCountSize>
137 kBackupRefPtrRefCountSizeParam;
Sergei Glazunov7afc89b92022-05-31 19:31:29138extern const BASE_EXPORT base::FeatureParam<bool>
139 kBackupRefPtrAsanEnableDereferenceCheckParam;
140extern const BASE_EXPORT base::FeatureParam<bool>
141 kBackupRefPtrAsanEnableExtractionCheckParam;
142extern const BASE_EXPORT base::FeatureParam<bool>
143 kBackupRefPtrAsanEnableInstantiationCheckParam;
Thiabaud Engelbrecht05f8b8112022-09-16 02:18:29144extern const BASE_EXPORT base::FeatureParam<AlternateBucketDistributionMode>
145 kPartitionAllocAlternateBucketDistributionParam;
Takashi Sakamoto0044f2f2020-06-04 04:19:16146
Bartek Nowierskidd715522023-05-04 11:13:44147BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtrForAsh);
148
Arthur Sonzognia570236352022-12-19 13:18:54149BASE_EXPORT BASE_DECLARE_FEATURE(kLowerPAMemoryLimitForNonMainRenderers);
Daniel Cheng0fff5c232022-09-21 17:43:34150BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanMUAwareScheduler);
151BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanStackScanning);
152BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDCScan);
153BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanImmediateFreeing);
154BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanEagerClearing);
155BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocSortActiveSlotSpans);
156BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocUseAlternateDistribution);
Benoit Lize7ebe3d42022-11-24 21:12:00157#if BUILDFLAG(IS_WIN)
158BASE_EXPORT BASE_DECLARE_FEATURE(kPageAllocatorRetryOnCommitFailure);
159#endif
Michael Lippautzd34f7b2c2021-04-21 08:32:26160
Kalvin Leeac8c71912023-05-17 06:17:29161// Name of the synthetic trial associated with forcibly enabling BRP in
162// all processes.
163inline constexpr base::StringPiece kRendererLiveBRPSyntheticTrialName =
164 "BackupRefPtrRendererLive";
165
Takashi Sakamoto0c9274d2020-10-08 04:17:37166} // namespace features
Takashi Sakamoto0044f2f2020-06-04 04:19:16167} // namespace base
168
Takashi Sakamoto1b5312d2021-10-18 08:53:46169#endif // BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_