signalvar.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* $OpenBSD: signalvar.h,v 1.28 2015/05/05 02:13:46 guenther Exp $ */
  2. /* $NetBSD: signalvar.h,v 1.17 1996/04/22 01:23:31 christos Exp $ */
  3. /*
  4. * Copyright (c) 1991, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the University nor the names of its contributors
  16. * may be used to endorse or promote products derived from this software
  17. * without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * @(#)signalvar.h 8.3 (Berkeley) 1/4/94
  32. */
  33. #ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */
  34. #define _SYS_SIGNALVAR_H_
  35. /*
  36. * Kernel signal definitions and data structures,
  37. * not exported to user programs.
  38. */
  39. /*
  40. * Process signal actions and state, needed only within the process
  41. * (not necessarily resident).
  42. */
  43. struct sigacts {
  44. sig_t ps_sigact[NSIG]; /* disposition of signals */
  45. sigset_t ps_catchmask[NSIG]; /* signals to be blocked */
  46. sigset_t ps_sigonstack; /* signals to take on sigstack */
  47. sigset_t ps_sigintr; /* signals that interrupt syscalls */
  48. sigset_t ps_sigreset; /* signals that reset when caught */
  49. sigset_t ps_siginfo; /* signals that provide siginfo */
  50. sigset_t ps_sigignore; /* signals being ignored */
  51. sigset_t ps_sigcatch; /* signals being caught by user */
  52. int ps_flags; /* signal flags, below */
  53. int ps_refcnt; /* reference count */
  54. };
  55. /* signal flags */
  56. #define SAS_NOCLDSTOP 0x01 /* No SIGCHLD when children stop. */
  57. #define SAS_NOCLDWAIT 0x02 /* No zombies if child dies */
  58. /* additional signal action values, used only temporarily/internally */
  59. #define SIG_CATCH (void (*)(int))2
  60. #define SIG_HOLD (void (*)(int))3
  61. /*
  62. * Determine signal that should be delivered to process p, the current
  63. * process, 0 if none. If there is a pending stop signal with default
  64. * action, the process stops in issignal().
  65. */
  66. #define CURSIG(p) \
  67. (((p)->p_siglist == 0 || \
  68. (((p)->p_p->ps_flags & PS_TRACED) == 0 && \
  69. ((p)->p_siglist & ~(p)->p_sigmask) == 0)) ? \
  70. 0 : issignal(p))
  71. /*
  72. * Clear a pending signal from a process.
  73. */
  74. #define CLRSIG(p, sig) atomic_clearbits_int(&(p)->p_siglist, sigmask(sig))
  75. /*
  76. * Signal properties and actions.
  77. * The array below categorizes the signals and their default actions
  78. * according to the following properties:
  79. */
  80. #define SA_KILL 0x01 /* terminates process by default */
  81. #define SA_CORE 0x02 /* ditto and coredumps */
  82. #define SA_STOP 0x04 /* suspend process */
  83. #define SA_TTYSTOP 0x08 /* ditto, from tty */
  84. #define SA_IGNORE 0x10 /* ignore by default */
  85. #define SA_CONT 0x20 /* continue if suspended */
  86. #define SA_CANTMASK 0x40 /* non-maskable, catchable */
  87. #ifdef SIGPROP
  88. int sigprop[NSIG + 1] = {
  89. 0, /* unused */
  90. SA_KILL, /* SIGHUP */
  91. SA_KILL, /* SIGINT */
  92. SA_KILL|SA_CORE, /* SIGQUIT */
  93. SA_KILL|SA_CORE, /* SIGILL */
  94. SA_KILL|SA_CORE, /* SIGTRAP */
  95. SA_KILL|SA_CORE, /* SIGABRT */
  96. SA_KILL|SA_CORE, /* SIGEMT */
  97. SA_KILL|SA_CORE, /* SIGFPE */
  98. SA_KILL, /* SIGKILL */
  99. SA_KILL|SA_CORE, /* SIGBUS */
  100. SA_KILL|SA_CORE, /* SIGSEGV */
  101. SA_KILL|SA_CORE, /* SIGSYS */
  102. SA_KILL, /* SIGPIPE */
  103. SA_KILL, /* SIGALRM */
  104. SA_KILL, /* SIGTERM */
  105. SA_IGNORE, /* SIGURG */
  106. SA_STOP, /* SIGSTOP */
  107. SA_STOP|SA_TTYSTOP, /* SIGTSTP */
  108. SA_IGNORE|SA_CONT, /* SIGCONT */
  109. SA_IGNORE, /* SIGCHLD */
  110. SA_STOP|SA_TTYSTOP, /* SIGTTIN */
  111. SA_STOP|SA_TTYSTOP, /* SIGTTOU */
  112. SA_IGNORE, /* SIGIO */
  113. SA_KILL, /* SIGXCPU */
  114. SA_KILL, /* SIGXFSZ */
  115. SA_KILL, /* SIGVTALRM */
  116. SA_KILL, /* SIGPROF */
  117. SA_IGNORE, /* SIGWINCH */
  118. SA_IGNORE, /* SIGINFO */
  119. SA_KILL, /* SIGUSR1 */
  120. SA_KILL, /* SIGUSR2 */
  121. SA_IGNORE, /* SIGTHR */
  122. };
  123. #define contsigmask (sigmask(SIGCONT))
  124. #define stopsigmask (sigmask(SIGSTOP) | sigmask(SIGTSTP) | \
  125. sigmask(SIGTTIN) | sigmask(SIGTTOU))
  126. #endif /* SIGPROP */
  127. #define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP))
  128. #ifdef _KERNEL
  129. enum signal_type { SPROCESS, STHREAD, SPROPAGATED };
  130. /*
  131. * Machine-independent functions:
  132. */
  133. int coredump(struct proc *p);
  134. void execsigs(struct proc *p);
  135. void gsignal(int pgid, int sig);
  136. void csignal(pid_t pgid, int signum, uid_t uid, uid_t euid);
  137. int issignal(struct proc *p);
  138. void pgsignal(struct pgrp *pgrp, int sig, int checkctty);
  139. void postsig(int sig);
  140. void psignal(struct proc *p, int sig);
  141. void ptsignal(struct proc *p, int sig, enum signal_type type);
  142. #define prsignal(pr,sig) ptsignal((pr)->ps_mainproc, (sig), SPROCESS)
  143. void siginit(struct process *);
  144. void trapsignal(struct proc *p, int sig, u_long code, int type,
  145. union sigval val);
  146. void sigexit(struct proc *, int);
  147. int sigonstack(size_t);
  148. void setsigvec(struct proc *, int, struct sigaction *);
  149. int killpg1(struct proc *, int, int, int);
  150. void signal_init(void);
  151. struct sigacts *sigactsinit(struct process *);
  152. struct sigacts *sigactsshare(struct process *);
  153. void sigstkinit(struct sigaltstack *);
  154. void sigactsunshare(struct process *);
  155. void sigactsfree(struct process *);
  156. /*
  157. * Machine-dependent functions:
  158. */
  159. void sendsig(sig_t action, int sig, int returnmask, u_long code,
  160. int type, union sigval val);
  161. #endif /* _KERNEL */
  162. #endif /* !_SYS_SIGNALVAR_H_ */