1/* $OpenBSD: signal.h,v 1.30 2026/03/21 01:56:51 daniel Exp $ */
2/* $NetBSD: signal.h,v 1.21 1996/02/09 18:25:32 christos Exp $ */
3
4/*
5 * Copyright (c) 1982, 1986, 1989, 1991, 1993
6 * The Regents of the University of California. All rights reserved.
7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed
9 * to the University of California by American Telephone and Telegraph
10 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 * the permission of UNIX System Laboratories, Inc.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * @(#)signal.h 8.2 (Berkeley) 1/21/94
38 */
39
40#ifndef _SYS_SIGNAL_H_
41#define _SYS_SIGNAL_H_
42
43#include <machine/signal.h> /* sigcontext; codes for SIGILL, SIGFPE */
44
45#define _NSIG 33 /* counting 0 (mask is 1-32) */
46
47#if __BSD_VISIBLE
48#define NSIG _NSIG
49#endif
50
51#define SIGHUP 1 /* hangup */
52#define SIGINT 2 /* interrupt */
53#define SIGQUIT 3 /* quit */
54#define SIGILL 4 /* illegal instruction (not reset when caught) */
55#define SIGTRAP 5 /* trace trap (not reset when caught) */
56#define SIGABRT 6 /* abort() */
57#if __BSD_VISIBLE
58#define SIGIOT SIGABRT /* compatibility */
59#define SIGEMT 7 /* EMT instruction */
60#endif
61#define SIGFPE 8 /* floating point exception */
62#define SIGKILL 9 /* kill (cannot be caught or ignored) */
63#define SIGBUS 10 /* bus error */
64#define SIGSEGV 11 /* segmentation violation */
65#define SIGSYS 12 /* bad argument to system call */
66#define SIGPIPE 13 /* write on a pipe with no one to read it */
67#define SIGALRM 14 /* alarm clock */
68#define SIGTERM 15 /* software termination signal from kill */
69#define SIGURG 16 /* urgent condition on IO channel */
70#define SIGSTOP 17 /* sendable stop signal not from tty */
71#define SIGTSTP 18 /* stop signal from tty */
72#define SIGCONT 19 /* continue a stopped process */
73#define SIGCHLD 20 /* to parent on child stop or exit */
74#define SIGTTIN 21 /* to readers pgrp upon background tty read */
75#define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
76#if __BSD_VISIBLE
77#define SIGIO 23 /* input/output possible signal */
78#endif
79#define SIGXCPU 24 /* exceeded CPU time limit */
80#define SIGXFSZ 25 /* exceeded file size limit */
81#define SIGVTALRM 26 /* virtual time alarm */
82#define SIGPROF 27 /* profiling time alarm */
83#if __BSD_VISIBLE || __POSIX_VISIBLE >= 202405
84#define SIGWINCH 28 /* window size changes */
85#endif
86#if __BSD_VISIBLE
87#define SIGINFO 29 /* information request */
88#endif
89#define SIGUSR1 30 /* user defined signal 1 */
90#define SIGUSR2 31 /* user defined signal 2 */
91#if __BSD_VISIBLE
92#define SIGTHR 32 /* thread library AST */
93#endif
94
95/*
96 * Language spec says we must list exactly one parameter, even though we
97 * actually supply three. Ugh!
98 */
99#define SIG_DFL (void (*)(int))0
100#define SIG_IGN (void (*)(int))1
101#define SIG_ERR (void (*)(int))-1
102
103#if __POSIX_VISIBLE || __XPG_VISIBLE
104#ifndef _SIGSET_T_DEFINED_
105#define _SIGSET_T_DEFINED_
106typedef unsigned int sigset_t;
107#endif
108
109#include <sys/siginfo.h>
110
111/*
112 * Signal vector "template" used in sigaction call.
113 */
114struct sigaction {
115 union { /* signal handler */
116 void (*__sa_handler)(int);
117 void (*__sa_sigaction)(int, siginfo_t *, void *);
118 } __sigaction_u;
119 sigset_t sa_mask; /* signal mask to apply */
120 int sa_flags; /* see signal options below */
121};
122
123/* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */
124#define sa_handler __sigaction_u.__sa_handler
125#define sa_sigaction __sigaction_u.__sa_sigaction
126
127#if __XPG_VISIBLE >= 500
128#define SA_ONSTACK 0x0001 /* take signal on signal stack */
129#define SA_RESTART 0x0002 /* restart system on signal return */
130#define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */
131#define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */
132#define SA_NOCLDWAIT 0x0020 /* don't create zombies (assign to pid 1) */
133#endif /* __XPG_VISIBLE >= 500 */
134#define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */
135#if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE >= 500
136#define SA_SIGINFO 0x0040 /* generate siginfo_t */
137#endif
138
139/*
140 * Flags for sigprocmask:
141 */
142#define SIG_BLOCK 1 /* block specified signal set */
143#define SIG_UNBLOCK 2 /* unblock specified signal set */
144#define SIG_SETMASK 3 /* set specified signal set */
145#endif /* __POSIX_VISIBLE || __XPG_VISIBLE */
146
147#if __BSD_VISIBLE
148typedef void (*sig_t)(int); /* type of signal function */
149
150/*
151 * 4.3 compatibility:
152 * Signal vector "template" used in sigvec call.
153 */
154struct sigvec {
155 void (*sv_handler)(int); /* signal handler */
156 int sv_mask; /* signal mask to apply */
157 int sv_flags; /* see signal options below */
158};
159#define SV_ONSTACK SA_ONSTACK
160#define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */
161#define SV_RESETHAND SA_RESETHAND
162#define sv_onstack sv_flags /* isn't compatibility wonderful! */
163
164/*
165 * Macro for converting signal number to a mask suitable for
166 * sigblock().
167 */
168#define sigmask(m) (1U << ((m)-1))
169
170#define BADSIG SIG_ERR
171
172#endif /* __BSD_VISIBLE */
173
174#if __BSD_VISIBLE || __XPG_VISIBLE >= 420
175/*
176 * Structure used in sigaltstack call.
177 */
178typedef struct sigaltstack {
179 void *ss_sp; /* signal stack base */
180 size_t ss_size; /* signal stack length */
181 int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */
182} stack_t;
183#define SS_ONSTACK 0x0001 /* take signals on alternate stack */
184#define SS_DISABLE 0x0004 /* disable taking signals on alternate stack */
185#define MINSIGSTKSZ (3U << _MAX_PAGE_SHIFT) /* minimum allowable stack */
186#if _MAX_PAGE_SHIFT < 14 /* recommended stack size */
187#define SIGSTKSZ (MINSIGSTKSZ + (1U << _MAX_PAGE_SHIFT) * 4)
188#else
189#define SIGSTKSZ (MINSIGSTKSZ + (1U << _MAX_PAGE_SHIFT) * 2)
190#endif
191
192typedef struct sigcontext ucontext_t;
193#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
194
195#ifndef _KERNEL
196/*
197 * For historical reasons; programs expect signal's return value to be
198 * defined by <sys/signal.h>.
199 */
200__BEGIN_DECLS
201void (*signal(int, void (*)(int)))(int);
202__END_DECLS
203#endif /* !_KERNEL */
204#endif /* !_SYS_SIGNAL_H_ */