]>
Commit | Line | Data |
---|---|---|
28f540f4 | 1 | /* Translate Mach exception codes into signal numbers. i386 version. |
04277e02 | 2 | Copyright (C) 1991-2019 Free Software Foundation, Inc. |
478b92f0 | 3 | This file is part of the GNU C Library. |
28f540f4 | 4 | |
478b92f0 | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
28f540f4 | 9 | |
478b92f0 UD |
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 | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
28f540f4 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
28f540f4 RM |
18 | |
19 | #include <hurd.h> | |
20 | #include <hurd/signal.h> | |
21 | #include <mach/exception.h> | |
22 | ||
23 | /* Translate the Mach exception codes, as received in an `exception_raise' RPC, | |
24 | into a signal number and signal subcode. */ | |
25 | ||
26 | void | |
0e3426bb | 27 | _hurd_exception2signal (struct hurd_signal_detail *detail, int *signo) |
28f540f4 | 28 | { |
0e3426bb | 29 | detail->error = 0; |
28f540f4 | 30 | |
0e3426bb | 31 | switch (detail->exc) |
28f540f4 RM |
32 | { |
33 | default: | |
34 | *signo = SIGIOT; | |
0e3426bb | 35 | detail->code = detail->exc; |
28f540f4 | 36 | break; |
0e3426bb | 37 | |
28f540f4 | 38 | case EXC_BAD_ACCESS: |
43c6b444 MK |
39 | if (detail->exc_code == KERN_INVALID_ADDRESS |
40 | || detail->exc_code == KERN_PROTECTION_FAILURE | |
41 | || detail->exc_code == KERN_WRITE_PROTECTION_FAILURE) | |
28f540f4 RM |
42 | *signo = SIGSEGV; |
43 | else | |
44 | *signo = SIGBUS; | |
0e3426bb RM |
45 | detail->code = detail->exc_subcode; |
46 | detail->error = detail->exc_code; | |
28f540f4 RM |
47 | break; |
48 | ||
49 | case EXC_BAD_INSTRUCTION: | |
50 | *signo = SIGILL; | |
0e3426bb RM |
51 | if (detail->exc_code == EXC_I386_INVOP) |
52 | detail->code = ILL_INVOPR_FAULT; | |
53 | else if (detail->exc_code == EXC_I386_STKFLT) | |
54 | detail->code = ILL_STACK_FAULT; | |
28f540f4 | 55 | else |
0e3426bb | 56 | detail->code = 0; |
28f540f4 | 57 | break; |
0e3426bb | 58 | |
28f540f4 | 59 | case EXC_ARITHMETIC: |
0e3426bb | 60 | switch (detail->exc_code) |
28f540f4 RM |
61 | { |
62 | case EXC_I386_DIV: /* integer divide by zero */ | |
63 | *signo = SIGFPE; | |
0e3426bb | 64 | detail->code = FPE_INTDIV_FAULT; |
28f540f4 | 65 | break; |
0e3426bb | 66 | |
28f540f4 RM |
67 | case EXC_I386_INTO: /* integer overflow */ |
68 | *signo = SIGFPE; | |
0e3426bb | 69 | detail->code = FPE_INTOVF_TRAP; |
28f540f4 RM |
70 | break; |
71 | ||
72 | /* These aren't anywhere documented or used in Mach 3.0. */ | |
73 | case EXC_I386_NOEXT: | |
74 | case EXC_I386_EXTOVR: | |
75 | default: | |
76 | *signo = SIGFPE; | |
0e3426bb | 77 | detail->code = 0; |
28f540f4 RM |
78 | break; |
79 | ||
80 | case EXC_I386_EXTERR: | |
81 | /* Subcode is the fp_status word saved by the hardware. | |
82 | Give an error code corresponding to the first bit set. */ | |
0e3426bb | 83 | if (detail->exc_subcode & FPS_IE) |
28f540f4 RM |
84 | { |
85 | *signo = SIGILL; | |
0e3426bb | 86 | detail->code = ILL_FPEOPR_FAULT; |
28f540f4 | 87 | } |
0e3426bb | 88 | else if (detail->exc_subcode & FPS_DE) |
28f540f4 RM |
89 | { |
90 | *signo = SIGFPE; | |
0e3426bb | 91 | detail->code = FPE_FLTDNR_FAULT; |
28f540f4 | 92 | } |
0e3426bb | 93 | else if (detail->exc_subcode & FPS_ZE) |
28f540f4 RM |
94 | { |
95 | *signo = SIGFPE; | |
0e3426bb | 96 | detail->code = FPE_FLTDIV_FAULT; |
28f540f4 | 97 | } |
0e3426bb | 98 | else if (detail->exc_subcode & FPS_OE) |
28f540f4 RM |
99 | { |
100 | *signo = SIGFPE; | |
0e3426bb | 101 | detail->code = FPE_FLTOVF_FAULT; |
28f540f4 | 102 | } |
0e3426bb | 103 | else if (detail->exc_subcode & FPS_UE) |
28f540f4 RM |
104 | { |
105 | *signo = SIGFPE; | |
0e3426bb | 106 | detail->code = FPE_FLTUND_FAULT; |
28f540f4 | 107 | } |
0e3426bb | 108 | else if (detail->exc_subcode & FPS_PE) |
28f540f4 RM |
109 | { |
110 | *signo = SIGFPE; | |
0e3426bb | 111 | detail->code = FPE_FLTINX_FAULT; |
28f540f4 RM |
112 | } |
113 | else | |
114 | { | |
115 | *signo = SIGFPE; | |
0e3426bb | 116 | detail->code = 0; |
28f540f4 RM |
117 | } |
118 | break; | |
119 | ||
0e3426bb | 120 | /* These two can only be arithmetic exceptions if we |
28f540f4 RM |
121 | are in V86 mode, which sounds like emulation to me. |
122 | (See Mach 3.0 i386/trap.c.) */ | |
123 | case EXC_I386_EMERR: | |
124 | *signo = SIGFPE; | |
0e3426bb | 125 | detail->code = FPE_EMERR_FAULT; |
28f540f4 RM |
126 | break; |
127 | case EXC_I386_BOUND: | |
128 | *signo = SIGFPE; | |
0e3426bb | 129 | detail->code = FPE_EMBND_FAULT; |
28f540f4 RM |
130 | break; |
131 | } | |
132 | break; | |
133 | ||
0e3426bb | 134 | case EXC_EMULATION: |
28f540f4 RM |
135 | /* 3.0 doesn't give this one, why, I don't know. */ |
136 | *signo = SIGEMT; | |
0e3426bb | 137 | detail->code = 0; |
28f540f4 RM |
138 | break; |
139 | ||
140 | case EXC_SOFTWARE: | |
141 | /* The only time we get this in Mach 3.0 | |
142 | is for an out of bounds trap. */ | |
0e3426bb | 143 | if (detail->exc_code == EXC_I386_BOUND) |
28f540f4 RM |
144 | { |
145 | *signo = SIGFPE; | |
0e3426bb | 146 | detail->code = FPE_SUBRNG_FAULT; |
28f540f4 RM |
147 | } |
148 | else | |
149 | { | |
150 | *signo = SIGEMT; | |
0e3426bb | 151 | detail->code = 0; |
28f540f4 RM |
152 | } |
153 | break; | |
0e3426bb | 154 | |
28f540f4 RM |
155 | case EXC_BREAKPOINT: |
156 | *signo = SIGTRAP; | |
0e3426bb RM |
157 | if (detail->exc_code == EXC_I386_SGL) |
158 | detail->code = DBG_SINGLE_TRAP; | |
159 | else if (detail->exc_code == EXC_I386_BPT) | |
160 | detail->code = DBG_BRKPNT_FAULT; | |
28f540f4 | 161 | else |
0e3426bb | 162 | detail->code = 0; |
28f540f4 RM |
163 | break; |
164 | } | |
165 | } | |
ff297b70 | 166 | libc_hidden_def (_hurd_exception2signal) |