Modified: trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm (211534 => 211535)
--- trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm 2017-02-01 22:41:52 UTC (rev 211534)
+++ trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm 2017-02-01 22:52:02 UTC (rev 211535)
@@ -120,7 +120,7 @@
}
if (m_receivePort) {
- mach_port_mod_refs(mach_task_self(), m_receivePort, MACH_PORT_RIGHT_RECEIVE, -1);
+ mach_port_destruct(mach_task_self(), m_receivePort, 0, reinterpret_cast<mach_port_context_t>(this));
m_receivePort = MACH_PORT_NULL;
}
@@ -170,6 +170,8 @@
if (m_isServer) {
m_receivePort = identifier.port;
m_sendPort = MACH_PORT_NULL;
+
+ mach_port_guard(mach_task_self(), m_receivePort, reinterpret_cast<mach_port_context_t>(this), true);
} else {
m_receivePort = MACH_PORT_NULL;
m_sendPort = identifier.port;
@@ -181,19 +183,6 @@
m_xpcConnection = identifier.xpcConnection;
}
-template<typename Function>
-static dispatch_source_t createReceiveSource(mach_port_t receivePort, WorkQueue& workQueue, Function&& function)
-{
- dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, receivePort, 0, workQueue.dispatchQueue());
- dispatch_source_set_event_handler(source, function);
-
- dispatch_source_set_cancel_handler(source, ^{
- mach_port_mod_refs(mach_task_self(), receivePort, MACH_PORT_RIGHT_RECEIVE, -1);
- });
-
- return source;
-}
-
bool Connection::open()
{
if (m_isServer) {
@@ -205,17 +194,21 @@
ASSERT(m_sendPort);
// Create the receive port.
- mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &m_receivePort);
+ uint32_t flags = MPO_CONTEXT_AS_GUARD | MPO_QLIMIT | MPO_STRICT | MPO_INSERT_SEND_RIGHT;
#if PLATFORM(MAC)
- mach_port_set_attributes(mach_task_self(), m_receivePort, MACH_PORT_DENAP_RECEIVER, (mach_port_info_t)0, 0);
+ flags |= MPO_DENAP_RECEIVER;
#endif
+ mach_port_options_t portOptions;
+ portOptions.flags = flags;
+ portOptions.mpl.mpl_qlimit = MACH_PORT_QLIMIT_LARGE;
+ mach_port_construct(mach_task_self(), &portOptions, reinterpret_cast<mach_port_context_t>(this), &m_receivePort);
+
m_isConnected = true;
- // Send the initialize message, which contains a send right for the server to use.
auto encoder = std::make_unique<Encoder>("IPC", "InitializeConnection", 0);
- encoder->encode(MachPort(m_receivePort, MACH_MSG_TYPE_MAKE_SEND));
+ encoder->encode(MachPort(m_receivePort, MACH_MSG_TYPE_MOVE_SEND));
initializeSendSource();
@@ -222,20 +215,24 @@
sendMessage(WTFMove(encoder), { });
}
- // Change the message queue length for the receive port.
- setMachPortQueueLength(m_receivePort, MACH_PORT_QLIMIT_LARGE);
-
- // Register the data available handler.
RefPtr<Connection> connection(this);
- m_receiveSource = createReceiveSource(m_receivePort, m_connectionQueue, [connection] {
+ m_receiveSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, m_receivePort, 0, m_connectionQueue->dispatchQueue());
+ dispatch_source_set_event_handler(m_receiveSource, [connection] {
connection->receiveSourceEventHandler();
});
+ dispatch_source_set_cancel_handler(m_receiveSource, [connection, receivePort = m_receivePort] {
+ mach_port_destruct(mach_task_self(), receivePort, 0, reinterpret_cast<mach_port_context_t>(connection.get()));
+ });
#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED <= 101000
if (m_exceptionPort) {
- m_exceptionPortDataAvailableSource = createReceiveSource(m_exceptionPort, m_connectionQueue, [connection] {
+ m_exceptionPortDataAvailableSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, m_exceptionPort, 0, m_connectionQueue.dispatchQueue());
+ dispatch_source_set_event_handler(source, [connection] {
connection->exceptionSourceEventHandler();
});
+ dispatch_source_set_cancel_handler(source, [connection, exceptionPort = connection->m_exceptionPort] {
+ mach_port_mod_refs(mach_task_self(), exceptionPort, MACH_PORT_RIGHT_RECEIVE, -1);
+ });
auto encoder = std::make_unique<Encoder>("IPC", "SetExceptionPort", 0);
encoder->encode(MachPort(m_exceptionPort, MACH_MSG_TYPE_MAKE_SEND));