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