Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors. All rights reserved. |
| 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 | #include "base/allocator/partition_alloc_features.h" |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 6 | |
David Sanders | 6e70994 | 2022-04-05 06:49:26 | [diff] [blame] | 7 | #include "base/base_export.h" |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 8 | #include "base/feature_list.h" |
Benoit Lize | 2e4a8f6 | 2022-01-12 13:35:21 | [diff] [blame] | 9 | #include "build/build_config.h" |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 10 | |
| 11 | namespace base { |
Takashi Sakamoto | 0c9274d | 2020-10-08 04:17:37 | [diff] [blame] | 12 | namespace features { |
Takashi Sakamoto | 0044f2f | 2020-06-04 04:19:16 | [diff] [blame] | 13 | |
Arthur Sonzogni | be6f013 | 2022-07-06 13:54:12 | [diff] [blame^] | 14 | const BASE_EXPORT Feature kPartitionAllocDanglingPtr{ |
| 15 | "PartitionAllocDanglingPtr", FEATURE_DISABLED_BY_DEFAULT}; |
| 16 | constexpr FeatureParam<DanglingPtrMode>::Option kDanglingPtrModeOption[] = { |
| 17 | {DanglingPtrMode::kCrash, "crash"}, |
| 18 | {DanglingPtrMode::kLogSignature, "log_signature"}, |
| 19 | }; |
| 20 | const base::FeatureParam<DanglingPtrMode> kDanglingPtrModeParam{ |
| 21 | &kPartitionAllocDanglingPtr, |
| 22 | "mode", |
| 23 | DanglingPtrMode::kCrash, |
| 24 | &kDanglingPtrModeOption, |
| 25 | }; |
| 26 | |
Bartek Nowierski | bba1846 | 2021-06-02 02:34:47 | [diff] [blame] | 27 | #if defined(PA_ALLOW_PCSCAN) |
Anton Bikineev | 9d8b21b | 2020-10-09 08:11:58 | [diff] [blame] | 28 | // If enabled, PCScan is turned on by default for all partitions that don't |
| 29 | // disable it explicitly. |
| 30 | const Feature kPartitionAllocPCScan{"PartitionAllocPCScan", |
| 31 | FEATURE_DISABLED_BY_DEFAULT}; |
Bartek Nowierski | bba1846 | 2021-06-02 02:34:47 | [diff] [blame] | 32 | #endif // defined(PA_ALLOW_PCSCAN) |
Anton Bikineev | 9d8b21b | 2020-10-09 08:11:58 | [diff] [blame] | 33 | |
Anton Bikineev | db908de | 2020-12-08 14:48:13 | [diff] [blame] | 34 | #if BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) |
| 35 | // If enabled, PCScan is turned on only for the browser's malloc partition. |
| 36 | const Feature kPartitionAllocPCScanBrowserOnly{ |
| 37 | "PartitionAllocPCScanBrowserOnly", FEATURE_DISABLED_BY_DEFAULT}; |
Benoit Lize | 6ae0027 | 2021-02-25 15:56:53 | [diff] [blame] | 38 | |
Anton Bikineev | d250933 | 2021-09-16 17:14:57 | [diff] [blame] | 39 | // If enabled, PCScan is turned on only for the renderer's malloc partition. |
| 40 | const Feature kPartitionAllocPCScanRendererOnly{ |
| 41 | "PartitionAllocPCScanRendererOnly", FEATURE_DISABLED_BY_DEFAULT}; |
| 42 | |
Bartek Nowierski | d2d35f9 | 2021-04-22 21:36:39 | [diff] [blame] | 43 | // If enabled, this instance belongs to the Control group of the BackupRefPtr |
| 44 | // binary experiment. |
| 45 | const Feature kPartitionAllocBackupRefPtrControl{ |
| 46 | "PartitionAllocBackupRefPtrControl", FEATURE_DISABLED_BY_DEFAULT}; |
| 47 | |
Benoit Lize | 006cfcb | 2021-03-29 16:18:52 | [diff] [blame] | 48 | // Use a larger maximum thread cache cacheable bucket size. |
| 49 | const Feature kPartitionAllocLargeThreadCacheSize{ |
Benoit Lize | 2e4a8f6 | 2022-01-12 13:35:21 | [diff] [blame] | 50 | "PartitionAllocLargeThreadCacheSize", |
Xiaohan Wang | 617a9a5f | 2022-01-15 19:23:01 | [diff] [blame] | 51 | #if BUILDFLAG(IS_ANDROID) && defined(ARCH_CPU_32_BITS) |
Benoit Lize | 2e4a8f6 | 2022-01-12 13:35:21 | [diff] [blame] | 52 | // Not unconditionally enabled on 32 bit Android, since it is a more |
| 53 | // memory-constrained platform. |
| 54 | FEATURE_DISABLED_BY_DEFAULT |
| 55 | #else |
| 56 | FEATURE_ENABLED_BY_DEFAULT |
| 57 | #endif |
| 58 | }; |
Benoit Lize | 006cfcb | 2021-03-29 16:18:52 | [diff] [blame] | 59 | |
Benoit Lize | f13d793 | 2022-01-07 10:29:32 | [diff] [blame] | 60 | const BASE_EXPORT Feature kPartitionAllocLargeEmptySlotSpanRing{ |
| 61 | "PartitionAllocLargeEmptySlotSpanRing", FEATURE_DISABLED_BY_DEFAULT}; |
Sergei Glazunov | 7afc89b9 | 2022-05-31 19:31:29 | [diff] [blame] | 62 | #endif // BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) |
Benoit Lize | f13d793 | 2022-01-07 10:29:32 | [diff] [blame] | 63 | |
Keishi Hattori | ebb719d | 2022-05-13 09:40:30 | [diff] [blame] | 64 | const Feature kPartitionAllocBackupRefPtr { |
| 65 | "PartitionAllocBackupRefPtr", |
Sergei Glazunov | 38f07f6 | 2022-06-15 09:45:58 | [diff] [blame] | 66 | #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_WIN) || \ |
| 67 | (BUILDFLAG(USE_ASAN_BACKUP_REF_PTR) && BUILDFLAG(IS_LINUX)) |
Keishi Hattori | ebb719d | 2022-05-13 09:40:30 | [diff] [blame] | 68 | FEATURE_ENABLED_BY_DEFAULT |
| 69 | #else |
| 70 | FEATURE_DISABLED_BY_DEFAULT |
| 71 | #endif |
| 72 | }; |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 73 | |
| 74 | constexpr FeatureParam<BackupRefPtrEnabledProcesses>::Option |
| 75 | kBackupRefPtrEnabledProcessesOptions[] = { |
| 76 | {BackupRefPtrEnabledProcesses::kBrowserOnly, "browser-only"}, |
| 77 | {BackupRefPtrEnabledProcesses::kBrowserAndRenderer, |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 78 | "browser-and-renderer"}, |
Bartek Nowierski | 7668047 | 2021-12-09 17:58:25 | [diff] [blame] | 79 | {BackupRefPtrEnabledProcesses::kNonRenderer, "non-renderer"}, |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 80 | {BackupRefPtrEnabledProcesses::kAllProcesses, "all-processes"}}; |
Keishi Hattori | af499ac | 2021-09-22 23:45:04 | [diff] [blame] | 81 | |
| 82 | const base::FeatureParam<BackupRefPtrEnabledProcesses> |
| 83 | kBackupRefPtrEnabledProcessesParam{ |
| 84 | &kPartitionAllocBackupRefPtr, "enabled-processes", |
| 85 | BackupRefPtrEnabledProcesses::kBrowserOnly, |
| 86 | &kBackupRefPtrEnabledProcessesOptions}; |
| 87 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 88 | constexpr FeatureParam<BackupRefPtrMode>::Option kBackupRefPtrModeOptions[] = { |
Bartek Nowierski | ea35aa52 | 2021-12-10 07:08:20 | [diff] [blame] | 89 | {BackupRefPtrMode::kDisabled, "disabled"}, |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 90 | {BackupRefPtrMode::kEnabled, "enabled"}, |
Keishi Hattori | c384e2f | 2022-06-16 09:32:57 | [diff] [blame] | 91 | {BackupRefPtrMode::kEnabledWithoutZapping, "enabled-without-zapping"}, |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 92 | {BackupRefPtrMode::kDisabledButSplitPartitions2Way, |
| 93 | "disabled-but-2-way-split"}, |
| 94 | {BackupRefPtrMode::kDisabledButSplitPartitions3Way, |
| 95 | "disabled-but-3-way-split"}, |
| 96 | }; |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 97 | |
Bartek Nowierski | da7d8f1c | 2021-12-08 19:30:59 | [diff] [blame] | 98 | const base::FeatureParam<BackupRefPtrMode> kBackupRefPtrModeParam{ |
| 99 | &kPartitionAllocBackupRefPtr, "brp-mode", BackupRefPtrMode::kEnabled, |
| 100 | &kBackupRefPtrModeOptions}; |
Bartek Nowierski | e9ad8a7d | 2021-11-04 08:37:39 | [diff] [blame] | 101 | |
Sergei Glazunov | 7afc89b9 | 2022-05-31 19:31:29 | [diff] [blame] | 102 | const base::FeatureParam<bool> kBackupRefPtrAsanEnableDereferenceCheckParam{ |
| 103 | &kPartitionAllocBackupRefPtr, "asan-enable-dereference-check", true}; |
| 104 | const base::FeatureParam<bool> kBackupRefPtrAsanEnableExtractionCheckParam{ |
| 105 | &kPartitionAllocBackupRefPtr, "asan-enable-extraction-check", |
| 106 | false}; // Not much noise at the moment to enable by default. |
| 107 | const base::FeatureParam<bool> kBackupRefPtrAsanEnableInstantiationCheckParam{ |
| 108 | &kPartitionAllocBackupRefPtr, "asan-enable-instantiation-check", true}; |
Anton Bikineev | db908de | 2020-12-08 14:48:13 | [diff] [blame] | 109 | |
Thiabaud Engelbrecht | 1efe437 | 2022-02-16 19:33:09 | [diff] [blame] | 110 | // If enabled, switches the bucket distribution to an alternate one. The |
| 111 | // alternate distribution must have buckets that are a subset of the default |
| 112 | // one. |
| 113 | const Feature kPartitionAllocUseAlternateDistribution{ |
| 114 | "PartitionAllocUseAlternateDistribution", FEATURE_DISABLED_BY_DEFAULT}; |
| 115 | |
Michael Lippautz | d34f7b2c | 2021-04-21 08:32:26 | [diff] [blame] | 116 | // If enabled, switches PCScan scheduling to a mutator-aware scheduler. Does not |
| 117 | // affect whether PCScan is enabled itself. |
| 118 | const Feature kPartitionAllocPCScanMUAwareScheduler{ |
| 119 | "PartitionAllocPCScanMUAwareScheduler", FEATURE_ENABLED_BY_DEFAULT}; |
| 120 | |
Hannes Payer | a33df7f | 2021-06-22 18:44:14 | [diff] [blame] | 121 | // If enabled, PCScan frees unconditionally all quarantined objects. |
| 122 | // This is a performance testing feature. |
| 123 | const Feature kPartitionAllocPCScanImmediateFreeing{ |
| 124 | "PartitionAllocPCScanImmediateFreeing", FEATURE_DISABLED_BY_DEFAULT}; |
| 125 | |
Anton Bikineev | 7f11c21 | 2021-08-24 12:03:09 | [diff] [blame] | 126 | // If enabled, PCScan clears eagerly (synchronously) on free(). |
| 127 | const Feature kPartitionAllocPCScanEagerClearing{ |
| 128 | "PartitionAllocPCScanEagerClearing", FEATURE_DISABLED_BY_DEFAULT}; |
| 129 | |
Anton Bikineev | ea8859b | 2021-04-29 19:17:22 | [diff] [blame] | 130 | // In addition to heap, scan also the stack of the current mutator. |
| 131 | const Feature kPartitionAllocPCScanStackScanning { |
| 132 | "PartitionAllocPCScanStackScanning", |
| 133 | #if defined(PA_PCSCAN_STACK_SUPPORTED) |
| 134 | FEATURE_ENABLED_BY_DEFAULT |
| 135 | #else |
| 136 | FEATURE_DISABLED_BY_DEFAULT |
| 137 | #endif // defined(PA_PCSCAN_STACK_SUPPORTED) |
| 138 | }; |
| 139 | |
Anton Bikineev | 6b5ab95 | 2021-05-19 23:57:57 | [diff] [blame] | 140 | const Feature kPartitionAllocDCScan{"PartitionAllocDCScan", |
| 141 | FEATURE_DISABLED_BY_DEFAULT}; |
| 142 | |
Benoit Lize | c9ec6149 | 2022-05-20 10:51:25 | [diff] [blame] | 143 | // Whether to sort the active slot spans in PurgeMemory(). |
| 144 | extern const Feature kPartitionAllocSortActiveSlotSpans{ |
| 145 | "PartitionAllocSortActiveSlotSpans", FEATURE_DISABLED_BY_DEFAULT}; |
| 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 |