/* -----------------------------------------------------------------------------
- * $Id: Signals.c,v 1.27 2002/09/03 14:07:03 simonmar Exp $
+ * $Id: Signals.c,v 1.30 2002/12/05 14:20:55 stolz Exp $
*
* (c) The GHC Team, 1998-1999
*
* Install a Haskell signal handler.
* -------------------------------------------------------------------------- */
-StgInt
-stg_sig_install(StgInt sig, StgInt spi, StgStablePtr handler, void *mask)
+int
+stg_sig_install(int sig, int spi, StgStablePtr *handler, void *mask)
{
sigset_t signals, osignals;
struct sigaction action;
break;
case STG_SIG_HAN:
- handlers[sig] = (StgInt)handler;
+ case STG_SIG_RST:
+ handlers[sig] = (StgInt)*handler;
sigaddset(&userSignals, sig);
action.sa_handler = generic_handler;
+ if (spi == STG_SIG_RST) {
+ action.sa_flags = SA_RESETHAND;
+ }
n_haskell_handlers++;
break;
else
sigemptyset(&action.sa_mask);
- action.sa_flags = sig == SIGCHLD && nocldstop ? SA_NOCLDSTOP : 0;
+ action.sa_flags |= sig == SIGCHLD && nocldstop ? SA_NOCLDSTOP : 0;
if (sigaction(sig, &action, NULL) ||
sigprocmask(SIG_SETMASK, &osignals, NULL))
return STG_SIG_ERR;
}
- return previous_spi;
+ if (previous_spi == STG_SIG_DFL || previous_spi == STG_SIG_IGN
+ || previous_spi == STG_SIG_ERR) {
+ return previous_spi;
+ } else {
+ *handler = (StgStablePtr)previous_spi;
+ return STG_SIG_HAN;
+ }
}
/* -----------------------------------------------------------------------------
unblockUserSignals();
}
+/* ----------------------------------------------------------------------------
+ * Mark signal handlers during GC.
+ *
+ * We do this rather than trying to start all the signal handlers
+ * prior to GC, because that requires extra heap for the new threads.
+ * Signals must be blocked (see blockUserSignals() above) during GC to
+ * avoid race conditions.
+ * -------------------------------------------------------------------------- */
+
+void
+markSignalHandlers (evac_fn evac)
+{
+ StgPtr *p;
+
+ p = next_pending_handler;
+ while (p != pending_handler_buf) {
+ p--;
+ evac((StgClosure **)p);
+ }
+}
+
#else // PAR
StgInt
stg_sig_install(StgInt sig, StgInt spi, StgStablePtr handler, sigset_t *mask)