Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Takashi Sakamoto | 1b5312d | 2021-10-18 08:53:46 | [diff] [blame] | 5 | #ifndef BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_ |
| 6 | #define BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_ |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 7 | |
Bartek Nowierski | d5d1984a | 2022-12-18 12:13:15 | [diff] [blame] | 8 | #include "base/allocator/partition_allocator/partition_alloc_buildflags.h" |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 9 | #include "base/base_export.h" |
Hans Wennborg | 133b1f5 | 2021-05-11 19:49:03 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
Anthony Vallee-Dubois | 9dbbbda3 | 2022-08-26 01:25:31 | [diff] [blame] | 11 | #include "base/feature_list.h" |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 12 | #include "base/metrics/field_trial_params.h" |
Kalvin Lee | ac8c7191 | 2023-05-17 06:17:29 | [diff] [blame] | 13 | #include "base/strings/string_piece.h" |
Benoit Lize | 7ebe3d4 | 2022-11-24 21:12:00 | [diff] [blame] | 14 | #include "build/build_config.h" |
Takashi Sakamoto | 3f767cdd | 2020-08-20 08:37:31 | [diff] [blame] | 15 | |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 16 | namespace base { |
Takashi Sakamoto | 0c9274d | 2020-10-08 04:17:37 | [diff] [blame] | 17 | namespace features { |
| 18 | |
Paul Semel | b0ce484 | 2022-09-28 08:09:53 | [diff] [blame] | 19 | extern const BASE_EXPORT Feature kPartitionAllocUnretainedDanglingPtr; |
| 20 | enum class UnretainedDanglingPtrMode { |
| 21 | kCrash, |
| 22 | kDumpWithoutCrashing, |
| 23 | }; |
| 24 | extern const BASE_EXPORT base::FeatureParam<UnretainedDanglingPtrMode> |
| 25 | kUnretainedDanglingPtrModeParam; |
| 26 | |
Arthur Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 27 | // See /docs/dangling_ptr.md |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 28 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDanglingPtr); |
Arthur Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 29 | enum 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âris | e90af2c | 2023-01-30 14:22:41 | [diff] [blame] | 35 | // 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 Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 41 | |
| 42 | // Note: This will be extended with a single shot DumpWithoutCrashing. |
| 43 | }; |
| 44 | extern const BASE_EXPORT base::FeatureParam<DanglingPtrMode> |
| 45 | kDanglingPtrModeParam; |
Pâris | e90af2c | 2023-01-30 14:22:41 | [diff] [blame] | 46 | enum 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 | }; |
| 56 | extern const BASE_EXPORT base::FeatureParam<DanglingPtrType> |
| 57 | kDanglingPtrTypeParam; |
Arthur Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 58 | |
Bartek Nowierski | bc01b711 | 2023-02-01 14:11:42 | [diff] [blame] | 59 | #if BUILDFLAG(USE_STARSCAN) |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 60 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScan); |
Bartek Nowierski | bc01b711 | 2023-02-01 14:11:42 | [diff] [blame] | 61 | #endif |
Anton Bikineev | db908de | 2020-12-08 14:48:13 | [diff] [blame] | 62 | #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 63 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanBrowserOnly); |
| 64 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanRendererOnly); |
| 65 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtrControl); |
| 66 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeThreadCacheSize); |
| 67 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeEmptySlotSpanRing); |
Sergei Glazunov | 7afc89b9 | 2022-05-31 19:31:29 | [diff] [blame] | 68 | #endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 69 | |
| 70 | enum class BackupRefPtrEnabledProcesses { |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 71 | // BRP enabled only in the browser process. |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 72 | kBrowserOnly, |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 73 | // BRP enabled only in the browser and renderer processes. |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 74 | kBrowserAndRenderer, |
Bartek Nowierski | 7668047 | 2021-12-09 17:58:25 | [diff] [blame] | 75 | // BRP enabled in all processes, except renderer. |
| 76 | kNonRenderer, |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 77 | // BRP enabled in all processes. |
| 78 | kAllProcesses, |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 79 | }; |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 80 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 81 | enum class BackupRefPtrMode { |
Bartek Nowierski | ea35aa52 | 2021-12-10 07:08:20 | [diff] [blame] | 82 | // BRP is disabled across all partitions. Equivalent to the Finch flag being |
| 83 | // disabled. |
| 84 | kDisabled, |
| 85 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 86 | // 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 Hattori | c384e2f | 2022-06-16 09:32:57 | [diff] [blame] | 91 | // Same as kEnabled but without zapping quarantined objects. |
| 92 | kEnabledWithoutZapping, |
| 93 | |
Keishi Hattori | 7381718 | 2023-04-13 07:06:03 | [diff] [blame] | 94 | // Same as kEnabled but registers the main partition to memory reclaimer. |
| 95 | kEnabledWithMemoryReclaimer, |
Keishi Hattori | dbf9240 | 2023-04-07 12:22:30 | [diff] [blame] | 96 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 97 | // 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 Hattori | 7381718 | 2023-04-13 07:06:03 | [diff] [blame] | 101 | // Same as kDisabledButSplitPartitions2Way but registers the main partition to |
| 102 | // memory reclaimer. |
| 103 | kDisabledButSplitPartitions2WayWithMemoryReclaimer, |
| 104 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 105 | // 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 Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 108 | }; |
| 109 | |
Bartek Nowierski | f726420 | 2023-05-17 00:23:52 | [diff] [blame] | 110 | // 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. |
| 112 | enum 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 Engelbrecht | 05f8b811 | 2022-09-16 02:18:29 | [diff] [blame] | 126 | enum class AlternateBucketDistributionMode : uint8_t { |
| 127 | kDefault, |
Thiabaud Engelbrecht | 05f8b811 | 2022-09-16 02:18:29 | [diff] [blame] | 128 | kDenser, |
| 129 | }; |
| 130 | |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 131 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtr); |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 132 | extern const BASE_EXPORT base::FeatureParam<BackupRefPtrEnabledProcesses> |
| 133 | kBackupRefPtrEnabledProcessesParam; |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 134 | extern const BASE_EXPORT base::FeatureParam<BackupRefPtrMode> |
| 135 | kBackupRefPtrModeParam; |
Bartek Nowierski | f726420 | 2023-05-17 00:23:52 | [diff] [blame] | 136 | extern const BASE_EXPORT base::FeatureParam<BackupRefPtrRefCountSize> |
| 137 | kBackupRefPtrRefCountSizeParam; |
Sergei Glazunov | 7afc89b9 | 2022-05-31 19:31:29 | [diff] [blame] | 138 | extern const BASE_EXPORT base::FeatureParam<bool> |
| 139 | kBackupRefPtrAsanEnableDereferenceCheckParam; |
| 140 | extern const BASE_EXPORT base::FeatureParam<bool> |
| 141 | kBackupRefPtrAsanEnableExtractionCheckParam; |
| 142 | extern const BASE_EXPORT base::FeatureParam<bool> |
| 143 | kBackupRefPtrAsanEnableInstantiationCheckParam; |
Thiabaud Engelbrecht | 05f8b811 | 2022-09-16 02:18:29 | [diff] [blame] | 144 | extern const BASE_EXPORT base::FeatureParam<AlternateBucketDistributionMode> |
| 145 | kPartitionAllocAlternateBucketDistributionParam; |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 146 | |
Bartek Nowierski | dd71552 | 2023-05-04 11:13:44 | [diff] [blame] | 147 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtrForAsh); |
| 148 | |
Arthur Sonzogni | a57023635 | 2022-12-19 13:18:54 | [diff] [blame] | 149 | BASE_EXPORT BASE_DECLARE_FEATURE(kLowerPAMemoryLimitForNonMainRenderers); |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 150 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanMUAwareScheduler); |
| 151 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanStackScanning); |
| 152 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDCScan); |
| 153 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanImmediateFreeing); |
| 154 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanEagerClearing); |
| 155 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocSortActiveSlotSpans); |
| 156 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocUseAlternateDistribution); |
Benoit Lize | 7ebe3d4 | 2022-11-24 21:12:00 | [diff] [blame] | 157 | #if BUILDFLAG(IS_WIN) |
| 158 | BASE_EXPORT BASE_DECLARE_FEATURE(kPageAllocatorRetryOnCommitFailure); |
| 159 | #endif |
Michael Lippautz | d34f7b2c | 2021-04-21 08:32:26 | [diff] [blame] | 160 | |
Kalvin Lee | ac8c7191 | 2023-05-17 06:17:29 | [diff] [blame] | 161 | // Name of the synthetic trial associated with forcibly enabling BRP in |
| 162 | // all processes. |
| 163 | inline constexpr base::StringPiece kRendererLiveBRPSyntheticTrialName = |
| 164 | "BackupRefPtrRendererLive"; |
| 165 | |
Takashi Sakamoto | 0c9274d | 2020-10-08 04:17:37 | [diff] [blame] | 166 | } // namespace features |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 167 | } // namespace base |
| 168 | |
Takashi Sakamoto | 1b5312d | 2021-10-18 08:53:46 | [diff] [blame] | 169 | #endif // BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_ |