blob: 69796418dd1d6122a1fb4a6010ae664d5904b9fc [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"
Benoit Lize7ebe3d42022-11-24 21:12:0013#include "build/build_config.h"
Takashi Sakamoto3f767cdd2020-08-20 08:37:3114
Takashi Sakamoto0044f2f2020-06-04 04:19:1615namespace base {
Takashi Sakamoto0c9274d2020-10-08 04:17:3716namespace features {
17
Paul Semelb0ce4842022-09-28 08:09:5318extern const BASE_EXPORT Feature kPartitionAllocUnretainedDanglingPtr;
19enum class UnretainedDanglingPtrMode {
20 kCrash,
21 kDumpWithoutCrashing,
22};
23extern const BASE_EXPORT base::FeatureParam<UnretainedDanglingPtrMode>
24 kUnretainedDanglingPtrModeParam;
25
Arthur Sonzognibe6f0132022-07-06 13:54:1226// See /docs/dangling_ptr.md
Daniel Cheng0fff5c232022-09-21 17:43:3427BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDanglingPtr);
Arthur Sonzognibe6f0132022-07-06 13:54:1228enum class DanglingPtrMode {
29 // Crash immediately after detecting a dangling raw_ptr.
30 kCrash, // (default)
31
32 // Log the signature of every occurrences without crashing. It is used by
33 // bots.
Pârise90af2c2023-01-30 14:22:4134 // Format "[DanglingSignature]\t<1>\t<2>\t<3>\t<4>"
35 // 1. The function which freed the memory while it was still referenced.
36 // 2. The task in which the memory was freed.
37 // 3. The function which released the raw_ptr reference.
38 // 4. The task in which the raw_ptr was released.
39 kLogOnly,
Arthur Sonzognibe6f0132022-07-06 13:54:1240
41 // Note: This will be extended with a single shot DumpWithoutCrashing.
42};
43extern const BASE_EXPORT base::FeatureParam<DanglingPtrMode>
44 kDanglingPtrModeParam;
Pârise90af2c2023-01-30 14:22:4145enum class DanglingPtrType {
46 // Act on any dangling raw_ptr released after being freed.
47 kAll, // (default)
48
49 // Detect when freeing memory and releasing the dangling raw_ptr happens in
50 // a different task. Those are more likely to cause use after free.
51 kCrossTask,
52
53 // Note: This will be extended with LongLived
54};
55extern const BASE_EXPORT base::FeatureParam<DanglingPtrType>
56 kDanglingPtrTypeParam;
Arthur Sonzognibe6f0132022-07-06 13:54:1257
Bartek Nowierskibc01b7112023-02-01 14:11:4258#if BUILDFLAG(USE_STARSCAN)
Daniel Cheng0fff5c232022-09-21 17:43:3459BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScan);
Bartek Nowierskibc01b7112023-02-01 14:11:4260#endif
Anton Bikineevdb908de2020-12-08 14:48:1361#if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
Daniel Cheng0fff5c232022-09-21 17:43:3462BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanBrowserOnly);
63BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanRendererOnly);
64BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtrControl);
65BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeThreadCacheSize);
66BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeEmptySlotSpanRing);
Sergei Glazunov7afc89b92022-05-31 19:31:2967#endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
Keishi Hattoriaf499ac2021-09-22 23:45:0468
69enum class BackupRefPtrEnabledProcesses {
Bartek Nowierskie9ad8a7d2021-11-04 08:37:3970 // BRP enabled only in the browser process.
Keishi Hattoriaf499ac2021-09-22 23:45:0471 kBrowserOnly,
Bartek Nowierskie9ad8a7d2021-11-04 08:37:3972 // BRP enabled only in the browser and renderer processes.
Keishi Hattoriaf499ac2021-09-22 23:45:0473 kBrowserAndRenderer,
Bartek Nowierski76680472021-12-09 17:58:2574 // BRP enabled in all processes, except renderer.
75 kNonRenderer,
Bartek Nowierskie9ad8a7d2021-11-04 08:37:3976 // BRP enabled in all processes.
77 kAllProcesses,
Keishi Hattoriaf499ac2021-09-22 23:45:0478};
Bartek Nowierskie9ad8a7d2021-11-04 08:37:3979
Bartek Nowierskida7d8f1c2021-12-08 19:30:5980enum class BackupRefPtrMode {
Bartek Nowierskiea35aa522021-12-10 07:08:2081 // BRP is disabled across all partitions. Equivalent to the Finch flag being
82 // disabled.
83 kDisabled,
84
Bartek Nowierskida7d8f1c2021-12-08 19:30:5985 // BRP is enabled in the main partition, as well as certain Renderer-only
86 // partitions (if enabled in Renderer at all).
87 // This entails splitting the main partition.
88 kEnabled,
89
Keishi Hattoric384e2f2022-06-16 09:32:5790 // Same as kEnabled but without zapping quarantined objects.
91 kEnabledWithoutZapping,
92
Keishi Hattori73817182023-04-13 07:06:0393 // Same as kEnabled but registers the main partition to memory reclaimer.
94 kEnabledWithMemoryReclaimer,
Keishi Hattoridbf92402023-04-07 12:22:3095
Bartek Nowierskida7d8f1c2021-12-08 19:30:5996 // BRP is disabled, but the main partition is split out, as if BRP was enabled
97 // in the "previous slot" mode.
98 kDisabledButSplitPartitions2Way,
99
Keishi Hattori73817182023-04-13 07:06:03100 // Same as kDisabledButSplitPartitions2Way but registers the main partition to
101 // memory reclaimer.
102 kDisabledButSplitPartitions2WayWithMemoryReclaimer,
103
Bartek Nowierskida7d8f1c2021-12-08 19:30:59104 // BRP is disabled, but the main partition *and* aligned partition are split
105 // out, as if BRP was enabled in the "before allocation" mode.
106 kDisabledButSplitPartitions3Way,
Keishi Hattoria8fb2be2022-11-21 05:52:59107
108 // BRP is disabled, but add dummy ref count to each allocation. This will
109 // increase allocation size but not change any of the logic. If an issue
110 // reproduce in this mode, it means the increase in size is causing it.
111 kDisabledButAddDummyRefCount,
Bartek Nowierskida7d8f1c2021-12-08 19:30:59112};
113
Thiabaud Engelbrecht05f8b8112022-09-16 02:18:29114enum class AlternateBucketDistributionMode : uint8_t {
115 kDefault,
Thiabaud Engelbrecht05f8b8112022-09-16 02:18:29116 kDenser,
117};
118
Daniel Cheng0fff5c232022-09-21 17:43:34119BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtr);
Keishi Hattoriaf499ac2021-09-22 23:45:04120extern const BASE_EXPORT base::FeatureParam<BackupRefPtrEnabledProcesses>
121 kBackupRefPtrEnabledProcessesParam;
Bartek Nowierskida7d8f1c2021-12-08 19:30:59122extern const BASE_EXPORT base::FeatureParam<BackupRefPtrMode>
123 kBackupRefPtrModeParam;
Sergei Glazunov7afc89b92022-05-31 19:31:29124extern const BASE_EXPORT base::FeatureParam<bool>
125 kBackupRefPtrAsanEnableDereferenceCheckParam;
126extern const BASE_EXPORT base::FeatureParam<bool>
127 kBackupRefPtrAsanEnableExtractionCheckParam;
128extern const BASE_EXPORT base::FeatureParam<bool>
129 kBackupRefPtrAsanEnableInstantiationCheckParam;
Thiabaud Engelbrecht05f8b8112022-09-16 02:18:29130extern const BASE_EXPORT base::FeatureParam<AlternateBucketDistributionMode>
131 kPartitionAllocAlternateBucketDistributionParam;
Takashi Sakamoto0044f2f2020-06-04 04:19:16132
Bartek Nowierskidd715522023-05-04 11:13:44133BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtrForAsh);
134
Arthur Sonzognia570236352022-12-19 13:18:54135BASE_EXPORT BASE_DECLARE_FEATURE(kLowerPAMemoryLimitForNonMainRenderers);
Daniel Cheng0fff5c232022-09-21 17:43:34136BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanMUAwareScheduler);
137BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanStackScanning);
138BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDCScan);
139BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanImmediateFreeing);
140BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanEagerClearing);
141BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocSortActiveSlotSpans);
142BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocUseAlternateDistribution);
Benoit Lize7ebe3d42022-11-24 21:12:00143#if BUILDFLAG(IS_WIN)
144BASE_EXPORT BASE_DECLARE_FEATURE(kPageAllocatorRetryOnCommitFailure);
145#endif
Michael Lippautzd34f7b2c2021-04-21 08:32:26146
Takashi Sakamoto0c9274d2020-10-08 04:17:37147} // namespace features
Takashi Sakamoto0044f2f2020-06-04 04:19:16148} // namespace base
149
Takashi Sakamoto1b5312d2021-10-18 08:53:46150#endif // BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_