Diff
Modified: trunk/Source/WebKit/ChangeLog (292457 => 292458)
--- trunk/Source/WebKit/ChangeLog 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/ChangeLog 2022-04-06 11:16:26 UTC (rev 292458)
@@ -1,3 +1,66 @@
+2022-04-06 Zan Dobersek <zdober...@igalia.com>
+
+ [Unix] Adopt UnixFileDescriptor in IPC::Attachment
+ https://bugs.webkit.org/show_bug.cgi?id=238801
+
+ Reviewed by Carlos Garcia Campos.
+
+ Adopt WTF::UnixFileDescriptor for usage in IPC::Attachment, in place of
+ a raw integer value. This simplifies move operations and destruction of
+ this value.
+
+ The two relevant constructors are changed to expect a UnixFileDescriptor
+ rvalue, and they're also made explicit. The file descriptor object is
+ accessible through both a const and a non-const getter, which allows the
+ user to read or release the file descriptor contained there. There's
+ also a release method that returns the contained UnixFileDescriptor.
+
+ The releaseFileDescriptor() and fileDescriptor() methods, previously
+ releasing or returning the contained integer value of the descriptor.
+ Call sites for these methods as well as the old-form constructors are
+ adjusted to the new variants.
+
+ * Platform/IPC/Attachment.h:
+ (IPC::Attachment::isNull const):
+ (IPC::Attachment::fd const):
+ (IPC::Attachment::release):
+ (IPC::Attachment::releaseFileDescriptor): Deleted.
+ (IPC::Attachment::fileDescriptor const): Deleted.
+ * Platform/IPC/unix/AttachmentUnix.cpp:
+ (IPC::Attachment::Attachment):
+ (IPC::Attachment::operator=):
+ (IPC::Attachment::~Attachment): Deleted.
+ * Platform/IPC/unix/ConnectionUnix.cpp:
+ (IPC::Connection::processMessage):
+ (IPC::Connection::sendOutputMessage):
+ (IPC::Connection::createConnectionIdentifierPair):
+ * Platform/unix/SharedMemoryUnix.cpp:
+ (WebKit::SharedMemory::Handle::isNull const):
+ (WebKit::SharedMemory::map):
+ (WebKit::SharedMemory::createHandle):
+ * Shared/WebCoreArgumentCoders.cpp:
+ (IPC::ArgumentCoder<UnixFileDescriptor>::encode):
+ (IPC::ArgumentCoder<UnixFileDescriptor>::decode):
+ * Shared/glib/UserMessage.cpp:
+ (WebKit::UserMessage::encode const):
+ (WebKit::UserMessage::decode):
+ * UIProcess/API/wpe/PageClientImpl.cpp:
+ (WebKit::PageClientImpl::hostFileDescriptor):
+ * UIProcess/glib/WebProcessPoolGLib.cpp:
+ (WebKit::WebProcessPool::platformInitializeWebProcess):
+ * WebProcess/GPU/GPUProcessConnectionInfo.h:
+ (WebKit::GPUProcessConnectionInfo::identifier const):
+ (WebKit::GPUProcessConnectionInfo::releaseIdentifier):
+ * WebProcess/Inspector/WebInspector.cpp:
+ (WebKit::WebInspector::setFrontendConnection):
+ * WebProcess/Network/NetworkProcessConnectionInfo.h:
+ (WebKit::NetworkProcessConnectionInfo::identifier const):
+ (WebKit::NetworkProcessConnectionInfo::releaseIdentifier):
+ * WebProcess/WebPage/WebPage.h:
+ (WebKit::WebPage::hostFileDescriptor const):
+ * WebProcess/glib/WebProcessGLib.cpp:
+ (WebKit::WebProcess::platformInitializeWebProcess):
+
2022-04-06 Youenn Fablet <you...@apple.com>
ServiceWorkerClients.openWindow should not need to get all clients asynchronously to resolve its promise
Modified: trunk/Source/WebKit/Platform/IPC/Attachment.h (292457 => 292458)
--- trunk/Source/WebKit/Platform/IPC/Attachment.h 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/Platform/IPC/Attachment.h 2022-04-06 11:16:26 UTC (rev 292458)
@@ -40,6 +40,7 @@
#if USE(UNIX_DOMAIN_SOCKETS)
#include <variant>
#include <wtf/Function.h>
+#include <wtf/unix/UnixFileDescriptor.h>
#endif
namespace IPC {
@@ -63,10 +64,11 @@
};
#if USE(UNIX_DOMAIN_SOCKETS)
+ explicit Attachment(UnixFileDescriptor&&, size_t);
+ explicit Attachment(UnixFileDescriptor&&);
+
Attachment(Attachment&&);
Attachment& operator=(Attachment&&);
- Attachment(int fileDescriptor, size_t);
- Attachment(int fileDescriptor);
~Attachment();
using SocketDescriptor = int;
@@ -84,10 +86,12 @@
Type type() const { return m_type; }
#if USE(UNIX_DOMAIN_SOCKETS)
+ bool isNull() const { return !m_fd; }
size_t size() const { return m_size; }
- int releaseFileDescriptor() { int temp = m_fileDescriptor; m_fileDescriptor = -1; return temp; }
- int fileDescriptor() const { return m_fileDescriptor; }
+ const UnixFileDescriptor& fd() const { return m_fd; }
+ UnixFileDescriptor release() { return std::exchange(m_fd, UnixFileDescriptor { }); }
+
const CustomWriter& customWriter() const { return m_customWriter; }
#elif OS(DARWIN)
void release();
@@ -106,7 +110,7 @@
Type m_type;
#if USE(UNIX_DOMAIN_SOCKETS)
- int m_fileDescriptor { -1 };
+ UnixFileDescriptor m_fd;
size_t m_size;
CustomWriter m_customWriter;
#elif OS(DARWIN)
Modified: trunk/Source/WebKit/Platform/IPC/unix/AttachmentUnix.cpp (292457 => 292458)
--- trunk/Source/WebKit/Platform/IPC/unix/AttachmentUnix.cpp 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/Platform/IPC/unix/AttachmentUnix.cpp 2022-04-06 11:16:26 UTC (rev 292458)
@@ -31,16 +31,16 @@
namespace IPC {
-Attachment::Attachment(int fileDescriptor, size_t size)
+Attachment::Attachment(UnixFileDescriptor&& fd, size_t size)
: m_type(MappedMemoryType)
- , m_fileDescriptor(fileDescriptor)
+ , m_fd(WTFMove(fd))
, m_size(size)
{
}
-Attachment::Attachment(int fileDescriptor)
+Attachment::Attachment(UnixFileDescriptor&& fd)
: m_type(SocketType)
- , m_fileDescriptor(fileDescriptor)
+ , m_fd(WTFMove(fd))
, m_size(0)
{
}
@@ -47,18 +47,16 @@
Attachment::Attachment(Attachment&& attachment)
: m_type(attachment.m_type)
- , m_fileDescriptor(attachment.m_fileDescriptor)
+ , m_fd(WTFMove(attachment.m_fd))
, m_size(attachment.m_size)
, m_customWriter(WTFMove(attachment.m_customWriter))
{
attachment.m_type = Uninitialized;
- attachment.m_fileDescriptor = -1;
attachment.m_size = 0;
}
Attachment::Attachment(CustomWriter&& writer)
: m_type(CustomWriterType)
- , m_fileDescriptor(-1)
, m_size(0)
, m_customWriter(WTFMove(writer))
{
@@ -68,8 +66,7 @@
{
m_type = attachment.m_type;
attachment.m_type = Uninitialized;
- m_fileDescriptor = attachment.m_fileDescriptor;
- attachment.m_fileDescriptor = -1;
+ m_fd = WTFMove(attachment.m_fd);
m_size = attachment.m_size;
attachment.m_size = 0;
m_customWriter = WTFMove(attachment.m_customWriter);
@@ -77,10 +74,6 @@
return *this;
}
-Attachment::~Attachment()
-{
- if (m_fileDescriptor != -1)
- closeWithRetry(m_fileDescriptor);
-}
+Attachment::~Attachment() = default;
} // namespace IPC
Modified: trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp (292457 => 292458)
--- trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp 2022-04-06 11:16:26 UTC (rev 292458)
@@ -204,12 +204,12 @@
case Attachment::MappedMemoryType:
if (!attachmentInfo[i].isNull())
fd = m_fileDescriptors[fdIndex++];
- attachments[attachmentCount - i - 1] = Attachment(fd, attachmentInfo[i].size());
+ attachments[attachmentCount - i - 1] = Attachment(UnixFileDescriptor(fd, UnixFileDescriptor::Adopt), attachmentInfo[i].size());
break;
case Attachment::SocketType:
if (!attachmentInfo[i].isNull())
fd = m_fileDescriptors[fdIndex++];
- attachments[attachmentCount - i - 1] = Attachment(fd);
+ attachments[attachmentCount - i - 1] = Attachment(UnixFileDescriptor(fd, UnixFileDescriptor::Adopt));
break;
case Attachment::CustomWriterType:
attachments[attachmentCount - i - 1] = Attachment(Attachment::CustomWriter(m_socketDescriptor));
@@ -230,7 +230,7 @@
}
WebKit::SharedMemory::Handle handle;
- handle.adoptAttachment(IPC::Attachment(m_fileDescriptors[attachmentFileDescriptorCount - 1], attachmentInfo[attachmentCount].size()));
+ handle.adoptAttachment(Attachment(UnixFileDescriptor(m_fileDescriptors[attachmentFileDescriptorCount - 1], UnixFileDescriptor::Adopt), attachmentInfo[attachmentCount].size()));
oolMessageBody = WebKit::SharedMemory::map(handle, WebKit::SharedMemory::Protection::ReadOnly);
if (!oolMessageBody) {
@@ -489,7 +489,7 @@
size_t attachmentFDBufferLength = std::count_if(attachments.begin(), attachments.end(),
[](const Attachment& attachment) {
- return attachment.fileDescriptor() != -1;
+ return !attachment.isNull();
});
if (attachmentFDBufferLength) {
@@ -517,9 +517,9 @@
attachmentInfo[i].setSize(attachments[i].size());
FALLTHROUGH;
case Attachment::SocketType:
- if (attachments[i].fileDescriptor() != -1) {
+ if (!attachments[i].isNull()) {
ASSERT(fdPtr);
- fdPtr[fdIndex++] = attachments[i].fileDescriptor();
+ fdPtr[fdIndex++] = attachments[i].fd().value();
} else
attachmentInfo[i].setNull();
break;
@@ -638,6 +638,6 @@
std::optional<Connection::ConnectionIdentifierPair> Connection::createConnectionIdentifierPair()
{
Connection::SocketPair socketPair = Connection::createPlatformConnection();
- return ConnectionIdentifierPair { socketPair.server, Attachment { socketPair.client } };
+ return ConnectionIdentifierPair { socketPair.server, Attachment { UnixFileDescriptor { socketPair.client, UnixFileDescriptor::Adopt } } };
}
} // namespace IPC
Modified: trunk/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp (292457 => 292458)
--- trunk/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/Platform/unix/SharedMemoryUnix.cpp 2022-04-06 11:16:26 UTC (rev 292458)
@@ -75,7 +75,7 @@
bool SharedMemory::Handle::isNull() const
{
- return m_attachment.fileDescriptor() == -1;
+ return m_attachment.isNull();
}
void SharedMemory::IPCHandle::encode(IPC::Encoder& encoder) const
@@ -200,9 +200,9 @@
{
ASSERT(!handle.isNull());
- int fd = handle.m_attachment.releaseFileDescriptor();
- void* data = "" handle.m_attachment.size(), accessModeMMap(protection), MAP_SHARED, fd, 0);
- closeWithRetry(fd);
+ UnixFileDescriptor fd = handle.m_attachment.release();
+ void* data = "" handle.m_attachment.size(), accessModeMMap(protection), MAP_SHARED, fd.value(), 0);
+ fd = { };
if (data == MAP_FAILED)
return nullptr;
@@ -240,12 +240,12 @@
// FIXME: Handle the case where the passed Protection is ReadOnly.
// See https://bugs.webkit.org/show_bug.cgi?id=131542.
- int duplicatedHandle = dupCloseOnExec(m_fileDescriptor.value());
- if (duplicatedHandle == -1) {
+ UnixFileDescriptor duplicate { m_fileDescriptor.value(), UnixFileDescriptor::Duplicate };
+ if (!duplicate) {
ASSERT_NOT_REACHED();
return false;
}
- handle.m_attachment = IPC::Attachment(duplicatedHandle, m_size);
+ handle.m_attachment = IPC::Attachment(WTFMove(duplicate), m_size);
return true;
}
Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (292457 => 292458)
--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp 2022-04-06 11:16:26 UTC (rev 292458)
@@ -3295,13 +3295,12 @@
void ArgumentCoder<UnixFileDescriptor>::encode(Encoder& encoder, const UnixFileDescriptor& fd)
{
- auto duplicate = fd.duplicate();
- encoder.addAttachment(Attachment(duplicate.release()));
+ encoder.addAttachment(Attachment(fd.duplicate()));
}
void ArgumentCoder<UnixFileDescriptor>::encode(Encoder& encoder, UnixFileDescriptor&& fd)
{
- encoder.addAttachment(Attachment(fd.release()));
+ encoder.addAttachment(Attachment(WTFMove(fd)));
}
std::optional<UnixFileDescriptor> ArgumentCoder<UnixFileDescriptor>::decode(Decoder& decoder)
@@ -3309,7 +3308,7 @@
auto attachment = decoder.takeLastAttachment();
if (!attachment)
return std::nullopt;
- return std::optional<UnixFileDescriptor> { std::in_place, attachment->releaseFileDescriptor(), UnixFileDescriptor::Adopt };
+ return std::optional<UnixFileDescriptor> { std::in_place, attachment->release() };
}
#endif
Modified: trunk/Source/WebKit/Shared/glib/UserMessage.cpp (292457 => 292458)
--- trunk/Source/WebKit/Shared/glib/UserMessage.cpp 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/Shared/glib/UserMessage.cpp 2022-04-06 11:16:26 UTC (rev 292458)
@@ -51,7 +51,7 @@
if (fileDescriptors) {
int length = g_unix_fd_list_get_length(fileDescriptors.get());
for (int i = 0; i < length; ++i)
- attachments.append(IPC::Attachment(g_unix_fd_list_get(fileDescriptors.get(), i, nullptr)));
+ attachments.append(IPC::Attachment(UnixFileDescriptor(g_unix_fd_list_get(fileDescriptors.get(), i, nullptr), UnixFileDescriptor::Adopt)));
}
encoder << attachments;
}
@@ -91,7 +91,7 @@
if (!attachments->isEmpty()) {
result.fileDescriptors = adoptGRef(g_unix_fd_list_new());
for (auto& attachment : *attachments) {
- if (g_unix_fd_list_append(result.fileDescriptors.get(), attachment.releaseFileDescriptor(), nullptr) == -1)
+ if (g_unix_fd_list_append(result.fileDescriptors.get(), attachment.release().release(), nullptr) == -1)
return std::nullopt;
}
}
Modified: trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp (292457 => 292458)
--- trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/UIProcess/API/wpe/PageClientImpl.cpp 2022-04-06 11:16:26 UTC (rev 292458)
@@ -59,7 +59,7 @@
IPC::Attachment PageClientImpl::hostFileDescriptor()
{
- return wpe_view_backend_get_renderer_host_fd(m_view.backend());
+ return IPC::Attachment(UnixFileDescriptor(wpe_view_backend_get_renderer_host_fd(m_view.backend()), UnixFileDescriptor::Adopt));
}
std::unique_ptr<DrawingAreaProxy> PageClientImpl::createDrawingAreaProxy(WebProcessProxy& process)
Modified: trunk/Source/WebKit/UIProcess/glib/WebProcessPoolGLib.cpp (292457 => 292458)
--- trunk/Source/WebKit/UIProcess/glib/WebProcessPoolGLib.cpp 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/UIProcess/glib/WebProcessPoolGLib.cpp 2022-04-06 11:16:26 UTC (rev 292458)
@@ -78,7 +78,7 @@
parameters.isServiceWorkerProcess = process.isRunningServiceWorkers();
if (!parameters.isServiceWorkerProcess) {
- parameters.hostClientFileDescriptor = wpe_renderer_host_create_client();
+ parameters.hostClientFileDescriptor = IPC::Attachment(UnixFileDescriptor(wpe_renderer_host_create_client(), UnixFileDescriptor::Adopt));
parameters.implementationLibraryName = FileSystem::fileSystemRepresentation(String { wpe_loader_get_loaded_implementation_library_name() });
}
#endif
@@ -88,7 +88,7 @@
#if USE(WPE_RENDERER)
wpe_loader_init("libWPEBackend-fdo-1.0.so.1");
if (AcceleratedBackingStoreWayland::checkRequirements()) {
- parameters.hostClientFileDescriptor = wpe_renderer_host_create_client();
+ parameters.hostClientFileDescriptor = IPC::Attachment(UnixFileDescriptor(wpe_renderer_host_create_client(), UnixFileDescriptor::Adopt));
parameters.implementationLibraryName = FileSystem::fileSystemRepresentation(String { wpe_loader_get_loaded_implementation_library_name() });
}
#elif USE(EGL)
Modified: trunk/Source/WebKit/WebProcess/GPU/GPUProcessConnectionInfo.h (292457 => 292458)
--- trunk/Source/WebKit/WebProcess/GPU/GPUProcessConnectionInfo.h 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/WebProcess/GPU/GPUProcessConnectionInfo.h 2022-04-06 11:16:26 UTC (rev 292458)
@@ -41,7 +41,7 @@
IPC::Connection::Identifier identifier() const
{
#if USE(UNIX_DOMAIN_SOCKETS)
- return IPC::Connection::Identifier(connection.fileDescriptor());
+ return IPC::Connection::Identifier(connection.fd().value());
#elif OS(DARWIN)
return IPC::Connection::Identifier(connection.port());
#elif OS(WINDOWS)
@@ -55,7 +55,7 @@
IPC::Connection::Identifier releaseIdentifier()
{
#if USE(UNIX_DOMAIN_SOCKETS)
- auto returnValue = IPC::Connection::Identifier(connection.releaseFileDescriptor());
+ auto returnValue = IPC::Connection::Identifier(connection.release().release());
#else
auto returnValue = identifier();
#endif
Modified: trunk/Source/WebKit/WebProcess/Inspector/WebInspector.cpp (292457 => 292458)
--- trunk/Source/WebKit/WebProcess/Inspector/WebInspector.cpp 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/WebProcess/Inspector/WebInspector.cpp 2022-04-06 11:16:26 UTC (rev 292458)
@@ -85,7 +85,7 @@
}
#if USE(UNIX_DOMAIN_SOCKETS)
- IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.releaseFileDescriptor());
+ IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.release().release());
#elif OS(DARWIN)
IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.port());
#elif OS(WINDOWS)
Modified: trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnectionInfo.h (292457 => 292458)
--- trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnectionInfo.h 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/WebProcess/Network/NetworkProcessConnectionInfo.h 2022-04-06 11:16:26 UTC (rev 292458)
@@ -40,7 +40,7 @@
IPC::Connection::Identifier identifier() const
{
#if USE(UNIX_DOMAIN_SOCKETS)
- return IPC::Connection::Identifier(connection.fileDescriptor());
+ return IPC::Connection::Identifier(connection.fd().value());
#elif OS(DARWIN)
return IPC::Connection::Identifier(connection.port());
#elif OS(WINDOWS)
@@ -54,7 +54,7 @@
IPC::Connection::Identifier releaseIdentifier()
{
#if USE(UNIX_DOMAIN_SOCKETS)
- auto returnValue = IPC::Connection::Identifier(connection.releaseFileDescriptor());
+ auto returnValue = IPC::Connection::Identifier(connection.release().release());
#else
auto returnValue = identifier();
#endif
Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (292457 => 292458)
--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2022-04-06 11:16:26 UTC (rev 292458)
@@ -1339,7 +1339,7 @@
#endif
#if USE(WPE_RENDERER)
- int hostFileDescriptor() const { return m_hostFileDescriptor.fileDescriptor(); }
+ int hostFileDescriptor() const { return m_hostFileDescriptor.fd().value(); }
#endif
void updateCurrentModifierState(OptionSet<WebCore::PlatformEvent::Modifier> modifiers);
Modified: trunk/Source/WebKit/WebProcess/glib/WebProcessGLib.cpp (292457 => 292458)
--- trunk/Source/WebKit/WebProcess/glib/WebProcessGLib.cpp 2022-04-06 10:13:31 UTC (rev 292457)
+++ trunk/Source/WebKit/WebProcess/glib/WebProcessGLib.cpp 2022-04-06 11:16:26 UTC (rev 292458)
@@ -114,7 +114,7 @@
wpe_loader_init(parameters.implementationLibraryName.data());
RELEASE_ASSERT(is<PlatformDisplayLibWPE>(PlatformDisplay::sharedDisplay()));
- downcast<PlatformDisplayLibWPE>(PlatformDisplay::sharedDisplay()).initialize(parameters.hostClientFileDescriptor.releaseFileDescriptor());
+ downcast<PlatformDisplayLibWPE>(PlatformDisplay::sharedDisplay()).initialize(parameters.hostClientFileDescriptor.release().release());
}
#endif
@@ -122,7 +122,7 @@
if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::Wayland) {
#if USE(WPE_RENDERER)
if (!parameters.isServiceWorkerProcess) {
- auto hostClientFileDescriptor = parameters.hostClientFileDescriptor.releaseFileDescriptor();
+ auto hostClientFileDescriptor = parameters.hostClientFileDescriptor.release().release();
if (hostClientFileDescriptor != -1) {
wpe_loader_init(parameters.implementationLibraryName.data());
m_wpeDisplay = WebCore::PlatformDisplayLibWPE::create();