Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame^] | 1 | # Copyright 2019 The Chromium Authors |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [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 | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 5 | import("//base/allocator/partition_allocator/partition_alloc.gni") |
Rob Hueber | 336a5ae | 2019-09-10 21:43:05 | [diff] [blame] | 6 | import("//build/config/chromecast_build.gni") |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 7 | import("//build/config/sanitizers/sanitizers.gni") |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 8 | import("//build_overrides/partition_alloc.gni") |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 9 | |
Ali Juma | 50a1938 | 2021-09-20 21:25:23 | [diff] [blame] | 10 | if (is_ios) { |
| 11 | import("//build/config/ios/ios_sdk.gni") |
| 12 | } |
| 13 | |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 14 | declare_args() { |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 15 | # Causes all the allocations to be routed via allocator_shim.cc. |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 16 | use_allocator_shim = use_allocator_shim_default |
Yuki Shiino | 24622fa | 2020-08-26 12:01:02 | [diff] [blame] | 17 | |
Yuki Shiino | 90d5fe68 | 2020-09-02 11:03:51 | [diff] [blame] | 18 | # Whether PartitionAlloc should be available for use or not. |
| 19 | # true makes PartitionAlloc linked to the executable or shared library and |
Bartek Nowierski | 974b49b | 2022-02-03 04:29:09 | [diff] [blame] | 20 | # makes it available for use. It doesn't mean that the default allocator |
| 21 | # is PartitionAlloc, which is governed by |use_allocator|. |
Yuki Shiino | 90d5fe68 | 2020-09-02 11:03:51 | [diff] [blame] | 22 | # |
Bartek Nowierski | 974b49b | 2022-02-03 04:29:09 | [diff] [blame] | 23 | # This flag is currently set to false only on Cronet bots, because Cronet |
| 24 | # doesn't use PartitionAlloc at all, and doesn't wish to incur the library |
| 25 | # size increase (crbug.com/674570). |
| 26 | use_partition_alloc = true |
Yuki Shiino | 90d5fe68 | 2020-09-02 11:03:51 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | if (!use_partition_alloc && use_allocator == "partition") { |
| 30 | # If there is a conflict, prioritize |use_partition_alloc| over |
| 31 | # |use_allocator|. |
| 32 | use_allocator = "none" |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 33 | } |
| 34 | |
Benoit Lize | f4e1472 | 2022-01-12 10:56:52 | [diff] [blame] | 35 | assert(use_allocator == "none" || use_allocator == "partition") |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 36 | |
Rohit Rao | 849b426 | 2020-05-01 19:10:34 | [diff] [blame] | 37 | assert( |
Yuki Shiino | 24622fa | 2020-08-26 12:01:02 | [diff] [blame] | 38 | !use_allocator_shim || is_linux || is_chromeos || is_android || is_win || |
Kevin Marshall | 64a82a9 | 2021-09-08 20:49:45 | [diff] [blame] | 39 | is_fuchsia || is_apple, |
| 40 | "use_allocator_shim works only on Android, iOS, Linux, macOS, Fuchsia, " + |
| 41 | "and Windows.") |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 42 | |
Moe Ahmadi | a36d801a | 2021-08-30 22:30:53 | [diff] [blame] | 43 | if (is_win && use_allocator_shim) { |
Kevin Marshall | 64a82a9 | 2021-09-08 20:49:45 | [diff] [blame] | 44 | # TODO(crbug.com/1245317): Add a comment indicating why the shim doesn't work. |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 45 | assert(!is_component_build, |
Moe Ahmadi | a36d801a | 2021-08-30 22:30:53 | [diff] [blame] | 46 | "The allocator shim doesn't work for the component build on Windows.") |
Nico Weber | b80b085 | 2019-08-01 22:03:01 | [diff] [blame] | 47 | } |
Bartek Nowierski | ceb2fb3 | 2021-05-26 15:09:05 | [diff] [blame] | 48 | |
Kalvin Lee | ecf3a88 | 2022-07-22 15:10:47 | [diff] [blame] | 49 | declare_args() { |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 50 | # If we use PartitionAlloc as default allocator and enable its MTECheckedPtr |
| 51 | # support as default, we can use_mte_checked_ptr=true as default. |
| 52 | use_mte_checked_ptr = enable_mte_checked_ptr_support_default && |
| 53 | use_partition_alloc && use_allocator == "partition" |
Kalvin Lee | ecf3a88 | 2022-07-22 15:10:47 | [diff] [blame] | 54 | } |
| 55 | |
Keishi Hattori | 01d5ac8fe | 2021-11-26 23:59:14 | [diff] [blame] | 56 | declare_args() { |
| 57 | # Set use_backup_ref_ptr true to use BackupRefPtr (BRP) as the implementation |
| 58 | # of raw_ptr<T>, and enable PartitionAlloc support for it. |
Kalvin Lee | ecf3a88 | 2022-07-22 15:10:47 | [diff] [blame] | 59 | # We also disable BRP in the presence of MTECheckedPtr, which is almost |
| 60 | # never enabled. |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 61 | use_backup_ref_ptr = enable_backup_ref_ptr_support_default && |
| 62 | use_partition_alloc && use_allocator == "partition" |
Kalvin Lee | 6f79e39 | 2022-02-18 18:55:50 | [diff] [blame] | 63 | } |
Keishi Hattori | 01d5ac8fe | 2021-11-26 23:59:14 | [diff] [blame] | 64 | |
Takashi Sakamoto | 7fdb169 | 2022-08-26 08:17:58 | [diff] [blame] | 65 | assert(!use_backup_ref_ptr || enable_backup_ref_ptr_support, |
| 66 | "BackupRefPtr needs enable_backup_ref_ptr_support.") |
| 67 | |
| 68 | assert(!use_mte_checked_ptr || enable_mte_checked_ptr_support, |
| 69 | "MTECheckedPtr needs enable_mte_checked_ptr_support.") |
| 70 | |
Kalvin Lee | 240f4d1 | 2022-03-21 22:35:19 | [diff] [blame] | 71 | assert(!(use_backup_ref_ptr && use_mte_checked_ptr), |
| 72 | "MTECheckedPtr conflicts with BRP.") |
| 73 | |
Kalvin Lee | 6f79e39 | 2022-02-18 18:55:50 | [diff] [blame] | 74 | declare_args() { |
Sergei Glazunov | 38f07f6 | 2022-06-15 09:45:58 | [diff] [blame] | 75 | # The supported platforms are supposed to match `_is_brp_supported`, but we |
| 76 | # enable the feature on Linux early because it's most widely used for security |
| 77 | # research |
| 78 | use_asan_backup_ref_ptr = is_asan && (is_win || is_android || is_linux) |
Keishi Hattori | 01d5ac8fe | 2021-11-26 23:59:14 | [diff] [blame] | 79 | } |
| 80 | |
Bartek Nowierski | ceb2fb3 | 2021-05-26 15:09:05 | [diff] [blame] | 81 | # Prevent using BackupRefPtr when PartitionAlloc-Everywhere isn't used. |
| 82 | # In theory, such a configuration is possible, but its scope would be limited to |
| 83 | # only Blink partitions, which is currently not tested. Better to trigger an |
| 84 | # error, than have BackupRefPtr silently disabled while believing it is enabled. |
| 85 | if (!is_nacl) { |
| 86 | assert(!use_backup_ref_ptr || use_allocator == "partition", |
| 87 | "Can't use BackupRefPtr without PartitionAlloc-Everywhere") |
| 88 | } |
| 89 | |
Sergei Glazunov | 017ec4e8 | 2022-01-26 11:50:49 | [diff] [blame] | 90 | # BackupRefPtr and AsanBackupRefPtr are mutually exclusive variants of raw_ptr. |
| 91 | assert( |
| 92 | !use_backup_ref_ptr || !use_asan_backup_ref_ptr, |
| 93 | "Both BackupRefPtr and AsanBackupRefPtr can't be enabled at the same time") |
| 94 | |
| 95 | assert(!use_asan_backup_ref_ptr || is_asan, |
| 96 | "AsanBackupRefPtr requires AddressSanitizer") |