diff options
Diffstat (limited to 'Source/WebKit2/Platform/qt')
-rw-r--r-- | Source/WebKit2/Platform/qt/MappedMemoryPool.cpp | 114 | ||||
-rw-r--r-- | Source/WebKit2/Platform/qt/MappedMemoryPool.h | 109 | ||||
-rw-r--r-- | Source/WebKit2/Platform/qt/ModuleQt.cpp | 1 | ||||
-rw-r--r-- | Source/WebKit2/Platform/qt/RunLoopQt.cpp | 1 | ||||
-rw-r--r-- | Source/WebKit2/Platform/qt/SharedMemoryQt.cpp | 176 | ||||
-rw-r--r-- | Source/WebKit2/Platform/qt/WorkQueueQt.cpp | 39 |
6 files changed, 131 insertions, 309 deletions
diff --git a/Source/WebKit2/Platform/qt/MappedMemoryPool.cpp b/Source/WebKit2/Platform/qt/MappedMemoryPool.cpp deleted file mode 100644 index d36d82b..0000000 --- a/Source/WebKit2/Platform/qt/MappedMemoryPool.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2010 University of Szeged - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "MappedMemoryPool.h" - -#include "CleanupHandler.h" -#include "StdLibExtras.h" -#include <QDir> -#include <QIODevice> -#include <QTemporaryFile> - -namespace WebKit { - -MappedMemoryPool* MappedMemoryPool::theInstance = 0; - -MappedMemoryPool* MappedMemoryPool::instance() -{ - if (!theInstance) { - theInstance = new MappedMemoryPool; - - // Do not leave mapping files on the disk. - CleanupHandler::instance()->markForCleanup(theInstance); - } - - return theInstance; -} - -MappedMemoryPool::~MappedMemoryPool() -{ - CleanupHandler::instance()->unmark(theInstance); - - for (unsigned n = 0; n < m_pool.size(); ++n) { - MappedMemory& current = m_pool.at(n); - if (!current.file) - continue; - current.file->remove(); - delete current.file; - } - m_pool.clear(); -} - -MappedMemory* MappedMemoryPool::mapMemory(size_t size) -{ - for (unsigned n = 0; n < m_pool.size(); ++n) { - MappedMemory& current = m_pool.at(n); - if (current.dataSize >= size && current.isFree()) { - current.markUsed(); - return ¤t; - } - } - - MappedMemory newMap; - newMap.dataSize = size; - newMap.file = new QTemporaryFile(QDir::tempPath() + "/WebKit2UpdateChunk"); - newMap.file->open(QIODevice::ReadWrite); - newMap.fileName = newMap.file->fileName(); - newMap.file->resize(newMap.mapSize()); - newMap.mappedBytes = newMap.file->map(0, newMap.mapSize()); - newMap.file->close(); - newMap.markUsed(); - m_pool.append(newMap); - return &m_pool.last(); -} - -MappedMemory* MappedMemoryPool::mapFile(QString fileName, size_t size) -{ - for (unsigned n = 0; n < m_pool.size(); ++n) { - MappedMemory& current = m_pool.at(n); - if (current.fileName == fileName) { - ASSERT(!current.isFree()); - return ¤t; - } - } - - MappedMemory newMap; - newMap.file = new QFile(fileName); - newMap.fileName = fileName; - newMap.dataSize = size; - ASSERT(newMap.file->exists()); - ASSERT(newMap.file->size() >= newMap.mapSize()); - newMap.file->open(QIODevice::ReadWrite); - newMap.mappedBytes = newMap.file->map(0, newMap.mapSize()); - ASSERT(newMap.mappedBytes); - ASSERT(!newMap.isFree()); - newMap.file->close(); - m_pool.append(newMap); - return &m_pool.last(); -} - -} // namespace WebKit diff --git a/Source/WebKit2/Platform/qt/MappedMemoryPool.h b/Source/WebKit2/Platform/qt/MappedMemoryPool.h deleted file mode 100644 index 8d6af8c..0000000 --- a/Source/WebKit2/Platform/qt/MappedMemoryPool.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2010 Apple Inc. All rights reserved. - * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) - * Copyright (C) 2010 University of Szeged - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef MappedMemoryPool_h -#define MappedMemoryPool_h - -#include <QFile> -#include <QObject> -#include <wtf/StdLibExtras.h> -#include <wtf/Vector.h> - -namespace WebKit { - -class MappedMemoryPool; - -struct MappedMemory { - - QString mappedFileName() const - { - ASSERT(file); - ASSERT(mappedBytes); - return fileName; - } - - void markFree() - { - ASSERT(mappedBytes); - dataPtr->isFree = true; - } - - uchar* data() const - { - ASSERT(mappedBytes); - return dataPtr->bytes; - } - -private: - friend class MappedMemoryPool; - - MappedMemory() - : file(0) - , mappedBytes(0) - , dataSize(0) - { - } - - void markUsed() { dataPtr->isFree = false; } - - size_t mapSize() const { return dataSize + sizeof(Data); } - bool isFree() const { return dataPtr->isFree; } - - struct Data { - uint32_t isFree; // keep bytes aligned - uchar bytes[]; - }; - - QFile* file; - QString fileName; - union { - uchar* mappedBytes; - Data* dataPtr; - }; - size_t dataSize; -}; - -class MappedMemoryPool : QObject { - Q_OBJECT -public: - static MappedMemoryPool* instance(); - - MappedMemory* mapMemory(size_t size); - MappedMemory* mapFile(QString fileName, size_t size); - -private: - MappedMemoryPool() { } - ~MappedMemoryPool(); - - static MappedMemoryPool* theInstance; - - Vector<MappedMemory> m_pool; -}; - -} // namespace WebKit - -#endif // MappedMemoryPool_h diff --git a/Source/WebKit2/Platform/qt/ModuleQt.cpp b/Source/WebKit2/Platform/qt/ModuleQt.cpp index 8a68cf4..de83691 100644 --- a/Source/WebKit2/Platform/qt/ModuleQt.cpp +++ b/Source/WebKit2/Platform/qt/ModuleQt.cpp @@ -24,6 +24,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include "Module.h" namespace WebKit { diff --git a/Source/WebKit2/Platform/qt/RunLoopQt.cpp b/Source/WebKit2/Platform/qt/RunLoopQt.cpp index d7d859d..b7aea2f 100644 --- a/Source/WebKit2/Platform/qt/RunLoopQt.cpp +++ b/Source/WebKit2/Platform/qt/RunLoopQt.cpp @@ -24,6 +24,7 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include "RunLoop.h" #include "WorkItem.h" diff --git a/Source/WebKit2/Platform/qt/SharedMemoryQt.cpp b/Source/WebKit2/Platform/qt/SharedMemoryQt.cpp index f5fecfc..91af533 100644 --- a/Source/WebKit2/Platform/qt/SharedMemoryQt.cpp +++ b/Source/WebKit2/Platform/qt/SharedMemoryQt.cpp @@ -25,143 +25,193 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include "SharedMemory.h" #include "ArgumentDecoder.h" #include "ArgumentEncoder.h" -#include "CleanupHandler.h" #include "WebCoreArgumentCoders.h" +#include <QDir> +#include <errno.h> +#include <fcntl.h> +#include <stdlib.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/types.h> #include <unistd.h> -#include <QCoreApplication> -#include <QLatin1String> -#include <QSharedMemory> -#include <QString> -#include <QUuid> #include <wtf/Assertions.h> #include <wtf/CurrentTime.h> namespace WebKit { SharedMemory::Handle::Handle() - : m_key() + : m_fileDescriptor(-1) , m_size(0) { } SharedMemory::Handle::~Handle() { + if (!isNull()) + while (close(m_fileDescriptor) == -1 && errno == EINTR) { } } bool SharedMemory::Handle::isNull() const { - return m_key.isNull(); + return m_fileDescriptor == -1; } void SharedMemory::Handle::encode(CoreIPC::ArgumentEncoder* encoder) const { - encoder->encodeUInt64(m_size); - encoder->encode(m_key); - m_key = String(); + ASSERT(!isNull()); + + encoder->encode(releaseToAttachment()); } bool SharedMemory::Handle::decode(CoreIPC::ArgumentDecoder* decoder, Handle& handle) { ASSERT_ARG(handle, !handle.m_size); - ASSERT_ARG(handle, handle.m_key.isNull()); + ASSERT_ARG(handle, handle.isNull()); - uint64_t size; - if (!decoder->decodeUInt64(size)) + CoreIPC::Attachment attachment; + if (!decoder->decode(attachment)) return false; - String key; - if (!decoder->decode(key)) - return false; + handle.adoptFromAttachment(attachment.releaseFileDescriptor(), attachment.size()); + return true; +} - handle.m_size = size; - handle.m_key = key; +CoreIPC::Attachment SharedMemory::Handle::releaseToAttachment() const +{ + ASSERT(!isNull()); - return true; + int temp = m_fileDescriptor; + m_fileDescriptor = -1; + return CoreIPC::Attachment(temp, m_size); } -static QString createUniqueKey() +void SharedMemory::Handle::adoptFromAttachment(int fileDescriptor, size_t size) { - return QLatin1String("QWKSharedMemoryKey") + QUuid::createUuid().toString(); + ASSERT(!m_size); + ASSERT(isNull()); + + m_fileDescriptor = fileDescriptor; + m_size = size; } 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); + QString tempName = QDir::temp().filePath("qwkshm.XXXXXX"); + QByteArray tempNameCSTR = tempName.toLocal8Bit(); + char* tempNameC = tempNameCSTR.data(); + + int fileDescriptor; + while ((fileDescriptor = mkstemp(tempNameC)) == -1) { + if (errno != EINTR) + return 0; + } + while (fcntl(fileDescriptor, F_SETFD, FD_CLOEXEC) == -1) { + if (errno != EINTR) { + while (close(fileDescriptor) == -1 && errno == EINTR) { } + unlink(tempNameC); + return 0; + } + } - sharedMemory->m_impl = impl; - sharedMemory->m_size = size; - sharedMemory->m_data = impl->data(); + while (ftruncate(fileDescriptor, size) == -1) { + if (errno != EINTR) { + while (close(fileDescriptor) == -1 && errno == EINTR) { } + unlink(tempNameC); + return 0; + } + } - // Do not leave the shared memory segment behind. - CleanupHandler::instance()->markForCleanup(impl); + void* data = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileDescriptor, 0); + if (data == MAP_FAILED) { + while (close(fileDescriptor) == -1 && errno == EINTR) { } + unlink(tempNameC); + return 0; + } - return sharedMemory.release(); + unlink(tempNameC); + + RefPtr<SharedMemory> instance = adoptRef(new SharedMemory()); + instance->m_data = data; + instance->m_fileDescriptor = fileDescriptor; + instance->m_size = size; + return instance.release(); } -static inline QSharedMemory::AccessMode accessMode(SharedMemory::Protection protection) +static inline int accessModeMMap(SharedMemory::Protection protection) { switch (protection) { case SharedMemory::ReadOnly: - return QSharedMemory::ReadOnly; + return PROT_READ; case SharedMemory::ReadWrite: - return QSharedMemory::ReadWrite; + return PROT_READ | PROT_WRITE; } ASSERT_NOT_REACHED(); - return QSharedMemory::ReadWrite; + return PROT_READ | PROT_WRITE; } PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection protection) { - if (handle.isNull()) - return 0; + ASSERT(!handle.isNull()); - QSharedMemory* impl = new QSharedMemory(QString(handle.m_key)); - bool attached = impl->attach(accessMode(protection)); - if (!attached) { - delete impl; + void* data = mmap(0, handle.m_size, accessModeMMap(protection), MAP_SHARED, handle.m_fileDescriptor, 0); + if (data == MAP_FAILED) return 0; - } - RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory)); - sharedMemory->m_impl = impl; - ASSERT(handle.m_size == impl->size()); - sharedMemory->m_size = handle.m_size; - sharedMemory->m_data = impl->data(); - - // Do not leave the shared memory segment behind. - CleanupHandler::instance()->markForCleanup(impl); - - return sharedMemory.release(); + RefPtr<SharedMemory> instance = adoptRef(new SharedMemory()); + instance->m_data = data; + instance->m_fileDescriptor = handle.m_fileDescriptor; + instance->m_size = handle.m_size; + handle.m_fileDescriptor = -1; + return instance; } SharedMemory::~SharedMemory() { - if (CleanupHandler::instance()->hasStartedDeleting()) - return; + munmap(m_data, m_size); + while (close(m_fileDescriptor) == -1 && errno == EINTR) { } +} + +static inline int accessModeFile(SharedMemory::Protection protection) +{ + switch (protection) { + case SharedMemory::ReadOnly: + return O_RDONLY; + case SharedMemory::ReadWrite: + return O_RDWR; + } - CleanupHandler::instance()->unmark(m_impl); - delete m_impl; + ASSERT_NOT_REACHED(); + return O_RDWR; } bool SharedMemory::createHandle(Handle& handle, Protection protection) { - ASSERT_ARG(handle, handle.m_key.isNull()); ASSERT_ARG(handle, !handle.m_size); + ASSERT_ARG(handle, handle.isNull()); + + int duplicatedHandle; + while ((duplicatedHandle = dup(m_fileDescriptor)) == -1) { + if (errno != EINTR) { + ASSERT_NOT_REACHED(); + return false; + } + } - QString key = m_impl->key(); - if (key.isNull()) - return false; - handle.m_key = String(key); + while ((fcntl(duplicatedHandle, F_SETFD, FD_CLOEXEC | accessModeFile(protection)) == -1)) { + if (errno != EINTR) { + ASSERT_NOT_REACHED(); + while (close(duplicatedHandle) == -1 && errno == EINTR) { } + return false; + } + } + handle.m_fileDescriptor = duplicatedHandle; handle.m_size = m_size; - return true; } diff --git a/Source/WebKit2/Platform/qt/WorkQueueQt.cpp b/Source/WebKit2/Platform/qt/WorkQueueQt.cpp index 271984f..24af404 100644 --- a/Source/WebKit2/Platform/qt/WorkQueueQt.cpp +++ b/Source/WebKit2/Platform/qt/WorkQueueQt.cpp @@ -24,11 +24,13 @@ * THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" #include "WorkQueue.h" #include <QLocalSocket> #include <QObject> #include <QThread> +#include <QProcess> #include <wtf/Threading.h> #include "NotImplemented.h" @@ -75,32 +77,17 @@ public: WorkItem* m_workItem; }; -void WorkQueue::connectSignal(QObject* o, const char* signal, PassOwnPtr<WorkItem> workItem) -{ - WorkQueue::WorkItemQt* itemQt = new WorkQueue::WorkItemQt(this, o, signal, workItem.leakPtr()); - itemQt->moveToThread(m_workThread); - m_signalListeners.add(o, itemQt); -} - -void WorkQueue::disconnectSignal(QObject* o, const char* name) -{ - HashMap<QObject*, WorkItemQt*>::iterator it = m_signalListeners.find(o); - for (; it != m_signalListeners.end(); ++it) { - if (strcmp(it->second->m_signal, name)) - continue; - delete it->second; - m_signalListeners.remove(it); - return; - } -} - -void WorkQueue::moveSocketToWorkThread(QLocalSocket* socket) +QSocketNotifier* WorkQueue::registerSocketEventHandler(int socketDescriptor, QSocketNotifier::Type type, PassOwnPtr<WorkItem> workItem) { ASSERT(m_workThread); - ASSERT(socket); - socket->setParent(0); - socket->moveToThread(m_workThread); + QSocketNotifier* notifier = new QSocketNotifier(socketDescriptor, type, 0); + notifier->setEnabled(false); + notifier->moveToThread(m_workThread); + WorkQueue::WorkItemQt* itemQt = new WorkQueue::WorkItemQt(this, notifier, SIGNAL(activated(int)), workItem.leakPtr()); + itemQt->moveToThread(m_workThread); + notifier->setEnabled(true); + return notifier; } void WorkQueue::platformInitialize(const char*) @@ -129,4 +116,10 @@ void WorkQueue::scheduleWorkAfterDelay(PassOwnPtr<WorkItem>, double) notImplemented(); } +void WorkQueue::scheduleWorkOnTermination(WebKit::PlatformProcessIdentifier process, PassOwnPtr<WorkItem> workItem) +{ + WorkQueue::WorkItemQt* itemQt = new WorkQueue::WorkItemQt(this, process, SIGNAL(finished(int, QProcess::ExitStatus)), workItem.leakPtr()); + itemQt->moveToThread(m_workThread); +} + #include "WorkQueueQt.moc" |