Title: [263045] trunk
Revision
263045
Author
[email protected]
Date
2020-06-15 11:29:58 -0700 (Mon, 15 Jun 2020)

Log Message

Signal handlers should have a two phase installation.
https://bugs.webkit.org/show_bug.cgi?id=213160

Reviewed by Mark Lam.

Source/_javascript_Core:

* jsc.cpp:
(CommandLine::parseArguments):
(jscmain):
* runtime/InitializeThreading.cpp:
(JSC::initializeThreading):
* runtime/VMTraps.cpp:
* tools/SigillCrashAnalyzer.cpp:
(JSC::installCrashHandler):
* wasm/WasmFaultSignalHandler.cpp:
(JSC::Wasm::enableFastMemory):
(JSC::Wasm::prepareFastMemory):
* wasm/WasmFaultSignalHandler.h:

Source/WebKit:

Put back old WASM fast memory installation.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::initializeWebProcess):

Source/WTF:

LLDB does not like it when we single step while there are mach exception
handlers installed because LLDB suspends all the non-active threads.
With Mach exception handlers installed, the OS will send a mach message
to our exception handler port, which is different than the active thread.
When this happens, the combination of LLDB and the process JSC is in effectively
deadlock.

Under our new approach, we go back to only telling the OS we care about
these exceptions late but lock down the function pointers early. This way
processes that benefit from our exception handler code are easier to debug.

* wtf/threads/Signals.cpp:
(WTF::addSignalHandler):
(WTF::activateSignalHandlersFor):
(WTF::installSignalHandler): Deleted.
* wtf/threads/Signals.h:

Tools:

* TestWebKitAPI/Tests/WTF/Signals.cpp:
(TEST):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (263044 => 263045)


--- trunk/Source/_javascript_Core/ChangeLog	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-06-15 18:29:58 UTC (rev 263045)
@@ -1,3 +1,23 @@
+2020-06-15  Keith Miller  <[email protected]>
+
+        Signal handlers should have a two phase installation.
+        https://bugs.webkit.org/show_bug.cgi?id=213160
+
+        Reviewed by Mark Lam.
+
+        * jsc.cpp:
+        (CommandLine::parseArguments):
+        (jscmain):
+        * runtime/InitializeThreading.cpp:
+        (JSC::initializeThreading):
+        * runtime/VMTraps.cpp:
+        * tools/SigillCrashAnalyzer.cpp:
+        (JSC::installCrashHandler):
+        * wasm/WasmFaultSignalHandler.cpp:
+        (JSC::Wasm::enableFastMemory):
+        (JSC::Wasm::prepareFastMemory):
+        * wasm/WasmFaultSignalHandler.h:
+
 2020-06-15  Yusuke Suzuki  <[email protected]>
 
         Unreviewed, fix LLInt

Modified: trunk/Source/_javascript_Core/jsc.cpp (263044 => 263045)


--- trunk/Source/_javascript_Core/jsc.cpp	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/_javascript_Core/jsc.cpp	2020-06-15 18:29:58 UTC (rev 263045)
@@ -66,6 +66,7 @@
 #include "TypedArrayInlines.h"
 #include "VMInspector.h"
 #include "WasmCapabilities.h"
+#include "WasmFaultSignalHandler.h"
 #include "WasmMemory.h"
 #include <stdio.h>
 #include <stdlib.h>
@@ -2986,11 +2987,16 @@
                 return SignalAction::ForceDefault;
             };
 
-            installSignalHandler(Signal::IllegalInstruction, SignalHandler(exit));
-            installSignalHandler(Signal::AccessFault, SignalHandler(exit));
-            installSignalHandler(Signal::FloatingPoint, SignalHandler(exit));
+            addSignalHandler(Signal::IllegalInstruction, SignalHandler(exit));
+            addSignalHandler(Signal::AccessFault, SignalHandler(exit));
+            addSignalHandler(Signal::FloatingPoint, SignalHandler(exit));
             // once we do this lldb won't work anymore because we will exit on any breakpoints it sets.
-            installSignalHandler(Signal::Breakpoint, SignalHandler(exit));
+            addSignalHandler(Signal::Breakpoint, SignalHandler(exit));
+
+            activateSignalHandlersFor(Signal::IllegalInstruction);
+            activateSignalHandlersFor(Signal::AccessFault);
+            activateSignalHandlersFor(Signal::FloatingPoint);
+            activateSignalHandlersFor(Signal::Breakpoint);
 #endif
             continue;
         }
@@ -3122,6 +3128,10 @@
     Worker worker(Workers::singleton());
     
     VM& vm = VM::create(LargeHeap).leakRef();
+#if ENABLE(WEBASSEMBLY)
+    Wasm::enableFastMemory();
+#endif
+
     int result;
     bool success = true;
     GlobalObject* globalObject = nullptr;

Modified: trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp (263044 => 263045)


--- trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/_javascript_Core/runtime/InitializeThreading.cpp	2020-06-15 18:29:58 UTC (rev 263045)
@@ -95,7 +95,7 @@
 #endif
         VMTraps::initializeSignals();
 #if ENABLE(WEBASSEMBLY)
-        Wasm::enableFastMemory();
+        Wasm::prepareFastMemory();
 #endif
 
         WTF::compilerFence();

Modified: trunk/Source/_javascript_Core/runtime/VMTraps.cpp (263044 => 263045)


--- trunk/Source/_javascript_Core/runtime/VMTraps.cpp	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/_javascript_Core/runtime/VMTraps.cpp	2020-06-15 18:29:58 UTC (rev 263045)
@@ -193,13 +193,15 @@
     SignalSender(const AbstractLocker& locker, VM& vm)
         : Base(locker, vm.traps().m_lock, vm.traps().m_condition.copyRef())
         , m_vm(vm)
-    { }
+    {
+        activateSignalHandlersFor(Signal::AccessFault);
+    }
 
     static void initializeSignals()
     {
         static std::once_flag once;
         std::call_once(once, [] {
-            installSignalHandler(Signal::AccessFault, [] (Signal, SigInfo&, PlatformRegisters& registers) -> SignalAction {
+            addSignalHandler(Signal::AccessFault, [] (Signal, SigInfo&, PlatformRegisters& registers) -> SignalAction {
                 auto signalContext = SignalContext::tryCreate(registers);
                 if (!signalContext)
                     return SignalAction::NotHandled;

Modified: trunk/Source/_javascript_Core/tools/SigillCrashAnalyzer.cpp (263044 => 263045)


--- trunk/Source/_javascript_Core/tools/SigillCrashAnalyzer.cpp	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/_javascript_Core/tools/SigillCrashAnalyzer.cpp	2020-06-15 18:29:58 UTC (rev 263045)
@@ -156,7 +156,7 @@
 static void installCrashHandler()
 {
 #if CPU(X86_64) || CPU(ARM64)
-    installSignalHandler(Signal::IllegalInstruction, [] (Signal, SigInfo&, PlatformRegisters& registers) {
+    addSignalHandler(Signal::IllegalInstruction, [] (Signal, SigInfo&, PlatformRegisters& registers) {
         auto signalContext = SignalContext::tryCreate(registers);
         if (!signalContext)
             return SignalAction::NotHandled;
@@ -169,6 +169,7 @@
         analyzer.analyze(*signalContext);
         return SignalAction::NotHandled;
     });
+    activateSignalHandlersFor(Signal::IllegalInstruction);
 #endif
 }
 

Modified: trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.cpp (263044 => 263045)


--- trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.cpp	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.cpp	2020-06-15 18:29:58 UTC (rev 263045)
@@ -113,12 +113,28 @@
         if (!Options::useWebAssemblyFastMemory())
             return;
 
-        installSignalHandler(Signal::AccessFault, [] (Signal signal, SigInfo& sigInfo, PlatformRegisters& ucontext) {
-            return trapHandler(signal, sigInfo, ucontext);
-        });
+        activateSignalHandlersFor(Signal::AccessFault);
 
         fastHandlerInstalled = true;
     });
+#endif
+}
+
+void prepareFastMemory()
+{
+#if ENABLE(WEBASSEMBLY_FAST_MEMORY)
+    static std::once_flag once;
+    std::call_once(once, [] {
+        if (!Wasm::isSupported())
+            return;
+
+        if (!Options::useWebAssemblyFastMemory())
+            return;
+
+        addSignalHandler(Signal::AccessFault, [] (Signal signal, SigInfo& sigInfo, PlatformRegisters& ucontext) {
+            return trapHandler(signal, sigInfo, ucontext);
+        });
+    });
 #endif // ENABLE(WEBASSEMBLY_FAST_MEMORY)
 }
     

Modified: trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.h (263044 => 263045)


--- trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.h	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/_javascript_Core/wasm/WasmFaultSignalHandler.h	2020-06-15 18:29:58 UTC (rev 263045)
@@ -32,6 +32,7 @@
 namespace Wasm {
 
 bool fastMemoryEnabled();
+JS_EXPORT_PRIVATE void prepareFastMemory();
 JS_EXPORT_PRIVATE void enableFastMemory();
 
 } } // namespace JSC::Wasm

Modified: trunk/Source/WTF/ChangeLog (263044 => 263045)


--- trunk/Source/WTF/ChangeLog	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/WTF/ChangeLog	2020-06-15 18:29:58 UTC (rev 263045)
@@ -1,3 +1,27 @@
+2020-06-15  Keith Miller  <[email protected]>
+
+        Signal handlers should have a two phase installation.
+        https://bugs.webkit.org/show_bug.cgi?id=213160
+
+        Reviewed by Mark Lam.
+
+        LLDB does not like it when we single step while there are mach exception
+        handlers installed because LLDB suspends all the non-active threads.
+        With Mach exception handlers installed, the OS will send a mach message
+        to our exception handler port, which is different than the active thread.
+        When this happens, the combination of LLDB and the process JSC is in effectively
+        deadlock.
+
+        Under our new approach, we go back to only telling the OS we care about
+        these exceptions late but lock down the function pointers early. This way
+        processes that benefit from our exception handler code are easier to debug.
+
+        * wtf/threads/Signals.cpp:
+        (WTF::addSignalHandler):
+        (WTF::activateSignalHandlersFor):
+        (WTF::installSignalHandler): Deleted.
+        * wtf/threads/Signals.h:
+
 2020-06-15  Per Arne Vollan  <[email protected]>
 
         Pack bytes a little tighter in MemoryPressureHandler

Modified: trunk/Source/WTF/wtf/threads/Signals.cpp (263044 => 263045)


--- trunk/Source/WTF/wtf/threads/Signals.cpp	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/WTF/wtf/threads/Signals.cpp	2020-06-15 18:29:58 UTC (rev 263045)
@@ -235,11 +235,12 @@
     g_wtfConfig.signalHandlers.useMach = true;
 }
 
+static exception_mask_t activeExceptions;
 inline void setExceptionPorts(const AbstractLocker& threadGroupLocker, Thread& thread)
 {
     UNUSED_PARAM(threadGroupLocker);
     SignalHandlers& handlers = g_wtfConfig.signalHandlers;
-    kern_return_t result = thread_set_exception_ports(thread.machThread(), handlers.activeExceptions, handlers.exceptionPort, EXCEPTION_STATE | MACH_EXCEPTION_CODES, MACHINE_THREAD_STATE);
+    kern_return_t result = thread_set_exception_ports(thread.machThread(), handlers.addedExceptions &activeExceptions, handlers.exceptionPort, EXCEPTION_STATE | MACH_EXCEPTION_CODES, MACHINE_THREAD_STATE);
     if (result != KERN_SUCCESS) {
         dataLogLn("thread set port failed due to ", mach_error_string(result));
         CRASH();
@@ -265,11 +266,8 @@
         setExceptionPorts(locker, thread);
 }
 
-#else
-static constexpr bool useMach = false;
 #endif // HAVE(MACH_EXCEPTIONS)
 
-
 inline size_t offsetForSystemSignal(int sig)
 {
     Signal signal = fromSystemSignal(sig);
@@ -278,14 +276,14 @@
 
 static void jscSignalHandler(int, siginfo_t*, void*);
 
-void installSignalHandler(Signal signal, SignalHandler&& handler)
+void addSignalHandler(Signal signal, SignalHandler&& handler)
 {
     Config::AssertNotFrozenScope assertScope;
     SignalHandlers& handlers = g_wtfConfig.signalHandlers;
     ASSERT(signal < Signal::Unknown);
-#if HAVE(MACH_EXCEPTIONS)
     ASSERT(!handlers.useMach || signal != Signal::Usr);
 
+#if HAVE(MACH_EXCEPTIONS)
     if (handlers.useMach)
         startMachExceptionHandlerThread();
 #endif
@@ -293,10 +291,9 @@
     static std::once_flag initializeOnceFlags[static_cast<size_t>(Signal::NumberOfSignals)];
     std::call_once(initializeOnceFlags[static_cast<size_t>(signal)], [&] {
         Config::AssertNotFrozenScope assertScope;
-#if HAVE(MACH_EXCEPTIONS)
-        bool useMach = handlers.useMach;
-#endif
-        if (!useMach) {
+
+        handlers.addedExceptions |= toMachMask(signal);
+        if (!handlers.useMach) {
             struct sigaction action;
             action.sa_sigaction = jscSignalHandler;
             auto result = sigfillset(&action.sa_mask);
@@ -314,11 +311,19 @@
     });
 
     handlers.add(signal, WTFMove(handler));
+}
 
+void activateSignalHandlersFor(Signal signal)
+{
+    UNUSED_PARAM(signal);
 #if HAVE(MACH_EXCEPTIONS)
+    const SignalHandlers& handlers = g_wtfConfig.signalHandlers;
+    ASSERT(signal < Signal::Unknown);
+    ASSERT(!handlers.useMach || signal != Signal::Usr);
+
     auto locker = holdLock(activeThreads().getLock());
     if (handlers.useMach) {
-        handlers.activeExceptions |= toMachMask(signal);
+        activeExceptions |= toMachMask(signal);
 
         for (auto& thread : activeThreads().threads(locker))
             setExceptionPorts(locker, thread.get());

Modified: trunk/Source/WTF/wtf/threads/Signals.h (263044 => 263045)


--- trunk/Source/WTF/wtf/threads/Signals.h	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/WTF/wtf/threads/Signals.h	2020-06-15 18:29:58 UTC (rev 263045)
@@ -109,8 +109,10 @@
 
 #if HAVE(MACH_EXCEPTIONS)
     mach_port_t exceptionPort;
-    exception_mask_t activeExceptions;
+    exception_mask_t addedExceptions;
     bool useMach;
+#else
+    static constexpr bool useMach = false;
 #endif
     uint8_t numberOfHandlers[numberOfSignals];
     SignalHandlerMemory handlers[numberOfSignals][maxNumberOfHandlers];
@@ -117,13 +119,15 @@
     struct sigaction oldActions[numberOfSignals];
 };
 
-// Call this method whenever you want to install a signal handler. This function needs to be called
+// Call this method whenever you want to add a signal handler. This function needs to be called
 // before g_wtfConfig is frozen. After the g_wtfConfig is frozen, no additional signal handlers may
 // be installed. Any attempt to do so will trigger a crash.
 // Note: Your signal handler will be called every time the handler for the desired signal is called.
 // Thus it is your responsibility to discern if the signal fired was yours.
-// This function is a one way street i.e. once installed, a signal handler cannot be uninstalled.
-WTF_EXPORT_PRIVATE void installSignalHandler(Signal, SignalHandler&&);
+// These functions are a one way street i.e. once installed, a signal handler cannot be uninstalled
+// and once commited they can't be turned off.
+WTF_EXPORT_PRIVATE void addSignalHandler(Signal, SignalHandler&&);
+WTF_EXPORT_PRIVATE void activateSignalHandlersFor(Signal);
 
 
 #if HAVE(MACH_EXCEPTIONS)
@@ -147,6 +151,7 @@
 using WTF::fromSystemSignal;
 using WTF::SignalAction;
 using WTF::SignalHandler;
-using WTF::installSignalHandler;
+using WTF::addSignalHandler;
+using WTF::activateSignalHandlersFor;
 
 #endif // USE(PTHREADS) && HAVE(MACHINE_CONTEXT)

Modified: trunk/Source/WebKit/ChangeLog (263044 => 263045)


--- trunk/Source/WebKit/ChangeLog	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/WebKit/ChangeLog	2020-06-15 18:29:58 UTC (rev 263045)
@@ -1,3 +1,15 @@
+2020-06-15  Keith Miller  <[email protected]>
+
+        Signal handlers should have a two phase installation.
+        https://bugs.webkit.org/show_bug.cgi?id=213160
+
+        Reviewed by Mark Lam.
+
+        Put back old WASM fast memory installation.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::initializeWebProcess):
+
 2020-06-15  Víctor Manuel Jáquez Leal  <[email protected]>
 
         Suppress compiler warnings

Modified: trunk/Source/WebKit/WebProcess/WebProcess.cpp (263044 => 263045)


--- trunk/Source/WebKit/WebProcess/WebProcess.cpp	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Source/WebKit/WebProcess/WebProcess.cpp	2020-06-15 18:29:58 UTC (rev 263045)
@@ -83,6 +83,7 @@
 #include "WebsiteDataType.h"
 #include <_javascript_Core/JSLock.h>
 #include <_javascript_Core/MemoryStatistics.h>
+#include <_javascript_Core/WasmFaultSignalHandler.h>
 #include <WebCore/AXObjectCache.h>
 #include <WebCore/ApplicationCacheStorage.h>
 #include <WebCore/AuthenticationChallenge.h>
@@ -473,6 +474,10 @@
     ServiceWorkerProvider::setSharedProvider(WebServiceWorkerProvider::singleton());
 #endif
 
+#if ENABLE(WEBASSEMBLY)
+    JSC::Wasm::enableFastMemory();
+#endif
+
 #if ENABLE(RESOURCE_LOAD_STATISTICS) && !RELEASE_LOG_DISABLED
     WebResourceLoadObserver::setShouldLogUserInteraction(parameters.shouldLogUserInteraction);
 #endif

Modified: trunk/Tools/ChangeLog (263044 => 263045)


--- trunk/Tools/ChangeLog	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Tools/ChangeLog	2020-06-15 18:29:58 UTC (rev 263045)
@@ -1,3 +1,13 @@
+2020-06-15  Keith Miller  <[email protected]>
+
+        Signal handlers should have a two phase installation.
+        https://bugs.webkit.org/show_bug.cgi?id=213160
+
+        Reviewed by Mark Lam.
+
+        * TestWebKitAPI/Tests/WTF/Signals.cpp:
+        (TEST):
+
 2020-06-15  Sihui Liu  <[email protected]>
 
         Text manipulation does not observe newly displayed element inside previously observed content

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/Signals.cpp (263044 => 263045)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/Signals.cpp	2020-06-15 17:51:38 UTC (rev 263044)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/Signals.cpp	2020-06-15 18:29:58 UTC (rev 263045)
@@ -40,11 +40,12 @@
 TEST(Signals, SignalsWorkOnExit)
 {
     static bool handlerRan = false;
-    installSignalHandler(Signal::Usr, [] (Signal, SigInfo&, PlatformRegisters&) -> SignalAction {
+    addSignalHandler(Signal::Usr, [] (Signal, SigInfo&, PlatformRegisters&) -> SignalAction {
         dataLogLn("here");
         handlerRan = true;
         return SignalAction::Handled;
     });
+    activateSignalHandlersFor(Signal::Usr);
 
     Atomic<bool> receiverShouldKeepRunning(true);
     Ref<Thread> receiverThread = (Thread::create("ThreadMessage receiver",
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to