/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#ident	"$Header: signal.h 1.42 90/08/23 $"

/* $Log:	signal.h,v $
*/

#ifndef _SYS_SIGNAL_H
#define _SYS_SIGNAL_H	1

#ifndef INLIBC
typedef	int	sigset_t;	/*sigset_t is a <=32 bit interger mask       */
typedef	int	sig_atomic_t;	/* an int is atomic accros asynhcrnous       */
				/* intterupts. 			             */
#endif /* INLIBC */

#define	SIGHUP	1	/* hangup 				*/
#define	SIGINT	2	/* interrupt (rubout) 			*/
#define	SIGQUIT	3	/* quit (ASCII FS) 			*/
#define	SIGILL	4	/* illegal instruction (not reset when caught)*/

#ifndef _POSIX_SOURCE
#define	   ILL_RESOP_FAULT	0x1	/* reserved operation fault */
#endif /* _POSIX_SOURCE */

#define	SIGTRAP	5	/* trace trap (not reset when caught) 	*/
#define	SIGIOT	6	/* IOT instruction 			*/
#define SIGABRT 6	/* used by abort, replace SIGIOT in the  future */
#define	SIGEMT	7	/* EMT instruction 			*/
#define	SIGFPE	8	/* floating point exception 		*/

#ifndef _POSIX_SOURCE
			/* fpu.h also defines code 0-0x8f 	*/
#define	   FPE_INTOVF_TRAP	0xe0	/* integer overflow trap */
#define	   FPE_INTDIV_FAULT	0xe1	/* integer divide by zero fault */
#define	   FPE_COP_FAULT	0xe2	/* co-processor error 	*/
#define    FPE_COP_DNA		0xe3   /* no co-proc or emulator */
#endif /* _POSIX_SOURCE */

#define	SIGKILL	9	/* kill (cannot be caught or ignored) 	*/
#define	SIGBUS	10	/* bus error 				*/
#define	SIGSEGV	11	/* segmentation violation 		*/

#ifndef _POSIX_SOURCE
#define	   SEGV_ARRAY_FAULT	0x1	/* array bounds check 	*/
#define	   SEGV_STACK_FAULT	0x2	/* stack fault 		*/
#define	   SEGV_PRIVIN_FAULT	0x3	/* privileged instruction fault */
#define	   SEGV_PAGE_FAULT	0x4	/* page fault 		*/
#endif /* _POSIX_SOURCE */

#define	SIGSYS	12	/* bad argument to system call 		*/
			/* code is system call number 		*/
#define	SIGPIPE	13	/* write on a pipe with no one to read it */
#define	SIGALRM	14	/* alarm clock 				*/
#define	SIGTERM	15	/* software termination signal from kill */
#define	SIGUSR1	16	/* user defined signal 1 		*/
#define	SIGUSR2	17	/* user defined signal 2 		*/
#define	SIGCLD	18	/* death of a child 			*/
#define	SIGCHLD	18	/* death of a child 			*/
#define	SIGPWR	19	/* power-fail restart 			*/

#ifndef _POSIX_SOURCE
#define	PWR_FAIL 1	/* Power failure, UPS active		*/
#define PWR_OK   2	/* Power back on, UPS inactive		*/
#endif /* _POSIX_SOURCE */

#define SIGWINCH 20	/* window change 			*/
#define SIGURG 21	/* urgent socket condition		*/
#define SIGPOLL 22	/* pollable event occured 		*/
#define SIGIO 22	/* socket I/O possible (SIGPOLL alias)	*/
#define	SIGSTOP	23
#define SIGTSTP 24
#define SIGCONT 25
#define SIGTTIN 26
#define SIGTTOU 27
#define	SIGVTALRM 28
#define	SIGPROF 29

#ifndef INLIBC
#if lint && (! INKERNEL )
#define	SIG_DFL	(void(*)())0
#define SIG_ERR (void(*)())0
#define	SIG_IGN	(void (*)())0
#define SIG_HOLD (void(*)())0
#define SIG_CATCH (void(*)())0
#else
#define	SIG_DFL	(void(*)())0
#define SIG_ERR	(void(*)())-1
#define	SIG_IGN	(void (*)())1
#ifndef _POSIX_SOURCE
#define SIG_HOLD (void(*)())2
#define SIG_CATCH (void(*)())3
#endif /* _POSIX_SOURCE */
#endif /* lint && ! INKERNEL */

/*
 * POSIX IEEE std 1003.1-1988 3.3.4.1
 * The structure sigaction is used to describe the action taken on a signal.
 */
struct	sigaction {
	void		(*sa_handler)(); /* SIG_DFL, SIG_IGN, or pointer */
					 /* to a function                */
	sigset_t	sa_mask;	 /* set of signals to be blocked */
					 /* during execution of signal-  */
					 /* catching function            */
	int		sa_flags;	 /* spcial flags to be used when */
					 /* delivering signal 		 */
};

#define	SA_NOCLDSTOP	1		/* do not generate SIGCHLD when	*/
					/* children stop 		*/
#define SA_ALTSTACK	0x100		/* use alternative stack 	*/
#define SA_NOHOLD	0x200		/* old signal() style handler   */
#define SA_SIGSET	0x400		/* system V sigset style handler*/
#define SA_SUSP		0x800		/* was waiting in sigsuspend    */

#endif /* not INLIBC */
/*
 * These are the sigprocmask(request,new,old) request arguments.
 */
#define SIG_BLOCK	1
#define SIG_UNBLOCK	2
#define SIG_SETMASK	3

/*_________________________________________________________________
 * None of the rest of this file is visible to a POSIX_SOURCE file.
 *_________________________________________________________________
 */
#ifndef _POSIX_SOURCE

#define	NSIG	30	/* The valid signal number is from 1 to NSIG-1 	*/
#define MAXSIG	32	/* size of sigset_t 				*/

/*
 * these are the sigcontext(request,addr) request arguments
 */
#define	SF_SIGNO	1	/* the delievered signal */
#define	SF_CODE		2	/* code set (see above)  */	
#define	SF_SEGVCODE	3	/* faluting address      */
#define	SF_PC		4	/* pc at time of signal  */
#define	SF_SP		5	/* sp at time of signal  */
#define	SF_R0		6	/* %eip/r0               */
#define	SF_SET_PC	7	/* changes pc            */
#define	SF_CODE_DATA	8	/* (u_segvcode)          */
#define	SF_SYSCODE	9	/* system call           */	
#define	SF_TRAPCODE	10	/* machine trap type     */	

#ifndef INLIBC
struct	sigaltstack {			/* sigaltstack() structure */
	char 	*sas_sp;		/* signal stack pointer */
	int 	sas_onstack;		/* signal stack pointer */
};

struct	sigstack {			/* sigstack() structure */
	char 	*ss_sp;			/* signal stack pointer */
	int	ss_onstack;		/* flag for if on stack or not*/
};
#endif

#if defined(INKERNEL) || defined(INLIBC)
/* The following definitions are only used by kernel 
 * and lib/libc/xxxx/sys/signal.[cs] 
 * and lib/libseq/sigstack.s
 *		| byte3  |   byte2        |  byte1    | byte0 |
 *		|     POSIX P10003.1      | SVR3.1    | signo |
 */
#define SIGNO_MASK	0x000000ff
#define SIGDEFER	0x00000100
#define SIGHOLD		0x00000200
#define SIGRELSE	0x00000400
#define SIGIGNORE	0x00000800
#define SIGPAUSE	0x00001000
/* POSIX function support */
#define SIGACTION	0x00010000
#define SIGPROCMASK	0x00020000
#define SIGSUSPEND	0x00040000
#define SIGEMPTYSET	0x00080000
#define SIGFILLSET	0x00100000
#define SIGPENDING	0x00200000
#define SIGADDSET	0x00400000
#define SIGDELSET	0x00800000
#define SIGISMEMBER	0x01000000
#define SIGALT		0x02000000	/* reserved for sigaltstack() */
#endif /* INKERNEL or INLIBC */

/*_________________________________________________________________
 * None of the rest of this file is visible unless INKERNEL is set
 *_________________________________________________________________
 */
#ifdef INKERNEL

/* define those signals within range of MAXSIG that are illegal */
#define SIG_NOT	(sigmask(21)|sigmask(30)|sigmask(31))
#define SIG_ALL (-1)

/*
 * define set manipulation macros (by signo)
 * see POSIX 3.3.3.2 - only used by kernel code.
 */
#define sigmask(m)		(1 << ((m)-1))
#define	SIGM_ADDSET(set,sigm)	((set) |= (sigm))
#define	SIGM_DELSET(set,sigm)	((set) &= ~(sigm))
#define	SIGM_ISMEMBER(set,sigm)	((set) & (sigm))
#define	SIGM_INTERSECT(set1,set2)	((set1) & (set2))
#define	SIGM_UNION(set1,set2)	((set1) | (set2))
#define SIGM_CLR(set) 		((set)=0)
/*
 * issig() return codes.  Note that these are order dependent.
 * used to sema.c et al.
 */
#define	STOPPED		-1	/* No signal to process, stop was processed */
#define	NOSIG		0	/* No signal to process */
#define	GOTSIG		1	/* Signal to process */
#define	STPGOTSIG	2	/* Signal to process, stop was processed */
#define	NULLSIG	 sigmask(SIGKILL) /* non-zero out of bounds signal mask */

/* 
 * This signals cannot be masked (blocked).
 */
#define	CANTMASK (sigmask(SIGKILL)|sigmask(SIGSTOP)|SIG_NOT)
/*
 * These signals cannot be ignored.
 */
#define CANTIGNORE (sigmask(SIGKILL)|sigmask(SIGSTOP))
/*
 * These signals cannot be caught.
 */
#define	CANTCATCH (sigmask(SIGKILL)|sigmask(SIGSTOP)|SIG_NOT)
/*
 * These signals are affected be SIGCONT.
 */
#define	STOPS	 (sigmask(SIGSTOP)|sigmask(SIGTSTP)|sigmask(SIGTTIN)|sigmask(SIGTTOU))
/*
 * These signals can not be sent with kill.
 */
#define	CANTKILL (SIG_NOT)
/* 
 * These signals default action is to ignore the signal.
 */
#define	DEFIGNORE (sigmask(SIGCLD)|sigmask(SIGPOLL)|sigmask(SIGWINCH)|sigmask(SIGPWR))
/*

/*
 * POSIX P1003.1 job control signals
 */
#define S_JC	(sigmask(SIGCHLD)|\
		 sigmask(SIGCONT)|sigmask(SIGSTOP)|sigmask(SIGTSTP)|\
		 sigmask(SIGTTIN)|sigmask(SIGTTOU) )
/*
 * set of all POSIX standard signals .
 */
#define S_SUPPORTED ( sigmask(SIGABRT)|sigmask(SIGALRM)|sigmask(SIGFPE)|\
	sigmask(SIGHUP)|sigmask(SIGILL)|sigmask(SIGINT)|sigmask(SIGKILL)|\
	sigmask(SIGPIPE)|sigmask(SIGQUIT)|sigmask(SIGSEGV)|sigmask(SIGTERM)|\
	sigmask(SIGUSR1)|sigmask(SIGUSR2)|S_JC )

#endif /* INKERNEL */
#endif /* _POSIX_SOURCE */
#endif /* _SYS_SIGNAL_H */
