On macOS, use Mach port messaging instead of Unix domain sockets for all IPC transport. This makes the transport capable of carrying Mach port rights as message attachments, which is a prerequisite for sending IOSurface handles over the main IPC channel (currently sent via a separate out-of-band path). It also avoids the need for the FD acknowledgement protocol that TransportSocket requires, since Mach port right transfers are atomic in the kernel. Three connection establishment patterns: - Spawned helper processes (WebContent, RequestServer, etc.) use the existing MachPortServer: the child sends its task port with a reply port, and the parent responds with a pre-created port pair. - Socket-bootstrapped connections (WebDriver, BrowserProcess) exchange Mach port names over the socket, then drop the socket. - Pre-created pairs for IPC tests and in-message transport transfer. Attachment on macOS now wraps a MachPort instead of a file descriptor, converting between the two via fileport_makeport()/fileport_makefd(). The LibIPC socket transport tests are disabled on macOS since they are socket-specific.
57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2026, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/HashMap.h>
|
|
#include <AK/Platform.h>
|
|
#include <AK/StringView.h>
|
|
#include <AK/Variant.h>
|
|
|
|
#if !defined(AK_OS_MACH)
|
|
# error "TransportBootstrapMach is only available on Mach platforms"
|
|
#endif
|
|
|
|
#include <LibCore/MachPort.h>
|
|
#include <LibCore/Socket.h>
|
|
#include <LibThreading/Mutex.h>
|
|
|
|
namespace IPC {
|
|
|
|
struct TransportBootstrapMachPorts {
|
|
Core::MachPort receive_right;
|
|
Core::MachPort send_right;
|
|
};
|
|
|
|
ErrorOr<TransportBootstrapMachPorts> bootstrap_transport_from_mach_server(StringView server_name);
|
|
ErrorOr<TransportBootstrapMachPorts> bootstrap_transport_from_server_port(Core::MachPort const& server_port);
|
|
ErrorOr<TransportBootstrapMachPorts> bootstrap_transport_over_socket(Core::LocalSocket&);
|
|
|
|
class TransportBootstrapMachServer {
|
|
AK_MAKE_NONCOPYABLE(TransportBootstrapMachServer);
|
|
|
|
public:
|
|
TransportBootstrapMachServer() = default;
|
|
|
|
void register_pending_transport(pid_t, TransportBootstrapMachPorts);
|
|
void register_reply_port(pid_t, Core::MachPort reply_port);
|
|
|
|
private:
|
|
struct WaitingForPorts {
|
|
TransportBootstrapMachPorts ports;
|
|
};
|
|
struct WaitingForReplyPort {
|
|
Core::MachPort reply_port;
|
|
};
|
|
using PendingBootstrapState = Variant<WaitingForPorts, WaitingForReplyPort>;
|
|
|
|
static void send_transport_ports_to_child(Core::MachPort reply_port, TransportBootstrapMachPorts ports);
|
|
|
|
Threading::Mutex m_pending_bootstrap_mutex;
|
|
HashMap<pid_t, PendingBootstrapState> m_pending_bootstrap;
|
|
};
|
|
|
|
}
|