home *** CD-ROM | disk | FTP | other *** search
- #ifdef BSD
- #include <stdio.h>
- #include <sys/types.h>
- #include <signal.h>
-
- extern int errno;
-
- #undef integer /* Silly stdtypes */
- #include "Kernel/h/system.h"
- #include "Kernel/h/stdTypes.h"
- #include "Kernel/h/kEvents.h"
- #include "Kernel/h/kmdTypes.h"
-
- extern void EmeraldSigUpCall();
-
- /*
- * SetHandler(signal, handler)
- *
- * Signal is a Unix signal. Handler is a pointer to a function which
- * handles that signal.
- *
- * Called by other modules in the kernel to specify that a particular
- * routine is to be called when a signal comes in. Analogous to the
- * Unix system call sigset(). The main difference is that critical
- * sections can be protected by calls to HoldSigs and ReleaseSigs, in
- * which case the call to the handler is deferred until the call to
- * ReleaseSigs.
- * Revised to access an array of pointers to the active signal table
- * entries, and to conform to new signal hold/release protocol.
- * [Eric Jul, Aug. 1983.]
- *
- * Modified June 1986 to use alternative signal stack and to hold
- * other signals while in a signal handler (as to keep overhead down
- * and avoid signal stack overflow).
- */
-
-
- #define THESIGMASK \
- 1<<SIGPIPE | \
- 1<<SIGALRM | \
- 1<<SIGURG | \
- 1<<SIGCHLD | \
- 1<<SIGIO | \
- 1<<SIGXCPU | \
- 1<<SIGXFSZ | \
- 1<<SIGVTALRM | \
- 1<<28 | \
- 1<<29 | \
- 1<<30
-
- void SetHandler(sig, handler)
- int sig;
- void (* handler)();
- /* Set a signal handler in a way so that HoldSigs and ReleaseSigs
- may be used to block the signal */
- {
- /*
- * It is assumed that the alternate signal stack has already
- * been defined using sigstack
- */
- struct sigvec vec;
-
- DebugMsg(4, "Setting #%d signal %d handler = 0x%08x\n", ActCount, sig,
- handler);
-
- SigTable[sig].Handler = handler;
- ActSig[ActCount++] = sig;
- vec.sv_handler = RealSigHandler;
- vec.sv_mask = THESIGMASK;
- vec.sv_onstack = 1; /* use the alternate stack */
- if (sigvec(sig, &vec, 0) == -1) {
- perror("sigvec");
- abort();
- };
- }
-
- /*
- * RealSigHandler(sig)
- *
- * This is the routine that runs at interrupt time.
- *
- * Little known fact: Signal handlers are given the signal number as
- * first argument. This is undocumented as far as I know. We probably
- * shouldn't rely on undocumented "features".
- * Note for later versions: It is a documented feature of Unix 4.2bsd.
- */
-
- RealSigHandler(sig)
- int sig;
- {
- register int savedErrno; /* Signal handler must not destroy errno */
- savedErrno = errno;
- DebugMsg(4, "Signal %d has arrived\n", sig);
- /* The following call tells the Emerald kernel about the signal */
- EmeraldSigUpCall(sig);
- errno = savedErrno;
- if (SigsHeld) {
- SigTable[sig].Ntimes++;
- Pending = 1;
- DebugMsg(5, " signal count now: %d\n", SigTable[sig].Ntimes);
- }
- else
- (SigTable[sig].Handler)(sig);
- errno = savedErrno;
- }
-
- #endif BSD
-