1 /* $NetBSD: siginfo.h,v 1.34 2019/09/30 21:13:33 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 41 typedef union sigval { 42 int sival_int; 43 void *sival_ptr; 44 } sigval_t; 45 46 struct _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 88 struct { 89 int _pe_report_event; 90 union { 91 pid_t _pe_other_pid; 92 lwpid_t _pe_lwp; 93 } _option; 94 } _ptrace_state; 95 } _reason; 96 }; 97 98 #ifdef _KERNEL 99 typedef struct ksiginfo { 100 u_long ksi_flags; /* 4 or 8 bytes (LP64) */ 101 TAILQ_ENTRY(ksiginfo) ksi_list; 102 struct _ksiginfo ksi_info; 103 lwpid_t ksi_lid; /* 0, or directed to LWP */ 104 } ksiginfo_t; 105 106 #define KSI_TRAP 0x01 /* signal caused by trap */ 107 #define KSI_EMPTY 0x02 /* no additional information */ 108 #define KSI_QUEUED 0x04 /* on a sigpend_t queue */ 109 #define KSI_FROMPOOL 0x08 /* allocated from the ksiginfo pool */ 110 111 /* Macros to initialize a ksiginfo_t. */ 112 #define KSI_INIT(ksi) \ 113 do { \ 114 memset((ksi), 0, sizeof(*(ksi))); \ 115 } while (/*CONSTCOND*/0) 116 117 #define KSI_INIT_EMPTY(ksi) \ 118 do { \ 119 KSI_INIT((ksi)); \ 120 (ksi)->ksi_flags = KSI_EMPTY; \ 121 } while (/*CONSTCOND*/0) 122 123 #define KSI_INIT_TRAP(ksi) \ 124 do { \ 125 KSI_INIT((ksi)); \ 126 (ksi)->ksi_flags = KSI_TRAP; \ 127 } while (/*CONSTCOND*/0) 128 129 /* Copy the part of ksiginfo_t without the queue pointers */ 130 #define KSI_COPY(fksi, tksi) \ 131 do { \ 132 (tksi)->ksi_info = (fksi)->ksi_info; \ 133 (tksi)->ksi_flags = (fksi)->ksi_flags; \ 134 } while (/*CONSTCOND*/0) 135 136 137 /* Predicate macros to test how a ksiginfo_t was generated. */ 138 #define KSI_TRAP_P(ksi) (((ksi)->ksi_flags & KSI_TRAP) != 0) 139 #define KSI_EMPTY_P(ksi) (((ksi)->ksi_flags & KSI_EMPTY) != 0) 140 141 /* 142 * Old-style signal handler "code" arguments were only non-zero for 143 * signals caused by traps. 144 */ 145 #define KSI_TRAPCODE(ksi) (KSI_TRAP_P(ksi) ? (ksi)->ksi_trap : 0) 146 #endif /* _KERNEL */ 147 148 typedef union siginfo { 149 char si_pad[128]; /* Total size; for future expansion */ 150 struct _ksiginfo _info; 151 } siginfo_t; 152 153 /** Field access macros */ 154 #define si_signo _info._signo 155 #define si_code _info._code 156 #define si_errno _info._errno 157 158 #define si_value _info._reason._rt._value 159 #define si_pid _info._reason._child._pid 160 #define si_uid _info._reason._child._uid 161 #define si_status _info._reason._child._status 162 #define si_utime _info._reason._child._utime 163 #define si_stime _info._reason._child._stime 164 165 #define si_addr _info._reason._fault._addr 166 #define si_trap _info._reason._fault._trap 167 #define si_trap2 _info._reason._fault._trap2 168 #define si_trap3 _info._reason._fault._trap3 169 170 #define si_band _info._reason._poll._band 171 #define si_fd _info._reason._poll._fd 172 173 #define si_sysnum _info._reason._syscall._sysnum 174 #define si_retval _info._reason._syscall._retval 175 #define si_error _info._reason._syscall._error 176 #define si_args _info._reason._syscall._args 177 178 #define si_pe_report_event _info._reason._ptrace_state._pe_report_event 179 #define si_pe_other_pid _info._reason._ptrace_state._option._pe_other_pid 180 #define si_pe_lwp _info._reason._ptrace_state._option._pe_lwp 181 182 #ifdef _KERNEL 183 /** Field access macros */ 184 #define ksi_signo ksi_info._signo 185 #define ksi_code ksi_info._code 186 #define ksi_errno ksi_info._errno 187 188 #define ksi_value ksi_info._reason._rt._value 189 #define ksi_pid ksi_info._reason._child._pid 190 #define ksi_uid ksi_info._reason._child._uid 191 #define ksi_status ksi_info._reason._child._status 192 #define ksi_utime ksi_info._reason._child._utime 193 #define ksi_stime ksi_info._reason._child._stime 194 195 #define ksi_addr ksi_info._reason._fault._addr 196 #define ksi_trap ksi_info._reason._fault._trap 197 #define ksi_trap2 ksi_info._reason._fault._trap2 198 #define ksi_trap3 ksi_info._reason._fault._trap3 199 200 #define ksi_band ksi_info._reason._poll._band 201 #define ksi_fd ksi_info._reason._poll._fd 202 203 #define ksi_sysnum ksi_info._reason._syscall._sysnum 204 #define ksi_retval ksi_info._reason._syscall._retval 205 #define ksi_error ksi_info._reason._syscall._error 206 #define ksi_args ksi_info._reason._syscall._args 207 208 #define ksi_pe_report_event ksi_info._reason._ptrace_state._pe_report_event 209 #define ksi_pe_other_pid ksi_info._reason._ptrace_state._option._pe_other_pid 210 #define ksi_pe_lwp ksi_info._reason._ptrace_state._option._pe_lwp 211 #endif /* _KERNEL */ 212 213 /** si_code */ 214 /* SIGILL */ 215 #define ILL_ILLOPC 1 /* Illegal opcode */ 216 #define ILL_ILLOPN 2 /* Illegal operand */ 217 #define ILL_ILLADR 3 /* Illegal addressing mode */ 218 #define ILL_ILLTRP 4 /* Illegal trap */ 219 #define ILL_PRVOPC 5 /* Privileged opcode */ 220 #define ILL_PRVREG 6 /* Privileged register */ 221 #define ILL_COPROC 7 /* Coprocessor error */ 222 #define ILL_BADSTK 8 /* Internal stack error */ 223 224 /* SIGFPE */ 225 #define FPE_INTDIV 1 /* Integer divide by zero */ 226 #define FPE_INTOVF 2 /* Integer overflow */ 227 #define FPE_FLTDIV 3 /* Floating point divide by zero */ 228 #define FPE_FLTOVF 4 /* Floating point overflow */ 229 #define FPE_FLTUND 5 /* Floating point underflow */ 230 #define FPE_FLTRES 6 /* Floating point inexact result */ 231 #define FPE_FLTINV 7 /* Invalid Floating point operation */ 232 #define FPE_FLTSUB 8 /* Subscript out of range */ 233 234 /* SIGSEGV */ 235 #define SEGV_MAPERR 1 /* Address not mapped to object */ 236 #define SEGV_ACCERR 2 /* Invalid permissions for mapped object*/ 237 238 /* SIGBUS */ 239 #define BUS_ADRALN 1 /* Invalid address alignment */ 240 #define BUS_ADRERR 2 /* Non-existent physical address */ 241 #define BUS_OBJERR 3 /* Object specific hardware error */ 242 243 /* SIGTRAP */ 244 #define TRAP_BRKPT 1 /* Process breakpoint */ 245 #define TRAP_TRACE 2 /* Process trace trap */ 246 #define TRAP_EXEC 3 /* Process exec trap */ 247 #define TRAP_CHLD 4 /* Process child trap */ 248 #define TRAP_LWP 5 /* Process lwp trap */ 249 #define TRAP_DBREG 6 /* Process hardware debug register trap */ 250 #define TRAP_SCE 7 /* Process syscall entry trap */ 251 #define TRAP_SCX 8 /* Process syscall exit trap */ 252 253 /* SIGCHLD */ 254 #define CLD_EXITED 1 /* Child has exited */ 255 #define CLD_KILLED 2 /* Child has terminated abnormally but */ 256 /* did not create a core file */ 257 #define CLD_DUMPED 3 /* Child has terminated abnormally and */ 258 /* created a core file */ 259 #define CLD_TRAPPED 4 /* Traced child has trapped */ 260 #define CLD_STOPPED 5 /* Child has stopped */ 261 #define CLD_CONTINUED 6 /* Stopped child has continued */ 262 263 /* SIGIO */ 264 #define POLL_IN 1 /* Data input available */ 265 #define POLL_OUT 2 /* Output buffers available */ 266 #define POLL_MSG 3 /* Input message available */ 267 #define POLL_ERR 4 /* I/O Error */ 268 #define POLL_PRI 5 /* High priority input available */ 269 #define POLL_HUP 6 /* Device disconnected */ 270 271 272 /** si_code */ 273 #define SI_USER 0 /* Sent by kill(2) */ 274 #define SI_QUEUE -1 /* Sent by the sigqueue(2) */ 275 #define SI_TIMER -2 /* Generated by expiration of a timer */ 276 /* set by timer_settime(2) */ 277 #define SI_ASYNCIO -3 /* Generated by completion of an */ 278 /* asynchronous I/O signal */ 279 #define SI_MESGQ -4 /* Generated by arrival of a message on */ 280 /* an empty message queue */ 281 #if defined(_KERNEL) || defined(_NETBSD_SOURCE) 282 #define SI_LWP -5 /* Generated by _lwp_kill(2) */ 283 #define SI_NOINFO 32767 /* No signal specific info available */ 284 #endif 285 286 #endif /* !_SYS_SIGINFO_H_ */ 287