Changeset 247020 in webkit


Ignore:
Timestamp:
Jul 1, 2019 2:11:29 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Alex Christensen <achristensen@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):

Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r247018 r247020  
     12019-07-01  Alex Christensen  <achristensen@webkit.org>
     2
     3        Add main thread assertions in sendWithAsyncReply code
     4        https://bugs.webkit.org/show_bug.cgi?id=199324
     5
     6        Reviewed by Sam Weinig.
     7
     8        sendWithAsyncReply can only be used on the main thread because
     9        the CompletionHandler will be called on the main thread, and if it's
     10        called from a background thread, then HashMap corruption will likely happen.
     11        Add assertions to alert developers that they should only call sendWithAsyncReply
     12        from the main thread.
     13
     14        This is responding to good feedback from r237294
     15
     16        * Platform/IPC/Connection.cpp:
     17        (IPC::asyncReplyHandlerMap):
     18        (IPC::nextAsyncReplyHandlerID):
     19        (IPC::addAsyncReplyHandler):
     20        (IPC::clearAsyncReplyHandlers):
     21        (IPC::CompletionHandler<void):
     22
    1232019-07-01  Eric Carlson  <eric.carlson@apple.com>
    224
  • trunk/Source/WebKit/Platform/IPC/Connection.cpp

    r245767 r247020  
    240240static HashMap<uintptr_t, HashMap<uint64_t, CompletionHandler<void(Decoder*)>>>& asyncReplyHandlerMap()
    241241{
     242    ASSERT(RunLoop::isMain());
    242243    static NeverDestroyed<HashMap<uintptr_t, HashMap<uint64_t, CompletionHandler<void(Decoder*)>>>> map;
    243244    return map.get();
     
    11281129uint64_t nextAsyncReplyHandlerID()
    11291130{
     1131    ASSERT(RunLoop::isMain());
    11301132    static uint64_t identifier { 0 };
    11311133    return ++identifier;
     
    11341136void addAsyncReplyHandler(Connection& connection, uint64_t identifier, CompletionHandler<void(Decoder*)>&& completionHandler)
    11351137{
     1138    ASSERT(RunLoop::isMain());
    11361139    auto result = asyncReplyHandlerMap().ensure(reinterpret_cast<uintptr_t>(&connection), [] {
    11371140        return HashMap<uint64_t, CompletionHandler<void(Decoder*)>>();
     
    11421145void clearAsyncReplyHandlers(const Connection& connection)
    11431146{
     1147    ASSERT(RunLoop::isMain());
    11441148    auto map = asyncReplyHandlerMap().take(reinterpret_cast<uintptr_t>(&connection));
    11451149    for (auto& handler : map.values()) {
     
    11511155CompletionHandler<void(Decoder*)> takeAsyncReplyHandler(Connection& connection, uint64_t identifier)
    11521156{
     1157    ASSERT(RunLoop::isMain());
    11531158    auto iterator = asyncReplyHandlerMap().find(reinterpret_cast<uintptr_t>(&connection));
    11541159    if (iterator != asyncReplyHandlerMap().end()) {
Note: See TracChangeset for help on using the changeset viewer.