0

PA: Remove deps to early_zone_registration_mac.h

By adding a new header shim/early_zone_registration_constants.h,
which defines only constants and can be shared between allocator
shims and early_zone_registration_mac.o, removes dependencies to
early_zone_registration_mac.h from allocator shims.

Bug: 1337681
Change-Id: I3331e75c6eacb710b4f8e99ccd2a7e85db49f800
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4600728
Reviewed-by: Takashi Sakamoto <tasak@google.com>
Reviewed-by: Benoit Lize <lizeb@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1155455}
This commit is contained in:
Yuki Shiino
2023-06-09 11:20:07 +00:00
committed by Chromium LUCI CQ
parent c11c29fd0a
commit 4ece9bd9ee
7 changed files with 44 additions and 27 deletions

@ -1181,6 +1181,7 @@ component("base") {
"allocator/early_zone_registration_mac.h",
"allocator/partition_allocator/shim/allocator_shim_override_mac_default_zone.h",
"allocator/partition_allocator/shim/allocator_shim_override_mac_symbols.h",
"allocator/partition_allocator/shim/early_zone_registration_constants.h",
]
configs += [ "//base/allocator:mac_no_default_new_delete_symbols" ]
}

@ -26,6 +26,7 @@ if (is_apple) {
sources = [
"early_zone_registration_mac.cc",
"early_zone_registration_mac.h",
"partition_allocator/shim/early_zone_registration_constants.h",
]
deps = [

@ -8,6 +8,7 @@
#include <malloc/malloc.h>
#include "base/allocator/partition_allocator/partition_alloc_buildflags.h"
#include "base/allocator/partition_allocator/shim/early_zone_registration_constants.h"
// BASE_EXPORT tends to be defined as soon as anything from //base is included.
#if defined(BASE_EXPORT)
@ -208,11 +209,11 @@ void EarlyMallocZoneRegistration() {
// Could use something lower to support fewer functions, but this is
// consistent with the real zone installed by PartitionAlloc.
g_delegating_zone.version = kZoneVersion;
g_delegating_zone.version = allocator_shim::kZoneVersion;
g_delegating_zone.introspect = &g_delegating_zone_introspect;
// This name is used in PartitionAlloc's initialization to determine whether
// it should replace the delegating zone.
g_delegating_zone.zone_name = kDelegatingZoneName;
g_delegating_zone.zone_name = allocator_shim::kDelegatingZoneName;
// Register puts the new zone at the end, unregister swaps the new zone with
// the last one.
@ -254,7 +255,7 @@ void AllowDoublePartitionAllocZoneRegistration() {
for (unsigned int i = 0; i < zone_count; i++) {
malloc_zone_t* zone = reinterpret_cast<malloc_zone_t*>(zones[i]);
if (zone->zone_name &&
strcmp(zone->zone_name, kPartitionAllocZoneName) == 0) {
strcmp(zone->zone_name, allocator_shim::kPartitionAllocZoneName) == 0) {
zone->zone_name = "RenamedPartitionAlloc";
break;
}

@ -10,22 +10,6 @@
namespace partition_alloc {
static constexpr char kDelegatingZoneName[] =
"DelegatingDefaultZoneForPartitionAlloc";
static constexpr char kPartitionAllocZoneName[] = "PartitionAlloc";
// Zone version. Determines which callbacks are set in the various malloc_zone_t
// structs.
#if (__MAC_OS_X_VERSION_MAX_ALLOWED >= 130000) || \
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 160100)
#define PA_TRY_FREE_DEFAULT_IS_AVAILABLE 1
#endif
#if PA_TRY_FREE_DEFAULT_IS_AVAILABLE
constexpr int kZoneVersion = 13;
#else
constexpr int kZoneVersion = 9;
#endif
// Must be called *once*, *before* the process becomes multi-threaded.
void EarlyMallocZoneRegistration();

@ -7,7 +7,6 @@
# migration gets done.
include_rules = [
"+base/allocator/early_zone_registration_mac.h",
"+base/base_export.h",
]

@ -18,13 +18,13 @@
#include <atomic>
#include <tuple>
#include "base/allocator/early_zone_registration_mac.h"
#include "base/allocator/partition_allocator/partition_alloc_base/bits.h"
#include "base/allocator/partition_allocator/partition_alloc_base/logging.h"
#include "base/allocator/partition_allocator/partition_alloc_base/mac/mach_logging.h"
#include "base/allocator/partition_allocator/partition_alloc_buildflags.h"
#include "base/allocator/partition_allocator/partition_alloc_check.h"
#include "base/allocator/partition_allocator/partition_alloc_constants.h"
#include "base/allocator/partition_allocator/shim/early_zone_registration_constants.h"
namespace partition_alloc {
@ -261,8 +261,7 @@ bool IsAlreadyRegistered() {
// strcmp() and not a pointer comparison, as the zone was registered from
// another library, the pointers don't match.
if (zone->zone_name &&
(strcmp(zone->zone_name, partition_alloc::kPartitionAllocZoneName) ==
0)) {
(strcmp(zone->zone_name, kPartitionAllocZoneName) == 0)) {
// This zone is provided by PartitionAlloc, so this function has been
// called from another library (or the main executable), nothing to do.
//
@ -309,8 +308,8 @@ void InitializeZone() {
// version >= 11: introspect.print_task is supported
// version >= 12: introspect.task_statistics is supported
// version >= 13: try_free_default is supported
g_mac_malloc_zone.version = partition_alloc::kZoneVersion;
g_mac_malloc_zone.zone_name = partition_alloc::kPartitionAllocZoneName;
g_mac_malloc_zone.version = kZoneVersion;
g_mac_malloc_zone.zone_name = kPartitionAllocZoneName;
g_mac_malloc_zone.introspect = &g_mac_malloc_introspection;
g_mac_malloc_zone.size = MallocZoneSize;
g_mac_malloc_zone.malloc = MallocZoneMalloc;
@ -365,8 +364,7 @@ InitializeDefaultMallocZoneWithPartitionAlloc() {
InitializeZone();
malloc_zone_t* system_default_zone = GetDefaultMallocZone();
if (strcmp(system_default_zone->zone_name,
partition_alloc::kDelegatingZoneName) == 0) {
if (strcmp(system_default_zone->zone_name, kDelegatingZoneName) == 0) {
// The first zone is our zone, we can unregister it, replacing it with the
// new one. This relies on a precise zone setup, done in
// |EarlyMallocZoneRegistration()|.

@ -0,0 +1,33 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_SHIM_EARLY_ZONE_REGISTRATION_CONSTANTS_H_
#define BASE_ALLOCATOR_PARTITION_ALLOCATOR_SHIM_EARLY_ZONE_REGISTRATION_CONSTANTS_H_
// This is an Apple-only file, used to register PartitionAlloc's zone *before*
// the process becomes multi-threaded. These constants are shared between the
// allocator shim which installs the PartitionAlloc's malloc zone and the
// application which installs the "early malloc zone" to reserve the zone slot.
namespace allocator_shim {
static constexpr char kDelegatingZoneName[] =
"DelegatingDefaultZoneForPartitionAlloc";
static constexpr char kPartitionAllocZoneName[] = "PartitionAlloc";
// Zone version. Determines which callbacks are set in the various malloc_zone_t
// structs.
#if (__MAC_OS_X_VERSION_MAX_ALLOWED >= 130000) || \
(__IPHONE_OS_VERSION_MAX_ALLOWED >= 160100)
#define PA_TRY_FREE_DEFAULT_IS_AVAILABLE 1
#endif
#if PA_TRY_FREE_DEFAULT_IS_AVAILABLE
constexpr int kZoneVersion = 13;
#else
constexpr int kZoneVersion = 9;
#endif
} // namespace allocator_shim
#endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_SHIM_EARLY_ZONE_REGISTRATION_CONSTANTS_H_