<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[168583] trunk/Source/WebKit2</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/168583">168583</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2014-05-10 13:51:20 -0700 (Sat, 10 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Simplify createDataAvailableSource
https://bugs.webkit.org/show_bug.cgi?id=132782
&lt;rdar://problem/16815202&gt;

Reviewed by Sam Weinig.

* Platform/IPC/mac/ConnectionMac.mm: Renamed from Source/WebKit2/Platform/IPC/mac/ConnectionMac.cpp.
Rename to make this Objective-C++ so we get the lambda-to-block conversion.

(IPC::createDataAvailableSource):
Make this a function template and just pass the function directly to dispatch_source_set_event_handler.

(IPC::Connection::open):
Use lambdas instead of WTF::bind, so we'll make sure the connection is kept alive.

* WebKit2.xcodeproj/project.pbxproj:
Update for ConnectionMac.cpp to ConnectionMac.mm rename.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2PlatformIPCmacConnectionMacmm">trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2PlatformIPCmacConnectionMaccpp">trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (168582 => 168583)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-05-10 20:20:36 UTC (rev 168582)
+++ trunk/Source/WebKit2/ChangeLog        2014-05-10 20:51:20 UTC (rev 168583)
</span><span class="lines">@@ -1,5 +1,25 @@
</span><span class="cx"> 2014-05-10  Anders Carlsson  &lt;andersca@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Simplify createDataAvailableSource
+        https://bugs.webkit.org/show_bug.cgi?id=132782
+        &lt;rdar://problem/16815202&gt;
+
+        Reviewed by Sam Weinig.
+
+        * Platform/IPC/mac/ConnectionMac.mm: Renamed from Source/WebKit2/Platform/IPC/mac/ConnectionMac.cpp.
+        Rename to make this Objective-C++ so we get the lambda-to-block conversion.
+
+        (IPC::createDataAvailableSource):
+        Make this a function template and just pass the function directly to dispatch_source_set_event_handler.
+
+        (IPC::Connection::open):
+        Use lambdas instead of WTF::bind, so we'll make sure the connection is kept alive.
+
+        * WebKit2.xcodeproj/project.pbxproj:
+        Update for ConnectionMac.cpp to ConnectionMac.mm rename.
+
+2014-05-10  Anders Carlsson  &lt;andersca@apple.com&gt;
+
</ins><span class="cx">         Follow-up fix.
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Darin Adler.
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCmacConnectionMaccpp"></a>
<div class="delfile"><h4>Deleted: trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.cpp (168582 => 168583)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.cpp        2014-05-10 20:20:36 UTC (rev 168582)
+++ trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.cpp        2014-05-10 20:51:20 UTC (rev 168583)
</span><span class="lines">@@ -1,529 +0,0 @@
</span><del>-/*
- * Copyright (C) 2010 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.
- */
-
-#include &quot;config.h&quot;
-#include &quot;Connection.h&quot;
-
-#include &quot;DataReference.h&quot;
-#include &quot;ImportanceAssertion.h&quot;
-#include &quot;MachPort.h&quot;
-#include &quot;MachUtilities.h&quot;
-#include &lt;mach/mach_error.h&gt;
-#include &lt;mach/vm_map.h&gt;
-#include &lt;wtf/RunLoop.h&gt;
-#include &lt;xpc/xpc.h&gt;
-
-#if __has_include(&lt;xpc/private.h&gt;)
-#include &lt;xpc/private.h&gt;
-#endif
-
-extern &quot;C&quot; void xpc_connection_get_audit_token(xpc_connection_t, audit_token_t*);
-
-namespace IPC {
-
-static const size_t inlineMessageMaxSize = 4096;
-
-// Message flags.
-enum {
-    MessageBodyIsOutOfLine = 1 &lt;&lt; 0
-};
-    
-void Connection::platformInvalidate()
-{
-    if (!m_isConnected)
-        return;
-
-    m_isConnected = false;
-
-    ASSERT(m_sendPort);
-    ASSERT(m_receivePort);
-
-    // Unregister our ports.
-    dispatch_source_cancel(m_deadNameSource);
-    dispatch_release(m_deadNameSource);
-    m_deadNameSource = 0;
-    m_sendPort = MACH_PORT_NULL;
-
-    dispatch_source_cancel(m_receivePortDataAvailableSource);
-    dispatch_release(m_receivePortDataAvailableSource);
-    m_receivePortDataAvailableSource = 0;
-    m_receivePort = MACH_PORT_NULL;
-
-#if !PLATFORM(IOS)
-    if (m_exceptionPort) {
-        dispatch_source_cancel(m_exceptionPortDataAvailableSource);
-        dispatch_release(m_exceptionPortDataAvailableSource);
-        m_exceptionPortDataAvailableSource = 0;
-        m_exceptionPort = MACH_PORT_NULL;
-    }
-#endif
-
-    if (m_xpcConnection) {
-        xpc_release(m_xpcConnection);
-        m_xpcConnection = 0;
-    }
-}
-
-void Connection::platformInitialize(Identifier identifier)
-{
-#if !PLATFORM(IOS)
-    m_exceptionPort = MACH_PORT_NULL;
-    m_exceptionPortDataAvailableSource = nullptr;
-#endif
-
-    if (m_isServer) {
-        m_receivePort = identifier.port;
-        m_sendPort = MACH_PORT_NULL;
-    } else {
-        m_receivePort = MACH_PORT_NULL;
-        m_sendPort = identifier.port;
-    }
-
-    m_deadNameSource = nullptr;
-    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);
-}
-
-static dispatch_source_t createDataAvailableSource(mach_port_t receivePort, WorkQueue* workQueue, std::function&lt;void ()&gt; function)
-{
-    dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_RECV, receivePort, 0, workQueue-&gt;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) {
-        ASSERT(m_receivePort);
-        ASSERT(!m_sendPort);
-        
-    } else {
-        ASSERT(!m_receivePort);
-        ASSERT(m_sendPort);
-
-        // Create the receive port.
-        mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &amp;m_receivePort);
-
-#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 1090
-        mach_port_set_attributes(mach_task_self(), m_receivePort, MACH_PORT_IMPORTANCE_RECEIVER, (mach_port_info_t)0, 0);
-#endif
-
-        m_isConnected = true;
-        
-        // Send the initialize message, which contains a send right for the server to use.
-        auto encoder = std::make_unique&lt;MessageEncoder&gt;(&quot;IPC&quot;, &quot;InitializeConnection&quot;, 0);
-        encoder-&gt;encode(MachPort(m_receivePort, MACH_MSG_TYPE_MAKE_SEND));
-
-        sendMessage(std::move(encoder));
-
-        initializeDeadNameSource();
-    }
-
-    // Change the message queue length for the receive port.
-    setMachPortQueueLength(m_receivePort, MACH_PORT_QLIMIT_LARGE);
-
-    // Register the data available handler.
-    m_receivePortDataAvailableSource = createDataAvailableSource(m_receivePort, m_connectionQueue.get(), bind(&amp;Connection::receiveSourceEventHandler, this));
-
-#if !PLATFORM(IOS)
-    // If we have an exception port, register the data available handler and send over the port to the other end.
-    if (m_exceptionPort) {
-        m_exceptionPortDataAvailableSource = createDataAvailableSource(m_exceptionPort, m_connectionQueue.get(), bind(&amp;Connection::exceptionSourceEventHandler, this));
-
-        auto encoder = std::make_unique&lt;MessageEncoder&gt;(&quot;IPC&quot;, &quot;SetExceptionPort&quot;, 0);
-        encoder-&gt;encode(MachPort(m_exceptionPort, MACH_MSG_TYPE_MAKE_SEND));
-
-        sendMessage(std::move(encoder));
-    }
-#endif
-
-    ref();
-    dispatch_async(m_connectionQueue-&gt;dispatchQueue(), ^{
-        dispatch_resume(m_receivePortDataAvailableSource);
-
-        if (m_deadNameSource)
-            dispatch_resume(m_deadNameSource);
-#if !PLATFORM(IOS)
-        if (m_exceptionPortDataAvailableSource)
-            dispatch_resume(m_exceptionPortDataAvailableSource);
-#endif
-
-        deref();
-    });
-
-    return true;
-}
-
-static inline size_t machMessageSize(size_t bodySize, size_t numberOfPortDescriptors = 0, size_t numberOfOOLMemoryDescriptors = 0)
-{
-    size_t size = sizeof(mach_msg_header_t) + bodySize;
-    if (numberOfPortDescriptors || numberOfOOLMemoryDescriptors) {
-        size += sizeof(mach_msg_body_t);
-        if (numberOfPortDescriptors)
-            size += (numberOfPortDescriptors * sizeof(mach_msg_port_descriptor_t));
-        if (numberOfOOLMemoryDescriptors)
-            size += (numberOfOOLMemoryDescriptors * sizeof(mach_msg_ool_descriptor_t));
-    }
-    return round_msg(size);
-}
-
-bool Connection::platformCanSendOutgoingMessages() const
-{
-    return true;
-}
-
-bool Connection::sendOutgoingMessage(std::unique_ptr&lt;MessageEncoder&gt; encoder)
-{
-    Vector&lt;Attachment&gt; attachments = encoder-&gt;releaseAttachments();
-    
-    size_t numberOfPortDescriptors = 0;
-    size_t numberOfOOLMemoryDescriptors = 0;
-    for (size_t i = 0; i &lt; attachments.size(); ++i) {
-        Attachment::Type type = attachments[i].type();
-        if (type == Attachment::MachPortType)
-            numberOfPortDescriptors++;
-    }
-    
-    size_t messageSize = machMessageSize(encoder-&gt;bufferSize(), numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
-
-    bool messageBodyIsOOL = false;
-    if (messageSize &gt; inlineMessageMaxSize) {
-        messageBodyIsOOL = true;
-
-        numberOfOOLMemoryDescriptors++;
-        messageSize = machMessageSize(0, numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
-    }
-
-    char stackBuffer[inlineMessageMaxSize];
-    char* buffer = &amp;stackBuffer[0];
-    if (messageSize &gt; inlineMessageMaxSize)
-        buffer = (char*)mmap(0, messageSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
-
-    bool isComplex = (numberOfPortDescriptors + numberOfOOLMemoryDescriptors &gt; 0);
-
-    mach_msg_header_t* header = reinterpret_cast&lt;mach_msg_header_t*&gt;(buffer);
-    header-&gt;msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
-    header-&gt;msgh_size = messageSize;
-    header-&gt;msgh_remote_port = m_sendPort;
-    header-&gt;msgh_local_port = MACH_PORT_NULL;
-    header-&gt;msgh_id = 0;
-    if (messageBodyIsOOL)
-        header-&gt;msgh_id |= MessageBodyIsOutOfLine;
-
-    uint8_t* messageData;
-
-    if (isComplex) {
-        header-&gt;msgh_bits |= MACH_MSGH_BITS_COMPLEX;
-
-        mach_msg_body_t* body = reinterpret_cast&lt;mach_msg_body_t*&gt;(header + 1);
-        body-&gt;msgh_descriptor_count = numberOfPortDescriptors + numberOfOOLMemoryDescriptors;
-        uint8_t* descriptorData = reinterpret_cast&lt;uint8_t*&gt;(body + 1);
-
-        for (size_t i = 0; i &lt; attachments.size(); ++i) {
-            Attachment attachment = attachments[i];
-
-            mach_msg_descriptor_t* descriptor = reinterpret_cast&lt;mach_msg_descriptor_t*&gt;(descriptorData);
-            switch (attachment.type()) {
-            case Attachment::MachPortType:
-                descriptor-&gt;port.name = attachment.port();
-                descriptor-&gt;port.disposition = attachment.disposition();
-                descriptor-&gt;port.type = MACH_MSG_PORT_DESCRIPTOR;            
-
-                descriptorData += sizeof(mach_msg_port_descriptor_t);
-                break;
-            default:
-                ASSERT_NOT_REACHED();
-            }
-        }
-
-        if (messageBodyIsOOL) {
-            mach_msg_descriptor_t* descriptor = reinterpret_cast&lt;mach_msg_descriptor_t*&gt;(descriptorData);
-
-            descriptor-&gt;out_of_line.address = encoder-&gt;buffer();
-            descriptor-&gt;out_of_line.size = encoder-&gt;bufferSize();
-            descriptor-&gt;out_of_line.copy = MACH_MSG_VIRTUAL_COPY;
-            descriptor-&gt;out_of_line.deallocate = false;
-            descriptor-&gt;out_of_line.type = MACH_MSG_OOL_DESCRIPTOR;
-
-            descriptorData += sizeof(mach_msg_ool_descriptor_t);
-        }
-
-        messageData = descriptorData;
-    } else
-        messageData = (uint8_t*)(header + 1);
-
-    // Copy the data if it is not being sent out-of-line.
-    if (!messageBodyIsOOL)
-        memcpy(messageData, encoder-&gt;buffer(), encoder-&gt;bufferSize());
-
-    ASSERT(m_sendPort);
-
-    // Send the message.
-    kern_return_t kr = mach_msg(header, MACH_SEND_MSG, messageSize, 0, MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
-    if (kr != KERN_SUCCESS) {
-        // FIXME: What should we do here?
-    }
-
-    if (buffer != &amp;stackBuffer[0])
-        munmap(buffer, messageSize);
-
-    return true;
-}
-
-void Connection::initializeDeadNameSource()
-{
-    m_deadNameSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_SEND, m_sendPort, 0, m_connectionQueue-&gt;dispatchQueue());
-    dispatch_source_set_event_handler(m_deadNameSource, bind(&amp;Connection::connectionDidClose, this));
-
-    mach_port_t sendPort = m_sendPort;
-    dispatch_source_set_cancel_handler(m_deadNameSource, ^{
-        // Release our send right.
-        mach_port_deallocate(mach_task_self(), sendPort);
-    });
-}
-
-static std::unique_ptr&lt;MessageDecoder&gt; createMessageDecoder(mach_msg_header_t* header)
-{
-    if (!(header-&gt;msgh_bits &amp; MACH_MSGH_BITS_COMPLEX)) {
-        // We have a simple message.
-        uint8_t* body = reinterpret_cast&lt;uint8_t*&gt;(header + 1);
-        size_t bodySize = header-&gt;msgh_size - sizeof(mach_msg_header_t);
-
-        return std::make_unique&lt;MessageDecoder&gt;(DataReference(body, bodySize), Vector&lt;Attachment&gt;());
-    }
-
-    bool messageBodyIsOOL = header-&gt;msgh_id &amp; MessageBodyIsOutOfLine;
-
-    mach_msg_body_t* body = reinterpret_cast&lt;mach_msg_body_t*&gt;(header + 1);
-    mach_msg_size_t numDescriptors = body-&gt;msgh_descriptor_count;
-    ASSERT(numDescriptors);
-
-    uint8_t* descriptorData = reinterpret_cast&lt;uint8_t*&gt;(body + 1);
-
-    // If the message body was sent out-of-line, don't treat the last descriptor
-    // as an attachment, since it is really the message body.
-    if (messageBodyIsOOL)
-        --numDescriptors;
-
-    // Build attachment list
-    Vector&lt;Attachment&gt; attachments(numDescriptors);
-
-    for (mach_msg_size_t i = 0; i &lt; numDescriptors; ++i) {
-        mach_msg_descriptor_t* descriptor = reinterpret_cast&lt;mach_msg_descriptor_t*&gt;(descriptorData);
-
-        switch (descriptor-&gt;type.type) {
-        case MACH_MSG_PORT_DESCRIPTOR:
-            attachments[numDescriptors - i - 1] = Attachment(descriptor-&gt;port.name, descriptor-&gt;port.disposition);
-            descriptorData += sizeof(mach_msg_port_descriptor_t);
-            break;
-        default:
-            ASSERT(false &amp;&amp; &quot;Unhandled descriptor type&quot;);
-        }
-    }
-
-    if (messageBodyIsOOL) {
-        mach_msg_descriptor_t* descriptor = reinterpret_cast&lt;mach_msg_descriptor_t*&gt;(descriptorData);
-        ASSERT(descriptor-&gt;type.type == MACH_MSG_OOL_DESCRIPTOR);
-
-        uint8_t* messageBody = static_cast&lt;uint8_t*&gt;(descriptor-&gt;out_of_line.address);
-        size_t messageBodySize = descriptor-&gt;out_of_line.size;
-
-        auto decoder = std::make_unique&lt;MessageDecoder&gt;(DataReference(messageBody, messageBodySize), std::move(attachments));
-
-        vm_deallocate(mach_task_self(), reinterpret_cast&lt;vm_address_t&gt;(descriptor-&gt;out_of_line.address), descriptor-&gt;out_of_line.size);
-
-        return decoder;
-    }
-
-    uint8_t* messageBody = descriptorData;
-    size_t messageBodySize = header-&gt;msgh_size - (descriptorData - reinterpret_cast&lt;uint8_t*&gt;(header));
-
-    return std::make_unique&lt;MessageDecoder&gt;(DataReference(messageBody, messageBodySize), attachments);
-}
-
-// The receive buffer size should always include the maximum trailer size.
-static const size_t receiveBufferSize = inlineMessageMaxSize + MAX_TRAILER_SIZE;
-typedef Vector&lt;char, receiveBufferSize&gt; ReceiveBuffer;
-
-static mach_msg_header_t* readFromMachPort(mach_port_t machPort, ReceiveBuffer&amp; buffer)
-{
-    buffer.resize(receiveBufferSize);
-
-    mach_msg_header_t* header = reinterpret_cast&lt;mach_msg_header_t*&gt;(buffer.data());
-    kern_return_t kr = mach_msg(header, MACH_RCV_MSG | MACH_RCV_LARGE | MACH_RCV_TIMEOUT, 0, buffer.size(), machPort, 0, MACH_PORT_NULL);
-    if (kr == MACH_RCV_TIMED_OUT)
-        return 0;
-
-    if (kr == MACH_RCV_TOO_LARGE) {
-        // The message was too large, resize the buffer and try again.
-        buffer.resize(header-&gt;msgh_size + MAX_TRAILER_SIZE);
-        header = reinterpret_cast&lt;mach_msg_header_t*&gt;(buffer.data());
-        
-        kr = mach_msg(header, MACH_RCV_MSG | MACH_RCV_LARGE | MACH_RCV_TIMEOUT, 0, buffer.size(), machPort, 0, MACH_PORT_NULL);
-        ASSERT(kr != MACH_RCV_TOO_LARGE);
-    }
-
-    if (kr != MACH_MSG_SUCCESS) {
-        ASSERT_NOT_REACHED();
-        return 0;
-    }
-
-    return header;
-}
-
-void Connection::receiveSourceEventHandler()
-{
-    ReceiveBuffer buffer;
-
-    mach_msg_header_t* header = readFromMachPort(m_receivePort, buffer);
-    if (!header)
-        return;
-
-    std::unique_ptr&lt;MessageDecoder&gt; decoder = createMessageDecoder(header);
-    ASSERT(decoder);
-
-#if PLATFORM(MAC) &amp;&amp; __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 1090
-    decoder-&gt;setImportanceAssertion(std::make_unique&lt;ImportanceAssertion&gt;(header));
-#endif
-
-    if (decoder-&gt;messageReceiverName() == &quot;IPC&quot; &amp;&amp; decoder-&gt;messageName() == &quot;InitializeConnection&quot;) {
-        ASSERT(m_isServer);
-        ASSERT(!m_isConnected);
-        ASSERT(!m_sendPort);
-
-        MachPort port;
-        if (!decoder-&gt;decode(port)) {
-            // FIXME: Disconnect.
-            return;
-        }
-
-        m_sendPort = port.port();
-        
-        if (m_sendPort) {
-            initializeDeadNameSource();
-            dispatch_resume(m_deadNameSource);
-        }
-
-        m_isConnected = true;
-
-        // Send any pending outgoing messages.
-        sendOutgoingMessages();
-        
-        return;
-    }
-
-#if !PLATFORM(IOS)
-    if (decoder-&gt;messageReceiverName() == &quot;IPC&quot; &amp;&amp; decoder-&gt;messageName() == &quot;SetExceptionPort&quot;) {
-        if (m_isServer) {
-            // Server connections aren't supposed to have their exception ports overriden. Treat this as an invalid message.
-            m_clientRunLoop.dispatch(bind(&amp;Connection::dispatchDidReceiveInvalidMessage, this, decoder-&gt;messageReceiverName().toString(), decoder-&gt;messageName().toString()));
-            return;
-        }
-        MachPort exceptionPort;
-        if (!decoder-&gt;decode(exceptionPort))
-            return;
-
-        setMachExceptionPort(exceptionPort.port());
-        return;
-    }
-#endif
-
-    processIncomingMessage(std::move(decoder));
-}    
-
-#if !PLATFORM(IOS)
-void Connection::exceptionSourceEventHandler()
-{
-    ReceiveBuffer buffer;
-
-    mach_msg_header_t* header = readFromMachPort(m_exceptionPort, buffer);
-    if (!header)
-        return;
-
-    // We've read the exception message. Now send it on to the real exception port.
-
-    // The remote port should have a send once right.
-    ASSERT(MACH_MSGH_BITS_REMOTE(header-&gt;msgh_bits) == MACH_MSG_TYPE_MOVE_SEND_ONCE);
-
-    // Now get the real exception port.
-    mach_port_t exceptionPort = machExceptionPort();
-
-    // First, get the complex bit from the source message.
-    mach_msg_bits_t messageBits = header-&gt;msgh_bits &amp; MACH_MSGH_BITS_COMPLEX;
-    messageBits |= MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MOVE_SEND_ONCE);
-
-    header-&gt;msgh_bits = messageBits;
-    header-&gt;msgh_local_port = header-&gt;msgh_remote_port;
-    header-&gt;msgh_remote_port = exceptionPort;
-
-    // Now send along the message.
-    kern_return_t kr = mach_msg(header, MACH_SEND_MSG, header-&gt;msgh_size, 0, MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
-    if (kr != KERN_SUCCESS) {
-        LOG_ERROR(&quot;Failed to send message to real exception port. %s (%x)&quot;, mach_error_string(kr), kr);
-        ASSERT_NOT_REACHED();
-    }
-
-    connectionDidClose();
-}
-
-void Connection::setShouldCloseConnectionOnMachExceptions()
-{
-    ASSERT(m_exceptionPort == MACH_PORT_NULL);
-
-    if (mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &amp;m_exceptionPort) != KERN_SUCCESS)
-        ASSERT_NOT_REACHED();
-
-    if (mach_port_insert_right(mach_task_self(), m_exceptionPort, m_exceptionPort, MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS)
-        ASSERT_NOT_REACHED();
-}
-#endif
-
-IPC::Connection::Identifier Connection::identifier() const
-{
-    return Identifier(m_isServer ? m_receivePort : m_sendPort, m_xpcConnection);
-}
-    
-bool Connection::getAuditToken(audit_token_t&amp; auditToken)
-{
-    if (!m_xpcConnection)
-        return false;
-    
-    xpc_connection_get_audit_token(m_xpcConnection, &amp;auditToken);
-    return true;
-}
-    
-} // namespace IPC
</del></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCmacConnectionMacmmfromrev168582trunkSourceWebKit2PlatformIPCmacConnectionMaccpp"></a>
<div class="copfile"><h4>Copied: trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm (from rev 168582, trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.cpp) (0 => 168583)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm                                (rev 0)
+++ trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm        2014-05-10 20:51:20 UTC (rev 168583)
</span><span class="lines">@@ -0,0 +1,533 @@
</span><ins>+/*
+ * Copyright (C) 2010 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.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;Connection.h&quot;
+
+#include &quot;DataReference.h&quot;
+#include &quot;ImportanceAssertion.h&quot;
+#include &quot;MachPort.h&quot;
+#include &quot;MachUtilities.h&quot;
+#include &lt;mach/mach_error.h&gt;
+#include &lt;mach/vm_map.h&gt;
+#include &lt;wtf/RunLoop.h&gt;
+#include &lt;xpc/xpc.h&gt;
+
+#if __has_include(&lt;xpc/private.h&gt;)
+#include &lt;xpc/private.h&gt;
+#endif
+
+extern &quot;C&quot; void xpc_connection_get_audit_token(xpc_connection_t, audit_token_t*);
+
+namespace IPC {
+
+static const size_t inlineMessageMaxSize = 4096;
+
+// Message flags.
+enum {
+    MessageBodyIsOutOfLine = 1 &lt;&lt; 0
+};
+    
+void Connection::platformInvalidate()
+{
+    if (!m_isConnected)
+        return;
+
+    m_isConnected = false;
+
+    ASSERT(m_sendPort);
+    ASSERT(m_receivePort);
+
+    // Unregister our ports.
+    dispatch_source_cancel(m_deadNameSource);
+    dispatch_release(m_deadNameSource);
+    m_deadNameSource = 0;
+    m_sendPort = MACH_PORT_NULL;
+
+    dispatch_source_cancel(m_receivePortDataAvailableSource);
+    dispatch_release(m_receivePortDataAvailableSource);
+    m_receivePortDataAvailableSource = 0;
+    m_receivePort = MACH_PORT_NULL;
+
+#if !PLATFORM(IOS)
+    if (m_exceptionPort) {
+        dispatch_source_cancel(m_exceptionPortDataAvailableSource);
+        dispatch_release(m_exceptionPortDataAvailableSource);
+        m_exceptionPortDataAvailableSource = 0;
+        m_exceptionPort = MACH_PORT_NULL;
+    }
+#endif
+
+    if (m_xpcConnection) {
+        xpc_release(m_xpcConnection);
+        m_xpcConnection = 0;
+    }
+}
+
+void Connection::platformInitialize(Identifier identifier)
+{
+#if !PLATFORM(IOS)
+    m_exceptionPort = MACH_PORT_NULL;
+    m_exceptionPortDataAvailableSource = nullptr;
+#endif
+
+    if (m_isServer) {
+        m_receivePort = identifier.port;
+        m_sendPort = MACH_PORT_NULL;
+    } else {
+        m_receivePort = MACH_PORT_NULL;
+        m_sendPort = identifier.port;
+    }
+
+    m_deadNameSource = nullptr;
+    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&lt;typename Function&gt;
+static dispatch_source_t createDataAvailableSource(mach_port_t receivePort, WorkQueue&amp; workQueue, Function&amp;&amp; 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) {
+        ASSERT(m_receivePort);
+        ASSERT(!m_sendPort);
+        
+    } else {
+        ASSERT(!m_receivePort);
+        ASSERT(m_sendPort);
+
+        // Create the receive port.
+        mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &amp;m_receivePort);
+
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 1090
+        mach_port_set_attributes(mach_task_self(), m_receivePort, MACH_PORT_IMPORTANCE_RECEIVER, (mach_port_info_t)0, 0);
+#endif
+
+        m_isConnected = true;
+        
+        // Send the initialize message, which contains a send right for the server to use.
+        auto encoder = std::make_unique&lt;MessageEncoder&gt;(&quot;IPC&quot;, &quot;InitializeConnection&quot;, 0);
+        encoder-&gt;encode(MachPort(m_receivePort, MACH_MSG_TYPE_MAKE_SEND));
+
+        sendMessage(std::move(encoder));
+
+        initializeDeadNameSource();
+    }
+
+    // Change the message queue length for the receive port.
+    setMachPortQueueLength(m_receivePort, MACH_PORT_QLIMIT_LARGE);
+
+    // Register the data available handler.
+    RefPtr&lt;Connection&gt; connection(this);
+    m_receivePortDataAvailableSource = createDataAvailableSource(m_receivePort, *m_connectionQueue, [connection] {
+        connection-&gt;receiveSourceEventHandler();
+    });
+
+#if !PLATFORM(IOS)
+    // If we have an exception port, register the data available handler and send over the port to the other end.
+    if (m_exceptionPort) {
+        m_exceptionPortDataAvailableSource = createDataAvailableSource(m_exceptionPort, *m_connectionQueue, [connection] {
+            connection-&gt;exceptionSourceEventHandler();
+        });
+
+        auto encoder = std::make_unique&lt;MessageEncoder&gt;(&quot;IPC&quot;, &quot;SetExceptionPort&quot;, 0);
+        encoder-&gt;encode(MachPort(m_exceptionPort, MACH_MSG_TYPE_MAKE_SEND));
+
+        sendMessage(std::move(encoder));
+    }
+#endif
+
+    ref();
+    dispatch_async(m_connectionQueue-&gt;dispatchQueue(), ^{
+        dispatch_resume(m_receivePortDataAvailableSource);
+
+        if (m_deadNameSource)
+            dispatch_resume(m_deadNameSource);
+#if !PLATFORM(IOS)
+        if (m_exceptionPortDataAvailableSource)
+            dispatch_resume(m_exceptionPortDataAvailableSource);
+#endif
+
+        deref();
+    });
+
+    return true;
+}
+
+static inline size_t machMessageSize(size_t bodySize, size_t numberOfPortDescriptors = 0, size_t numberOfOOLMemoryDescriptors = 0)
+{
+    size_t size = sizeof(mach_msg_header_t) + bodySize;
+    if (numberOfPortDescriptors || numberOfOOLMemoryDescriptors) {
+        size += sizeof(mach_msg_body_t);
+        if (numberOfPortDescriptors)
+            size += (numberOfPortDescriptors * sizeof(mach_msg_port_descriptor_t));
+        if (numberOfOOLMemoryDescriptors)
+            size += (numberOfOOLMemoryDescriptors * sizeof(mach_msg_ool_descriptor_t));
+    }
+    return round_msg(size);
+}
+
+bool Connection::platformCanSendOutgoingMessages() const
+{
+    return true;
+}
+
+bool Connection::sendOutgoingMessage(std::unique_ptr&lt;MessageEncoder&gt; encoder)
+{
+    Vector&lt;Attachment&gt; attachments = encoder-&gt;releaseAttachments();
+    
+    size_t numberOfPortDescriptors = 0;
+    size_t numberOfOOLMemoryDescriptors = 0;
+    for (size_t i = 0; i &lt; attachments.size(); ++i) {
+        Attachment::Type type = attachments[i].type();
+        if (type == Attachment::MachPortType)
+            numberOfPortDescriptors++;
+    }
+    
+    size_t messageSize = machMessageSize(encoder-&gt;bufferSize(), numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
+
+    bool messageBodyIsOOL = false;
+    if (messageSize &gt; inlineMessageMaxSize) {
+        messageBodyIsOOL = true;
+
+        numberOfOOLMemoryDescriptors++;
+        messageSize = machMessageSize(0, numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
+    }
+
+    char stackBuffer[inlineMessageMaxSize];
+    char* buffer = &amp;stackBuffer[0];
+    if (messageSize &gt; inlineMessageMaxSize)
+        buffer = (char*)mmap(0, messageSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+
+    bool isComplex = (numberOfPortDescriptors + numberOfOOLMemoryDescriptors &gt; 0);
+
+    mach_msg_header_t* header = reinterpret_cast&lt;mach_msg_header_t*&gt;(buffer);
+    header-&gt;msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
+    header-&gt;msgh_size = messageSize;
+    header-&gt;msgh_remote_port = m_sendPort;
+    header-&gt;msgh_local_port = MACH_PORT_NULL;
+    header-&gt;msgh_id = 0;
+    if (messageBodyIsOOL)
+        header-&gt;msgh_id |= MessageBodyIsOutOfLine;
+
+    uint8_t* messageData;
+
+    if (isComplex) {
+        header-&gt;msgh_bits |= MACH_MSGH_BITS_COMPLEX;
+
+        mach_msg_body_t* body = reinterpret_cast&lt;mach_msg_body_t*&gt;(header + 1);
+        body-&gt;msgh_descriptor_count = numberOfPortDescriptors + numberOfOOLMemoryDescriptors;
+        uint8_t* descriptorData = reinterpret_cast&lt;uint8_t*&gt;(body + 1);
+
+        for (size_t i = 0; i &lt; attachments.size(); ++i) {
+            Attachment attachment = attachments[i];
+
+            mach_msg_descriptor_t* descriptor = reinterpret_cast&lt;mach_msg_descriptor_t*&gt;(descriptorData);
+            switch (attachment.type()) {
+            case Attachment::MachPortType:
+                descriptor-&gt;port.name = attachment.port();
+                descriptor-&gt;port.disposition = attachment.disposition();
+                descriptor-&gt;port.type = MACH_MSG_PORT_DESCRIPTOR;            
+
+                descriptorData += sizeof(mach_msg_port_descriptor_t);
+                break;
+            default:
+                ASSERT_NOT_REACHED();
+            }
+        }
+
+        if (messageBodyIsOOL) {
+            mach_msg_descriptor_t* descriptor = reinterpret_cast&lt;mach_msg_descriptor_t*&gt;(descriptorData);
+
+            descriptor-&gt;out_of_line.address = encoder-&gt;buffer();
+            descriptor-&gt;out_of_line.size = encoder-&gt;bufferSize();
+            descriptor-&gt;out_of_line.copy = MACH_MSG_VIRTUAL_COPY;
+            descriptor-&gt;out_of_line.deallocate = false;
+            descriptor-&gt;out_of_line.type = MACH_MSG_OOL_DESCRIPTOR;
+
+            descriptorData += sizeof(mach_msg_ool_descriptor_t);
+        }
+
+        messageData = descriptorData;
+    } else
+        messageData = (uint8_t*)(header + 1);
+
+    // Copy the data if it is not being sent out-of-line.
+    if (!messageBodyIsOOL)
+        memcpy(messageData, encoder-&gt;buffer(), encoder-&gt;bufferSize());
+
+    ASSERT(m_sendPort);
+
+    // Send the message.
+    kern_return_t kr = mach_msg(header, MACH_SEND_MSG, messageSize, 0, MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+    if (kr != KERN_SUCCESS) {
+        // FIXME: What should we do here?
+    }
+
+    if (buffer != &amp;stackBuffer[0])
+        munmap(buffer, messageSize);
+
+    return true;
+}
+
+void Connection::initializeDeadNameSource()
+{
+    m_deadNameSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_MACH_SEND, m_sendPort, 0, m_connectionQueue-&gt;dispatchQueue());
+    dispatch_source_set_event_handler(m_deadNameSource, bind(&amp;Connection::connectionDidClose, this));
+
+    mach_port_t sendPort = m_sendPort;
+    dispatch_source_set_cancel_handler(m_deadNameSource, ^{
+        // Release our send right.
+        mach_port_deallocate(mach_task_self(), sendPort);
+    });
+}
+
+static std::unique_ptr&lt;MessageDecoder&gt; createMessageDecoder(mach_msg_header_t* header)
+{
+    if (!(header-&gt;msgh_bits &amp; MACH_MSGH_BITS_COMPLEX)) {
+        // We have a simple message.
+        uint8_t* body = reinterpret_cast&lt;uint8_t*&gt;(header + 1);
+        size_t bodySize = header-&gt;msgh_size - sizeof(mach_msg_header_t);
+
+        return std::make_unique&lt;MessageDecoder&gt;(DataReference(body, bodySize), Vector&lt;Attachment&gt;());
+    }
+
+    bool messageBodyIsOOL = header-&gt;msgh_id &amp; MessageBodyIsOutOfLine;
+
+    mach_msg_body_t* body = reinterpret_cast&lt;mach_msg_body_t*&gt;(header + 1);
+    mach_msg_size_t numDescriptors = body-&gt;msgh_descriptor_count;
+    ASSERT(numDescriptors);
+
+    uint8_t* descriptorData = reinterpret_cast&lt;uint8_t*&gt;(body + 1);
+
+    // If the message body was sent out-of-line, don't treat the last descriptor
+    // as an attachment, since it is really the message body.
+    if (messageBodyIsOOL)
+        --numDescriptors;
+
+    // Build attachment list
+    Vector&lt;Attachment&gt; attachments(numDescriptors);
+
+    for (mach_msg_size_t i = 0; i &lt; numDescriptors; ++i) {
+        mach_msg_descriptor_t* descriptor = reinterpret_cast&lt;mach_msg_descriptor_t*&gt;(descriptorData);
+
+        switch (descriptor-&gt;type.type) {
+        case MACH_MSG_PORT_DESCRIPTOR:
+            attachments[numDescriptors - i - 1] = Attachment(descriptor-&gt;port.name, descriptor-&gt;port.disposition);
+            descriptorData += sizeof(mach_msg_port_descriptor_t);
+            break;
+        default:
+            ASSERT(false &amp;&amp; &quot;Unhandled descriptor type&quot;);
+        }
+    }
+
+    if (messageBodyIsOOL) {
+        mach_msg_descriptor_t* descriptor = reinterpret_cast&lt;mach_msg_descriptor_t*&gt;(descriptorData);
+        ASSERT(descriptor-&gt;type.type == MACH_MSG_OOL_DESCRIPTOR);
+
+        uint8_t* messageBody = static_cast&lt;uint8_t*&gt;(descriptor-&gt;out_of_line.address);
+        size_t messageBodySize = descriptor-&gt;out_of_line.size;
+
+        auto decoder = std::make_unique&lt;MessageDecoder&gt;(DataReference(messageBody, messageBodySize), std::move(attachments));
+
+        vm_deallocate(mach_task_self(), reinterpret_cast&lt;vm_address_t&gt;(descriptor-&gt;out_of_line.address), descriptor-&gt;out_of_line.size);
+
+        return decoder;
+    }
+
+    uint8_t* messageBody = descriptorData;
+    size_t messageBodySize = header-&gt;msgh_size - (descriptorData - reinterpret_cast&lt;uint8_t*&gt;(header));
+
+    return std::make_unique&lt;MessageDecoder&gt;(DataReference(messageBody, messageBodySize), attachments);
+}
+
+// The receive buffer size should always include the maximum trailer size.
+static const size_t receiveBufferSize = inlineMessageMaxSize + MAX_TRAILER_SIZE;
+typedef Vector&lt;char, receiveBufferSize&gt; ReceiveBuffer;
+
+static mach_msg_header_t* readFromMachPort(mach_port_t machPort, ReceiveBuffer&amp; buffer)
+{
+    buffer.resize(receiveBufferSize);
+
+    mach_msg_header_t* header = reinterpret_cast&lt;mach_msg_header_t*&gt;(buffer.data());
+    kern_return_t kr = mach_msg(header, MACH_RCV_MSG | MACH_RCV_LARGE | MACH_RCV_TIMEOUT, 0, buffer.size(), machPort, 0, MACH_PORT_NULL);
+    if (kr == MACH_RCV_TIMED_OUT)
+        return 0;
+
+    if (kr == MACH_RCV_TOO_LARGE) {
+        // The message was too large, resize the buffer and try again.
+        buffer.resize(header-&gt;msgh_size + MAX_TRAILER_SIZE);
+        header = reinterpret_cast&lt;mach_msg_header_t*&gt;(buffer.data());
+        
+        kr = mach_msg(header, MACH_RCV_MSG | MACH_RCV_LARGE | MACH_RCV_TIMEOUT, 0, buffer.size(), machPort, 0, MACH_PORT_NULL);
+        ASSERT(kr != MACH_RCV_TOO_LARGE);
+    }
+
+    if (kr != MACH_MSG_SUCCESS) {
+        ASSERT_NOT_REACHED();
+        return 0;
+    }
+
+    return header;
+}
+
+void Connection::receiveSourceEventHandler()
+{
+    ReceiveBuffer buffer;
+
+    mach_msg_header_t* header = readFromMachPort(m_receivePort, buffer);
+    if (!header)
+        return;
+
+    std::unique_ptr&lt;MessageDecoder&gt; decoder = createMessageDecoder(header);
+    ASSERT(decoder);
+
+#if PLATFORM(MAC) &amp;&amp; __MAC_OS_X_VERSION_MIN_REQUIRED &gt;= 1090
+    decoder-&gt;setImportanceAssertion(std::make_unique&lt;ImportanceAssertion&gt;(header));
+#endif
+
+    if (decoder-&gt;messageReceiverName() == &quot;IPC&quot; &amp;&amp; decoder-&gt;messageName() == &quot;InitializeConnection&quot;) {
+        ASSERT(m_isServer);
+        ASSERT(!m_isConnected);
+        ASSERT(!m_sendPort);
+
+        MachPort port;
+        if (!decoder-&gt;decode(port)) {
+            // FIXME: Disconnect.
+            return;
+        }
+
+        m_sendPort = port.port();
+        
+        if (m_sendPort) {
+            initializeDeadNameSource();
+            dispatch_resume(m_deadNameSource);
+        }
+
+        m_isConnected = true;
+
+        // Send any pending outgoing messages.
+        sendOutgoingMessages();
+        
+        return;
+    }
+
+#if !PLATFORM(IOS)
+    if (decoder-&gt;messageReceiverName() == &quot;IPC&quot; &amp;&amp; decoder-&gt;messageName() == &quot;SetExceptionPort&quot;) {
+        if (m_isServer) {
+            // Server connections aren't supposed to have their exception ports overriden. Treat this as an invalid message.
+            m_clientRunLoop.dispatch(bind(&amp;Connection::dispatchDidReceiveInvalidMessage, this, decoder-&gt;messageReceiverName().toString(), decoder-&gt;messageName().toString()));
+            return;
+        }
+        MachPort exceptionPort;
+        if (!decoder-&gt;decode(exceptionPort))
+            return;
+
+        setMachExceptionPort(exceptionPort.port());
+        return;
+    }
+#endif
+
+    processIncomingMessage(std::move(decoder));
+}    
+
+#if !PLATFORM(IOS)
+void Connection::exceptionSourceEventHandler()
+{
+    ReceiveBuffer buffer;
+
+    mach_msg_header_t* header = readFromMachPort(m_exceptionPort, buffer);
+    if (!header)
+        return;
+
+    // We've read the exception message. Now send it on to the real exception port.
+
+    // The remote port should have a send once right.
+    ASSERT(MACH_MSGH_BITS_REMOTE(header-&gt;msgh_bits) == MACH_MSG_TYPE_MOVE_SEND_ONCE);
+
+    // Now get the real exception port.
+    mach_port_t exceptionPort = machExceptionPort();
+
+    // First, get the complex bit from the source message.
+    mach_msg_bits_t messageBits = header-&gt;msgh_bits &amp; MACH_MSGH_BITS_COMPLEX;
+    messageBits |= MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MOVE_SEND_ONCE);
+
+    header-&gt;msgh_bits = messageBits;
+    header-&gt;msgh_local_port = header-&gt;msgh_remote_port;
+    header-&gt;msgh_remote_port = exceptionPort;
+
+    // Now send along the message.
+    kern_return_t kr = mach_msg(header, MACH_SEND_MSG, header-&gt;msgh_size, 0, MACH_PORT_NULL, MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL);
+    if (kr != KERN_SUCCESS) {
+        LOG_ERROR(&quot;Failed to send message to real exception port. %s (%x)&quot;, mach_error_string(kr), kr);
+        ASSERT_NOT_REACHED();
+    }
+
+    connectionDidClose();
+}
+
+void Connection::setShouldCloseConnectionOnMachExceptions()
+{
+    ASSERT(m_exceptionPort == MACH_PORT_NULL);
+
+    if (mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &amp;m_exceptionPort) != KERN_SUCCESS)
+        ASSERT_NOT_REACHED();
+
+    if (mach_port_insert_right(mach_task_self(), m_exceptionPort, m_exceptionPort, MACH_MSG_TYPE_MAKE_SEND) != KERN_SUCCESS)
+        ASSERT_NOT_REACHED();
+}
+#endif
+
+IPC::Connection::Identifier Connection::identifier() const
+{
+    return Identifier(m_isServer ? m_receivePort : m_sendPort, m_xpcConnection);
+}
+    
+bool Connection::getAuditToken(audit_token_t&amp; auditToken)
+{
+    if (!m_xpcConnection)
+        return false;
+    
+    xpc_connection_get_audit_token(m_xpcConnection, &amp;auditToken);
+    return true;
+}
+    
+} // namespace IPC
</ins></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (168582 => 168583)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-05-10 20:20:36 UTC (rev 168582)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2014-05-10 20:51:20 UTC (rev 168583)
</span><span class="lines">@@ -180,7 +180,7 @@
</span><span class="cx">                 1A2D956F12848564001EB962 /* ChildProcess.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A2D956D12848564001EB962 /* ChildProcess.h */; };
</span><span class="cx">                 1A2D957012848564001EB962 /* ChildProcess.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A2D956E12848564001EB962 /* ChildProcess.cpp */; };
</span><span class="cx">                 1A30066E1110F4F70031937C /* ResponsivenessTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A30066C1110F4F70031937C /* ResponsivenessTimer.h */; };
</span><del>-                1A30EAC6115D7DA30053E937 /* ConnectionMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A30EAC5115D7DA30053E937 /* ConnectionMac.cpp */; };
</del><ins>+                1A30EAC6115D7DA30053E937 /* ConnectionMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1A30EAC5115D7DA30053E937 /* ConnectionMac.mm */; };
</ins><span class="cx">                 1A334DED16DE8F88006A8E38 /* StorageAreaMapMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A334DEB16DE8F88006A8E38 /* StorageAreaMapMessageReceiver.cpp */; };
</span><span class="cx">                 1A334DEE16DE8F88006A8E38 /* StorageAreaMapMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A334DEC16DE8F88006A8E38 /* StorageAreaMapMessages.h */; };
</span><span class="cx">                 1A3C888018A5ABAE00C4C962 /* WKPreferencesInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A3C887F18A5ABAE00C4C962 /* WKPreferencesInternal.h */; };
</span><span class="lines">@@ -1990,7 +1990,7 @@
</span><span class="cx">                 1A2D956D12848564001EB962 /* ChildProcess.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChildProcess.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A2D956E12848564001EB962 /* ChildProcess.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ChildProcess.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A30066C1110F4F70031937C /* ResponsivenessTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResponsivenessTimer.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><del>-                1A30EAC5115D7DA30053E937 /* ConnectionMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConnectionMac.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</del><ins>+                1A30EAC5115D7DA30053E937 /* ConnectionMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ConnectionMac.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 1A334DEA16DE8B68006A8E38 /* StorageAreaMap.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = StorageAreaMap.messages.in; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A334DEB16DE8F88006A8E38 /* StorageAreaMapMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageAreaMapMessageReceiver.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 1A334DEC16DE8F88006A8E38 /* StorageAreaMapMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageAreaMapMessages.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -6269,7 +6269,7 @@
</span><span class="cx">                 BCC56F751159955E001CCAF9 /* mac */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><del>-                                1A30EAC5115D7DA30053E937 /* ConnectionMac.cpp */,
</del><ins>+                                1A30EAC5115D7DA30053E937 /* ConnectionMac.mm */,
</ins><span class="cx">                                 1A1EC69D1872092100B951F0 /* ImportanceAssertion.h */,
</span><span class="cx">                                 BCC56F771159957D001CCAF9 /* MachPort.h */,
</span><span class="cx">                         );
</span><span class="lines">@@ -8398,7 +8398,7 @@
</span><span class="cx">                                 1A6F9FB711E1408500DB1371 /* CommandLinePOSIX.cpp in Sources */,
</span><span class="cx">                                 BC032DAA10F437D10058C15A /* Connection.cpp in Sources */,
</span><span class="cx">                                 2DA944A31884E4F000ED86DB /* WebTouchEventIOS.cpp in Sources */,
</span><del>-                                1A30EAC6115D7DA30053E937 /* ConnectionMac.cpp in Sources */,
</del><ins>+                                1A30EAC6115D7DA30053E937 /* ConnectionMac.mm in Sources */,
</ins><span class="cx">                                 5136183D163126DA00A99DDE /* ConnectionStack.cpp in Sources */,
</span><span class="cx">                                 2DA944B91884EA3900ED86DB /* WebBackForwardListProxyIOS.mm in Sources */,
</span><span class="cx">                                 515E773318402D510007203F /* UniqueIDBDatabaseIdentifier.cpp in Sources */,
</span></span></pre>
</div>
</div>

</body>
</html>