Modified: trunk/Source/WebKit2/ChangeLog (182803 => 182804)
--- trunk/Source/WebKit2/ChangeLog 2015-04-14 18:40:27 UTC (rev 182803)
+++ trunk/Source/WebKit2/ChangeLog 2015-04-14 19:15:28 UTC (rev 182804)
@@ -1,3 +1,24 @@
+2015-04-14 Anders Carlsson <[email protected]>
+
+ More work on making the SharedMemory interface more sane
+ https://bugs.webkit.org/show_bug.cgi?id=143718
+
+ Reviewed by Andreas Kling.
+
+ Get rid of m_shouldVMDeallocateData. The idea is that shared memory created by calling
+ SharedMemory::allocate has a non-null m_data pointer, and a null m_port. Shared memory created
+ by calling SharedMemory::create with a pointer and a length has a non-null port but a null m_data
+ since the data can be unmapped by the caller and we don't want to hold on to dangling pointers.
+
+ * Platform/SharedMemory.h:
+ (WebKit::SharedMemory::data):
+ * Platform/mac/SharedMemoryMac.cpp:
+ (WebKit::SharedMemory::allocate):
+ (WebKit::SharedMemory::create):
+ (WebKit::SharedMemory::map):
+ (WebKit::SharedMemory::~SharedMemory):
+ (WebKit::SharedMemory::createHandle):
+
2015-04-14 Antti Koivisto <[email protected]>
Network Cache: Deduplicate body data
Modified: trunk/Source/WebKit2/Platform/SharedMemory.h (182803 => 182804)
--- trunk/Source/WebKit2/Platform/SharedMemory.h 2015-04-14 18:40:27 UTC (rev 182803)
+++ trunk/Source/WebKit2/Platform/SharedMemory.h 2015-04-14 19:15:28 UTC (rev 182804)
@@ -85,7 +85,11 @@
bool createHandle(Handle&, Protection);
size_t size() const { return m_size; }
- void* data() const { return m_data; }
+ void* data() const
+ {
+ ASSERT(m_data);
+ return m_data;
+ }
// Return the system page size in bytes.
static unsigned systemPageSize();
@@ -93,7 +97,6 @@
private:
size_t m_size;
void* m_data;
- bool m_shouldVMDeallocateData;
Protection m_protection;
#if OS(DARWIN)
Modified: trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp (182803 => 182804)
--- trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp 2015-04-14 18:40:27 UTC (rev 182803)
+++ trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp 2015-04-14 19:15:28 UTC (rev 182804)
@@ -106,17 +106,16 @@
kern_return_t kr = mach_vm_allocate(mach_task_self(), &address, round_page(size), VM_FLAGS_ANYWHERE);
if (kr != KERN_SUCCESS) {
LOG_ERROR("Failed to allocate mach_vm_allocate shared memory (%zu bytes). %s (%x)", size, mach_error_string(kr), kr);
- return 0;
+ return nullptr;
}
- RefPtr<SharedMemory> sharedMemory = create(toPointer(address), size, Protection::ReadWrite);
- if (!sharedMemory) {
- mach_vm_deallocate(mach_task_self(), address, round_page(size));
- return 0;
- }
-
- sharedMemory->m_shouldVMDeallocateData = true;
- return sharedMemory.release();
+ RefPtr<SharedMemory> sharedMemory = adoptRef(*new SharedMemory);
+ sharedMemory->m_size = size;
+ sharedMemory->m_data = toPointer(address);
+ sharedMemory->m_port = MACH_PORT_NULL;
+ sharedMemory->m_protection = Protection::ReadWrite;
+
+ return sharedMemory;
}
static inline vm_prot_t machProtection(SharedMemory::Protection protection)
@@ -155,8 +154,7 @@
RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory));
sharedMemory->m_size = size;
- sharedMemory->m_data = data;
- sharedMemory->m_shouldVMDeallocateData = false;
+ sharedMemory->m_data = nullptr;
sharedMemory->m_port = port;
sharedMemory->m_protection = protection;
@@ -179,7 +177,6 @@
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;
@@ -188,7 +185,7 @@
SharedMemory::~SharedMemory()
{
- if (m_data && m_shouldVMDeallocateData) {
+ if (m_data) {
kern_return_t kr = mach_vm_deallocate(mach_task_self(), toVMAddress(m_data), round_page(m_size));
ASSERT_UNUSED(kr, kr == KERN_SUCCESS);
}
@@ -206,7 +203,6 @@
ASSERT(!handle.m_port);
ASSERT(!handle.m_size);
- mach_vm_address_t address = toVMAddress(m_data);
memory_object_size_t size = round_page(m_size);
mach_port_t port;
@@ -217,6 +213,9 @@
if (mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, 1) != KERN_SUCCESS)
return false;
} else {
+ ASSERT(m_data);
+ mach_vm_address_t address = toVMAddress(m_data);
+
// Create a mach port that represents the shared memory.
kern_return_t kr = mach_make_memory_entry_64(mach_task_self(), &size, address, machProtection(protection), &port, MACH_PORT_NULL);
if (kr != KERN_SUCCESS)