diff options
Diffstat (limited to 'Source/WebKit2/Platform')
-rw-r--r-- | Source/WebKit2/Platform/IPC/Arguments.h | 2 | ||||
-rw-r--r-- | Source/WebKit2/Platform/IPC/Attachment.cpp | 5 | ||||
-rw-r--r-- | Source/WebKit2/Platform/IPC/Attachment.h | 8 | ||||
-rw-r--r-- | Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm | 15 | ||||
-rw-r--r-- | Source/WebKit2/Platform/IPC/win/AttachmentWin.cpp | 87 | ||||
-rw-r--r-- | Source/WebKit2/Platform/IPC/win/ConnectionWin.cpp | 34 | ||||
-rw-r--r-- | Source/WebKit2/Platform/SharedMemory.h | 3 | ||||
-rw-r--r-- | Source/WebKit2/Platform/win/SharedMemoryWin.cpp | 56 |
8 files changed, 160 insertions, 50 deletions
diff --git a/Source/WebKit2/Platform/IPC/Arguments.h b/Source/WebKit2/Platform/IPC/Arguments.h index d7bf21774..64ecd8677 100644 --- a/Source/WebKit2/Platform/IPC/Arguments.h +++ b/Source/WebKit2/Platform/IPC/Arguments.h @@ -29,6 +29,8 @@ #include "ArgumentDecoder.h" #include "ArgumentEncoder.h" +#include <tuple> + namespace IPC { template<size_t index, typename... Elements> diff --git a/Source/WebKit2/Platform/IPC/Attachment.cpp b/Source/WebKit2/Platform/IPC/Attachment.cpp index 59033de38..366749816 100644 --- a/Source/WebKit2/Platform/IPC/Attachment.cpp +++ b/Source/WebKit2/Platform/IPC/Attachment.cpp @@ -33,6 +33,9 @@ namespace IPC { Attachment::Attachment() : m_type(Uninitialized) +#if OS(WINDOWS) + , m_handle(0) +#endif { } @@ -50,6 +53,7 @@ void Attachment::release() } #endif +#if !OS(WINDOWS) void Attachment::encode(ArgumentEncoder& encoder) const { encoder.addAttachment(WTFMove(*const_cast<Attachment*>(this))); @@ -61,5 +65,6 @@ bool Attachment::decode(ArgumentDecoder& decoder, Attachment& attachment) return false; return true; } +#endif } // namespace IPC diff --git a/Source/WebKit2/Platform/IPC/Attachment.h b/Source/WebKit2/Platform/IPC/Attachment.h index 10e66c298..9165a1998 100644 --- a/Source/WebKit2/Platform/IPC/Attachment.h +++ b/Source/WebKit2/Platform/IPC/Attachment.h @@ -58,6 +58,10 @@ public: ~Attachment(); #elif OS(DARWIN) Attachment(mach_port_name_t, mach_msg_type_name_t disposition); +#elif OS(WINDOWS) + Attachment(HANDLE handle) + : m_handle(handle) + { } #endif Type type() const { return m_type; } @@ -73,6 +77,8 @@ public: // MachPortType mach_port_name_t port() const { return m_port; } mach_msg_type_name_t disposition() const { return m_disposition; } +#elif OS(WINDOWS) + HANDLE handle() const { return m_handle; } #endif void encode(ArgumentEncoder&) const; @@ -87,6 +93,8 @@ private: #elif OS(DARWIN) mach_port_name_t m_port; mach_msg_type_name_t m_disposition; +#elif OS(WINDOWS) + HANDLE m_handle; #endif }; diff --git a/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm b/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm index b7ac61a9d..a12e25431 100644 --- a/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm +++ b/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm @@ -111,8 +111,19 @@ private: void Connection::platformInvalidate() { - if (!m_isConnected) + if (!m_isConnected) { + if (m_sendPort) { + mach_port_deallocate(mach_task_self(), m_sendPort); + m_sendPort = MACH_PORT_NULL; + } + + if (m_receivePort) { + mach_port_mod_refs(mach_task_self(), m_receivePort, MACH_PORT_RIGHT_RECEIVE, -1); + m_receivePort = MACH_PORT_NULL; + } + return; + } m_isConnected = false; @@ -138,8 +149,6 @@ void Connection::platformInvalidate() m_exceptionPort = MACH_PORT_NULL; } #endif - - m_xpcConnection = nullptr; } void Connection::terminateSoon(double intervalInSeconds) diff --git a/Source/WebKit2/Platform/IPC/win/AttachmentWin.cpp b/Source/WebKit2/Platform/IPC/win/AttachmentWin.cpp new file mode 100644 index 000000000..a81b22623 --- /dev/null +++ b/Source/WebKit2/Platform/IPC/win/AttachmentWin.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * Copyright (C) 2017 Konstantin Tokarev <annulen@yandex.ru> + * + * 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. + */ + +#include "config.h" +#include "Attachment.h" + +#include "ArgumentDecoder.h" +#include "ArgumentEncoder.h" + +// FIXME: This code is duplicated with SharedMemory::Handle implementation for Win + +namespace IPC { + +void Attachment::encode(ArgumentEncoder& encoder) const +{ + // Hand off ownership of our HANDLE to the receiving process. It will close it for us. + // FIXME: If the receiving process crashes before it receives the memory, the memory will be + // leaked. See <http://webkit.org/b/47502>. + encoder << reinterpret_cast<uint64_t>(m_handle); + + // Send along our PID so that the receiving process can duplicate the HANDLE for its own use. + encoder << static_cast<uint32_t>(::GetCurrentProcessId()); +} + +static bool getDuplicatedHandle(HANDLE sourceHandle, DWORD sourcePID, HANDLE& duplicatedHandle) +{ + duplicatedHandle = 0; + if (!sourceHandle) + return true; + + HANDLE sourceProcess = ::OpenProcess(PROCESS_DUP_HANDLE, FALSE, sourcePID); + if (!sourceProcess) + return false; + + // Copy the handle into our process and close the handle that the sending process created for us. + BOOL success = ::DuplicateHandle(sourceProcess, sourceHandle, ::GetCurrentProcess(), &duplicatedHandle, 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE); + ASSERT_WITH_MESSAGE(success, "::DuplicateHandle failed with error %lu", ::GetLastError()); + + ::CloseHandle(sourceProcess); + + return success; +} + +bool Attachment::decode(ArgumentDecoder& decoder, Attachment& attachment) +{ + ASSERT_ARG(attachment, !attachment.m_handle); + + uint64_t sourceHandle; + if (!decoder.decode(sourceHandle)) + return false; + + uint32_t sourcePID; + if (!decoder.decode(sourcePID)) + return false; + + HANDLE duplicatedHandle; + if (!getDuplicatedHandle(reinterpret_cast<HANDLE>(sourceHandle), sourcePID, duplicatedHandle)) + return false; + + attachment.m_handle = duplicatedHandle; + return true; +} + +} // namespace IPC diff --git a/Source/WebKit2/Platform/IPC/win/ConnectionWin.cpp b/Source/WebKit2/Platform/IPC/win/ConnectionWin.cpp index a2730ca69..7ea5ba0f5 100644 --- a/Source/WebKit2/Platform/IPC/win/ConnectionWin.cpp +++ b/Source/WebKit2/Platform/IPC/win/ConnectionWin.cpp @@ -27,7 +27,6 @@ #include "Connection.h" #include "DataReference.h" -#include <wtf/Functional.h> #include <wtf/RandomNumber.h> #include <wtf/text/WTFString.h> #include <wtf/threads/BinarySemaphore.h> @@ -161,8 +160,8 @@ void Connection::readEventHandler() if (!m_readBuffer.isEmpty()) { // We have a message, let's dispatch it. - OwnPtr<MessageDecoder> decoder = MessageDecoder::create(DataReference(m_readBuffer.data(), m_readBuffer.size())); - processIncomingMessage(decoder.release()); + auto decoder = std::make_unique<MessageDecoder>(DataReference(m_readBuffer.data(), m_readBuffer.size()), Vector<Attachment>()); + processIncomingMessage(WTFMove(decoder)); } // Find out the size of the next message in the pipe (if there is one) so that we can read @@ -250,12 +249,21 @@ bool Connection::open() // We connected the two ends of the pipe in createServerAndClientIdentifiers. m_isConnected = true; + RefPtr<Connection> protectedThis(this); + // Start listening for read and write state events. - m_connectionQueue->registerHandle(m_readState.hEvent, bind(&Connection::readEventHandler, this)); - m_connectionQueue->registerHandle(m_writeState.hEvent, bind(&Connection::writeEventHandler, this)); + m_connectionQueue->registerHandle(m_readState.hEvent, [protectedThis] { + protectedThis->readEventHandler(); + }); + + m_connectionQueue->registerHandle(m_writeState.hEvent, [protectedThis] { + protectedThis->writeEventHandler(); + }); // Schedule a read. - m_connectionQueue->dispatch(bind(&Connection::readEventHandler, this)); + m_connectionQueue->dispatch([protectedThis] { + protectedThis->readEventHandler(); + }); return true; } @@ -268,7 +276,7 @@ bool Connection::platformCanSendOutgoingMessages() const return !m_pendingWriteEncoder; } -bool Connection::sendOutgoingMessage(PassOwnPtr<MessageEncoder> encoder) +bool Connection::sendOutgoingMessage(std::unique_ptr<MessageEncoder> encoder) { ASSERT(!m_pendingWriteEncoder); @@ -301,7 +309,7 @@ bool Connection::sendOutgoingMessage(PassOwnPtr<MessageEncoder> encoder) // The message will be sent soon. Hold onto the encoder so that it won't be destroyed // before the write completes. - m_pendingWriteEncoder = encoder; + m_pendingWriteEncoder = WTFMove(encoder); // We can only send one asynchronous message at a time (see comment in platformCanSendOutgoingMessages). return false; @@ -348,4 +356,14 @@ bool Connection::dispatchSentMessagesUntil(const Vector<HWND>& windows, WTF::Bin } } +void Connection::willSendSyncMessage(unsigned flags) +{ + UNUSED_PARAM(flags); +} + +void Connection::didReceiveSyncReply(unsigned flags) +{ + UNUSED_PARAM(flags); +} + } // namespace IPC diff --git a/Source/WebKit2/Platform/SharedMemory.h b/Source/WebKit2/Platform/SharedMemory.h index 165ecfae5..4174e5cfb 100644 --- a/Source/WebKit2/Platform/SharedMemory.h +++ b/Source/WebKit2/Platform/SharedMemory.h @@ -82,6 +82,7 @@ public: size_t m_size; #elif OS(WINDOWS) mutable HANDLE m_handle; + size_t m_size; #endif }; @@ -93,7 +94,7 @@ public: #endif #if OS(WINDOWS) - static PassRefPtr<SharedMemory> adopt(HANDLE, size_t, Protection); + static RefPtr<SharedMemory> adopt(HANDLE, size_t, Protection); #endif ~SharedMemory(); diff --git a/Source/WebKit2/Platform/win/SharedMemoryWin.cpp b/Source/WebKit2/Platform/win/SharedMemoryWin.cpp index acf37be83..dff1339ef 100644 --- a/Source/WebKit2/Platform/win/SharedMemoryWin.cpp +++ b/Source/WebKit2/Platform/win/SharedMemoryWin.cpp @@ -40,6 +40,11 @@ SharedMemory::Handle::Handle() SharedMemory::Handle::~Handle() { + clear(); +} + +void SharedMemory::Handle::clear() +{ if (!m_handle) return; @@ -110,16 +115,16 @@ bool SharedMemory::Handle::decode(IPC::ArgumentDecoder& decoder, Handle& handle) return true; } -PassRefPtr<SharedMemory> SharedMemory::create(size_t size) +RefPtr<SharedMemory> SharedMemory::allocate(size_t size) { HANDLE handle = ::CreateFileMappingW(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, 0); if (!handle) - return 0; + return nullptr; void* baseAddress = ::MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, size); if (!baseAddress) { ::CloseHandle(handle); - return 0; + return nullptr; } RefPtr<SharedMemory> memory = adoptRef(new SharedMemory); @@ -127,15 +132,15 @@ PassRefPtr<SharedMemory> SharedMemory::create(size_t size) memory->m_data = baseAddress; memory->m_handle = handle; - return memory.release(); + return memory; } static DWORD accessRights(SharedMemory::Protection protection) { switch (protection) { - case SharedMemory::ReadOnly: + case SharedMemory::Protection::ReadOnly: return FILE_MAP_READ; - case SharedMemory::ReadWrite: + case SharedMemory::Protection::ReadWrite: return FILE_MAP_READ | FILE_MAP_WRITE; } @@ -143,36 +148,36 @@ static DWORD accessRights(SharedMemory::Protection protection) return 0; } -PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection protection) +RefPtr<SharedMemory> SharedMemory::map(const Handle& handle, Protection protection) { RefPtr<SharedMemory> memory = adopt(handle.m_handle, handle.m_size, protection); if (!memory) - return 0; + return nullptr; // The SharedMemory object now owns the HANDLE. handle.m_handle = 0; - return memory.release(); + return memory; } -PassRefPtr<SharedMemory> SharedMemory::adopt(HANDLE handle, size_t size, Protection protection) +RefPtr<SharedMemory> SharedMemory::adopt(HANDLE handle, size_t size, Protection protection) { if (!handle) - return 0; + return nullptr; DWORD desiredAccess = accessRights(protection); void* baseAddress = ::MapViewOfFile(handle, desiredAccess, 0, 0, size); ASSERT_WITH_MESSAGE(baseAddress, "::MapViewOfFile failed with error %lu", ::GetLastError()); if (!baseAddress) - return 0; + return nullptr; RefPtr<SharedMemory> memory = adoptRef(new SharedMemory); memory->m_size = size; memory->m_data = baseAddress; memory->m_handle = handle; - return memory.release(); + return memory; } SharedMemory::~SharedMemory() @@ -200,31 +205,6 @@ bool SharedMemory::createHandle(Handle& handle, Protection protection) return true; } -PassRefPtr<SharedMemory> SharedMemory::createCopyOnWriteCopy(size_t size) const -{ - ASSERT_ARG(size, size <= this->size()); - - HANDLE duplicatedHandle; - BOOL result = ::DuplicateHandle(::GetCurrentProcess(), m_handle, ::GetCurrentProcess(), &duplicatedHandle, 0, FALSE, DUPLICATE_SAME_ACCESS); - ASSERT_WITH_MESSAGE(result, "::DuplicateHandle failed with error %lu", ::GetLastError()); - if (!result) - return 0; - - void* newMapping = ::MapViewOfFile(duplicatedHandle, FILE_MAP_COPY, 0, 0, size); - ASSERT_WITH_MESSAGE(newMapping, "::MapViewOfFile failed with error %lu", ::GetLastError()); - if (!newMapping) { - ::CloseHandle(duplicatedHandle); - return 0; - } - - RefPtr<SharedMemory> memory = adoptRef(new SharedMemory); - memory->m_size = size; - memory->m_data = newMapping; - memory->m_handle = duplicatedHandle; - - return memory.release(); -} - unsigned SharedMemory::systemPageSize() { static unsigned pageSize = 0; |