Skip to content

Commit

Permalink
Make SharedMemoryHandle non-copyable
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=256539

Reviewed by Kimmo Kinnunen.

Add `WTF_MAKE_NONCOPYABLE` to `SharedMemoryHandle`. Enumerate
constructors for the class.

Move common implementation of `SharedMemoryHandle` into common .cpp.

* Source/WebKit/Platform/SharedMemory.cpp:
(WebKit::SharedMemoryHandle::SharedMemoryHandle):
(WebKit::SharedMemoryHandle::isNull const):
* Source/WebKit/Platform/SharedMemory.h:
* Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp:
(WebKit::SharedMemoryHandle::isNull const): Deleted.
* Source/WebKit/Platform/unix/SharedMemoryUnix.cpp:
(WebKit::SharedMemoryHandle::isNull const): Deleted.
* Source/WebKit/Platform/win/SharedMemoryWin.cpp:
(WebKit::SharedMemoryHandle::isNull const): Deleted.
* Source/WebKit/Shared/IPCStreamTester.cpp:
(WebKit::IPCStreamTester::syncMessageReturningSharedMemory1):
* Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp:
(WebKit::IPCTestingAPI::JSSharedMemory::createHandle):

Canonical link: https://commits.webkit.org/263897@main
  • Loading branch information
donny-dont committed May 10, 2023
1 parent 5fae846 commit 00afd6a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
11 changes: 11 additions & 0 deletions Source/WebKit/Platform/SharedMemory.cpp
Expand Up @@ -33,6 +33,17 @@ namespace WebKit {

using namespace WebCore;

SharedMemoryHandle::SharedMemoryHandle(SharedMemoryHandle::Type&& handle, size_t size)
: m_handle(WTFMove(handle))
, m_size(size)
{
}

bool SharedMemoryHandle::isNull() const
{
return !m_handle;
}

RefPtr<SharedMemory> SharedMemory::copyBuffer(const FragmentedSharedBuffer& buffer)
{
if (buffer.isEmpty())
Expand Down
7 changes: 7 additions & 0 deletions Source/WebKit/Platform/SharedMemory.h
Expand Up @@ -60,6 +60,7 @@ namespace WebKit {
enum class MemoryLedger { None, Default, Network, Media, Graphics, Neural };

class SharedMemoryHandle {
WTF_MAKE_NONCOPYABLE(SharedMemoryHandle);
public:
using Type =
#if USE(UNIX_DOMAIN_SOCKETS)
Expand All @@ -70,6 +71,12 @@ class SharedMemoryHandle {
Win32Handle;
#endif

SharedMemoryHandle() = default;
SharedMemoryHandle(SharedMemoryHandle&&) = default;
SharedMemoryHandle(SharedMemoryHandle::Type&&, size_t);

SharedMemoryHandle& operator=(SharedMemoryHandle&&) = default;

bool isNull() const;

size_t size() const { return m_size; }
Expand Down
5 changes: 0 additions & 5 deletions Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp
Expand Up @@ -91,11 +91,6 @@ void SharedMemoryHandle::setOwnershipOfMemory(const WebCore::ProcessIdentity& pr
#endif
}

bool SharedMemoryHandle::isNull() const
{
return !m_handle;
}

static inline void* toPointer(mach_vm_address_t address)
{
return reinterpret_cast<void*>(static_cast<uintptr_t>(address));
Expand Down
5 changes: 0 additions & 5 deletions Source/WebKit/Platform/unix/SharedMemoryUnix.cpp
Expand Up @@ -52,11 +52,6 @@

namespace WebKit {

bool SharedMemoryHandle::isNull() const
{
return !m_handle;
}

UnixFileDescriptor SharedMemoryHandle::releaseHandle()
{
return WTFMove(m_handle);
Expand Down
5 changes: 0 additions & 5 deletions Source/WebKit/Platform/win/SharedMemoryWin.cpp
Expand Up @@ -31,11 +31,6 @@

namespace WebKit {

bool SharedMemoryHandle::isNull() const
{
return !m_handle;
}

RefPtr<SharedMemory> SharedMemory::allocate(size_t size)
{
Win32Handle handle { ::CreateFileMappingW(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, 0) };
Expand Down
6 changes: 3 additions & 3 deletions Source/WebKit/Shared/IPCStreamTester.cpp
Expand Up @@ -26,15 +26,15 @@
#include "config.h"
#include "IPCStreamTester.h"

#include <wtf/WTFProcess.h>

#if ENABLE(IPC_TESTING_API)

#include "Decoder.h"
#include "IPCStreamTesterMessages.h"
#include "IPCStreamTesterProxyMessages.h"
#include "IPCUtilities.h"
#include "StreamConnectionWorkQueue.h"
#include "StreamServerConnection.h"
#include <wtf/WTFProcess.h>

#if USE(FOUNDATION)
#include <CoreFoundation/CoreFoundation.h>
Expand Down Expand Up @@ -86,7 +86,7 @@ void IPCStreamTester::syncMessageReturningSharedMemory1(uint32_t byteCount, Comp
uint8_t* data = static_cast<uint8_t*>(sharedMemory->data());
for (size_t i = 0; i < sharedMemory->size(); ++i)
data[i] = i;
return *handle;
return WTFMove(*handle);
}();
completionHandler(WTFMove(result));
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp
Expand Up @@ -1342,7 +1342,7 @@ JSValueRef JSIPCSemaphore::waitFor(JSContextRef context, JSObjectRef, JSObjectRe
SharedMemory::Handle JSSharedMemory::createHandle(SharedMemory::Protection protection)
{
if (auto handle = m_sharedMemory->createHandle(protection))
return *handle;
return WTFMove(*handle);
return { };
}

Expand Down

0 comments on commit 00afd6a

Please sign in to comment.