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" |
Benoit Lize | bfe74a65 | 2021-04-02 04:54:04 | [diff] [blame] | 9 | #include "base/allocator/partition_allocator/partition_alloc_config.h" |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 10 | #include "base/base_export.h" |
Hans Wennborg | 133b1f5 | 2021-05-11 19:49:03 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
Anthony Vallee-Dubois | 9dbbbda3 | 2022-08-26 01:25:31 | [diff] [blame] | 12 | #include "base/feature_list.h" |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 13 | #include "base/metrics/field_trial_params.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 |
| 28 | // |
| 29 | // Usage: |
| 30 | // --enable-features=PartitionAllocDanglingPtr:mode/crash |
| 31 | // --enable-features=PartitionAllocDanglingPtr:mode/log_signature |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 32 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDanglingPtr); |
Arthur Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame] | 33 | enum class DanglingPtrMode { |
| 34 | // Crash immediately after detecting a dangling raw_ptr. |
| 35 | kCrash, // (default) |
| 36 | |
| 37 | // Log the signature of every occurrences without crashing. It is used by |
| 38 | // bots. |
| 39 | // Format "[DanglingSignature]\t<1>\t<2>" |
| 40 | // 1. The function who freed the memory while it was still referenced. |
| 41 | // 2. The function who released the raw_ptr reference. |
| 42 | kLogSignature, |
| 43 | |
| 44 | // Note: This will be extended with a single shot DumpWithoutCrashing. |
| 45 | }; |
| 46 | extern const BASE_EXPORT base::FeatureParam<DanglingPtrMode> |
| 47 | kDanglingPtrModeParam; |
| 48 | |
Bartek Nowierski | bba1846 | 2021-06-02 02:34:47 | [diff] [blame] | 49 | #if defined(PA_ALLOW_PCSCAN) |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 50 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScan); |
Bartek Nowierski | bba1846 | 2021-06-02 02:34:47 | [diff] [blame] | 51 | #endif // defined(PA_ALLOW_PCSCAN) |
Anton Bikineev | db908de | 2020-12-08 14:48:13 | [diff] [blame] | 52 | #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 53 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanBrowserOnly); |
| 54 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanRendererOnly); |
| 55 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtrControl); |
| 56 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeThreadCacheSize); |
| 57 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocLargeEmptySlotSpanRing); |
Sergei Glazunov | 7afc89b9 | 2022-05-31 19:31:29 | [diff] [blame] | 58 | #endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 59 | |
| 60 | enum class BackupRefPtrEnabledProcesses { |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 61 | // BRP enabled only in the browser process. |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 62 | kBrowserOnly, |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 63 | // BRP enabled only in the browser and renderer processes. |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 64 | kBrowserAndRenderer, |
Bartek Nowierski | 7668047 | 2021-12-09 17:58:25 | [diff] [blame] | 65 | // BRP enabled in all processes, except renderer. |
| 66 | kNonRenderer, |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 67 | // BRP enabled in all processes. |
| 68 | kAllProcesses, |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 69 | }; |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 70 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 71 | enum class BackupRefPtrMode { |
Bartek Nowierski | ea35aa52 | 2021-12-10 07:08:20 | [diff] [blame] | 72 | // BRP is disabled across all partitions. Equivalent to the Finch flag being |
| 73 | // disabled. |
| 74 | kDisabled, |
| 75 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 76 | // BRP is enabled in the main partition, as well as certain Renderer-only |
| 77 | // partitions (if enabled in Renderer at all). |
| 78 | // This entails splitting the main partition. |
| 79 | kEnabled, |
| 80 | |
Keishi Hattori | c384e2f | 2022-06-16 09:32:57 | [diff] [blame] | 81 | // Same as kEnabled but without zapping quarantined objects. |
| 82 | kEnabledWithoutZapping, |
| 83 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 84 | // BRP is disabled, but the main partition is split out, as if BRP was enabled |
| 85 | // in the "previous slot" mode. |
| 86 | kDisabledButSplitPartitions2Way, |
| 87 | |
| 88 | // BRP is disabled, but the main partition *and* aligned partition are split |
| 89 | // out, as if BRP was enabled in the "before allocation" mode. |
| 90 | kDisabledButSplitPartitions3Way, |
Keishi Hattori | a8fb2be | 2022-11-21 05:52:59 | [diff] [blame] | 91 | |
| 92 | // BRP is disabled, but add dummy ref count to each allocation. This will |
| 93 | // increase allocation size but not change any of the logic. If an issue |
| 94 | // reproduce in this mode, it means the increase in size is causing it. |
| 95 | kDisabledButAddDummyRefCount, |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 96 | }; |
| 97 | |
Thiabaud Engelbrecht | 05f8b811 | 2022-09-16 02:18:29 | [diff] [blame] | 98 | enum class AlternateBucketDistributionMode : uint8_t { |
| 99 | kDefault, |
| 100 | kCoarser, |
| 101 | kDenser, |
| 102 | }; |
| 103 | |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 104 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocBackupRefPtr); |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 105 | extern const BASE_EXPORT base::FeatureParam<BackupRefPtrEnabledProcesses> |
| 106 | kBackupRefPtrEnabledProcessesParam; |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 107 | extern const BASE_EXPORT base::FeatureParam<BackupRefPtrMode> |
| 108 | kBackupRefPtrModeParam; |
Sergei Glazunov | 7afc89b9 | 2022-05-31 19:31:29 | [diff] [blame] | 109 | extern const BASE_EXPORT base::FeatureParam<bool> |
| 110 | kBackupRefPtrAsanEnableDereferenceCheckParam; |
| 111 | extern const BASE_EXPORT base::FeatureParam<bool> |
| 112 | kBackupRefPtrAsanEnableExtractionCheckParam; |
| 113 | extern const BASE_EXPORT base::FeatureParam<bool> |
| 114 | kBackupRefPtrAsanEnableInstantiationCheckParam; |
Thiabaud Engelbrecht | 05f8b811 | 2022-09-16 02:18:29 | [diff] [blame] | 115 | extern const BASE_EXPORT base::FeatureParam<AlternateBucketDistributionMode> |
| 116 | kPartitionAllocAlternateBucketDistributionParam; |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 117 | |
Daniel Cheng | 0fff5c23 | 2022-09-21 17:43:34 | [diff] [blame] | 118 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanMUAwareScheduler); |
| 119 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanStackScanning); |
| 120 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocDCScan); |
| 121 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanImmediateFreeing); |
| 122 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocPCScanEagerClearing); |
| 123 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocSortActiveSlotSpans); |
| 124 | BASE_EXPORT BASE_DECLARE_FEATURE(kPartitionAllocUseAlternateDistribution); |
Benoit Lize | 7ebe3d4 | 2022-11-24 21:12:00 | [diff] [blame] | 125 | #if BUILDFLAG(IS_WIN) |
| 126 | BASE_EXPORT BASE_DECLARE_FEATURE(kPageAllocatorRetryOnCommitFailure); |
| 127 | #endif |
Michael Lippautz | d34f7b2c | 2021-04-21 08:32:26 | [diff] [blame] | 128 | |
Takashi Sakamoto | 0c9274d | 2020-10-08 04:17:37 | [diff] [blame] | 129 | } // namespace features |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 130 | } // namespace base |
| 131 | |
Takashi Sakamoto | 1b5312d | 2021-10-18 08:53:46 | [diff] [blame] | 132 | #endif // BASE_ALLOCATOR_PARTITION_ALLOC_FEATURES_H_ |