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