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.
63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Atomic.h>
|
|
#include <AK/Platform.h>
|
|
#include <AK/String.h>
|
|
#include <LibCore/MachPort.h>
|
|
#include <LibThreading/Forward.h>
|
|
#include <LibWebView/Forward.h>
|
|
|
|
#if !defined(AK_OS_MACH)
|
|
# error "This file is only for Mach kernel-based OS's"
|
|
#endif
|
|
|
|
namespace WebView {
|
|
|
|
class WEBVIEW_API MachPortServer {
|
|
|
|
public:
|
|
MachPortServer();
|
|
~MachPortServer();
|
|
|
|
void start();
|
|
void stop();
|
|
|
|
bool is_initialized();
|
|
|
|
struct ChildMachPortRegistration {
|
|
pid_t pid { -1 };
|
|
Core::MachPort child_port;
|
|
Core::MachPort reply_port;
|
|
};
|
|
Function<void(ChildMachPortRegistration)> on_receive_child_mach_port;
|
|
struct BackingStoresMessage {
|
|
pid_t pid { -1 };
|
|
u64 page_id { 0 };
|
|
i32 front_backing_store_id { 0 };
|
|
i32 back_backing_store_id { 0 };
|
|
Core::MachPort front_backing_store_port;
|
|
Core::MachPort back_backing_store_port;
|
|
};
|
|
Function<void(BackingStoresMessage)> on_receive_backing_stores;
|
|
|
|
ByteString const& server_port_name() const { return m_server_port_name; }
|
|
|
|
private:
|
|
void thread_loop();
|
|
ErrorOr<void> allocate_server_port();
|
|
|
|
NonnullRefPtr<Threading::Thread> m_thread;
|
|
ByteString const m_server_port_name;
|
|
Core::MachPort m_server_port_recv_right;
|
|
Core::MachPort m_server_port_send_right;
|
|
|
|
Atomic<bool> m_should_stop { false };
|
|
};
|
|
|
|
}
|