xref: /titanic_44/usr/src/lib/efcode/engine/signal.c (revision 34f9b3eef6fdadbda0a846aa4d68691ac40eace5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <signal.h>
33 #include <unistd.h>
34 
35 #include <sys/time.h>
36 #include <sys/termio.h>
37 
38 #include <fcode/private.h>
39 #include <fcode/log.h>
40 
41 static fcode_env_t *saved_envp;
42 static struct termio saved_termio;
43 
44 static void
45 process_signal(int sig, siginfo_t *sip, void *addr)
46 {
47 	/*
48 	 * Format appropriate error message, want fault addr if Bus Error
49 	 * or Segmentation Violation.
50 	 */
51 	switch (sig) {
52 	case SIGSEGV:
53 	case SIGBUS:
54 	case SIGILL:
55 	case SIGFPE:
56 		forth_abort(saved_envp, "%s: Fault Addr: 0x%08x",
57 		    strsignal(sig), sip->si_addr);
58 
59 	case SIGQUIT:
60 		ioctl(fileno(stdin), TCSETA, &saved_termio);
61 		log_message(MSG_FATAL, "SIGQUIT\n");
62 		abort();
63 
64 	case SIGINT:
65 		ioctl(fileno(stdin), TCSETA, &saved_termio);
66 		break;
67 	}
68 	forth_abort(saved_envp, strsignal(sig));
69 }
70 
71 void
72 install_handlers(fcode_env_t *env)
73 {
74 	struct sigaction sa;
75 
76 	saved_envp = env;
77 
78 	ioctl(fileno(stdin), TCGETA, &saved_termio);
79 
80 	sigemptyset(&sa.sa_mask);
81 	sa.sa_flags = SA_SIGINFO|SA_NODEFER;
82 	sa.sa_handler = 0;
83 	sa.sa_sigaction = process_signal;
84 
85 	sigaction(SIGINT, &sa, NULL);
86 	sigaction(SIGQUIT, &sa, NULL);
87 	sigaction(SIGSEGV, &sa, NULL);
88 	sigaction(SIGBUS, &sa, NULL);
89 	sigaction(SIGUSR1, &sa, NULL);
90 	sigaction(SIGFPE, &sa, NULL);
91 }
92