1/* $NetBSD: siginfo.h,v 1.33 2019/05/06 08:05:03 kamil Exp $ */
2
3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _SYS_SIGINFO_H_
33#define _SYS_SIGINFO_H_
34
35#include <machine/signal.h>
36#include <sys/featuretest.h>
37#ifdef _KERNEL
38#include <sys/queue.h>
39#endif
40
41typedef union sigval {
42 int sival_int;
43 void *sival_ptr;
44} sigval_t;
45
46struct _ksiginfo {
47 int _signo;
48 int _code;
49 int _errno;
50#ifdef _LP64
51 /* In _LP64 the union starts on an 8-byte boundary. */
52 int _pad;
53#endif
54 union {
55 struct {
56 pid_t _pid;
57 uid_t _uid;
58 sigval_t _value;
59 } _rt;
60
61 struct {
62 pid_t _pid;
63 uid_t _uid;
64 int _status;
65 clock_t _utime;
66 clock_t _stime;
67 } _child;
68
69 struct {
70 void *_addr;
71 int _trap;
72 int _trap2;
73 int _trap3;
74 } _fault;
75
76 struct {
77 long _band;
78 int _fd;
79 } _poll;
80
81 struct {
82 int _sysnum;
83 int _retval[2];
84 int _error;
85 uint64_t _args[8]; /* SYS_MAXSYSARGS */
86 } _syscall;
87 } _reason;
88};
89
90#ifdef _KERNEL
91typedef struct ksiginfo {
92 u_long ksi_flags; /* 4 or 8 bytes (LP64) */
93 TAILQ_ENTRY(ksiginfo) ksi_list;
94 struct _ksiginfo ksi_info;
95 lwpid_t ksi_lid; /* 0, or directed to LWP */
96} ksiginfo_t;
97
98#define KSI_TRAP 0x01 /* signal caused by trap */
99#define KSI_EMPTY 0x02 /* no additional information */
100#define KSI_QUEUED 0x04 /* on a sigpend_t queue */
101#define KSI_FROMPOOL 0x08 /* allocated from the ksiginfo pool */
102
103/* Macros to initialize a ksiginfo_t. */
104#define KSI_INIT(ksi) \
105do { \
106 memset((ksi), 0, sizeof(*(ksi))); \
107} while (/*CONSTCOND*/0)
108
109#define KSI_INIT_EMPTY(ksi) \
110do { \
111 KSI_INIT((ksi)); \
112 (ksi)->ksi_flags = KSI_EMPTY; \
113} while (/*CONSTCOND*/0)
114
115#define KSI_INIT_TRAP(ksi) \
116do { \
117 KSI_INIT((ksi)); \
118 (ksi)->ksi_flags = KSI_TRAP; \
119} while (/*CONSTCOND*/0)
120
121/* Copy the part of ksiginfo_t without the queue pointers */
122#define KSI_COPY(fksi, tksi) \
123do { \
124 (tksi)->ksi_info = (fksi)->ksi_info; \
125 (tksi)->ksi_flags = (fksi)->ksi_flags; \
126} while (/*CONSTCOND*/0)
127
128
129/* Predicate macros to test how a ksiginfo_t was generated. */
130#define KSI_TRAP_P(ksi) (((ksi)->ksi_flags & KSI_TRAP) != 0)
131#define KSI_EMPTY_P(ksi) (((ksi)->ksi_flags & KSI_EMPTY) != 0)
132
133/*
134 * Old-style signal handler "code" arguments were only non-zero for
135 * signals caused by traps.
136 */
137#define KSI_TRAPCODE(ksi) (KSI_TRAP_P(ksi) ? (ksi)->ksi_trap : 0)
138#endif /* _KERNEL */
139
140typedef union siginfo {
141 char si_pad[128]; /* Total size; for future expansion */
142 struct _ksiginfo _info;
143} siginfo_t;
144
145/** Field access macros */
146#define si_signo _info._signo
147#define si_code _info._code
148#define si_errno _info._errno
149
150#define si_value _info._reason._rt._value
151#define si_pid _info._reason._child._pid
152#define si_uid _info._reason._child._uid
153#define si_status _info._reason._child._status
154#define si_utime _info._reason._child._utime
155#define si_stime _info._reason._child._stime
156
157#define si_addr _info._reason._fault._addr
158#define si_trap _info._reason._fault._trap
159#define si_trap2 _info._reason._fault._trap2
160#define si_trap3 _info._reason._fault._trap3
161
162#define si_band _info._reason._poll._band
163#define si_fd _info._reason._poll._fd
164
165#define si_sysnum _info._reason._syscall._sysnum
166#define si_retval _info._reason._syscall._retval
167#define si_error _info._reason._syscall._error
168#define si_args _info._reason._syscall._args
169
170#ifdef _KERNEL
171/** Field access macros */
172#define ksi_signo ksi_info._signo
173#define ksi_code ksi_info._code
174#define ksi_errno ksi_info._errno
175
176#define ksi_value ksi_info._reason._rt._value
177#define ksi_pid ksi_info._reason._child._pid
178#define ksi_uid ksi_info._reason._child._uid
179#define ksi_status ksi_info._reason._child._status
180#define ksi_utime ksi_info._reason._child._utime
181#define ksi_stime ksi_info._reason._child._stime
182
183#define ksi_addr ksi_info._reason._fault._addr
184#define ksi_trap ksi_info._reason._fault._trap
185#define ksi_trap2 ksi_info._reason._fault._trap2
186#define ksi_trap3 ksi_info._reason._fault._trap3
187
188#define ksi_band ksi_info._reason._poll._band
189#define ksi_fd ksi_info._reason._poll._fd
190
191#define ksi_sysnum ksi_info._reason._syscall._sysnum
192#define ksi_retval ksi_info._reason._syscall._retval
193#define ksi_error ksi_info._reason._syscall._error
194#define ksi_args ksi_info._reason._syscall._args
195#endif /* _KERNEL */
196
197/** si_code */
198/* SIGILL */
199#define ILL_ILLOPC 1 /* Illegal opcode */
200#define ILL_ILLOPN 2 /* Illegal operand */
201#define ILL_ILLADR 3 /* Illegal addressing mode */
202#define ILL_ILLTRP 4 /* Illegal trap */
203#define ILL_PRVOPC 5 /* Privileged opcode */
204#define ILL_PRVREG 6 /* Privileged register */
205#define ILL_COPROC 7 /* Coprocessor error */
206#define ILL_BADSTK 8 /* Internal stack error */
207
208/* SIGFPE */
209#define FPE_INTDIV 1 /* Integer divide by zero */
210#define FPE_INTOVF 2 /* Integer overflow */
211#define FPE_FLTDIV 3 /* Floating point divide by zero */
212#define FPE_FLTOVF 4 /* Floating point overflow */
213#define FPE_FLTUND 5 /* Floating point underflow */
214#define FPE_FLTRES 6 /* Floating point inexact result */
215#define FPE_FLTINV 7 /* Invalid Floating point operation */
216#define FPE_FLTSUB 8 /* Subscript out of range */
217
218/* SIGSEGV */
219#define SEGV_MAPERR 1 /* Address not mapped to object */
220#define SEGV_ACCERR 2 /* Invalid permissions for mapped object*/
221
222/* SIGBUS */
223#define BUS_ADRALN 1 /* Invalid address alignment */
224#define BUS_ADRERR 2 /* Non-existent physical address */
225#define BUS_OBJERR 3 /* Object specific hardware error */
226
227/* SIGTRAP */
228#define TRAP_BRKPT 1 /* Process breakpoint */
229#define TRAP_TRACE 2 /* Process trace trap */
230#define TRAP_EXEC 3 /* Process exec trap */
231#define TRAP_CHLD 4 /* Process child trap */
232#define TRAP_LWP 5 /* Process lwp trap */
233#define TRAP_DBREG 6 /* Process hardware debug register trap */
234#define TRAP_SCE 7 /* Process syscall entry trap */
235#define TRAP_SCX 8 /* Process syscall exit trap */
236
237/* SIGCHLD */
238#define CLD_EXITED 1 /* Child has exited */
239#define CLD_KILLED 2 /* Child has terminated abnormally but */
240 /* did not create a core file */
241#define CLD_DUMPED 3 /* Child has terminated abnormally and */
242 /* created a core file */
243#define CLD_TRAPPED 4 /* Traced child has trapped */
244#define CLD_STOPPED 5 /* Child has stopped */
245#define CLD_CONTINUED 6 /* Stopped child has continued */
246
247/* SIGIO */
248#define POLL_IN 1 /* Data input available */
249#define POLL_OUT 2 /* Output buffers available */
250#define POLL_MSG 3 /* Input message available */
251#define POLL_ERR 4 /* I/O Error */
252#define POLL_PRI 5 /* High priority input available */
253#define POLL_HUP 6 /* Device disconnected */
254
255
256/** si_code */
257#define SI_USER 0 /* Sent by kill(2) */
258#define SI_QUEUE -1 /* Sent by the sigqueue(2) */
259#define SI_TIMER -2 /* Generated by expiration of a timer */
260 /* set by timer_settime(2) */
261#define SI_ASYNCIO -3 /* Generated by completion of an */
262 /* asynchronous I/O signal */
263#define SI_MESGQ -4 /* Generated by arrival of a message on */
264 /* an empty message queue */
265#if defined(_KERNEL) || defined(_NETBSD_SOURCE)
266#define SI_LWP -5 /* Generated by _lwp_kill(2) */
267#define SI_NOINFO 32767 /* No signal specific info available */
268#endif
269
270#endif /* !_SYS_SIGINFO_H_ */
271