0

Make macOS shared memory implementation work on iOS as well

iOS currently uses a file-based implementation of shared memory
(platform_shared_memory_region_posix.cc), that is responsible for a
significant fraction of Chrome's disk writes overall. While Chrome
on iOS never needs to share memory between processes, cross-platform
primitives like mojo pipes use PlatformSharedMemoryRegion on iOS too.

macOS currently uses an implementation of shared memory using
mach_make_memory_entry_64. This implementation nearly works on iOS
as-is, except that mach_vm_map is not available on iOS, which instead
supports vm_map (and similarly doesn't support other mach_vm_*
functions but supports their vm_* equivalents). macOS also supports
vm_map. The main advantage of mach_vm_map and the other mach_vm_*
functions is interoperability between 32-bit and 64-bit processes
(e.g., sharing memory between such processes), which is not an issue
for Chrome on macOS, since it is 64-bit only.

This CL modifies the macOS implementation of PlatformSharedMemoryRegion
to use vm_map instead of mach_vm_map, and uses this implementation on
iOS as well. This fixes the excessive disk write issue on iOS, and also
leaves iOS in a better state for a potential future where Chrome needs
to share memory between processes.

Change-Id: I9560cba636a371e684665d59869038e4f29b957e
Bug: 1327411
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3673160
Commit-Queue: Ali Juma <ajuma@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Ken Rockot <rockot@google.com>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1009355}
This commit is contained in:
Ali Juma
2022-05-31 23:51:41 +00:00
committed by Chromium LUCI CQ
parent 7c9807281a
commit dff201a0ce
18 changed files with 102 additions and 101 deletions

@ -2213,6 +2213,8 @@ mixed_component("base") {
"mac/scoped_objc_class_swizzler.h",
"mac/scoped_objc_class_swizzler.mm",
"mac/scoped_typeref.h",
"memory/platform_shared_memory_mapper_mac.cc",
"memory/platform_shared_memory_region_mac.cc",
"message_loop/message_pump_mac.h",
"message_loop/message_pump_mac.mm",
"power_monitor/power_monitor_device_source_ios.mm",
@ -2266,7 +2268,7 @@ mixed_component("base") {
# Android and MacOS have their own custom shared memory handle
# implementations. e.g. due to supporting both POSIX and native handles.
if (is_posix && !is_android && !is_mac) {
if (is_posix && !is_android && !is_apple) {
sources += [
"memory/platform_shared_memory_mapper_posix.cc",
"memory/platform_shared_memory_region_posix.cc",

@ -6,7 +6,7 @@
namespace base::subtle {
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_ANDROID)
ScopedFDPair::ScopedFDPair() = default;
ScopedFDPair::ScopedFDPair(ScopedFDPair&&) = default;

@ -7,7 +7,7 @@
#include "build/build_config.h"
#if BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_APPLE)
#include <mach/mach.h>
#include "base/mac/scoped_mach_port.h"
#elif BUILDFLAG(IS_FUCHSIA)
@ -22,7 +22,7 @@
namespace base::subtle {
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_ANDROID)
// Helper structs to keep two descriptors on POSIX. It's needed to support
// ConvertToReadOnly().
struct BASE_EXPORT FDPair {
@ -49,7 +49,7 @@ struct BASE_EXPORT ScopedFDPair {
#endif
// Platform-specific shared memory type used by the shared memory system.
#if BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_APPLE)
using PlatformSharedMemoryHandle = mach_port_t;
using ScopedPlatformSharedMemoryHandle = mac::ScopedMachSendRight;
#elif BUILDFLAG(IS_FUCHSIA)

@ -6,7 +6,7 @@
#include "base/logging.h"
#include <mach/mach_vm.h>
#include <mach/vm_map.h>
#include "base/mac/mach_logging.h"
namespace base {
@ -17,19 +17,18 @@ absl::optional<span<uint8_t>> PlatformSharedMemoryMapper::Map(
uint64_t offset,
size_t size) {
vm_prot_t vm_prot_write = write_allowed ? VM_PROT_WRITE : 0;
mach_vm_address_t address = 0;
kern_return_t kr =
mach_vm_map(mach_task_self(),
&address, // Output parameter
size,
0, // Alignment mask
VM_FLAGS_ANYWHERE, handle, offset,
FALSE, // Copy
VM_PROT_READ | vm_prot_write, // Current protection
VM_PROT_READ | vm_prot_write, // Maximum protection
VM_INHERIT_NONE);
vm_address_t address = 0;
kern_return_t kr = vm_map(mach_task_self(),
&address, // Output parameter
size,
0, // Alignment mask
VM_FLAGS_ANYWHERE, handle, offset,
FALSE, // Copy
VM_PROT_READ | vm_prot_write, // Current protection
VM_PROT_READ | vm_prot_write, // Maximum protection
VM_INHERIT_NONE);
if (kr != KERN_SUCCESS) {
MACH_DLOG(ERROR, kr) << "mach_vm_map";
MACH_DLOG(ERROR, kr) << "vm_map";
return absl::nullopt;
}
@ -37,10 +36,10 @@ absl::optional<span<uint8_t>> PlatformSharedMemoryMapper::Map(
}
void PlatformSharedMemoryMapper::Unmap(span<uint8_t> mapping) {
kern_return_t kr = mach_vm_deallocate(
mach_task_self(), reinterpret_cast<mach_vm_address_t>(mapping.data()),
kern_return_t kr = vm_deallocate(
mach_task_self(), reinterpret_cast<vm_address_t>(mapping.data()),
mapping.size());
MACH_DLOG_IF(ERROR, kr != KERN_SUCCESS, kr) << "mach_vm_deallocate";
MACH_DLOG_IF(ERROR, kr != KERN_SUCCESS, kr) << "vm_deallocate";
}
} // namespace base

@ -124,7 +124,7 @@ class BASE_EXPORT PlatformSharedMemoryRegion {
Mode mode,
size_t size,
const UnguessableToken& guid);
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_APPLE)
// Specialized version of Take() for POSIX that takes only one file descriptor
// instead of pair. Cannot be used with kWritable |mode|.
static PlatformSharedMemoryRegion Take(ScopedFD handle,
@ -173,13 +173,13 @@ class BASE_EXPORT PlatformSharedMemoryRegion {
// kWritable mode, all other modes will CHECK-fail. The object will have
// kReadOnly mode after this call on success.
bool ConvertToReadOnly();
#if BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_APPLE)
// Same as above, but |mapped_addr| is used as a hint to avoid additional
// mapping of the memory object.
// |mapped_addr| must be mapped location of |memory_object_|. If the location
// is unknown, |mapped_addr| should be |nullptr|.
bool ConvertToReadOnly(void* mapped_addr);
#endif // BUILDFLAG(IS_MAC)
#endif // BUILDFLAG(IS_APPLE)
// Converts the region to unsafe. Returns whether the operation succeeded.
// Makes the current instance invalid on failure. Can be called only in

@ -4,7 +4,7 @@
#include "base/memory/platform_shared_memory_region.h"
#include <mach/mach_vm.h>
#include <mach/vm_map.h>
#include "base/mac/mach_logging.h"
#include "base/mac/scoped_mach_vm.h"
@ -12,10 +12,6 @@
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_IOS)
#error "MacOS only - iOS uses platform_shared_memory_region_posix.cc"
#endif
namespace base {
namespace subtle {
@ -88,12 +84,12 @@ bool PlatformSharedMemoryRegion::ConvertToReadOnly(void* mapped_addr) {
mac::ScopedMachVM scoped_memory;
if (!temp_addr) {
// Intentionally lower current prot and max prot to |VM_PROT_READ|.
kern_return_t kr = mach_vm_map(
mach_task_self(), reinterpret_cast<mach_vm_address_t*>(&temp_addr),
size_, 0, VM_FLAGS_ANYWHERE, handle_copy.get(), 0, FALSE, VM_PROT_READ,
VM_PROT_READ, VM_INHERIT_NONE);
kern_return_t kr =
vm_map(mach_task_self(), reinterpret_cast<vm_address_t*>(&temp_addr),
size_, 0, VM_FLAGS_ANYWHERE, handle_copy.get(), 0, FALSE,
VM_PROT_READ, VM_PROT_READ, VM_INHERIT_NONE);
if (kr != KERN_SUCCESS) {
MACH_DLOG(ERROR, kr) << "mach_vm_map";
MACH_DLOG(ERROR, kr) << "vm_map";
return false;
}
scoped_memory.reset(reinterpret_cast<vm_address_t>(temp_addr),
@ -143,7 +139,7 @@ PlatformSharedMemoryRegion PlatformSharedMemoryRegion::Create(Mode mode,
CHECK_NE(mode, Mode::kReadOnly) << "Creating a region in read-only mode will "
"lead to this region being non-modifiable";
mach_vm_size_t vm_size = size;
memory_object_size_t vm_size = size;
mac::ScopedMachSendRight named_right;
kern_return_t kr = mach_make_memory_entry_64(
mach_task_self(), &vm_size,
@ -165,19 +161,19 @@ bool PlatformSharedMemoryRegion::CheckPlatformHandlePermissionsCorrespondToMode(
PlatformSharedMemoryHandle handle,
Mode mode,
size_t size) {
mach_vm_address_t temp_addr = 0;
vm_address_t temp_addr = 0;
kern_return_t kr =
mach_vm_map(mach_task_self(), &temp_addr, size, 0, VM_FLAGS_ANYWHERE,
handle, 0, FALSE, VM_PROT_READ | VM_PROT_WRITE,
VM_PROT_READ | VM_PROT_WRITE, VM_INHERIT_NONE);
vm_map(mach_task_self(), &temp_addr, size, 0, VM_FLAGS_ANYWHERE, handle,
0, FALSE, VM_PROT_READ | VM_PROT_WRITE,
VM_PROT_READ | VM_PROT_WRITE, VM_INHERIT_NONE);
if (kr == KERN_SUCCESS) {
kern_return_t kr_deallocate =
mach_vm_deallocate(mach_task_self(), temp_addr, size);
vm_deallocate(mach_task_self(), temp_addr, size);
// TODO(crbug.com/838365): convert to DLOG when bug fixed.
MACH_LOG_IF(ERROR, kr_deallocate != KERN_SUCCESS, kr_deallocate)
<< "mach_vm_deallocate";
<< "vm_deallocate";
} else if (kr != KERN_INVALID_RIGHT) {
MACH_LOG(ERROR, kr) << "mach_vm_map";
MACH_LOG(ERROR, kr) << "vm_map";
return false;
}

@ -16,10 +16,10 @@
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_MAC)
#include <mach/mach_vm.h>
#if BUILDFLAG(IS_APPLE)
#include <mach/vm_map.h>
#include <sys/mman.h>
#elif BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_IOS)
#elif BUILDFLAG(IS_POSIX)
#include <sys/mman.h>
#include "base/debug/proc_maps_linux.h"
#elif BUILDFLAG(IS_WIN)
@ -212,7 +212,7 @@ TEST_F(PlatformSharedMemoryRegionTest, MapAtWithOverflowTest) {
EXPECT_FALSE(mapping.IsValid());
}
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_APPLE)
// Tests that the second handle is closed after a conversion to read-only on
// POSIX.
TEST_F(PlatformSharedMemoryRegionTest,
@ -238,17 +238,21 @@ TEST_F(PlatformSharedMemoryRegionTest, ConvertToUnsafeInvalidatesSecondHandle) {
#endif
void CheckReadOnlyMapProtection(void* addr) {
#if BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_APPLE)
vm_region_basic_info_64 basic_info;
mach_vm_size_t dummy_size = 0;
void* temp_addr = addr;
MachVMRegionResult result = GetBasicInfo(
mach_task_self(), &dummy_size,
reinterpret_cast<mach_vm_address_t*>(&temp_addr), &basic_info);
ASSERT_EQ(result, MachVMRegionResult::Success);
vm_size_t dummy_size = 0;
mach_msg_type_number_t info_count = VM_REGION_BASIC_INFO_COUNT_64;
mach_port_t object_name;
kern_return_t kr = vm_region_64(
mach_task_self(), reinterpret_cast<vm_address_t*>(&addr), &dummy_size,
VM_REGION_BASIC_INFO_64, reinterpret_cast<vm_region_info_t>(&basic_info),
&info_count, &object_name);
mach_port_deallocate(mach_task_self(), object_name);
ASSERT_EQ(kr, KERN_SUCCESS);
EXPECT_EQ(basic_info.protection & VM_PROT_ALL, VM_PROT_READ);
EXPECT_EQ(basic_info.max_protection & VM_PROT_ALL, VM_PROT_READ);
#elif BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_IOS)
#elif BUILDFLAG(IS_POSIX)
std::string proc_maps;
ASSERT_TRUE(base::debug::ReadProcMaps(&proc_maps));
std::vector<base::debug::MappedMemoryRegion> regions;

@ -846,7 +846,7 @@ void FieldTrialList::PopulateLaunchOptionsWithFieldTrialState(
}
#endif // !BUILDFLAG(IS_IOS)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_NACL)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_NACL)
// static
int FieldTrialList::GetFieldTrialDescriptor() {
InstantiateFieldTrialAllocatorIfNeeded();
@ -859,7 +859,7 @@ int FieldTrialList::GetFieldTrialDescriptor() {
return global_->readonly_allocator_region_.GetPlatformHandle().fd;
#endif
}
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_NACL)
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_NACL)
// static
ReadOnlySharedMemoryRegion

@ -572,13 +572,13 @@ class BASE_EXPORT FieldTrialList {
LaunchOptions* launch_options);
#endif // !BUILDFLAG(IS_IOS)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_NACL)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_NACL)
// On POSIX, we also need to explicitly pass down this file descriptor that
// should be shared with the child process. Returns -1 if it was not
// initialized properly. The current process remains the onwer of the passed
// descriptor.
static int GetFieldTrialDescriptor();
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_NACL)
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_NACL)
static ReadOnlySharedMemoryRegion DuplicateFieldTrialSharedMemoryForTesting();

@ -24,8 +24,8 @@
#include <zircon/rights.h>
#endif
#if BUILDFLAG(IS_MAC)
#include <mach/mach_vm.h>
#if BUILDFLAG(IS_APPLE)
#include <mach/vm_map.h>
#endif
#if BUILDFLAG(IS_WIN)
@ -41,7 +41,7 @@ static const size_t kDataSize = 1024;
// Common routine used with Posix file descriptors. Check that shared memory
// file descriptor |fd| does not allow writable mappings. Return true on
// success, false otherwise.
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)
static bool CheckReadOnlySharedMemoryFdPosix(int fd) {
// Note that the error on Android is EPERM, unlike other platforms where
// it will be EACCES.
@ -66,7 +66,7 @@ static bool CheckReadOnlySharedMemoryFdPosix(int fd) {
}
return true;
}
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC)
#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_APPLE)
#if BUILDFLAG(IS_FUCHSIA)
// Fuchsia specific implementation.
@ -88,16 +88,16 @@ bool CheckReadOnlySharedMemoryFuchsiaHandle(zx::unowned_vmo handle) {
return true;
}
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
bool CheckReadOnlySharedMemoryMachPort(mach_port_t memory_object) {
mach_vm_address_t memory;
const kern_return_t kr = mach_vm_map(
mach_task_self(), &memory, kDataSize, 0, VM_FLAGS_ANYWHERE, memory_object,
0, FALSE, VM_PROT_READ | VM_PROT_WRITE,
VM_PROT_READ | VM_PROT_WRITE | VM_PROT_IS_MASK, VM_INHERIT_NONE);
vm_address_t memory;
const kern_return_t kr =
vm_map(mach_task_self(), &memory, kDataSize, 0, VM_FLAGS_ANYWHERE,
memory_object, 0, FALSE, VM_PROT_READ | VM_PROT_WRITE,
VM_PROT_READ | VM_PROT_WRITE | VM_PROT_IS_MASK, VM_INHERIT_NONE);
if (kr == KERN_SUCCESS) {
LOG(ERROR) << "mach_vm_map() should have failed!";
mach_vm_deallocate(mach_task_self(), memory, kDataSize); // Cleanup.
LOG(ERROR) << "vm_map() should have failed!";
vm_deallocate(mach_task_self(), memory, kDataSize); // Cleanup.
return false;
}
return true;
@ -126,7 +126,7 @@ bool CheckReadOnlyPlatformSharedMemoryRegionForTesting(
return false;
}
#if BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_APPLE)
return CheckReadOnlySharedMemoryMachPort(region.GetPlatformHandle());
#elif BUILDFLAG(IS_FUCHSIA)
return CheckReadOnlySharedMemoryFuchsiaHandle(region.GetPlatformHandle());

@ -140,7 +140,7 @@ component("message_support") {
]
}
if (is_mac) {
if (is_apple) {
sources += [
"mach_port_attachment_mac.cc",
"mach_port_attachment_mac.h",

@ -24,7 +24,7 @@
#include "ipc/ipc_message_attachment_set.h"
#include "ipc/ipc_mojo_param_traits.h"
#if BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_APPLE)
#include "ipc/mach_port_mac.h"
#endif
@ -963,7 +963,7 @@ void ParamTraits<base::subtle::PlatformSharedMemoryRegion>::Write(
#elif BUILDFLAG(IS_FUCHSIA)
zx::vmo vmo = const_cast<param_type&>(p).PassPlatformHandle();
WriteParam(m, vmo);
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
base::mac::ScopedMachSendRight h =
const_cast<param_type&>(p).PassPlatformHandle();
MachPortMac mach_port_mac(h.get());
@ -1017,7 +1017,7 @@ bool ParamTraits<base::subtle::PlatformSharedMemoryRegion>::Read(
return false;
*r = base::subtle::PlatformSharedMemoryRegion::Take(std::move(vmo), mode,
size, guid);
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
MachPortMac mach_port_mac;
if (!ReadParam(m, iter, &mach_port_mac))
return false;
@ -1077,7 +1077,7 @@ void ParamTraits<base::subtle::PlatformSharedMemoryRegion>::Log(
#elif BUILDFLAG(IS_WIN)
l->append("Handle: ");
LogParam(p.GetPlatformHandle(), l);
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
l->append("Mach port: ");
LogParam(p.GetPlatformHandle(), l);
#elif BUILDFLAG(IS_ANDROID)

@ -652,7 +652,7 @@ MojoResult Core::CreateDataPipe(const MojoCreateDataPipeOptions* options,
// consumer of this pipe, and it would be impossible to support such access
// control on Android anyway.
auto writable_region_handle = ring_buffer_region.PassPlatformHandle();
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_APPLE)
// This isn't strictly necessary, but it does make the handle configuration
// consistent with regular UnsafeSharedMemoryRegions.
writable_region_handle.readonly_fd.reset();

@ -17,7 +17,7 @@
#include "base/win/scoped_handle.h"
#endif
#if BUILDFLAG(IS_MAC)
#if BUILDFLAG(IS_APPLE)
#include "base/mac/scoped_mach_port.h"
#endif
@ -32,7 +32,7 @@ void ExtractPlatformHandlesFromSharedMemoryRegionHandle(
*extracted_handle = PlatformHandle(base::win::ScopedHandle(handle.Take()));
#elif BUILDFLAG(IS_FUCHSIA)
*extracted_handle = PlatformHandle(std::move(handle));
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
// This is a Mach port. Same code as above and below, but separated for
// clarity.
*extracted_handle = PlatformHandle(std::move(handle));
@ -55,7 +55,7 @@ CreateSharedMemoryRegionHandleFromPlatformHandles(
#elif BUILDFLAG(IS_FUCHSIA)
DCHECK(!readonly_handle.is_valid());
return zx::vmo(handle.TakeHandle());
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
DCHECK(!readonly_handle.is_valid());
return handle.TakeMachSendRight();
#elif BUILDFLAG(IS_ANDROID)

@ -258,10 +258,10 @@ MojoResult SharedBufferDispatcher::DuplicateBufferHandle(
} else if (region_.GetMode() ==
base::subtle::PlatformSharedMemoryRegion::Mode::kWritable) {
auto handle = region_.PassPlatformHandle();
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_MAC)
// On POSIX systems excluding Android, Fuchsia, and OSX, we explicitly
// wipe out the secondary (read-only) FD from the platform handle to
// repurpose it for exclusive unsafe usage.
#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_APPLE)
// On POSIX systems excluding Android, Fuchsia, iOS, and macOS, we
// explicitly wipe out the secondary (read-only) FD from the platform
// handle to repurpose it for exclusive unsafe usage.
handle.readonly_fd.reset();
#endif
region_ = base::subtle::PlatformSharedMemoryRegion::Take(

@ -19,8 +19,8 @@
#include <zircon/status.h>
#include "base/fuchsia/fuchsia_logging.h"
#elif BUILDFLAG(IS_MAC)
#include <mach/mach_vm.h>
#elif BUILDFLAG(IS_APPLE)
#include <mach/vm_map.h>
#include "base/mac/mach_logging.h"
#include "base/mac/scoped_mach_port.h"
@ -71,7 +71,7 @@ zx::handle CloneHandle(const zx::handle& handle) {
ZX_DLOG(ERROR, result) << "zx_duplicate_handle";
return std::move(dupe);
}
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
base::mac::ScopedMachSendRight CloneMachPort(
const base::mac::ScopedMachSendRight& mach_port) {
DCHECK(mach_port.is_valid());
@ -107,7 +107,7 @@ PlatformHandle::PlatformHandle(base::win::ScopedHandle handle)
#elif BUILDFLAG(IS_FUCHSIA)
PlatformHandle::PlatformHandle(zx::handle handle)
: type_(Type::kHandle), handle_(std::move(handle)) {}
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
PlatformHandle::PlatformHandle(base::mac::ScopedMachSendRight mach_port)
: type_(Type::kMachSend), mach_send_(std::move(mach_port)) {}
PlatformHandle::PlatformHandle(base::mac::ScopedMachReceiveRight mach_port)
@ -133,7 +133,7 @@ PlatformHandle& PlatformHandle::operator=(PlatformHandle&& other) {
handle_ = std::move(other.handle_);
#elif BUILDFLAG(IS_FUCHSIA)
handle_ = std::move(other.handle_);
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
mach_send_ = std::move(other.mach_send_);
mach_receive_ = std::move(other.mach_receive_);
#endif
@ -168,7 +168,7 @@ void PlatformHandle::ToMojoPlatformHandle(PlatformHandle handle,
out_handle->value = handle.TakeHandle().release();
break;
}
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
if (handle.is_mach_send()) {
out_handle->type = MOJO_PLATFORM_HANDLE_TYPE_MACH_SEND_RIGHT;
out_handle->value = static_cast<uint64_t>(handle.ReleaseMachSendRight());
@ -208,7 +208,7 @@ PlatformHandle PlatformHandle::FromMojoPlatformHandle(
#elif BUILDFLAG(IS_FUCHSIA)
if (handle->type == MOJO_PLATFORM_HANDLE_TYPE_FUCHSIA_HANDLE)
return PlatformHandle(zx::handle(handle->value));
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
if (handle->type == MOJO_PLATFORM_HANDLE_TYPE_MACH_SEND_RIGHT) {
return PlatformHandle(base::mac::ScopedMachSendRight(
static_cast<mach_port_t>(handle->value)));
@ -232,7 +232,7 @@ void PlatformHandle::reset() {
handle_.Close();
#elif BUILDFLAG(IS_FUCHSIA)
handle_.reset();
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
mach_send_.reset();
mach_receive_.reset();
#endif
@ -249,7 +249,7 @@ void PlatformHandle::release() {
std::ignore = handle_.Take();
#elif BUILDFLAG(IS_FUCHSIA)
std::ignore = handle_.release();
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
std::ignore = mach_send_.release();
std::ignore = mach_receive_.release();
#endif
@ -266,7 +266,7 @@ PlatformHandle PlatformHandle::Clone() const {
if (is_valid_handle())
return PlatformHandle(CloneHandle(handle_));
return PlatformHandle(CloneFD(fd_));
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
if (is_valid_mach_send())
return PlatformHandle(CloneMachPort(mach_send_));
CHECK(!is_valid_mach_receive()) << "Cannot clone Mach receive rights";

@ -15,7 +15,7 @@
#include "base/win/scoped_handle.h"
#elif BUILDFLAG(IS_FUCHSIA)
#include <lib/zx/handle.h>
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
#include "base/mac/scoped_mach_port.h"
#endif
@ -45,7 +45,7 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformHandle {
kNone,
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_FUCHSIA)
kHandle,
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
kMachSend,
kMachReceive,
#endif
@ -61,7 +61,7 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformHandle {
explicit PlatformHandle(base::win::ScopedHandle handle);
#elif BUILDFLAG(IS_FUCHSIA)
explicit PlatformHandle(zx::handle handle);
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
explicit PlatformHandle(base::mac::ScopedMachSendRight mach_port);
explicit PlatformHandle(base::mac::ScopedMachReceiveRight mach_port);
#endif
@ -132,7 +132,7 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformHandle {
type_ = Type::kNone;
return handle_.release();
}
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
bool is_valid() const { return is_valid_fd() || is_valid_mach_port(); }
bool is_valid_mach_port() const {
return is_valid_mach_send() || is_valid_mach_receive();
@ -222,7 +222,7 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformHandle {
base::win::ScopedHandle handle_;
#elif BUILDFLAG(IS_FUCHSIA)
zx::handle handle_;
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
base::mac::ScopedMachSendRight mach_send_;
base::mac::ScopedMachReceiveRight mach_receive_;
#endif

@ -66,7 +66,7 @@ ScopedSharedBufferHandle WrapPlatformSharedMemoryRegion(
#elif BUILDFLAG(IS_FUCHSIA)
platform_handles[0].type = MOJO_PLATFORM_HANDLE_TYPE_FUCHSIA_HANDLE;
platform_handles[0].value = static_cast<uint64_t>(handle.release());
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
platform_handles[0].type = MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT;
platform_handles[0].value = static_cast<uint64_t>(handle.release());
#elif BUILDFLAG(IS_ANDROID)
@ -128,7 +128,7 @@ base::subtle::PlatformSharedMemoryRegion UnwrapPlatformSharedMemoryRegion(
if (platform_handles[0].type != MOJO_PLATFORM_HANDLE_TYPE_FUCHSIA_HANDLE)
return base::subtle::PlatformSharedMemoryRegion();
region_handle.reset(static_cast<zx_handle_t>(platform_handles[0].value));
#elif BUILDFLAG(IS_MAC)
#elif BUILDFLAG(IS_APPLE)
if (num_platform_handles != 1)
return base::subtle::PlatformSharedMemoryRegion();
if (platform_handles[0].type != MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT)