Everywhere: Replace Unix socket IPC transport with Mach ports on macOS

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.
This commit is contained in:
Aliaksandr Kalenik
2026-03-19 19:42:05 +01:00
committed by Alexander Kalenik
parent 8836f28267
commit 4ea4d63008
Notes: github-actions[bot] 2026-03-23 17:52:55 +00:00
37 changed files with 1139 additions and 149 deletions

View File

@@ -1292,15 +1292,28 @@ TransferDataEncoder::TransferDataEncoder(IPC::MessageBuffer&& buffer)
{
}
IPC::MessageBuffer const& TransferDataEncoder::buffer() const
{
return m_buffer;
}
IPC::MessageBuffer TransferDataEncoder::take_buffer() const
{
VERIFY(!m_buffer_has_been_taken);
m_buffer_has_been_taken = true;
return move(m_buffer);
}
void TransferDataEncoder::append(SerializationRecord&& record)
{
VERIFY(!m_buffer_has_been_taken);
MUST(m_buffer.append_data(record.data(), record.size()));
}
void TransferDataEncoder::extend(Vector<TransferDataEncoder> data_holders)
{
for (auto& data_holder : data_holders)
MUST(m_buffer.extend(move(data_holder.m_buffer)));
MUST(m_buffer.extend(data_holder.take_buffer()));
}
TransferDataDecoder::TransferDataDecoder(SerializationRecord const& record)
@@ -1337,12 +1350,14 @@ namespace IPC {
template<>
ErrorOr<void> encode(Encoder& encoder, Web::HTML::TransferDataEncoder const& data_holder)
{
TRY(encoder.encode(data_holder.buffer().data()));
auto buffer = data_holder.take_buffer();
auto data = buffer.take_data();
auto attachments = buffer.take_attachments();
auto const& attachments = data_holder.buffer().attachments();
TRY(encoder.encode(data));
TRY(encoder.encode(static_cast<u32>(attachments.size())));
for (auto const& attachment : attachments)
TRY(encoder.append_attachment(TRY(attachment.clone())));
for (auto& attachment : attachments)
TRY(encoder.append_attachment(move(attachment)));
return {};
}