1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * University Copyright- Copyright (c) 1982, 1986, 1988 32 * The Regents of the University of California 33 * All Rights Reserved 34 * 35 * University Acknowledgment- Portions of this document are derived from 36 * software developed by the University of California, Berkeley, and its 37 * contributors. 38 */ 39 40 #ifndef _SYS_SIGNAL_H 41 #define _SYS_SIGNAL_H 42 43 #include <sys/feature_tests.h> 44 #include <sys/iso/signal_iso.h> 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 #if defined(__EXTENSIONS__) || defined(_KERNEL) || !defined(_STRICT_STDC) || \ 51 defined(__XOPEN_OR_POSIX) 52 53 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 54 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 55 (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) 56 /* 57 * We need <sys/siginfo.h> for the declaration of siginfo_t. 58 */ 59 #include <sys/siginfo.h> 60 #endif 61 62 /* Duplicated in <sys/ucontext.h> as a result of XPG4v2 requirements */ 63 #ifndef _SIGSET_T 64 #define _SIGSET_T 65 typedef struct { /* signal set type */ 66 unsigned int __sigbits[4]; 67 } sigset_t; 68 #endif /* _SIGSET_T */ 69 70 typedef struct { 71 unsigned int __sigbits[3]; 72 } k_sigset_t; 73 74 /* 75 * The signal handler routine can have either one or three arguments. 76 * Existing C code has used either form so not specifing the arguments 77 * neatly finesses the problem. C++ doesn't accept this. To C++ 78 * "(*sa_handler)()" indicates a routine with no arguments (ANSI C would 79 * specify this as "(*sa_handler)(void)"). One or the other form must be 80 * used for C++ and the only logical choice is "(*sa_handler)(int)" to allow 81 * the SIG_* defines to work. "(*sa_sigaction)(int, siginfo_t *, void *)" 82 * can be used for the three argument form. 83 */ 84 85 /* 86 * Note: storage overlap by sa_handler and sa_sigaction 87 */ 88 struct sigaction { 89 int sa_flags; 90 union { 91 #ifdef __cplusplus 92 void (*_handler)(int); 93 #else 94 void (*_handler)(); 95 #endif 96 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 97 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 98 (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) 99 void (*_sigaction)(int, siginfo_t *, void *); 100 #endif 101 } _funcptr; 102 sigset_t sa_mask; 103 #ifndef _LP64 104 int sa_resv[2]; 105 #endif 106 }; 107 #define sa_handler _funcptr._handler 108 #define sa_sigaction _funcptr._sigaction 109 110 #if defined(_SYSCALL32) 111 112 /* Kernel view of the ILP32 user sigaction structure */ 113 114 struct sigaction32 { 115 int32_t sa_flags; 116 union { 117 caddr32_t _handler; 118 caddr32_t _sigaction; 119 } _funcptr; 120 sigset_t sa_mask; 121 int32_t sa_resv[2]; 122 }; 123 124 #endif /* _SYSCALL32 */ 125 126 /* this is only valid for SIGCLD */ 127 #define SA_NOCLDSTOP 0x00020000 /* don't send job control SIGCLD's */ 128 #endif 129 130 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 131 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \ 132 defined(_XPG4_2) 133 134 /* non-conformant ANSI compilation */ 135 136 /* definitions for the sa_flags field */ 137 #define SA_ONSTACK 0x00000001 138 #define SA_RESETHAND 0x00000002 139 #define SA_RESTART 0x00000004 140 #endif 141 142 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 143 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \ 144 (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) 145 #define SA_SIGINFO 0x00000008 146 #endif 147 148 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 149 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 150 defined(_XPG4_2) 151 #define SA_NODEFER 0x00000010 152 153 /* this is only valid for SIGCLD */ 154 #define SA_NOCLDWAIT 0x00010000 /* don't save zombie children */ 155 156 #if defined(__EXTENSIONS__) || !defined(_XPG4_2) 157 /* 158 * use of these symbols by applications is injurious 159 * to binary compatibility 160 */ 161 #define NSIG 73 /* valid signals range from 1 to NSIG-1 */ 162 #define MAXSIG 72 /* size of u_signal[], NSIG-1 <= MAXSIG */ 163 #endif /* defined(__EXTENSIONS__) || !defined(_XPG4_2) */ 164 165 #define MINSIGSTKSZ 2048 166 #define SIGSTKSZ 8192 167 168 #define SS_ONSTACK 0x00000001 169 #define SS_DISABLE 0x00000002 170 171 /* Duplicated in <sys/ucontext.h> as a result of XPG4v2 requirements. */ 172 #ifndef _STACK_T 173 #define _STACK_T 174 #if defined(__EXTENSIONS__) || !defined(_XPG4_2) 175 typedef struct sigaltstack { 176 #else 177 typedef struct { 178 #endif 179 void *ss_sp; 180 size_t ss_size; 181 int ss_flags; 182 } stack_t; 183 184 #if defined(_SYSCALL32) 185 186 /* Kernel view of the ILP32 user sigaltstack structure */ 187 188 typedef struct sigaltstack32 { 189 caddr32_t ss_sp; 190 size32_t ss_size; 191 int32_t ss_flags; 192 } stack32_t; 193 194 #endif /* _SYSCALL32 */ 195 196 #endif /* _STACK_T */ 197 198 #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */ 199 200 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 201 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) 202 203 /* signotify id used only by libc for mq_notify()/aio_notify() */ 204 typedef struct signotify_id { /* signotify id struct */ 205 pid_t sn_pid; /* pid of proc to be notified */ 206 int sn_index; /* index in preallocated pool */ 207 int sn_pad; /* reserved */ 208 } signotify_id_t; 209 210 #if defined(_SYSCALL32) 211 212 /* Kernel view of the ILP32 user signotify_id structure */ 213 214 typedef struct signotify32_id { 215 pid32_t sn_pid; /* pid of proc to be notified */ 216 int32_t sn_index; /* index in preallocated pool */ 217 int32_t sn_pad; /* reserved */ 218 } signotify32_id_t; 219 220 #endif /* _SYSCALL32 */ 221 222 /* Command codes for sig_notify call */ 223 224 #define SN_PROC 1 /* queue signotify for process */ 225 #define SN_CANCEL 2 /* cancel the queued signotify */ 226 #define SN_SEND 3 /* send the notified signal */ 227 228 #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */ 229 230 /* Added as per XPG4v2 */ 231 #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 232 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 233 defined(_XPG4_2) 234 struct sigstack { 235 void *ss_sp; 236 int ss_onstack; 237 }; 238 #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */ 239 240 /* 241 * For definition of ucontext_t; must follow struct definition 242 * for sigset_t 243 */ 244 #if defined(_XPG4_2) 245 #include <sys/ucontext.h> 246 #endif /* defined(_XPG4_2) */ 247 248 #ifdef _KERNEL 249 #include <sys/t_lock.h> 250 251 extern const k_sigset_t nullsmask; /* a null signal mask */ 252 extern const k_sigset_t fillset; /* all signals, guaranteed contiguous */ 253 extern const k_sigset_t cantmask; /* cannot be caught or ignored */ 254 extern const k_sigset_t cantreset; /* cannot be reset after catching */ 255 extern const k_sigset_t ignoredefault; /* ignored by default */ 256 extern const k_sigset_t stopdefault; /* stop by default */ 257 extern const k_sigset_t coredefault; /* dumps core by default */ 258 extern const k_sigset_t holdvfork; /* held while doing vfork */ 259 260 #define sigmask(n) ((unsigned int)1 << (((n) - 1) & (32 - 1))) 261 #define sigword(n) (((unsigned int)((n) - 1))>>5) 262 263 #if ((MAXSIG > (2 * 32)) && (MAXSIG <= (3 * 32))) 264 #define FILLSET0 0xffffffffu 265 #define FILLSET1 0xffffffffu 266 #define FILLSET2 ((1u << (MAXSIG - 64)) - 1) 267 #else 268 #error "fix me: MAXSIG out of bounds" 269 #endif 270 271 #define CANTMASK0 (sigmask(SIGKILL)|sigmask(SIGSTOP)) 272 #define CANTMASK1 0 273 #define CANTMASK2 0 274 275 #define sigemptyset(s) (*(s) = nullsmask) 276 #define sigfillset(s) (*(s) = fillset) 277 #define sigaddset(s, n) ((s)->__sigbits[sigword(n)] |= sigmask(n)) 278 #define sigdelset(s, n) ((s)->__sigbits[sigword(n)] &= ~sigmask(n)) 279 #define sigismember(s, n) (sigmask(n) & (s)->__sigbits[sigword(n)]) 280 #define sigisempty(s) (!((s)->__sigbits[0] | (s)->__sigbits[1] | \ 281 (s)->__sigbits[2])) 282 #define sigutok(us, ks) \ 283 ((ks)->__sigbits[0] = (us)->__sigbits[0] & (FILLSET0 & ~CANTMASK0), \ 284 (ks)->__sigbits[1] = (us)->__sigbits[1] & (FILLSET1 & ~CANTMASK1), \ 285 (ks)->__sigbits[2] = (us)->__sigbits[2] & (FILLSET2 & ~CANTMASK2)) 286 #define sigktou(ks, us) ((us)->__sigbits[0] = (ks)->__sigbits[0], \ 287 (us)->__sigbits[1] = (ks)->__sigbits[1], \ 288 (us)->__sigbits[2] = (ks)->__sigbits[2], \ 289 (us)->__sigbits[3] = 0) 290 typedef struct { 291 int sig; /* signal no. */ 292 int perm; /* flag for EPERM */ 293 int checkperm; /* check perm or not */ 294 int sicode; /* has siginfo.si_code */ 295 union sigval value; /* user specified value */ 296 } sigsend_t; 297 298 typedef struct { 299 sigqueue_t sn_sigq; /* sigq struct for notification */ 300 u_longlong_t sn_snid; /* unique id for notification */ 301 } signotifyq_t; 302 303 typedef struct sigqhdr { /* sigqueue pool header */ 304 sigqueue_t *sqb_free; /* free sigq struct list */ 305 int sqb_count; /* sigq free count */ 306 uint_t sqb_maxcount; /* sigq max free count */ 307 size_t sqb_size; /* size of header+free structs */ 308 uchar_t sqb_pexited; /* process has exited */ 309 uint_t sqb_sent; /* number of sigq sent */ 310 kcondvar_t sqb_cv; /* waiting for a sigq struct */ 311 kmutex_t sqb_lock; /* lock for sigq pool */ 312 } sigqhdr_t; 313 314 #define _SIGQUEUE_SIZE_BASIC 128 /* basic limit */ 315 #define _SIGQUEUE_SIZE_PRIVILEGED 512 /* privileged limit */ 316 #define _SIGQUEUE_SIZE_MAX 8192 /* maximum limit */ 317 318 #define _SIGNOTIFY_MAX 32 319 320 extern void setsigact(int, void (*)(int), const k_sigset_t *, int); 321 extern void sigorset(k_sigset_t *, const k_sigset_t *); 322 extern void sigandset(k_sigset_t *, const k_sigset_t *); 323 extern void sigdiffset(k_sigset_t *, const k_sigset_t *); 324 extern void sigintr(k_sigset_t *, int); 325 extern void sigunintr(k_sigset_t *); 326 extern void sigreplace(k_sigset_t *, k_sigset_t *); 327 328 extern int kill(pid_t, int); 329 330 #endif /* _KERNEL */ 331 332 #ifdef __cplusplus 333 } 334 #endif 335 336 #endif /* _SYS_SIGNAL_H */