]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/sys/signalvar.h
If the credential on an incoming thread is correct, don't bother
[FreeBSD/FreeBSD.git] / sys / sys / signalvar.h
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$
35  */
36
37 #ifndef _SYS_SIGNALVAR_H_
38 #define _SYS_SIGNALVAR_H_
39
40 #include <sys/signal.h>
41
42 /*
43  * Kernel signal definitions and data structures,
44  * not exported to user programs.
45  */
46
47 /*
48  * Process signal actions and state, needed only within the process
49  * (not necessarily resident).
50  */
51 struct sigacts {
52         sig_t   ps_sigact[_SIG_MAXSIG]; /* disposition of signals */
53         sigset_t ps_catchmask[_SIG_MAXSIG];     /* signals to be blocked */
54         sigset_t ps_sigonstack;         /* signals to take on sigstack */
55         sigset_t ps_sigintr;            /* signals that interrupt syscalls */
56         sigset_t ps_sigreset;           /* signals that reset when caught */
57         sigset_t ps_signodefer;         /* signals not masked while handled */
58         sigset_t ps_siginfo;            /* signals that want SA_SIGINFO args */
59         sigset_t ps_osigset;            /* signals that use osigset_t */
60         sigset_t ps_usertramp;          /* SunOS compat; libc sigtramp XXX */
61 };
62
63 /*
64  * Compatibility.
65  */
66 typedef struct {
67         struct osigcontext si_sc;
68         int             si_signo;
69         int             si_code;
70         union sigval    si_value;
71 } osiginfo_t;
72
73 struct osigaction {
74         union {
75                 void    (*__sa_handler) __P((int));
76                 void    (*__sa_sigaction) __P((int, osiginfo_t *, void *));
77         } __sigaction_u;                /* signal handler */
78         osigset_t       sa_mask;        /* signal mask to apply */
79         int             sa_flags;       /* see signal options below */
80 };
81
82 typedef void __osiginfohandler_t __P((int, osiginfo_t *, void *));
83
84 /* additional signal action values, used only temporarily/internally */
85 #define SIG_CATCH       ((__sighandler_t *)2)
86 #define SIG_HOLD        ((__sighandler_t *)3)
87
88 /*
89  * get signal action for process and signal; currently only for current process
90  */
91 #define SIGACTION(p, sig)       (p->p_sigacts->ps_sigact[_SIG_IDX(sig)])
92
93 /*
94  * sigset_t manipulation macros
95  */
96 #define SIGADDSET(set, signo)                                           \
97         (set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo)
98
99 #define SIGDELSET(set, signo)                                           \
100         (set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo)
101
102 #define SIGEMPTYSET(set)                                                \
103         do {                                                            \
104                 int __i;                                                \
105                 for (__i = 0; __i < _SIG_WORDS; __i++)                  \
106                         (set).__bits[__i] = 0;                          \
107         } while (0)
108
109 #define SIGFILLSET(set)                                                 \
110         do {                                                            \
111                 int __i;                                                \
112                 for (__i = 0; __i < _SIG_WORDS; __i++)                  \
113                         (set).__bits[__i] = ~0U;                        \
114         } while (0)
115
116 #define SIGISMEMBER(set, signo)                                         \
117         ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo))
118
119 #define SIGISEMPTY(set)         __sigisempty(&(set))
120 #define SIGNOTEMPTY(set)        (!__sigisempty(&(set)))
121
122 #define SIGSETEQ(set1, set2)    __sigseteq(&(set1), &(set2))
123 #define SIGSETNEQ(set1, set2)   (!__sigseteq(&(set1), &(set2)))
124
125 #define SIGSETOR(set1, set2)                                            \
126         do {                                                            \
127                 int __i;                                                \
128                 for (__i = 0; __i < _SIG_WORDS; __i++)                  \
129                         (set1).__bits[__i] |= (set2).__bits[__i];       \
130         } while (0)
131
132 #define SIGSETAND(set1, set2)                                           \
133         do {                                                            \
134                 int __i;                                                \
135                 for (__i = 0; __i < _SIG_WORDS; __i++)                  \
136                         (set1).__bits[__i] &= (set2).__bits[__i];       \
137         } while (0)
138
139 #define SIGSETNAND(set1, set2)                                          \
140         do {                                                            \
141                 int __i;                                                \
142                 for (__i = 0; __i < _SIG_WORDS; __i++)                  \
143                         (set1).__bits[__i] &= ~(set2).__bits[__i];      \
144         } while (0)
145
146 #define SIGSETLO(set1, set2)    ((set1).__bits[0] = (set2).__bits[0])
147 #define SIGSETOLD(set, oset)    ((set).__bits[0] = (oset))
148
149 #define SIG_CANTMASK(set)                                               \
150         SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP)
151
152 #define SIG_STOPSIGMASK(set)                                            \
153         SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP),               \
154         SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU)
155
156 #define SIG_CONTSIGMASK(set)                                            \
157         SIGDELSET(set, SIGCONT)
158
159 #define sigcantmask     (sigmask(SIGKILL) | sigmask(SIGSTOP))
160
161 #define SIG2OSIG(sig, osig)     osig = (sig).__bits[0]
162 #define OSIG2SIG(osig, sig)     SIGEMPTYSET(sig); (sig).__bits[0] = osig
163
164 static __inline int
165 __sigisempty(sigset_t *set)
166 {
167         int i;
168
169         for (i = 0; i < _SIG_WORDS; i++) {
170                 if (set->__bits[i])
171                         return (0);
172         }
173         return (1);
174 }
175
176 static __inline int
177 __sigseteq(sigset_t *set1, sigset_t *set2)
178 {
179         int i;
180
181         for (i = 0; i < _SIG_WORDS; i++) {
182                 if (set1->__bits[i] != set2->__bits[i])
183                         return (0);
184         }
185         return (1);
186 }
187
188 #ifdef _KERNEL
189
190 struct pgrp;
191 struct thread;
192 struct proc;
193 struct sigio;
194
195 extern int sugid_coredump;      /* Sysctl variable kern.sugid_coredump */
196
197 /*
198  * Machine-independent functions:
199  */
200 int     CURSIG(struct proc *p);
201 void    execsigs __P((struct proc *p));
202 void    gsignal __P((int pgid, int sig));
203 int     issignal __P((struct proc *p));
204 void    killproc __P((struct proc *p, char *why));
205 void    pgsigio __P((struct sigio *, int signum, int checkctty));
206 void    pgsignal __P((struct pgrp *pgrp, int sig, int checkctty));
207 void    postsig __P((int sig));
208 void    psignal __P((struct proc *p, int sig));
209 void    sigexit __P((struct thread *td, int signum)) __dead2;
210 void    siginit __P((struct proc *p));
211 void    trapsignal __P((struct proc *p, int sig, u_long code));
212
213 /*
214  * Machine-dependent functions:
215  */
216 void    sendsig __P((sig_t action, int sig, sigset_t *retmask, u_long code));
217
218 #endif /* _KERNEL */
219
220 #endif /* !_SYS_SIGNALVAR_H_ */