blob: ec9b5505e32641e837d335eeeda2128039493ccb [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061# Copyright 2019 The Chromium Authors
Nico Weberb80b0852019-08-01 22:03:012# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Takashi Sakamoto7fdb1692022-08-26 08:17:585import("//base/allocator/partition_allocator/partition_alloc.gni")
Rob Hueber336a5ae2019-09-10 21:43:056import("//build/config/chromecast_build.gni")
Nico Weberb80b0852019-08-01 22:03:017import("//build/config/sanitizers/sanitizers.gni")
Takashi Sakamoto7fdb1692022-08-26 08:17:588import("//build_overrides/partition_alloc.gni")
Nico Weberb80b0852019-08-01 22:03:019
Ali Juma50a19382021-09-20 21:25:2310if (is_ios) {
11 import("//build/config/ios/ios_sdk.gni")
12}
13
Nico Weberb80b0852019-08-01 22:03:0114declare_args() {
Nico Weberb80b0852019-08-01 22:03:0115 # Causes all the allocations to be routed via allocator_shim.cc.
Takashi Sakamoto7fdb1692022-08-26 08:17:5816 use_allocator_shim = use_allocator_shim_default
Yuki Shiino24622fa2020-08-26 12:01:0217
Yuki Shiino90d5fe682020-09-02 11:03:5118 # Whether PartitionAlloc should be available for use or not.
19 # true makes PartitionAlloc linked to the executable or shared library and
Bartek Nowierski974b49b2022-02-03 04:29:0920 # makes it available for use. It doesn't mean that the default allocator
21 # is PartitionAlloc, which is governed by |use_allocator|.
Yuki Shiino90d5fe682020-09-02 11:03:5122 #
Bartek Nowierski974b49b2022-02-03 04:29:0923 # 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 Shiino90d5fe682020-09-02 11:03:5127}
28
29if (!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 Weberb80b0852019-08-01 22:03:0133}
34
Benoit Lizef4e14722022-01-12 10:56:5235assert(use_allocator == "none" || use_allocator == "partition")
Nico Weberb80b0852019-08-01 22:03:0136
Rohit Rao849b4262020-05-01 19:10:3437assert(
Yuki Shiino24622fa2020-08-26 12:01:0238 !use_allocator_shim || is_linux || is_chromeos || is_android || is_win ||
Kevin Marshall64a82a92021-09-08 20:49:4539 is_fuchsia || is_apple,
40 "use_allocator_shim works only on Android, iOS, Linux, macOS, Fuchsia, " +
41 "and Windows.")
Nico Weberb80b0852019-08-01 22:03:0142
Moe Ahmadia36d801a2021-08-30 22:30:5343if (is_win && use_allocator_shim) {
Kevin Marshall64a82a92021-09-08 20:49:4544 # TODO(crbug.com/1245317): Add a comment indicating why the shim doesn't work.
Nico Weberb80b0852019-08-01 22:03:0145 assert(!is_component_build,
Moe Ahmadia36d801a2021-08-30 22:30:5346 "The allocator shim doesn't work for the component build on Windows.")
Nico Weberb80b0852019-08-01 22:03:0147}
Bartek Nowierskiceb2fb32021-05-26 15:09:0548
Kalvin Leeecf3a882022-07-22 15:10:4749declare_args() {
Takashi Sakamoto7fdb1692022-08-26 08:17:5850 # 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 Leeecf3a882022-07-22 15:10:4754}
55
Keishi Hattori01d5ac8fe2021-11-26 23:59:1456declare_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 Leeecf3a882022-07-22 15:10:4759 # We also disable BRP in the presence of MTECheckedPtr, which is almost
60 # never enabled.
Takashi Sakamoto7fdb1692022-08-26 08:17:5861 use_backup_ref_ptr = enable_backup_ref_ptr_support_default &&
62 use_partition_alloc && use_allocator == "partition"
Kalvin Lee6f79e392022-02-18 18:55:5063}
Keishi Hattori01d5ac8fe2021-11-26 23:59:1464
Takashi Sakamoto7fdb1692022-08-26 08:17:5865assert(!use_backup_ref_ptr || enable_backup_ref_ptr_support,
66 "BackupRefPtr needs enable_backup_ref_ptr_support.")
67
68assert(!use_mte_checked_ptr || enable_mte_checked_ptr_support,
69 "MTECheckedPtr needs enable_mte_checked_ptr_support.")
70
Kalvin Lee240f4d12022-03-21 22:35:1971assert(!(use_backup_ref_ptr && use_mte_checked_ptr),
72 "MTECheckedPtr conflicts with BRP.")
73
Kalvin Lee6f79e392022-02-18 18:55:5074declare_args() {
Sergei Glazunov38f07f62022-06-15 09:45:5875 # 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 Hattori01d5ac8fe2021-11-26 23:59:1479}
80
Bartek Nowierskiceb2fb32021-05-26 15:09:0581# 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.
85if (!is_nacl) {
86 assert(!use_backup_ref_ptr || use_allocator == "partition",
87 "Can't use BackupRefPtr without PartitionAlloc-Everywhere")
88}
89
Sergei Glazunov017ec4e82022-01-26 11:50:4990# BackupRefPtr and AsanBackupRefPtr are mutually exclusive variants of raw_ptr.
91assert(
92 !use_backup_ref_ptr || !use_asan_backup_ref_ptr,
93 "Both BackupRefPtr and AsanBackupRefPtr can't be enabled at the same time")
94
95assert(!use_asan_backup_ref_ptr || is_asan,
96 "AsanBackupRefPtr requires AddressSanitizer")