1 /* 2 * Copyright (c) 1982, 1986, 1989 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)signal.h 7.13 (Berkeley) 10/31/90 8 */ 9 10 #ifndef NSIG 11 #define NSIG 32 /* counting 0; could be 33 (mask is 1-32) */ 12 13 #ifndef _POSIX_SOURCE 14 #ifdef KERNEL 15 #include "machine/trap.h" /* codes for SIGILL, SIGFPE */ 16 #else 17 #include <machine/trap.h> /* codes for SIGILL, SIGFPE */ 18 #endif 19 #endif /* _POSIX_SOURCE */ 20 21 #define SIGHUP 1 /* hangup */ 22 #define SIGINT 2 /* interrupt */ 23 #define SIGQUIT 3 /* quit */ 24 #define SIGILL 4 /* illegal instruction (not reset when caught) */ 25 #ifndef _POSIX_SOURCE 26 #define SIGTRAP 5 /* trace trap (not reset when caught) */ 27 #endif 28 #define SIGABRT 6 /* abort() */ 29 #ifndef _POSIX_SOURCE 30 #define SIGIOT SIGABRT /* compatibility */ 31 #define SIGEMT 7 /* EMT instruction */ 32 #endif 33 #define SIGFPE 8 /* floating point exception */ 34 #define SIGKILL 9 /* kill (cannot be caught or ignored) */ 35 #ifndef _POSIX_SOURCE 36 #define SIGBUS 10 /* bus error */ 37 #endif 38 #define SIGSEGV 11 /* segmentation violation */ 39 #ifndef _POSIX_SOURCE 40 #define SIGSYS 12 /* bad argument to system call */ 41 #endif 42 #define SIGPIPE 13 /* write on a pipe with no one to read it */ 43 #define SIGALRM 14 /* alarm clock */ 44 #define SIGTERM 15 /* software termination signal from kill */ 45 #ifndef _POSIX_SOURCE 46 #define SIGURG 16 /* urgent condition on IO channel */ 47 #endif 48 #define SIGSTOP 17 /* sendable stop signal not from tty */ 49 #define SIGTSTP 18 /* stop signal from tty */ 50 #define SIGCONT 19 /* continue a stopped process */ 51 #define SIGCHLD 20 /* to parent on child stop or exit */ 52 #define SIGTTIN 21 /* to readers pgrp upon background tty read */ 53 #define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ 54 #ifndef _POSIX_SOURCE 55 #define SIGIO 23 /* input/output possible signal */ 56 #define SIGXCPU 24 /* exceeded CPU time limit */ 57 #define SIGXFSZ 25 /* exceeded file size limit */ 58 #define SIGVTALRM 26 /* virtual time alarm */ 59 #define SIGPROF 27 /* profiling time alarm */ 60 #define SIGWINCH 28 /* window size changes */ 61 #define SIGINFO 29 /* information request */ 62 #endif 63 #define SIGUSR1 30 /* user defined signal 1 */ 64 #define SIGUSR2 31 /* user defined signal 2 */ 65 66 #ifndef _POSIX_SOURCE 67 typedef void (*sig_t)(); 68 #endif 69 70 #ifndef KERNEL 71 void (*signal())(); 72 #endif 73 74 typedef unsigned int sigset_t; 75 76 #if __STDC__ || c_plusplus 77 int sigemptyset(sigset_t *); 78 int sigfillset(sigset_t *); 79 int sigaddset(sigset_t *, int); 80 int sigdelset(sigset_t *, int); 81 int sigismember(const sigset_t *, int); 82 #else 83 int sigemptyset(); 84 int sigfillset(); 85 int sigaddset(); 86 int sigdelset(); 87 int sigismember(); 88 #endif 89 90 #define sigemptyset(set) ( *(set) = 0 ) 91 #define sigfillset(set) ( *(set) = ~(sigset_t)0, 0 ) 92 #define sigaddset(set, signo) ( *(set) |= 1 << ((signo) - 1), 0) 93 #define sigdelset(set, signo) ( *(set) &= ~(1 << ((signo) - 1)), 0) 94 #define sigismember(set, signo) ( (*(set) & (1 << ((signo) - 1))) != 0) 95 96 /* 97 * Signal vector "template" used in sigaction call. 98 */ 99 struct sigaction { 100 void (*sa_handler)(); /* signal handler */ 101 sigset_t sa_mask; /* signal mask to apply */ 102 int sa_flags; /* see signal options below */ 103 }; 104 #ifndef _POSIX_SOURCE 105 #define SA_ONSTACK 0x0001 /* take signal on signal stack */ 106 #define SA_RESTART 0x0002 /* do not restart system on signal return */ 107 #endif 108 #define SA_NOCLDSTOP 0x0004 /* do not generate SIGCHLD on child stop */ 109 110 /* 111 * Flags for sigprocmask: 112 */ 113 #define SIG_BLOCK 1 /* block specified signal set */ 114 #define SIG_UNBLOCK 2 /* unblock specified signal set */ 115 #define SIG_SETMASK 3 /* set specified signal set */ 116 117 #ifndef _POSIX_SOURCE 118 /* 119 * 4.3 compatibility: 120 * Signal vector "template" used in sigvec call. 121 */ 122 struct sigvec { 123 void (*sv_handler)(); /* signal handler */ 124 int sv_mask; /* signal mask to apply */ 125 int sv_flags; /* see signal options below */ 126 }; 127 #define SV_ONSTACK SA_ONSTACK 128 #define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */ 129 #define sv_onstack sv_flags /* isn't compatibility wonderful! */ 130 131 /* 132 * Structure used in sigstack call. 133 */ 134 struct sigstack { 135 char *ss_sp; /* signal stack pointer */ 136 int ss_onstack; /* current status */ 137 }; 138 139 /* 140 * Information pushed on stack when a signal is delivered. 141 * This is used by the kernel to restore state following 142 * execution of the signal handler. It is also made available 143 * to the handler to allow it to restore state properly if 144 * a non-standard exit is performed. 145 */ 146 struct sigcontext { 147 int sc_onstack; /* sigstack state to restore */ 148 int sc_mask; /* signal mask to restore */ 149 int sc_sp; /* sp to restore */ 150 int sc_fp; /* fp to restore */ 151 int sc_ap; /* ap to restore */ 152 int sc_pc; /* pc to restore */ 153 int sc_ps; /* psl to restore */ 154 }; 155 156 /* 157 * Macro for converting signal number to a mask suitable for 158 * sigblock(). 159 */ 160 #define sigmask(m) (1 << ((m)-1)) 161 162 #define BADSIG (void (*)())-1 163 #endif /* _POSIX_SOURCE */ 164 165 #define SIG_DFL (void (*)())0 166 #define SIG_IGN (void (*)())1 167 168 #ifdef KERNEL 169 #define SIG_CATCH (void (*)())2 170 #define SIG_HOLD (void (*)())3 171 172 #define sigcantmask (sigmask(SIGKILL)|sigmask(SIGSTOP)) 173 /* 174 * get signal action for process and signal; currently only for current process 175 */ 176 #define SIGACTION(p, sig) (u.u_signal[(sig)]) 177 178 /* 179 * Determine signal that should be delivered to process p, the current process, 180 * 0 if none. If there is a pending stop signal with default action, 181 * the process stops in issig(). 182 */ 183 #define CURSIG(p) \ 184 (((p)->p_sig == 0 || \ 185 ((p)->p_flag&STRC) == 0 && ((p)->p_sig &~ (p)->p_sigmask) == 0) ? \ 186 0 : issig()) 187 188 /* 189 * Clear a pending signal from a process. 190 */ 191 #define CLRSIG(p, sig) { (p)->p_sig &= ~sigmask(sig); } 192 193 #endif /* KERNEL */ 194 195 #ifndef KERNEL 196 #if __STDC__ || c_plusplus 197 #include <sys/types.h> 198 int kill(pid_t, int); 199 int sigaction(int, const struct sigaction *, struct sigaction *); 200 int sigprocmask(int, const sigset_t *, sigset_t *); 201 int sigpending(sigset_t *); 202 int sigsuspend(const sigset_t *); 203 #else 204 int kill(); 205 int sigaction(); 206 int sigprocmask(); 207 int sigpending(); 208 int sigsuspend(); 209 #endif 210 #endif 211 #endif /* NSIG */ 212