| # Copyright 2019 The Chromium Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("//base/allocator/partition_allocator/partition_alloc.gni") |
| import("//build/config/chromecast_build.gni") |
| import("//build/config/sanitizers/sanitizers.gni") |
| import("//build_overrides/partition_alloc.gni") |
| |
| if (is_ios) { |
| import("//build/config/ios/ios_sdk.gni") |
| } |
| |
| declare_args() { |
| # Causes all the allocations to be routed via allocator_shim.cc. |
| use_allocator_shim = use_allocator_shim_default |
| |
| # Whether PartitionAlloc should be available for use or not. |
| # true makes PartitionAlloc linked to the executable or shared library and |
| # makes it available for use. It doesn't mean that the default allocator |
| # is PartitionAlloc, which is governed by |use_allocator|. |
| # |
| # This flag is currently set to false only on Cronet bots, because Cronet |
| # doesn't use PartitionAlloc at all, and doesn't wish to incur the library |
| # size increase (crbug.com/674570). |
| use_partition_alloc = true |
| } |
| |
| if (!use_partition_alloc && use_allocator == "partition") { |
| # If there is a conflict, prioritize |use_partition_alloc| over |
| # |use_allocator|. |
| use_allocator = "none" |
| } |
| |
| assert(use_allocator == "none" || use_allocator == "partition") |
| |
| assert( |
| !use_allocator_shim || is_linux || is_chromeos || is_android || is_win || |
| is_fuchsia || is_apple, |
| "use_allocator_shim works only on Android, iOS, Linux, macOS, Fuchsia, " + |
| "and Windows.") |
| |
| if (is_win && use_allocator_shim) { |
| # TODO(crbug.com/1245317): Add a comment indicating why the shim doesn't work. |
| assert(!is_component_build, |
| "The allocator shim doesn't work for the component build on Windows.") |
| } |
| |
| declare_args() { |
| # If we use PartitionAlloc as default allocator and enable its MTECheckedPtr |
| # support as default, we can use_mte_checked_ptr=true as default. |
| use_mte_checked_ptr = enable_mte_checked_ptr_support_default && |
| use_partition_alloc && use_allocator == "partition" |
| } |
| |
| declare_args() { |
| # Set use_backup_ref_ptr true to use BackupRefPtr (BRP) as the implementation |
| # of raw_ptr<T>, and enable PartitionAlloc support for it. |
| # We also disable BRP in the presence of MTECheckedPtr, which is almost |
| # never enabled. |
| use_backup_ref_ptr = enable_backup_ref_ptr_support_default && |
| use_partition_alloc && use_allocator == "partition" |
| } |
| |
| assert(!use_backup_ref_ptr || enable_backup_ref_ptr_support, |
| "BackupRefPtr needs enable_backup_ref_ptr_support.") |
| |
| assert(!use_mte_checked_ptr || enable_mte_checked_ptr_support, |
| "MTECheckedPtr needs enable_mte_checked_ptr_support.") |
| |
| assert(!(use_backup_ref_ptr && use_mte_checked_ptr), |
| "MTECheckedPtr conflicts with BRP.") |
| |
| declare_args() { |
| # The supported platforms are supposed to match `_is_brp_supported`, but we |
| # enable the feature on Linux early because it's most widely used for security |
| # research |
| use_asan_backup_ref_ptr = is_asan && (is_win || is_android || is_linux) |
| } |
| |
| # Prevent using BackupRefPtr when PartitionAlloc-Everywhere isn't used. |
| # In theory, such a configuration is possible, but its scope would be limited to |
| # only Blink partitions, which is currently not tested. Better to trigger an |
| # error, than have BackupRefPtr silently disabled while believing it is enabled. |
| if (!is_nacl) { |
| assert(!use_backup_ref_ptr || use_allocator == "partition", |
| "Can't use BackupRefPtr without PartitionAlloc-Everywhere") |
| } |
| |
| # BackupRefPtr and AsanBackupRefPtr are mutually exclusive variants of raw_ptr. |
| assert( |
| !use_backup_ref_ptr || !use_asan_backup_ref_ptr, |
| "Both BackupRefPtr and AsanBackupRefPtr can't be enabled at the same time") |
| |
| assert(!use_asan_backup_ref_ptr || is_asan, |
| "AsanBackupRefPtr requires AddressSanitizer") |