1 /* $NetBSD: siginfo.h,v 1.20 2011/01/02 18:12:01 skrll 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 #ifdef _KERNEL 37 #include <sys/queue.h> 38 #endif 39 40 typedef union sigval { 41 int sival_int; 42 void *sival_ptr; 43 } sigval_t; 44 45 struct _ksiginfo { 46 int _signo; 47 int _code; 48 int _errno; 49 #ifdef _LP64 50 /* In _LP64 the union starts on an 8-byte boundary. */ 51 int _pad; 52 #endif 53 union { 54 struct { 55 pid_t _pid; 56 uid_t _uid; 57 sigval_t _value; 58 } _rt; 59 60 struct { 61 pid_t _pid; 62 uid_t _uid; 63 int _status; 64 clock_t _utime; 65 clock_t _stime; 66 } _child; 67 68 struct { 69 void *_addr; 70 int _trap; 71 } _fault; 72 73 struct { 74 long _band; 75 int _fd; 76 } _poll; 77 } _reason; 78 }; 79 80 #ifdef _KERNEL 81 typedef struct ksiginfo { 82 u_long ksi_flags; /* 4 or 8 bytes (LP64) */ 83 CIRCLEQ_ENTRY(ksiginfo) ksi_list; 84 struct _ksiginfo ksi_info; 85 lwpid_t ksi_lid; /* 0, or directed to LWP */ 86 } ksiginfo_t; 87 88 #define KSI_TRAP 0x01 /* signal caused by trap */ 89 #define KSI_EMPTY 0x02 /* no additional information */ 90 #define KSI_QUEUED 0x04 /* on a sigpend_t queue */ 91 #define KSI_FROMPOOL 0x08 /* allocated from the ksiginfo pool */ 92 93 /* Macros to initialize a ksiginfo_t. */ 94 #define KSI_INIT(ksi) \ 95 do { \ 96 memset((ksi), 0, sizeof(*(ksi))); \ 97 } while (/*CONSTCOND*/0) 98 99 #define KSI_INIT_EMPTY(ksi) \ 100 do { \ 101 KSI_INIT((ksi)); \ 102 (ksi)->ksi_flags = KSI_EMPTY; \ 103 } while (/*CONSTCOND*/0) 104 105 #define KSI_INIT_TRAP(ksi) \ 106 do { \ 107 KSI_INIT((ksi)); \ 108 (ksi)->ksi_flags = KSI_TRAP; \ 109 } while (/*CONSTCOND*/0) 110 111 /* Copy the part of ksiginfo_t without the queue pointers */ 112 #define KSI_COPY(fksi, tksi) \ 113 do { \ 114 (tksi)->ksi_info = (fksi)->ksi_info; \ 115 (tksi)->ksi_flags = (fksi)->ksi_flags; \ 116 } while (/*CONSTCOND*/0) 117 118 119 /* Predicate macros to test how a ksiginfo_t was generated. */ 120 #define KSI_TRAP_P(ksi) (((ksi)->ksi_flags & KSI_TRAP) != 0) 121 #define KSI_EMPTY_P(ksi) (((ksi)->ksi_flags & KSI_EMPTY) != 0) 122 123 /* 124 * Old-style signal handler "code" arguments were only non-zero for 125 * signals caused by traps. 126 */ 127 #define KSI_TRAPCODE(ksi) (KSI_TRAP_P(ksi) ? (ksi)->ksi_trap : 0) 128 #endif /* _KERNEL */ 129 130 typedef union siginfo { 131 char si_pad[128]; /* Total size; for future expansion */ 132 struct _ksiginfo _info; 133 } siginfo_t; 134 135 /** Field access macros */ 136 #define si_signo _info._signo 137 #define si_code _info._code 138 #define si_errno _info._errno 139 140 #define si_value _info._reason._rt._value 141 #define si_pid _info._reason._child._pid 142 #define si_uid _info._reason._child._uid 143 #define si_status _info._reason._child._status 144 #define si_utime _info._reason._child._utime 145 #define si_stime _info._reason._child._stime 146 147 #define si_addr _info._reason._fault._addr 148 #define si_trap _info._reason._fault._trap 149 150 #define si_band _info._reason._poll._band 151 #define si_fd _info._reason._poll._fd 152 153 #ifdef _KERNEL 154 /** Field access macros */ 155 #define ksi_signo ksi_info._signo 156 #define ksi_code ksi_info._code 157 #define ksi_errno ksi_info._errno 158 159 #define ksi_value ksi_info._reason._rt._value 160 #define ksi_pid ksi_info._reason._child._pid 161 #define ksi_uid ksi_info._reason._child._uid 162 #define ksi_status ksi_info._reason._child._status 163 #define ksi_utime ksi_info._reason._child._utime 164 #define ksi_stime ksi_info._reason._child._stime 165 166 #define ksi_addr ksi_info._reason._fault._addr 167 #define ksi_trap ksi_info._reason._fault._trap 168 169 #define ksi_band ksi_info._reason._poll._band 170 #define ksi_fd ksi_info._reason._poll._fd 171 #endif /* _KERNEL */ 172 173 /** si_code */ 174 /* SIGILL */ 175 #define ILL_ILLOPC 1 /* Illegal opcode */ 176 #define ILL_ILLOPN 2 /* Illegal operand */ 177 #define ILL_ILLADR 3 /* Illegal addressing mode */ 178 #define ILL_ILLTRP 4 /* Illegal trap */ 179 #define ILL_PRVOPC 5 /* Privileged opcode */ 180 #define ILL_PRVREG 6 /* Privileged register */ 181 #define ILL_COPROC 7 /* Coprocessor error */ 182 #define ILL_BADSTK 8 /* Internal stack error */ 183 184 /* SIGFPE */ 185 #define FPE_INTDIV 1 /* Integer divide by zero */ 186 #define FPE_INTOVF 2 /* Integer overflow */ 187 #define FPE_FLTDIV 3 /* Floating point divide by zero */ 188 #define FPE_FLTOVF 4 /* Floating point overflow */ 189 #define FPE_FLTUND 5 /* Floating point underflow */ 190 #define FPE_FLTRES 6 /* Floating point inexact result */ 191 #define FPE_FLTINV 7 /* Invalid Floating point operation */ 192 #define FPE_FLTSUB 8 /* Subscript out of range */ 193 194 /* SIGSEGV */ 195 #define SEGV_MAPERR 1 /* Address not mapped to object */ 196 #define SEGV_ACCERR 2 /* Invalid permissions for mapped object*/ 197 198 /* SIGBUS */ 199 #define BUS_ADRALN 1 /* Invalid address alignment */ 200 #define BUS_ADRERR 2 /* Non-existent physical address */ 201 #define BUS_OBJERR 3 /* Object specific hardware error */ 202 203 /* SIGTRAP */ 204 #define TRAP_BRKPT 1 /* Process breakpoint */ 205 #define TRAP_TRACE 2 /* Process trace trap */ 206 207 /* SIGCHLD */ 208 #define CLD_EXITED 1 /* Child has exited */ 209 #define CLD_KILLED 2 /* Child has terminated abnormally but */ 210 /* did not create a core file */ 211 #define CLD_DUMPED 3 /* Child has terminated abnormally and */ 212 /* created a core file */ 213 #define CLD_TRAPPED 4 /* Traced child has trapped */ 214 #define CLD_STOPPED 5 /* Child has stopped */ 215 #define CLD_CONTINUED 6 /* Stopped child has continued */ 216 217 /* SIGPOLL */ 218 #define POLL_IN 1 /* Data input available */ 219 #define POLL_OUT 2 /* Output buffers available */ 220 #define POLL_MSG 3 /* Input message available */ 221 #define POLL_ERR 4 /* I/O Error */ 222 #define POLL_PRI 5 /* High priority input available */ 223 #define POLL_HUP 6 /* Device disconnected */ 224 225 226 /** si_code */ 227 #define SI_USER 0 /* Sent by kill(2) */ 228 #define SI_QUEUE -1 /* Sent by the sigqueue(2) */ 229 #define SI_TIMER -2 /* Generated by expiration of a timer */ 230 /* set by timer_settime(2) */ 231 #define SI_ASYNCIO -3 /* Generated by completion of an */ 232 /* asynchronous I/O signal */ 233 #define SI_MESGQ -4 /* Generated by arrival of a message on */ 234 /* an empty message queue */ 235 #if defined(_KERNEL) || defined(_NETBSD_SOURCE) 236 #define SI_LWP -5 /* Generated by _lwp_kill(2) */ 237 #define SI_NOINFO 32767 /* No signal specific info available */ 238 #endif 239 240 #endif /* !_SYS_SIGINFO_H_ */ 241