annotate libstdc++-v3/libsupc++/eh_arm.cc @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // -*- C++ -*- ARM specific Exception handling support routines.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 // Copyright (C) 2004-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 //
kono
parents:
diff changeset
4 // This file is part of GCC.
kono
parents:
diff changeset
5 //
kono
parents:
diff changeset
6 // GCC is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
7 // it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
8 // the Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
9 // any later version.
kono
parents:
diff changeset
10 //
kono
parents:
diff changeset
11 // GCC is distributed in the hope that it will be useful,
kono
parents:
diff changeset
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
14 // GNU General Public License for more details.
kono
parents:
diff changeset
15 //
kono
parents:
diff changeset
16 // Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
17 // permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
18 // 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
19 //
kono
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
21 // a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
23 // <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include <cxxabi.h>
kono
parents:
diff changeset
26 #include "unwind-cxx.h"
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 #ifdef __ARM_EABI_UNWINDER__
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 using namespace __cxxabiv1;
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 // Given the thrown type THROW_TYPE, exception object UE_HEADER and a
kono
parents:
diff changeset
34 // type CATCH_TYPE to compare against, return whether or not there is
kono
parents:
diff changeset
35 // a match and if so, update *THROWN_PTR_P to point to either the
kono
parents:
diff changeset
36 // type-matched object, or in the case of a pointer type, the object
kono
parents:
diff changeset
37 // pointed to by the pointer.
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 extern "C" __cxa_type_match_result
kono
parents:
diff changeset
40 __cxa_type_match(_Unwind_Exception* ue_header,
kono
parents:
diff changeset
41 const std::type_info* catch_type,
kono
parents:
diff changeset
42 bool is_reference __attribute__((__unused__)),
kono
parents:
diff changeset
43 void** thrown_ptr_p)
kono
parents:
diff changeset
44 {
kono
parents:
diff changeset
45 bool forced_unwind
kono
parents:
diff changeset
46 = __is_gxx_forced_unwind_class(ue_header->exception_class);
kono
parents:
diff changeset
47 bool foreign_exception
kono
parents:
diff changeset
48 = !forced_unwind && !__is_gxx_exception_class(ue_header->exception_class);
kono
parents:
diff changeset
49 bool dependent_exception
kono
parents:
diff changeset
50 = __is_dependent_exception(ue_header->exception_class);
kono
parents:
diff changeset
51 __cxa_exception* xh = __get_exception_header_from_ue(ue_header);
kono
parents:
diff changeset
52 __cxa_dependent_exception *dx = __get_dependent_exception_from_ue(ue_header);
kono
parents:
diff changeset
53 const std::type_info* throw_type;
kono
parents:
diff changeset
54 void *thrown_ptr = 0;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 if (forced_unwind)
kono
parents:
diff changeset
57 throw_type = &typeid(abi::__forced_unwind);
kono
parents:
diff changeset
58 else if (foreign_exception)
kono
parents:
diff changeset
59 throw_type = &typeid(abi::__foreign_exception);
kono
parents:
diff changeset
60 else
kono
parents:
diff changeset
61 {
kono
parents:
diff changeset
62 if (dependent_exception)
kono
parents:
diff changeset
63 xh = __get_exception_header_from_obj (dx->primaryException);
kono
parents:
diff changeset
64 throw_type = xh->exceptionType;
kono
parents:
diff changeset
65 // We used to require the caller set the target of thrown_ptr_p,
kono
parents:
diff changeset
66 // but that's incorrect -- the EHABI makes no such requirement
kono
parents:
diff changeset
67 // -- and not all callers will set it. Fortunately callers that
kono
parents:
diff changeset
68 // do initialize will always pass us the value we calculate
kono
parents:
diff changeset
69 // here, so there's no backwards compatibility problem.
kono
parents:
diff changeset
70 thrown_ptr = __get_object_from_ue (ue_header);
kono
parents:
diff changeset
71 }
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 __cxa_type_match_result result = ctm_succeeded;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 // Pointer types need to adjust the actual pointer, not
kono
parents:
diff changeset
76 // the pointer to pointer that is the exception object.
kono
parents:
diff changeset
77 // This also has the effect of passing pointer types
kono
parents:
diff changeset
78 // "by value" through the __cxa_begin_catch return value.
kono
parents:
diff changeset
79 if (throw_type->__is_pointer_p())
kono
parents:
diff changeset
80 {
kono
parents:
diff changeset
81 thrown_ptr = *(void**) thrown_ptr;
kono
parents:
diff changeset
82 // We need to indicate the indirection to our caller.
kono
parents:
diff changeset
83 result = ctm_succeeded_with_ptr_to_base;
kono
parents:
diff changeset
84 }
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 if (catch_type->__do_catch(throw_type, &thrown_ptr, 1))
kono
parents:
diff changeset
87 {
kono
parents:
diff changeset
88 *thrown_ptr_p = thrown_ptr;
kono
parents:
diff changeset
89 return result;
kono
parents:
diff changeset
90 }
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 return ctm_failed;
kono
parents:
diff changeset
93 }
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 // ABI defined routine called at the start of a cleanup handler.
kono
parents:
diff changeset
96 extern "C" bool
kono
parents:
diff changeset
97 __cxa_begin_cleanup(_Unwind_Exception* ue_header)
kono
parents:
diff changeset
98 {
kono
parents:
diff changeset
99 __cxa_eh_globals *globals = __cxa_get_globals();
kono
parents:
diff changeset
100 __cxa_exception *header = __get_exception_header_from_ue(ue_header);
kono
parents:
diff changeset
101 bool native = __is_gxx_exception_class(header->unwindHeader.exception_class);
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103
kono
parents:
diff changeset
104 if (native)
kono
parents:
diff changeset
105 {
kono
parents:
diff changeset
106 header->propagationCount++;
kono
parents:
diff changeset
107 // Add it to the chain if this is the first time we've seen this
kono
parents:
diff changeset
108 // exception.
kono
parents:
diff changeset
109 if (header->propagationCount == 1)
kono
parents:
diff changeset
110 {
kono
parents:
diff changeset
111 header->nextPropagatingException = globals->propagatingExceptions;
kono
parents:
diff changeset
112 globals->propagatingExceptions = header;
kono
parents:
diff changeset
113 }
kono
parents:
diff changeset
114 }
kono
parents:
diff changeset
115 else
kono
parents:
diff changeset
116 {
kono
parents:
diff changeset
117 // Remember the exception object, so end_cleanup can return it.
kono
parents:
diff changeset
118 // These cannot be stacked, so we must abort if we already have
kono
parents:
diff changeset
119 // a propagating exception.
kono
parents:
diff changeset
120 if (globals->propagatingExceptions)
kono
parents:
diff changeset
121 std::terminate ();
kono
parents:
diff changeset
122 globals->propagatingExceptions = header;
kono
parents:
diff changeset
123 }
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 return true;
kono
parents:
diff changeset
126 }
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 // Do the work for __cxa_end_cleanup. Returns the currently propagating
kono
parents:
diff changeset
129 // exception object.
kono
parents:
diff changeset
130 extern "C" _Unwind_Exception *
kono
parents:
diff changeset
131 __gnu_end_cleanup(void)
kono
parents:
diff changeset
132 {
kono
parents:
diff changeset
133 __cxa_exception *header;
kono
parents:
diff changeset
134 __cxa_eh_globals *globals = __cxa_get_globals();
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 header = globals->propagatingExceptions;
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 // Check something hasn't gone horribly wrong.
kono
parents:
diff changeset
139 if (!header)
kono
parents:
diff changeset
140 std::terminate();
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 if (__is_gxx_exception_class(header->unwindHeader.exception_class))
kono
parents:
diff changeset
143 {
kono
parents:
diff changeset
144 header->propagationCount--;
kono
parents:
diff changeset
145 if (header->propagationCount == 0)
kono
parents:
diff changeset
146 {
kono
parents:
diff changeset
147 // Remove exception from chain.
kono
parents:
diff changeset
148 globals->propagatingExceptions = header->nextPropagatingException;
kono
parents:
diff changeset
149 header->nextPropagatingException = NULL;
kono
parents:
diff changeset
150 }
kono
parents:
diff changeset
151 }
kono
parents:
diff changeset
152 else
kono
parents:
diff changeset
153 globals->propagatingExceptions = NULL;
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 return &header->unwindHeader;
kono
parents:
diff changeset
156 }
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 #ifdef __TMS320C6X__
kono
parents:
diff changeset
159 // Assembly wrapper to call __gnu_end_cleanup without clobbering
kono
parents:
diff changeset
160 // function arguments to _Unwind_Resume.
kono
parents:
diff changeset
161 asm (".global __cxa_end_cleanup\n"
kono
parents:
diff changeset
162 " .type __cxa_end_cleanup, \"function\"\n"
kono
parents:
diff changeset
163 "__cxa_end_cleanup:\n"
kono
parents:
diff changeset
164 " stw .d2t2 B9, *B15--[10]\n"
kono
parents:
diff changeset
165 " stw .d2t2 B8, *+B15[9]\n"
kono
parents:
diff changeset
166 " stw .d2t2 B7, *+B15[8]\n"
kono
parents:
diff changeset
167 " stw .d2t2 B6, *+B15[7]\n"
kono
parents:
diff changeset
168 " stw .d2t2 B5, *+B15[6]\n"
kono
parents:
diff changeset
169 " stw .d2t2 B4, *+B15[5]\n"
kono
parents:
diff changeset
170 " stw .d2t1 A9, *+B15[4]\n"
kono
parents:
diff changeset
171 " stw .d2t1 A8, *+B15[3]\n"
kono
parents:
diff changeset
172 " stw .d2t1 A7, *+B15[2]\n"
kono
parents:
diff changeset
173 " stw .d2t1 A6, *+B15[1]\n"
kono
parents:
diff changeset
174 #ifdef _TMS320C6400_PLUS
kono
parents:
diff changeset
175 " callp .s2 (__gnu_end_cleanup), B3\n"
kono
parents:
diff changeset
176 #elif defined(_TMS320C6400)
kono
parents:
diff changeset
177 " call .s2 (__gnu_end_cleanup)\n"
kono
parents:
diff changeset
178 " addkpc .s2 1f, B3, 0\n"
kono
parents:
diff changeset
179 " nop 4\n"
kono
parents:
diff changeset
180 "1:\n"
kono
parents:
diff changeset
181 #else
kono
parents:
diff changeset
182 " call .s2 (__gnu_end_cleanup)\n"
kono
parents:
diff changeset
183 " mvkl .s2 1f, B3\n"
kono
parents:
diff changeset
184 " mvkh .s2 1f, B3\n"
kono
parents:
diff changeset
185 " nop 3\n"
kono
parents:
diff changeset
186 "1:\n"
kono
parents:
diff changeset
187 #endif
kono
parents:
diff changeset
188 " ldw .d2t1 *+B15[1], A6\n"
kono
parents:
diff changeset
189 " ldw .d2t1 *+B15[2], A7\n"
kono
parents:
diff changeset
190 " ldw .d2t1 *+B15[3], A8\n"
kono
parents:
diff changeset
191 " ldw .d2t1 *+B15[4], A9\n"
kono
parents:
diff changeset
192 " ldw .d2t2 *+B15[5], B4\n"
kono
parents:
diff changeset
193 " ldw .d2t2 *+B15[6], B5\n"
kono
parents:
diff changeset
194 " ldw .d2t2 *+B15[7], B6\n"
kono
parents:
diff changeset
195 " ldw .d2t2 *+B15[8], B7\n"
kono
parents:
diff changeset
196 " ldw .d2t2 *+B15[9], B8\n"
kono
parents:
diff changeset
197 " ldw .d2t2 *++B15[10], B9\n"
kono
parents:
diff changeset
198 " b .s2 _Unwind_Resume\n"
kono
parents:
diff changeset
199 " nop 5\n");
kono
parents:
diff changeset
200 #else
kono
parents:
diff changeset
201 // Assembly wrapper to call __gnu_end_cleanup without clobbering r1-r3.
kono
parents:
diff changeset
202 // Also push r4 to preserve stack alignment.
kono
parents:
diff changeset
203 #ifdef __thumb__
kono
parents:
diff changeset
204 asm (" .pushsection .text.__cxa_end_cleanup\n"
kono
parents:
diff changeset
205 " .global __cxa_end_cleanup\n"
kono
parents:
diff changeset
206 " .type __cxa_end_cleanup, \"function\"\n"
kono
parents:
diff changeset
207 " .thumb_func\n"
kono
parents:
diff changeset
208 "__cxa_end_cleanup:\n"
kono
parents:
diff changeset
209 " push\t{r1, r2, r3, r4}\n"
kono
parents:
diff changeset
210 " bl\t__gnu_end_cleanup\n"
kono
parents:
diff changeset
211 " pop\t{r1, r2, r3, r4}\n"
kono
parents:
diff changeset
212 " bl\t_Unwind_Resume @ Never returns\n"
kono
parents:
diff changeset
213 " .popsection\n");
kono
parents:
diff changeset
214 #else
kono
parents:
diff changeset
215 asm (" .pushsection .text.__cxa_end_cleanup\n"
kono
parents:
diff changeset
216 " .global __cxa_end_cleanup\n"
kono
parents:
diff changeset
217 " .type __cxa_end_cleanup, \"function\"\n"
kono
parents:
diff changeset
218 "__cxa_end_cleanup:\n"
kono
parents:
diff changeset
219 " stmfd\tsp!, {r1, r2, r3, r4}\n"
kono
parents:
diff changeset
220 " bl\t__gnu_end_cleanup\n"
kono
parents:
diff changeset
221 " ldmfd\tsp!, {r1, r2, r3, r4}\n"
kono
parents:
diff changeset
222 " bl\t_Unwind_Resume @ Never returns\n"
kono
parents:
diff changeset
223 " .popsection\n");
kono
parents:
diff changeset
224 #endif
kono
parents:
diff changeset
225 #endif
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 #endif