Use Mach exceptions instead of signals where possible
authorkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 May 2017 01:30:13 +0000 (01:30 +0000)
committerkeith_miller@apple.com <keith_miller@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 May 2017 01:30:13 +0000 (01:30 +0000)
commit93db4760257924a289bbe5d1d66b24cb89c5ccca
tree627233208b7b1b11ef91725fa80db71d23baf0ae
parent2cc7449dacba592ac3c136ba7c7f538a28e551c7
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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@216808 268f45cc-cd09-0410-ab3c-d52691b4dbfc
25 files changed:
Source/JavaScriptCore/API/tests/ExecutionTimeLimitTest.cpp
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSLock.cpp
Source/JavaScriptCore/runtime/Options.cpp
Source/JavaScriptCore/runtime/Options.h
Source/JavaScriptCore/runtime/VMTraps.cpp
Source/JavaScriptCore/tools/SigillCrashAnalyzer.cpp
Source/JavaScriptCore/wasm/WasmBBQPlan.cpp
Source/JavaScriptCore/wasm/WasmFaultSignalHandler.cpp
Source/JavaScriptCore/wasm/WasmMachineThreads.cpp
Source/WTF/ChangeLog
Source/WTF/Configurations/WTF.xcconfig
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/Platform.h
Source/WTF/wtf/PlatformRegisters.h
Source/WTF/wtf/StackBounds.h
Source/WTF/wtf/ThreadHolder.cpp
Source/WTF/wtf/ThreadMessage.cpp
Source/WTF/wtf/ThreadMessage.h
Source/WTF/wtf/Threading.h
Source/WTF/wtf/mac/MachExceptions.defs [new file with mode: 0644]
Source/WTF/wtf/threads/Signals.cpp
Source/WTF/wtf/threads/Signals.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WTF/ThreadMessages.cpp