Title: [186424] releases/WebKitGTK/webkit-2.8/Source/WebKit2
Revision
186424
Author
[email protected]
Date
2015-07-07 02:09:49 -0700 (Tue, 07 Jul 2015)

Log Message

Merge r185824 - [WK2] ConnectionUnix should use FastMalloc to allocate on-heap resources
https://bugs.webkit.org/show_bug.cgi?id=146143

Reviewed by Carlos Garcia Campos.

IPC handling in Unix-specific IPC::Connection implementation should use
FastMalloc to allocate on-heap resources, instead of allocating via the
system allocator.

The AttachmentInfo class is marked as allocatable through FastMalloc.
That way it can be allocated through FastMalloc while still handled
through std::unique_ptr<>.

The char[] arrays in readBytesFromSocket() and Connection::sendOutgoingMessage()
are now handled through a MallocPtr<> object.

In Connection::sendOutgoingMessage(), both the AttachmentInfo[] and char[]
arrays are now only allocated if there are actual attachments contained
in the message. The code that's conditioned with a non-empty attachments
Vector is now also grouped together, in a single branch.

* Platform/IPC/unix/ConnectionUnix.cpp:
(IPC::readBytesFromSocket):
(IPC::Connection::sendOutgoingMessage):

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.8/Source/WebKit2/ChangeLog (186423 => 186424)


--- releases/WebKitGTK/webkit-2.8/Source/WebKit2/ChangeLog	2015-07-07 09:05:25 UTC (rev 186423)
+++ releases/WebKitGTK/webkit-2.8/Source/WebKit2/ChangeLog	2015-07-07 09:09:49 UTC (rev 186424)
@@ -1,3 +1,30 @@
+2015-06-22  Zan Dobersek  <[email protected]>
+
+        [WK2] ConnectionUnix should use FastMalloc to allocate on-heap resources
+        https://bugs.webkit.org/show_bug.cgi?id=146143
+
+        Reviewed by Carlos Garcia Campos.
+
+        IPC handling in Unix-specific IPC::Connection implementation should use
+        FastMalloc to allocate on-heap resources, instead of allocating via the
+        system allocator.
+
+        The AttachmentInfo class is marked as allocatable through FastMalloc.
+        That way it can be allocated through FastMalloc while still handled
+        through std::unique_ptr<>.
+
+        The char[] arrays in readBytesFromSocket() and Connection::sendOutgoingMessage()
+        are now handled through a MallocPtr<> object.
+
+        In Connection::sendOutgoingMessage(), both the AttachmentInfo[] and char[]
+        arrays are now only allocated if there are actual attachments contained
+        in the message. The code that's conditioned with a non-empty attachments
+        Vector is now also grouped together, in a single branch.
+
+        * Platform/IPC/unix/ConnectionUnix.cpp:
+        (IPC::readBytesFromSocket):
+        (IPC::Connection::sendOutgoingMessage):
+
 2015-06-17  Carlos Garcia Campos  <[email protected]>
 
         [GTK] WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER doesn't disable memory cache when set before the web process is launched

Modified: releases/WebKitGTK/webkit-2.8/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp (186423 => 186424)


--- releases/WebKitGTK/webkit-2.8/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp	2015-07-07 09:05:25 UTC (rev 186423)
+++ releases/WebKitGTK/webkit-2.8/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp	2015-07-07 09:09:49 UTC (rev 186424)
@@ -95,6 +95,7 @@
 };
 
 class AttachmentInfo {
+    WTF_MAKE_FAST_ALLOCATED;
 public:
     AttachmentInfo()
         : m_type(Attachment::Uninitialized)
@@ -294,8 +295,8 @@
     memset(&iov, 0, sizeof(iov));
 
     message.msg_controllen = CMSG_SPACE(sizeof(int) * attachmentMaxAmount);
-    auto attachmentDescriptorBuffer = std::make_unique<char[]>(message.msg_controllen);
-    memset(attachmentDescriptorBuffer.get(), 0, message.msg_controllen);
+    MallocPtr<char> attachmentDescriptorBuffer = MallocPtr<char>::malloc(sizeof(char) * message.msg_controllen);
+    memset(attachmentDescriptorBuffer.get(), 0, sizeof(char) * message.msg_controllen);
     message.msg_control = attachmentDescriptorBuffer.get();
 
     iov[0].iov_base = buffer;
@@ -460,21 +461,20 @@
     iov[0].iov_base = reinterpret_cast<void*>(&messageInfo);
     iov[0].iov_len = sizeof(messageInfo);
 
-    auto attachmentInfo = std::make_unique<AttachmentInfo[]>(attachments.size());
+    std::unique_ptr<AttachmentInfo[]> attachmentInfo;
+    MallocPtr<char> attachmentFDBuffer;
 
-    size_t attachmentFDBufferLength = 0;
     if (!attachments.isEmpty()) {
-        for (size_t i = 0; i < attachments.size(); ++i) {
-            if (attachments[i].fileDescriptor() != -1)
-                attachmentFDBufferLength++;
-        }
-    }
-    auto attachmentFDBuffer = std::make_unique<char[]>(CMSG_SPACE(sizeof(int) * attachmentFDBufferLength));
-
-    if (!attachments.isEmpty()) {
         int* fdPtr = 0;
 
+        size_t attachmentFDBufferLength = std::count_if(attachments.begin(), attachments.end(),
+            [](const Attachment& attachment) {
+                return attachment.fileDescriptor() != -1;
+            });
+
         if (attachmentFDBufferLength) {
+            attachmentFDBuffer = MallocPtr<char>::malloc(sizeof(char) * CMSG_SPACE(sizeof(int) * attachmentFDBufferLength));
+
             message.msg_control = attachmentFDBuffer.get();
             message.msg_controllen = CMSG_SPACE(sizeof(int) * attachmentFDBufferLength);
             memset(message.msg_control, 0, message.msg_controllen);
@@ -487,6 +487,7 @@
             fdPtr = reinterpret_cast<int*>(CMSG_DATA(cmsg));
         }
 
+        attachmentInfo = std::make_unique<AttachmentInfo[]>(attachments.size());
         int fdIndex = 0;
         for (size_t i = 0; i < attachments.size(); ++i) {
             attachmentInfo[i].setType(attachments[i].type());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to