Registering multiple Mach port names with the bootstrap server at runtime is not how macOS expects it to be used — the bootstrap server is meant for static services, and the only reason we used it originally was so child processes could reach back to the UI process. Remove bootstrap_transport_over_socket(), which had both sides register dynamic names with the bootstrap server and exchange them over a socket. Instead, WebDriver and BrowserProcess connections now go through MachPortServer instances directly. When a non-child process contacts a MachPortServer, the server creates a port pair on demand (detected via sysctl ppid check) and returns the local half immediately. This keeps bootstrap server usage limited to the one original case: child processes looking up their parent's MachPortServer. WebDriver Session now runs its own MachPortServer per session. --webdriver-content-path becomes --webdriver-mach-server-name on macOS. Spare WebContent launches are skipped when a WebDriver session is active to avoid bootstrap races.
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:
|
|
explicit MachPortServer(ByteString server_port_name);
|
|
~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 };
|
|
};
|
|
|
|
}
|