diff --git a/base/BUILD.gn b/base/BUILD.gn index 6195d40d959b66..cd62aecd572f86 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -1973,8 +1973,6 @@ component("base") { "mac/authorization_util.h", "mac/authorization_util.mm", "mac/close_nocancel.cc", - "mac/dispatch_source_mach.cc", - "mac/dispatch_source_mach.h", "mac/launch_application.h", "mac/launch_application.mm", "mac/launchd.cc", @@ -2055,6 +2053,8 @@ component("base") { "mac/call_with_eh_frame.cc", "mac/call_with_eh_frame.h", "mac/call_with_eh_frame_asm.S", + "mac/dispatch_source_mach.cc", + "mac/dispatch_source_mach.h", "mac/foundation_util.h", "mac/foundation_util.mm", "mac/mac_logging.h", @@ -2153,11 +2153,15 @@ component("base") { "files/file_path_watcher_kqueue.cc", "files/file_path_watcher_kqueue.h", "files/file_path_watcher_mac.cc", + "ios/sim_header_shims.h", + "mac/mach_port_rendezvous.cc", + "mac/mach_port_rendezvous.h", "process/memory_mac.mm", "process/process_iterator_ios.mm", "sync_socket_posix.cc", "synchronization/waitable_event_watcher_mac.cc", ] + libs += [ "bsm" ] } else { sources += [ "process/memory_stubs.cc" ] } diff --git a/base/ios/sim_header_shims.h b/base/ios/sim_header_shims.h new file mode 100644 index 00000000000000..0245f80cef4b42 --- /dev/null +++ b/base/ios/sim_header_shims.h @@ -0,0 +1,41 @@ +// 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_IOS_SIM_HEADER_SHIMS_H_ +#define BASE_IOS_SIM_HEADER_SHIMS_H_ + +#include "build/blink_buildflags.h" + +#if !BUILDFLAG(USE_BLINK) +#error File can only be included when USE_BLINK is true +#endif + +// This file includes the necessary headers that are not part of the +// iOS public SDK in order to support multiprocess support on iOS. + +__BEGIN_DECLS + +#define BOOTSTRAP_MAX_NAME_LEN 128 +typedef char name_t[BOOTSTRAP_MAX_NAME_LEN]; +kern_return_t bootstrap_check_in(mach_port_t bp, + const name_t service_name, + mach_port_t* sp); +kern_return_t bootstrap_look_up(mach_port_t bp, + const name_t service_name, + mach_port_t* sp); +pid_t audit_token_to_pid(audit_token_t atoken); + +const char* bootstrap_strerror(kern_return_t r); +#define BOOTSTRAP_SUCCESS 0 +#define BOOTSTRAP_NOT_PRIVILEGED 1100 +#define BOOTSTRAP_NAME_IN_USE 1101 +#define BOOTSTRAP_UNKNOWN_SERVICE 1102 +#define BOOTSTRAP_SERVICE_ACTIVE 1103 +#define BOOTSTRAP_BAD_COUNT 1104 +#define BOOTSTRAP_NO_MEMORY 1105 +#define BOOTSTRAP_NO_CHILDREN 1106 + +__END_DECLS + +#endif // BASE_IOS_SIM_HEADER_SHIMS_H_ \ No newline at end of file diff --git a/base/mac/mach_logging.cc b/base/mac/mach_logging.cc index bc4c908ba8dd10..d792370249cb29 100644 --- a/base/mac/mach_logging.cc +++ b/base/mac/mach_logging.cc @@ -10,9 +10,13 @@ #include "base/strings/stringprintf.h" #include "build/build_config.h" -#if !BUILDFLAG(IS_IOS) +#if BUILDFLAG(USE_BLINK) +#if BUILDFLAG(IS_IOS) +#include "base/ios/sim_header_shims.h" +#else #include -#endif // !BUILDFLAG(IS_IOS) +#endif // BUILDFLAG(IS_IOS) +#endif // BUILDFLAG(USE_BLINK) namespace { @@ -44,7 +48,7 @@ MachLogMessage::~MachLogMessage() { << FormatMachErrorNumber(mach_err_); } -#if !BUILDFLAG(IS_IOS) +#if BUILDFLAG(USE_BLINK) BootstrapLogMessage::BootstrapLogMessage(const char* file_path, int line, @@ -83,6 +87,6 @@ BootstrapLogMessage::~BootstrapLogMessage() { } } -#endif // !BUILDFLAG(IS_IOS) +#endif // BUILDFLAG(USE_BLINK) } // namespace logging diff --git a/base/mac/mach_logging.h b/base/mac/mach_logging.h index 88edac16fd47f3..e29be963a55a5b 100644 --- a/base/mac/mach_logging.h +++ b/base/mac/mach_logging.h @@ -9,6 +9,7 @@ #include "base/base_export.h" #include "base/logging.h" +#include "build/blink_buildflags.h" #include "build/build_config.h" // Use the MACH_LOG family of macros along with a mach_error_t (kern_return_t) @@ -97,7 +98,7 @@ class BASE_EXPORT MachLogMessage : public logging::LogMessage { DCHECK_IS_ON() && !(condition)) \ << "Check failed: " #condition << ". " -#if !BUILDFLAG(IS_IOS) +#if BUILDFLAG(USE_BLINK) namespace logging { @@ -165,6 +166,6 @@ class BASE_EXPORT BootstrapLogMessage : public logging::LogMessage { DCHECK_IS_ON() && !(condition)) \ << "Check failed: " #condition << ". " -#endif // !BUILDFLAG(IS_IOS) +#endif // BUILDFLAG(USE_BLINK) #endif // BASE_MAC_MACH_LOGGING_H_ diff --git a/base/mac/mach_port_rendezvous.cc b/base/mac/mach_port_rendezvous.cc index a83022b38e93eb..892f65f8ceed3a 100644 --- a/base/mac/mach_port_rendezvous.cc +++ b/base/mac/mach_port_rendezvous.cc @@ -4,9 +4,7 @@ #include "base/mac/mach_port_rendezvous.h" -#include #include -#include #include #include @@ -19,6 +17,13 @@ #include "base/notreached.h" #include "base/strings/stringprintf.h" +#if BUILDFLAG(IS_IOS) +#include "base/ios/sim_header_shims.h" +#else +#include +#include +#endif + namespace base { namespace { diff --git a/base/metrics/field_trial.cc b/base/metrics/field_trial.cc index 9f8dbf251f188c..06cb7bf933caee 100644 --- a/base/metrics/field_trial.cc +++ b/base/metrics/field_trial.cc @@ -34,6 +34,10 @@ #include "base/process/launch.h" #endif +#if BUILDFLAG(IS_MAC) +#include "base/mac/mach_port_rendezvous.h" +#endif + // On POSIX, the fd is shared using the mapping in GlobalDescriptors. #if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) #include "base/posix/global_descriptors.h" diff --git a/base/process/launch.cc b/base/process/launch.cc index 916b8b16a23200..09efd4cbe8306c 100644 --- a/base/process/launch.cc +++ b/base/process/launch.cc @@ -5,6 +5,10 @@ #include "base/process/launch.h" #include "build/build_config.h" +#if BUILDFLAG(IS_MAC) || (BUILDFLAG(IS_IOS) && BUILDFLAG(USE_BLINK)) +#include "base/mac/mach_port_rendezvous.h" +#endif + namespace base { LaunchOptions::LaunchOptions() = default; diff --git a/base/process/launch.h b/base/process/launch.h index e88bff5102dd1b..4703f941599b6e 100644 --- a/base/process/launch.h +++ b/base/process/launch.h @@ -22,6 +22,7 @@ #include "base/process/process_handle.h" #include "base/strings/string_piece.h" #include "base/threading/thread_restrictions.h" +#include "build/blink_buildflags.h" #include "build/build_config.h" #if BUILDFLAG(IS_WIN) @@ -35,12 +36,13 @@ #include "base/posix/file_descriptor_shuffle.h" #endif -#if BUILDFLAG(IS_MAC) -#include "base/mac/mach_port_rendezvous.h" -#endif - namespace base { +#if BUILDFLAG(IS_APPLE) +class MachRendezvousPort; +using MachPortsForRendezvous = std::map; +#endif + #if BUILDFLAG(IS_WIN) typedef std::vector HandlesToInheritVector; #elif BUILDFLAG(IS_FUCHSIA) @@ -213,7 +215,7 @@ struct BASE_EXPORT LaunchOptions { bool kill_on_parent_death = false; #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) -#if BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_MAC) || (BUILDFLAG(IS_IOS) && BUILDFLAG(USE_BLINK)) // Mach ports that will be accessible to the child process. These are not // directly inherited across process creation, but they are stored by a Mach // IPC server that a child process can communicate with to retrieve them. @@ -235,7 +237,7 @@ struct BASE_EXPORT LaunchOptions { // Apply a process scheduler policy to enable mitigations against CPU side- // channel attacks. bool enable_cpu_security_mitigations = false; -#endif // BUILDFLAG(IS_MAC) +#endif // BUILDFLAG(IS_MAC) || (BUILDFLAG(IS_IOS) && BUILDFLAG(USE_BLINK)) #if BUILDFLAG(IS_FUCHSIA) // If valid, launches the application in that job object. diff --git a/base/process/launch_mac.cc b/base/process/launch_mac.cc index f860be6fbb6caf..a6e71128fb047f 100644 --- a/base/process/launch_mac.cc +++ b/base/process/launch_mac.cc @@ -14,6 +14,7 @@ #include "base/command_line.h" #include "base/files/scoped_file.h" #include "base/logging.h" +#include "base/mac/mach_port_rendezvous.h" #include "base/posix/eintr_wrapper.h" #include "base/process/environment_internal.h" #include "base/threading/scoped_blocking_call.h" diff --git a/base/task/current_thread.cc b/base/task/current_thread.cc index 05daff869644ce..b062ee6f827b72 100644 --- a/base/task/current_thread.cc +++ b/base/task/current_thread.cc @@ -238,7 +238,7 @@ bool CurrentIOThread::WatchFileDescriptor( } #endif // BUILDFLAG(IS_WIN) -#if BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_MAC) || (BUILDFLAG(IS_IOS) && !BUILDFLAG(CRONET_BUILD)) bool CurrentIOThread::WatchMachReceivePort( mach_port_t port, MessagePumpForIO::MachPortWatchController* controller, diff --git a/base/task/current_thread.h b/base/task/current_thread.h index 6e5aea5de684f5..c7e113456e0119 100644 --- a/base/task/current_thread.h +++ b/base/task/current_thread.h @@ -12,6 +12,7 @@ #include "base/functional/callback_forward.h" #include "base/memory/raw_ptr.h" #include "base/memory/scoped_refptr.h" +#include "base/message_loop/ios_cronet_buildflags.h" #include "base/message_loop/message_pump_for_io.h" #include "base/message_loop/message_pump_for_ui.h" #include "base/pending_task.h" @@ -283,7 +284,7 @@ class BASE_EXPORT CurrentIOThread : public CurrentThread { MessagePumpForIO::FdWatcher* delegate); #endif // BUILDFLAG(IS_WIN) -#if BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_MAC) || (BUILDFLAG(IS_IOS) && !BUILDFLAG(CRONET_BUILD)) bool WatchMachReceivePort( mach_port_t port, MessagePumpForIO::MachPortWatchController* controller, diff --git a/content/app/initialize_mojo_core.cc b/content/app/initialize_mojo_core.cc index cf110bb3ca1b7a..d4ccbff8c9b167 100644 --- a/content/app/initialize_mojo_core.cc +++ b/content/app/initialize_mojo_core.cc @@ -81,7 +81,7 @@ void InitializeMojoCore() { // Note #2: some platforms can directly allocated shared memory in a // sandboxed process. The defines below must be in sync with the // implementation of mojo::NodeController::CreateSharedBuffer(). -#if !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_FUCHSIA) +#if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_FUCHSIA) if (sandbox::policy::IsUnsandboxedSandboxType( sandbox::policy::SandboxTypeFromCommandLine( *base::CommandLine::ForCurrentProcess()))) { @@ -98,7 +98,7 @@ void InitializeMojoCore() { // allocate shared memory. mojo::SharedMemoryUtils::InstallBaseHooks(); } -#endif // !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_FUCHSIA) +#endif // !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_FUCHSIA) } } // namespace content diff --git a/content/browser/child_process_launcher_helper_mac.cc b/content/browser/child_process_launcher_helper_mac.cc index 27cfd077c8c9c9..7bac4c30d0be2d 100644 --- a/content/browser/child_process_launcher_helper_mac.cc +++ b/content/browser/child_process_launcher_helper_mac.cc @@ -4,6 +4,7 @@ #include "base/command_line.h" #include "base/containers/flat_map.h" +#include "base/mac/mach_port_rendezvous.h" #include "base/no_destructor.h" #include "base/path_service.h" #include "base/posix/global_descriptors.h" diff --git a/mojo/BUILD.gn b/mojo/BUILD.gn index 16801c7d5ab4f8..8d96261793d305 100644 --- a/mojo/BUILD.gn +++ b/mojo/BUILD.gn @@ -2,7 +2,9 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("//build/buildflag_header.gni") import("//build/config/ui.gni") +import("//mojo/features.gni") import("//testing/test.gni") group("mojo") { @@ -21,18 +23,25 @@ group("mojo") { deps += [ "//services/service_manager:all" ] } +buildflag_header("buildflags") { + header = "buildflags.h" + flags = [ "MOJO_USE_APPLE_CHANNEL=$mojo_use_apple_channel" ] +} + group("tests") { testonly = true deps = [ ":mojo_perftests", ":mojo_unittests", "//mojo/public/tools:mojo_python_unittests", - "//services/service_manager/tests", "//third_party/ipcz/src:ipcz_tests", ] if (!is_ios) { - deps += [ "//ipc:ipc_tests" ] + deps += [ + "//ipc:ipc_tests", + "//services/service_manager/tests", + ] } } diff --git a/mojo/core/BUILD.gn b/mojo/core/BUILD.gn index fdb50e0bcb2529..65723960e27664 100644 --- a/mojo/core/BUILD.gn +++ b/mojo/core/BUILD.gn @@ -6,6 +6,7 @@ import("//build/config/chromeos/ui_mode.gni") import("//build/config/compiler/compiler.gni") import("//build/config/nacl/config.gni") import("//chrome/process_version_rc_template.gni") +import("//mojo/features.gni") import("//testing/libfuzzer/fuzzer_test.gni") import("//testing/test.gni") @@ -140,6 +141,7 @@ template("core_impl_source_set") { public_deps = [ "//base", + "//mojo:buildflags", "//mojo/core/embedder:features", "//mojo/core/ports", "//mojo/public/c/system:headers", @@ -155,7 +157,7 @@ template("core_impl_source_set") { public_deps += [ "//third_party/fuchsia-sdk/sdk/pkg/fdio" ] } - if (is_posix && !is_mac) { + if (is_posix && !mojo_use_apple_channel) { if (!is_nacl) { sources += [ "broker_posix.cc", @@ -174,7 +176,7 @@ template("core_impl_source_set") { } } - if (is_mac) { + if (mojo_use_apple_channel) { sources += [ "channel_mac.cc" ] } @@ -364,6 +366,7 @@ source_set("test_sources") { deps = [ "//base", "//base/test:test_support", + "//mojo:buildflags", "//mojo/core:embedder_internal", "//mojo/core/embedder", "//mojo/core/ports:tests", diff --git a/mojo/core/broker_host.cc b/mojo/core/broker_host.cc index e1d6c2de3952aa..a0371495987594 100644 --- a/mojo/core/broker_host.cc +++ b/mojo/core/broker_host.cc @@ -12,6 +12,7 @@ #include "base/ranges/algorithm.h" #include "base/task/single_thread_task_runner.h" #include "build/build_config.h" +#include "mojo/buildflags.h" #include "mojo/core/broker_messages.h" #include "mojo/core/platform_handle_utils.h" @@ -125,7 +126,8 @@ void BrokerHost::OnBufferRequest(uint32_t num_bytes) { ExtractPlatformHandlesFromSharedMemoryRegionHandle( region.PassPlatformHandle(), &h[0], &h[1]); handles.emplace_back(std::move(h[0])); -#if !BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if !BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_ANDROID) || \ + BUILDFLAG(MOJO_USE_APPLE_CHANNEL) // Non-POSIX systems, as well as Android and Mac, only use a single handle // to represent a writable region. DCHECK(!h[1].is_valid()); diff --git a/mojo/core/broker_posix.cc b/mojo/core/broker_posix.cc index 96cdf72864dd67..26c7c2d71412ba 100644 --- a/mojo/core/broker_posix.cc +++ b/mojo/core/broker_posix.cc @@ -13,6 +13,7 @@ #include "base/logging.h" #include "base/memory/platform_shared_memory_region.h" #include "build/build_config.h" +#include "mojo/buildflags.h" #include "mojo/core/broker_messages.h" #include "mojo/core/channel.h" #include "mojo/core/platform_handle_utils.h" @@ -115,7 +116,8 @@ base::WritableSharedMemoryRegion Broker::GetWritableSharedMemoryRegion( return base::WritableSharedMemoryRegion(); } -#if !BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) +#if !BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_ANDROID) || \ + BUILDFLAG(MOJO_USE_APPLE_CHANNEL) // Non-POSIX systems, as well as Android and Mac, only use a single handle to // represent a writable region. constexpr size_t kNumExpectedHandles = 1; diff --git a/mojo/core/channel.cc b/mojo/core/channel.cc index fe5e6a8aef064c..71d2ab3c21df35 100644 --- a/mojo/core/channel.cc +++ b/mojo/core/channel.cc @@ -28,7 +28,7 @@ #include "mojo/core/core.h" #include "mojo/core/embedder/features.h" -#if BUILDFLAG(IS_MAC) +#if BUILDFLAG(MOJO_USE_APPLE_CHANNEL) #include "base/mac/mach_logging.h" #elif BUILDFLAG(IS_WIN) #include "base/win/win_util.h" @@ -185,7 +185,7 @@ struct ComplexMessage : public Channel::Message { #if BUILDFLAG(IS_WIN) // On Windows, handles are serialised into the extra header section. raw_ptr handles_ = nullptr; -#elif BUILDFLAG(IS_MAC) +#elif BUILDFLAG(MOJO_USE_APPLE_CHANNEL) // On OSX, handles are serialised into the extra header section. raw_ptr mach_ports_header_ = nullptr; #endif @@ -354,7 +354,7 @@ Channel::MessagePtr Channel::Message::Deserialize( uint32_t max_handles = extra_header_size / sizeof(HandleEntry); #elif BUILDFLAG(IS_FUCHSIA) uint32_t max_handles = extra_header_size / sizeof(HandleInfoEntry); -#elif BUILDFLAG(IS_MAC) +#elif BUILDFLAG(MOJO_USE_APPLE_CHANNEL) if (extra_header_size > 0 && extra_header_size < sizeof(MachPortsExtraHeader)) { DLOG(ERROR) << "Decoding invalid message: " << extra_header_size << " < " @@ -523,7 +523,7 @@ ComplexMessage::ComplexMessage(size_t capacity, #elif BUILDFLAG(IS_FUCHSIA) // On Fuchsia we serialize handle types into the extra header space. extra_header_size = max_handles_ * sizeof(HandleInfoEntry); -#elif BUILDFLAG(IS_MAC) +#elif BUILDFLAG(MOJO_USE_APPLE_CHANNEL) // On OSX, some of the platform handles may be mach ports, which are // serialised into the message buffer. Since there could be a mix of fds and // mach ports, we store the mach ports as an pair (of uint32_t), @@ -573,7 +573,7 @@ ComplexMessage::ComplexMessage(size_t capacity, // Initialize all handles to invalid values. for (size_t i = 0; i < max_handles_; ++i) handles_[i].handle = base::win::HandleToUint32(INVALID_HANDLE_VALUE); -#elif BUILDFLAG(IS_MAC) +#elif BUILDFLAG(MOJO_USE_APPLE_CHANNEL) mach_ports_header_ = reinterpret_cast(mutable_extra_header()); mach_ports_header_->num_ports = 0; @@ -609,7 +609,7 @@ bool ComplexMessage::ExtendPayload(size_t new_payload_size) { // payload buffer has been relocated. #if BUILDFLAG(IS_WIN) handles_ = reinterpret_cast(mutable_extra_header()); -#elif BUILDFLAG(IS_MAC) +#elif BUILDFLAG(MOJO_USE_APPLE_CHANNEL) mach_ports_header_ = reinterpret_cast(mutable_extra_header()); #endif @@ -662,7 +662,7 @@ void ComplexMessage::SetHandles( } #endif // BUILDFLAG(IS_WIN) -#if BUILDFLAG(IS_MAC) +#if BUILDFLAG(MOJO_USE_APPLE_CHANNEL) if (mach_ports_header_) { for (size_t i = 0; i < max_handles_; ++i) { mach_ports_header_->entries[i] = {0}; diff --git a/mojo/core/channel.h b/mojo/core/channel.h index 286f79a38c8aa7..4cc0e92760e26e 100644 --- a/mojo/core/channel.h +++ b/mojo/core/channel.h @@ -18,6 +18,7 @@ #include "base/synchronization/lock.h" #include "base/task/single_thread_task_runner.h" #include "build/build_config.h" +#include "mojo/buildflags.h" #include "mojo/core/connection_params.h" #include "mojo/core/platform_handle_in_transit.h" #include "mojo/public/cpp/platform/platform_channel_endpoint.h" @@ -146,7 +147,7 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel uint32_t num_bytes; }; -#if BUILDFLAG(IS_MAC) +#if BUILDFLAG(MOJO_USE_APPLE_CHANNEL) struct MachPortsEntry { // The PlatformHandle::Type. uint8_t type; @@ -327,10 +328,12 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel Channel(const Channel&) = delete; Channel& operator=(const Channel&) = delete; -#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && \ + !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) // At this point only ChannelPosix needs InitFeatures. static void set_posix_use_writev(bool use_writev); -#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_MAC) +#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && + // !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) static void set_use_trivial_messages(bool use_trivial_messages); diff --git a/mojo/core/core.cc b/mojo/core/core.cc index 44089825f1f987..caeb00dea277ab 100644 --- a/mojo/core/core.cc +++ b/mojo/core/core.cc @@ -24,6 +24,7 @@ #include "base/trace_event/memory_dump_manager.h" #include "base/trace_event/trace_id_helper.h" #include "build/build_config.h" +#include "mojo/buildflags.h" #include "mojo/core/channel.h" #include "mojo/core/configuration.h" #include "mojo/core/data_pipe_consumer_dispatcher.h" @@ -1031,7 +1032,8 @@ MojoResult Core::WrapPlatformSharedMemoryRegion( MojoHandle* mojo_handle) { DCHECK(size); -#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && \ + !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) if (access_mode == MOJO_PLATFORM_SHARED_MEMORY_REGION_ACCESS_MODE_WRITABLE) { if (num_platform_handles != 2) return MOJO_RESULT_INVALID_ARGUMENT; @@ -1154,7 +1156,8 @@ MojoResult Core::UnwrapPlatformSharedMemoryRegion( if (available_handle_storage_slots < 1) return MOJO_RESULT_RESOURCE_EXHAUSTED; *num_platform_handles = 1; -#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && \ + !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) if (region.GetMode() == base::subtle::PlatformSharedMemoryRegion::Mode::kWritable) { if (available_handle_storage_slots < 2) diff --git a/mojo/core/embedder/BUILD.gn b/mojo/core/embedder/BUILD.gn index 32327cd8410afb..fce6597c6d6da0 100644 --- a/mojo/core/embedder/BUILD.gn +++ b/mojo/core/embedder/BUILD.gn @@ -20,6 +20,7 @@ component("embedder") { public_deps = [ "//base", + "//mojo:buildflags", "//mojo/public/cpp/platform", "//third_party/ipcz/src:ipcz_chromium", ] @@ -39,5 +40,8 @@ component("features") { public = [ "features.h" ] sources = [ "features.cc" ] - public_deps = [ "//base" ] + public_deps = [ + "//base", + "//mojo:buildflags", + ] } diff --git a/mojo/core/embedder/embedder.cc b/mojo/core/embedder/embedder.cc index 53968a70b94245..868b521ebac602 100644 --- a/mojo/core/embedder/embedder.cc +++ b/mojo/core/embedder/embedder.cc @@ -14,6 +14,7 @@ #include "base/task/single_thread_task_runner.h" #include "base/task/task_runner.h" #include "build/build_config.h" +#include "mojo/buildflags.h" #include "mojo/core/channel.h" #include "mojo/core/configuration.h" #include "mojo/core/core.h" @@ -51,7 +52,8 @@ std::atomic g_mojo_ipcz_enabled{true}; void InitFeatures() { CHECK(base::FeatureList::GetInstance()); -#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && \ + !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) Channel::set_posix_use_writev( base::FeatureList::IsEnabled(kMojoPosixUseWritev)); diff --git a/mojo/core/embedder/features.cc b/mojo/core/embedder/features.cc index abfc12bd545281..c35da9455d526f 100644 --- a/mojo/core/embedder/features.cc +++ b/mojo/core/embedder/features.cc @@ -9,7 +9,8 @@ namespace mojo { namespace core { -#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && \ + !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) BASE_FEATURE(kMojoLinuxChannelSharedMem, "MojoLinuxChannelSharedMem", @@ -25,7 +26,8 @@ const base::FeatureParam kMojoLinuxChannelSharedMemEfdZeroOnWake{ BASE_FEATURE(kMojoPosixUseWritev, "MojoPosixUseWritev", base::FEATURE_DISABLED_BY_DEFAULT); -#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_MAC) +#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && + // !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) BASE_FEATURE(kMojoInlineMessagePayloads, "MojoInlineMessagePayloads", diff --git a/mojo/core/embedder/features.h b/mojo/core/embedder/features.h index 79a2ab2ca42bca..392886cb59a9a2 100644 --- a/mojo/core/embedder/features.h +++ b/mojo/core/embedder/features.h @@ -9,11 +9,13 @@ #include "base/feature_list.h" #include "base/metrics/field_trial_params.h" #include "build/build_config.h" +#include "mojo/buildflags.h" namespace mojo { namespace core { -#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && \ + !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID) COMPONENT_EXPORT(MOJO_CORE_EMBEDDER_FEATURES) BASE_DECLARE_FEATURE(kMojoLinuxChannelSharedMem); @@ -29,7 +31,8 @@ extern const base::FeatureParam kMojoLinuxChannelSharedMemEfdZeroOnWake; COMPONENT_EXPORT(MOJO_CORE_EMBEDDER_FEATURES) BASE_DECLARE_FEATURE(kMojoPosixUseWritev); -#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && !BUILDFLAG(IS_MAC) +#endif // BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_NACL) && + // !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) COMPONENT_EXPORT(MOJO_CORE_EMBEDDER_FEATURES) BASE_DECLARE_FEATURE(kMojoInlineMessagePayloads); diff --git a/mojo/core/invitation_unittest.cc b/mojo/core/invitation_unittest.cc index 080324374e424f..82802319ad06cc 100644 --- a/mojo/core/invitation_unittest.cc +++ b/mojo/core/invitation_unittest.cc @@ -24,6 +24,7 @@ #include "base/test/multiprocess_test.h" #include "base/test/task_environment.h" #include "build/build_config.h" +#include "mojo/buildflags.h" #include "mojo/core/core.h" #include "mojo/core/embedder/embedder.h" #include "mojo/core/node_controller.h" @@ -36,6 +37,10 @@ #include "mojo/public/cpp/system/platform_handle.h" #include "third_party/abseil-cpp/absl/types/optional.h" +#if BUILDFLAG(MOJO_USE_APPLE_CHANNEL) +#include "base/mac/mach_port_rendezvous.h" +#endif + namespace mojo { namespace core { namespace { @@ -90,7 +95,7 @@ void PrepareToPassRemoteEndpoint(PlatformChannel* channel, std::string value; #if BUILDFLAG(IS_FUCHSIA) channel->PrepareToPassRemoteEndpoint(&options->handles_to_transfer, &value); -#elif BUILDFLAG(IS_MAC) +#elif BUILDFLAG(MOJO_USE_APPLE_CHANNEL) channel->PrepareToPassRemoteEndpoint(&options->mach_ports_for_rendezvous, &value); #elif BUILDFLAG(IS_POSIX) diff --git a/mojo/core/shared_buffer_dispatcher.cc b/mojo/core/shared_buffer_dispatcher.cc index 575a992af59dd7..b1c2777d04aeb5 100644 --- a/mojo/core/shared_buffer_dispatcher.cc +++ b/mojo/core/shared_buffer_dispatcher.cc @@ -14,6 +14,7 @@ #include "base/logging.h" #include "base/memory/ptr_util.h" #include "build/build_config.h" +#include "mojo/buildflags.h" #include "mojo/core/configuration.h" #include "mojo/core/node_controller.h" #include "mojo/core/options_validation.h" @@ -145,7 +146,8 @@ scoped_refptr SharedBufferDispatcher::Deserialize( } PlatformHandle handles[2]; -#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && \ + !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) if (serialized_state->access_mode == MOJO_PLATFORM_SHARED_MEMORY_REGION_ACCESS_MODE_WRITABLE) { if (num_platform_handles != 2) @@ -323,7 +325,8 @@ void SharedBufferDispatcher::StartSerialize(uint32_t* num_bytes, *num_bytes = sizeof(SerializedState); *num_ports = 0; *num_platform_handles = 1; -#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && \ + !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) if (region_.GetMode() == base::subtle::PlatformSharedMemoryRegion::Mode::kWritable) { *num_platform_handles = 2; @@ -362,7 +365,8 @@ bool SharedBufferDispatcher::EndSerialize(void* destination, serialized_state->padding = 0; auto region = std::move(region_); -#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_MAC) +#if BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID) && \ + !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) if (region.GetMode() == base::subtle::PlatformSharedMemoryRegion::Mode::kWritable) { PlatformHandle platform_handles[2]; diff --git a/mojo/features.gni b/mojo/features.gni new file mode 100644 index 00000000000000..8a39caaf17b7b7 --- /dev/null +++ b/mojo/features.gni @@ -0,0 +1,9 @@ +# 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. + +import("//build/config/features.gni") + +declare_args() { + mojo_use_apple_channel = is_mac || (is_ios && use_blink) +} diff --git a/mojo/public/DEPS b/mojo/public/DEPS index f9b6d571e3f096..432815c4f8e73d 100644 --- a/mojo/public/DEPS +++ b/mojo/public/DEPS @@ -1,12 +1,12 @@ include_rules = [ "+base", "+build", - "+mojo/public", "+testing", "+third_party/ipcz/include", "-mojo", "+mojo/public", + "+mojo/buildflags.h", # Temporary until mojom [Native] is gone. "+ipc/ipc_param_traits.h", diff --git a/mojo/public/cpp/base/BUILD.gn b/mojo/public/cpp/base/BUILD.gn index ecb18f9098d4e7..74462c103aa2ad 100644 --- a/mojo/public/cpp/base/BUILD.gn +++ b/mojo/public/cpp/base/BUILD.gn @@ -69,6 +69,7 @@ component("typemap_traits") { public_deps = [ ":shared_typemap_traits", "//base", + "//mojo:buildflags", "//mojo/public/cpp/base", "//mojo/public/mojom/base:base_shared", ] diff --git a/mojo/public/cpp/base/file_unittest.cc b/mojo/public/cpp/base/file_unittest.cc index cb4b38b2c3474e..f6c04e3ef911e0 100644 --- a/mojo/public/cpp/base/file_unittest.cc +++ b/mojo/public/cpp/base/file_unittest.cc @@ -5,6 +5,7 @@ #include "base/files/scoped_temp_dir.h" #include "base/sync_socket.h" #include "build/build_config.h" +#include "mojo/buildflags.h" #include "mojo/public/cpp/base/file_mojom_traits.h" #include "mojo/public/cpp/base/read_only_file_mojom_traits.h" #include "mojo/public/cpp/test_support/test_utils.h" @@ -135,8 +136,9 @@ TEST(FileTest, ReadOnlyFileDeath) { #endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) // This should work on all platforms. This check might be relaxed in which case -// this test can be removed. -#if DCHECK_IS_ON() +// this test can be removed. iOS without blink does not build SyncSocket, so do +// not build this when blink isn't used. +#if DCHECK_IS_ON() && (!BUILDFLAG(IS_IOS) || BUILDFLAG(MOJO_USE_APPLE_CHANNEL)) TEST(FileTest, NonPhysicalFileDeath) { #if defined(OFFICIAL_BUILD) const char kPhysicalFileCheckFailedRegex[] = ""; diff --git a/mojo/public/cpp/platform/BUILD.gn b/mojo/public/cpp/platform/BUILD.gn index a51ff31e98baec..5c07c9185c1f3b 100644 --- a/mojo/public/cpp/platform/BUILD.gn +++ b/mojo/public/cpp/platform/BUILD.gn @@ -35,6 +35,7 @@ component("platform") { public_deps = [ "//base", + "//mojo:buildflags", "//mojo/public/c/system:headers", ] diff --git a/mojo/public/cpp/platform/DEPS b/mojo/public/cpp/platform/DEPS index 1bb0bd35dbe679..b92f5c5885794f 100644 --- a/mojo/public/cpp/platform/DEPS +++ b/mojo/public/cpp/platform/DEPS @@ -2,6 +2,7 @@ include_rules = [ # Mojo platform support must not depend on any other part of the Mojo public # library. "-mojo", + "+mojo/buildflags.h", "+mojo/public/c/system", "+mojo/public/cpp/platform", "+net/base", diff --git a/mojo/public/cpp/platform/platform_channel.cc b/mojo/public/cpp/platform/platform_channel.cc index 470b55c6600c70..83bf6f8146c30c 100644 --- a/mojo/public/cpp/platform/platform_channel.cc +++ b/mojo/public/cpp/platform/platform_channel.cc @@ -16,6 +16,7 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "build/build_config.h" +#include "mojo/buildflags.h" #if BUILDFLAG(IS_WIN) #include @@ -36,7 +37,7 @@ #include "base/posix/global_descriptors.h" #endif -#if BUILDFLAG(IS_MAC) +#if BUILDFLAG(MOJO_USE_APPLE_CHANNEL) #include #include "base/mac/mach_logging.h" @@ -101,7 +102,7 @@ void CreateChannel(PlatformHandle* local_endpoint, DCHECK(local_endpoint->is_valid()); DCHECK(remote_endpoint->is_valid()); } -#elif BUILDFLAG(IS_MAC) +#elif BUILDFLAG(MOJO_USE_APPLE_CHANNEL) void CreateChannel(PlatformHandle* local_endpoint, PlatformHandle* remote_endpoint) { // Mach messaging is simplex; and in order to enable full-duplex diff --git a/mojo/public/cpp/platform/platform_channel_endpoint.cc b/mojo/public/cpp/platform/platform_channel_endpoint.cc index 1db7bbfb0a3ae6..15f90cde0446af 100644 --- a/mojo/public/cpp/platform/platform_channel_endpoint.cc +++ b/mojo/public/cpp/platform/platform_channel_endpoint.cc @@ -15,9 +15,10 @@ #include "build/build_config.h" #include "mojo/public/cpp/platform/platform_channel.h" -#if BUILDFLAG(IS_MAC) +#if BUILDFLAG(MOJO_USE_APPLE_CHANNEL) #include +#include "base/mac/mach_port_rendezvous.h" #include "base/mac/scoped_mach_port.h" #elif BUILDFLAG(IS_FUCHSIA) #include @@ -40,7 +41,7 @@ namespace { // generate a key when setting the file descriptor. constexpr int kAndroidClientHandleDescriptor = base::GlobalDescriptors::kBaseDescriptor + 10000; -#elif BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_MAC) +#elif BUILDFLAG(IS_POSIX) && !BUILDFLAG(MOJO_USE_APPLE_CHANNEL) bool IsTargetDescriptorUsed(const base::FileHandleMappingVector& mapping, int target_fd) { for (auto& [i, fd] : mapping) { @@ -99,7 +100,7 @@ void PlatformChannelEndpoint::PrepareToPass(HandlePassingInfo& info, int mapped_fd = kAndroidClientHandleDescriptor + info.size(); info.emplace_back(fd, mapped_fd); value = base::NumberToString(mapped_fd); -#elif BUILDFLAG(IS_MAC) +#elif BUILDFLAG(MOJO_USE_APPLE_CHANNEL) DCHECK(platform_handle().is_mach_receive()); base::mac::ScopedMachReceiveRight receive_right = TakePlatformHandle().TakeMachReceiveRight(); @@ -134,7 +135,7 @@ void PlatformChannelEndpoint::PrepareToPass(base::LaunchOptions& options, PrepareToPass(options.handles_to_inherit, command_line); #elif BUILDFLAG(IS_FUCHSIA) PrepareToPass(options.handles_to_transfer, command_line); -#elif BUILDFLAG(IS_MAC) +#elif BUILDFLAG(MOJO_USE_APPLE_CHANNEL) PrepareToPass(options.mach_ports_for_rendezvous, command_line); #elif BUILDFLAG(IS_POSIX) PrepareToPass(options.fds_to_remap, command_line); @@ -182,7 +183,7 @@ PlatformChannelEndpoint PlatformChannelEndpoint::RecoverFromString( } return PlatformChannelEndpoint(PlatformHandle( base::ScopedFD(base::GlobalDescriptors::GetInstance()->Get(key)))); -#elif BUILDFLAG(IS_MAC) +#elif BUILDFLAG(MOJO_USE_APPLE_CHANNEL) auto* client = base::MachPortRendezvousClient::GetInstance(); if (!client) { DLOG(ERROR) << "Mach rendezvous failed."; diff --git a/mojo/public/cpp/platform/platform_channel_endpoint.h b/mojo/public/cpp/platform/platform_channel_endpoint.h index c6b25bb096ba8e..086b2f05526ab1 100644 --- a/mojo/public/cpp/platform/platform_channel_endpoint.h +++ b/mojo/public/cpp/platform/platform_channel_endpoint.h @@ -10,6 +10,7 @@ #include "base/process/launch.h" #include "base/strings/string_piece.h" #include "build/build_config.h" +#include "mojo/buildflags.h" #include "mojo/public/cpp/platform/platform_handle.h" namespace mojo { @@ -26,7 +27,7 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformChannelEndpoint { using HandlePassingInfo = base::HandlesToInheritVector; #elif BUILDFLAG(IS_FUCHSIA) using HandlePassingInfo = base::HandlesToTransferVector; -#elif BUILDFLAG(IS_MAC) +#elif BUILDFLAG(MOJO_USE_APPLE_CHANNEL) using HandlePassingInfo = base::MachPortsForRendezvous; #elif BUILDFLAG(IS_POSIX) using HandlePassingInfo = base::FileHandleMappingVector; diff --git a/mojo/public/tools/bindings/mojom.gni b/mojo/public/tools/bindings/mojom.gni index 6db8179e8587ac..ded5325917b879 100644 --- a/mojo/public/tools/bindings/mojom.gni +++ b/mojo/public/tools/bindings/mojom.gni @@ -1259,39 +1259,6 @@ template("mojom") { "${bindings_configuration.component_macro_suffix}_IMPL" ] } - export_args = [] - export_args_overridden = false - if (defined(bindings_configuration.for_blink) && - bindings_configuration.for_blink) { - if (defined(invoker.export_class_attribute_blink)) { - export_args_overridden = true - export_args += [ - "--export_attribute", - invoker.export_class_attribute_blink, - "--export_header", - invoker.export_header_blink, - ] - } - } else if (defined(invoker.export_class_attribute)) { - export_args_overridden = true - export_args += [ - "--export_attribute", - invoker.export_class_attribute, - "--export_header", - invoker.export_header, - ] - } - - if (!export_args_overridden && defined(invoker.component_macro_prefix)) { - export_args += [ - "--export_attribute", - "COMPONENT_EXPORT(${invoker.component_macro_prefix}" + - "${bindings_configuration.component_macro_suffix})", - "--export_header", - "base/component_export.h", - ] - } - generate_java = false if (!cpp_only && defined(invoker.generate_java)) { generate_java = invoker.generate_java @@ -1300,6 +1267,38 @@ template("mojom") { type_mappings_path = "$target_gen_dir/${target_name}${variant_suffix}__type_mappings" if (sources_list != []) { + export_args = [] + export_args_overridden = false + if (defined(bindings_configuration.for_blink) && + bindings_configuration.for_blink) { + if (defined(invoker.export_class_attribute_blink)) { + export_args_overridden = true + export_args += [ + "--export_attribute", + invoker.export_class_attribute_blink, + "--export_header", + invoker.export_header_blink, + ] + } + } else if (defined(invoker.export_class_attribute)) { + export_args_overridden = true + export_args += [ + "--export_attribute", + invoker.export_class_attribute, + "--export_header", + invoker.export_header, + ] + } + if (!export_args_overridden && defined(invoker.component_macro_prefix)) { + export_args += [ + "--export_attribute", + "COMPONENT_EXPORT(${invoker.component_macro_prefix}" + + "${bindings_configuration.component_macro_suffix})", + "--export_header", + "base/component_export.h", + ] + } + generator_cpp_output_suffixes = [] variant_dash_suffix = "" if (defined(variant)) { diff --git a/services/service_manager/service_process_launcher.cc b/services/service_manager/service_process_launcher.cc index a34c819f8d053e..7f4f7e76bb37a1 100644 --- a/services/service_manager/service_process_launcher.cc +++ b/services/service_manager/service_process_launcher.cc @@ -36,6 +36,10 @@ #include "services/service_manager/public/mojom/service.mojom.h" #include "services/service_manager/switches.h" +#if BUILDFLAG(IS_MAC) +#include "base/mac/mach_port_rendezvous.h" +#endif + #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) #include "sandbox/linux/services/namespace_sandbox.h" #endif diff --git a/services/service_manager/tests/util.cc b/services/service_manager/tests/util.cc index 9bf16a250be52e..8db9af7bbb39d8 100644 --- a/services/service_manager/tests/util.cc +++ b/services/service_manager/tests/util.cc @@ -25,6 +25,10 @@ #include "services/service_manager/public/mojom/service.mojom.h" #include "third_party/abseil-cpp/absl/types/optional.h" +#if BUILDFLAG(IS_MAC) +#include "base/mac/mach_port_rendezvous.h" +#endif + namespace service_manager { namespace test {