Title: [247020] trunk/Source/WebKit
Revision
247020
Author
commit-qu...@webkit.org
Date
2019-07-01 14:11:29 -0700 (Mon, 01 Jul 2019)

Log Message

Add main thread assertions in sendWithAsyncReply code
https://bugs.webkit.org/show_bug.cgi?id=199324

Patch by Alex Christensen <achristen...@webkit.org> on 2019-07-01
Reviewed by Sam Weinig.

sendWithAsyncReply can only be used on the main thread because
the CompletionHandler will be called on the main thread, and if it's
called from a background thread, then HashMap corruption will likely happen.
Add assertions to alert developers that they should only call sendWithAsyncReply
from the main thread.

This is responding to good feedback from r237294

* Platform/IPC/Connection.cpp:
(IPC::asyncReplyHandlerMap):
(IPC::nextAsyncReplyHandlerID):
(IPC::addAsyncReplyHandler):
(IPC::clearAsyncReplyHandlers):
(IPC::CompletionHandler<void):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (247019 => 247020)


--- trunk/Source/WebKit/ChangeLog	2019-07-01 21:07:31 UTC (rev 247019)
+++ trunk/Source/WebKit/ChangeLog	2019-07-01 21:11:29 UTC (rev 247020)
@@ -1,3 +1,25 @@
+2019-07-01  Alex Christensen  <achristen...@webkit.org>
+
+        Add main thread assertions in sendWithAsyncReply code
+        https://bugs.webkit.org/show_bug.cgi?id=199324
+
+        Reviewed by Sam Weinig.
+
+        sendWithAsyncReply can only be used on the main thread because
+        the CompletionHandler will be called on the main thread, and if it's
+        called from a background thread, then HashMap corruption will likely happen.
+        Add assertions to alert developers that they should only call sendWithAsyncReply
+        from the main thread.
+
+        This is responding to good feedback from r237294
+
+        * Platform/IPC/Connection.cpp:
+        (IPC::asyncReplyHandlerMap):
+        (IPC::nextAsyncReplyHandlerID):
+        (IPC::addAsyncReplyHandler):
+        (IPC::clearAsyncReplyHandlers):
+        (IPC::CompletionHandler<void):
+
 2019-07-01  Eric Carlson  <eric.carl...@apple.com>
 
         [iOS] Exiting from fullscreen scrolls to top of page

Modified: trunk/Source/WebKit/Platform/IPC/Connection.cpp (247019 => 247020)


--- trunk/Source/WebKit/Platform/IPC/Connection.cpp	2019-07-01 21:07:31 UTC (rev 247019)
+++ trunk/Source/WebKit/Platform/IPC/Connection.cpp	2019-07-01 21:11:29 UTC (rev 247020)
@@ -239,6 +239,7 @@
 
 static HashMap<uintptr_t, HashMap<uint64_t, CompletionHandler<void(Decoder*)>>>& asyncReplyHandlerMap()
 {
+    ASSERT(RunLoop::isMain());
     static NeverDestroyed<HashMap<uintptr_t, HashMap<uint64_t, CompletionHandler<void(Decoder*)>>>> map;
     return map.get();
 }
@@ -1127,6 +1128,7 @@
 
 uint64_t nextAsyncReplyHandlerID()
 {
+    ASSERT(RunLoop::isMain());
     static uint64_t identifier { 0 };
     return ++identifier;
 }
@@ -1133,6 +1135,7 @@
 
 void addAsyncReplyHandler(Connection& connection, uint64_t identifier, CompletionHandler<void(Decoder*)>&& completionHandler)
 {
+    ASSERT(RunLoop::isMain());
     auto result = asyncReplyHandlerMap().ensure(reinterpret_cast<uintptr_t>(&connection), [] {
         return HashMap<uint64_t, CompletionHandler<void(Decoder*)>>();
     }).iterator->value.add(identifier, WTFMove(completionHandler));
@@ -1141,6 +1144,7 @@
 
 void clearAsyncReplyHandlers(const Connection& connection)
 {
+    ASSERT(RunLoop::isMain());
     auto map = asyncReplyHandlerMap().take(reinterpret_cast<uintptr_t>(&connection));
     for (auto& handler : map.values()) {
         if (handler)
@@ -1150,6 +1154,7 @@
 
 CompletionHandler<void(Decoder*)> takeAsyncReplyHandler(Connection& connection, uint64_t identifier)
 {
+    ASSERT(RunLoop::isMain());
     auto iterator = asyncReplyHandlerMap().find(reinterpret_cast<uintptr_t>(&connection));
     if (iterator != asyncReplyHandlerMap().end()) {
         if (!iterator->value.isValidKey(identifier)) {
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to