Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: signals.c | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | /* | |
24 | * Copyright 2006 Sun Microsystems, Inc. All rights reserved. | |
25 | * Use is subject to license terms. | |
26 | */ | |
27 | #pragma ident "@(#)signals.c 1.6 06/08/31 SMI" | |
28 | ||
29 | /* | |
30 | * Signal handling code | |
31 | */ | |
32 | ||
33 | #include <stdio.h> | |
34 | #include <stdlib.h> | |
35 | #include <unistd.h> | |
36 | #include <errno.h> | |
37 | #include <sys/time.h> | |
38 | #include <sys/types.h> | |
39 | #include <signal.h> | |
40 | #include <stropts.h> | |
41 | #include <poll.h> | |
42 | ||
43 | #include "basics.h" | |
44 | ||
45 | /* | |
46 | * Definitions | |
47 | */ | |
48 | ||
49 | static void exit_handler(int); | |
50 | static void hup_handler(int); | |
51 | static void poll_handler(int); | |
52 | ||
53 | /* | |
54 | * Default signal settings for the main LWP | |
55 | */ | |
56 | ||
57 | void | |
58 | init_signals() | |
59 | { | |
60 | /* | |
61 | * typically these two delivered as a result of terminal | |
62 | * attach/detach | |
63 | */ | |
64 | signal(SIGPOLL, poll_handler); | |
65 | signal(SIGHUP, hup_handler); | |
66 | /* standard signals */ | |
67 | signal(SIGINT, exit_handler); | |
68 | signal(SIGILL, exit_handler); | |
69 | signal(SIGIOT, exit_handler); | |
70 | signal(SIGFPE, exit_handler); | |
71 | #if !defined(HOST_OS_LINUX) | |
72 | signal(SIGEMT, exit_handler); | |
73 | #endif | |
74 | signal(SIGBUS, exit_handler); | |
75 | signal(SIGSEGV, exit_handler); | |
76 | signal(SIGSYS, exit_handler); | |
77 | } | |
78 | ||
79 | ||
80 | static void | |
81 | exit_handler(int sig) | |
82 | { | |
83 | char *strp; | |
84 | ||
85 | switch (sig) { | |
86 | case SIGINT: | |
87 | strp = "Interrupted"; | |
88 | break; | |
89 | case SIGILL: | |
90 | strp = "Illegal Instruction"; | |
91 | break; | |
92 | case SIGTRAP: | |
93 | strp = "Trace Trap"; | |
94 | break; | |
95 | case SIGSEGV: | |
96 | strp = "Segmentation violation"; | |
97 | break; | |
98 | case SIGBUS: | |
99 | strp = "Bus Error"; | |
100 | break; | |
101 | case SIGIOT: | |
102 | strp = "IOT Trap"; | |
103 | break; | |
104 | #if !defined(HOST_OS_LINUX) | |
105 | case SIGEMT: | |
106 | strp = "EMT Trap"; | |
107 | break; | |
108 | #endif | |
109 | case SIGFPE: | |
110 | strp = "Numeric Exception (Divide by Zero?)"; | |
111 | break; | |
112 | case SIGSYS: | |
113 | strp = "Bad System Call Argument"; | |
114 | break; | |
115 | default: | |
116 | strp = NULL; | |
117 | break; | |
118 | } | |
119 | ||
120 | fflush(stdout); | |
121 | ||
122 | if (strp != NULL) | |
123 | fprintf(stderr, "SIGNAL: %s\n", strp); | |
124 | else | |
125 | fprintf(stderr, "SIGNAL: Unknown signal %d\n", sig); | |
126 | ||
127 | fflush(stderr); | |
128 | ||
129 | exit(1); | |
130 | } | |
131 | ||
132 | ||
133 | static void | |
134 | hup_handler(int sig) | |
135 | { | |
136 | fprintf(stderr, "Hup !\n"); | |
137 | } | |
138 | ||
139 | ||
140 | static void | |
141 | poll_handler(int sig) | |
142 | { | |
143 | fprintf(stderr, "Poll !\n"); | |
144 | } |