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" |
Benoit Lize | 7ebe3d4 | 2022-11-24 21:12:00 | [diff] [blame] | 13 | #include "build/build_config.h" |
Takashi Sakamoto | 3f767cdd | 2020-08-20 08:37:31 | [diff] [blame] | 14 | |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 15 | namespace base { |
Takashi Sakamoto | 0c9274d | 2020-10-08 04:17:37 | [diff] [blame] | 16 | namespace features { |
| 17 | |
Paul Semel | b0ce484 | 2022-09-28 08:09:53 | [diff] [blame] | 18 | extern const BASE_EXPORT Feature kPartitionAllocUnretainedDanglingPtr; |
| 19 | enum class UnretainedDanglingPtrMode { |
| 20 | kCrash, |
| 21 | kDumpWithoutCrashing, |
| 22 | }; |
| 23 | extern const BASE_EXPORT base::FeatureParam<UnretainedDanglingPtrMode> |
| 24 | kUnretainedDanglingPtrModeParam; |
| 25 | |
Arthur Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 26 | // See /docs/dangling_ptr.md |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 27 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDanglingPtr); |
Arthur Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 28 | enum 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âris | e90af2c | 2023-01-30 14:22:41 | [diff] [blame] | 34 | // 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 Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 40 | |
| 41 | // Note: This will be extended with a single shot DumpWithoutCrashing. |
| 42 | }; |
| 43 | extern const BASE_EXPORT base::FeatureParam<DanglingPtrMode> |
| 44 | kDanglingPtrModeParam; |
Pâris | e90af2c | 2023-01-30 14:22:41 | [diff] [blame] | 45 | enum 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 | }; |
| 55 | extern const BASE_EXPORT base::FeatureParam<DanglingPtrType> |
| 56 | kDanglingPtrTypeParam; |
Arthur Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 57 | |
Bartek Nowierski | bc01b711 | 2023-02-01 14:11:42 | [diff] [blame] | 58 | #if BUILDFLAG(USE_STARSCAN) |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 59 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScan); |
Bartek Nowierski | bc01b711 | 2023-02-01 14:11:42 | [diff] [blame] | 60 | #endif |
Anton Bikineev | db908de | 2020-12-08 14:48:13 | [diff] [blame] | 61 | #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 62 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanBrowserOnly); |
| 63 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanRendererOnly); |
| 64 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtrControl); |
| 65 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeThreadCacheSize); |
| 66 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeEmptySlotSpanRing); |
Sergei Glazunov | 7afc89b9 | 2022-05-31 19:31:29 | [diff] [blame] | 67 | #endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 68 | |
| 69 | enum class BackupRefPtrEnabledProcesses { |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 70 | // BRP enabled only in the browser process. |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 71 | kBrowserOnly, |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 72 | // BRP enabled only in the browser and renderer processes. |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 73 | kBrowserAndRenderer, |
Bartek Nowierski | 7668047 | 2021-12-09 17:58:25 | [diff] [blame] | 74 | // BRP enabled in all processes, except renderer. |
| 75 | kNonRenderer, |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 76 | // BRP enabled in all processes. |
| 77 | kAllProcesses, |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 78 | }; |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 79 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 80 | enum class BackupRefPtrMode { |
Bartek Nowierski | ea35aa52 | 2021-12-10 07:08:20 | [diff] [blame] | 81 | // BRP is disabled across all partitions. Equivalent to the Finch flag being |
| 82 | // disabled. |
| 83 | kDisabled, |
| 84 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 85 | // 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 Hattori | c384e2f | 2022-06-16 09:32:57 | [diff] [blame] | 90 | // Same as kEnabled but without zapping quarantined objects. |
| 91 | kEnabledWithoutZapping, |
| 92 | |
Keishi Hattori | 7381718 | 2023-04-13 07:06:03 | [diff] [blame] | 93 | // Same as kEnabled but registers the main partition to memory reclaimer. |
| 94 | kEnabledWithMemoryReclaimer, |
Keishi Hattori | dbf9240 | 2023-04-07 12:22:30 | [diff] [blame] | 95 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 96 | // 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 Hattori | 7381718 | 2023-04-13 07:06:03 | [diff] [blame] | 100 | // Same as kDisabledButSplitPartitions2Way but registers the main partition to |
| 101 | // memory reclaimer. |
| 102 | kDisabledButSplitPartitions2WayWithMemoryReclaimer, |
| 103 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 104 | // 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 Hattori | a8fb2be | 2022-11-21 05:52:59 | [diff] [blame] | 107 | |
| 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 Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 112 | }; |
| 113 | |
Thiabaud Engelbrecht | 05f8b811 | 2022-09-16 02:18:29 | [diff] [blame] | 114 | enum class AlternateBucketDistributionMode : uint8_t { |
| 115 | kDefault, |
Thiabaud Engelbrecht | 05f8b811 | 2022-09-16 02:18:29 | [diff] [blame] | 116 | kDenser, |
| 117 | }; |
| 118 | |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 119 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtr); |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 120 | extern const BASE_EXPORT base::FeatureParam<BackupRefPtrEnabledProcesses> |
| 121 | kBackupRefPtrEnabledProcessesParam; |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 122 | extern const BASE_EXPORT base::FeatureParam<BackupRefPtrMode> |
| 123 | kBackupRefPtrModeParam; |
Sergei Glazunov | 7afc89b9 | 2022-05-31 19:31:29 | [diff] [blame] | 124 | extern const BASE_EXPORT base::FeatureParam<bool> |
| 125 | kBackupRefPtrAsanEnableDereferenceCheckParam; |
| 126 | extern const BASE_EXPORT base::FeatureParam<bool> |
| 127 | kBackupRefPtrAsanEnableExtractionCheckParam; |
| 128 | extern const BASE_EXPORT base::FeatureParam<bool> |
| 129 | kBackupRefPtrAsanEnableInstantiationCheckParam; |
Thiabaud Engelbrecht | 05f8b811 | 2022-09-16 02:18:29 | [diff] [blame] | 130 | extern const BASE_EXPORT base::FeatureParam<AlternateBucketDistributionMode> |
| 131 | kPartitionAllocAlternateBucketDistributionParam; |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 132 | |
Bartek Nowierski | dd71552 | 2023-05-04 11:13:44 | [diff] [blame^] | 133 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtrForAsh); |
| 134 | |
Arthur Sonzogni | a57023635 | 2022-12-19 13:18:54 | [diff] [blame] | 135 | BASE_EXPORT BASE_DECLARE_FEATURE(kLowerPAMemoryLimitForNonMainRenderers); |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 136 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanMUAwareScheduler); |
| 137 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanStackScanning); |
| 138 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDCScan); |
| 139 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanImmediateFreeing); |
| 140 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanEagerClearing); |
| 141 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocSortActiveSlotSpans); |
| 142 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocUseAlternateDistribution); |
Benoit Lize | 7ebe3d4 | 2022-11-24 21:12:00 | [diff] [blame] | 143 | #if BUILDFLAG(IS_WIN) |
| 144 | BASE_EXPORT BASE_DECLARE_FEATURE(kPageAllocatorRetryOnCommitFailure); |
| 145 | #endif |
Michael Lippautz | d34f7b2c | 2021-04-21 08:32:26 | [diff] [blame] | 146 | |
Takashi Sakamoto | 0c9274d | 2020-10-08 04:17:37 | [diff] [blame] | 147 | } // namespace features |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 148 | } // namespace base |
| 149 | |
Takashi Sakamoto | 1b5312d | 2021-10-18 08:53:46 | [diff] [blame] | 150 | #endif // BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_ |