Title: [158890] trunk/Source/WebKit2
Revision
158890
Author
[email protected]
Date
2013-11-07 17:54:28 -0800 (Thu, 07 Nov 2013)

Log Message

Get rid of the out-of-line memory attachment type
https://bugs.webkit.org/show_bug.cgi?id=124023

Reviewed by Andreas Kling.

We're only using out-of-line memory for when the message body is too big, so
isolate that code in Connection and get rid of the out of line attachment type.

* Platform/CoreIPC/Attachment.cpp:
(CoreIPC::Attachment::Attachment):
* Platform/CoreIPC/Attachment.h:
(CoreIPC::Attachment::port):
(CoreIPC::Attachment::disposition):
* Platform/CoreIPC/mac/ConnectionMac.cpp:
(CoreIPC::Connection::sendOutgoingMessage):
(CoreIPC::createMessageDecoder):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (158889 => 158890)


--- trunk/Source/WebKit2/ChangeLog	2013-11-08 01:42:59 UTC (rev 158889)
+++ trunk/Source/WebKit2/ChangeLog	2013-11-08 01:54:28 UTC (rev 158890)
@@ -1,3 +1,22 @@
+2013-11-07  Anders Carlsson  <[email protected]>
+
+        Get rid of the out-of-line memory attachment type
+        https://bugs.webkit.org/show_bug.cgi?id=124023
+
+        Reviewed by Andreas Kling.
+
+        We're only using out-of-line memory for when the message body is too big, so
+        isolate that code in Connection and get rid of the out of line attachment type.
+
+        * Platform/CoreIPC/Attachment.cpp:
+        (CoreIPC::Attachment::Attachment):
+        * Platform/CoreIPC/Attachment.h:
+        (CoreIPC::Attachment::port):
+        (CoreIPC::Attachment::disposition):
+        * Platform/CoreIPC/mac/ConnectionMac.cpp:
+        (CoreIPC::Connection::sendOutgoingMessage):
+        (CoreIPC::createMessageDecoder):
+
 2013-11-07  Simon Fraser  <[email protected]>
 
         Lots of layers get solid color but transparent contents layers now

Modified: trunk/Source/WebKit2/Platform/CoreIPC/Attachment.cpp (158889 => 158890)


--- trunk/Source/WebKit2/Platform/CoreIPC/Attachment.cpp	2013-11-08 01:42:59 UTC (rev 158889)
+++ trunk/Source/WebKit2/Platform/CoreIPC/Attachment.cpp	2013-11-08 01:54:28 UTC (rev 158890)
@@ -39,20 +39,11 @@
 #if OS(DARWIN)
 Attachment::Attachment(mach_port_name_t port, mach_msg_type_name_t disposition)
     : m_type(MachPortType)
+    , m_port(port)
+    , m_disposition(disposition)
 {
-    m_port.port = port;
-    m_port.disposition = disposition;
 }
 
-Attachment::Attachment(void* address, mach_msg_size_t size, mach_msg_copy_options_t copyOptions, bool deallocate)
-    : m_type(MachOOLMemoryType)
-{
-    m_oolMemory.address = address;
-    m_oolMemory.size = size;
-    m_oolMemory.copyOptions = copyOptions;
-    m_oolMemory.deallocate = deallocate;
-}
-
 void Attachment::release()
 {
     m_type = Uninitialized;

Modified: trunk/Source/WebKit2/Platform/CoreIPC/Attachment.h (158889 => 158890)


--- trunk/Source/WebKit2/Platform/CoreIPC/Attachment.h	2013-11-08 01:42:59 UTC (rev 158889)
+++ trunk/Source/WebKit2/Platform/CoreIPC/Attachment.h	2013-11-08 01:54:28 UTC (rev 158890)
@@ -44,7 +44,6 @@
         Uninitialized,
 #if OS(DARWIN)
         MachPortType,
-        MachOOLMemoryType,
 #elif USE(UNIX_DOMAIN_SOCKETS)
         SocketType,
         MappedMemoryType
@@ -53,7 +52,6 @@
 
 #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)
     Attachment(int fileDescriptor, size_t);
     Attachment(int fileDescriptor);
@@ -65,14 +63,9 @@
     void release();
 
     // MachPortType
-    mach_port_name_t port() const { ASSERT(m_type == MachPortType); return m_port.port; }
-    mach_msg_type_name_t disposition() const { ASSERT(m_type == MachPortType); return m_port.disposition; }
+    mach_port_name_t port() const { return m_port; }
+    mach_msg_type_name_t disposition() const { return m_disposition; }
 
-    // MachOOLMemoryType
-    void* address() const { ASSERT(m_type == MachOOLMemoryType); return m_oolMemory.address; }
-    mach_msg_size_t size() const { ASSERT(m_type == MachOOLMemoryType); return m_oolMemory.size; }
-    mach_msg_copy_options_t copyOptions() const { ASSERT(m_type == MachOOLMemoryType); return m_oolMemory.copyOptions; }
-    bool deallocate() const { ASSERT(m_type == MachOOLMemoryType); return m_oolMemory.deallocate; }
 #elif USE(UNIX_DOMAIN_SOCKETS)
     size_t size() const { return m_size; }
 
@@ -89,18 +82,8 @@
     Type m_type;
 
 #if OS(DARWIN)
-    union {
-        struct {
-            mach_port_name_t port;
-            mach_msg_type_name_t disposition;
-        } m_port;
-        struct {
-            void* address;
-            mach_msg_size_t size;
-            mach_msg_copy_options_t copyOptions;
-            bool deallocate;
-        } m_oolMemory;
-    };
+    mach_port_name_t m_port;
+    mach_msg_type_name_t m_disposition;
 #elif USE(UNIX_DOMAIN_SOCKETS)
     int m_fileDescriptor;
     size_t m_size;

Modified: trunk/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp (158889 => 158890)


--- trunk/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp	2013-11-08 01:42:59 UTC (rev 158889)
+++ trunk/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp	2013-11-08 01:54:28 UTC (rev 158890)
@@ -201,8 +201,6 @@
         Attachment::Type type = attachments[i].type();
         if (type == Attachment::MachPortType)
             numberOfPortDescriptors++;
-        else if (type == Attachment::MachOOLMemoryType)
-            numberOfOOLMemoryDescriptors++;
     }
     
     size_t messageSize = machMessageSize(encoder->bufferSize(), numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
@@ -212,7 +210,6 @@
     if (messageSize > sizeof(buffer)) {
         messageBodyIsOOL = true;
 
-        attachments.append(Attachment(encoder->buffer(), encoder->bufferSize(), MACH_MSG_VIRTUAL_COPY, false));
         numberOfOOLMemoryDescriptors++;
         messageSize = machMessageSize(0, numberOfPortDescriptors, numberOfOOLMemoryDescriptors);
     }
@@ -220,7 +217,7 @@
     bool isComplex = (numberOfPortDescriptors + numberOfOOLMemoryDescriptors > 0);
 
     mach_msg_header_t* header = reinterpret_cast<mach_msg_header_t*>(&buffer);
-    header->msgh_bits = isComplex ? MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND | MACH_MSGH_BITS_COMPLEX, 0) : MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
+    header->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, 0);
     header->msgh_size = messageSize;
     header->msgh_remote_port = m_sendPort;
     header->msgh_local_port = MACH_PORT_NULL;
@@ -231,10 +228,12 @@
     uint8_t* messageData;
 
     if (isComplex) {
+        header->msgh_bits |= MACH_MSGH_BITS_COMPLEX;
+
         mach_msg_body_t* body = reinterpret_cast<mach_msg_body_t*>(header + 1);
         body->msgh_descriptor_count = numberOfPortDescriptors + numberOfOOLMemoryDescriptors;
-
         uint8_t* descriptorData = reinterpret_cast<uint8_t*>(body + 1);
+
         for (size_t i = 0; i < attachments.size(); ++i) {
             Attachment attachment = attachments[i];
 
@@ -247,20 +246,23 @@
 
                 descriptorData += sizeof(mach_msg_port_descriptor_t);
                 break;
-            case Attachment::MachOOLMemoryType:
-                descriptor->out_of_line.address = attachment.address();
-                descriptor->out_of_line.size = attachment.size();
-                descriptor->out_of_line.copy = attachment.copyOptions();
-                descriptor->out_of_line.deallocate = attachment.deallocate();
-                descriptor->out_of_line.type = MACH_MSG_OOL_DESCRIPTOR;            
-
-                descriptorData += sizeof(mach_msg_ool_descriptor_t);
-                break;
             default:
                 ASSERT_NOT_REACHED();
             }
         }
 
+        if (messageBodyIsOOL) {
+            mach_msg_descriptor_t* descriptor = reinterpret_cast<mach_msg_descriptor_t*>(descriptorData);
+
+            descriptor->out_of_line.address = encoder->buffer();
+            descriptor->out_of_line.size = encoder->bufferSize();
+            descriptor->out_of_line.copy = MACH_MSG_VIRTUAL_COPY;
+            descriptor->out_of_line.deallocate = false;
+            descriptor->out_of_line.type = MACH_MSG_OOL_DESCRIPTOR;
+
+            descriptorData += sizeof(mach_msg_ool_descriptor_t);
+        }
+
         messageData = descriptorData;
     } else
         messageData = (uint8_t*)(header + 1);
@@ -326,10 +328,6 @@
             attachments[numDescriptors - i - 1] = Attachment(descriptor->port.name, descriptor->port.disposition);
             descriptorData += sizeof(mach_msg_port_descriptor_t);
             break;
-        case MACH_MSG_OOL_DESCRIPTOR:
-            attachments[numDescriptors - i - 1] = Attachment(descriptor->out_of_line.address, descriptor->out_of_line.size, descriptor->out_of_line.copy, descriptor->out_of_line.deallocate);
-            descriptorData += sizeof(mach_msg_ool_descriptor_t);
-            break;
         default:
             ASSERT(false && "Unhandled descriptor type");
         }
@@ -338,15 +336,13 @@
     if (messageBodyIsOOL) {
         mach_msg_descriptor_t* descriptor = reinterpret_cast<mach_msg_descriptor_t*>(descriptorData);
         ASSERT(descriptor->type.type == MACH_MSG_OOL_DESCRIPTOR);
-        Attachment messageBodyAttachment(descriptor->out_of_line.address, descriptor->out_of_line.size,
-                                         descriptor->out_of_line.copy, descriptor->out_of_line.deallocate);
 
-        uint8_t* messageBody = static_cast<uint8_t*>(messageBodyAttachment.address());
-        size_t messageBodySize = messageBodyAttachment.size();
+        uint8_t* messageBody = static_cast<uint8_t*>(descriptor->out_of_line.address);
+        size_t messageBodySize = descriptor->out_of_line.size;
 
         auto decoder = std::make_unique<MessageDecoder>(DataReference(messageBody, messageBodySize), std::move(attachments));
 
-        vm_deallocate(mach_task_self(), reinterpret_cast<vm_address_t>(messageBodyAttachment.address()), messageBodyAttachment.size());
+        vm_deallocate(mach_task_self(), reinterpret_cast<vm_address_t>(descriptor->out_of_line.address), descriptor->out_of_line.size);
 
         return decoder;
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to