1 // -*- C++ -*- ARM specific Exception handling support routines.
2 // Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 // This file is part of GCC.
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)
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.
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
18 // the Free Software Foundation, 51 Franklin Street, Fifth Floor,
19 // Boston, MA 02110-1301, USA.
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.
31 #include "unwind-cxx.h"
33 #ifdef __ARM_EABI_UNWINDER__
35 using namespace __cxxabiv1
;
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.
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__
)),
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
);
51 __cxa_exception
* xh
= __get_exception_header_from_ue(ue_header
);
52 const std::type_info
* throw_type
;
55 throw_type
= &typeid(abi::__forced_unwind
);
56 else if (foreign_exception
)
57 throw_type
= &typeid(abi::__foreign_exception
);
59 throw_type
= xh
->exceptionType
;
61 void* thrown_ptr
= *thrown_ptr_p
;
63 // Pointer types need to adjust the actual pointer, not
64 // the pointer to pointer that is the exception object.
65 // This also has the effect of passing pointer types
66 // "by value" through the __cxa_begin_catch return value.
67 if (throw_type
->__is_pointer_p())
68 thrown_ptr
= *(void**) thrown_ptr
;
70 if (catch_type
->__do_catch(throw_type
, &thrown_ptr
, 1))
72 *thrown_ptr_p
= thrown_ptr
;
74 if (typeid(*catch_type
) == typeid (typeid(void*)))
76 const __pointer_type_info
*catch_pointer_type
=
77 static_cast<const __pointer_type_info
*> (catch_type
);
78 const __pointer_type_info
*throw_pointer_type
=
79 static_cast<const __pointer_type_info
*> (throw_type
);
81 if (typeid (*catch_pointer_type
->__pointee
) != typeid (void)
82 && (*catch_pointer_type
->__pointee
!=
83 *throw_pointer_type
->__pointee
))
84 return ctm_succeeded_with_ptr_to_base
;
93 // ABI defined routine called at the start of a cleanup handler.
95 __cxa_begin_cleanup(_Unwind_Exception
* ue_header
)
97 __cxa_eh_globals
*globals
= __cxa_get_globals();
98 __cxa_exception
*header
= __get_exception_header_from_ue(ue_header
);
99 bool native
= __is_gxx_exception_class(header
->unwindHeader
.exception_class
);
104 header
->propagationCount
++;
105 // Add it to the chain if this is the first time we've seen this
107 if (header
->propagationCount
== 1)
109 header
->nextPropagatingException
= globals
->propagatingExceptions
;
110 globals
->propagatingExceptions
= header
;
115 // Remember the exception object, so end_cleanup can return it.
116 // These cannot be stacked, so we must abort if we already have
117 // a propagating exception.
118 if (globals
->propagatingExceptions
)
120 globals
->propagatingExceptions
= header
;
126 // Do the work for __cxa_end_cleanup. Returns the currently propagating
128 extern "C" _Unwind_Exception
*
129 __gnu_end_cleanup(void)
131 __cxa_exception
*header
;
132 __cxa_eh_globals
*globals
= __cxa_get_globals();
134 header
= globals
->propagatingExceptions
;
136 // Check something hasn't gone horribly wrong.
140 if (__is_gxx_exception_class(header
->unwindHeader
.exception_class
))
142 header
->propagationCount
--;
143 if (header
->propagationCount
== 0)
145 // Remove exception from chain.
146 globals
->propagatingExceptions
= header
->nextPropagatingException
;
147 header
->nextPropagatingException
= NULL
;
151 globals
->propagatingExceptions
= NULL
;
153 return &header
->unwindHeader
;
156 // Assembly wrapper to call __gnu_end_cleanup without clobbering r1-r3.
157 // Also push r4 to preserve stack alignment.
159 asm (".global __cxa_end_cleanup\n"
160 " .type __cxa_end_cleanup, \"function\"\n"
162 "__cxa_end_cleanup:\n"
163 " push\t{r1, r2, r3, r4}\n"
164 " bl\t__gnu_end_cleanup\n"
165 " pop\t{r1, r2, r3, r4}\n"
166 " bl\t_Unwind_Resume @ Never returns\n");
168 asm (".global __cxa_end_cleanup\n"
169 " .type __cxa_end_cleanup, \"function\"\n"
170 "__cxa_end_cleanup:\n"
171 " stmfd\tsp!, {r1, r2, r3, r4}\n"
172 " bl\t__gnu_end_cleanup\n"
173 " ldmfd\tsp!, {r1, r2, r3, r4}\n"
174 " bl\t_Unwind_Resume @ Never returns\n");