Title: [288354] trunk
Revision
288354
Author
[email protected]
Date
2022-01-21 00:32:53 -0800 (Fri, 21 Jan 2022)

Log Message

Support in-process testing of IPC messages
https://bugs.webkit.org/show_bug.cgi?id=231674
<rdar://84189314>

Patch by Kimmo Kinnunen <[email protected]> on 2022-01-21
Reviewed by Brent Fulgham.

Source/WebKit:

Add IPCTester service to UI, GPU, Network, Authn process.
The service can be used to send random messages to the processes.

Test: ipc/start-message-testing.html

* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* GPUProcess/GPUConnectionToWebProcess.cpp:
(WebKit::GPUConnectionToWebProcess::dispatchMessage):
(WebKit::GPUConnectionToWebProcess::dispatchSyncMessage):
* GPUProcess/GPUConnectionToWebProcess.h:
* NetworkProcess/NetworkConnectionToWebProcess.cpp:
(WebKit::NetworkConnectionToWebProcess::didReceiveMessage):
(WebKit::NetworkConnectionToWebProcess::didReceiveSyncMessage):
* NetworkProcess/NetworkConnectionToWebProcess.h:
* Platform/IPC/Connection.cpp:
(IPC::Connection::dispatchIncomingMessageForTesting):
(IPC::Connection::dispatchMessage):
(IPC::CompletionHandler<void):
Remove asserts from takeAsyncReplyHandler, they're already present
in the caller. The caller can filter them based on the testing flag,
allowing testing without asserts.
* Platform/IPC/Connection.h:
* Platform/IPC/Decoder.cpp:
(IPC::Decoder::create):
(IPC::Decoder::Decoder):
(IPC::Decoder::~Decoder):
* Platform/IPC/Decoder.h:
* Platform/IPC/cocoa/ConnectionCocoa.mm:
(IPC::createMessageDecoder):
* Platform/IPC/unix/ConnectionUnix.cpp:
(IPC::Connection::processMessage):
* Platform/IPC/win/ConnectionWin.cpp:
(IPC::Connection::readEventHandler):
* Shared/IPCTester.cpp: Added.
(WebKit::messageTestDriver):
(WebKit::runMessageTesting):
(WebKit::IPCTester::~IPCTester):
(WebKit::IPCTester::startMessageTesting):
(WebKit::IPCTester::stopMessageTesting):
(WebKit::IPCTester::stopIfNeeded):
* Shared/IPCTester.h: Added.
* Shared/IPCTester.messages.in: Copied from Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.messages.in.
* Sources.txt:
* UIProcess/LegacySessionStateCodingNone.cpp:
(WebKit::decodeLegacySessionState):
* UIProcess/WebProcessPool.cpp:
* UIProcess/WebProcessPool.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::shouldSendPendingMessage):
* WebAuthnProcess/WebAuthnConnectionToWebProcess.cpp:
(WebKit::WebAuthnConnectionToWebProcess::dispatchMessage):
(WebKit::WebAuthnConnectionToWebProcess::dispatchSyncMessage):
* WebAuthnProcess/WebAuthnConnectionToWebProcess.h:
* WebAuthnProcess/WebAuthnConnectionToWebProcess.messages.in:
* WebKit.xcodeproj/project.pbxproj:
* WebProcess/WebPage/IPCTestingAPI.cpp:
(WebKit::IPCTestingAPI::JSMessageListener::didReceiveMessage):
(WebKit::IPCTestingAPI::JSMessageListener::willSendMessage):

LayoutTests:

done-ipc-fuzizng

* TestExpectations:
* ipc/start-message-testing.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (288353 => 288354)


--- trunk/LayoutTests/ChangeLog	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/LayoutTests/ChangeLog	2022-01-21 08:32:53 UTC (rev 288354)
@@ -1,3 +1,16 @@
+2022-01-21  Kimmo Kinnunen  <[email protected]>
+
+        Support in-process testing of IPC messages
+        https://bugs.webkit.org/show_bug.cgi?id=231674
+        <rdar://84189314>
+
+        Reviewed by Brent Fulgham.
+
+        done-ipc-fuzizng
+
+        * TestExpectations:
+        * ipc/start-message-testing.html: Added.
+
 2022-01-20  Jon Lee  <[email protected]>
 
         Partially garden [iOS] Triage failing LayoutTests in the storage/indexeddb directory

Modified: trunk/LayoutTests/TestExpectations (288353 => 288354)


--- trunk/LayoutTests/TestExpectations	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/LayoutTests/TestExpectations	2022-01-21 08:32:53 UTC (rev 288354)
@@ -5200,6 +5200,9 @@
 # IPC test failing in Debug mode due to assert.
 [ Debug ] ipc/send-invalid-message.html [ Skip ]
 
+# The test invokes random messages, potentially produces random results.
+ipc/start-message-testing.html [ Skip ]
+
 imported/w3c/web-platform-tests/css/css-shadow-parts/interaction-with-nested-pseudo-class.html [ ImageOnlyFailure ]
 
 webkit.org/b/183994 imported/w3c/web-platform-tests/css/cssom/css-style-attr-decl-block.html [ Failure ]

Added: trunk/LayoutTests/ipc/start-message-testing.html (0 => 288354)


--- trunk/LayoutTests/ipc/start-message-testing.html	                        (rev 0)
+++ trunk/LayoutTests/ipc/start-message-testing.html	2022-01-21 08:32:53 UTC (rev 288354)
@@ -0,0 +1,31 @@
+<!DOCTYPE html><!-- webkit-test-runner [ IPCTestingAPIEnabled=true ] -->
+<body>
+<script>
+if (window.testRunner)
+    testRunner.dumpAsText();
+
+var driverName = {type: "String", value: "default"};
+
+function stop() {
+    if (window.IPC) {
+        IPC.sendSyncMessage("GPU", 0, IPC.messages.IPCTester_StopMessageTesting.name, []);
+        IPC.sendSyncMessage("Networking", 0, IPC.messages.IPCTester_StopMessageTesting.name, []);
+        IPC.sendSyncMessage("UI", 0, IPC.messages.IPCTester_StopMessageTesting.name, []);
+        console.log("stopped");
+    }
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+if (window.IPC) {
+    IPC.sendMessage("GPU", 0, IPC.messages.IPCTester_StartMessageTesting.name, [driverName]);
+    IPC.sendMessage("Networking", 0, IPC.messages.IPCTester_StartMessageTesting.name, [driverName]);
+    IPC.sendMessage("UI", 0, IPC.messages.IPCTester_StartMessageTesting.name, [driverName]);
+    console.log("started");
+}
+setTimeout(stop, 3000);
+
+</script>
+<p>Test passes if it does not crash.</p>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebKit/CMakeLists.txt (288353 => 288354)


--- trunk/Source/WebKit/CMakeLists.txt	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/CMakeLists.txt	2022-01-21 08:32:53 UTC (rev 288354)
@@ -214,6 +214,7 @@
     NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy
 
     Shared/AuxiliaryProcess
+    Shared/IPCTester
     Shared/WebConnection
 
     Shared/Authentication/AuthenticationManager

Modified: trunk/Source/WebKit/ChangeLog (288353 => 288354)


--- trunk/Source/WebKit/ChangeLog	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/ChangeLog	2022-01-21 08:32:53 UTC (rev 288354)
@@ -1,3 +1,72 @@
+2022-01-21  Kimmo Kinnunen  <[email protected]>
+
+        Support in-process testing of IPC messages
+        https://bugs.webkit.org/show_bug.cgi?id=231674
+        <rdar://84189314>
+
+        Reviewed by Brent Fulgham.
+
+        Add IPCTester service to UI, GPU, Network, Authn process.
+        The service can be used to send random messages to the processes.
+
+        Test: ipc/start-message-testing.html
+
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * GPUProcess/GPUConnectionToWebProcess.cpp:
+        (WebKit::GPUConnectionToWebProcess::dispatchMessage):
+        (WebKit::GPUConnectionToWebProcess::dispatchSyncMessage):
+        * GPUProcess/GPUConnectionToWebProcess.h:
+        * NetworkProcess/NetworkConnectionToWebProcess.cpp:
+        (WebKit::NetworkConnectionToWebProcess::didReceiveMessage):
+        (WebKit::NetworkConnectionToWebProcess::didReceiveSyncMessage):
+        * NetworkProcess/NetworkConnectionToWebProcess.h:
+        * Platform/IPC/Connection.cpp:
+        (IPC::Connection::dispatchIncomingMessageForTesting):
+        (IPC::Connection::dispatchMessage):
+        (IPC::CompletionHandler<void):
+        Remove asserts from takeAsyncReplyHandler, they're already present
+        in the caller. The caller can filter them based on the testing flag,
+        allowing testing without asserts.
+        * Platform/IPC/Connection.h:
+        * Platform/IPC/Decoder.cpp:
+        (IPC::Decoder::create):
+        (IPC::Decoder::Decoder):
+        (IPC::Decoder::~Decoder):
+        * Platform/IPC/Decoder.h:
+        * Platform/IPC/cocoa/ConnectionCocoa.mm:
+        (IPC::createMessageDecoder):
+        * Platform/IPC/unix/ConnectionUnix.cpp:
+        (IPC::Connection::processMessage):
+        * Platform/IPC/win/ConnectionWin.cpp:
+        (IPC::Connection::readEventHandler):
+        * Shared/IPCTester.cpp: Added.
+        (WebKit::messageTestDriver):
+        (WebKit::runMessageTesting):
+        (WebKit::IPCTester::~IPCTester):
+        (WebKit::IPCTester::startMessageTesting):
+        (WebKit::IPCTester::stopMessageTesting):
+        (WebKit::IPCTester::stopIfNeeded):
+        * Shared/IPCTester.h: Added.
+        * Shared/IPCTester.messages.in: Copied from Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.messages.in.
+        * Sources.txt:
+        * UIProcess/LegacySessionStateCodingNone.cpp:
+        (WebKit::decodeLegacySessionState):
+        * UIProcess/WebProcessPool.cpp:
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::shouldSendPendingMessage):
+        * WebAuthnProcess/WebAuthnConnectionToWebProcess.cpp:
+        (WebKit::WebAuthnConnectionToWebProcess::dispatchMessage):
+        (WebKit::WebAuthnConnectionToWebProcess::dispatchSyncMessage):
+        * WebAuthnProcess/WebAuthnConnectionToWebProcess.h:
+        * WebAuthnProcess/WebAuthnConnectionToWebProcess.messages.in:
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/WebPage/IPCTestingAPI.cpp:
+        (WebKit::IPCTestingAPI::JSMessageListener::didReceiveMessage):
+        (WebKit::IPCTestingAPI::JSMessageListener::willSendMessage):
+
 2022-01-20  Devin Rousso  <[email protected]>
 
         Add SPI for passing around and getting details about `WebCore::CSSStyleDeclaration` in injected bundle code

Modified: trunk/Source/WebKit/DerivedSources-input.xcfilelist (288353 => 288354)


--- trunk/Source/WebKit/DerivedSources-input.xcfilelist	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/DerivedSources-input.xcfilelist	2022-01-21 08:32:53 UTC (rev 288354)
@@ -123,6 +123,7 @@
 $(PROJECT_DIR)/Shared/Authentication/AuthenticationManager.messages.in
 $(PROJECT_DIR)/Shared/AuxiliaryProcess.messages.in
 $(PROJECT_DIR)/Shared/HTTPSUpgrade/HTTPSUpgradeList.txt
+$(PROJECT_DIR)/Shared/IPCTester.messages.in
 $(PROJECT_DIR)/Shared/Notifications/NotificationManagerMessageHandler.messages.in
 $(PROJECT_DIR)/Shared/Notifications/NotificationManagerProxy.messages.in
 $(PROJECT_DIR)/Shared/Plugins/NPObjectMessageReceiver.messages.in

Modified: trunk/Source/WebKit/DerivedSources-output.xcfilelist (288353 => 288354)


--- trunk/Source/WebKit/DerivedSources-output.xcfilelist	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/DerivedSources-output.xcfilelist	2022-01-21 08:32:53 UTC (rev 288354)
@@ -46,6 +46,9 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/GPUProcessProxyMessageReceiver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/GPUProcessProxyMessages.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/GPUProcessProxyMessagesReplies.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/IPCTesterMessageReceiver.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/IPCTesterMessages.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/IPCTesterMessagesReplies.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/LegacyCustomProtocolManagerMessageReceiver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/LegacyCustomProtocolManagerMessages.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebKit/LegacyCustomProtocolManagerMessagesReplies.h

Modified: trunk/Source/WebKit/DerivedSources.make (288353 => 288354)


--- trunk/Source/WebKit/DerivedSources.make	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/DerivedSources.make	2022-01-21 08:32:53 UTC (rev 288354)
@@ -148,6 +148,7 @@
 	Shared/Authentication/AuthenticationManager \
 	Shared/Notifications/NotificationManagerMessageHandler \
 	Shared/WebConnection \
+	Shared/IPCTester \
 	UIProcess/WebFullScreenManagerProxy \
 	UIProcess/RemoteLayerTree/RemoteLayerTreeDrawingAreaProxy \
 	UIProcess/GPU/GPUProcessProxy \

Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp (288353 => 288354)


--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -149,6 +149,10 @@
 #include "WCContentBufferManager.h"
 #endif
 
+#if ENABLE(IPC_TESTING_API)
+#include "IPCTesterMessages.h"
+#endif
+
 namespace WebKit {
 using namespace WebCore;
 
@@ -795,6 +799,12 @@
             m_remoteRemoteCommandListener->didReceiveMessage(connection, decoder);
         return true;
     }
+#if ENABLE(IPC_TESTING_API)
+    if (decoder.messageReceiverName() == Messages::IPCTester::messageReceiverName()) {
+        m_ipcTester.didReceiveMessage(connection, decoder);
+        return true;
+    }
+#endif
 
     return messageReceiverMap().dispatchMessage(connection, decoder);
 }
@@ -869,6 +879,12 @@
         // Skip messages for already removed receivers.
         return true;
 #endif
+#if ENABLE(IPC_TESTING_API)
+    if (decoder.messageReceiverName() == Messages::IPCTester::messageReceiverName()) {
+        m_ipcTester.didReceiveSyncMessage(connection, decoder, replyEncoder);
+        return true;
+    }
+#endif
     return messageReceiverMap().dispatchSyncMessage(connection, decoder, replyEncoder);
 }
 

Modified: trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h (288353 => 288354)


--- trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h	2022-01-21 08:32:53 UTC (rev 288354)
@@ -64,6 +64,10 @@
 #include "WCLayerTreeHostIdentifier.h"
 #endif
 
+#if ENABLE(IPC_TESTING_API)
+#include "IPCTester.h"
+#endif
+
 namespace WebCore {
 class SecurityOrigin;
 struct SecurityOriginData;
@@ -349,6 +353,9 @@
 #if ENABLE(ROUTING_ARBITRATION) && HAVE(AVAUDIO_ROUTING_ARBITER)
     UniqueRef<LocalAudioSessionRoutingArbitrator> m_routingArbitrator;
 #endif
+#if ENABLE(IPC_TESTING_API)
+    IPCTester m_ipcTester;
+#endif
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp (288353 => 288354)


--- trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -85,6 +85,10 @@
 #include "LegacyCustomProtocolManager.h"
 #endif
 
+#if ENABLE(IPC_TESTING_API)
+#include "IPCTesterMessages.h"
+#endif
+
 #define CONNECTION_RELEASE_LOG(channel, fmt, ...) RELEASE_LOG(channel, "%p - [webProcessIdentifier=%" PRIu64 "] NetworkConnectionToWebProcess::" fmt, this, webProcessIdentifier().toUInt64(), ##__VA_ARGS__)
 #define CONNECTION_RELEASE_LOG_ERROR(channel, fmt, ...) RELEASE_LOG_ERROR(channel, "%p - [webProcessIdentifier=%" PRIu64 "] NetworkConnectionToWebProcess::" fmt, this, webProcessIdentifier().toUInt64(), ##__VA_ARGS__)
 
@@ -276,6 +280,19 @@
         return paymentCoordinator().didReceiveMessage(connection, decoder);
 #endif
 
+#if ENABLE(IPC_TESTING_API)
+    if (decoder.messageReceiverName() == Messages::IPCTester::messageReceiverName()) {
+        m_ipcTester.didReceiveMessage(connection, decoder);
+        return;
+    }
+#endif
+
+    // Add new receiver name tests above this.
+#if ENABLE(IPC_TESTING_API)
+    if (connection.ignoreInvalidMessageForTesting())
+        return;
+#endif
+
     WTFLogAlways("Unhandled network process message '%s'", description(decoder.messageName()));
     ASSERT_NOT_REACHED();
 }
@@ -353,6 +370,19 @@
         return paymentCoordinator().didReceiveSyncMessage(connection, decoder, reply);
 #endif
 
+#if ENABLE(IPC_TESTING_API)
+    if (decoder.messageReceiverName() == Messages::IPCTester::messageReceiverName()) {
+        m_ipcTester.didReceiveSyncMessage(connection, decoder, reply);
+        return true;
+    }
+#endif
+
+    // Add new receiver name tests above this.
+#if ENABLE(IPC_TESTING_API)
+    if (connection.ignoreInvalidMessageForTesting())
+        return true;
+#endif
+
     WTFLogAlways("Unhandled network process message '%s'", description(decoder.messageName()));
     ASSERT_NOT_REACHED();
     return false;

Modified: trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h (288353 => 288354)


--- trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h	2022-01-21 08:32:53 UTC (rev 288354)
@@ -56,6 +56,10 @@
 #include <wtf/RefCounted.h>
 #include <wtf/URLHash.h>
 
+#if ENABLE(IPC_TESTING_API)
+#include "IPCTester.h"
+#endif
+
 namespace PAL {
 class SessionID;
 }
@@ -415,6 +419,9 @@
         
     HashSet<URL> m_blobURLs;
     HashSet<URL> m_blobURLHandles;
+#if ENABLE(IPC_TESTING_API)
+    IPCTester m_ipcTester;
+#endif
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/Platform/IPC/Connection.cpp (288353 => 288354)


--- trunk/Source/WebKit/Platform/IPC/Connection.cpp	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/Platform/IPC/Connection.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -874,6 +874,13 @@
 {
     m_messageObservers.append(observer);
 }
+
+void Connection::dispatchIncomingMessageForTesting(std::unique_ptr<Decoder>&& decoder)
+{
+    m_connectionQueue->dispatch([protectedThis = Ref { *this }, decoder = WTFMove(decoder)]() mutable {
+        protectedThis->processIncomingMessage(WTFMove(decoder));
+    });
+}
 #endif
 
 void Connection::postConnectionDidCloseOnConnectionWorkQueue()
@@ -1056,6 +1063,11 @@
     if (decoder.messageReceiverName() == ReceiverName::AsyncReply) {
         auto handler = takeAsyncReplyHandler(*this, decoder.destinationID());
         if (!handler) {
+            markCurrentlyDispatchedMessageAsInvalid();
+#if ENABLE(IPC_TESTING_API)
+            if (m_ignoreInvalidMessageForTesting)
+                return;
+#endif
             ASSERT_NOT_REACHED();
             return;
         }
@@ -1274,17 +1286,11 @@
     Locker locker { asyncReplyHandlerMapLock };
     auto& map = asyncReplyHandlerMap();
     auto iterator = map.find(reinterpret_cast<uintptr_t>(&connection));
-    if (iterator != map.end()) {
-        if (!iterator->value.isValidKey(identifier)) {
-            ASSERT_NOT_REACHED();
-            connection.markCurrentlyDispatchedMessageAsInvalid();
-            return nullptr;
-        }
-        ASSERT(iterator->value.contains(identifier));
-        return iterator->value.take(identifier);
-    }
-    ASSERT_NOT_REACHED();
-    return nullptr;
+    if (iterator == map.end())
+        return nullptr;
+    if (!iterator->value.isValidKey(identifier))
+        return nullptr;
+    return iterator->value.take(identifier);
 }
 
 void Connection::wakeUpRunLoop()

Modified: trunk/Source/WebKit/Platform/IPC/Connection.h (288353 => 288354)


--- trunk/Source/WebKit/Platform/IPC/Connection.h	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/Platform/IPC/Connection.h	2022-01-21 08:32:53 UTC (rev 288354)
@@ -322,6 +322,7 @@
 
     void setIgnoreInvalidMessageForTesting() { m_ignoreInvalidMessageForTesting = true; }
     bool ignoreInvalidMessageForTesting() const { return m_ignoreInvalidMessageForTesting; }
+    void dispatchIncomingMessageForTesting(std::unique_ptr<Decoder>&&);
 #endif
 
     void dispatchMessageReceiverMessage(MessageReceiver&, std::unique_ptr<Decoder>&&);

Modified: trunk/Source/WebKit/Platform/IPC/Decoder.cpp (288353 => 288354)


--- trunk/Source/WebKit/Platform/IPC/Decoder.cpp	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/Platform/IPC/Decoder.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -47,7 +47,7 @@
     return bufferCopy;
 }
 
-std::unique_ptr<Decoder> Decoder::create(const uint8_t* buffer, size_t bufferSize, void (*bufferDeallocator)(const uint8_t*, size_t), Vector<Attachment>&& attachments)
+std::unique_ptr<Decoder> Decoder::create(const uint8_t* buffer, size_t bufferSize, Vector<Attachment>&& attachments)
 {
     ASSERT(buffer);
     if (UNLIKELY(!buffer)) {
@@ -54,25 +54,25 @@
         RELEASE_LOG_FAULT(IPC, "Decoder::create() called with a null buffer (bufferSize: %lu)", bufferSize);
         return nullptr;
     }
+    return Decoder::create(copyBuffer(buffer, bufferSize), bufferSize, [](const uint8_t* ptr, size_t) { fastFree(const_cast<uint8_t*>(ptr)); }, WTFMove(attachments)); // NOLINT
+}
 
-    const uint8_t* bufferCopy;
-    if (!bufferDeallocator) {
-        bufferCopy = copyBuffer(buffer, bufferSize);
-        ASSERT(bufferCopy);
-        if (UNLIKELY(!bufferCopy))
-            return nullptr;
-    } else
-        bufferCopy = buffer;
-
-    auto decoder = std::unique_ptr<Decoder>(new Decoder(bufferCopy, bufferSize, bufferDeallocator, WTFMove(attachments)));
+std::unique_ptr<Decoder> Decoder::create(const uint8_t* buffer, size_t bufferSize, BufferDeallocator&& bufferDeallocator, Vector<Attachment>&& attachments)
+{
+    ASSERT(buffer);
+    if (UNLIKELY(!buffer)) {
+        RELEASE_LOG_FAULT(IPC, "Decoder::create() called with a null buffer (bufferSize: %lu)", bufferSize);
+        return nullptr;
+    }
+    auto decoder = std::unique_ptr<Decoder>(new Decoder(buffer, bufferSize, WTFMove(bufferDeallocator), WTFMove(attachments)));
     return decoder->isValid() ? WTFMove(decoder) : nullptr;
 }
 
-Decoder::Decoder(const uint8_t* buffer, size_t bufferSize, void (*bufferDeallocator)(const uint8_t*, size_t), Vector<Attachment>&& attachments)
+Decoder::Decoder(const uint8_t* buffer, size_t bufferSize, BufferDeallocator&& bufferDeallocator, Vector<Attachment>&& attachments)
     : m_buffer { buffer }
     , m_bufferPos { m_buffer }
     , m_bufferEnd { m_buffer + bufferSize }
-    , m_bufferDeallocator { bufferDeallocator }
+    , m_bufferDeallocator { WTFMove(bufferDeallocator) }
     , m_attachments { WTFMove(attachments) }
 {
     if (UNLIKELY(reinterpret_cast<uintptr_t>(m_buffer) % alignof(uint64_t))) {
@@ -94,7 +94,7 @@
     : m_buffer { stream }
     , m_bufferPos { m_buffer }
     , m_bufferEnd { m_buffer + streamSize }
-    , m_bufferDeallocator([] (const uint8_t*, size_t) { })
+    , m_bufferDeallocator { nullptr }
     , m_destinationID(destinationID)
 {
     if (UNLIKELY(!decode(m_messageName)))
@@ -104,12 +104,8 @@
 Decoder::~Decoder()
 {
     ASSERT(m_buffer);
-
     if (m_bufferDeallocator)
         m_bufferDeallocator(m_buffer, m_bufferEnd - m_buffer);
-    else
-        fastFree(const_cast<uint8_t*>(m_buffer));
-
     // FIXME: We need to dispose of the mach ports in cases of failure.
 }
 

Modified: trunk/Source/WebKit/Platform/IPC/Decoder.h (288353 => 288354)


--- trunk/Source/WebKit/Platform/IPC/Decoder.h	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/Platform/IPC/Decoder.h	2022-01-21 08:32:53 UTC (rev 288354)
@@ -27,6 +27,7 @@
 
 #include "Attachment.h"
 #include "MessageNames.h"
+#include <wtf/Function.h>
 #include <wtf/OptionSet.h>
 #include <wtf/Vector.h>
 
@@ -46,7 +47,9 @@
 class Decoder {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static std::unique_ptr<Decoder> create(const uint8_t* buffer, size_t bufferSize, void (*bufferDeallocator)(const uint8_t*, size_t), Vector<Attachment>&&);
+    static std::unique_ptr<Decoder> create(const uint8_t* buffer, size_t bufferSize, Vector<Attachment>&&);
+    using BufferDeallocator = Function<void(const uint8_t*, size_t)>;
+    static std::unique_ptr<Decoder> create(const uint8_t* buffer, size_t bufferSize, BufferDeallocator&&, Vector<Attachment>&&);
     Decoder(const uint8_t* stream, size_t streamSize, uint64_t destinationID);
 
     ~Decoder();
@@ -139,7 +142,7 @@
     static constexpr bool isIPCDecoder = true;
 
 private:
-    Decoder(const uint8_t* buffer, size_t bufferSize, void (*bufferDeallocator)(const uint8_t*, size_t), Vector<Attachment>&&);
+    Decoder(const uint8_t* buffer, size_t bufferSize, BufferDeallocator&&, Vector<Attachment>&&);
 
     bool alignBufferPosition(size_t alignment, size_t);
     bool bufferIsLargeEnoughToContain(size_t alignment, size_t) const;
@@ -147,7 +150,7 @@
     const uint8_t* m_buffer;
     const uint8_t* m_bufferPos;
     const uint8_t* m_bufferEnd;
-    void (*m_bufferDeallocator)(const uint8_t*, size_t);
+    BufferDeallocator m_bufferDeallocator;
 
     Vector<Attachment> m_attachments;
 

Modified: trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm (288353 => 288354)


--- trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm	2022-01-21 08:32:53 UTC (rev 288354)
@@ -426,7 +426,7 @@
             return nullptr;
         }
 
-        return Decoder::create(body, bodySize, nullptr, Vector<Attachment> { });
+        return Decoder::create(body, bodySize, { });
     }
 
     mach_msg_body_t* body = reinterpret_cast<mach_msg_body_t*>(header + 1);
@@ -487,7 +487,7 @@
         return nullptr;
     }
 
-    return Decoder::create(messageBody, messageBodySize, nullptr, WTFMove(attachments));
+    return Decoder::create(messageBody, messageBodySize, WTFMove(attachments));
 }
 
 // The receive buffer size should always include the maximum trailer size.

Modified: trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp (288353 => 288354)


--- trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/Platform/IPC/unix/ConnectionUnix.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -245,7 +245,7 @@
     if (messageInfo.isBodyOutOfLine())
         messageBody = reinterpret_cast<uint8_t*>(oolMessageBody->data());
 
-    auto decoder = Decoder::create(messageBody, messageInfo.bodySize(), nullptr, WTFMove(attachments));
+    auto decoder = Decoder::create(messageBody, messageInfo.bodySize(), WTFMove(attachments));
     ASSERT(decoder);
     if (!decoder)
         return false;

Modified: trunk/Source/WebKit/Platform/IPC/win/ConnectionWin.cpp (288353 => 288354)


--- trunk/Source/WebKit/Platform/IPC/win/ConnectionWin.cpp	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/Platform/IPC/win/ConnectionWin.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -140,7 +140,7 @@
 
         if (!m_readBuffer.isEmpty()) {
             // We have a message, let's dispatch it.
-            auto decoder = Decoder::create(m_readBuffer.data(), m_readBuffer.size(), nullptr, { });
+            auto decoder = Decoder::create(m_readBuffer.data(), m_readBuffer.size(), { });
             ASSERT(decoder);
             if (!decoder)
                 return;

Added: trunk/Source/WebKit/Shared/IPCTester.cpp (0 => 288354)


--- trunk/Source/WebKit/Shared/IPCTester.cpp	                        (rev 0)
+++ trunk/Source/WebKit/Shared/IPCTester.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2021 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 "IPCTester.h"
+
+#if ENABLE(IPC_TESTING_API)
+#include "Connection.h"
+#include "Decoder.h"
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <wtf/CryptographicallyRandomNumber.h>
+#include <wtf/threads/BinarySemaphore.h>
+
+// The tester API.
+extern "C" {
+// Returns 0 if driver should continue.
+typedef int (*WKMessageTestSendMessageFunc)(const uint8_t* data, size_t sz, void* context);
+typedef void (*WKMessageTestDriverFunc)(WKMessageTestSendMessageFunc sendMessageFunc, void* context);
+}
+
+namespace {
+struct SendMessageContext {
+    IPC::Connection& connection;
+    std::atomic<bool>& shouldStop;
+};
+}
+
+extern "C" {
+
+static void defaultTestDriver(WKMessageTestSendMessageFunc sendMessageFunc, void* context)
+{
+    Vector<uint8_t> data(1000);
+    for (int i = 0; i < 1000; i++) {
+        cryptographicallyRandomValues(data.data(), data.size());
+        int ret = sendMessageFunc(data.data(), data.size(), context);
+        if (ret)
+            return;
+    }
+}
+
+static int sendTestMessage(const uint8_t* data, size_t size, void* context)
+{
+    auto messageContext = reinterpret_cast<SendMessageContext*>(context);
+    if (messageContext->shouldStop)
+        return 1;
+    auto& testedConnection = messageContext->connection;
+    if (!testedConnection.isValid())
+        return 1;
+    BinarySemaphore semaphore;
+    auto decoder = IPC::Decoder::create(data, size, [&semaphore] (const uint8_t*, size_t) { semaphore.signal(); }, { }); // NOLINT
+    if (decoder) {
+        testedConnection.dispatchIncomingMessageForTesting(WTFMove(decoder));
+        semaphore.wait();
+    }
+    return 0;
+}
+
+}
+
+namespace WebKit {
+
+static WKMessageTestDriverFunc messageTestDriver(String&& driverName)
+{
+    if (driverName.isEmpty() || driverName == "default")
+        driverName = getenv("WEBKIT_MESSAGE_TEST_DEFAULT_DRIVER");
+    if (driverName.isEmpty() || driverName == "default")
+        return defaultTestDriver;
+    auto testDriver = reinterpret_cast<WKMessageTestDriverFunc>(dlsym(RTLD_DEFAULT, driverName.utf8().data()));
+    RELEASE_ASSERT(testDriver);
+    return testDriver;
+}
+
+static void runMessageTesting(IPC::Connection& connection, std::atomic<bool>& shouldStop, String&& driverName)
+{
+    connection.setIgnoreInvalidMessageForTesting();
+    SendMessageContext context { connection, shouldStop };
+    auto driver = messageTestDriver(WTFMove(driverName));
+    driver(sendTestMessage, &context);
+}
+
+IPCTester::IPCTester() = default;
+
+IPCTester::~IPCTester()
+{
+    stopIfNeeded();
+}
+
+void IPCTester::startMessageTesting(IPC::Connection& connection, String&& driverName)
+{
+    if (!m_testQueue)
+        m_testQueue = WorkQueue::create("IPC testing work queue");
+    m_testQueue->dispatch([connection = Ref { connection }, &shouldStop = m_shouldStop, driverName = WTFMove(driverName)]() mutable {
+        runMessageTesting(connection, shouldStop, WTFMove(driverName));
+    });
+}
+
+void IPCTester::stopMessageTesting(CompletionHandler<void()> completionHandler)
+{
+    stopIfNeeded();
+    completionHandler();
+}
+
+void IPCTester::stopIfNeeded()
+{
+    if (m_testQueue) {
+        m_shouldStop = true;
+        m_testQueue->dispatchSync([] { });
+        m_testQueue = nullptr;
+    }
+}
+
+}
+
+#endif

Added: trunk/Source/WebKit/Shared/IPCTester.h (0 => 288354)


--- trunk/Source/WebKit/Shared/IPCTester.h	                        (rev 0)
+++ trunk/Source/WebKit/Shared/IPCTester.h	2022-01-21 08:32:53 UTC (rev 288354)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2021 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
+
+#if ENABLE(IPC_TESTING_API)
+
+#include "MessageReceiver.h"
+#include <atomic>
+#include <wtf/WorkQueue.h>
+
+namespace WebKit {
+
+class IPCTester final : public IPC::MessageReceiver {
+public:
+    IPCTester();
+    ~IPCTester();
+
+    // IPC::MessageReceiver overrides.
+    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
+    bool didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, UniqueRef<IPC::Encoder>&) final;
+private:
+    // Messages.
+    void startMessageTesting(IPC::Connection&, String&& driverName);
+    void stopMessageTesting(CompletionHandler<void()>);
+
+    void stopIfNeeded();
+
+    RefPtr<WorkQueue> m_testQueue;
+    std::atomic<bool> m_shouldStop { false };
+};
+
+}
+
+#endif

Copied: trunk/Source/WebKit/Shared/IPCTester.messages.in (from rev 288353, trunk/Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.messages.in) (0 => 288354)


--- trunk/Source/WebKit/Shared/IPCTester.messages.in	                        (rev 0)
+++ trunk/Source/WebKit/Shared/IPCTester.messages.in	2022-01-21 08:32:53 UTC (rev 288354)
@@ -0,0 +1,30 @@
+# Copyright (C) 2021 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.
+
+#if ENABLE(IPC_TESTING_API)
+
+messages -> IPCTester NotRefCounted {
+    StartMessageTesting(String driverName) WantsConnection
+    StopMessageTesting() -> () Synchronous
+}
+
+#endif

Modified: trunk/Source/WebKit/Sources.txt (288353 => 288354)


--- trunk/Source/WebKit/Sources.txt	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/Sources.txt	2022-01-21 08:32:53 UTC (rev 288354)
@@ -221,6 +221,7 @@
 Shared/FontInfo.cpp
 Shared/FrameInfoData.cpp
 Shared/InspectorExtensionTypes.cpp
+Shared/IPCTester.cpp
 Shared/LayerTreeContext.cpp
 Shared/LoadParameters.cpp
 Shared/NavigationActionData.cpp
@@ -843,6 +844,7 @@
 
 WebProcess/XR/PlatformXRSystemProxy.cpp
 
+IPCTesterMessageReceiver.cpp
 NetworkBroadcastChannelRegistryMessageReceiver.cpp
 RTCDataChannelRemoteManagerMessageReceiver.cpp
 RTCDataChannelRemoteManagerProxyMessageReceiver.cpp

Modified: trunk/Source/WebKit/UIProcess/LegacySessionStateCodingNone.cpp (288353 => 288354)


--- trunk/Source/WebKit/UIProcess/LegacySessionStateCodingNone.cpp	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/UIProcess/LegacySessionStateCodingNone.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -48,7 +48,7 @@
 
 bool decodeLegacySessionState(const uint8_t* data, size_t dataSize, SessionState& sessionState)
 {
-    auto decoder = IPC::Decoder::create(data, dataSize, nullptr, Vector<IPC::Attachment>());
+    auto decoder = IPC::Decoder::create(data, dataSize, { });
     if (!decoder)
         return false;
 

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (288353 => 288354)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -147,6 +147,10 @@
 #include <wtf/RefCountedLeakCounter.h>
 #endif
 
+#if ENABLE(IPC_TESTING_API)
+#include "IPCTesterMessages.h"
+#endif
+
 #define WEBPROCESSPOOL_RELEASE_LOG(channel, fmt, ...) RELEASE_LOG(channel, "%p - WebProcessPool::" fmt, this, ##__VA_ARGS__)
 #define WEBPROCESSPOOL_RELEASE_LOG_STATIC(channel, fmt, ...) RELEASE_LOG(channel, "WebProcessPool::" fmt, ##__VA_ARGS__)
 #define WEBPROCESSPOOL_RELEASE_LOG_ERROR(channel, fmt, ...) RELEASE_LOG_ERROR(channel, "%p - WebProcessPool::" fmt, this, ##__VA_ARGS__)
@@ -251,6 +255,9 @@
 #endif
 
     addMessageReceiver(Messages::WebProcessPool::messageReceiverName(), *this);
+#if ENABLE(IPC_TESTING_API)
+    addMessageReceiver(Messages::IPCTester::messageReceiverName(), m_ipcTester);
+#endif
 
     // NOTE: These sub-objects must be initialized after m_messageReceiverMap..
     addSupplement<WebGeolocationManagerProxy>();

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.h (288353 => 288354)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.h	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.h	2022-01-21 08:32:53 UTC (rev 288354)
@@ -75,6 +75,11 @@
 #include <pal/system/SystemSleepListener.h>
 #endif
 
+
+#if ENABLE(IPC_TESTING_API)
+#include "IPCTester.h"
+#endif
+
 namespace API {
 class AutomationClient;
 class DownloadClient;
@@ -803,6 +808,9 @@
     std::unique_ptr<WebCore::PowerObserver> m_powerObserver;
     std::unique_ptr<PAL::SystemSleepListener> m_systemSleepListener;
 #endif
+#if ENABLE(IPC_TESTING_API)
+    IPCTester m_ipcTester;
+#endif
 };
 
 template<typename T>

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (288353 => 288354)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -464,7 +464,7 @@
     if (message.encoder->messageName() == IPC::MessageName::WebPage_LoadRequestWaitingForProcessLaunch) {
         auto buffer = message.encoder->buffer();
         auto bufferSize = message.encoder->bufferSize();
-        auto decoder = IPC::Decoder::create(buffer, bufferSize, nullptr, { });
+        auto decoder = IPC::Decoder::create(buffer, bufferSize, { });
         ASSERT(decoder);
         if (!decoder)
             return false;

Modified: trunk/Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.cpp (288353 => 288354)


--- trunk/Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.cpp	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -33,6 +33,10 @@
 #include "WebAuthnProcess.h"
 #include <WebCore/AuthenticatorResponseData.h>
 
+#if ENABLE(IPC_TESTING_API)
+#include "IPCTesterMessages.h"
+#endif
+
 namespace WebKit {
 using namespace WebCore;
 
@@ -67,6 +71,29 @@
     CRASH();
 }
 
+bool WebAuthnConnectionToWebProcess::dispatchMessage(IPC::Connection& connection, IPC::Decoder& decoder)
+{
+#if ENABLE(IPC_TESTING_API)
+    if (decoder.messageReceiverName() == Messages::IPCTester::messageReceiverName()) {
+        m_ipcTester.didReceiveMessage(connection, decoder);
+        return true;
+    }
+#endif
+    return false;
+}
+
+bool WebAuthnConnectionToWebProcess::dispatchSyncMessage(IPC::Connection& connection, IPC::Decoder& decoder, UniqueRef<IPC::Encoder>& replyEncoder)
+{
+#if ENABLE(IPC_TESTING_API)
+    if (decoder.messageReceiverName() == Messages::IPCTester::messageReceiverName()) {
+        m_ipcTester.didReceiveSyncMessage(connection, decoder, replyEncoder);
+        return true;
+    }
+#endif
+    return false;
+}
+
+
 void WebAuthnConnectionToWebProcess::makeCredential(Vector<uint8_t>&& hash, PublicKeyCredentialCreationOptions&& options, bool processingUserGesture, RequestCompletionHandler&& handler)
 {
     handleRequest({ WTFMove(hash), WTFMove(options), nullptr, WebAuthenticationPanelResult::Unavailable, nullptr, std::nullopt, { }, processingUserGesture, String(), nullptr }, WTFMove(handler));

Modified: trunk/Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.h (288353 => 288354)


--- trunk/Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.h	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.h	2022-01-21 08:32:53 UTC (rev 288354)
@@ -32,6 +32,10 @@
 #include <WebCore/ProcessIdentifier.h>
 #include <wtf/RefCounted.h>
 
+#if ENABLE(IPC_TESTING_API)
+#include "IPCTester.h"
+#endif
+
 namespace WebCore {
 enum class AuthenticatorAttachment;
 struct AuthenticatorResponseData;
@@ -67,7 +71,11 @@
     void didClose(IPC::Connection&) final;
     void didReceiveInvalidMessage(IPC::Connection&, IPC::MessageName) final;
     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
+    bool didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, UniqueRef<IPC::Encoder>&);
 
+    bool dispatchMessage(IPC::Connection&, IPC::Decoder&);
+    bool dispatchSyncMessage(IPC::Connection&, IPC::Decoder&, UniqueRef<IPC::Encoder>&);
+
     // Receivers.
     void makeCredential(Vector<uint8_t>&& hash, WebCore::PublicKeyCredentialCreationOptions&&, bool processingUserGesture, RequestCompletionHandler&&);
     void getAssertion(Vector<uint8_t>&& hash, WebCore::PublicKeyCredentialRequestOptions&&, bool processingUserGesture, RequestCompletionHandler&&);
@@ -79,6 +87,9 @@
     Ref<IPC::Connection> m_connection;
     Ref<WebAuthnProcess> m_WebAuthnProcess;
     const WebCore::ProcessIdentifier m_webProcessIdentifier;
+#if ENABLE(IPC_TESTING_API)
+    IPCTester m_ipcTester;
+#endif
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.messages.in (288353 => 288354)


--- trunk/Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.messages.in	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/WebAuthnProcess/WebAuthnConnectionToWebProcess.messages.in	2022-01-21 08:32:53 UTC (rev 288354)
@@ -22,7 +22,7 @@
 
 #if ENABLE(WEB_AUTHN)
 
-messages -> WebAuthnConnectionToWebProcess {
+messages -> WebAuthnConnectionToWebProcess WantsDispatchMessage {
 
     MakeCredential(Vector<uint8_t> hash, struct WebCore::PublicKeyCredentialCreationOptions options, bool processingUserGesture) -> (struct WebCore::AuthenticatorResponseData data, enum:int WebCore::AuthenticatorAttachment attachment, struct WebCore::ExceptionData exception) Async
     GetAssertion(Vector<uint8_t> hash, struct WebCore::PublicKeyCredentialRequestOptions options, bool processingUserGesture) -> (struct WebCore::AuthenticatorResponseData data, enum:int WebCore::AuthenticatorAttachment attachment, struct WebCore::ExceptionData exception) Async

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (288353 => 288354)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-01-21 08:32:53 UTC (rev 288354)
@@ -1318,6 +1318,7 @@
 		7B73124225CC8525003B2796 /* StreamConnectionEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B73123925CC8525003B2796 /* StreamConnectionEncoder.h */; };
 		7BAB111025DD02B3008FC479 /* ScopedActiveMessageReceiveQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BAB110F25DD02B2008FC479 /* ScopedActiveMessageReceiveQueue.h */; };
 		7BCF70DE2615D06E00E4FB70 /* ScopedRenderingResourcesRequestCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7BCF70CB2614935E00E4FB70 /* ScopedRenderingResourcesRequestCocoa.mm */; };
+		7BDDA3192747C0400038659E /* (null) in Headers */ = {isa = PBXBuildFile; };
 		7C065F2C1C8CD95F00C2D950 /* WebUserContentControllerDataTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C065F2A1C8CD95F00C2D950 /* WebUserContentControllerDataTypes.h */; };
 		7C135AA9173B0BCA00586AE2 /* WKPluginInformation.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C135AA7173B0BCA00586AE2 /* WKPluginInformation.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7C1BA33E1A4A0E600043E249 /* APIDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C1BA33C1A4A0E600043E249 /* APIDictionary.h */; };
@@ -5046,6 +5047,8 @@
 		7B483F1C25CDDA9B00120486 /* MessageReceiveQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageReceiveQueue.h; sourceTree = "<group>"; };
 		7B483F1D25CDDA9B00120486 /* MessageReceiveQueueMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MessageReceiveQueueMap.cpp; sourceTree = "<group>"; };
 		7B483F1E25CDDA9B00120486 /* MessageReceiveQueues.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageReceiveQueues.h; sourceTree = "<group>"; };
+		7B50E97F2771F6CE003DAAC4 /* IPCTester.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = IPCTester.cpp; sourceTree = "<group>"; };
+		7B50E9802771F6CF003DAAC4 /* IPCTester.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IPCTester.h; sourceTree = "<group>"; };
 		7B64C0B6254C5C250006B4AF /* GraphicsContextGLIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLIdentifier.h; sourceTree = "<group>"; };
 		7B73123125CC8523003B2796 /* StreamConnectionBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamConnectionBuffer.h; sourceTree = "<group>"; };
 		7B73123225CC8523003B2796 /* StreamConnectionWorkQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamConnectionWorkQueue.cpp; sourceTree = "<group>"; };
@@ -7104,6 +7107,8 @@
 				118502602673B0DA00A6425E /* XR */,
 				E3BCE877267252120011D8DB /* AccessibilityPreferences.cpp */,
 				E3BCE878267252120011D8DB /* AccessibilityPreferences.h */,
+				7B50E97F2771F6CE003DAAC4 /* IPCTester.cpp */,
+				7B50E9802771F6CF003DAAC4 /* IPCTester.h */,
 				A7D792D51767CB6E00881CBE /* ActivityAssertion.cpp */,
 				A7D792D41767CB0900881CBE /* ActivityAssertion.h */,
 				BC329D9A16ACCE9900316DE2 /* APIWebArchive.h */,
@@ -12975,6 +12980,7 @@
 				C5BCE5DF1C50766A00CDE3FA /* InteractionInformationAtPosition.h in Headers */,
 				2D4D2C811DF60BF3002EB10C /* InteractionInformationRequest.h in Headers */,
 				A31F60A425CC7DB900AF14F4 /* IPCSemaphore.h in Headers */,
+				7BDDA3192747C0400038659E /* (null) in Headers */,
 				9B47908F253151CC00EC11AB /* JSIPCBinding.h in Headers */,
 				C1663E5B24AEAA2F00C6A3B2 /* LaunchServicesDatabaseXPCConstants.h in Headers */,
 				BCE0937814FB128C001138D9 /* LayerHostingContext.h in Headers */,

Modified: trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp (288353 => 288354)


--- trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp	2022-01-21 06:38:30 UTC (rev 288353)
+++ trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp	2022-01-21 08:32:53 UTC (rev 288354)
@@ -1886,7 +1886,7 @@
     auto* globalObject = toJS(m_context);
     JSC::JSLockHolder lock(globalObject->vm());
 
-    auto mutableDecoder = IPC::Decoder::create(decoder.buffer(), decoder.length(), nullptr, { });
+    auto mutableDecoder = IPC::Decoder::create(decoder.buffer(), decoder.length(), { });
     auto* description = jsDescriptionFromDecoder(globalObject, *mutableDecoder);
 
     JSValueRef arguments[] = { description ? toRef(globalObject, description) : JSValueMakeUndefined(m_context) };
@@ -1903,7 +1903,7 @@
     auto* globalObject = toJS(m_context);
     JSC::JSLockHolder lock(globalObject->vm());
 
-    auto decoder = IPC::Decoder::create(encoder.buffer(), encoder.bufferSize(), nullptr, { });
+    auto decoder = IPC::Decoder::create(encoder.buffer(), encoder.bufferSize(), { });
     auto* description = jsDescriptionFromDecoder(globalObject, *decoder);
 
     JSValueRef arguments[] = { description ? toRef(globalObject, description) : JSValueMakeUndefined(m_context) };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to