Skip to content

Commit

Permalink
Convert IPC::Signal to the new IPC serialization format
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=268393

Reviewed by Matt Woodrow.

* Source/WebKit/CMakeLists.txt:
* Source/WebKit/DerivedSources-input.xcfilelist:
* Source/WebKit/DerivedSources.make:
* Source/WebKit/Platform/IPC/IPCEvent.h:
(IPC::Signal::takeSendRight):
(IPC::Signal::semaphore const):
(IPC::Signal::encode): Deleted.
(IPC::Signal::decode): Deleted.
* Source/WebKit/Platform/IPC/IPCEvent.serialization.in: Added.
* Source/WebKit/Platform/IPC/darwin/IPCEventDarwin.cpp:
(IPC::Signal::encode): Deleted.
(IPC::Signal::decode): Deleted.
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:

* Tools/TestWebKitAPI/Tests/IPC/EventTests.cpp:
The test was encoding a single Signal object on sender side. However,
on recipient side, it was decoding first a uint64_t and then a Signal.
I have no idea why it was trying to decode that uint64_t given that we
don't send one. One of the tests started failing on iOS only when
decoding that uint64_t. As a result, I tried dropping the decoding of
this uint64_t in ALL the tests and they are all still passing.

Canonical link: https://commits.webkit.org/273956@main
  • Loading branch information
cdumez committed Feb 2, 2024
1 parent 76bc8f3 commit 4d873d0
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 32 deletions.
1 change: 1 addition & 0 deletions Source/WebKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ set(WebKit_SERIALIZATION_IN_FILES
NetworkProcess/storage/FileSystemStorageError.serialization.in

Platform/IPC/FormDataReference.serialization.in
Platform/IPC/IPCEvent.serialization.in
Platform/IPC/IPCSemaphore.serialization.in
Platform/IPC/ObjectIdentifierReference.serialization.in
Platform/IPC/SharedBufferReference.serialization.in
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/DerivedSources-input.xcfilelist
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ $(PROJECT_DIR)/NetworkProcess/webrtc/NetworkRTCProvider.messages.in
$(PROJECT_DIR)/NetworkProcess/webrtc/RTCDataChannelRemoteManagerProxy.messages.in
$(PROJECT_DIR)/NetworkProcess/webtransport/NetworkTransportSession.messages.in
$(PROJECT_DIR)/Platform/IPC/FormDataReference.serialization.in
$(PROJECT_DIR)/Platform/IPC/IPCEvent.serialization.in
$(PROJECT_DIR)/Platform/IPC/IPCSemaphore.serialization.in
$(PROJECT_DIR)/Platform/IPC/ObjectIdentifierReference.serialization.in
$(PROJECT_DIR)/Platform/IPC/SharedBufferReference.serialization.in
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/DerivedSources.make
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ SERIALIZATION_DESCRIPTION_FILES = \
NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManagerInterface.serialization.in \
NetworkProcess/storage/FileSystemStorageError.serialization.in \
Platform/IPC/FormDataReference.serialization.in \
Platform/IPC/IPCEvent.serialization.in \
Platform/IPC/IPCSemaphore.serialization.in \
Platform/IPC/ObjectIdentifierReference.serialization.in \
Platform/IPC/SharedBufferReference.serialization.in \
Expand Down
20 changes: 5 additions & 15 deletions Source/WebKit/Platform/IPC/IPCEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,20 @@ class Signal {

#if PLATFORM(COCOA)
void signal();
void encode(Encoder&) &&;
static std::optional<Signal> decode(Decoder&);

MachSendRight takeSendRight() { return WTFMove(m_sendRight); }
#else
void signal()
{
m_semaphore.signal();
}

void encode(Encoder& encoder) &&
{
encoder << m_semaphore;
}

static std::optional<Signal> decode(Decoder& decoder)
{
std::optional<Semaphore> semaphore = decoder.decode<Semaphore>();
if (!semaphore)
return std::nullopt;

return Signal(WTFMove(*semaphore));
}
const Semaphore& semaphore() const { return m_semaphore; }
#endif

private:
friend struct IPC::ArgumentCoder<Signal, void>;

friend std::optional<EventSignalPair> createEventSignalPair();

#if PLATFORM(COCOA)
Expand Down
32 changes: 32 additions & 0 deletions Source/WebKit/Platform/IPC/IPCEvent.serialization.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2024 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.

webkit_platform_header: "IPCEvent.h"

[CustomHeader, RValue, WebKitPlatform] class IPC::Signal {
#if PLATFORM(COCOA)
WTF::MachSendRight takeSendRight();
#endif
#if !PLATFORM(COCOA)
IPC::Semaphore semaphore();
#endif
}
15 changes: 0 additions & 15 deletions Source/WebKit/Platform/IPC/darwin/IPCEventDarwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,6 @@ void Signal::signal()
RELEASE_LOG_ERROR(Process, "IPC::Signal::signal Could not send mach message, error %x", ret);
}

void Signal::encode(Encoder& encoder) &&
{
encoder << WTFMove(m_sendRight);
}

std::optional<Signal> Signal::decode(Decoder& decoder)
{
std::optional<MachSendRight> sendRight;
decoder >> sendRight;
if (!sendRight)
return std::nullopt;

return Signal(WTFMove(*sendRight));
}

std::optional<EventSignalPair> createEventSignalPair()
{
// Create the listening port.
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/WebKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5196,6 +5196,7 @@
46B0524522668D2400265B97 /* WebDeviceOrientationAndMotionAccessController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebDeviceOrientationAndMotionAccessController.cpp; sourceTree = "<group>"; };
46B2452428ECA335000A5925 /* WebScreenOrientationManagerProxyIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebScreenOrientationManagerProxyIOS.mm; path = ios/WebScreenOrientationManagerProxyIOS.mm; sourceTree = "<group>"; };
46B9E2372B04228A008346A5 /* LoadParameters.serialization.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = LoadParameters.serialization.in; sourceTree = "<group>"; };
46BB389C2B69764600F02BE0 /* IPCEvent.serialization.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = IPCEvent.serialization.in; sourceTree = "<group>"; };
46C392282316EC4D008EED9B /* WebPageProxyIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebPageProxyIdentifier.h; sourceTree = "<group>"; };
46C5B7CB27AADDBE000C5B47 /* RemoteWorkerLibWebRTCProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteWorkerLibWebRTCProvider.h; sourceTree = "<group>"; };
46C5B7CC27AADDBE000C5B47 /* RemoteWorkerFrameLoaderClient.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteWorkerFrameLoaderClient.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9251,6 +9252,7 @@
465237FA2B055C41005B3097 /* FormDataReference.serialization.in */,
C0CE72AC1247E78D00BC0EC4 /* HandleMessage.h */,
A73E66BC2AB107BB005FC327 /* IPCEvent.h */,
46BB389C2B69764600F02BE0 /* IPCEvent.serialization.in */,
A31F60A225CC7DB800AF14F4 /* IPCSemaphore.h */,
46CD8C442B059FF500360248 /* IPCSemaphore.serialization.in */,
7B9FC5AC28A3B440007570E7 /* IPCUtilities.cpp */,
Expand Down
2 changes: 0 additions & 2 deletions Tools/TestWebKitAPI/Tests/IPC/EventTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ TEST_P(EventTestABBA, SerializeAndSignal)
ASSERT_TRUE(openB());

bClient().setAsyncMessageHandler([&] (IPC::Decoder& decoder) -> bool {
decoder.decode<uint64_t>();
auto signal = decoder.decode<IPC::Signal>();
signal->signal();

Expand All @@ -108,7 +107,6 @@ TEST_P(EventTestABBA, InterruptOnDestruct)
ASSERT_TRUE(openB());

bClient().setAsyncMessageHandler([&] (IPC::Decoder& decoder) -> bool {
decoder.decode<uint64_t>();
{
auto signal = decoder.decode<IPC::Signal>();
}
Expand Down

0 comments on commit 4d873d0

Please sign in to comment.