Title: [292862] trunk/Source/WebKit
Revision
292862
Author
[email protected]
Date
2022-04-14 06:23:44 -0700 (Thu, 14 Apr 2022)

Log Message

Some IPC related message forwarding functions use const lvalue references
https://bugs.webkit.org/show_bug.cgi?id=238937

Patch by Kimmo Kinnunen <[email protected]> on 2022-04-14
Reviewed by Antti Koivisto.

Passing the message as const lvalue reference prevents IPC messages to be
changed to support move semantics for some message arguments.

Fix by using universal references in the shell function signatures.
Forward the messages from one shell function to other as rvalue references
via WTFMove, since the messages are always such that they are forwarded so.
This also catches most such errors in the future.

No new tests, refactor.

* Platform/IPC/MessageSender.h:
(IPC::MessageSender::send):
(IPC::MessageSender::sendSync):
(IPC::MessageSender::sendWithAsyncReply):
* WebProcess/WebPage/DrawingArea.h:
(WebKit::DrawingArea::send):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (292861 => 292862)


--- trunk/Source/WebKit/ChangeLog	2022-04-14 08:48:21 UTC (rev 292861)
+++ trunk/Source/WebKit/ChangeLog	2022-04-14 13:23:44 UTC (rev 292862)
@@ -1,3 +1,27 @@
+2022-04-14  Kimmo Kinnunen  <[email protected]>
+
+        Some IPC related message forwarding functions use const lvalue references
+        https://bugs.webkit.org/show_bug.cgi?id=238937
+
+        Reviewed by Antti Koivisto.
+
+        Passing the message as const lvalue reference prevents IPC messages to be
+        changed to support move semantics for some message arguments.
+
+        Fix by using universal references in the shell function signatures.
+        Forward the messages from one shell function to other as rvalue references
+        via WTFMove, since the messages are always such that they are forwarded so.
+        This also catches most such errors in the future.
+
+        No new tests, refactor.
+
+        * Platform/IPC/MessageSender.h:
+        (IPC::MessageSender::send):
+        (IPC::MessageSender::sendSync):
+        (IPC::MessageSender::sendWithAsyncReply):
+        * WebProcess/WebPage/DrawingArea.h:
+        (WebKit::DrawingArea::send):
+
 2022-04-14  Youenn Fablet  <[email protected]>
 
         Expose workers as service worker clients and implement registration matching for dedicated workers

Modified: trunk/Source/WebKit/Platform/IPC/MessageSender.h (292861 => 292862)


--- trunk/Source/WebKit/Platform/IPC/MessageSender.h	2022-04-14 08:48:21 UTC (rev 292861)
+++ trunk/Source/WebKit/Platform/IPC/MessageSender.h	2022-04-14 13:23:44 UTC (rev 292862)
@@ -35,25 +35,24 @@
 public:
     virtual ~MessageSender();
 
-    template<typename U> bool send(const U& message, OptionSet<SendOption> sendOptions = { })
+    template<typename T> bool send(T&& message, OptionSet<SendOption> sendOptions = { })
     {
-        return send(message, messageSenderDestinationID(), sendOptions);
+        return send(WTFMove(message), messageSenderDestinationID(), sendOptions);
     }
 
-    template<typename U> bool send(const U& message, uint64_t destinationID, OptionSet<SendOption> sendOptions = { })
+    template<typename T> bool send(T&& message, uint64_t destinationID, OptionSet<SendOption> sendOptions = { })
     {
-        static_assert(!U::isSync, "Message is sync!");
+        static_assert(!T::isSync, "Message is sync!");
 
-        auto encoder = makeUniqueRef<Encoder>(U::name(), destinationID);
+        auto encoder = makeUniqueRef<Encoder>(T::name(), destinationID);
         encoder.get() << message.arguments();
-        
         return sendMessage(WTFMove(encoder), sendOptions);
     }
-    
-    template<typename U, typename T>
-    bool send(const U& message, ObjectIdentifier<T> destinationID, OptionSet<SendOption> sendOptions = { })
+
+    template<typename T, typename U>
+    bool send(T&& message, ObjectIdentifier<U> destinationID, OptionSet<SendOption> sendOptions = { })
     {
-        return send<U>(message, destinationID.toUInt64(), sendOptions);
+        return send(WTFMove(message), destinationID.toUInt64(), sendOptions);
     }
     using SendSyncResult = Connection::SendSyncResult;
 
@@ -62,7 +61,7 @@
     {
         static_assert(T::isSync, "Message is not sync!");
 
-        return sendSync(std::forward<T>(message), WTFMove(reply), messageSenderDestinationID(), timeout, sendSyncOptions);
+        return sendSync(WTFMove(message), WTFMove(reply), messageSenderDestinationID(), timeout, sendSyncOptions);
     }
 
     template<typename T>
@@ -74,10 +73,10 @@
         return { };
     }
 
-    template<typename U, typename T>
-    SendSyncResult sendSync(U&& message, typename U::Reply&& reply, ObjectIdentifier<T> destinationID, Timeout timeout = Timeout::infinity(), OptionSet<SendSyncOption> sendSyncOptions = { })
+    template<typename T, typename U>
+    SendSyncResult sendSync(T&& message, typename T::Reply&& reply, ObjectIdentifier<U> destinationID, Timeout timeout = Timeout::infinity(), OptionSet<SendSyncOption> sendSyncOptions = { })
     {
-        return sendSync<U>(std::forward<U>(message), WTFMove(reply), destinationID.toUInt64(), timeout, sendSyncOptions);
+        return sendSync(WTFMove(message), WTFMove(reply), destinationID.toUInt64(), timeout, sendSyncOptions);
     }
 
     template<typename T, typename C>
@@ -94,7 +93,7 @@
         auto encoder = makeUniqueRef<IPC::Encoder>(T::name(), destinationID);
         uint64_t listenerID = IPC::nextAsyncReplyHandlerID();
         encoder.get() << listenerID;
-        encoder.get() << message.arguments();
+        encoder.get() << WTFMove(message).arguments();
         sendMessage(WTFMove(encoder), sendOptions, {{ [completionHandler = WTFMove(completionHandler)] (IPC::Decoder* decoder) mutable {
             if (decoder && decoder->isValid())
                 T::callReply(*decoder, WTFMove(completionHandler));

Modified: trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.h (292861 => 292862)


--- trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.h	2022-04-14 08:48:21 UTC (rev 292861)
+++ trunk/Source/WebKit/WebProcess/WebPage/DrawingArea.h	2022-04-14 13:23:44 UTC (rev 292862)
@@ -157,9 +157,9 @@
 protected:
     DrawingArea(DrawingAreaType, DrawingAreaIdentifier, WebPage&);
 
-    template<typename U> bool send(const U& message)
+    template<typename T> bool send(T&& message)
     {
-        return m_webPage.send(message, m_identifier.toUInt64(), { });
+        return m_webPage.send(WTFMove(message), m_identifier.toUInt64(), { });
     }
 
     const DrawingAreaType m_type;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to