xref: /openbsd/sys/sys/signalvar.h (revision fe1c98ea)
1 /*	$OpenBSD: signalvar.h,v 1.57 2024/11/04 22:41:50 claudio Exp $	*/
2 /*	$NetBSD: signalvar.h,v 1.17 1996/04/22 01:23:31 christos Exp $	*/
3 
4 /*
5  * Copyright (c) 1991, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)signalvar.h	8.3 (Berkeley) 1/4/94
33  */
34 
35 #ifndef	_SYS_SIGNALVAR_H_		/* tmp for user.h */
36 #define	_SYS_SIGNALVAR_H_
37 
38 /*
39  * Kernel signal definitions and data structures,
40  * not exported to user programs.
41  */
42 
43 /*
44  * Process signal actions and state, needed only within the process
45  * (not necessarily resident).
46  *
47  * Locks used to protect struct members in struct sigacts:
48  *	a	atomic operations
49  *	m	this process' `ps_mtx'
50  */
51 struct	sigacts {
52 	sig_t	ps_sigact[NSIG];	/* [m] disposition of signals */
53 	sigset_t ps_catchmask[NSIG];	/* [m] signals to be blocked */
54 	sigset_t ps_sigonstack;		/* [m] signals to take on sigstack */
55 	sigset_t ps_sigintr;		/* [m] signals interrupt syscalls */
56 	sigset_t ps_sigreset;		/* [m] signals that reset when caught */
57 	sigset_t ps_siginfo;		/* [m] signals that provide siginfo */
58 	sigset_t ps_sigignore;		/* [m] signals being ignored */
59 	sigset_t ps_sigcatch;		/* [m] signals being caught by user */
60 	int	ps_sigflags;		/* [a] signal flags, below */
61 };
62 
63 /* signal flags */
64 #define	SAS_NOCLDSTOP	0x01	/* No SIGCHLD when children stop. */
65 #define	SAS_NOCLDWAIT	0x02	/* No zombies if child dies */
66 
67 /* additional signal action values, used only temporarily/internally */
68 #define	SIG_CATCH	(void (*)(int))2
69 #define	SIG_HOLD	(void (*)(int))3
70 
71 /*
72  * Check if process p has an unmasked signal pending.
73  * Return mask of pending signals.
74  */
75 #define SIGPENDING(p)							\
76 	(((p)->p_siglist | (p)->p_p->ps_siglist) & ~(p)->p_sigmask)
77 
78 /*
79  * Signal properties and actions.
80  */
81 #define	SA_KILL		0x01		/* terminates process by default */
82 #define	SA_CORE		0x02		/* ditto and coredumps */
83 #define	SA_STOP		0x04		/* suspend process */
84 #define	SA_TTYSTOP	0x08		/* ditto, from tty */
85 #define	SA_IGNORE	0x10		/* ignore by default */
86 #define	SA_CONT		0x20		/* continue if suspended */
87 #define	SA_CANTMASK	0x40		/* non-maskable, catchable */
88 
89 #define	sigcantmask	(sigmask(SIGKILL) | sigmask(SIGSTOP))
90 
91 #ifdef _KERNEL
92 enum signal_type { SPROCESS, STHREAD, SPROPAGATED };
93 
94 struct sigio_ref;
95 
96 struct sigctx {
97 	sig_t		sig_action;
98 	sigset_t	sig_catchmask;
99 	int		sig_onstack;
100 	int		sig_intr;
101 	int		sig_reset;
102 	int		sig_info;
103 	int		sig_ignore;
104 	int		sig_catch;
105 	int		sig_stop;
106 };
107 
108 /*
109  * Machine-independent functions:
110  */
111 int	coredump(struct proc *p);
112 void	execsigs(struct proc *p);
113 int	cursig(struct proc *p, struct sigctx *, int);
114 void	pgsigio(struct sigio_ref *sir, int sig, int checkctty);
115 void	pgsignal(struct pgrp *pgrp, int sig, int checkctty);
116 void	psignal(struct proc *p, int sig);
117 void	ptsignal(struct proc *p, int sig, enum signal_type type);
118 void	prsignal(struct process *pr, int sig);
119 void	trapsignal(struct proc *p, int sig, u_long code, int type,
120 	    union sigval val);
121 __dead void sigexit(struct proc *, int);
122 void	sigabort(struct proc *);
123 int	sigismasked(struct proc *, int);
124 int	sigonstack(size_t);
125 int	killpg1(struct proc *, int, int, int);
126 
127 void	signal_init(void);
128 
129 void	sigstkinit(struct sigaltstack *);
130 struct sigacts	*sigactsinit(struct process *);
131 void	sigactsfree(struct sigacts *);
132 void	siginit(struct sigacts *);
133 
134 /*
135  * Machine-dependent functions:
136  */
137 int	sendsig(sig_t _catcher, int _sig, sigset_t _mask, const siginfo_t *_si,
138 	    int _info, int _onstack);
139 #endif	/* _KERNEL */
140 #endif	/* !_SYS_SIGNALVAR_H_ */
141