summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCheng Shao <terrorjack@type.dance>2023-04-02 13:46:41 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-04-24 12:20:21 -0400
commit2685a12d462573ce23ef7f4356a2f8c95ef63e1d (patch)
tree40d96645b79f7800905cc02df446c9f5a779bd14
parent87095f6a283d95016f66f4a14a3da923c394877c (diff)
downloadhaskell-2685a12d462573ce23ef7f4356a2f8c95ef63e1d.tar.gz
compiler: don't install signal handlers when the host platform doesn't have signals
Previously, large parts of GHC API will transitively invoke withSignalHandlers, which doesn't work on host platforms without signal functionality at all (e.g. wasm32-wasi). By making withSignalHandlers a no-op on those platforms, we can make more parts of GHC API work out of the box when signals aren't supported.
-rw-r--r--compiler/GHC/Utils/Panic.hs8
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/GHC/Utils/Panic.hs b/compiler/GHC/Utils/Panic.hs
index 94d9e7cefd..0a95ea4d1e 100644
--- a/compiler/GHC/Utils/Panic.hs
+++ b/compiler/GHC/Utils/Panic.hs
@@ -7,6 +7,8 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables, LambdaCase #-}
+#include <ghcautoconf.h>
+
-- | Defines basic functions for printing error messages.
--
-- It's hard to put these functions anywhere else without causing
@@ -236,6 +238,11 @@ signalHandlersRefCount = unsafePerformIO $ newMVar (0,Nothing)
-- | Temporarily install standard signal handlers for catching ^C, which just
-- throw an exception in the current thread.
withSignalHandlers :: ExceptionMonad m => m a -> m a
+#if !defined(HAVE_SIGNAL_H)
+-- No signal functionality exist on the host platform (e.g. on
+-- wasm32-wasi), so don't attempt to set up signal handlers
+withSignalHandlers = id
+#else
withSignalHandlers act = do
main_thread <- liftIO myThreadId
wtid <- liftIO (mkWeakThreadId main_thread)
@@ -295,6 +302,7 @@ withSignalHandlers act = do
mayInstallHandlers
act `MC.finally` mayUninstallHandlers
+#endif
callStackDoc :: HasCallStack => SDoc
callStackDoc = prettyCallStackDoc callStack