Diff
Modified: trunk/Source/WTF/wtf/cocoa/MachSendRight.cpp (295665 => 295666)
--- trunk/Source/WTF/wtf/cocoa/MachSendRight.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WTF/wtf/cocoa/MachSendRight.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -72,8 +72,26 @@
CRASH();
}
+static void assertSendRight(mach_port_t port)
+{
+ if (port == MACH_PORT_NULL)
+ return;
+
+ unsigned count = 0;
+ auto kr = mach_port_get_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, &count);
+ if (kr == KERN_SUCCESS && !count)
+ kr = mach_port_get_refs(mach_task_self(), port, MACH_PORT_RIGHT_DEAD_NAME, &count);
+
+ if (kr == KERN_SUCCESS && count > 0)
+ return;
+
+ RELEASE_LOG_ERROR(Process, "mach_port_get_refs error for port %d: %{private}s (%#x)", port, mach_error_string(kr), kr);
+ CRASH();
+}
+
MachSendRight MachSendRight::adopt(mach_port_t port)
{
+ assertSendRight(port);
return MachSendRight(port);
}
@@ -118,6 +136,7 @@
MachSendRight& MachSendRight::operator=(const MachSendRight& other)
{
if (this != &other) {
+ releaseSendRight(m_port);
m_port = other.sendRight();
retainSendRight(m_port);
}
Modified: trunk/Source/WebKit/GPUProcess/GPUProcess.cpp (295665 => 295666)
--- trunk/Source/WebKit/GPUProcess/GPUProcess.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/GPUProcess/GPUProcess.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -121,7 +121,7 @@
#if USE(UNIX_DOMAIN_SOCKETS)
return IPC::Connection::Identifier { connectionHandle.release().release() };
#elif OS(DARWIN)
- return IPC::Connection::Identifier { connectionHandle.port() };
+ return IPC::Connection::Identifier { connectionHandle.leakSendRight() };
#elif OS(WINDOWS)
return IPC::Connection::Identifier { connectionHandle.handle() };
#else
Modified: trunk/Source/WebKit/Platform/IPC/Attachment.cpp (295665 => 295666)
--- trunk/Source/WebKit/Platform/IPC/Attachment.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Platform/IPC/Attachment.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -37,16 +37,16 @@
}
#if OS(DARWIN) && !USE(UNIX_DOMAIN_SOCKETS)
-Attachment::Attachment(mach_port_name_t port, mach_msg_type_name_t disposition)
- : m_type(MachPortType)
- , m_port(port)
- , m_disposition(disposition)
+Attachment::Attachment(MachSendRight&& right)
+ : MachSendRight(WTFMove(right))
+ , m_type(MachPortType)
{
}
-void Attachment::release()
+Attachment::Attachment(const MachSendRight& right)
+ : MachSendRight(right)
+ , m_type(MachPortType)
{
- m_type = Uninitialized;
}
#endif
Modified: trunk/Source/WebKit/Platform/IPC/Attachment.h (295665 => 295666)
--- trunk/Source/WebKit/Platform/IPC/Attachment.h 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Platform/IPC/Attachment.h 2022-06-20 04:25:46 UTC (rev 295666)
@@ -31,6 +31,7 @@
#if OS(DARWIN) && !USE(UNIX_DOMAIN_SOCKETS)
#include <mach/mach_init.h>
#include <mach/mach_traps.h>
+#include <wtf/MachSendRight.h>
#endif
#if OS(WINDOWS)
@@ -48,7 +49,11 @@
class Decoder;
class Encoder;
+#if OS(DARWIN)
+class Attachment : public MachSendRight {
+#else
class Attachment {
+#endif
public:
Attachment();
@@ -76,7 +81,8 @@
using CustomWriter = std::variant<CustomWriterFunc, SocketDescriptor>;
Attachment(CustomWriter&&);
#elif OS(DARWIN)
- Attachment(mach_port_name_t, mach_msg_type_name_t disposition);
+ Attachment(MachSendRight&&);
+ Attachment(const MachSendRight&);
#elif OS(WINDOWS)
Attachment(HANDLE handle)
: m_handle(handle)
@@ -93,12 +99,6 @@
UnixFileDescriptor release() { return std::exchange(m_fd, UnixFileDescriptor { }); }
const CustomWriter& customWriter() const { return m_customWriter; }
-#elif OS(DARWIN)
- void release();
-
- // 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
@@ -113,9 +113,6 @@
UnixFileDescriptor m_fd;
size_t m_size;
CustomWriter m_customWriter;
-#elif OS(DARWIN)
- mach_port_name_t m_port { 0 };
- mach_msg_type_name_t m_disposition { 0 };
#elif OS(WINDOWS)
HANDLE m_handle { INVALID_HANDLE_VALUE };
#endif
Modified: trunk/Source/WebKit/Platform/IPC/StreamServerConnection.cpp (295665 => 295666)
--- trunk/Source/WebKit/Platform/IPC/StreamServerConnection.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Platform/IPC/StreamServerConnection.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -58,7 +58,7 @@
#if USE(UNIX_DOMAIN_SOCKETS)
IPC::Connection::Identifier connectionHandle { connectionIdentifier.release().release() };
#elif OS(DARWIN)
- IPC::Connection::Identifier connectionHandle { connectionIdentifier.port() };
+ IPC::Connection::Identifier connectionHandle { connectionIdentifier.leakSendRight() };
#elif OS(WINDOWS)
IPC::Connection::Identifier connectionHandle { connectionIdentifier.handle() };
#else
Modified: trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm (295665 => 295666)
--- trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm 2022-06-20 04:25:46 UTC (rev 295666)
@@ -31,7 +31,6 @@
#import "ImportanceAssertion.h"
#import "Logging.h"
#import "MachMessage.h"
-#import "MachPort.h"
#import "MachUtilities.h"
#import "ReasonSPI.h"
#import "WKCrashReporter.h"
@@ -217,8 +216,11 @@
// Send the initialize message, which contains a send right for the server to use.
auto encoder = makeUniqueRef<Encoder>(MessageName::InitializeConnection, 0);
- encoder.get() << MachPort(m_receivePort, MACH_MSG_TYPE_MAKE_SEND);
+ mach_port_insert_right(mach_task_self(), m_receivePort, m_receivePort, MACH_MSG_TYPE_MAKE_SEND);
+ MachSendRight right = MachSendRight::adopt(m_receivePort);
+ encoder.get() << Attachment { WTFMove(right) };
+
initializeSendSource();
sendMessage(WTFMove(encoder), { });
@@ -338,8 +340,8 @@
ASSERT(attachment.type() == Attachment::MachPortType);
if (attachment.type() == Attachment::MachPortType) {
auto* descriptor = getDescriptorAndAdvance(messageData, sizeof(mach_msg_port_descriptor_t));
- descriptor->port.name = attachment.port();
- descriptor->port.disposition = attachment.disposition();
+ descriptor->port.name = attachment.leakSendRight();
+ descriptor->port.disposition = MACH_MSG_TYPE_MOVE_SEND;
descriptor->port.type = MACH_MSG_PORT_DESCRIPTOR;
}
}
@@ -459,8 +461,10 @@
ASSERT(descriptor->type.type == MACH_MSG_PORT_DESCRIPTOR);
if (descriptor->type.type != MACH_MSG_PORT_DESCRIPTOR)
return nullptr;
+ ASSERT(descriptor->port.disposition == MACH_MSG_TYPE_PORT_SEND);
+ MachSendRight right = MachSendRight::adopt(descriptor->port.name);
- attachments[numberOfAttachments - i - 1] = Attachment { descriptor->port.name, descriptor->port.disposition };
+ attachments[numberOfAttachments - i - 1] = Attachment { WTFMove(right) };
descriptorData += sizeof(mach_msg_port_descriptor_t);
}
@@ -569,13 +573,13 @@
return;
}
- MachPort port;
- if (!decoder->decode(port)) {
+ Attachment attachment;
+ if (!decoder->decode(attachment)) {
// FIXME: Disconnect.
return;
}
- m_sendPort = port.port();
+ m_sendPort = attachment.leakSendRight();
if (m_sendPort) {
ASSERT(MACH_PORT_VALID(m_receivePort));
@@ -676,6 +680,9 @@
RELEASE_LOG_ERROR(Process, "Connection::createConnectionIdentifierPair: Could not allocate mach port, returned port was invalid");
return std::nullopt;
}
- return ConnectionIdentifierPair { Connection::Identifier { listeningPort }, Attachment { listeningPort, MACH_MSG_TYPE_MAKE_SEND } };
+ mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND);
+ MachSendRight right = MachSendRight::adopt(listeningPort);
+
+ return ConnectionIdentifierPair { Connection::Identifier { listeningPort }, Attachment { WTFMove(right) } };
}
} // namespace IPC
Deleted: trunk/Source/WebKit/Platform/IPC/cocoa/MachPort.h (295665 => 295666)
--- trunk/Source/WebKit/Platform/IPC/cocoa/MachPort.h 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Platform/IPC/cocoa/MachPort.h 2022-06-20 04:25:46 UTC (rev 295666)
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2010 Apple Inc. 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 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.
- */
-
-#pragma once
-
-#include "ArgumentCoder.h"
-#include "Attachment.h"
-
-namespace IPC {
-
-class MachPort {
-public:
- MachPort()
- : m_port(MACH_PORT_NULL)
- , m_disposition(0)
- {
- }
-
- MachPort(mach_port_name_t port, mach_msg_type_name_t disposition)
- : m_port(port)
- , m_disposition(disposition)
- {
- }
-
- void encode(Encoder& encoder) const
- {
- encoder << Attachment(m_port, m_disposition);
- }
-
- static WARN_UNUSED_RETURN bool decode(Decoder& decoder, MachPort& p)
- {
- Attachment attachment;
- if (!decoder.decode(attachment))
- return false;
-
- p.m_port = attachment.port();
- p.m_disposition = attachment.disposition();
- return true;
- }
-
- mach_port_name_t port() const { return m_port; }
- mach_msg_type_name_t disposition() const { return m_disposition; }
-
-private:
- mach_port_name_t m_port;
- mach_msg_type_name_t m_disposition;
-};
-
-} // namespace IPC
Modified: trunk/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp (295665 => 295666)
--- trunk/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -24,9 +24,14 @@
*/
#include "config.h"
+#include "ArgumentCoders.h"
+#include "Attachment.h"
+#include "Decoder.h"
+#include "Encoder.h"
#include "SharedFileHandle.h"
+#include "WebCoreArgumentCoders.h"
+#include <wtf/MachSendRight.h>
-#include "MachPort.h"
#include <pal/spi/cocoa/FilePortSPI.h>
namespace IPC {
@@ -40,20 +45,19 @@
{
mach_port_name_t fileport = MACH_PORT_NULL;
if (fileport_makeport(m_handle.handle(), &fileport) == -1) {
- encoder << MachPort();
return;
}
- encoder << MachPort(fileport, MACH_MSG_TYPE_MOVE_SEND);
+ encoder << MachSendRight::adopt(fileport);
}
std::optional<SharedFileHandle> SharedFileHandle::decode(Decoder& decoder)
{
- MachPort machPort;
- if (!decoder.decode(machPort))
+ auto fileport = decoder.decode<MachSendRight>();
+ if (UNLIKELY(!decoder.isValid()))
return std::nullopt;
- int fd = fileport_makefd(machPort.port());
+ int fd = fileport_makefd(fileport->sendRight());
if (fd == -1)
return SharedFileHandle { };
Modified: trunk/Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp (295665 => 295666)
--- trunk/Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Platform/cocoa/SharedMemoryCocoa.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -28,7 +28,6 @@
#include "ArgumentCoders.h"
#include "Logging.h"
-#include "MachPort.h"
#include <WebCore/SharedBuffer.h>
#include <mach/mach_error.h>
#include <mach/mach_port.h>
@@ -128,7 +127,7 @@
{
encoder << static_cast<uint64_t>(handle.m_size);
encoder << dataSize;
- encoder << IPC::MachPort(handle.m_port, MACH_MSG_TYPE_MOVE_SEND);
+ encoder << MachSendRight::adopt(handle.m_port);
handle.m_port = MACH_PORT_NULL;
}
@@ -151,12 +150,12 @@
if (dataLength > bufferSize)
return false;
- IPC::MachPort machPort;
- if (!decoder.decode(machPort))
+ auto sendRight = decoder.decode<MachSendRight>();
+ if (UNLIKELY(!decoder.isValid()))
return false;
handle.m_size = bufferSize;
- handle.m_port = machPort.port();
+ handle.m_port = sendRight->leakSendRight();
ipcHandle.handle = WTFMove(handle);
ipcHandle.dataSize = dataLength;
return true;
Modified: trunk/Source/WebKit/Scripts/webkit/parser_unittest.py (295665 => 295666)
--- trunk/Source/WebKit/Scripts/webkit/parser_unittest.py 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Scripts/webkit/parser_unittest.py 2022-06-20 04:25:46 UTC (rev 295666)
@@ -191,7 +191,7 @@
{
'name': 'DidCreateWebProcessConnection',
'parameters': (
- ('IPC::MachPort', 'connectionIdentifier'),
+ ('MachSendRight', 'connectionIdentifier'),
('OptionSet<WebKit::SelectionFlags>', 'flags'),
),
'conditions': ('PLATFORM(MAC)'),
Modified: trunk/Source/WebKit/Scripts/webkit/tests/MessageArgumentDescriptions.cpp (295665 => 295666)
--- trunk/Source/WebKit/Scripts/webkit/tests/MessageArgumentDescriptions.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Scripts/webkit/tests/MessageArgumentDescriptions.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -417,7 +417,7 @@
#if PLATFORM(MAC)
case MessageName::TestWithLegacyReceiver_DidCreateWebProcessConnection:
return Vector<ArgumentDescription> {
- { "connectionIdentifier", "IPC::MachPort", nullptr, false },
+ { "connectionIdentifier", "MachSendRight", nullptr, false },
{ "flags", "OptionSet<WebKit::SelectionFlags>", nullptr, false },
};
case MessageName::TestWithLegacyReceiver_InterpretKeyEvent:
@@ -526,7 +526,7 @@
#if PLATFORM(MAC)
case MessageName::TestWithoutAttributes_DidCreateWebProcessConnection:
return Vector<ArgumentDescription> {
- { "connectionIdentifier", "IPC::MachPort", nullptr, false },
+ { "connectionIdentifier", "MachSendRight", nullptr, false },
{ "flags", "OptionSet<WebKit::SelectionFlags>", nullptr, false },
};
case MessageName::TestWithoutAttributes_InterpretKeyEvent:
Modified: trunk/Source/WebKit/Scripts/webkit/tests/TestWithLegacyReceiver.messages.in (295665 => 295666)
--- trunk/Source/WebKit/Scripts/webkit/tests/TestWithLegacyReceiver.messages.in 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Scripts/webkit/tests/TestWithLegacyReceiver.messages.in 2022-06-20 04:25:46 UTC (rev 295666)
@@ -56,7 +56,7 @@
SetVideoLayerID(WebCore::GraphicsLayer::PlatformLayerID videoLayerID)
#if PLATFORM(MAC)
- DidCreateWebProcessConnection(IPC::MachPort connectionIdentifier, OptionSet<WebKit::SelectionFlags> flags)
+ DidCreateWebProcessConnection(MachSendRight connectionIdentifier, OptionSet<WebKit::SelectionFlags> flags)
#endif
#if PLATFORM(MAC)
Modified: trunk/Source/WebKit/Scripts/webkit/tests/TestWithLegacyReceiverMessageReceiver.cpp (295665 => 295666)
--- trunk/Source/WebKit/Scripts/webkit/tests/TestWithLegacyReceiverMessageReceiver.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Scripts/webkit/tests/TestWithLegacyReceiverMessageReceiver.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -36,9 +36,6 @@
#include "GestureTypes.h"
#endif
#include "HandleMessage.h"
-#if PLATFORM(MAC)
-#include "MachPort.h"
-#endif
#include "Plugin.h"
#include "TestWithLegacyReceiverMessages.h"
#include "WebCoreArgumentCoders.h"
@@ -54,6 +51,9 @@
#include <utility>
#include <wtf/HashMap.h>
#if PLATFORM(MAC)
+#include <wtf/MachSendRight.h>
+#endif
+#if PLATFORM(MAC)
#include <wtf/OptionSet.h>
#endif
#include <wtf/Vector.h>
Modified: trunk/Source/WebKit/Scripts/webkit/tests/TestWithLegacyReceiverMessages.h (295665 => 295666)
--- trunk/Source/WebKit/Scripts/webkit/tests/TestWithLegacyReceiverMessages.h 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Scripts/webkit/tests/TestWithLegacyReceiverMessages.h 2022-06-20 04:25:46 UTC (rev 295666)
@@ -40,6 +40,7 @@
#include <utility>
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
+#include <wtf/MachSendRight.h>
#include <wtf/OptionSet.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/Vector.h>
@@ -47,7 +48,6 @@
namespace IPC {
class DummyType;
-class MachPort;
}
namespace WebKit {
@@ -471,12 +471,12 @@
#if PLATFORM(MAC)
class DidCreateWebProcessConnection {
public:
- using Arguments = std::tuple<const IPC::MachPort&, const OptionSet<WebKit::SelectionFlags>&>;
+ using Arguments = std::tuple<const MachSendRight&, const OptionSet<WebKit::SelectionFlags>&>;
static IPC::MessageName name() { return IPC::MessageName::TestWithLegacyReceiver_DidCreateWebProcessConnection; }
static constexpr bool isSync = false;
- DidCreateWebProcessConnection(const IPC::MachPort& connectionIdentifier, const OptionSet<WebKit::SelectionFlags>& flags)
+ DidCreateWebProcessConnection(const MachSendRight& connectionIdentifier, const OptionSet<WebKit::SelectionFlags>& flags)
: m_arguments(connectionIdentifier, flags)
{
}
Modified: trunk/Source/WebKit/Scripts/webkit/tests/TestWithoutAttributes.messages.in (295665 => 295666)
--- trunk/Source/WebKit/Scripts/webkit/tests/TestWithoutAttributes.messages.in 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Scripts/webkit/tests/TestWithoutAttributes.messages.in 2022-06-20 04:25:46 UTC (rev 295666)
@@ -63,7 +63,7 @@
SetVideoLayerID(WebCore::GraphicsLayer::PlatformLayerID videoLayerID)
#if PLATFORM(MAC)
- DidCreateWebProcessConnection(IPC::MachPort connectionIdentifier, OptionSet<WebKit::SelectionFlags> flags)
+ DidCreateWebProcessConnection(MachSendRight connectionIdentifier, OptionSet<WebKit::SelectionFlags> flags)
#endif
#if PLATFORM(MAC)
Modified: trunk/Source/WebKit/Scripts/webkit/tests/TestWithoutAttributesMessageReceiver.cpp (295665 => 295666)
--- trunk/Source/WebKit/Scripts/webkit/tests/TestWithoutAttributesMessageReceiver.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Scripts/webkit/tests/TestWithoutAttributesMessageReceiver.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -36,9 +36,6 @@
#include "GestureTypes.h"
#endif
#include "HandleMessage.h"
-#if PLATFORM(MAC)
-#include "MachPort.h"
-#endif
#include "Plugin.h"
#include "TestWithoutAttributesMessages.h"
#include "WebCoreArgumentCoders.h"
@@ -54,6 +51,9 @@
#include <utility>
#include <wtf/HashMap.h>
#if PLATFORM(MAC)
+#include <wtf/MachSendRight.h>
+#endif
+#if PLATFORM(MAC)
#include <wtf/OptionSet.h>
#endif
#include <wtf/Vector.h>
Modified: trunk/Source/WebKit/Scripts/webkit/tests/TestWithoutAttributesMessages.h (295665 => 295666)
--- trunk/Source/WebKit/Scripts/webkit/tests/TestWithoutAttributesMessages.h 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Scripts/webkit/tests/TestWithoutAttributesMessages.h 2022-06-20 04:25:46 UTC (rev 295666)
@@ -40,6 +40,7 @@
#include <utility>
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
+#include <wtf/MachSendRight.h>
#include <wtf/OptionSet.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/Vector.h>
@@ -47,7 +48,6 @@
namespace IPC {
class DummyType;
-class MachPort;
}
namespace WebKit {
@@ -471,12 +471,12 @@
#if PLATFORM(MAC)
class DidCreateWebProcessConnection {
public:
- using Arguments = std::tuple<const IPC::MachPort&, const OptionSet<WebKit::SelectionFlags>&>;
+ using Arguments = std::tuple<const MachSendRight&, const OptionSet<WebKit::SelectionFlags>&>;
static IPC::MessageName name() { return IPC::MessageName::TestWithoutAttributes_DidCreateWebProcessConnection; }
static constexpr bool isSync = false;
- DidCreateWebProcessConnection(const IPC::MachPort& connectionIdentifier, const OptionSet<WebKit::SelectionFlags>& flags)
+ DidCreateWebProcessConnection(const MachSendRight& connectionIdentifier, const OptionSet<WebKit::SelectionFlags>& flags)
: m_arguments(connectionIdentifier, flags)
{
}
Modified: trunk/Source/WebKit/Shared/IPCConnectionTester.cpp (295665 => 295666)
--- trunk/Source/WebKit/Shared/IPCConnectionTester.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Shared/IPCConnectionTester.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -38,7 +38,7 @@
#if USE(UNIX_DOMAIN_SOCKETS)
return { connectionIdentifier.release().release() };
#elif OS(DARWIN)
- return { connectionIdentifier.port() };
+ return { connectionIdentifier.leakSendRight() };
#elif OS(WINDOWS)
return { connectionIdentifier.handle() };
#else
Modified: trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm (295665 => 295666)
--- trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/Shared/mac/WebCoreArgumentCodersMac.mm 2022-06-20 04:25:46 UTC (rev 295666)
@@ -277,12 +277,12 @@
void ArgumentCoder<MachSendRight>::encode(Encoder& encoder, const MachSendRight& sendRight)
{
- encoder << Attachment(sendRight.copySendRight().leakSendRight(), MACH_MSG_TYPE_MOVE_SEND);
+ encoder << Attachment { sendRight };
}
void ArgumentCoder<MachSendRight>::encode(Encoder& encoder, MachSendRight&& sendRight)
{
- encoder << Attachment(sendRight.leakSendRight(), MACH_MSG_TYPE_MOVE_SEND);
+ encoder << Attachment { WTFMove(sendRight) };
}
bool ArgumentCoder<MachSendRight>::decode(Decoder& decoder, MachSendRight& sendRight)
@@ -291,10 +291,7 @@
if (!decoder.decode(attachment))
return false;
- if (attachment.disposition() != MACH_MSG_TYPE_MOVE_SEND)
- return false;
-
- sendRight = MachSendRight::adopt(attachment.port());
+ sendRight = WTFMove(attachment);
return true;
}
Modified: trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp (295665 => 295666)
--- trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/UIProcess/GPU/GPUProcessProxy.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -50,6 +50,7 @@
#include <WebCore/ScreenProperties.h>
#include <wtf/CompletionHandler.h>
#include <wtf/LogInitialization.h>
+#include <wtf/MachSendRight.h>
#include <wtf/TranslatedProcess.h>
#if PLATFORM(IOS_FAMILY)
Modified: trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp (295665 => 295666)
--- trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -309,8 +309,8 @@
reply(NetworkProcessConnectionInfo { WTFMove(*identifier), cookieAcceptPolicy });
UNUSED_VARIABLE(this);
#elif OS(DARWIN)
- MESSAGE_CHECK(MACH_PORT_VALID(identifier->port()));
- reply(NetworkProcessConnectionInfo { IPC::Attachment { identifier->port(), MACH_MSG_TYPE_MOVE_SEND }, cookieAcceptPolicy, connection()->getAuditToken() });
+ MESSAGE_CHECK(MACH_PORT_VALID(identifier->sendRight()));
+ reply(NetworkProcessConnectionInfo { WTFMove(*identifier) , cookieAcceptPolicy, connection()->getAuditToken() });
#else
notImplemented();
#endif
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (295665 => 295666)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2022-06-20 04:25:46 UTC (rev 295666)
@@ -1786,7 +1786,6 @@
BCBD3915125BB1A800D2C29F /* WebPageProxyMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = BCBD3913125BB1A800D2C29F /* WebPageProxyMessages.h */; };
BCBECDE816B6416800047A1A /* XPCServiceEntryPoint.h in Headers */ = {isa = PBXBuildFile; fileRef = BCBECDE616B6416700047A1A /* XPCServiceEntryPoint.h */; };
BCC43ABB127B95DC00317F16 /* PlatformPopupMenuData.h in Headers */ = {isa = PBXBuildFile; fileRef = BCC43AB9127B95DC00317F16 /* PlatformPopupMenuData.h */; };
- BCC56F791159957D001CCAF9 /* MachPort.h in Headers */ = {isa = PBXBuildFile; fileRef = BCC56F771159957D001CCAF9 /* MachPort.h */; };
BCC8B374125FB69000DE46A4 /* WKGeometry.h in Headers */ = {isa = PBXBuildFile; fileRef = BCC8B373125FB69000DE46A4 /* WKGeometry.h */; settings = {ATTRIBUTES = (Private, ); }; };
BCC938E11180DE440085E5FE /* WKContextPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = BCC938E01180DE440085E5FE /* WKContextPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
BCCF6ABD12C91EF9008F9C35 /* WebImage.h in Headers */ = {isa = PBXBuildFile; fileRef = BCCF6ABB12C91EF9008F9C35 /* WebImage.h */; };
@@ -6312,7 +6311,6 @@
BCC43AB8127B95DC00317F16 /* PlatformPopupMenuData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformPopupMenuData.cpp; sourceTree = "<group>"; };
BCC43AB9127B95DC00317F16 /* PlatformPopupMenuData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformPopupMenuData.h; sourceTree = "<group>"; };
BCC43AC6127B99DE00317F16 /* WebPopupMenuMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebPopupMenuMac.mm; sourceTree = "<group>"; };
- BCC56F771159957D001CCAF9 /* MachPort.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MachPort.h; sourceTree = "<group>"; };
BCC8B373125FB69000DE46A4 /* WKGeometry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKGeometry.h; sourceTree = "<group>"; };
BCC938E01180DE440085E5FE /* WKContextPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContextPrivate.h; sourceTree = "<group>"; };
BCCF6ABA12C91EF9008F9C35 /* WebImage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebImage.cpp; sourceTree = "<group>"; };
@@ -12434,7 +12432,6 @@
1A1EC69D1872092100B951F0 /* ImportanceAssertion.h */,
1A6D86BF1DF75265007745E8 /* MachMessage.cpp */,
1A6D86C01DF75265007745E8 /* MachMessage.h */,
- BCC56F771159957D001CCAF9 /* MachPort.h */,
93468E6C2714AF88009983E3 /* SharedFileHandleCocoa.cpp */,
);
path = cocoa;
@@ -14214,7 +14211,6 @@
51A7F2F3125BF820008AEB1D /* Logging.h in Headers */,
0FDCD7F71D47E92A009F08BC /* LogInitialization.h in Headers */,
1A6D86C21DF75265007745E8 /* MachMessage.h in Headers */,
- BCC56F791159957D001CCAF9 /* MachPort.h in Headers */,
1A24B5F311F531E800C38269 /* MachUtilities.h in Headers */,
462CD80C28204DFA00F0EA04 /* MarkSurfacesAsVolatileRequestIdentifier.h in Headers */,
A15799BE2584433200528236 /* MediaFormatReader.h in Headers */,
Modified: trunk/Source/WebKit/WebProcess/Inspector/WebInspector.cpp (295665 => 295666)
--- trunk/Source/WebKit/WebProcess/Inspector/WebInspector.cpp 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/WebProcess/Inspector/WebInspector.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -87,7 +87,7 @@
#if USE(UNIX_DOMAIN_SOCKETS)
IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.release().release());
#elif OS(DARWIN)
- IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.port());
+ IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.leakSendRight());
#elif OS(WINDOWS)
IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.handle());
#else
Modified: trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnectionInfo.h (295665 => 295666)
--- trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnectionInfo.h 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnectionInfo.h 2022-06-20 04:25:46 UTC (rev 295666)
@@ -42,7 +42,7 @@
#if USE(UNIX_DOMAIN_SOCKETS)
return IPC::Connection::Identifier(connection.fd().value());
#elif OS(DARWIN)
- return IPC::Connection::Identifier(connection.port());
+ return IPC::Connection::Identifier(connection.sendRight());
#elif OS(WINDOWS)
return IPC::Connection::Identifier(connection.handle());
#else
@@ -55,6 +55,8 @@
{
#if USE(UNIX_DOMAIN_SOCKETS)
auto returnValue = IPC::Connection::Identifier(connection.release().release());
+#elif OS(DARWIN)
+ auto returnValue = IPC::Connection::Identifier(connection.leakSendRight());
#else
auto returnValue = identifier();
#endif
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (295665 => 295666)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2022-06-20 03:57:23 UTC (rev 295665)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2022-06-20 04:25:46 UTC (rev 295666)
@@ -983,6 +983,7 @@
CEBCA13A1E3A807A00C73293 /* page-without-csp.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEBCA1371E3A803400C73293 /* page-without-csp.html */; };
CEBCA13B1E3A807A00C73293 /* page-without-csp-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEBCA1361E3A803400C73293 /* page-without-csp-iframe.html */; };
CEDA12412437C9FB00C28A9E /* editable-region-composited-and-non-composited-overlap.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEDA12402437C9EA00C28A9E /* editable-region-composited-and-non-composited-overlap.html */; };
+ D04CF93F285C77CA005D6337 /* MachSendRight.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D04CF93E285C77C9005D6337 /* MachSendRight.cpp */; };
DD0EDF8D2798A6AD005152AD /* libgtest.a in Product Dependencies */ = {isa = PBXBuildFile; fileRef = F3FC3EE213678B7300126A65 /* libgtest.a */; };
DD42949F284BE0B7004D49ED /* WebKit.framework in Product Dependencies */ = {isa = PBXBuildFile; fileRef = C081224813FC1B0300DC39AE /* WebKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
DDD2187627A21750002B7025 /* WebKit.framework in Product Dependencies */ = {isa = PBXBuildFile; fileRef = C081224813FC1B0300DC39AE /* WebKit.framework */; };
@@ -3002,6 +3003,7 @@
CEBCA1371E3A803400C73293 /* page-without-csp.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "page-without-csp.html"; sourceTree = "<group>"; };
CED73D35246F204C00DAE327 /* InsertTextAlternatives.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = InsertTextAlternatives.mm; sourceTree = "<group>"; };
CEDA12402437C9EA00C28A9E /* editable-region-composited-and-non-composited-overlap.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; name = "editable-region-composited-and-non-composited-overlap.html"; path = "ios/editable-region-composited-and-non-composited-overlap.html"; sourceTree = SOURCE_ROOT; };
+ D04CF93E285C77C9005D6337 /* MachSendRight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MachSendRight.cpp; sourceTree = "<group>"; };
D3BE5E341E4CE85E00FD563A /* WKWebViewGetContents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewGetContents.mm; sourceTree = "<group>"; };
DC69AA621CF77C6500C6272F /* ScopedLambda.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScopedLambda.cpp; sourceTree = "<group>"; };
DF1C7CE827F5161D00D8145C /* BundlePageConsoleMessageWithDetails.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BundlePageConsoleMessageWithDetails.mm; sourceTree = "<group>"; };
@@ -4112,6 +4114,7 @@
37C7CC341EA41EC8007BD956 /* libTestWTFAlwaysMissing-iOS.tbd */,
37C7CC2E1EA41702007BD956 /* libTestWTFAlwaysMissing-macOS-v2.tbd */,
37C7CC351EA41EC8007BD956 /* libTestWTFAlwaysMissing-macOS.tbd */,
+ D04CF93E285C77C9005D6337 /* MachSendRight.cpp */,
7CBBA07619BB8A9100BBF025 /* OSObjectPtr.cpp */,
44449DC02718B4B700E821B5 /* OSObjectPtrCocoa.mm */,
44449DBF2718B4B600E821B5 /* OSObjectPtrCocoaARC.mm */,
@@ -5524,6 +5527,7 @@
7C83DEE81D0A590C00FEBCF3 /* ListHashSet.cpp in Sources */,
7C83DF1D1D0A590C00FEBCF3 /* Lock.cpp in Sources */,
A57D54F61F3395D000A97AA7 /* Logger.cpp in Sources */,
+ D04CF93F285C77CA005D6337 /* MachSendRight.cpp in Sources */,
4909EE3A2D09480C88982D56 /* Markable.cpp in Sources */,
7C83DEED1D0A590C00FEBCF3 /* MathExtras.cpp in Sources */,
7C83DEF11D0A590C00FEBCF3 /* MediaTime.cpp in Sources */,
Added: trunk/Tools/TestWebKitAPI/Tests/WTF/darwin/MachSendRight.cpp (0 => 295666)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/darwin/MachSendRight.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/darwin/MachSendRight.cpp 2022-06-20 04:25:46 UTC (rev 295666)
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2014-2022 Apple Inc. 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 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 <wtf/MachSendRight.h>
+
+#include <mach/mach.h>
+
+namespace TestWebKitAPI {
+
+static unsigned getSendRefs(mach_port_t port)
+{
+ unsigned count = 0;
+ auto kr = mach_port_get_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, &count);
+ EXPECT_EQ(kr, KERN_SUCCESS);
+ return count;
+}
+
+static mach_port_t setup()
+{
+ mach_port_t port = MACH_PORT_NULL;
+ auto kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &port);
+ EXPECT_EQ(kr, KERN_SUCCESS);
+
+ kr = mach_port_insert_right(mach_task_self(), port, port, MACH_MSG_TYPE_MAKE_SEND);
+ EXPECT_EQ(kr, KERN_SUCCESS);
+
+ EXPECT_EQ(getSendRefs(port), 1u);
+
+ return port;
+}
+
+void shutdown(mach_port_t port)
+{
+ EXPECT_EQ(getSendRefs(port), 0u);
+ EXPECT_EQ(mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_RECEIVE, -1), KERN_SUCCESS);
+
+ // Confirm that releasing the receive right reference resulted in the port name being released.
+ EXPECT_EQ(mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_RECEIVE, -1), KERN_INVALID_NAME);
+}
+
+TEST(MachSendRight, Adopt)
+{
+ auto port = setup();
+
+ {
+ MachSendRight right = MachSendRight::adopt(port);
+ EXPECT_EQ(getSendRefs(port), 1u);
+ }
+
+ shutdown(port);
+}
+
+TEST(MachSendRight, Copy)
+{
+ auto port = setup();
+
+ {
+ MachSendRight right = MachSendRight::adopt(port);
+ MachSendRight copy = right;
+
+ EXPECT_EQ(getSendRefs(port), 2u);
+ }
+
+ shutdown(port);
+}
+
+TEST(MachSendRight, Move)
+{
+ auto port = setup();
+
+ {
+ MachSendRight right = MachSendRight::adopt(port);
+ MachSendRight move = WTFMove(right);
+
+ EXPECT_EQ(getSendRefs(port), 1u);
+ }
+
+ shutdown(port);
+}
+
+TEST(MachSendRight, Overwrite)
+{
+ auto first = setup();
+ auto second = setup();
+
+ {
+ MachSendRight firstRight = MachSendRight::adopt(first);
+ MachSendRight secondRight = MachSendRight::adopt(second);
+
+ secondRight = firstRight;
+
+ EXPECT_EQ(getSendRefs(first), 2u);
+ EXPECT_EQ(getSendRefs(second), 0u);
+ }
+
+ shutdown(first);
+ shutdown(second);
+}
+
+TEST(MachSendRight, OverwriteMove)
+{
+ auto first = setup();
+ auto second = setup();
+
+ {
+ MachSendRight firstRight = MachSendRight::adopt(first);
+ MachSendRight secondRight = MachSendRight::adopt(second);
+
+ secondRight = WTFMove(firstRight);
+
+ EXPECT_EQ(getSendRefs(first), 1u);
+ EXPECT_EQ(getSendRefs(second), 0u);
+ }
+
+ shutdown(first);
+ shutdown(second);
+}
+
+
+TEST(MachSendRight, DeadName)
+{
+ // Release the receive right so that the send right becomes a dead name right instead, and
+ // confirm that MachSendRight handles this.
+ auto port = setup();
+ EXPECT_EQ(mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_RECEIVE, -1), KERN_SUCCESS);
+
+ {
+ MachSendRight right = MachSendRight::adopt(port);
+ EXPECT_EQ(getSendRefs(port), 0u);
+
+ unsigned count = 0;
+ auto kr = mach_port_get_refs(mach_task_self(), port, MACH_PORT_RIGHT_DEAD_NAME, &count);
+ EXPECT_EQ(kr, KERN_SUCCESS);
+ EXPECT_EQ(count, 1u);
+ }
+
+ EXPECT_EQ(mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_DEAD_NAME, -1), KERN_INVALID_NAME);
+}
+
+}
+
+