Title: [168584] trunk/Source/WebKit2
Revision
168584
Author
[email protected]
Date
2014-05-10 15:17:24 -0700 (Sat, 10 May 2014)

Log Message

WebKit2 is leaking an xpc_connection per web process it creates
https://bugs.webkit.org/show_bug.cgi?id=132785
<rdar://problem/14912160>

Reviewed by Sam Weinig.

Introduce an IPC::XPCPtr smart pointer class and use it for XPC connections inside Connection::Identifier and Connection itself.

Make sure we always adopt any connections that are created.

* DatabaseProcess/EntryPoint/mac/XPCService/DatabaseServiceEntryPoint.mm:
(DatabaseServiceInitializer):
* NetworkProcess/EntryPoint/mac/XPCService/NetworkServiceEntryPoint.mm:
(WebKit::NetworkServiceInitializerDelegate::NetworkServiceInitializerDelegate):
(NetworkServiceInitializer):
* Platform/IPC/Connection.h:
(IPC::Connection::Identifier::Identifier):
(IPC::Connection::xpcConnection):
* Platform/IPC/mac/ConnectionMac.mm:
(IPC::Connection::platformInvalidate):
(IPC::Connection::platformInitialize):
(IPC::Connection::getAuditToken):
* Platform/IPC/mac/XPCPtr.h: Added.
(IPC::XPCPtr::XPCPtr):
(IPC::XPCPtr::~XPCPtr):
(IPC::XPCPtr::get):
(IPC::XPCPtr::operator!):
(IPC::XPCPtr::operator=):
(IPC::adoptXPC):
* PluginProcess/EntryPoint/mac/XPCService/PluginServiceEntryPoint.mm:
(WebKit::PluginServiceInitializerDelegate::PluginServiceInitializerDelegate):
(PluginServiceInitializer):
* Shared/EntryPointUtilities/mac/LegacyProcess/ChildProcessMain.mm:
(WebKit::BootstrapMain):
* Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h:
(WebKit::XPCServiceInitializerDelegate::XPCServiceInitializerDelegate):
(WebKit::XPCServiceInitializer):
* Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm:
(WebKit::XPCServiceInitializerDelegate::hasEntitlement):
(WebKit::XPCServiceInitializerDelegate::isClientSandboxed):
* Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm:
(WebKit::XPCServiceEventHandler):
* Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm:
(WebKit::XPCServiceEventHandler):
* UIProcess/Launcher/ProcessLauncher.cpp:
(WebKit::ProcessLauncher::didFinishLaunchingProcess):
* UIProcess/Launcher/mac/ProcessLauncherMac.mm:
(WebKit::connectToService):
* WebKit2.xcodeproj/project.pbxproj:
* WebProcess/EntryPoint/mac/XPCService/WebContentServiceEntryPoint.mm:
(WebContentServiceInitializer):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (168583 => 168584)


--- trunk/Source/WebKit2/ChangeLog	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/ChangeLog	2014-05-10 22:17:24 UTC (rev 168584)
@@ -1,5 +1,59 @@
 2014-05-10  Anders Carlsson  <[email protected]>
 
+        WebKit2 is leaking an xpc_connection per web process it creates
+        https://bugs.webkit.org/show_bug.cgi?id=132785
+        <rdar://problem/14912160>
+
+        Reviewed by Sam Weinig.
+
+        Introduce an IPC::XPCPtr smart pointer class and use it for XPC connections inside Connection::Identifier and Connection itself.
+
+        Make sure we always adopt any connections that are created.
+
+        * DatabaseProcess/EntryPoint/mac/XPCService/DatabaseServiceEntryPoint.mm:
+        (DatabaseServiceInitializer):
+        * NetworkProcess/EntryPoint/mac/XPCService/NetworkServiceEntryPoint.mm:
+        (WebKit::NetworkServiceInitializerDelegate::NetworkServiceInitializerDelegate):
+        (NetworkServiceInitializer):
+        * Platform/IPC/Connection.h:
+        (IPC::Connection::Identifier::Identifier):
+        (IPC::Connection::xpcConnection):
+        * Platform/IPC/mac/ConnectionMac.mm:
+        (IPC::Connection::platformInvalidate):
+        (IPC::Connection::platformInitialize):
+        (IPC::Connection::getAuditToken):
+        * Platform/IPC/mac/XPCPtr.h: Added.
+        (IPC::XPCPtr::XPCPtr):
+        (IPC::XPCPtr::~XPCPtr):
+        (IPC::XPCPtr::get):
+        (IPC::XPCPtr::operator!):
+        (IPC::XPCPtr::operator=):
+        (IPC::adoptXPC):
+        * PluginProcess/EntryPoint/mac/XPCService/PluginServiceEntryPoint.mm:
+        (WebKit::PluginServiceInitializerDelegate::PluginServiceInitializerDelegate):
+        (PluginServiceInitializer):
+        * Shared/EntryPointUtilities/mac/LegacyProcess/ChildProcessMain.mm:
+        (WebKit::BootstrapMain):
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h:
+        (WebKit::XPCServiceInitializerDelegate::XPCServiceInitializerDelegate):
+        (WebKit::XPCServiceInitializer):
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm:
+        (WebKit::XPCServiceInitializerDelegate::hasEntitlement):
+        (WebKit::XPCServiceInitializerDelegate::isClientSandboxed):
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm:
+        (WebKit::XPCServiceEventHandler):
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm:
+        (WebKit::XPCServiceEventHandler):
+        * UIProcess/Launcher/ProcessLauncher.cpp:
+        (WebKit::ProcessLauncher::didFinishLaunchingProcess):
+        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+        (WebKit::connectToService):
+        * WebKit2.xcodeproj/project.pbxproj:
+        * WebProcess/EntryPoint/mac/XPCService/WebContentServiceEntryPoint.mm:
+        (WebContentServiceInitializer):
+
+2014-05-10  Anders Carlsson  <[email protected]>
+
         Simplify createDataAvailableSource
         https://bugs.webkit.org/show_bug.cgi?id=132782
         <rdar://problem/16815202>

Modified: trunk/Source/WebKit2/DatabaseProcess/EntryPoint/mac/XPCService/DatabaseServiceEntryPoint.mm (168583 => 168584)


--- trunk/Source/WebKit2/DatabaseProcess/EntryPoint/mac/XPCService/DatabaseServiceEntryPoint.mm	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/DatabaseProcess/EntryPoint/mac/XPCService/DatabaseServiceEntryPoint.mm	2014-05-10 22:17:24 UTC (rev 168584)
@@ -36,5 +36,5 @@
 
 void DatabaseServiceInitializer(xpc_connection_t connection, xpc_object_t initializerMessage)
 {
-    XPCServiceInitializer<DatabaseProcess, XPCServiceInitializerDelegate>(connection, initializerMessage);
+    XPCServiceInitializer<DatabaseProcess, XPCServiceInitializerDelegate>(IPC::adoptXPC(connection), initializerMessage);
 }

Modified: trunk/Source/WebKit2/NetworkProcess/EntryPoint/mac/XPCService/NetworkServiceEntryPoint.mm (168583 => 168584)


--- trunk/Source/WebKit2/NetworkProcess/EntryPoint/mac/XPCService/NetworkServiceEntryPoint.mm	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/NetworkProcess/EntryPoint/mac/XPCService/NetworkServiceEntryPoint.mm	2014-05-10 22:17:24 UTC (rev 168584)
@@ -34,8 +34,8 @@
 
 class NetworkServiceInitializerDelegate : public XPCServiceInitializerDelegate {
 public:
-    NetworkServiceInitializerDelegate(xpc_connection_t connection, xpc_object_t initializerMessage)
-        : XPCServiceInitializerDelegate(connection, initializerMessage)
+    NetworkServiceInitializerDelegate(IPC::XPCPtr<xpc_connection_t> connection, xpc_object_t initializerMessage)
+        : XPCServiceInitializerDelegate(std::move(connection), initializerMessage)
     {
     }
 };
@@ -53,6 +53,6 @@
     // the this process don't try to insert the shim and crash.
     EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/SecItemShim.dylib");
 
-    XPCServiceInitializer<NetworkProcess, NetworkServiceInitializerDelegate>(connection, initializerMessage);
+    XPCServiceInitializer<NetworkProcess, NetworkServiceInitializerDelegate>(IPC::adoptXPC(connection), initializerMessage);
 #endif
 }

Modified: trunk/Source/WebKit2/Platform/IPC/Connection.h (168583 => 168584)


--- trunk/Source/WebKit2/Platform/IPC/Connection.h	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.h	2014-05-10 22:17:24 UTC (rev 168584)
@@ -41,8 +41,8 @@
 #include <wtf/text/CString.h>
 
 #if OS(DARWIN)
+#include "XPCPtr.h"
 #include <mach/mach_port.h>
-#include <xpc/xpc.h>
 #endif
 
 #if PLATFORM(GTK) || PLATFORM(EFL)
@@ -92,27 +92,25 @@
     struct Identifier {
         Identifier()
             : port(MACH_PORT_NULL)
-            , xpcConnection(0)
         {
         }
 
         Identifier(mach_port_t port)
             : port(port)
-            , xpcConnection(0)
         {
         }
 
-        Identifier(mach_port_t port, xpc_connection_t xpcConnection)
+        Identifier(mach_port_t port, XPCPtr<xpc_connection_t> xpcConnection)
             : port(port)
-            , xpcConnection(xpcConnection)
+            , xpcConnection(std::move(xpcConnection))
         {
         }
 
         mach_port_t port;
-        xpc_connection_t xpcConnection;
+        XPCPtr<xpc_connection_t> xpcConnection;
     };
     static bool identifierIsNull(Identifier identifier) { return identifier.port == MACH_PORT_NULL; }
-    xpc_connection_t xpcConnection() { return m_xpcConnection; }
+    xpc_connection_t xpcConnection() { return m_xpcConnection.get(); }
     bool getAuditToken(audit_token_t&);
 #elif USE(UNIX_DOMAIN_SOCKETS)
     typedef int Identifier;
@@ -298,7 +296,7 @@
     dispatch_source_t m_exceptionPortDataAvailableSource;
 #endif
 
-    xpc_connection_t m_xpcConnection;
+    XPCPtr<xpc_connection_t> m_xpcConnection;
 
 #elif USE(UNIX_DOMAIN_SOCKETS)
     // Called on the connection queue.

Modified: trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm (168583 => 168584)


--- trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm	2014-05-10 22:17:24 UTC (rev 168584)
@@ -80,10 +80,7 @@
     }
 #endif
 
-    if (m_xpcConnection) {
-        xpc_release(m_xpcConnection);
-        m_xpcConnection = 0;
-    }
+    m_xpcConnection = nullptr;
 }
 
 void Connection::platformInitialize(Identifier identifier)
@@ -105,10 +102,6 @@
     m_receivePortDataAvailableSource = nullptr;
 
     m_xpcConnection = identifier.xpcConnection;
-    // FIXME: Instead of explicitly retaining the connection here, Identifier::xpcConnection
-    // should just be a smart pointer.
-    if (m_xpcConnection)
-        xpc_retain(m_xpcConnection);
 }
 
 template<typename Function>
@@ -520,13 +513,13 @@
 {
     return Identifier(m_isServer ? m_receivePort : m_sendPort, m_xpcConnection);
 }
-    
+
 bool Connection::getAuditToken(audit_token_t& auditToken)
 {
     if (!m_xpcConnection)
         return false;
     
-    xpc_connection_get_audit_token(m_xpcConnection, &auditToken);
+    xpc_connection_get_audit_token(m_xpcConnection.get(), &auditToken);
     return true;
 }
     

Copied: trunk/Source/WebKit2/Platform/IPC/mac/XPCPtr.h (from rev 168583, trunk/Source/WebKit2/NetworkProcess/EntryPoint/mac/XPCService/NetworkServiceEntryPoint.mm) (0 => 168584)


--- trunk/Source/WebKit2/Platform/IPC/mac/XPCPtr.h	                        (rev 0)
+++ trunk/Source/WebKit2/Platform/IPC/mac/XPCPtr.h	2014-05-10 22:17:24 UTC (rev 168584)
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef XPCPtr_h
+#define XPCPtr_h
+
+#include <xpc/xpc.h>
+
+namespace IPC {
+
+struct AdoptXPC { };
+
+template<typename T> class XPCPtr {
+public:
+    XPCPtr()
+        : m_ptr(nullptr)
+    {
+    }
+
+    XPCPtr(AdoptXPC, T ptr)
+        : m_ptr(ptr)
+    {
+    }
+
+    ~XPCPtr()
+    {
+        if (m_ptr)
+            xpc_release(m_ptr);
+    }
+
+    T get() const { return m_ptr; }
+
+    bool operator!() const { return !m_ptr; }
+
+    XPCPtr(const XPCPtr& other)
+        : m_ptr(other.m_ptr)
+    {
+        if (m_ptr)
+            xpc_retain(m_ptr);
+    }
+
+    XPCPtr(XPCPtr&& other)
+        : m_ptr(other.m_ptr)
+    {
+        other.m_ptr = nullptr;
+    }
+
+    XPCPtr& operator=(const XPCPtr& other)
+    {
+        T optr = other.get();
+        if (optr)
+            xpc_retain(optr);
+
+        T ptr = m_ptr;
+        m_ptr = optr;
+
+        if (ptr)
+            xpc_release(ptr);
+
+        return *this;
+    }
+
+    XPCPtr& operator=(std::nullptr_t)
+    {
+        if (m_ptr)
+            xpc_release(m_ptr);
+        m_ptr = nullptr;
+
+        return *this;
+    }
+private:
+    T m_ptr;
+};
+
+template<typename T> inline XPCPtr<T> adoptXPC(T ptr)
+{
+    return XPCPtr<T>(AdoptXPC { }, ptr);
+}
+
+} // namespace IPC
+
+#endif // XPCPtr_h

Modified: trunk/Source/WebKit2/PluginProcess/EntryPoint/mac/XPCService/PluginServiceEntryPoint.mm (168583 => 168584)


--- trunk/Source/WebKit2/PluginProcess/EntryPoint/mac/XPCService/PluginServiceEntryPoint.mm	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/PluginProcess/EntryPoint/mac/XPCService/PluginServiceEntryPoint.mm	2014-05-10 22:17:24 UTC (rev 168584)
@@ -37,8 +37,8 @@
 
 class PluginServiceInitializerDelegate : public XPCServiceInitializerDelegate {
 public:
-    PluginServiceInitializerDelegate(xpc_connection_t connection, xpc_object_t initializerMessage)
-        : XPCServiceInitializerDelegate(connection, initializerMessage)
+    PluginServiceInitializerDelegate(IPC::XPCPtr<xpc_connection_t> connection, xpc_object_t initializerMessage)
+        : XPCServiceInitializerDelegate(std::move(connection), initializerMessage)
     {
     }
 
@@ -76,6 +76,6 @@
     // spawned by the PluginProcess don't try to insert the shim and crash.
     EnvironmentUtilities::stripValuesEndingWithString("DYLD_INSERT_LIBRARIES", "/PluginProcessShim.dylib");
 
-    XPCServiceInitializer<PluginProcess, PluginServiceInitializerDelegate>(connection, initializerMessage);
+    XPCServiceInitializer<PluginProcess, PluginServiceInitializerDelegate>(IPC::adoptXPC(connection), initializerMessage);
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
 }

Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/LegacyProcess/ChildProcessMain.mm (168583 => 168584)


--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/LegacyProcess/ChildProcessMain.mm	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/LegacyProcess/ChildProcessMain.mm	2014-05-10 22:17:24 UTC (rev 168584)
@@ -59,7 +59,7 @@
 
     static void* frameworkLibrary = dlopen(argv[1], RTLD_NOW);
     if (!frameworkLibrary) {
-        NSLog(@"Unable to load WebKit2.framework: %s\n", dlerror());
+        NSLog(@"Unable to load WebKit.framework: %s\n", dlerror());
         return EXIT_FAILURE;
     }
 
@@ -73,7 +73,7 @@
 
         bootstrapMainFunction = reinterpret_cast<BootstrapMainFunction>(dlsym(frameworkLibrary, [entryPointFunctionName UTF8String]));
         if (!bootstrapMainFunction) {
-            NSLog(@"Unable to find entry point '%s' in WebKit2.framework: %s\n", [entryPointFunctionName UTF8String], dlerror());
+            NSLog(@"Unable to find entry point '%s' in WebKit.framework: %s\n", [entryPointFunctionName UTF8String], dlerror());
             return EXIT_FAILURE;
         }
     }

Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h (168583 => 168584)


--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.h	2014-05-10 22:17:24 UTC (rev 168584)
@@ -28,14 +28,14 @@
 
 #import "ChildProcess.h"
 #import "WebKit2Initialize.h"
-#import <xpc/xpc.h>
+#import "XPCPtr.h"
 
 namespace WebKit {
 
 class XPCServiceInitializerDelegate {
 public:
-    XPCServiceInitializerDelegate(xpc_connection_t connection, xpc_object_t initializerMessage)
-        : m_connection(connection)
+    XPCServiceInitializerDelegate(IPC::XPCPtr<xpc_connection_t> connection, xpc_object_t initializerMessage)
+        : m_connection(std::move(connection))
         , m_initializerMessage(initializerMessage)
     {
     }
@@ -55,14 +55,14 @@
     bool hasEntitlement(const char* entitlement);
     bool isClientSandboxed();
 
-    xpc_connection_t m_connection;
+    IPC::XPCPtr<xpc_connection_t> m_connection;
     xpc_object_t m_initializerMessage;
 };
 
 template<typename XPCServiceType, typename XPCServiceInitializerDelegateType>
-void XPCServiceInitializer(xpc_connection_t connection, xpc_object_t initializerMessage)
+void XPCServiceInitializer(IPC::XPCPtr<xpc_connection_t> connection, xpc_object_t initializerMessage)
 {
-    XPCServiceInitializerDelegateType delegate(connection, initializerMessage);
+    XPCServiceInitializerDelegateType delegate(std::move(connection), initializerMessage);
 
     // We don't want XPC to be in charge of whether the process should be terminated or not,
     // so ensure that we have an outstanding transaction here.

Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm (168583 => 168584)


--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceEntryPoint.mm	2014-05-10 22:17:24 UTC (rev 168584)
@@ -95,20 +95,16 @@
 
 bool XPCServiceInitializerDelegate::hasEntitlement(const char* entitlement)
 {
-    xpc_object_t value = xpc_connection_copy_entitlement_value(m_connection, entitlement);
+    auto value = IPC::adoptXPC(xpc_connection_copy_entitlement_value(m_connection.get(), entitlement));
     if (!value)
         return false;
 
-    bool result = xpc_get_type(value) == XPC_TYPE_BOOL && xpc_bool_get_value(value);
-
-    xpc_release(value);
-
-    return result;
+    return xpc_get_type(value.get()) == XPC_TYPE_BOOL && xpc_bool_get_value(value.get());
 }
 
 bool XPCServiceInitializerDelegate::isClientSandboxed()
 {
-    pid_t clientPID = xpc_connection_get_pid(m_connection);
+    pid_t clientPID = xpc_connection_get_pid(m_connection.get());
 
     return sandbox_check(clientPID, nullptr, SANDBOX_FILTER_NONE);
 }

Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm (168583 => 168584)


--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.Development.mm	2014-05-10 22:17:24 UTC (rev 168584)
@@ -29,7 +29,7 @@
 #import <spawn.h> 
 #import <stdio.h>
 #import <stdlib.h>
-#import <xpc/xpc.h>
+#import "XPCPtr.h"
 
 namespace WebKit {
 
@@ -122,7 +122,7 @@
             if (!strcmp(xpc_dictionary_get_string(event, "message-name"), "bootstrap")) {
                 static void* frameworkLibrary = dlopen(xpc_dictionary_get_string(event, "framework-executable-path"), RTLD_NOW);
                 if (!frameworkLibrary) {
-                    NSLog(@"Unable to load WebKit2.framework at path: %s (Error: %s)", xpc_dictionary_get_string(event, "framework-executable-path"), dlerror());
+                    NSLog(@"Unable to load WebKit.framework at path: %s (Error: %s)", xpc_dictionary_get_string(event, "framework-executable-path"), dlerror());
                     exit(EXIT_FAILURE);
                 }
 
@@ -136,10 +136,9 @@
                     exit(EXIT_FAILURE);
                 }
 
-                xpc_object_t reply = xpc_dictionary_create_reply(event);
-                xpc_dictionary_set_string(reply, "message-name", "process-finished-launching");
-                xpc_connection_send_message(xpc_dictionary_get_remote_connection(event), reply);
-                xpc_release(reply);
+                auto reply = IPC::adoptXPC(xpc_dictionary_create_reply(event));
+                xpc_dictionary_set_string(reply.get(), "message-name", "process-finished-launching");
+                xpc_connection_send_message(xpc_dictionary_get_remote_connection(event), reply.get());
 
                 dup2(xpc_dictionary_dup_fd(event, "stdout"), STDOUT_FILENO);
                 dup2(xpc_dictionary_dup_fd(event, "stderr"), STDERR_FILENO);

Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm (168583 => 168584)


--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm	2014-05-10 22:17:24 UTC (rev 168584)
@@ -24,7 +24,7 @@
  */
 
 #import <CoreFoundation/CoreFoundation.h>
-#import <xpc/xpc.h>
+#import "XPCPtr.h"
 
 namespace WebKit {
 
@@ -48,14 +48,13 @@
                 typedef void (*InitializerFunction)(xpc_connection_t, xpc_object_t);
                 InitializerFunction initializerFunctionPtr = reinterpret_cast<InitializerFunction>(CFBundleGetFunctionPointerForName(webKitBundle, entryPointFunctionName));
                 if (!initializerFunctionPtr) {
-                    NSLog(@"Unable to find entry point in WebKit2.framework with name: %@", (NSString *)entryPointFunctionName);
+                    NSLog(@"Unable to find entry point in WebKit.framework with name: %@", (NSString *)entryPointFunctionName);
                     exit(EXIT_FAILURE);
                 }
 
-                xpc_object_t reply = xpc_dictionary_create_reply(event);
-                xpc_dictionary_set_string(reply, "message-name", "process-finished-launching");
-                xpc_connection_send_message(xpc_dictionary_get_remote_connection(event), reply);
-                xpc_release(reply);
+                auto reply = IPC::adoptXPC(xpc_dictionary_create_reply(event));
+                xpc_dictionary_set_string(reply.get(), "message-name", "process-finished-launching");
+                xpc_connection_send_message(xpc_dictionary_get_remote_connection(event), reply.get());
 
                 initializerFunctionPtr(peer, event);
             }

Modified: trunk/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp (168583 => 168584)


--- trunk/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/UIProcess/Launcher/ProcessLauncher.cpp	2014-05-10 22:17:24 UTC (rev 168584)
@@ -57,11 +57,6 @@
 #if OS(DARWIN)
         if (identifier.port)
             mach_port_mod_refs(mach_task_self(), identifier.port, MACH_PORT_RIGHT_RECEIVE, -1);
-
-        if (identifier.xpcConnection) {
-            xpc_release(identifier.xpcConnection);
-            identifier.xpcConnection = 0;
-        }
 #endif
         return;
     }

Modified: trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm (168583 => 168584)


--- trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2014-05-10 22:17:24 UTC (rev 168584)
@@ -172,21 +172,20 @@
 
 static void connectToService(const ProcessLauncher::LaunchOptions& launchOptions, bool forDevelopment, ProcessLauncher* that, DidFinishLaunchingProcessFunction didFinishLaunchingProcessFunction, UUIDHolder* instanceUUID)
 {
-    // Create a connection to the WebKit2 XPC service.
-    xpc_connection_t connection = xpc_connection_create(serviceName(launchOptions, forDevelopment), 0);
-    xpc_connection_set_instance(connection, instanceUUID->uuid);
+    // Create a connection to the WebKit XPC service.
+    auto connection = IPC::adoptXPC(xpc_connection_create(serviceName(launchOptions, forDevelopment), 0));
+    xpc_connection_set_instance(connection.get(), instanceUUID->uuid);
 
     // XPC requires having an event handler, even if it is not used.
-    xpc_connection_set_event_handler(connection, ^(xpc_object_t event) { });
-    xpc_connection_resume(connection);
+    xpc_connection_set_event_handler(connection.get(), ^(xpc_object_t event) { });
+    xpc_connection_resume(connection.get());
 
 #if ENABLE(NETWORK_PROCESS) && !PLATFORM(IOS)
     // Leak a boost onto the NetworkProcess.
     if (launchOptions.processType == ProcessLauncher::NetworkProcess) {
-        xpc_object_t preBootstrapMessage = xpc_dictionary_create(0, 0, 0);
-        xpc_dictionary_set_string(preBootstrapMessage, "message-name", "pre-bootstrap");
-        xpc_connection_send_message(connection, preBootstrapMessage);
-        xpc_release(preBootstrapMessage);
+        auto preBootstrapMessage = IPC::adoptXPC(xpc_dictionary_create(nullptr, nullptr, 0));
+        xpc_dictionary_set_string(preBootstrapMessage.get(), "message-name", "pre-bootstrap");
+        xpc_connection_send_message(connection.get(), preBootstrapMessage.get());
     }
 #endif
 
@@ -200,29 +199,28 @@
     NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
     CString clientIdentifier = bundleIdentifier ? String([[NSBundle mainBundle] bundleIdentifier]).utf8() : *_NSGetProgname();
 
-    xpc_object_t bootstrapMessage = xpc_dictionary_create(0, 0, 0);
-    xpc_dictionary_set_string(bootstrapMessage, "message-name", "bootstrap");
-    xpc_dictionary_set_string(bootstrapMessage, "framework-executable-path", [[[NSBundle bundleWithIdentifier:@"com.apple.WebKit"] executablePath] fileSystemRepresentation]);
-    xpc_dictionary_set_mach_send(bootstrapMessage, "server-port", listeningPort);
-    xpc_dictionary_set_string(bootstrapMessage, "client-identifier", clientIdentifier.data());
-    xpc_dictionary_set_string(bootstrapMessage, "ui-process-name", [[[NSProcessInfo processInfo] processName] UTF8String]);
+    auto bootstrapMessage = IPC::adoptXPC(xpc_dictionary_create(nullptr, nullptr, 0));
+    xpc_dictionary_set_string(bootstrapMessage.get(), "message-name", "bootstrap");
+    xpc_dictionary_set_string(bootstrapMessage.get(), "framework-executable-path", [[[NSBundle bundleWithIdentifier:@"com.apple.WebKit"] executablePath] fileSystemRepresentation]);
+    xpc_dictionary_set_mach_send(bootstrapMessage.get(), "server-port", listeningPort);
+    xpc_dictionary_set_string(bootstrapMessage.get(), "client-identifier", clientIdentifier.data());
+    xpc_dictionary_set_string(bootstrapMessage.get(), "ui-process-name", [[[NSProcessInfo processInfo] processName] UTF8String]);
 
     if (forDevelopment) {
-        xpc_dictionary_set_fd(bootstrapMessage, "stdout", STDOUT_FILENO);
-        xpc_dictionary_set_fd(bootstrapMessage, "stderr", STDERR_FILENO);
+        xpc_dictionary_set_fd(bootstrapMessage.get(), "stdout", STDOUT_FILENO);
+        xpc_dictionary_set_fd(bootstrapMessage.get(), "stderr", STDERR_FILENO);
     }
 
-    xpc_object_t extraInitializationData = xpc_dictionary_create(0, 0, 0);
-    HashMap<String, String>::const_iterator it = launchOptions.extraInitializationData.begin();
-    HashMap<String, String>::const_iterator end = launchOptions.extraInitializationData.end();
-    for (; it != end; ++it)
-        xpc_dictionary_set_string(extraInitializationData, it->key.utf8().data(), it->value.utf8().data());
-    xpc_dictionary_set_value(bootstrapMessage, "extra-initialization-data", extraInitializationData);
-    xpc_release(extraInitializationData);
+    auto extraInitializationData = IPC::adoptXPC(xpc_dictionary_create(nullptr, nullptr, 0));
 
+    for (const auto& keyValuePair : launchOptions.extraInitializationData)
+        xpc_dictionary_set_string(extraInitializationData.get(), keyValuePair.key.utf8().data(), keyValuePair.value.utf8().data());
+
+    xpc_dictionary_set_value(bootstrapMessage.get(), "extra-initialization-data", extraInitializationData.get());
+
     that->ref();
 
-    xpc_connection_send_message_with_reply(connection, bootstrapMessage, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(xpc_object_t reply) {
+    xpc_connection_send_message_with_reply(connection.get(), bootstrapMessage.get(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(xpc_object_t reply) {
         xpc_type_t type = xpc_get_type(reply);
         if (type == XPC_TYPE_ERROR) {
             // We failed to launch. Release the send right.
@@ -237,15 +235,14 @@
             ASSERT(!strcmp(xpc_dictionary_get_string(reply, "message-name"), "process-finished-launching"));
 
             // The process has finished launching, grab the pid from the connection.
-            pid_t processIdentifier = xpc_connection_get_pid(connection);
+            pid_t processIdentifier = xpc_connection_get_pid(connection.get());
 
-            // We've finished launching the process, message back to the main run loop.
+            // We've finished launching the process, message back to the main run loop. This takes ownership of the connection.
             RunLoop::main().dispatch(bind(didFinishLaunchingProcessFunction, that, processIdentifier, IPC::Connection::Identifier(listeningPort, connection)));
         }
 
         that->deref();
     });
-    xpc_release(bootstrapMessage);
 }
 
 static void connectToReExecService(const ProcessLauncher::LaunchOptions& launchOptions, ProcessLauncher* that, DidFinishLaunchingProcessFunction didFinishLaunchingProcessFunction)
@@ -257,6 +254,8 @@
     // FIXME: This UUID should be stored on the ChildProcessProxy.
     RefPtr<UUIDHolder> instanceUUID = UUIDHolder::create();
 
+    // FIXME: It would be nice if we could use XPCPtr for this connection as well, but we'd have to be careful
+    // not to introduce any retain cycles in the call to xpc_connection_set_event_handler below.
     xpc_connection_t reExecConnection = xpc_connection_create(serviceName(launchOptions, true), 0);
     xpc_connection_set_instance(reExecConnection, instanceUUID->uuid);
 

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (168583 => 168584)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2014-05-10 22:17:24 UTC (rev 168584)
@@ -380,6 +380,7 @@
 		1AC86FF4130B46D3002C1257 /* WKPluginSiteDataManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AC86FF2130B46D3002C1257 /* WKPluginSiteDataManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		1AC8702D130B49A2002C1257 /* WebPluginSiteDataManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AC8702B130B49A2002C1257 /* WebPluginSiteDataManager.h */; };
 		1AC8702E130B49A2002C1257 /* WebPluginSiteDataManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1AC8702C130B49A2002C1257 /* WebPluginSiteDataManager.cpp */; };
+		1ACB7987191ECADD006A6A61 /* XPCPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ACB7986191ECADD006A6A61 /* XPCPtr.h */; };
 		1ACECD2417162DB1001FC9EF /* StorageAreaMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ACECD2217162DB1001FC9EF /* StorageAreaMap.cpp */; };
 		1ACECD2517162DB1001FC9EF /* StorageAreaMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 1ACECD2317162DB1001FC9EF /* StorageAreaMap.h */; };
 		1AD01BC81905D37E00C9C45F /* _WKErrorRecoveryAttempting.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AD01BC61905D37E00C9C45F /* _WKErrorRecoveryAttempting.mm */; };
@@ -2216,6 +2217,7 @@
 		1AC86FF2130B46D3002C1257 /* WKPluginSiteDataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKPluginSiteDataManager.h; sourceTree = "<group>"; };
 		1AC8702B130B49A2002C1257 /* WebPluginSiteDataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPluginSiteDataManager.h; sourceTree = "<group>"; };
 		1AC8702C130B49A2002C1257 /* WebPluginSiteDataManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPluginSiteDataManager.cpp; sourceTree = "<group>"; };
+		1ACB7986191ECADD006A6A61 /* XPCPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XPCPtr.h; sourceTree = "<group>"; };
 		1ACECD2217162DB1001FC9EF /* StorageAreaMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageAreaMap.cpp; sourceTree = "<group>"; };
 		1ACECD2317162DB1001FC9EF /* StorageAreaMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageAreaMap.h; sourceTree = "<group>"; };
 		1AD01BC61905D37E00C9C45F /* _WKErrorRecoveryAttempting.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKErrorRecoveryAttempting.mm; sourceTree = "<group>"; };
@@ -6272,6 +6274,7 @@
 				1A30EAC5115D7DA30053E937 /* ConnectionMac.mm */,
 				1A1EC69D1872092100B951F0 /* ImportanceAssertion.h */,
 				BCC56F771159957D001CCAF9 /* MachPort.h */,
+				1ACB7986191ECADD006A6A61 /* XPCPtr.h */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -7034,6 +7037,7 @@
 				33152976130D0CB200ED2483 /* SecurityOriginData.h in Headers */,
 				518D2CCB12D51DFB003BB93B /* SessionState.h in Headers */,
 				1AA20D5118AD50E0005D1ED4 /* WKNavigationDelegatePrivate.h in Headers */,
+				1ACB7987191ECADD006A6A61 /* XPCPtr.h in Headers */,
 				1A6420E512DCE2FF00CAAE2C /* ShareableBitmap.h in Headers */,
 				51217461164C20E30037A5C1 /* ShareableResource.h in Headers */,
 				1A24BED5120894D100FBB059 /* SharedMemory.h in Headers */,

Modified: trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentServiceEntryPoint.mm (168583 => 168584)


--- trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentServiceEntryPoint.mm	2014-05-10 20:51:20 UTC (rev 168583)
+++ trunk/Source/WebKit2/WebProcess/EntryPoint/mac/XPCService/WebContentServiceEntryPoint.mm	2014-05-10 22:17:24 UTC (rev 168584)
@@ -52,5 +52,5 @@
     InitWebCoreThreadSystemInterface();
 #endif // PLATFORM(IOS)
 
-    XPCServiceInitializer<WebProcess, XPCServiceInitializerDelegate>(connection, initializerMessage);
+    XPCServiceInitializer<WebProcess, XPCServiceInitializerDelegate>(IPC::adoptXPC(connection), initializerMessage);
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to