Ignore:
Timestamp:
May 12, 2017, 6:30:13 PM (8 years ago)
Author:
[email protected]
Message:

Use Mach exceptions instead of signals where possible
https://bugs.webkit.org/show_bug.cgi?id=171865

Reviewed by Mark Lam.

Source/JavaScriptCore:

This patch adds some new JSC options. The first is an option that
enables or disables web assembly tier up. The second controls
whether or not we use mach exceptions (where available).

  • API/tests/ExecutionTimeLimitTest.cpp:

(dispatchTermitateCallback):
(testExecutionTimeLimit):

  • runtime/JSLock.cpp:

(JSC::JSLock::didAcquireLock):

  • runtime/Options.cpp:

(JSC::overrideDefaults):
(JSC::Options::initialize):

  • runtime/Options.h:
  • runtime/VMTraps.cpp:

(JSC::SignalContext::SignalContext):
(JSC::SignalContext::adjustPCToPointToTrappingInstruction):
(JSC::installSignalHandler):
(JSC::VMTraps::SignalSender::send):

  • tools/SigillCrashAnalyzer.cpp:

(JSC::SignalContext::SignalContext):
(JSC::SignalContext::dump):
(JSC::installCrashHandler):

  • wasm/WasmBBQPlan.cpp:

(JSC::Wasm::BBQPlan::compileFunctions):

  • wasm/WasmFaultSignalHandler.cpp:

(JSC::Wasm::trapHandler):
(JSC::Wasm::enableFastMemory):

  • wasm/WasmMachineThreads.cpp:

(JSC::Wasm::resetInstructionCacheOnAllThreads):

Source/WTF:

This patch enables using mach exceptions on darwin. The way the
mach exception api works is that we create a mach port, which is
like a file descriptor. We then wait for a message to arrive on
that port in a thread. When another thread raises an exception (say
due to a bad memory access) the OS sends our thread a message. The
payload of that message is the register file of the crashing
thread. We then call our custom handlers that change the state as
needed. In order to restart the thread we send a payload back to
the OS with an updated register file along with a success message
header.

This patch also makes thread messages work without signals by
simply suspending the thread, and then running the message at that
time.

You can read more about mach exceptions here:
http://www.cs.cmu.edu/afs/cs/project/mach/public/doc/unpublished/exception.ps
and the Mach interface Generator (MiG) here:
http://www.cs.cmu.edu/afs/cs/project/mach/public/doc/unpublished/mig.ps

  • Configurations/WTF.xcconfig:
  • WTF.xcodeproj/project.pbxproj:
  • wtf/Platform.h:
  • wtf/PlatformRegisters.h:

(WTF::registersFromUContext):

  • wtf/StackBounds.h:

(WTF::StackBounds::StackBounds):

  • wtf/ThreadHolder.cpp:

(WTF::ThreadHolder::~ThreadHolder):

  • wtf/ThreadMessage.cpp:

(WTF::sendMessageUsingSignal):
(WTF::sendMessageUsingMach):
(WTF::deliverMessagesUsingMach):
(WTF::sendMessageScoped):

  • wtf/ThreadMessage.h:

(WTF::sendMessage):

  • wtf/Threading.h:

(WTF::Thread::machThread):

  • wtf/mac/MachExceptions.defs: Copied from Source/WTF/wtf/ThreadMessage.h.
  • wtf/threads/Signals.cpp:

(WTF::startMachExceptionHandlerThread):
(WTF::fromMachException):
(WTF::toMachMask):
(WTF::handleSignalsWithMach):
(WTF::setExceptionPorts):
(WTF::activeThreads):
(WTF::registerThreadForMachExceptionHandling):
(WTF::unregisterThreadForMachExceptionHandling):
(WTF::installSignalHandler):
(WTF::jscSignalHandler):

  • wtf/threads/Signals.h:

Tools:

  • TestWebKitAPI/Tests/WTF/ThreadMessages.cpp:

(runThreadMessageTest):
(TEST):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/tools/SigillCrashAnalyzer.cpp

    r216151 r216808  
    7979
    8080struct SignalContext {
    81     SignalContext(mcontext_t& mcontext)
    82         : mcontext(mcontext)
    83         , machinePC(MachineContext::instructionPointer(mcontext))
    84         , stackPointer(MachineContext::stackPointer(mcontext))
    85         , framePointer(MachineContext::framePointer(mcontext))
     81    SignalContext(PlatformRegisters& registers)
     82        : registers(registers)
     83        , machinePC(MachineContext::instructionPointer(registers))
     84        , stackPointer(MachineContext::stackPointer(registers))
     85        , framePointer(MachineContext::framePointer(registers))
    8686    { }
    8787
     
    113113
    114114#define DUMP_REGISTER(__reg) \
    115         log("Register " #__reg ": %p", reinterpret_cast<void*>(mcontext->__ss.__##__reg));
     115        log("Register " #__reg ": %p", reinterpret_cast<void*>(registers.__##__reg));
    116116        FOR_EACH_REGISTER(DUMP_REGISTER)
    117117#undef FOR_EACH_REGISTER
     
    121121        for (i = 0; i < 28; i += 4) {
    122122            log("x%d: %016llx x%d: %016llx x%d: %016llx x%d: %016llx",
    123                 i, mcontext->__ss.__x[i],
    124                 i+1, mcontext->__ss.__x[i+1],
    125                 i+2, mcontext->__ss.__x[i+2],
    126                 i+3, mcontext->__ss.__x[i+3]);
     123                i, registers.__x[i],
     124                i+1, registers.__x[i+1],
     125                i+2, registers.__x[i+2],
     126                i+3, registers.__x[i+3]);
    127127        }
    128128        ASSERT(i < 29);
    129129        log("x%d: %016llx fp: %016llx lr: %016llx",
    130             i, mcontext->__ss.__x[i], mcontext->__ss.__fp, mcontext->__ss.__lr);
     130            i, registers.__x[i], registers.__fp, registers.__lr);
    131131        log("sp: %016llx pc: %016llx cpsr: %08x",
    132             mcontext->__ss.__sp, mcontext->__ss.__pc, mcontext->__ss.__cpsr);
     132            registers.__sp, registers.__pc, registers.__cpsr);
    133133#endif
    134134    }
    135135
    136     mcontext_t& mcontext;
     136    PlatformRegisters& registers;
    137137    void* machinePC;
    138138    void* stackPointer;
     
    143143{
    144144#if CPU(X86_64) || CPU(ARM64)
    145     installSignalHandler(Signal::Ill, [] (int, siginfo_t*, void* uap) {
    146         SignalContext context(static_cast<ucontext_t*>(uap)->uc_mcontext);
     145    installSignalHandler(Signal::Ill, [] (Signal, SigInfo&, PlatformRegisters& registers) {
     146        SignalContext context(registers);
    147147
    148148        if (!isJITPC(context.machinePC))
Note: See TracChangeset for help on using the changeset viewer.