[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

kbalazs at webkit.org kbalazs at webkit.org
Wed Dec 22 15:23:00 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 8979e34c1ed5b883c84d4dcd452e48b5e9e4483f
Author: kbalazs at webkit.org <kbalazs at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Nov 2 15:47:49 2010 +0000

    [Qt][WK2] SharedMemory is broken
    https://bugs.webkit.org/show_bug.cgi?id=48520
    
    Reviewed by Andreas Kling.
    
    Implement SharedMemory with QSharedMemory to correctly handle
    ownership and to avoid extra allocation for page size requests.
    * Platform/SharedMemory.h:
    * Platform/qt/SharedMemoryQt.cpp:
    (WebKit::SharedMemory::Handle::Handle):
    (WebKit::SharedMemory::Handle::isNull):
    (WebKit::SharedMemory::Handle::encode):
    (WebKit::SharedMemory::Handle::decode):
    (WebKit::createUniqueKey):
    (WebKit::SharedMemory::create):
    (WebKit::accessMode):
    (WebKit::SharedMemory::~SharedMemory):
    (WebKit::SharedMemory::createHandle):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@71118 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index 02eb3a3..b73d3e2 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -1,3 +1,24 @@
+2010-11-02  Balazs Kelemen  <kbalazs at webkit.org>
+
+        Reviewed by Andreas Kling.
+
+        [Qt][WK2] SharedMemory is broken
+        https://bugs.webkit.org/show_bug.cgi?id=48520
+
+        Implement SharedMemory with QSharedMemory to correctly handle
+        ownership and to avoid extra allocation for page size requests.
+        * Platform/SharedMemory.h:
+        * Platform/qt/SharedMemoryQt.cpp:
+        (WebKit::SharedMemory::Handle::Handle):
+        (WebKit::SharedMemory::Handle::isNull):
+        (WebKit::SharedMemory::Handle::encode):
+        (WebKit::SharedMemory::Handle::decode):
+        (WebKit::createUniqueKey):
+        (WebKit::SharedMemory::create):
+        (WebKit::accessMode):
+        (WebKit::SharedMemory::~SharedMemory):
+        (WebKit::SharedMemory::createHandle):
+
 2010-11-02  Timothy Hatcher  <timothy at apple.com>
 
         Add WKInspector public APIs.
diff --git a/WebKit2/Platform/SharedMemory.h b/WebKit2/Platform/SharedMemory.h
index cb6ca15..05dc0dd 100644
--- a/WebKit2/Platform/SharedMemory.h
+++ b/WebKit2/Platform/SharedMemory.h
@@ -31,6 +31,10 @@
 #include <wtf/RefCounted.h>
 
 #if PLATFORM(QT)
+#include <QtGlobal>
+QT_BEGIN_NAMESPACE
+class QSharedMemory;
+QT_END_NAMESPACE
 #include <wtf/text/WTFString.h>
 #endif
 
@@ -65,7 +69,7 @@ public:
 #elif PLATFORM(WIN)
         mutable HANDLE m_handle;
 #elif PLATFORM(QT)
-        mutable String m_fileName;
+        mutable String m_key;
 #endif
         size_t m_size;
     };
@@ -91,6 +95,8 @@ private:
     void* m_data;
 #if PLATFORM(WIN)
     HANDLE m_handle;
+#elif PLATFORM(QT)
+    QSharedMemory* m_impl;
 #endif
 };
 
diff --git a/WebKit2/Platform/qt/SharedMemoryQt.cpp b/WebKit2/Platform/qt/SharedMemoryQt.cpp
index 1c5959d..0c237b0 100644
--- a/WebKit2/Platform/qt/SharedMemoryQt.cpp
+++ b/WebKit2/Platform/qt/SharedMemoryQt.cpp
@@ -29,18 +29,19 @@
 
 #include "ArgumentDecoder.h"
 #include "ArgumentEncoder.h"
-#include "MappedMemoryPool.h"
 #include "WebCoreArgumentCoders.h"
-#include <QIODevice>
 #include <unistd.h>
-#include <wtf/text/WTFString.h>
+#include <QLatin1String>
+#include <QSharedMemory>
+#include <QString>
+#include <QUuid>
+#include <wtf/Assertions.h>
+#include <wtf/CurrentTime.h>
 
 namespace WebKit {
 
-static MappedMemoryPool* mappedMemoryPool = MappedMemoryPool::instance();
-
 SharedMemory::Handle::Handle()
-    : m_fileName()
+    : m_key()
     , m_size(0)
 {
 }
@@ -51,57 +52,64 @@ SharedMemory::Handle::~Handle()
 
 bool SharedMemory::Handle::isNull() const
 {
-    return m_fileName.isNull();
+    return m_key.isNull();
 }
 
 void SharedMemory::Handle::encode(CoreIPC::ArgumentEncoder* encoder) const
 {
     encoder->encodeUInt64(m_size);
-    encoder->encode(m_fileName);
-    m_fileName = String();
+    encoder->encode(m_key);
+    m_key = String();
 }
 
 bool SharedMemory::Handle::decode(CoreIPC::ArgumentDecoder* decoder, Handle& handle)
 {
-    ASSERT(!handle.m_size);
-    ASSERT(handle.m_fileName.isEmpty());
+    ASSERT_ARG(handle, !handle.m_size);
+    ASSERT_ARG(handle, handle.m_key.isNull());
 
     uint64_t size;
     if (!decoder->decodeUInt64(size))
         return false;
 
-    String fileName;
-    if (!decoder->decode(fileName))
+    String key;
+    if (!decoder->decode(key))
        return false;
 
     handle.m_size = size;
-    handle.m_fileName = fileName;
+    handle.m_key = key;
 
     return true;
 }
 
-PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
+static QString createUniqueKey()
 {
-    MappedMemory* mm = mappedMemoryPool->mapMemory(size, QIODevice::ReadWrite);
+    return QLatin1String("QWKSharedMemoryKey") + QUuid::createUuid().toString();
+}
 
+PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
+{
     RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory));
+    QSharedMemory* impl = new QSharedMemory(createUniqueKey());
+    bool created = impl->create(size);
+    ASSERT_UNUSED(created, created);
+    sharedMemory->m_impl = impl;
     sharedMemory->m_size = size;
-    sharedMemory->m_data = reinterpret_cast<void*>(mm->data());
+    sharedMemory->m_data = impl->data();
 
     return sharedMemory.release();
 }
 
-static inline QIODevice::OpenMode mapProtection(SharedMemory::Protection protection)
+static inline QSharedMemory::AccessMode accessMode(SharedMemory::Protection protection)
 {
     switch (protection) {
     case SharedMemory::ReadOnly:
-        return QIODevice::ReadOnly;
+        return QSharedMemory::ReadOnly;
     case SharedMemory::ReadWrite:
-        return QIODevice::ReadWrite;
+        return QSharedMemory::ReadWrite;
     }
 
     ASSERT_NOT_REACHED();
-    return QIODevice::NotOpen;
+    return QSharedMemory::ReadWrite;
 }
 
 PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection protection)
@@ -109,45 +117,36 @@ PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection p
     if (handle.isNull())
         return 0;
 
-    QIODevice::OpenMode openMode = mapProtection(protection);
-
-    MappedMemory* mm = mappedMemoryPool->mapFile(QString(handle.m_fileName), handle.m_size, openMode);
-
     RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory));
+    QSharedMemory* impl = new QSharedMemory(QString(handle.m_key));
+    bool attached = impl->attach(accessMode(protection));
+    ASSERT_UNUSED(attached, attached);
+    sharedMemory->m_impl = impl;
+    ASSERT(handle.m_size == impl->size());
     sharedMemory->m_size = handle.m_size;
-    sharedMemory->m_data = reinterpret_cast<void*>(mm->data());
+    sharedMemory->m_data = impl->data();
 
     return sharedMemory.release();
 }
 
 SharedMemory::~SharedMemory()
 {
-    if (!m_data) {
-        // Ownership of the mapped memory has been passed.
-        return;
-    }
-
-    MappedMemory* mappedMemory = mappedMemoryPool->searchForMappedMemory(reinterpret_cast<uchar*>(m_data));
-    if (mappedMemory)
-        mappedMemory->markFree();
+    // m_impl must be non-null and it must point to a valid QSharedMemory object.
+    ASSERT(qobject_cast<QSharedMemory*>(m_impl));
+    delete m_impl;
 }
 
 bool SharedMemory::createHandle(Handle& handle, Protection protection)
 {
-    ASSERT(handle.m_fileName.isNull());
-    ASSERT(!handle.m_size);
+    ASSERT_ARG(handle, handle.m_key.isNull());
+    ASSERT_ARG(handle, !handle.m_size);
 
-    MappedMemory* mm = mappedMemoryPool->searchForMappedMemory(reinterpret_cast<uchar*>(m_data));
-
-    if (!mm)
+    QString key = m_impl->key();
+    if (key.isNull())
         return false;
-
-    handle.m_fileName = mm->file->fileName();
+    handle.m_key = String(key);
     handle.m_size = m_size;
 
-    // Hand off ownership of the mapped memory to the receiving process.
-    m_data = 0;
-
     return true;
 }
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list