xref: /onnv-gate/usr/src/uts/common/sys/signal.h (revision 11913:283e725df792)
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
52248Sraf  * Common Development and Distribution License (the "License").
62248Sraf  * 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  */
212248Sraf 
220Sstevel@tonic-gate /*
23*11913SRoger.Faulkner@Sun.COM  * Copyright 2010 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 #include <sys/feature_tests.h>
440Sstevel@tonic-gate #include <sys/iso/signal_iso.h>
450Sstevel@tonic-gate 
460Sstevel@tonic-gate #ifdef	__cplusplus
470Sstevel@tonic-gate extern "C" {
480Sstevel@tonic-gate #endif
490Sstevel@tonic-gate 
500Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || !defined(_STRICT_STDC) || \
510Sstevel@tonic-gate 	defined(__XOPEN_OR_POSIX)
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
540Sstevel@tonic-gate 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
550Sstevel@tonic-gate 	(_POSIX_C_SOURCE > 2) || defined(_XPG4_2)
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate  * We need <sys/siginfo.h> for the declaration of siginfo_t.
580Sstevel@tonic-gate  */
590Sstevel@tonic-gate #include <sys/siginfo.h>
600Sstevel@tonic-gate #endif
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /* Duplicated in <sys/ucontext.h> as a result of XPG4v2 requirements */
630Sstevel@tonic-gate #ifndef	_SIGSET_T
640Sstevel@tonic-gate #define	_SIGSET_T
650Sstevel@tonic-gate typedef struct {		/* signal set type */
660Sstevel@tonic-gate 	unsigned int	__sigbits[4];
670Sstevel@tonic-gate } sigset_t;
680Sstevel@tonic-gate #endif	/* _SIGSET_T */
690Sstevel@tonic-gate 
700Sstevel@tonic-gate typedef	struct {
71*11913SRoger.Faulkner@Sun.COM 	unsigned int	__sigbits[3];
720Sstevel@tonic-gate } k_sigset_t;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate /*
750Sstevel@tonic-gate  * The signal handler routine can have either one or three arguments.
760Sstevel@tonic-gate  * Existing C code has used either form so not specifing the arguments
770Sstevel@tonic-gate  * neatly finesses the problem.  C++ doesn't accept this.  To C++
780Sstevel@tonic-gate  * "(*sa_handler)()" indicates a routine with no arguments (ANSI C would
790Sstevel@tonic-gate  * specify this as "(*sa_handler)(void)").  One or the other form must be
800Sstevel@tonic-gate  * used for C++ and the only logical choice is "(*sa_handler)(int)" to allow
810Sstevel@tonic-gate  * the SIG_* defines to work.  "(*sa_sigaction)(int, siginfo_t *, void *)"
820Sstevel@tonic-gate  * can be used for the three argument form.
830Sstevel@tonic-gate  */
840Sstevel@tonic-gate 
850Sstevel@tonic-gate /*
860Sstevel@tonic-gate  * Note: storage overlap by sa_handler and sa_sigaction
870Sstevel@tonic-gate  */
880Sstevel@tonic-gate struct sigaction {
890Sstevel@tonic-gate 	int sa_flags;
900Sstevel@tonic-gate 	union {
910Sstevel@tonic-gate #ifdef	__cplusplus
920Sstevel@tonic-gate 		void (*_handler)(int);
930Sstevel@tonic-gate #else
940Sstevel@tonic-gate 		void (*_handler)();
950Sstevel@tonic-gate #endif
960Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
970Sstevel@tonic-gate 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
980Sstevel@tonic-gate 	(_POSIX_C_SOURCE > 2) || defined(_XPG4_2)
990Sstevel@tonic-gate 		void (*_sigaction)(int, siginfo_t *, void *);
1000Sstevel@tonic-gate #endif
1010Sstevel@tonic-gate 	}	_funcptr;
1020Sstevel@tonic-gate 	sigset_t sa_mask;
1030Sstevel@tonic-gate #ifndef _LP64
1040Sstevel@tonic-gate 	int sa_resv[2];
1050Sstevel@tonic-gate #endif
1060Sstevel@tonic-gate };
1070Sstevel@tonic-gate #define	sa_handler	_funcptr._handler
1080Sstevel@tonic-gate #define	sa_sigaction	_funcptr._sigaction
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate #if defined(_SYSCALL32)
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate /* Kernel view of the ILP32 user sigaction structure */
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate struct sigaction32 {
1150Sstevel@tonic-gate 	int32_t		sa_flags;
1160Sstevel@tonic-gate 	union {
1170Sstevel@tonic-gate 		caddr32_t	_handler;
1180Sstevel@tonic-gate 		caddr32_t	_sigaction;
1190Sstevel@tonic-gate 	}	_funcptr;
120*11913SRoger.Faulkner@Sun.COM 	sigset_t	sa_mask;
1210Sstevel@tonic-gate 	int32_t		sa_resv[2];
1220Sstevel@tonic-gate };
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /* this is only valid for SIGCLD */
1270Sstevel@tonic-gate #define	SA_NOCLDSTOP	0x00020000	/* don't send job control SIGCLD's */
1280Sstevel@tonic-gate #endif
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
1310Sstevel@tonic-gate 	(!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
1320Sstevel@tonic-gate 	defined(_XPG4_2)
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 			/* non-conformant ANSI compilation	*/
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate /* definitions for the sa_flags field */
1370Sstevel@tonic-gate #define	SA_ONSTACK	0x00000001
1380Sstevel@tonic-gate #define	SA_RESETHAND	0x00000002
1390Sstevel@tonic-gate #define	SA_RESTART	0x00000004
1400Sstevel@tonic-gate #endif
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
1430Sstevel@tonic-gate 	(!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
1440Sstevel@tonic-gate 	(_POSIX_C_SOURCE > 2) || defined(_XPG4_2)
1450Sstevel@tonic-gate #define	SA_SIGINFO	0x00000008
1460Sstevel@tonic-gate #endif
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
1490Sstevel@tonic-gate 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
1500Sstevel@tonic-gate 	defined(_XPG4_2)
1510Sstevel@tonic-gate #define	SA_NODEFER	0x00000010
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate /* this is only valid for SIGCLD */
1540Sstevel@tonic-gate #define	SA_NOCLDWAIT	0x00010000	/* don't save zombie children	 */
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(_XPG4_2)
1570Sstevel@tonic-gate /*
1580Sstevel@tonic-gate  * use of these symbols by applications is injurious
1590Sstevel@tonic-gate  *	to binary compatibility
1600Sstevel@tonic-gate  */
161*11913SRoger.Faulkner@Sun.COM #define	NSIG	73	/* valid signals range from 1 to NSIG-1 */
162*11913SRoger.Faulkner@Sun.COM #define	MAXSIG	72	/* size of u_signal[], NSIG-1 <= MAXSIG */
1630Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(_XPG4_2) */
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate #define	MINSIGSTKSZ	2048
1660Sstevel@tonic-gate #define	SIGSTKSZ	8192
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate #define	SS_ONSTACK	0x00000001
1690Sstevel@tonic-gate #define	SS_DISABLE	0x00000002
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate /* Duplicated in <sys/ucontext.h> as a result of XPG4v2 requirements. */
1720Sstevel@tonic-gate #ifndef	_STACK_T
1730Sstevel@tonic-gate #define	_STACK_T
1740Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(_XPG4_2)
1750Sstevel@tonic-gate typedef struct sigaltstack {
1760Sstevel@tonic-gate #else
1770Sstevel@tonic-gate typedef struct {
1780Sstevel@tonic-gate #endif
1790Sstevel@tonic-gate 	void	*ss_sp;
1800Sstevel@tonic-gate 	size_t	ss_size;
1810Sstevel@tonic-gate 	int	ss_flags;
1820Sstevel@tonic-gate } stack_t;
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate #if defined(_SYSCALL32)
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate /* Kernel view of the ILP32 user sigaltstack structure */
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate typedef struct sigaltstack32 {
1890Sstevel@tonic-gate 	caddr32_t	ss_sp;
1900Sstevel@tonic-gate 	size32_t	ss_size;
1910Sstevel@tonic-gate 	int32_t		ss_flags;
1920Sstevel@tonic-gate } stack32_t;
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate #endif /* _SYSCALL32 */
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate #endif /* _STACK_T */
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */
1990Sstevel@tonic-gate 
2000Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
2010Sstevel@tonic-gate 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
2020Sstevel@tonic-gate 
2032248Sraf /* signotify id used only by libc for mq_notify()/aio_notify() */
2040Sstevel@tonic-gate typedef struct signotify_id {		/* signotify id struct		*/
2050Sstevel@tonic-gate 	pid_t	sn_pid;			/* pid of proc to be notified	*/
2060Sstevel@tonic-gate 	int	sn_index;		/* index in preallocated pool	*/
2070Sstevel@tonic-gate 	int	sn_pad;			/* reserved			*/
2080Sstevel@tonic-gate } signotify_id_t;
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate #if defined(_SYSCALL32)
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate /* Kernel view of the ILP32 user signotify_id structure */
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate typedef struct signotify32_id {
2150Sstevel@tonic-gate 	pid32_t	sn_pid;			/* pid of proc to be notified */
2160Sstevel@tonic-gate 	int32_t	sn_index;		/* index in preallocated pool */
2170Sstevel@tonic-gate 	int32_t	sn_pad;			/* reserved */
2180Sstevel@tonic-gate } signotify32_id_t;
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate #endif	/* _SYSCALL32 */
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate /* Command codes for sig_notify call */
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate #define	SN_PROC		1		/* queue signotify for process	*/
2250Sstevel@tonic-gate #define	SN_CANCEL	2		/* cancel the queued signotify	*/
2260Sstevel@tonic-gate #define	SN_SEND		3		/* send the notified signal	*/
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate /* Added as per XPG4v2 */
2310Sstevel@tonic-gate #if defined(__EXTENSIONS__) || defined(_KERNEL) || \
2320Sstevel@tonic-gate 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
2330Sstevel@tonic-gate 	defined(_XPG4_2)
2340Sstevel@tonic-gate struct sigstack {
2350Sstevel@tonic-gate 	void	*ss_sp;
2360Sstevel@tonic-gate 	int	ss_onstack;
2370Sstevel@tonic-gate };
2380Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || defined(_KERNEL) ... */
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate /*
2410Sstevel@tonic-gate  * For definition of ucontext_t; must follow struct definition
2420Sstevel@tonic-gate  * for  sigset_t
2430Sstevel@tonic-gate  */
2440Sstevel@tonic-gate #if defined(_XPG4_2)
2450Sstevel@tonic-gate #include <sys/ucontext.h>
2460Sstevel@tonic-gate #endif /* defined(_XPG4_2) */
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate #ifdef _KERNEL
2490Sstevel@tonic-gate #include <sys/t_lock.h>
2500Sstevel@tonic-gate 
251*11913SRoger.Faulkner@Sun.COM extern const k_sigset_t nullsmask;	/* a null signal mask */
252*11913SRoger.Faulkner@Sun.COM extern const k_sigset_t fillset;	/* all signals, guaranteed contiguous */
253*11913SRoger.Faulkner@Sun.COM extern const k_sigset_t cantmask;	/* cannot be caught or ignored */
254*11913SRoger.Faulkner@Sun.COM extern const k_sigset_t cantreset;	/* cannot be reset after catching */
255*11913SRoger.Faulkner@Sun.COM extern const k_sigset_t ignoredefault;	/* ignored by default */
256*11913SRoger.Faulkner@Sun.COM extern const k_sigset_t stopdefault;	/* stop by default */
257*11913SRoger.Faulkner@Sun.COM extern const k_sigset_t coredefault;	/* dumps core by default */
258*11913SRoger.Faulkner@Sun.COM extern const k_sigset_t holdvfork;	/* held while doing vfork */
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate #define	sigmask(n)		((unsigned int)1 << (((n) - 1) & (32 - 1)))
2610Sstevel@tonic-gate #define	sigword(n)		(((unsigned int)((n) - 1))>>5)
2620Sstevel@tonic-gate 
263*11913SRoger.Faulkner@Sun.COM #if ((MAXSIG > (2 * 32)) && (MAXSIG <= (3 * 32)))
2640Sstevel@tonic-gate #define	FILLSET0	0xffffffffu
265*11913SRoger.Faulkner@Sun.COM #define	FILLSET1	0xffffffffu
266*11913SRoger.Faulkner@Sun.COM #define	FILLSET2	((1u << (MAXSIG - 64)) - 1)
2670Sstevel@tonic-gate #else
2680Sstevel@tonic-gate #error "fix me: MAXSIG out of bounds"
2690Sstevel@tonic-gate #endif
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate #define	CANTMASK0	(sigmask(SIGKILL)|sigmask(SIGSTOP))
2720Sstevel@tonic-gate #define	CANTMASK1	0
273*11913SRoger.Faulkner@Sun.COM #define	CANTMASK2	0
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate #define	sigemptyset(s)		(*(s) = nullsmask)
2760Sstevel@tonic-gate #define	sigfillset(s)		(*(s) = fillset)
2770Sstevel@tonic-gate #define	sigaddset(s, n)		((s)->__sigbits[sigword(n)] |= sigmask(n))
2780Sstevel@tonic-gate #define	sigdelset(s, n)		((s)->__sigbits[sigword(n)] &= ~sigmask(n))
2790Sstevel@tonic-gate #define	sigismember(s, n)	(sigmask(n) & (s)->__sigbits[sigword(n)])
280*11913SRoger.Faulkner@Sun.COM #define	sigisempty(s)		(!((s)->__sigbits[0] | (s)->__sigbits[1] | \
281*11913SRoger.Faulkner@Sun.COM 				(s)->__sigbits[2]))
2820Sstevel@tonic-gate #define	sigutok(us, ks)		\
2830Sstevel@tonic-gate 	((ks)->__sigbits[0] = (us)->__sigbits[0] & (FILLSET0 & ~CANTMASK0), \
284*11913SRoger.Faulkner@Sun.COM 	(ks)->__sigbits[1] = (us)->__sigbits[1] & (FILLSET1 & ~CANTMASK1), \
285*11913SRoger.Faulkner@Sun.COM 	(ks)->__sigbits[2] = (us)->__sigbits[2] & (FILLSET2 & ~CANTMASK2))
2860Sstevel@tonic-gate #define	sigktou(ks, us)		((us)->__sigbits[0] = (ks)->__sigbits[0], \
287*11913SRoger.Faulkner@Sun.COM 				(us)->__sigbits[1] = (ks)->__sigbits[1], \
288*11913SRoger.Faulkner@Sun.COM 				(us)->__sigbits[2] = (ks)->__sigbits[2], \
289*11913SRoger.Faulkner@Sun.COM 				(us)->__sigbits[3] = 0)
2900Sstevel@tonic-gate typedef struct {
2910Sstevel@tonic-gate 	int	sig;				/* signal no.		*/
2920Sstevel@tonic-gate 	int	perm;				/* flag for EPERM	*/
2930Sstevel@tonic-gate 	int	checkperm;			/* check perm or not	*/
2940Sstevel@tonic-gate 	int	sicode;				/* has siginfo.si_code	*/
2950Sstevel@tonic-gate 	union sigval value;			/* user specified value	*/
2960Sstevel@tonic-gate } sigsend_t;
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate typedef struct {
2990Sstevel@tonic-gate 	sigqueue_t	sn_sigq;	/* sigq struct for notification */
3000Sstevel@tonic-gate 	u_longlong_t	sn_snid;	/* unique id for notification	*/
3010Sstevel@tonic-gate } signotifyq_t;
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate 
3040Sstevel@tonic-gate typedef struct sigqhdr {		/* sigqueue pool header		*/
3050Sstevel@tonic-gate 	sigqueue_t	*sqb_free;	/* free sigq struct list	*/
3060Sstevel@tonic-gate 	uchar_t		sqb_count;	/* sigq free count		*/
3070Sstevel@tonic-gate 	uchar_t		sqb_maxcount;	/* sigq max free count		*/
3080Sstevel@tonic-gate 	ushort_t	sqb_size;	/* size of header+free structs	*/
3090Sstevel@tonic-gate 	uchar_t		sqb_pexited;	/* process has exited		*/
3100Sstevel@tonic-gate 	uchar_t		sqb_sent;	/* number of sigq sent		*/
3112248Sraf 	kcondvar_t	sqb_cv;		/* waiting for a sigq struct	*/
3120Sstevel@tonic-gate 	kmutex_t	sqb_lock;	/* lock for sigq pool		*/
3130Sstevel@tonic-gate } sigqhdr_t;
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate #define	_SIGQUEUE_MAX	32
3160Sstevel@tonic-gate #define	_SIGNOTIFY_MAX	32
3170Sstevel@tonic-gate 
318*11913SRoger.Faulkner@Sun.COM extern	void	setsigact(int, void (*)(int), const k_sigset_t *, int);
319*11913SRoger.Faulkner@Sun.COM extern	void	sigorset(k_sigset_t *, const k_sigset_t *);
320*11913SRoger.Faulkner@Sun.COM extern	void	sigandset(k_sigset_t *, const k_sigset_t *);
321*11913SRoger.Faulkner@Sun.COM extern	void	sigdiffset(k_sigset_t *, const k_sigset_t *);
3220Sstevel@tonic-gate extern	void	sigintr(k_sigset_t *, int);
3230Sstevel@tonic-gate extern	void	sigunintr(k_sigset_t *);
3240Sstevel@tonic-gate extern	void	sigreplace(k_sigset_t *, k_sigset_t *);
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate extern	int	kill(pid_t, int);
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate #endif /* _KERNEL */
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate #ifdef	__cplusplus
3310Sstevel@tonic-gate }
3320Sstevel@tonic-gate #endif
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate #endif /* _SYS_SIGNAL_H */
335