Title: [293723] trunk
Revision
293723
Author
[email protected]
Date
2022-05-03 07:16:55 -0700 (Tue, 03 May 2022)

Log Message

IPC stream connection sends should fail immediately when connection closes
https://bugs.webkit.org/show_bug.cgi?id=238253

Patch by Kimmo Kinnunen <[email protected]> on 2022-05-03
Reviewed by Simon Fraser.

Source/WebKit:

Send the StreamClientConnection client wait semaphore from
StreamServerConnection. This way the client will fail the wait
when the server crashes.

Test: ipc/stream-sync-crash-no-timeout.html

* GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
(WebKit::RemoteGraphicsContextGL::workQueueInitialize):
* GPUProcess/graphics/RemoteRenderingBackend.cpp:
(WebKit::RemoteRenderingBackend::startListeningForIPC):
* GPUProcess/graphics/WebGPU/RemoteGPU.cpp:
(WebKit::RemoteGPU::workQueueInitialize):
* Platform/IPC/StreamClientConnection.cpp:
(IPC::StreamClientConnection::setSemaphores):
(IPC::StreamClientConnection::wakeUpServer):
* Platform/IPC/StreamClientConnection.h:
(IPC::StreamClientConnection::tryAcquire):
(IPC::StreamClientConnection::tryAcquireAll):
* Platform/IPC/StreamConnectionBuffer.cpp:
(IPC::StreamConnectionBuffer::StreamConnectionBuffer):
(IPC::StreamConnectionBuffer::operator=):
(IPC::StreamConnectionBuffer::encode const):
(IPC::StreamConnectionBuffer::decode):
* Platform/IPC/StreamConnectionBuffer.h:
(IPC::StreamConnectionBuffer::dataSize const):
* Platform/IPC/StreamServerConnection.cpp:
(IPC::StreamServerConnection::release):
(IPC::StreamServerConnection::releaseAll):
* Platform/IPC/StreamServerConnection.h:
* Shared/IPCStreamTester.cpp:
(WebKit::IPCStreamTester::initialize):
(WebKit::IPCStreamTester::syncCrashOnZero):
* Shared/IPCStreamTester.h:
* Shared/IPCStreamTester.messages.in:
* Shared/IPCStreamTesterProxy.h:
* Shared/IPCStreamTesterProxy.messages.in:
* WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:
(WebKit::RemoteGraphicsContextGLProxy::wasCreated):
* WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h:
* WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in:
* WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
(WebKit::RemoteRenderingBackendProxy::streamConnection):
(WebKit::RemoteRenderingBackendProxy::didInitialize):
* WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:
* WebProcess/GPU/graphics/RemoteRenderingBackendProxy.messages.in:
* WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.cpp:
(WebKit::RemoteGPUProxy::wasCreated):
* WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.h:
* WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.messages.in:
* WebProcess/WebPage/IPCTestingAPI.cpp:
(WebKit::IPCTestingAPI::JSIPCStreamClientConnection::setSemaphores):
(WebKit::IPCTestingAPI::JSIPCStreamClientConnection::staticFunctions):
(WebKit::IPCTestingAPI::JSIPCStreamClientConnection::sendIPCStreamTesterSyncCrashOnZero):

LayoutTests:

The test works on minibrowser but GPUP startup code fails in run-webkit-tests,
thus disabled.

* TestExpectations:
* ipc/stream-sync-crash-no-timeout-expected.txt: Added.
* ipc/stream-sync-crash-no-timeout.html: Added.
* ipc/stream-sync-reply-shared-memory.html: Adjust after API change.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (293722 => 293723)


--- trunk/LayoutTests/ChangeLog	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/LayoutTests/ChangeLog	2022-05-03 14:16:55 UTC (rev 293723)
@@ -1,3 +1,18 @@
+2022-05-03  Kimmo Kinnunen  <[email protected]>
+
+        IPC stream connection sends should fail immediately when connection closes
+        https://bugs.webkit.org/show_bug.cgi?id=238253
+
+        Reviewed by Simon Fraser.
+
+        The test works on minibrowser but GPUP startup code fails in run-webkit-tests,
+        thus disabled.
+
+        * TestExpectations:
+        * ipc/stream-sync-crash-no-timeout-expected.txt: Added.
+        * ipc/stream-sync-crash-no-timeout.html: Added.
+        * ipc/stream-sync-reply-shared-memory.html: Adjust after API change.
+
 2022-05-03  Youenn Fablet  <[email protected]>
 
         ServiceWorkerRegistration update should fail if called from an installing service worker context

Modified: trunk/LayoutTests/TestExpectations (293722 => 293723)


--- trunk/LayoutTests/TestExpectations	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/LayoutTests/TestExpectations	2022-05-03 14:16:55 UTC (rev 293723)
@@ -5093,6 +5093,9 @@
 # IPC test failing in Debug mode due to assert.
 [ Debug ] ipc/send-invalid-message.html [ Skip ]
 
+# Restarted GPUP seems to crash.
+webkit.org/b/239959 ipc/stream-sync-crash-no-timeout.html [ Skip ]
+
 # The test invokes random messages, potentially produces random results.
 ipc/start-message-testing.html [ Skip ]
 

Added: trunk/LayoutTests/ipc/stream-sync-crash-no-timeout-expected.txt (0 => 293723)


--- trunk/LayoutTests/ipc/stream-sync-crash-no-timeout-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/ipc/stream-sync-crash-no-timeout-expected.txt	2022-05-03 14:16:55 UTC (rev 293723)
@@ -0,0 +1,4 @@
+CONSOLE MESSAGE: TypeError: Bad type name
+
+FAIL Test that stream sync message crash is noticed immediately TypeError: Bad type name
+

Added: trunk/LayoutTests/ipc/stream-sync-crash-no-timeout.html (0 => 293723)


--- trunk/LayoutTests/ipc/stream-sync-crash-no-timeout.html	                        (rev 0)
+++ trunk/LayoutTests/ipc/stream-sync-crash-no-timeout.html	2022-05-03 14:16:55 UTC (rev 293723)
@@ -0,0 +1,37 @@
+<!doctype html><!-- webkit-test-runner [ IPCTestingAPIEnabled=true ] -->
+<title>Test that stream sync message crash is noticed immediately</title>
+<script src=""
+<script src=""
+<body>
+<script>
+setup({ single_test: true });
+if (window.IPC) { // For compiles with !ENABLE(IPC_TESTING_API)
+    const defaultTimeout = 10;
+    const bufferSize = 100;
+    const streamTesterID = 4557;
+    for (const processTarget of IPC.processTargets) {
+        if (processTarget == "UI")
+            continue; // Crashing UI is not supported.
+        const streamConnection = IPC.createStreamClientConnection(processTarget, bufferSize);
+        IPC.sendMessage(processTarget, 0, IPC.messages.IPCTester_CreateStreamTester.name, [
+            { type: 'uint64_t', value: streamTesterID },
+            { type: 'StreamConnectionBuffer', value: streamConnection.streamBuffer() },
+        ]);
+        const arguments = IPC.waitForMessage(processTarget, streamTesterID, IPC.messages.IPCStreamTesterProxy_WasCreated.name, defaultTimeout);
+        streamConnection.setSemaphores(arguments[0].value, arguments[1].value);
+
+        // Test starts here.
+        const result = streamConnection.sendIPCStreamTesterSyncCrashOnZero(streamTesterID, 78, defaultTimeout);
+        assert_equals(result, 78,  `sync messages work for ${ processTarget }`);
+
+        const start = Date.now();
+        assert_throws_js(TypeError,
+            () => { streamConnection.sendIPCStreamTesterSyncCrashOnZero(streamTesterID, 0, defaultTimeout); },
+            `crashing sync message must return failure for ${ processTarget }`);
+        assert_less_than(Date.now() - start, 500, `crashing sync message must complete in 500ms for ${ processTarget }`);
+        console.log(`ttt: ${Date.now() - start}`);
+    }
+}
+done();
+</script>
+</body>
\ No newline at end of file

Modified: trunk/LayoutTests/ipc/stream-sync-reply-shared-memory.html (293722 => 293723)


--- trunk/LayoutTests/ipc/stream-sync-reply-shared-memory.html	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/LayoutTests/ipc/stream-sync-reply-shared-memory.html	2022-05-03 14:16:55 UTC (rev 293723)
@@ -16,7 +16,7 @@
             { type: 'StreamConnectionBuffer', value: streamConnection.streamBuffer() },
         ]);
         const arguments = IPC.waitForMessage(processTarget, streamTesterID, IPC.messages.IPCStreamTesterProxy_WasCreated.name, defaultTimeout);
-        streamConnection.setWakeUpSemaphore(arguments[0].value);
+        streamConnection.setSemaphores(arguments[0].value, arguments[1].value);
 
         // Test starts here.
         try {

Modified: trunk/Source/WebKit/ChangeLog (293722 => 293723)


--- trunk/Source/WebKit/ChangeLog	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/ChangeLog	2022-05-03 14:16:55 UTC (rev 293723)
@@ -1,3 +1,64 @@
+2022-05-03  Kimmo Kinnunen  <[email protected]>
+
+        IPC stream connection sends should fail immediately when connection closes
+        https://bugs.webkit.org/show_bug.cgi?id=238253
+
+        Reviewed by Simon Fraser.
+
+        Send the StreamClientConnection client wait semaphore from
+        StreamServerConnection. This way the client will fail the wait
+        when the server crashes.
+
+        Test: ipc/stream-sync-crash-no-timeout.html
+
+        * GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
+        (WebKit::RemoteGraphicsContextGL::workQueueInitialize):
+        * GPUProcess/graphics/RemoteRenderingBackend.cpp:
+        (WebKit::RemoteRenderingBackend::startListeningForIPC):
+        * GPUProcess/graphics/WebGPU/RemoteGPU.cpp:
+        (WebKit::RemoteGPU::workQueueInitialize):
+        * Platform/IPC/StreamClientConnection.cpp:
+        (IPC::StreamClientConnection::setSemaphores):
+        (IPC::StreamClientConnection::wakeUpServer):
+        * Platform/IPC/StreamClientConnection.h:
+        (IPC::StreamClientConnection::tryAcquire):
+        (IPC::StreamClientConnection::tryAcquireAll):
+        * Platform/IPC/StreamConnectionBuffer.cpp:
+        (IPC::StreamConnectionBuffer::StreamConnectionBuffer):
+        (IPC::StreamConnectionBuffer::operator=):
+        (IPC::StreamConnectionBuffer::encode const):
+        (IPC::StreamConnectionBuffer::decode):
+        * Platform/IPC/StreamConnectionBuffer.h:
+        (IPC::StreamConnectionBuffer::dataSize const):
+        * Platform/IPC/StreamServerConnection.cpp:
+        (IPC::StreamServerConnection::release):
+        (IPC::StreamServerConnection::releaseAll):
+        * Platform/IPC/StreamServerConnection.h:
+        * Shared/IPCStreamTester.cpp:
+        (WebKit::IPCStreamTester::initialize):
+        (WebKit::IPCStreamTester::syncCrashOnZero):
+        * Shared/IPCStreamTester.h:
+        * Shared/IPCStreamTester.messages.in:
+        * Shared/IPCStreamTesterProxy.h:
+        * Shared/IPCStreamTesterProxy.messages.in:
+        * WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:
+        (WebKit::RemoteGraphicsContextGLProxy::wasCreated):
+        * WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h:
+        * WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in:
+        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
+        (WebKit::RemoteRenderingBackendProxy::streamConnection):
+        (WebKit::RemoteRenderingBackendProxy::didInitialize):
+        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h:
+        * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.messages.in:
+        * WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.cpp:
+        (WebKit::RemoteGPUProxy::wasCreated):
+        * WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.h:
+        * WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.messages.in:
+        * WebProcess/WebPage/IPCTestingAPI.cpp:
+        (WebKit::IPCTestingAPI::JSIPCStreamClientConnection::setSemaphores):
+        (WebKit::IPCTestingAPI::JSIPCStreamClientConnection::staticFunctions):
+        (WebKit::IPCTestingAPI::JSIPCStreamClientConnection::sendIPCStreamTesterSyncCrashOnZero):
+
 2022-05-02  Tim Horton  <[email protected]>
 
         REGRESSION (r292351): Processes no longer get the right jetsam priority on iOS

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp (293722 => 293723)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp	2022-05-03 14:16:55 UTC (rev 293723)
@@ -131,9 +131,9 @@
         m_context->setClient(this);
         String extensions = m_context->getString(GraphicsContextGL::EXTENSIONS);
         String requestableExtensions = m_context->getString(GraphicsContextGL::REQUESTABLE_EXTENSIONS_ANGLE);
-        send(Messages::RemoteGraphicsContextGLProxy::WasCreated(true, remoteGraphicsContextGLStreamWorkQueue().wakeUpSemaphore(), extensions, requestableExtensions));
+        send(Messages::RemoteGraphicsContextGLProxy::WasCreated(true, remoteGraphicsContextGLStreamWorkQueue().wakeUpSemaphore(), m_streamConnection->clientWaitSemaphore(), extensions, requestableExtensions));
     } else
-        send(Messages::RemoteGraphicsContextGLProxy::WasCreated(false, IPC::Semaphore { }, emptyString(), emptyString()));
+        send(Messages::RemoteGraphicsContextGLProxy::WasCreated(false, { }, { }, emptyString(), emptyString()));
 }
 
 void RemoteGraphicsContextGL::workQueueUninitialize()

Modified: trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp (293722 => 293723)


--- trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp	2022-05-03 14:16:55 UTC (rev 293723)
@@ -111,7 +111,7 @@
     }
     m_streamConnection->startReceivingMessages(*this, Messages::RemoteRenderingBackend::messageReceiverName(), m_renderingBackendIdentifier.toUInt64());
     m_streamConnection->open();
-    send(Messages::RemoteRenderingBackendProxy::DidCreateWakeUpSemaphoreForDisplayListStream(m_workQueue->wakeUpSemaphore()), m_renderingBackendIdentifier);
+    send(Messages::RemoteRenderingBackendProxy::DidInitialize(m_workQueue->wakeUpSemaphore(), m_streamConnection->clientWaitSemaphore()), m_renderingBackendIdentifier);
 }
 
 void RemoteRenderingBackend::stopListeningForIPC()

Modified: trunk/Source/WebKit/GPUProcess/graphics/WebGPU/RemoteGPU.cpp (293722 => 293723)


--- trunk/Source/WebKit/GPUProcess/graphics/WebGPU/RemoteGPU.cpp	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/GPUProcess/graphics/WebGPU/RemoteGPU.cpp	2022-05-03 14:16:55 UTC (rev 293723)
@@ -94,9 +94,9 @@
 #endif
     if (backing) {
         m_backing = backing.releaseNonNull();
-        send(Messages::RemoteGPUProxy::WasCreated(true, workQueue().wakeUpSemaphore()));
+        send(Messages::RemoteGPUProxy::WasCreated(true, workQueue().wakeUpSemaphore(), m_streamConnection->clientWaitSemaphore()));
     } else
-        send(Messages::RemoteGPUProxy::WasCreated(false, workQueue().wakeUpSemaphore()));
+        send(Messages::RemoteGPUProxy::WasCreated(false, { }, { }));
 }
 
 void RemoteGPU::workQueueUninitialize()

Modified: trunk/Source/WebKit/Platform/IPC/StreamClientConnection.cpp (293722 => 293723)


--- trunk/Source/WebKit/Platform/IPC/StreamClientConnection.cpp	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/Platform/IPC/StreamClientConnection.cpp	2022-05-03 14:16:55 UTC (rev 293723)
@@ -96,18 +96,18 @@
         m_connection->invalidate();
 }
 
-void StreamClientConnection::setWakeUpSemaphore(IPC::Semaphore&& semaphore)
+void StreamClientConnection::setSemaphores(IPC::Semaphore&& wakeUp, IPC::Semaphore&& clientWait)
 {
-    m_wakeUpSemaphore = WTFMove(semaphore);
+    m_semaphores = { WTFMove(wakeUp), WTFMove(clientWait) };
     wakeUpServer();
 }
 
 void StreamClientConnection::wakeUpServer()
 {
-    if (!m_wakeUpSemaphore)
+    if (!m_semaphores)
         return;
 
-    m_wakeUpSemaphore->signal();
+    m_semaphores->wakeUp.signal();
     m_remainingMessageCountBeforeSendingWakeUp = 0;
 }
 

Modified: trunk/Source/WebKit/Platform/IPC/StreamClientConnection.h (293722 => 293723)


--- trunk/Source/WebKit/Platform/IPC/StreamClientConnection.h	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/Platform/IPC/StreamClientConnection.h	2022-05-03 14:16:55 UTC (rev 293723)
@@ -83,8 +83,8 @@
     ~StreamClientConnection();
 
     StreamConnectionBuffer& streamBuffer() { return m_buffer; }
-    void setWakeUpSemaphore(IPC::Semaphore&&);
-    bool hasWakeUpSemaphore() const { return m_wakeUpSemaphore.has_value(); }
+    void setSemaphores(IPC::Semaphore&& wakeUp, IPC::Semaphore&& clientWait);
+    bool hasSemaphores() const { return m_semaphores.has_value(); }
 
     void setWakeUpMessageHysteresis(unsigned hysteresis)
     {
@@ -155,7 +155,11 @@
     uint64_t m_currentDestinationID { 0 };
     size_t m_clientOffset { 0 };
     StreamConnectionBuffer m_buffer;
-    std::optional<Semaphore> m_wakeUpSemaphore;
+    struct Semaphores {
+        Semaphore wakeUp;
+        Semaphore clientWait;
+    };
+    std::optional<Semaphores> m_semaphores;
     unsigned m_remainingMessageCountBeforeSendingWakeUp { 0 };
     unsigned m_wakeUpMessageHysteresis { 0 };
 
@@ -307,7 +311,8 @@
             break;
         ClientLimit oldClientLimit = sharedClientLimit().compareExchangeStrong(clientLimit, ClientLimit::clientIsWaitingTag, std::memory_order_acq_rel, std::memory_order_acq_rel);
         if (clientLimit == oldClientLimit) {
-            m_buffer.clientWaitSemaphore().waitFor(timeout);
+            if (!m_semaphores || !m_semaphores->clientWait.waitFor(timeout))
+                return std::nullopt;
             clientLimit = sharedClientLimit().load(std::memory_order_acquire);
         } else
             clientLimit = oldClientLimit;
@@ -338,7 +343,8 @@
         if (!clientLimit && (clientOffset == ClientOffset::serverIsSleepingTag || !clientOffset))
             break;
 
-        m_buffer.clientWaitSemaphore().waitFor(timeout);
+        if (!m_semaphores || !m_semaphores->clientWait.waitFor(timeout))
+            return std::nullopt;
         if (timeout.didTimeOut())
             return std::nullopt;
     }

Modified: trunk/Source/WebKit/Platform/IPC/StreamConnectionBuffer.cpp (293722 => 293723)


--- trunk/Source/WebKit/Platform/IPC/StreamConnectionBuffer.cpp	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/Platform/IPC/StreamConnectionBuffer.cpp	2022-05-03 14:16:55 UTC (rev 293723)
@@ -46,10 +46,9 @@
     ASSERT(m_dataSize <= maximumSize());
 }
 
-StreamConnectionBuffer::StreamConnectionBuffer(Ref<WebKit::SharedMemory>&& memory, size_t memorySize, Semaphore&& clientWaitSemaphore)
+StreamConnectionBuffer::StreamConnectionBuffer(Ref<WebKit::SharedMemory>&& memory, size_t memorySize)
     : m_dataSize(memorySize - headerSize())
     , m_sharedMemory(WTFMove(memory))
-    , m_clientWaitSemaphore(WTFMove(clientWaitSemaphore))
 {
     ASSERT(m_dataSize > 0);
     ASSERT(m_dataSize <= maximumSize());
@@ -64,7 +63,6 @@
     if (this != &other) {
         m_dataSize = other.m_dataSize;
         m_sharedMemory = WTFMove(other.m_sharedMemory);
-        m_clientWaitSemaphore = WTFMove(other.m_clientWaitSemaphore);
     }
     return *this;
 }
@@ -76,7 +74,6 @@
         CRASH();
     WebKit::SharedMemory::IPCHandle ipcHandle { WTFMove(handle), m_sharedMemory->size() };
     encoder << ipcHandle;
-    encoder << m_clientWaitSemaphore;
 }
 
 std::optional<StreamConnectionBuffer> StreamConnectionBuffer::decode(Decoder& decoder)
@@ -85,10 +82,6 @@
     decoder >> ipcHandle;
     if (!ipcHandle)
         return std::nullopt;
-    std::optional<Semaphore> semaphore;
-    decoder >> semaphore;
-    if (!semaphore)
-        return std::nullopt;
     size_t dataSize = static_cast<size_t>(ipcHandle->dataSize);
     if (dataSize <= headerSize())
         return std::nullopt;
@@ -97,7 +90,7 @@
     auto sharedMemory = WebKit::SharedMemory::map(ipcHandle->handle, WebKit::SharedMemory::Protection::ReadWrite);
     if (sharedMemory->size() < dataSize)
         return std::nullopt;
-    return StreamConnectionBuffer { sharedMemory.releaseNonNull(), dataSize,  WTFMove(*semaphore) };
+    return StreamConnectionBuffer { sharedMemory.releaseNonNull(), dataSize };
 }
 
 Span<uint8_t> StreamConnectionBuffer::headerForTesting()

Modified: trunk/Source/WebKit/Platform/IPC/StreamConnectionBuffer.h (293722 => 293723)


--- trunk/Source/WebKit/Platform/IPC/StreamConnectionBuffer.h	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/Platform/IPC/StreamConnectionBuffer.h	2022-05-03 14:16:55 UTC (rev 293723)
@@ -26,7 +26,6 @@
 #pragma once
 
 #include "Decoder.h"
-#include "IPCSemaphore.h"
 #include "SharedMemory.h"
 #include <wtf/Atomics.h>
 
@@ -109,7 +108,6 @@
     Atomic<ServerOffset>& serverOffset() { return header().serverOffset; }
     uint8_t* data() const { return static_cast<uint8_t*>(m_sharedMemory->data()) + headerSize(); }
     size_t dataSize() const { return m_dataSize; }
-    Semaphore& clientWaitSemaphore() { return m_clientWaitSemaphore; }
 
     static constexpr size_t maximumSize() { return std::min(static_cast<size_t>(ClientOffset::serverIsSleepingTag), static_cast<size_t>(ClientOffset::serverIsSleepingTag)) - 1; }
     void encode(Encoder&) const;
@@ -119,7 +117,7 @@
     Span<uint8_t> dataForTesting();
 
 private:
-    StreamConnectionBuffer(Ref<WebKit::SharedMemory>&&, size_t memorySize, Semaphore&& clientWaitSemaphore);
+    StreamConnectionBuffer(Ref<WebKit::SharedMemory>&&, size_t memorySize);
 
     struct Header {
         Atomic<ServerOffset> serverOffset;
@@ -132,7 +130,6 @@
 
     size_t m_dataSize { 0 };
     Ref<WebKit::SharedMemory> m_sharedMemory;
-    Semaphore m_clientWaitSemaphore;
 };
 
 }

Modified: trunk/Source/WebKit/Platform/IPC/StreamServerConnection.cpp (293722 => 293723)


--- trunk/Source/WebKit/Platform/IPC/StreamServerConnection.cpp	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/Platform/IPC/StreamServerConnection.cpp	2022-05-03 14:16:55 UTC (rev 293723)
@@ -172,7 +172,7 @@
     ServerOffset oldServerOffset = sharedServerOffset().exchange(serverOffset, std::memory_order_acq_rel);
     // If the client wrote over serverOffset, it means the client is waiting.
     if (oldServerOffset == ServerOffset::clientIsWaitingTag)
-        m_buffer.clientWaitSemaphore().signal();
+        m_clientWaitSemaphore.signal();
     else
         ASSERT(!(oldServerOffset & ServerOffset::clientIsWaitingTag));
 
@@ -185,7 +185,7 @@
     ServerOffset oldServerOffset = sharedServerOffset().exchange(static_cast<ServerOffset>(0), std::memory_order_acq_rel);
     // If the client wrote over serverOffset, it means the client is waiting.
     if (oldServerOffset == ServerOffset::clientIsWaitingTag)
-        m_buffer.clientWaitSemaphore().signal();
+        m_clientWaitSemaphore.signal();
     else
         ASSERT(!(oldServerOffset & ServerOffset::clientIsWaitingTag));
     m_serverOffset = 0;

Modified: trunk/Source/WebKit/Platform/IPC/StreamServerConnection.h (293722 => 293723)


--- trunk/Source/WebKit/Platform/IPC/StreamServerConnection.h	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/Platform/IPC/StreamServerConnection.h	2022-05-03 14:16:55 UTC (rev 293723)
@@ -28,6 +28,7 @@
 #include "Connection.h"
 #include "Decoder.h"
 #include "Encoder.h"
+#include "IPCSemaphore.h"
 #include "MessageNames.h"
 #include "StreamConnectionBuffer.h"
 #include "StreamConnectionEncoder.h"
@@ -86,6 +87,8 @@
     template<typename T, typename... Arguments>
     void sendSyncReply(Connection::SyncRequestID, Arguments&&...);
 
+    Semaphore& clientWaitSemaphore() { return m_clientWaitSemaphore; }
+
 private:
     enum class HasDedicatedConnection : bool { No, Yes };
     StreamServerConnection(Ref<Connection>&&, StreamConnectionBuffer&&, StreamConnectionWorkQueue&, HasDedicatedConnection);
@@ -120,6 +123,7 @@
     bool dispatchOutOfStreamMessage(Decoder&&);
 
     Ref<IPC::Connection> m_connection;
+    Semaphore m_clientWaitSemaphore;
     StreamConnectionWorkQueue& m_workQueue;
 
     size_t m_serverOffset { 0 };

Modified: trunk/Source/WebKit/Shared/IPCStreamTester.cpp (293722 => 293723)


--- trunk/Source/WebKit/Shared/IPCStreamTester.cpp	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/Shared/IPCStreamTester.cpp	2022-05-03 14:16:55 UTC (rev 293723)
@@ -57,7 +57,7 @@
     m_streamConnection->startReceivingMessages(*this, Messages::IPCStreamTester::messageReceiverName(), m_identifier.toUInt64());
     m_streamConnection->open();
     workQueue().dispatch([this] {
-        m_streamConnection->connection().send(Messages::IPCStreamTesterProxy::WasCreated(workQueue().wakeUpSemaphore()), m_identifier);
+        m_streamConnection->connection().send(Messages::IPCStreamTesterProxy::WasCreated(workQueue().wakeUpSemaphore(), m_streamConnection->clientWaitSemaphore()), m_identifier);
     });
 }
 
@@ -87,6 +87,20 @@
     completionHandler(WTFMove(result));
 }
 
+void IPCStreamTester::syncCrashOnZero(int32_t value, CompletionHandler<void(int32_t)>&& completionHandler)
+{
+    if (!value) {
+        // Use exit so that we don't leave a crash report.
+#if OS(WINDOWS)
+        // Calling _exit in non-main threads may cause a deadlock in WTF::Thread::ThreadHolder::~ThreadHolder.
+        TerminateProcess(GetCurrentProcess(), EXIT_SUCCESS);
+#else
+        _exit(EXIT_SUCCESS);
+#endif
+    }
+    completionHandler(value);
 }
 
+}
+
 #endif

Modified: trunk/Source/WebKit/Shared/IPCStreamTester.h (293722 => 293723)


--- trunk/Source/WebKit/Shared/IPCStreamTester.h	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/Shared/IPCStreamTester.h	2022-05-03 14:16:55 UTC (rev 293723)
@@ -58,6 +58,7 @@
 
     // Messages.
     void syncMessageReturningSharedMemory1(uint32_t byteCount, CompletionHandler<void(SharedMemory::IPCHandle)>&&);
+    void syncCrashOnZero(int32_t, CompletionHandler<void(int32_t)>&&);
 
     const Ref<IPC::StreamConnectionWorkQueue> m_workQueue;
     const Ref<IPC::StreamServerConnection> m_streamConnection;

Modified: trunk/Source/WebKit/Shared/IPCStreamTester.messages.in (293722 => 293723)


--- trunk/Source/WebKit/Shared/IPCStreamTester.messages.in	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/Shared/IPCStreamTester.messages.in	2022-05-03 14:16:55 UTC (rev 293723)
@@ -24,6 +24,7 @@
 
 messages -> IPCStreamTester NotRefCounted Stream {
     SyncMessageReturningSharedMemory1(uint32_t byteCount) -> (WebKit::SharedMemory::IPCHandle handle) Synchronous NotStreamEncodableReply
+    SyncCrashOnZero(int32_t value) -> (int32_t sameValue) Synchronous
 }
 
 #endif

Modified: trunk/Source/WebKit/Shared/IPCStreamTesterProxy.h (293722 => 293723)


--- trunk/Source/WebKit/Shared/IPCStreamTesterProxy.h	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/Shared/IPCStreamTesterProxy.h	2022-05-03 14:16:55 UTC (rev 293723)
@@ -49,7 +49,7 @@
     ~IPCStreamTesterProxy() = default;
 
     // Messages.
-    void wasCreated(IPC::Semaphore&&) { }
+    void wasCreated(IPC::Semaphore&&, IPC::Semaphore&&) { }
 };
 
 }

Modified: trunk/Source/WebKit/Shared/IPCStreamTesterProxy.messages.in (293722 => 293723)


--- trunk/Source/WebKit/Shared/IPCStreamTesterProxy.messages.in	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/Shared/IPCStreamTesterProxy.messages.in	2022-05-03 14:16:55 UTC (rev 293723)
@@ -23,7 +23,7 @@
 #if ENABLE(IPC_TESTING_API)
 
 messages -> IPCStreamTesterProxy NotRefCounted {
-    void WasCreated(IPC::Semaphore streamWakeUpSemaphore)
+    void WasCreated(IPC::Semaphore streamWakeUpSemaphore, IPC::Semaphore streamClientWaitSemaphore)
 }
 
 #endif

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp (293722 => 293723)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp	2022-05-03 14:16:55 UTC (rev 293723)
@@ -317,7 +317,7 @@
     }
 }
 
-void RemoteGraphicsContextGLProxy::wasCreated(bool didSucceed, IPC::Semaphore&& semaphore, String&& availableExtensions, String&& requestedExtensions)
+void RemoteGraphicsContextGLProxy::wasCreated(bool didSucceed, IPC::Semaphore&& wakeUpSemaphore, IPC::Semaphore&& clientWaitSemaphore, String&& availableExtensions, String&& requestedExtensions)
 {
     if (isContextLost())
         return;
@@ -326,7 +326,7 @@
         return;
     }
     ASSERT(!m_didInitialize);
-    m_streamConnection.setWakeUpSemaphore(WTFMove(semaphore));
+    m_streamConnection.setSemaphores(WTFMove(wakeUpSemaphore), WTFMove(clientWaitSemaphore));
     m_didInitialize = true;
     initialize(availableExtensions, requestedExtensions);
 }

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h (293722 => 293723)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h	2022-05-03 14:16:55 UTC (rev 293723)
@@ -346,7 +346,7 @@
     GraphicsContextGLIdentifier m_graphicsContextGLIdentifier { GraphicsContextGLIdentifier::generate() };
 private:
     // Messages to be received.
-    void wasCreated(bool didSucceed, IPC::Semaphore&&, String&& availableExtensions, String&& requestedExtensions);
+    void wasCreated(bool didSucceed, IPC::Semaphore&&, IPC::Semaphore&&, String&& availableExtensions, String&& requestedExtensions);
     void wasLost();
     void wasChanged();
 

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in (293722 => 293723)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in	2022-05-03 14:16:55 UTC (rev 293723)
@@ -23,7 +23,7 @@
 #if ENABLE(GPU_PROCESS) && ENABLE(WEBGL)
 
 messages -> RemoteGraphicsContextGLProxy NotRefCounted {
-    void WasCreated(bool didSucceed, IPC::Semaphore streamWakeUpSemaphore, String availableExtensions, String requestableExtensions)
+    void WasCreated(bool didSucceed, IPC::Semaphore streamWakeUpSemaphore, IPC::Semaphore streamClientWaitSemaphore, String availableExtensions, String requestableExtensions)
     void WasLost()
     void WasChanged()
 }

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp (293722 => 293723)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp	2022-05-03 14:16:55 UTC (rev 293723)
@@ -427,18 +427,18 @@
 IPC::StreamClientConnection& RemoteRenderingBackendProxy::streamConnection()
 {
     ensureGPUProcessConnection();
-    if (UNLIKELY(!m_streamConnection->hasWakeUpSemaphore()))
-        m_streamConnection->waitForAndDispatchImmediately<Messages::RemoteRenderingBackendProxy::DidCreateWakeUpSemaphoreForDisplayListStream>(renderingBackendIdentifier(), 3_s, IPC::WaitForOption::InterruptWaitingIfSyncMessageArrives);
+    if (UNLIKELY(!m_streamConnection->hasSemaphores()))
+        m_streamConnection->waitForAndDispatchImmediately<Messages::RemoteRenderingBackendProxy::DidInitialize>(renderingBackendIdentifier(), 3_s, IPC::WaitForOption::InterruptWaitingIfSyncMessageArrives);
     return *m_streamConnection;
 }
 
-void RemoteRenderingBackendProxy::didCreateWakeUpSemaphoreForDisplayListStream(IPC::Semaphore&& semaphore)
+void RemoteRenderingBackendProxy::didInitialize(IPC::Semaphore&& wakeUp, IPC::Semaphore&& clientWait)
 {
     if (!m_streamConnection) {
         ASSERT_NOT_REACHED();
         return;
     }
-    m_streamConnection->setWakeUpSemaphore(WTFMove(semaphore));
+    m_streamConnection->setSemaphores(WTFMove(wakeUp), WTFMove(clientWait));
 }
 
 bool RemoteRenderingBackendProxy::isCached(const ImageBuffer& imageBuffer) const

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h (293722 => 293723)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h	2022-05-03 14:16:55 UTC (rev 293723)
@@ -133,7 +133,7 @@
 
     bool isGPUProcessConnectionClosed() const { return !m_gpuProcessConnection; }
 
-    void didCreateWakeUpSemaphoreForDisplayListStream(IPC::Semaphore&&);
+    void didInitialize(IPC::Semaphore&& wakeUpSemaphore, IPC::Semaphore&& clientWaitSemaphore);
 
     template<typename T, typename U>
     void sendToStream(T&& message, ObjectIdentifier<U> identifier)

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.messages.in (293722 => 293723)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.messages.in	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.messages.in	2022-05-03 14:16:55 UTC (rev 293723)
@@ -26,7 +26,7 @@
     DidCreateImageBufferBackend(WebKit::ImageBufferBackendHandle handle, WebCore::RenderingResourceIdentifier renderingResourceIdentifier)
     DidFlush(WebCore::GraphicsContextFlushIdentifier flushIdentifier, WebCore::RenderingResourceIdentifier renderingResourceIdentifier)
     DidFinalizeRenderingUpdate(WebKit::RenderingUpdateID didRenderingUpdateID)
-    DidCreateWakeUpSemaphoreForDisplayListStream(IPC::Semaphore wakeUpSemaphore)
+    DidInitialize(IPC::Semaphore wakeUpSemaphore, IPC::Semaphore clientWaitSemaphore)
     DidMarkLayersAsVolatile(WebKit::MarkSurfacesAsVolatileRequestIdentifier requestIdentifier, Vector<WebCore::RenderingResourceIdentifier> markedVolatileBufferIdentifiers, bool didMarkAllLayersAsVolatile)
 }
 

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.cpp (293722 => 293723)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.cpp	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.cpp	2022-05-03 14:16:55 UTC (rev 293723)
@@ -75,10 +75,10 @@
     m_lost = true;
 }
 
-void RemoteGPUProxy::wasCreated(bool didSucceed, IPC::Semaphore&& semaphore)
+void RemoteGPUProxy::wasCreated(bool didSucceed, IPC::Semaphore&& wakeUpSemaphore, IPC::Semaphore&& clientWaitSemaphore)
 {
     ASSERT(!m_didInitialize);
-    m_streamConnection.setWakeUpSemaphore(WTFMove(semaphore));
+    m_streamConnection.setSemaphores(WTFMove(wakeUpSemaphore), WTFMove(clientWaitSemaphore));
     m_didInitialize = true;
     m_lost = !didSucceed;
 }

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.h (293722 => 293723)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.h	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.h	2022-05-03 14:16:55 UTC (rev 293723)
@@ -76,7 +76,7 @@
     void gpuProcessConnectionDidClose(GPUProcessConnection&) final;
 
     // Messages to be received.
-    void wasCreated(bool didSucceed, IPC::Semaphore&&);
+    void wasCreated(bool didSucceed, IPC::Semaphore&& wakeUpSemaphore, IPC::Semaphore&& clientWaitSemaphore);
 
     void waitUntilInitialized();
 

Modified: trunk/Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.messages.in (293722 => 293723)


--- trunk/Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.messages.in	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/WebProcess/GPU/graphics/WebGPU/RemoteGPUProxy.messages.in	2022-05-03 14:16:55 UTC (rev 293723)
@@ -23,7 +23,7 @@
 #if ENABLE(GPU_PROCESS)
 
 messages -> RemoteGPUProxy NotRefCounted {
-    void WasCreated(bool didSucceed, IPC::Semaphore streamWakeUpSemaphore)
+    void WasCreated(bool didSucceed, IPC::Semaphore streamWakeUpSemaphore, IPC::Semaphore streamClientWaitSemaphore)
 }
 
 #endif

Modified: trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp (293722 => 293723)


--- trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp	2022-05-03 13:42:12 UTC (rev 293722)
+++ trunk/Source/WebKit/WebProcess/WebPage/IPCTestingAPI.cpp	2022-05-03 14:16:55 UTC (rev 293723)
@@ -32,6 +32,7 @@
 #include "FrameInfoData.h"
 #include "GPUProcessConnection.h"
 #include "IPCSemaphore.h"
+#include "IPCStreamTesterMessages.h"
 #include "JSIPCBinding.h"
 #include "MessageArgumentDescriptions.h"
 #include "NetworkProcessConnection.h"
@@ -193,7 +194,7 @@
         , m_streamConnection { connection, bufferSize }
     { }
 
-    void setWakeUpSemaphore(JSIPCSemaphore& jsSemaphore) { m_streamConnection.setWakeUpSemaphore(jsSemaphore.exchange()); }
+    void setSemaphores(JSIPCSemaphore& jsWakeUpSemaphore, JSIPCSemaphore& jsClientWaitSemaphore) { m_streamConnection.setSemaphores(jsWakeUpSemaphore.exchange(), jsClientWaitSemaphore.exchange()); }
 
     static JSClassRef wrapperClass();
     static JSIPCStreamClientConnection* unwrap(JSObjectRef);
@@ -204,9 +205,10 @@
 
     static const JSStaticFunction* staticFunctions();
     static JSValueRef streamBuffer(JSContextRef, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
-    static JSValueRef setWakeUpSemaphore(JSContextRef, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+    static JSValueRef setSemaphores(JSContextRef, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
     static JSValueRef sendMessage(JSContextRef, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
     static JSValueRef sendSyncMessage(JSContextRef, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
+    static JSValueRef sendIPCStreamTesterSyncCrashOnZero(JSContextRef, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
 
     WeakPtr<JSIPC> m_jsIPC;
     IPC::StreamClientConnection m_streamConnection;
@@ -854,9 +856,10 @@
 {
     static const JSStaticFunction functions[] = {
         { "streamBuffer", streamBuffer, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
-        { "setWakeUpSemaphore", setWakeUpSemaphore, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
+        { "setSemaphores", setSemaphores, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
         { "sendMessage", sendMessage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
         { "sendSyncMessage", sendSyncMessage, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
+        { "sendIPCStreamTesterSyncCrashOnZero", sendIPCStreamTesterSyncCrashOnZero, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly },
         { 0, 0, 0 }
     };
     return functions;
@@ -875,7 +878,7 @@
     return JSIPCStreamConnectionBuffer::create(*jsStreamConnection)->createJSWrapper(context);
 }
 
-JSValueRef JSIPCStreamClientConnection::setWakeUpSemaphore(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+JSValueRef JSIPCStreamClientConnection::setSemaphores(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     auto* globalObject = toJS(context);
     JSC::JSLockHolder lock(globalObject->vm());
@@ -885,18 +888,24 @@
         return JSValueMakeUndefined(context);
     }
 
-    if (argumentCount < 1) {
-        *exception = createTypeError(context, "Must specify an IPC semaphore as the first argument"_s);
+    if (argumentCount < 2) {
+        *exception = createTypeError(context, "Must specify an IPC semaphore as the first and second argument"_s);
         return JSValueMakeUndefined(context);
     }
 
-    RefPtr jsSemaphore = JSIPCSemaphore::toWrapped(context, arguments[0]);
-    if (!jsSemaphore) {
+    RefPtr jsWakeUpSemaphore = JSIPCSemaphore::toWrapped(context, arguments[0]);
+    if (!jsWakeUpSemaphore) {
         *exception = createTypeError(context, "Wrong type (expected Semaphore)"_s);
         return JSValueMakeUndefined(context);
     }
 
-    jsStreamConnection->setWakeUpSemaphore(*jsSemaphore);
+    RefPtr jsClientWaitSemaphore = JSIPCSemaphore::toWrapped(context, arguments[1]);
+    if (!jsClientWaitSemaphore) {
+        *exception = createTypeError(context, "Wrong type (expected Semaphore)"_s);
+        return JSValueMakeUndefined(context);
+    }
+
+    jsStreamConnection->setSemaphores(*jsWakeUpSemaphore, *jsClientWaitSemaphore);
     return JSValueMakeUndefined(context);
 }
 
@@ -1019,6 +1028,61 @@
     return JSValueMakeUndefined(context);
 }
 
+// FIXME(http://webkit.org/b/237197): Cannot send arbitrary messages, so we hard-code this one to be able to send it.
+JSValueRef JSIPCStreamClientConnection::sendIPCStreamTesterSyncCrashOnZero(JSContextRef context, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    auto* globalObject = toJS(context);
+    JSC::JSLockHolder lock(globalObject->vm());
+
+    RefPtr jsStreamConnection = toWrapped(context, thisObject);
+    if (!jsStreamConnection) {
+        *exception = createTypeError(context, "Wrong type"_s);
+        return JSValueMakeUndefined(context);
+    }
+
+    if (argumentCount < 3) {
+        *exception = createTypeError(context, "Must specify destination ID, value, and timeout as the first three arguments"_s);
+        return JSValueMakeUndefined(context);
+    }
+
+    auto destinationID = destinationIDFromArgument(globalObject, arguments[0], exception);
+    if (!destinationID)
+        return JSValueMakeUndefined(context);
+
+    int32_t value;
+    {
+        auto jsValue = toJS(globalObject, arguments[1]);
+        if (!jsValue.isNumber()) {
+            *exception = createTypeError(context, "value must be a number"_s);
+            return JSValueMakeUndefined(context);
+        }
+        value = static_cast<int32_t>(jsValue.asNumber());
+    }
+
+    Seconds timeoutDuration;
+    {
+        auto jsValue = toJS(globalObject, arguments[2]);
+        if (!jsValue.isNumber()) {
+            *exception = createTypeError(context, "timeout must be a number"_s);
+            return JSValueMakeUndefined(context);
+        }
+        timeoutDuration = Seconds { jsValue.asNumber() };
+    }
+
+    auto& streamConnection = jsStreamConnection->connection();
+    int32_t resultValue = 0;
+    enum JSIPCStreamTesterIdentifierType { };
+    auto destination = makeObjectIdentifier<JSIPCStreamTesterIdentifierType>(*destinationID);
+
+    auto result = streamConnection.sendSync(Messages::IPCStreamTester::SyncCrashOnZero(value), Messages::IPCStreamTester::SyncCrashOnZero::Reply(resultValue), destination, timeoutDuration);
+    if (!result) {
+        *exception = createTypeError(context, "sync send failed"_s);
+        return JSValueMakeUndefined(context);
+    }
+
+    return JSValueMakeNumber(context, resultValue);
+}
+
 JSObjectRef JSIPCStreamConnectionBuffer::createJSWrapper(JSContextRef context)
 {
     auto* globalObject = toJS(context);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to