Fix "ls: not found" problem during buildworld. mdate.sh script
[dragonfly.git] / sys / sys / signalvar.h
blobcc249417941201ed7b5cdb2926598310bf2ac388
1 /*
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
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.
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.
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 $
35 * $DragonFly: src/sys/sys/signalvar.h,v 1.12 2004/11/23 06:32:34 dillon Exp $
38 #ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */
39 #define _SYS_SIGNALVAR_H_
42 * Don't bring in the entire bleeding include set if we aren't the kernel.
43 * Userland is not allowed to bring in sys/proc.h except under special
44 * circumstances (e.g. sys/user.h)
46 #include <sys/signal.h>
47 #ifdef _KERNEL
48 #include <sys/proc.h>
49 #include <machine/lock.h>
50 #endif
53 * Kernel signal definitions and data structures,
54 * not exported to user programs.
58 * Process signal actions and state, needed only within the process
59 * (not necessarily resident).
61 struct sigacts {
62 sig_t ps_sigact[_SIG_MAXSIG]; /* disposition of signals */
63 sigset_t ps_catchmask[_SIG_MAXSIG]; /* signals to be blocked */
64 sigset_t ps_sigonstack; /* signals to take on sigstack */
65 sigset_t ps_sigintr; /* signals that interrupt syscalls */
66 sigset_t ps_sigreset; /* signals that reset when caught */
67 sigset_t ps_signodefer; /* signals not masked while handled */
68 sigset_t ps_siginfo; /* signals that want SA_SIGINFO args */
69 sigset_t ps_usertramp; /* SunOS compat; libc sigtramp XXX */
72 /* additional signal action values, used only temporarily/internally */
73 #define SIG_CATCH ((__sighandler_t *)2)
74 #define SIG_HOLD ((__sighandler_t *)3)
76 #ifdef _KERNEL
79 * get signal action for process and signal; currently only for current process
81 #define SIGACTION(p, sig) (p->p_sigacts->ps_sigact[_SIG_IDX(sig)])
83 #endif
86 * sigset_t manipulation macros
88 #define SIGADDSET(set, signo) \
89 (set).__bits[_SIG_WORD(signo)] |= _SIG_BIT(signo)
91 #define SIGDELSET(set, signo) \
92 (set).__bits[_SIG_WORD(signo)] &= ~_SIG_BIT(signo)
94 #define SIGEMPTYSET(set) \
95 do { \
96 int __i; \
97 for (__i = 0; __i < _SIG_WORDS; __i++) \
98 (set).__bits[__i] = 0; \
99 } while (0)
101 #define SIGFILLSET(set) \
102 do { \
103 int __i; \
104 for (__i = 0; __i < _SIG_WORDS; __i++) \
105 (set).__bits[__i] = ~(unsigned int)0; \
106 } while (0)
108 #define SIGISMEMBER(set, signo) \
109 ((set).__bits[_SIG_WORD(signo)] & _SIG_BIT(signo))
111 #define SIGISEMPTY(set) __sigisempty(&(set))
112 #define SIGNOTEMPTY(set) (!__sigisempty(&(set)))
114 #define SIGSETEQ(set1, set2) __sigseteq(&(set1), &(set2))
115 #define SIGSETNEQ(set1, set2) (!__sigseteq(&(set1), &(set2)))
117 #define SIGSETOR(set1, set2) \
118 do { \
119 int __i; \
120 for (__i = 0; __i < _SIG_WORDS; __i++) \
121 (set1).__bits[__i] |= (set2).__bits[__i]; \
122 } while (0)
124 #define SIGSETAND(set1, set2) \
125 do { \
126 int __i; \
127 for (__i = 0; __i < _SIG_WORDS; __i++) \
128 (set1).__bits[__i] &= (set2).__bits[__i]; \
129 } while (0)
131 #define SIGSETNAND(set1, set2) \
132 do { \
133 int __i; \
134 for (__i = 0; __i < _SIG_WORDS; __i++) \
135 (set1).__bits[__i] &= ~(set2).__bits[__i]; \
136 } while (0)
138 #define SIG_CANTMASK(set) \
139 SIGDELSET(set, SIGKILL), SIGDELSET(set, SIGSTOP)
141 #define SIG_STOPSIGMASK(set) \
142 SIGDELSET(set, SIGSTOP), SIGDELSET(set, SIGTSTP), \
143 SIGDELSET(set, SIGTTIN), SIGDELSET(set, SIGTTOU)
145 #define SIG_CONTSIGMASK(set) \
146 SIGDELSET(set, SIGCONT)
148 #define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP))
150 static __inline int
151 __sigisempty(sigset_t *set)
153 int i;
155 for (i = 0; i < _SIG_WORDS; i++) {
156 if (set->__bits[i])
157 return (0);
159 return (1);
162 static __inline int
163 __sigseteq(sigset_t *set1, sigset_t *set2)
165 int i;
167 for (i = 0; i < _SIG_WORDS; i++) {
168 if (set1->__bits[i] != set2->__bits[i])
169 return (0);
171 return (1);
174 #ifdef _KERNEL
176 typedef void (*proc_func_t)(struct proc *);
178 struct pgrp;
179 struct proc;
180 struct sigio;
181 struct vmupcall;
183 extern int sugid_coredump; /* Sysctl variable kern.sugid_coredump */
186 * Machine-independent functions:
188 void check_sigacts (void);
189 void execsigs (struct proc *p);
190 void gsignal (int pgid, int sig);
191 int issignal (struct proc *p);
192 int iscaught (struct proc *p);
193 void killproc (struct proc *p, char *why);
194 void pgsigio (struct sigio *, int signum, int checkctty);
195 void pgsignal (struct pgrp *pgrp, int sig, int checkctty);
196 void postsig (int sig);
197 void psignal (struct proc *p, int sig);
198 void siginit (struct proc *p);
199 void trapsignal (struct proc *p, int sig, u_long code);
200 int __cursig (struct proc *p);
203 * Machine-dependent functions:
205 void sendsig (sig_t action, int sig, sigset_t *retmask, u_long code);
206 void sendupcall (struct vmupcall *vu, int morepending);
207 int fetchupcall (struct vmupcall *vu, int morepending, void *rsp);
208 void sigexit (struct proc *p, int sig);
209 int checkpoint_signal_handler(struct proc *p);
212 * Inline functions:
214 #define CURSIG(p) __cursig(p)
217 * Determine signal that should be delivered to process p, the current
218 * process, 0 if none. If there is a pending stop signal with default
219 * action, the process stops in issignal().
221 * MP SAFE
223 extern __inline int __cursig(struct proc *p)
225 sigset_t tmpset;
226 int r;
228 tmpset = p->p_siglist;
229 SIGSETNAND(tmpset, p->p_sigmask);
230 if (SIGISEMPTY(p->p_siglist) ||
231 (!(p->p_flag & P_TRACED) && SIGISEMPTY(tmpset))) {
232 return(0);
234 r = issignal(p);
235 return(r);
238 #endif /* _KERNEL */
240 #endif /* !_SYS_SIGNALVAR_H_ */