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