+
+/* -----------------------------------------------------------------------------
+ * Install default signal handlers.
+ *
+ * The RTS installs a default signal handler for catching
+ * SIGINT, so that we can perform an orderly shutdown.
+ *
+ * Haskell code may install their own SIGINT handler, which is
+ * fine, provided they're so kind as to put back the old one
+ * when they de-install.
+ *
+ * In addition to handling SIGINT, the RTS also handles SIGFPE
+ * by ignoring it. Apparently IEEE requires floating-point
+ * exceptions to be ignored by default, but alpha-dec-osf3
+ * doesn't seem to do so.
+ * -------------------------------------------------------------------------- */
+void
+initDefaultHandlers()
+{
+ struct sigaction action,oact;
+
+#ifdef SMP
+ startup_guy = pthread_self();
+#endif
+#ifdef RTS_SUPPORTS_THREADS
+ handleSignalsInThisThread();
+#endif
+
+ // install the SIGINT handler
+ action.sa_handler = shutdown_handler;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+ if (sigaction(SIGINT, &action, &oact) != 0) {
+ errorBelch("warning: failed to install SIGINT handler");
+ }
+
+#if defined(HAVE_SIGINTERRUPT)
+ siginterrupt(SIGINT, 1); // isn't this the default? --SDM
+#endif
+
+ // install the SIGCONT handler
+ action.sa_handler = cont_handler;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+ if (sigaction(SIGCONT, &action, &oact) != 0) {
+ errorBelch("warning: failed to install SIGCONT handler");
+ }
+
+ // install the SIGFPE handler
+
+ // In addition to handling SIGINT, also handle SIGFPE by ignoring it.
+ // Apparently IEEE requires floating-point exceptions to be ignored by
+ // default, but alpha-dec-osf3 doesn't seem to do so.
+
+ // Commented out by SDM 2/7/2002: this causes an infinite loop on
+ // some architectures when an integer division by zero occurs: we
+ // don't recover from the floating point exception, and the
+ // program just generates another one immediately.
+#if 0
+ action.sa_handler = SIG_IGN;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+ if (sigaction(SIGFPE, &action, &oact) != 0) {
+ errorBelch("warning: failed to install SIGFPE handler");
+ }
+#endif
+
+#ifdef alpha_HOST_ARCH
+ ieee_set_fp_control(0);