xref: /titanic_50/usr/src/lib/libshell/common/include/fault.h (revision 3c112a2b34403220c06c3e2fcac403358cfba168)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1982-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                  David Korn <dgk@research.att.com>                   *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 #ifndef SH_SIGBITS
22 /*
23  *	UNIX shell
24  *	S. R. Bourne
25  *	Rewritten by David Korn
26  *
27  */
28 
29 #include	<sig.h>
30 #include	<setjmp.h>
31 #include	<error.h>
32 #include	<sfio.h>
33 #include	"FEATURE/setjmp"
34 #include	"FEATURE/sigfeatures"
35 
36 
37 #ifndef SIGWINCH
38 #   ifdef SIGWIND
39 #	define SIGWINCH	SIGWIND
40 #   else
41 #	ifdef SIGWINDOW
42 #	    define SIGWINCH	SIGWINDOW
43 #	endif
44 #   endif
45 #endif
46 
47 typedef void (*SH_SIGTYPE)(int,void(*)(int));
48 
49 #define SH_FORKLIM		16	/* fork timeout interval */
50 
51 #define SH_TRAP			0200	/* bit for internal traps */
52 #define SH_ERRTRAP		0	/* trap for non-zero exit status */
53 #define SH_KEYTRAP		1	/* trap for keyboard event */
54 #define SH_DEBUGTRAP		4	/* must be last internal trap */
55 
56 #define SH_SIGBITS		8
57 #define SH_SIGFAULT		1	/* signal handler is sh_fault */
58 #define SH_SIGOFF		2	/* signal handler is SIG_IGN */
59 #define SH_SIGSET		4	/* pending signal */
60 #define SH_SIGTRAP		010	/* pending trap */
61 #define SH_SIGDONE		020	/* default is exit */
62 #define SH_SIGIGNORE		040	/* default is ingore signal */
63 #define SH_SIGINTERACTIVE	0100	/* handle interactive specially */
64 #define SH_SIGTSTP		0200	/* tstp signal received */
65 #define SH_SIGALRM		0200	/* timer alarm received */
66 #define SH_SIGTERM		SH_SIGOFF /* term signal received */
67 #define SH_SIGRUNTIME		0400	/* runtime value */
68 
69 #define SH_SIGRTMIN		0	/* sh.sigruntime[] index */
70 #define SH_SIGRTMAX		1	/* sh.sigruntime[] index */
71 
72 /*
73  * These are longjmp values
74  */
75 
76 #define SH_JMPDOT	2
77 #define SH_JMPEVAL	3
78 #define SH_JMPTRAP	4
79 #define SH_JMPIO	5
80 #define SH_JMPCMD	6
81 #define SH_JMPFUN	7
82 #define SH_JMPERRFN	8
83 #define SH_JMPSUB	9
84 #define SH_JMPERREXIT	10
85 #define SH_JMPEXIT	11
86 #define SH_JMPSCRIPT	12
87 
88 struct openlist
89 {
90 	Sfio_t	*strm;
91 	struct openlist *next;
92 };
93 
94 struct checkpt
95 {
96 	sigjmp_buf	buff;
97 	sigjmp_buf	*prev;
98 	int		topfd;
99 	int		mode;
100 	struct openlist	*olist;
101 #if (ERROR_VERSION >= 20030214L)
102 	Error_context_t err;
103 #else
104 	struct errorcontext err;
105 #endif
106 };
107 
108 #define sh_pushcontext(bp,n)	( (bp)->mode=(n) , (bp)->olist=0,  \
109 				  (bp)->topfd=sh.topfd, (bp)->prev=sh.jmplist, \
110 				  (bp)->err = *ERROR_CONTEXT_BASE, \
111 					sh.jmplist = (sigjmp_buf*)(&(bp)->buff) \
112 				)
113 #define sh_popcontext(bp)	(sh.jmplist=(bp)->prev, errorpop(&((bp)->err)))
114 
115 extern void 	sh_fault(int);
116 extern void 	sh_done(void*,int);
117 extern void 	sh_chktrap(void);
118 extern void 	sh_sigclear(int);
119 extern void 	sh_sigdone(void);
120 extern void	sh_siginit(void*);
121 extern void 	sh_sigtrap(int);
122 extern void 	sh_sigreset(int);
123 extern void 	sh_timetraps(void);
124 extern void 	*sh_timeradd(unsigned long,int ,void (*)(void*),void*);
125 extern void	timerdel(void*);
126 
127 extern const char e_alarm[];
128 
129 #endif /* !SH_SIGBITS */
130