Title: [182774] trunk/Source/WebKit2
Revision
182774
Author
[email protected]
Date
2015-04-13 18:33:50 -0700 (Mon, 13 Apr 2015)

Log Message

Keep track of each shared memory object's protection when deciding whether to return our existing port
https://bugs.webkit.org/show_bug.cgi?id=143687

Reviewed by Tim Horton.

* Platform/SharedMemory.h:
* Platform/mac/SharedMemoryMac.cpp:
(WebKit::machProtection):
(WebKit::SharedMemory::create):
(WebKit::SharedMemory::map):
(WebKit::SharedMemory::createHandle):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (182773 => 182774)


--- trunk/Source/WebKit2/ChangeLog	2015-04-14 00:45:47 UTC (rev 182773)
+++ trunk/Source/WebKit2/ChangeLog	2015-04-14 01:33:50 UTC (rev 182774)
@@ -1,3 +1,17 @@
+2015-04-13  Anders Carlsson  <[email protected]>
+
+        Keep track of each shared memory object's protection when deciding whether to return our existing port
+        https://bugs.webkit.org/show_bug.cgi?id=143687
+
+        Reviewed by Tim Horton.
+
+        * Platform/SharedMemory.h:
+        * Platform/mac/SharedMemoryMac.cpp:
+        (WebKit::machProtection):
+        (WebKit::SharedMemory::create):
+        (WebKit::SharedMemory::map):
+        (WebKit::SharedMemory::createHandle):
+
 2015-04-13  Tim Horton  <[email protected]>
 
         Add a persistent, fixed scale factor to make it easy to scale down WK(Web)Views

Modified: trunk/Source/WebKit2/Platform/SharedMemory.h (182773 => 182774)


--- trunk/Source/WebKit2/Platform/SharedMemory.h	2015-04-14 00:45:47 UTC (rev 182773)
+++ trunk/Source/WebKit2/Platform/SharedMemory.h	2015-04-14 01:33:50 UTC (rev 182774)
@@ -94,6 +94,7 @@
     size_t m_size;
     void* m_data;
     bool m_shouldVMDeallocateData;
+    Protection m_protection;
 
 #if OS(DARWIN)
     mach_port_t m_port;

Modified: trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp (182773 => 182774)


--- trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp	2015-04-14 00:45:47 UTC (rev 182773)
+++ trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp	2015-04-14 01:33:50 UTC (rev 182774)
@@ -119,14 +119,27 @@
     return sharedMemory.release();
 }
 
-RefPtr<SharedMemory> SharedMemory::create(void* data, size_t size, Protection)
+static inline vm_prot_t machProtection(SharedMemory::Protection protection)
 {
+    switch (protection) {
+    case SharedMemory::Protection::ReadOnly:
+        return VM_PROT_READ;
+    case SharedMemory::Protection::ReadWrite:
+        return VM_PROT_READ | VM_PROT_WRITE;
+    }
+
+    ASSERT_NOT_REACHED();
+    return VM_PROT_NONE;
+}
+
+RefPtr<SharedMemory> SharedMemory::create(void* data, size_t size, Protection protection)
+{
     ASSERT(size);
     
     // Create a Mach port that represents the shared memory.
     mach_port_t port;
     memory_object_size_t memoryObjectSize = round_page(size);
-    kern_return_t kr = mach_make_memory_entry_64(mach_task_self(), &memoryObjectSize, toVMAddress(data), VM_PROT_DEFAULT | VM_PROT_IS_MASK, &port, MACH_PORT_NULL);
+    kern_return_t kr = mach_make_memory_entry_64(mach_task_self(), &memoryObjectSize, toVMAddress(data), machProtection(protection) | VM_PROT_IS_MASK, &port, MACH_PORT_NULL);
     
     if (kr != KERN_SUCCESS) {
         LOG_ERROR("Failed to create a mach port for shared memory. %s (%x)", mach_error_string(kr), kr);
@@ -145,23 +158,11 @@
     sharedMemory->m_data = data;
     sharedMemory->m_shouldVMDeallocateData = false;
     sharedMemory->m_port = port;
+    sharedMemory->m_protection = protection;
 
     return sharedMemory.release();
 }
 
-static inline vm_prot_t machProtection(SharedMemory::Protection protection)
-{
-    switch (protection) {
-    case SharedMemory::Protection::ReadOnly:
-        return VM_PROT_READ;
-    case SharedMemory::Protection::ReadWrite:
-        return VM_PROT_READ | VM_PROT_WRITE;
-    }
-
-    ASSERT_NOT_REACHED();
-    return VM_PROT_NONE;    
-}
-
 RefPtr<SharedMemory> SharedMemory::map(const Handle& handle, Protection protection)
 {
     if (handle.isNull())
@@ -173,15 +174,16 @@
     mach_vm_address_t mappedAddress = 0;
     kern_return_t kr = mach_vm_map(mach_task_self(), &mappedAddress, round_page(handle.m_size), 0, VM_FLAGS_ANYWHERE, handle.m_port, 0, false, vmProtection, vmProtection, VM_INHERIT_NONE);
     if (kr != KERN_SUCCESS)
-        return 0;
+        return nullptr;
 
     RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory));
     sharedMemory->m_size = handle.m_size;
     sharedMemory->m_data = toPointer(mappedAddress);
     sharedMemory->m_shouldVMDeallocateData = true;
     sharedMemory->m_port = MACH_PORT_NULL;
+    sharedMemory->m_protection = protection;
 
-    return sharedMemory.release();
+    return sharedMemory;
 }
 
 SharedMemory::~SharedMemory()
@@ -199,6 +201,8 @@
     
 bool SharedMemory::createHandle(Handle& handle, Protection protection)
 {
+    ASSERT(m_protection == protection || m_protection == Protection::ReadWrite && protection == Protection::ReadOnly);
+
     ASSERT(!handle.m_port);
     ASSERT(!handle.m_size);
 
@@ -207,7 +211,7 @@
 
     mach_port_t port;
 
-    if (protection == Protection::ReadWrite && m_port) {
+    if (protection == m_protection && m_port) {
         // Just re-use the port we have.
         port = m_port;
         if (mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, 1) != KERN_SUCCESS)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to