Add a DECLARE_DUMMY_MODULE for snd_cmi to detect kld/static-kernel conflicts.
[dragonfly.git] / sys / sys / signalvar.h
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)signalvar.h 8.6 (Berkeley) 2/19/95
34 * $FreeBSD: src/sys/sys/signalvar.h,v 1.34.2.1 2000/05/16 06:58:05 dillon Exp $
65957d54 35 * $DragonFly: src/sys/sys/signalvar.h,v 1.7 2003/10/24 14:10:46 daver Exp $
984263bc
MD
36 */
37
38#ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */
39#define _SYS_SIGNALVAR_H_
40
41#include <sys/signal.h>
42#include <sys/proc.h>
8a8d5d85 43#include <machine/lock.h>
984263bc
MD
44
45/*
46 * Kernel signal definitions and data structures,
47 * not exported to user programs.
48 */
49
50/*
51 * Process signal actions and state, needed only within the process
52 * (not necessarily resident).
53 */
54struct sigacts {
55 sig_t ps_sigact[_SIG_MAXSIG]; /* disposition of signals */
56 sigset_t ps_catchmask[_SIG_MAXSIG]; /* signals to be blocked */
57 sigset_t ps_sigonstack; /* signals to take on sigstack */
58 sigset_t ps_sigintr; /* signals that interrupt syscalls */
59 sigset_t ps_sigreset; /* signals that reset when caught */
60 sigset_t ps_signodefer; /* signals not masked while handled */
61 sigset_t ps_siginfo; /* signals that want SA_SIGINFO args */
984263bc
MD
62 sigset_t ps_usertramp; /* SunOS compat; libc sigtramp XXX */
63};
64
984263bc
MD
65/* additional signal action values, used only temporarily/internally */
66#define SIG_CATCH ((__sighandler_t *)2)
67#define SIG_HOLD ((__sighandler_t *)3)
68
69/*
70 * get signal action for process and signal; currently only for current process
71 */
72#define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)])
73
74/*
75 * sigset_t manipulation macros
76 */
77#define SIGADDSET(set, signo) \
78 (set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo)
79
80#define SIGDELSET(set, signo) \
81 (set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo)
82
83#define SIGEMPTYSET(set) \
84 do { \
85 int __i; \
86 for (__i = 0; __i < _SIG_WORDS; __i++) \
87 (set).__bits[__i] = 0; \
88 } while (0)
89
90#define SIGFILLSET(set) \
91 do { \
92 int __i; \
93 for (__i = 0; __i < _SIG_WORDS; __i++) \
94 (set).__bits[__i] = ~(unsigned int)0; \
95 } while (0)
96
97#define SIGISMEMBER(set, signo) \
98 ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo))
99
100#define SIGISEMPTY(set) __sigisempty(&(set))
101#define SIGNOTEMPTY(set) (!__sigisempty(&(set)))
102
103#define SIGSETEQ(set1, set2) __sigseteq(&(set1), &(set2))
104#define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2)))
105
106#define SIGSETOR(set1, set2) \
107 do { \
108 int __i; \
109 for (__i = 0; __i < _SIG_WORDS; __i++) \
110 (set1).__bits[__i] |= (set2).__bits[__i]; \
111 } while (0)
112
113#define SIGSETAND(set1, set2) \
114 do { \
115 int __i; \
116 for (__i = 0; __i < _SIG_WORDS; __i++) \
117 (set1).__bits[__i] &= (set2).__bits[__i]; \
118 } while (0)
119
120#define SIGSETNAND(set1, set2) \
121 do { \
122 int __i; \
123 for (__i = 0; __i < _SIG_WORDS; __i++) \
124 (set1).__bits[__i] &= ~(set2).__bits[__i]; \
125 } while (0)
126
984263bc
MD
127#define SIG_CANTMASK(set) \
128 SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP)
129
130#define SIG_STOPSIGMASK(set) \
131 SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \
132 SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU)
133
134#define SIG_CONTSIGMASK(set) \
135 SIGDELSET(set, SIGCONT)
136
137#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP))
138
984263bc
MD
139static __inline int
140__sigisempty(sigset_t *set)
141{
142 int i;
143
144 for (i = 0; i < _SIG_WORDS; i++) {
145 if (set->__bits[i])
146 return (0);
147 }
148 return (1);
149}
150
151static __inline int
152__sigseteq(sigset_t *set1, sigset_t *set2)
153{
154 int i;
155
156 for (i = 0; i < _SIG_WORDS; i++) {
157 if (set1->__bits[i] != set2->__bits[i])
158 return (0);
159 }
160 return (1);
161}
162
163#ifdef _KERNEL
164
9d63d5c0
MD
165typedef void (*proc_func_t)(struct proc *);
166
984263bc
MD
167struct pgrp;
168struct proc;
169struct sigio;
170
171extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */
172
173/*
174 * Machine-independent functions:
175 */
b153f746
RG
176void check_sigacts (void);
177void execsigs (struct proc *p);
178void gsignal (int pgid, int sig);
179int issignal (struct proc *p);
180void killproc (struct proc *p, char *why);
181void pgsigio (struct sigio *, int signum, int checkctty);
182void pgsignal (struct pgrp *pgrp, int sig, int checkctty);
183void postsig (int sig);
184void psignal (struct proc *p, int sig);
185void siginit (struct proc *p);
186void trapsignal (struct proc *p, int sig, u_long code);
187int __cursig (struct proc *p);
9d63d5c0
MD
188proc_func_t register_ckpt_func(proc_func_t func);
189
984263bc
MD
190
191/*
192 * Machine-dependent functions:
193 */
b153f746
RG
194void sendsig (sig_t action, int sig, sigset_t *retmask, u_long code);
195void sigexit (struct proc *p, int sig);
984263bc
MD
196
197/*
198 * Inline functions:
199 */
200#define CURSIG(p) __cursig(p)
201
202/*
203 * Determine signal that should be delivered to process p, the current
204 * process, 0 if none. If there is a pending stop signal with default
205 * action, the process stops in issignal().
206 *
207 * MP SAFE
208 */
209extern __inline int __cursig(struct proc *p)
210{
211 sigset_t tmpset;
212 int r;
213
214 tmpset = p->p_siglist;
215 SIGSETNAND(tmpset, p->p_sigmask);
216 if (SIGISEMPTY(p->p_siglist) ||
217 (!(p->p_flag & P_TRACED) && SIGISEMPTY(tmpset))) {
218 return(0);
219 }
984263bc 220 r = issignal(p);
984263bc
MD
221 return(r);
222}
223
224#endif /* _KERNEL */
225
226#endif /* !_SYS_SIGNALVAR_H_ */