Title: [101141] trunk/Source
Revision
101141
Author
[email protected]
Date
2011-11-24 08:51:13 -0800 (Thu, 24 Nov 2011)

Log Message

[Qt]WK2][Mac] Use Mac port's IPC implementation instead of Unix sockets
https://bugs.webkit.org/show_bug.cgi?id=72495

Source/_javascript_Core:

Update defines to not use Unix Domain Sockets for platform Qt on Mac.
This enables Qt to reuse existing code for mach ports and Grand
Central Dispatch based IPC.

Reviewed by Simon Hausmann.

* wtf/Platform.h:

Source/WebKit2:

Make Qt using mach ports and Grand Central Dispatch for IPC
when building on Mac.

Reviewed by Simon Hausmann.

* Platform/CoreIPC/Attachment.cpp:
* Platform/CoreIPC/Attachment.h:
* Platform/CoreIPC/Connection.h:
* Platform/CoreIPC/CoreIPCMessageKinds.h:
* Platform/SharedMemory.h:
* Platform/WorkQueue.h:
* Platform/mac/MachUtilities.cpp:
* Platform/mac/WorkQueueMac.cpp:
* Target.pri:
* UIProcess/Launcher/qt/ProcessLauncherQt.cpp:
(WebKit::ProcessLauncher::launchProcess):
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didFinishLaunching):
* WebProcess/qt/WebProcessMainQt.cpp:
(WebKit::WebProcessMainQt):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (101140 => 101141)


--- trunk/Source/_javascript_Core/ChangeLog	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/_javascript_Core/ChangeLog	2011-11-24 16:51:13 UTC (rev 101141)
@@ -1,3 +1,16 @@
+2011-11-24  Zeno Albisser  <[email protected]>
+
+        [Qt]WK2][Mac] Use Mac port's IPC implementation instead of Unix sockets
+        https://bugs.webkit.org/show_bug.cgi?id=72495
+
+        Update defines to not use Unix Domain Sockets for platform Qt on Mac.
+        This enables Qt to reuse existing code for mach ports and Grand
+        Central Dispatch based IPC.
+
+        Reviewed by Simon Hausmann.
+
+        * wtf/Platform.h:
+
 2011-11-24  Simon Hausmann  <[email protected]>
 
         [Qt] REGRESSION(r101131): WTF::scheduleDispatchFunctionsOnMainThread() doesn't work reliably

Modified: trunk/Source/_javascript_Core/wtf/Platform.h (101140 => 101141)


--- trunk/Source/_javascript_Core/wtf/Platform.h	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/_javascript_Core/wtf/Platform.h	2011-11-24 16:51:13 UTC (rev 101141)
@@ -563,6 +563,7 @@
 
 #if PLATFORM(QT) && OS(DARWIN)
 #define WTF_USE_CF 1
+#define HAVE_DISPATCH_H 1
 #endif
 
 #if OS(DARWIN) && !PLATFORM(GTK) && !PLATFORM(QT)
@@ -1109,7 +1110,7 @@
    breakages one port at a time. */
 #define WTF_USE_EXPORT_MACROS 0
 
-#if PLATFORM(QT) || PLATFORM(GTK) || PLATFORM(EFL)
+#if (PLATFORM(QT) && !OS(DARWIN)) || PLATFORM(GTK) || PLATFORM(EFL)
 #define WTF_USE_UNIX_DOMAIN_SOCKETS 1
 #endif
 

Modified: trunk/Source/WebKit2/ChangeLog (101140 => 101141)


--- trunk/Source/WebKit2/ChangeLog	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/ChangeLog	2011-11-24 16:51:13 UTC (rev 101141)
@@ -1,3 +1,29 @@
+2011-11-24  Zeno Albisser  <[email protected]>
+
+        [Qt]WK2][Mac] Use Mac port's IPC implementation instead of Unix sockets
+        https://bugs.webkit.org/show_bug.cgi?id=72495
+
+        Make Qt using mach ports and Grand Central Dispatch for IPC
+        when building on Mac.
+
+        Reviewed by Simon Hausmann.
+
+        * Platform/CoreIPC/Attachment.cpp:
+        * Platform/CoreIPC/Attachment.h:
+        * Platform/CoreIPC/Connection.h:
+        * Platform/CoreIPC/CoreIPCMessageKinds.h:
+        * Platform/SharedMemory.h:
+        * Platform/WorkQueue.h:
+        * Platform/mac/MachUtilities.cpp:
+        * Platform/mac/WorkQueueMac.cpp:
+        * Target.pri:
+        * UIProcess/Launcher/qt/ProcessLauncherQt.cpp:
+        (WebKit::ProcessLauncher::launchProcess):
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::didFinishLaunching):
+        * WebProcess/qt/WebProcessMainQt.cpp:
+        (WebKit::WebProcessMainQt):
+
 2011-11-17  Oleg Romashin  <[email protected]>
 
         [Qt][WK2] Stop leaking memory in string QWK2 API's

Modified: trunk/Source/WebKit2/Platform/CoreIPC/Attachment.cpp (101140 => 101141)


--- trunk/Source/WebKit2/Platform/CoreIPC/Attachment.cpp	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/Platform/CoreIPC/Attachment.cpp	2011-11-24 16:51:13 UTC (rev 101141)
@@ -36,7 +36,7 @@
 {
 }
 
-#if PLATFORM(MAC)
+#if OS(DARWIN)
 Attachment::Attachment(mach_port_name_t port, mach_msg_type_name_t disposition)
     : m_type(MachPortType)
 {

Modified: trunk/Source/WebKit2/Platform/CoreIPC/Attachment.h (101140 => 101141)


--- trunk/Source/WebKit2/Platform/CoreIPC/Attachment.h	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/Platform/CoreIPC/Attachment.h	2011-11-24 16:51:13 UTC (rev 101141)
@@ -26,6 +26,11 @@
 #ifndef Attachment_h
 #define Attachment_h
 
+#if OS(DARWIN)
+#include <mach/mach_init.h>
+#include <mach/mach_traps.h>
+#endif
+
 namespace CoreIPC {
 
 class ArgumentDecoder;
@@ -37,7 +42,7 @@
 
     enum Type {
         Uninitialized,
-#if PLATFORM(MAC)
+#if OS(DARWIN)
         MachPortType,
         MachOOLMemoryType,
 #elif USE(UNIX_DOMAIN_SOCKETS)
@@ -46,7 +51,7 @@
 #endif
     };
 
-#if PLATFORM(MAC)
+#if OS(DARWIN)
     Attachment(mach_port_name_t port, mach_msg_type_name_t disposition);
     Attachment(void* address, mach_msg_size_t size, mach_msg_copy_options_t copyOptions, bool deallocate);
 #elif USE(UNIX_DOMAIN_SOCKETS)
@@ -56,7 +61,7 @@
 
     Type type() const { return m_type; }
 
-#if PLATFORM(MAC)
+#if OS(DARWIN)
     void release();
 
     // MachPortType
@@ -83,7 +88,7 @@
 private:
     Type m_type;
 
-#if PLATFORM(MAC)
+#if OS(DARWIN)
     union {
         struct {
             mach_port_name_t port;

Modified: trunk/Source/WebKit2/Platform/CoreIPC/Connection.h (101140 => 101141)


--- trunk/Source/WebKit2/Platform/CoreIPC/Connection.h	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/Platform/CoreIPC/Connection.h	2011-11-24 16:51:13 UTC (rev 101141)
@@ -38,7 +38,7 @@
 #include <wtf/OwnPtr.h>
 #include <wtf/Threading.h>
 
-#if PLATFORM(MAC)
+#if OS(DARWIN)
 #include <mach/mach_port.h>
 #elif PLATFORM(WIN)
 #include <string>
@@ -108,7 +108,7 @@
         virtual ~QueueClient() { }
     };
 
-#if PLATFORM(MAC)
+#if OS(DARWIN)
     typedef mach_port_t Identifier;
 #elif PLATFORM(WIN)
     typedef HANDLE Identifier;
@@ -121,7 +121,7 @@
     static PassRefPtr<Connection> createClientConnection(Identifier, Client*, RunLoop* clientRunLoop);
     ~Connection();
 
-#if PLATFORM(MAC)
+#if OS(DARWIN)
     void setShouldCloseConnectionOnMachExceptions();
 #elif PLATFORM(QT)
     void setShouldCloseConnectionOnProcessTermination(WebKit::PlatformProcessIdentifier);
@@ -317,7 +317,7 @@
     bool m_shouldWaitForSyncReplies;
     Vector<PendingSyncReply> m_pendingSyncReplies;
 
-#if PLATFORM(MAC)
+#if OS(DARWIN)
     // Called on the connection queue.
     void receiveSourceEventHandler();
     void initializeDeadNameSource();
@@ -350,7 +350,6 @@
     Vector<int> m_fileDescriptors;
     size_t m_fileDescriptorsSize;
     int m_socketDescriptor;
-
 #if PLATFORM(QT)
     QSocketNotifier* m_socketNotifier;
 #endif

Modified: trunk/Source/WebKit2/Platform/CoreIPC/CoreIPCMessageKinds.h (101140 => 101141)


--- trunk/Source/WebKit2/Platform/CoreIPC/CoreIPCMessageKinds.h	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/Platform/CoreIPC/CoreIPCMessageKinds.h	2011-11-24 16:51:13 UTC (rev 101141)
@@ -35,7 +35,7 @@
 enum Kind {
     InitializeConnection,
     SyncMessageReply,
-#if PLATFORM(MAC)
+#if OS(DARWIN)
     SetExceptionPort,
 #endif
 };

Modified: trunk/Source/WebKit2/Platform/SharedMemory.h (101140 => 101141)


--- trunk/Source/WebKit2/Platform/SharedMemory.h	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/Platform/SharedMemory.h	2011-11-24 16:51:13 UTC (rev 101141)
@@ -66,7 +66,7 @@
 #endif
     private:
         friend class SharedMemory;
-#if PLATFORM(MAC)
+#if OS(DARWIN)
         mutable mach_port_t m_port;
 #elif PLATFORM(WIN)
         mutable HANDLE m_handle;
@@ -105,7 +105,7 @@
 private:
     size_t m_size;
     void* m_data;
-#if PLATFORM(MAC)
+#if OS(DARWIN)
     mach_port_t m_port;
 #elif PLATFORM(WIN)
     HANDLE m_handle;

Modified: trunk/Source/WebKit2/Platform/WorkQueue.h (101140 => 101141)


--- trunk/Source/WebKit2/Platform/WorkQueue.h	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/Platform/WorkQueue.h	2011-11-24 16:51:13 UTC (rev 101141)
@@ -27,7 +27,7 @@
 #ifndef WorkQueue_h
 #define WorkQueue_h
 
-#if PLATFORM(MAC)
+#if OS(DARWIN)
 #if HAVE(DISPATCH_H)
 #include <dispatch/dispatch.h>
 #endif
@@ -40,7 +40,7 @@
 #include <wtf/Threading.h>
 #include <wtf/Vector.h>
 
-#if PLATFORM(QT)
+#if PLATFORM(QT) && !OS(DARWIN)
 #include <QSocketNotifier>
 #include "PlatformProcessIdentifier.h"
 class QObject;
@@ -67,7 +67,7 @@
 
     void invalidate();
 
-#if PLATFORM(MAC)
+#if OS(DARWIN)
     enum MachPortEventType {
         // Fired when there is data on the given receive right.
         MachPortDataAvailable,
@@ -100,7 +100,7 @@
     void platformInitialize(const char* name);
     void platformInvalidate();
 
-#if PLATFORM(MAC)
+#if OS(DARWIN)
 #if HAVE(DISPATCH_H)
     static void executeWorkItem(void*);
     Mutex m_eventSourcesMutex;

Modified: trunk/Source/WebKit2/Platform/mac/MachUtilities.cpp (101140 => 101141)


--- trunk/Source/WebKit2/Platform/mac/MachUtilities.cpp	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/Platform/mac/MachUtilities.cpp	2011-11-24 16:51:13 UTC (rev 101141)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "MachUtilities.h"
 
+#include <mach/mach_init.h>
 #include <mach/task.h>
 
 void setMachPortQueueLength(mach_port_t receivePort, mach_port_msgcount_t queueLength)

Modified: trunk/Source/WebKit2/Platform/mac/WorkQueueMac.cpp (101140 => 101141)


--- trunk/Source/WebKit2/Platform/mac/WorkQueueMac.cpp	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/Platform/mac/WorkQueueMac.cpp	2011-11-24 16:51:13 UTC (rev 101141)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "WorkQueue.h"
 
+#include <mach/mach_init.h>
 #include <mach/mach_port.h>
 #include <wtf/PassOwnPtr.h>
 

Modified: trunk/Source/WebKit2/Target.pri (101140 => 101141)


--- trunk/Source/WebKit2/Target.pri	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/Target.pri	2011-11-24 16:51:13 UTC (rev 101141)
@@ -424,16 +424,12 @@
     Platform/CoreIPC/BinarySemaphore.cpp \
     Platform/CoreIPC/Connection.cpp \
     Platform/CoreIPC/DataReference.cpp \
-    Platform/CoreIPC/unix/AttachmentUnix.cpp \
-    Platform/CoreIPC/unix/ConnectionUnix.cpp \
     Platform/Logging.cpp \
     Platform/Module.cpp \
     Platform/RunLoop.cpp \
     Platform/WorkQueue.cpp \
     Platform/qt/ModuleQt.cpp \
     Platform/qt/RunLoopQt.cpp \
-    Platform/qt/WorkQueueQt.cpp \
-    Platform/unix/SharedMemoryUnix.cpp \
     PluginProcess/PluginControllerProxy.cpp \
     PluginProcess/PluginProcess.cpp \
     PluginProcess/WebProcessConnection.cpp \
@@ -755,6 +751,29 @@
     WebProcess/qt/WebProcessQt.cpp \
     $$WEBKIT2_GENERATED_SOURCES
 
+mac: {
+    INCLUDEPATH += \
+        Platform/mac \
+        Platform/CoreIPC/mac
+
+    HEADERS += \
+        Platform/mac/MachUtilities.h \
+        Platform/CoreIPC/mac/MachPort.h
+
+    SOURCES += \
+        Platform/CoreIPC/mac/ConnectionMac.cpp \
+        Platform/mac/MachUtilities.cpp \
+        Platform/mac/WorkQueueMac.cpp \
+        Platform/mac/SharedMemoryMac.cpp
+
+} else {
+    SOURCES += \
+        Platform/CoreIPC/unix/AttachmentUnix.cpp \
+        Platform/CoreIPC/unix/ConnectionUnix.cpp \
+        Platform/qt/WorkQueueQt.cpp \
+        Platform/unix/SharedMemoryUnix.cpp
+}
+
 contains(DEFINES, ENABLE_TOUCH_EVENTS=1) {
     HEADERS += \
         Shared/NativeWebTouchEvent.h

Modified: trunk/Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp (101140 => 101141)


--- trunk/Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/UIProcess/Launcher/qt/ProcessLauncherQt.cpp	2011-11-24 16:51:13 UTC (rev 101141)
@@ -55,6 +55,13 @@
 #include <signal.h>
 #endif
 
+#if OS(DARWIN)
+#include <mach/mach_init.h>
+#include <servers/bootstrap.h>
+
+extern "C" kern_return_t bootstrap_register2(mach_port_t, name_t, mach_port_t, uint64_t);
+#endif
+
 #if defined(SOCK_SEQPACKET) && !defined(Q_OS_MACX)
 #define SOCKET_TYPE SOCK_SEQPACKET
 #else
@@ -102,6 +109,22 @@
         applicationPath = applicationPath.arg(QLatin1String("QtWebProcess"));
     }
 
+#if OS(DARWIN)
+    // Create the listening port.
+    mach_port_t connector;
+    mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &connector);
+
+    // Insert a send right so we can send to it.
+    mach_port_insert_right(mach_task_self(), connector, connector, MACH_MSG_TYPE_MAKE_SEND);
+
+    // Register port with a service name to the system.
+    QString serviceName = QString("com.nokia.Qt.WebKit.QtWebProcess-%1-%2");
+    serviceName = serviceName.arg(QString().setNum(getpid()), QString().setNum((size_t)this));
+    kern_return_t kr = bootstrap_register2(bootstrap_port, const_cast<char*>(serviceName.toUtf8().data()), connector, 0);
+    ASSERT_UNUSED(kr, kr == KERN_SUCCESS);
+
+    QString program(applicationPath.arg(serviceName));
+#else
     int sockets[2];
     if (socketpair(AF_UNIX, SOCKET_TYPE, 0, sockets) == -1) {
         qDebug() << "Creation of socket failed with errno:" << errno;
@@ -119,12 +142,15 @@
         }
     }
 
+    int connector = sockets[1];
     QString program(applicationPath.arg(sockets[0]));
+#endif
 
     QProcess* webProcess = new QtWebProcess();
     webProcess->setProcessChannelMode(QProcess::ForwardedChannels);
     webProcess->start(program);
 
+#if !OS(DARWIN)
     // Don't expose the web socket to possible future web processes
     while (fcntl(sockets[0], F_SETFD, FD_CLOEXEC) == -1) {
         if (errno != EINTR) {
@@ -133,17 +159,22 @@
             return;
         }
     }
+#endif
 
     if (!webProcess->waitForStarted()) {
         qDebug() << "Failed to start" << program;
         ASSERT_NOT_REACHED();
+#if OS(DARWIN)
+        mach_port_deallocate(mach_task_self(), connector);
+        mach_port_mod_refs(mach_task_self(), connector, MACH_PORT_RIGHT_RECEIVE, -1);
+#endif
         delete webProcess;
         return;
     }
 
     setpriority(PRIO_PROCESS, webProcess->pid(), 10);
 
-    RunLoop::main()->scheduleWork(WorkItem::create(this, &WebKit::ProcessLauncher::didFinishLaunchingProcess, webProcess, sockets[1]));
+    RunLoop::main()->scheduleWork(WorkItem::create(this, &WebKit::ProcessLauncher::didFinishLaunchingProcess, webProcess, connector));
 }
 
 void ProcessLauncher::terminateProcess()

Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp (101140 => 101141)


--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp	2011-11-24 16:51:13 UTC (rev 101141)
@@ -408,7 +408,7 @@
     ASSERT(!m_connection);
     
     m_connection = CoreIPC::Connection::createServerConnection(connectionIdentifier, this, RunLoop::main());
-#if PLATFORM(MAC)
+#if OS(DARWIN)
     m_connection->setShouldCloseConnectionOnMachExceptions();
 #elif PLATFORM(QT)
     m_connection->setShouldCloseConnectionOnProcessTermination(processIdentifier());

Modified: trunk/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp (101140 => 101141)


--- trunk/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp	2011-11-24 16:36:29 UTC (rev 101140)
+++ trunk/Source/WebKit2/WebProcess/qt/WebProcessMainQt.cpp	2011-11-24 16:51:13 UTC (rev 101141)
@@ -52,6 +52,12 @@
 #include <QDebug>
 #endif
 
+#if !USE(UNIX_DOMAIN_SOCKETS)
+#include <servers/bootstrap.h>
+
+extern "C" kern_return_t bootstrap_look_up2(mach_port_t, const name_t, mach_port_t*, pid_t, uint64_t);
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -175,13 +181,24 @@
         return 1;
     }
 
+#if OS(DARWIN)
+    QString serviceName = app->arguments().value(1);
+
+    // Get the server port.
+    mach_port_t identifier;
+    kern_return_t kr = bootstrap_look_up2(bootstrap_port, serviceName.toUtf8().data(), &identifier, 0, 0);
+    if (kr) {
+        printf("bootstrap_look_up2 result: %x", kr);
+        return 2;
+    }
+#else
     bool wasNumber = false;
     int identifier = app->arguments().at(1).toInt(&wasNumber, 10);
     if (!wasNumber) {
         qDebug() << "Error: connection identifier wrong.";
         return 1;
     }
-
+#endif
 #if USE(ACCELERATED_COMPOSITING)
     WebGraphicsLayer::initFactory();
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to