]>
Commit | Line | Data |
---|---|---|
2a75c0b6 | 1 | // -*- C++ -*- ARM specific Exception handling support routines. |
6d419a6e | 2 | // Copyright (C) 2004, 2005, 2008 Free Software Foundation, Inc. |
2a75c0b6 PB |
3 | // |
4 | // This file is part of GCC. | |
5 | // | |
6 | // GCC is free software; you can redistribute it and/or modify | |
7 | // it under the terms of the GNU General Public License as published by | |
8 | // the Free Software Foundation; either version 2, or (at your option) | |
9 | // any later version. | |
10 | // | |
11 | // GCC is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public License | |
17 | // along with GCC; see the file COPYING. If not, write to | |
83f51799 KC |
18 | // the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
19 | // Boston, MA 02110-1301, USA. | |
2a75c0b6 PB |
20 | |
21 | // As a special exception, you may use this file as part of a free software | |
22 | // library without restriction. Specifically, if other files instantiate | |
23 | // templates or use macros or inline functions from this file, or you compile | |
24 | // this file and link it with other files to produce an executable, this | |
25 | // file does not by itself cause the resulting executable to be covered by | |
26 | // the GNU General Public License. This exception does not however | |
27 | // invalidate any other reasons why the executable file might be covered by | |
28 | // the GNU General Public License. | |
29 | ||
30 | #include <cxxabi.h> | |
31 | #include "unwind-cxx.h" | |
32 | ||
33 | #ifdef __ARM_EABI_UNWINDER__ | |
34 | ||
35 | using namespace __cxxabiv1; | |
36 | ||
37 | ||
38 | // Given the thrown type THROW_TYPE, pointer to a variable containing a | |
39 | // pointer to the exception object THROWN_PTR_P and a type CATCH_TYPE to | |
40 | // compare against, return whether or not there is a match and if so, | |
41 | // update *THROWN_PTR_P. | |
42 | ||
43 | extern "C" __cxa_type_match_result | |
44 | __cxa_type_match(_Unwind_Exception* ue_header, | |
45 | const std::type_info* catch_type, | |
46 | bool is_reference __attribute__((__unused__)), | |
47 | void** thrown_ptr_p) | |
48 | { | |
e32717fc JM |
49 | bool forced_unwind = __is_gxx_forced_unwind_class(ue_header->exception_class); |
50 | bool foreign_exception = !forced_unwind && !__is_gxx_exception_class(ue_header->exception_class); | |
6d419a6e PC |
51 | bool dependent_exception = |
52 | __is_dependent_exception(ue_header->exception_class); | |
2a75c0b6 | 53 | __cxa_exception* xh = __get_exception_header_from_ue(ue_header); |
6d419a6e | 54 | __cxa_dependent_exception *dx = __get_dependent_exception_from_ue(ue_header); |
ddb4f387 RE |
55 | const std::type_info* throw_type; |
56 | ||
e32717fc JM |
57 | if (forced_unwind) |
58 | throw_type = &typeid(abi::__forced_unwind); | |
59 | else if (foreign_exception) | |
ddb4f387 | 60 | throw_type = &typeid(abi::__foreign_exception); |
6d419a6e PC |
61 | else if (dependent_exception) |
62 | throw_type = __get_exception_header_from_obj | |
63 | (dx->primaryException)->exceptionType; | |
ddb4f387 RE |
64 | else |
65 | throw_type = xh->exceptionType; | |
66 | ||
2a75c0b6 PB |
67 | void* thrown_ptr = *thrown_ptr_p; |
68 | ||
69 | // Pointer types need to adjust the actual pointer, not | |
70 | // the pointer to pointer that is the exception object. | |
71 | // This also has the effect of passing pointer types | |
72 | // "by value" through the __cxa_begin_catch return value. | |
73 | if (throw_type->__is_pointer_p()) | |
74 | thrown_ptr = *(void**) thrown_ptr; | |
75 | ||
76 | if (catch_type->__do_catch(throw_type, &thrown_ptr, 1)) | |
77 | { | |
78 | *thrown_ptr_p = thrown_ptr; | |
79 | ||
80 | if (typeid(*catch_type) == typeid (typeid(void*))) | |
81 | { | |
82 | const __pointer_type_info *catch_pointer_type = | |
83 | static_cast<const __pointer_type_info *> (catch_type); | |
84 | const __pointer_type_info *throw_pointer_type = | |
85 | static_cast<const __pointer_type_info *> (throw_type); | |
86 | ||
87 | if (typeid (*catch_pointer_type->__pointee) != typeid (void) | |
88 | && (*catch_pointer_type->__pointee != | |
89 | *throw_pointer_type->__pointee)) | |
90 | return ctm_succeeded_with_ptr_to_base; | |
91 | } | |
92 | ||
93 | return ctm_succeeded; | |
94 | } | |
95 | ||
96 | return ctm_failed; | |
97 | } | |
98 | ||
99 | // ABI defined routine called at the start of a cleanup handler. | |
100 | extern "C" bool | |
101 | __cxa_begin_cleanup(_Unwind_Exception* ue_header) | |
102 | { | |
103 | __cxa_eh_globals *globals = __cxa_get_globals(); | |
104 | __cxa_exception *header = __get_exception_header_from_ue(ue_header); | |
1dcca6f3 | 105 | bool native = __is_gxx_exception_class(header->unwindHeader.exception_class); |
2a75c0b6 | 106 | |
1dcca6f3 NS |
107 | |
108 | if (native) | |
2a75c0b6 | 109 | { |
1dcca6f3 NS |
110 | header->propagationCount++; |
111 | // Add it to the chain if this is the first time we've seen this | |
112 | // exception. | |
113 | if (header->propagationCount == 1) | |
114 | { | |
115 | header->nextPropagatingException = globals->propagatingExceptions; | |
116 | globals->propagatingExceptions = header; | |
117 | } | |
2a75c0b6 | 118 | } |
1dcca6f3 | 119 | else |
2a75c0b6 | 120 | { |
1dcca6f3 NS |
121 | // Remember the exception object, so end_cleanup can return it. |
122 | // These cannot be stacked, so we must abort if we already have | |
123 | // a propagating exception. | |
124 | if (globals->propagatingExceptions) | |
125 | std::terminate (); | |
2a75c0b6 PB |
126 | globals->propagatingExceptions = header; |
127 | } | |
1dcca6f3 | 128 | |
c82f61c5 | 129 | return true; |
2a75c0b6 PB |
130 | } |
131 | ||
132 | // Do the work for __cxa_end_cleanup. Returns the currently propagating | |
133 | // exception object. | |
134 | extern "C" _Unwind_Exception * | |
135 | __gnu_end_cleanup(void) | |
136 | { | |
137 | __cxa_exception *header; | |
138 | __cxa_eh_globals *globals = __cxa_get_globals(); | |
139 | ||
140 | header = globals->propagatingExceptions; | |
141 | ||
142 | // Check something hasn't gone horribly wrong. | |
143 | if (!header) | |
144 | std::terminate(); | |
145 | ||
1dcca6f3 | 146 | if (__is_gxx_exception_class(header->unwindHeader.exception_class)) |
2a75c0b6 | 147 | { |
1dcca6f3 NS |
148 | header->propagationCount--; |
149 | if (header->propagationCount == 0) | |
150 | { | |
151 | // Remove exception from chain. | |
152 | globals->propagatingExceptions = header->nextPropagatingException; | |
153 | header->nextPropagatingException = NULL; | |
154 | } | |
2a75c0b6 | 155 | } |
1dcca6f3 NS |
156 | else |
157 | globals->propagatingExceptions = NULL; | |
158 | ||
2a75c0b6 PB |
159 | return &header->unwindHeader; |
160 | } | |
161 | ||
162 | // Assembly wrapper to call __gnu_end_cleanup without clobbering r1-r3. | |
163 | // Also push r4 to preserve stack alignment. | |
164 | #ifdef __thumb__ | |
165 | asm (".global __cxa_end_cleanup\n" | |
166 | " .type __cxa_end_cleanup, \"function\"\n" | |
167 | " .thumb_func\n" | |
168 | "__cxa_end_cleanup:\n" | |
169 | " push\t{r1, r2, r3, r4}\n" | |
170 | " bl\t__gnu_end_cleanup\n" | |
171 | " pop\t{r1, r2, r3, r4}\n" | |
172 | " bl\t_Unwind_Resume @ Never returns\n"); | |
173 | #else | |
174 | asm (".global __cxa_end_cleanup\n" | |
175 | " .type __cxa_end_cleanup, \"function\"\n" | |
176 | "__cxa_end_cleanup:\n" | |
177 | " stmfd\tsp!, {r1, r2, r3, r4}\n" | |
178 | " bl\t__gnu_end_cleanup\n" | |
179 | " ldmfd\tsp!, {r1, r2, r3, r4}\n" | |
180 | " bl\t_Unwind_Resume @ Never returns\n"); | |
181 | #endif | |
182 | ||
183 | #endif |