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