10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2248Sraf * Common Development and Distribution License (the "License"). 6*2248Sraf * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*2248Sraf 220Sstevel@tonic-gate /* 23*2248Sraf * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 280Sstevel@tonic-gate /* All Rights Reserved */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate /* 310Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 320Sstevel@tonic-gate * The Regents of the University of California 330Sstevel@tonic-gate * All Rights Reserved 340Sstevel@tonic-gate * 350Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 360Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 370Sstevel@tonic-gate * contributors. 380Sstevel@tonic-gate */ 390Sstevel@tonic-gate 400Sstevel@tonic-gate #ifndef _SYS_SIGNAL_H 410Sstevel@tonic-gate #define _SYS_SIGNAL_H 420Sstevel@tonic-gate 430Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 440Sstevel@tonic-gate 450Sstevel@tonic-gate #include <sys/feature_tests.h> 460Sstevel@tonic-gate #include <sys/iso/signal_iso.h> 470Sstevel@tonic-gate 480Sstevel@tonic-gate #ifdef __cplusplus 490Sstevel@tonic-gate extern "C" { 500Sstevel@tonic-gate #endif 510Sstevel@tonic-gate 520Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || !defined(_STRICT_STDC) || \ 530Sstevel@tonic-gate defined(__XOPEN_OR_POSIX) 540Sstevel@tonic-gate 550Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 560Sstevel@tonic-gate (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 570Sstevel@tonic-gate (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) 580Sstevel@tonic-gate /* 590Sstevel@tonic-gate * We need <sys/siginfo.h> for the declaration of siginfo_t. 600Sstevel@tonic-gate */ 610Sstevel@tonic-gate #include <sys/siginfo.h> 620Sstevel@tonic-gate #endif 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* Duplicated in <sys/ucontext.h> as a result of XPG4v2 requirements */ 650Sstevel@tonic-gate #ifndef _SIGSET_T 660Sstevel@tonic-gate #define _SIGSET_T 670Sstevel@tonic-gate typedef struct { /* signal set type */ 680Sstevel@tonic-gate unsigned int __sigbits[4]; 690Sstevel@tonic-gate } sigset_t; 700Sstevel@tonic-gate 710Sstevel@tonic-gate #if defined(_SYSCALL32) 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* Kernel view of the ILP32 user sigset_t structure */ 740Sstevel@tonic-gate 750Sstevel@tonic-gate typedef struct { 760Sstevel@tonic-gate uint32_t __sigbits[4]; 770Sstevel@tonic-gate } sigset32_t; 780Sstevel@tonic-gate 790Sstevel@tonic-gate #endif /* _SYSCALL32 */ 800Sstevel@tonic-gate 810Sstevel@tonic-gate #endif /* _SIGSET_T */ 820Sstevel@tonic-gate 830Sstevel@tonic-gate typedef struct { 840Sstevel@tonic-gate unsigned int __sigbits[2]; 850Sstevel@tonic-gate } k_sigset_t; 860Sstevel@tonic-gate 870Sstevel@tonic-gate /* 880Sstevel@tonic-gate * The signal handler routine can have either one or three arguments. 890Sstevel@tonic-gate * Existing C code has used either form so not specifing the arguments 900Sstevel@tonic-gate * neatly finesses the problem. C++ doesn't accept this. To C++ 910Sstevel@tonic-gate * "(*sa_handler)()" indicates a routine with no arguments (ANSI C would 920Sstevel@tonic-gate * specify this as "(*sa_handler)(void)"). One or the other form must be 930Sstevel@tonic-gate * used for C++ and the only logical choice is "(*sa_handler)(int)" to allow 940Sstevel@tonic-gate * the SIG_* defines to work. "(*sa_sigaction)(int, siginfo_t *, void *)" 950Sstevel@tonic-gate * can be used for the three argument form. 960Sstevel@tonic-gate */ 970Sstevel@tonic-gate 980Sstevel@tonic-gate /* 990Sstevel@tonic-gate * Note: storage overlap by sa_handler and sa_sigaction 1000Sstevel@tonic-gate */ 1010Sstevel@tonic-gate struct sigaction { 1020Sstevel@tonic-gate int sa_flags; 1030Sstevel@tonic-gate union { 1040Sstevel@tonic-gate #ifdef __cplusplus 1050Sstevel@tonic-gate void (*_handler)(int); 1060Sstevel@tonic-gate #else 1070Sstevel@tonic-gate void (*_handler)(); 1080Sstevel@tonic-gate #endif 1090Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 1100Sstevel@tonic-gate (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 1110Sstevel@tonic-gate (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) 1120Sstevel@tonic-gate void (*_sigaction)(int, siginfo_t *, void *); 1130Sstevel@tonic-gate #endif 1140Sstevel@tonic-gate } _funcptr; 1150Sstevel@tonic-gate sigset_t sa_mask; 1160Sstevel@tonic-gate #ifndef _LP64 1170Sstevel@tonic-gate int sa_resv[2]; 1180Sstevel@tonic-gate #endif 1190Sstevel@tonic-gate }; 1200Sstevel@tonic-gate #define sa_handler _funcptr._handler 1210Sstevel@tonic-gate #define sa_sigaction _funcptr._sigaction 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate #if defined(_SYSCALL32) 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* Kernel view of the ILP32 user sigaction structure */ 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate struct sigaction32 { 1280Sstevel@tonic-gate int32_t sa_flags; 1290Sstevel@tonic-gate union { 1300Sstevel@tonic-gate caddr32_t _handler; 1310Sstevel@tonic-gate caddr32_t _sigaction; 1320Sstevel@tonic-gate } _funcptr; 1330Sstevel@tonic-gate sigset32_t sa_mask; 1340Sstevel@tonic-gate int32_t sa_resv[2]; 1350Sstevel@tonic-gate }; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate #endif /* _SYSCALL32 */ 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate /* this is only valid for SIGCLD */ 1400Sstevel@tonic-gate #define SA_NOCLDSTOP 0x00020000 /* don't send job control SIGCLD's */ 1410Sstevel@tonic-gate #endif 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 1440Sstevel@tonic-gate (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \ 1450Sstevel@tonic-gate defined(_XPG4_2) 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* non-conformant ANSI compilation */ 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate /* definitions for the sa_flags field */ 1500Sstevel@tonic-gate #define SA_ONSTACK 0x00000001 1510Sstevel@tonic-gate #define SA_RESETHAND 0x00000002 1520Sstevel@tonic-gate #define SA_RESTART 0x00000004 1530Sstevel@tonic-gate #endif 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 1560Sstevel@tonic-gate (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \ 1570Sstevel@tonic-gate (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) 1580Sstevel@tonic-gate #define SA_SIGINFO 0x00000008 1590Sstevel@tonic-gate #endif 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 1620Sstevel@tonic-gate (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 1630Sstevel@tonic-gate defined(_XPG4_2) 1640Sstevel@tonic-gate #define SA_NODEFER 0x00000010 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate /* this is only valid for SIGCLD */ 1670Sstevel@tonic-gate #define SA_NOCLDWAIT 0x00010000 /* don't save zombie children */ 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(_XPG4_2) 1700Sstevel@tonic-gate /* 1710Sstevel@tonic-gate * use of these symbols by applications is injurious 1720Sstevel@tonic-gate * to binary compatibility 1730Sstevel@tonic-gate */ 1740Sstevel@tonic-gate #define NSIG 49 /* valid signals range from 1 to NSIG-1 */ 1750Sstevel@tonic-gate #define MAXSIG 48 /* size of u_signal[], NSIG-1 <= MAXSIG */ 1760Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(_XPG4_2) */ 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate #define MINSIGSTKSZ 2048 1790Sstevel@tonic-gate #define SIGSTKSZ 8192 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate #define SS_ONSTACK 0x00000001 1820Sstevel@tonic-gate #define SS_DISABLE 0x00000002 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate /* Duplicated in <sys/ucontext.h> as a result of XPG4v2 requirements. */ 1850Sstevel@tonic-gate #ifndef _STACK_T 1860Sstevel@tonic-gate #define _STACK_T 1870Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(_XPG4_2) 1880Sstevel@tonic-gate typedef struct sigaltstack { 1890Sstevel@tonic-gate #else 1900Sstevel@tonic-gate typedef struct { 1910Sstevel@tonic-gate #endif 1920Sstevel@tonic-gate void *ss_sp; 1930Sstevel@tonic-gate size_t ss_size; 1940Sstevel@tonic-gate int ss_flags; 1950Sstevel@tonic-gate } stack_t; 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate #if defined(_SYSCALL32) 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate /* Kernel view of the ILP32 user sigaltstack structure */ 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate typedef struct sigaltstack32 { 2020Sstevel@tonic-gate caddr32_t ss_sp; 2030Sstevel@tonic-gate size32_t ss_size; 2040Sstevel@tonic-gate int32_t ss_flags; 2050Sstevel@tonic-gate } stack32_t; 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate #endif /* _SYSCALL32 */ 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate #endif /* _STACK_T */ 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */ 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 2140Sstevel@tonic-gate (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) 2150Sstevel@tonic-gate 216*2248Sraf /* signotify id used only by libc for mq_notify()/aio_notify() */ 2170Sstevel@tonic-gate typedef struct signotify_id { /* signotify id struct */ 2180Sstevel@tonic-gate pid_t sn_pid; /* pid of proc to be notified */ 2190Sstevel@tonic-gate int sn_index; /* index in preallocated pool */ 2200Sstevel@tonic-gate int sn_pad; /* reserved */ 2210Sstevel@tonic-gate } signotify_id_t; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate #if defined(_SYSCALL32) 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /* Kernel view of the ILP32 user signotify_id structure */ 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate typedef struct signotify32_id { 2280Sstevel@tonic-gate pid32_t sn_pid; /* pid of proc to be notified */ 2290Sstevel@tonic-gate int32_t sn_index; /* index in preallocated pool */ 2300Sstevel@tonic-gate int32_t sn_pad; /* reserved */ 2310Sstevel@tonic-gate } signotify32_id_t; 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate #endif /* _SYSCALL32 */ 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate /* Command codes for sig_notify call */ 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate #define SN_PROC 1 /* queue signotify for process */ 2380Sstevel@tonic-gate #define SN_CANCEL 2 /* cancel the queued signotify */ 2390Sstevel@tonic-gate #define SN_SEND 3 /* send the notified signal */ 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */ 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate /* Added as per XPG4v2 */ 2440Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \ 2450Sstevel@tonic-gate (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \ 2460Sstevel@tonic-gate defined(_XPG4_2) 2470Sstevel@tonic-gate struct sigstack { 2480Sstevel@tonic-gate void *ss_sp; 2490Sstevel@tonic-gate int ss_onstack; 2500Sstevel@tonic-gate }; 2510Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */ 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate /* 2540Sstevel@tonic-gate * For definition of ucontext_t; must follow struct definition 2550Sstevel@tonic-gate * for sigset_t 2560Sstevel@tonic-gate */ 2570Sstevel@tonic-gate #if defined(_XPG4_2) 2580Sstevel@tonic-gate #include <sys/ucontext.h> 2590Sstevel@tonic-gate #endif /* defined(_XPG4_2) */ 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate #ifdef _KERNEL 2620Sstevel@tonic-gate #include <sys/t_lock.h> 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate extern k_sigset_t 2650Sstevel@tonic-gate nullsmask, /* a null signal mask */ 2660Sstevel@tonic-gate fillset, /* valid signals, guaranteed contiguous */ 2670Sstevel@tonic-gate holdvfork, /* held while doing vfork */ 2680Sstevel@tonic-gate cantmask, /* cannot be caught or ignored */ 2690Sstevel@tonic-gate cantreset, /* cannot be reset after catching */ 2700Sstevel@tonic-gate ignoredefault, /* ignored by default */ 2710Sstevel@tonic-gate stopdefault, /* stop by default */ 2720Sstevel@tonic-gate coredefault; /* dumps core by default */ 2730Sstevel@tonic-gate 2740Sstevel@tonic-gate #define sigmask(n) ((unsigned int)1 << (((n) - 1) & (32 - 1))) 2750Sstevel@tonic-gate #define sigword(n) (((unsigned int)((n) - 1))>>5) 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate #if ((MAXSIG > 32) && (MAXSIG <= 64)) 2780Sstevel@tonic-gate #define FILLSET0 0xffffffffu 2790Sstevel@tonic-gate #define FILLSET1 ((1u << (MAXSIG - 32)) - 1) 2800Sstevel@tonic-gate #else 2810Sstevel@tonic-gate #error "fix me: MAXSIG out of bounds" 2820Sstevel@tonic-gate #endif 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate #define CANTMASK0 (sigmask(SIGKILL)|sigmask(SIGSTOP)) 2850Sstevel@tonic-gate #define CANTMASK1 0 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate #define sigemptyset(s) (*(s) = nullsmask) 2880Sstevel@tonic-gate #define sigfillset(s) (*(s) = fillset) 2890Sstevel@tonic-gate #define sigaddset(s, n) ((s)->__sigbits[sigword(n)] |= sigmask(n)) 2900Sstevel@tonic-gate #define sigdelset(s, n) ((s)->__sigbits[sigword(n)] &= ~sigmask(n)) 2910Sstevel@tonic-gate #define sigismember(s, n) (sigmask(n) & (s)->__sigbits[sigword(n)]) 2920Sstevel@tonic-gate #define sigisempty(s) (!(((s)->__sigbits[0]) | ((s)->__sigbits[1]))) 2930Sstevel@tonic-gate #define sigutok(us, ks) \ 2940Sstevel@tonic-gate ((ks)->__sigbits[0] = (us)->__sigbits[0] & (FILLSET0 & ~CANTMASK0), \ 2950Sstevel@tonic-gate (ks)->__sigbits[1] = (us)->__sigbits[1] & (FILLSET1 & ~CANTMASK1)) 2960Sstevel@tonic-gate #define sigktou(ks, us) ((us)->__sigbits[0] = (ks)->__sigbits[0], \ 2970Sstevel@tonic-gate (us)->__sigbits[1] = (ks)->__sigbits[1], \ 2980Sstevel@tonic-gate (us)->__sigbits[2] = 0, \ 2990Sstevel@tonic-gate (us)->__sigbits[3] = 0) 3000Sstevel@tonic-gate typedef struct { 3010Sstevel@tonic-gate int sig; /* signal no. */ 3020Sstevel@tonic-gate int perm; /* flag for EPERM */ 3030Sstevel@tonic-gate int checkperm; /* check perm or not */ 3040Sstevel@tonic-gate int sicode; /* has siginfo.si_code */ 3050Sstevel@tonic-gate union sigval value; /* user specified value */ 3060Sstevel@tonic-gate } sigsend_t; 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate typedef struct { 3090Sstevel@tonic-gate sigqueue_t sn_sigq; /* sigq struct for notification */ 3100Sstevel@tonic-gate u_longlong_t sn_snid; /* unique id for notification */ 3110Sstevel@tonic-gate } signotifyq_t; 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate typedef struct sigqhdr { /* sigqueue pool header */ 3150Sstevel@tonic-gate sigqueue_t *sqb_free; /* free sigq struct list */ 3160Sstevel@tonic-gate uchar_t sqb_count; /* sigq free count */ 3170Sstevel@tonic-gate uchar_t sqb_maxcount; /* sigq max free count */ 3180Sstevel@tonic-gate ushort_t sqb_size; /* size of header+free structs */ 3190Sstevel@tonic-gate uchar_t sqb_pexited; /* process has exited */ 3200Sstevel@tonic-gate uchar_t sqb_sent; /* number of sigq sent */ 321*2248Sraf kcondvar_t sqb_cv; /* waiting for a sigq struct */ 3220Sstevel@tonic-gate kmutex_t sqb_lock; /* lock for sigq pool */ 3230Sstevel@tonic-gate } sigqhdr_t; 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate #define _SIGQUEUE_MAX 32 3260Sstevel@tonic-gate #define _SIGNOTIFY_MAX 32 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate extern void setsigact(int, void (*)(int), k_sigset_t, int); 3290Sstevel@tonic-gate extern void sigorset(k_sigset_t *, k_sigset_t *); 3300Sstevel@tonic-gate extern void sigandset(k_sigset_t *, k_sigset_t *); 3310Sstevel@tonic-gate extern void sigdiffset(k_sigset_t *, k_sigset_t *); 3320Sstevel@tonic-gate extern void sigintr(k_sigset_t *, int); 3330Sstevel@tonic-gate extern void sigunintr(k_sigset_t *); 3340Sstevel@tonic-gate extern void sigreplace(k_sigset_t *, k_sigset_t *); 3350Sstevel@tonic-gate 3360Sstevel@tonic-gate extern int kill(pid_t, int); 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate #endif /* _KERNEL */ 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate #ifdef __cplusplus 3410Sstevel@tonic-gate } 3420Sstevel@tonic-gate #endif 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate #endif /* _SYS_SIGNAL_H */ 345