]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/mach/hurd/i386/exc2signal.c
Update.
[thirdparty/glibc.git] / sysdeps / mach / hurd / i386 / exc2signal.c
1 /* Translate Mach exception codes into signal numbers. i386 version.
2 Copyright (C) 1991, 1992, 1994, 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #include <hurd.h>
21 #include <hurd/signal.h>
22 #include <mach/exception.h>
23
24 /* Translate the Mach exception codes, as received in an `exception_raise' RPC,
25 into a signal number and signal subcode. */
26
27 void
28 _hurd_exception2signal (struct hurd_signal_detail *detail, int *signo)
29 {
30 detail->error = 0;
31
32 switch (detail->exc)
33 {
34 default:
35 *signo = SIGIOT;
36 detail->code = detail->exc;
37 break;
38
39 case EXC_BAD_ACCESS:
40 if (detail->exc_code == KERN_PROTECTION_FAILURE)
41 *signo = SIGSEGV;
42 else
43 *signo = SIGBUS;
44 detail->code = detail->exc_subcode;
45 detail->error = detail->exc_code;
46 break;
47
48 case EXC_BAD_INSTRUCTION:
49 *signo = SIGILL;
50 if (detail->exc_code == EXC_I386_INVOP)
51 detail->code = ILL_INVOPR_FAULT;
52 else if (detail->exc_code == EXC_I386_STKFLT)
53 detail->code = ILL_STACK_FAULT;
54 else
55 detail->code = 0;
56 break;
57
58 case EXC_ARITHMETIC:
59 switch (detail->exc_code)
60 {
61 case EXC_I386_DIV: /* integer divide by zero */
62 *signo = SIGFPE;
63 detail->code = FPE_INTDIV_FAULT;
64 break;
65
66 case EXC_I386_INTO: /* integer overflow */
67 *signo = SIGFPE;
68 detail->code = FPE_INTOVF_TRAP;
69 break;
70
71 /* These aren't anywhere documented or used in Mach 3.0. */
72 case EXC_I386_NOEXT:
73 case EXC_I386_EXTOVR:
74 default:
75 *signo = SIGFPE;
76 detail->code = 0;
77 break;
78
79 case EXC_I386_EXTERR:
80 /* Subcode is the fp_status word saved by the hardware.
81 Give an error code corresponding to the first bit set. */
82 if (detail->exc_subcode & FPS_IE)
83 {
84 *signo = SIGILL;
85 detail->code = ILL_FPEOPR_FAULT;
86 }
87 else if (detail->exc_subcode & FPS_DE)
88 {
89 *signo = SIGFPE;
90 detail->code = FPE_FLTDNR_FAULT;
91 }
92 else if (detail->exc_subcode & FPS_ZE)
93 {
94 *signo = SIGFPE;
95 detail->code = FPE_FLTDIV_FAULT;
96 }
97 else if (detail->exc_subcode & FPS_OE)
98 {
99 *signo = SIGFPE;
100 detail->code = FPE_FLTOVF_FAULT;
101 }
102 else if (detail->exc_subcode & FPS_UE)
103 {
104 *signo = SIGFPE;
105 detail->code = FPE_FLTUND_FAULT;
106 }
107 else if (detail->exc_subcode & FPS_PE)
108 {
109 *signo = SIGFPE;
110 detail->code = FPE_FLTINX_FAULT;
111 }
112 else
113 {
114 *signo = SIGFPE;
115 detail->code = 0;
116 }
117 break;
118
119 /* These two can only be arithmetic exceptions if we
120 are in V86 mode, which sounds like emulation to me.
121 (See Mach 3.0 i386/trap.c.) */
122 case EXC_I386_EMERR:
123 *signo = SIGFPE;
124 detail->code = FPE_EMERR_FAULT;
125 break;
126 case EXC_I386_BOUND:
127 *signo = SIGFPE;
128 detail->code = FPE_EMBND_FAULT;
129 break;
130 }
131 break;
132
133 case EXC_EMULATION:
134 /* 3.0 doesn't give this one, why, I don't know. */
135 *signo = SIGEMT;
136 detail->code = 0;
137 break;
138
139 case EXC_SOFTWARE:
140 /* The only time we get this in Mach 3.0
141 is for an out of bounds trap. */
142 if (detail->exc_code == EXC_I386_BOUND)
143 {
144 *signo = SIGFPE;
145 detail->code = FPE_SUBRNG_FAULT;
146 }
147 else
148 {
149 *signo = SIGEMT;
150 detail->code = 0;
151 }
152 break;
153
154 case EXC_BREAKPOINT:
155 *signo = SIGTRAP;
156 if (detail->exc_code == EXC_I386_SGL)
157 detail->code = DBG_SINGLE_TRAP;
158 else if (detail->exc_code == EXC_I386_BPT)
159 detail->code = DBG_BRKPNT_FAULT;
160 else
161 detail->code = 0;
162 break;
163 }
164 }