Changeset 260165 in webkit


Ignore:
Timestamp:
Apr 15, 2020 6:40:42 PM (4 years ago)
Author:
rmorisset@apple.com
Message:

Flaky Test: fetch/fetch-worker-crash.html
https://bugs.webkit.org/show_bug.cgi?id=187257
<rdar://problem/48527526>

Reviewed by Yusuke Suzuki.

Source/JavaScriptCore:

The crash is coming from setExceptionPorts which is inlined in WTF::registerThreadForMachExceptionHandling.
From the error message we know that the problem is an "invalid port right".
http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/thread_set_exception_ports.html tells us that the "port right" is the third parameter to thread_set_exception_ports, which is exceptionPort in our case.
exceptionPort is a global variable defined at the top of Signals.cpp:

static mach_port_t exceptionPort;

It is set in exactly one place:

kern_return_t kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &exceptionPort);

in a std::call_once, in startMachExceptionHandlerThread().
Note that startMachExceptionHandlerThread() is called from the main thread just before the point where we are stuck.. and there is no synchronization to make sure it completed and its effect is visible to the worker thread before it uses exceptionPort.

So I think the crash is due to this race between allocating exceptionPort and using it, resulting in an invalid exceptionPort being sometimes passed to the kernel.
So this patch is a simple speculative fix, by running startMachExceptionHandlerThread() in initializeThreading(), before JSLock()::lock() can be run.

  • runtime/InitializeThreading.cpp:

(JSC::initializeThreading):

Source/WTF:

Make startMachExceptionHandlerThread visible so that we can make sure it is called whenever initializing JSC.

  • wtf/threads/Signals.cpp:

(WTF::startMachExceptionHandlerThread):

  • wtf/threads/Signals.h:
Location:
trunk/Source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r260162 r260165  
     12020-04-15  Robin Morisset  <rmorisset@apple.com>
     2
     3        Flaky Test: fetch/fetch-worker-crash.html
     4        https://bugs.webkit.org/show_bug.cgi?id=187257
     5        <rdar://problem/48527526>
     6
     7        Reviewed by Yusuke Suzuki.
     8
     9        The crash is coming from setExceptionPorts which is inlined in WTF::registerThreadForMachExceptionHandling.
     10        From the error message we know that the problem is an "invalid port right".
     11        http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/thread_set_exception_ports.html tells us that the "port right" is the third parameter to thread_set_exception_ports, which is exceptionPort in our case.
     12        exceptionPort is a global variable defined at the top of Signals.cpp:
     13          static mach_port_t exceptionPort;
     14        It is set in exactly one place:
     15          kern_return_t kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &exceptionPort);
     16        in a std::call_once, in startMachExceptionHandlerThread().
     17        Note that startMachExceptionHandlerThread() is called from the main thread just before the point where we are stuck.. and there is no synchronization to make sure it completed and its effect is visible to the worker thread before it uses exceptionPort.
     18
     19        So I think the crash is due to this race between allocating exceptionPort and using it, resulting in an invalid exceptionPort being sometimes passed to the kernel.
     20        So this patch is a simple speculative fix, by running startMachExceptionHandlerThread() in initializeThreading(), before JSLock()::lock() can be run.
     21
     22        * runtime/InitializeThreading.cpp:
     23        (JSC::initializeThreading):
     24
    1252020-04-15  Ross Kirsling  <ross.kirsling@sony.com>
    226
  • trunk/Source/JavaScriptCore/runtime/InitializeThreading.cpp

    r250725 r260165  
    5454#include <wtf/dtoa.h>
    5555#include <wtf/dtoa/cached-powers.h>
     56#include <wtf/threads/Signals.h>
    5657
    5758namespace JSC {
     
    100101        if (VM::isInMiniMode())
    101102            WTF::fastEnableMiniMode();
     103
     104#if HAVE(MACH_EXCEPTIONS)
     105        // JSLock::lock() can call registerThreadForMachExceptionHandling() which crashes if this has not been called first.
     106        WTF::startMachExceptionHandlerThread();
     107#endif
    102108    });
    103109}
  • trunk/Source/WTF/ChangeLog

    r260102 r260165  
     12020-04-15  Robin Morisset  <rmorisset@apple.com>
     2
     3        Flaky Test: fetch/fetch-worker-crash.html
     4        https://bugs.webkit.org/show_bug.cgi?id=187257
     5        <rdar://problem/48527526>
     6
     7        Reviewed by Yusuke Suzuki.
     8
     9        Make startMachExceptionHandlerThread visible so that we can make sure it is called whenever initializing JSC.
     10
     11        * wtf/threads/Signals.cpp:
     12        (WTF::startMachExceptionHandlerThread):
     13        * wtf/threads/Signals.h:
     14
    1152020-04-14  Peng Liu  <peng.liu6@apple.com>
    216
  • trunk/Source/WTF/wtf/threads/Signals.cpp

    r241583 r260165  
    7070static constexpr size_t maxMessageSize = 1 * KB;
    7171
    72 static void startMachExceptionHandlerThread()
     72void startMachExceptionHandlerThread()
    7373{
    7474    static std::once_flag once;
  • trunk/Source/WTF/wtf/threads/Signals.h

    r239427 r260165  
    9494class Thread;
    9595void registerThreadForMachExceptionHandling(Thread&);
     96void startMachExceptionHandlerThread();
    9697
    9798void handleSignalsWithMach();
Note: See TracChangeset for help on using the changeset viewer.