annotate libgcc/unwind-arm-common.inc @ 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 /* Common unwinding code for ARM EABI and C6X.
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 Contributed by Paul Brook
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is free software; you can redistribute it and/or modify it
kono
parents:
diff changeset
6 under the terms of the GNU General Public License as published by the
kono
parents:
diff changeset
7 Free Software Foundation; either version 3, or (at your option) any
kono
parents:
diff changeset
8 later version.
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 This file is distributed in the hope that it will be useful, but
kono
parents:
diff changeset
11 WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
kono
parents:
diff changeset
13 General Public License for more details.
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
16 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
17 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
20 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
22 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 #include "tconfig.h"
kono
parents:
diff changeset
25 #include "tsystem.h"
kono
parents:
diff changeset
26 #include "unwind.h"
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 /* Used for SystemTap unwinder probe. */
kono
parents:
diff changeset
29 #ifdef HAVE_SYS_SDT_H
kono
parents:
diff changeset
30 #include <sys/sdt.h>
kono
parents:
diff changeset
31 #endif
kono
parents:
diff changeset
32
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
33 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
34 /* Load r7 with rt_sigreturn value. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
35 #define ARM_SET_R7_RT_SIGRETURN 0xe3a070ad /* mov r7, #0xad */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
36 #define THUMB2_SET_R7_RT_SIGRETURN 0x07adf04f /* mov.w r7, #0xad */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
37
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
38 /* FDPIC jump to restorer sequence. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
39 #define FDPIC_LDR_R12_WITH_FUNCDESC 0xe59fc004 /* ldr r12, [pc, #4] */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
40 #define FDPIC_LDR_R9_WITH_GOT 0xe59c9004 /* ldr r9, [r12, #4] */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
41 #define FDPIC_LDR_PC_WITH_RESTORER 0xe59cf000 /* ldr pc, [r12] */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
42 #define FDPIC_T2_LDR_R12_WITH_FUNCDESC 0xc008f8df /* ldr.w r12, [pc, #8] */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
43 #define FDPIC_T2_LDR_R9_WITH_GOT 0x9004f8dc /* ldr.w r9, [r12, #4] */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
44 #define FDPIC_T2_LDR_PC_WITH_RESTORER 0xf000f8dc /* ldr.w pc, [r12] */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
45 #define FDPIC_FUNCDESC_OFFSET 12
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
46
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
47 /* Signal frame offsets. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
48 #define ARM_NEW_RT_SIGFRAME_UCONTEXT 0x80
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
49 #define ARM_UCONTEXT_SIGCONTEXT 0x14
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
50 #define ARM_SIGCONTEXT_R0 0xc
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
51 #endif
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
52
111
kono
parents:
diff changeset
53 /* We add a prototype for abort here to avoid creating a dependency on
kono
parents:
diff changeset
54 target headers. */
kono
parents:
diff changeset
55 extern void abort (void);
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 /* Definitions for C++ runtime support routines. We make these weak
kono
parents:
diff changeset
58 declarations to avoid pulling in libsupc++ unnecessarily. */
kono
parents:
diff changeset
59 typedef unsigned char bool;
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 typedef struct _ZSt9type_info type_info; /* This names C++ type_info type */
kono
parents:
diff changeset
62 enum __cxa_type_match_result
kono
parents:
diff changeset
63 {
kono
parents:
diff changeset
64 ctm_failed = 0,
kono
parents:
diff changeset
65 ctm_succeeded = 1,
kono
parents:
diff changeset
66 ctm_succeeded_with_ptr_to_base = 2
kono
parents:
diff changeset
67 };
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 void __attribute__((weak)) __cxa_call_unexpected(_Unwind_Control_Block *ucbp);
kono
parents:
diff changeset
70 bool __attribute__((weak)) __cxa_begin_cleanup(_Unwind_Control_Block *ucbp);
kono
parents:
diff changeset
71 enum __cxa_type_match_result __attribute__((weak)) __cxa_type_match
kono
parents:
diff changeset
72 (_Unwind_Control_Block *ucbp, const type_info *rttip,
kono
parents:
diff changeset
73 bool is_reference, void **matched_object);
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 _Unwind_Ptr __attribute__((weak))
kono
parents:
diff changeset
76 __gnu_Unwind_Find_exidx (_Unwind_Ptr, int *);
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 #define EXIDX_CANTUNWIND 1
kono
parents:
diff changeset
79 #define uint32_highbit (((_uw) 1) << 31)
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 #define UCB_FORCED_STOP_FN(ucbp) ((ucbp)->unwinder_cache.reserved1)
kono
parents:
diff changeset
82 #define UCB_PR_ADDR(ucbp) ((ucbp)->unwinder_cache.reserved2)
kono
parents:
diff changeset
83 #define UCB_SAVED_CALLSITE_ADDR(ucbp) ((ucbp)->unwinder_cache.reserved3)
kono
parents:
diff changeset
84 #define UCB_FORCED_STOP_ARG(ucbp) ((ucbp)->unwinder_cache.reserved4)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
85 #define UCB_PR_GOT(ucbp) ((ucbp)->unwinder_cache.reserved5)
111
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 /* Unwind descriptors. */
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 typedef struct
kono
parents:
diff changeset
90 {
kono
parents:
diff changeset
91 _uw16 length;
kono
parents:
diff changeset
92 _uw16 offset;
kono
parents:
diff changeset
93 } EHT16;
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 typedef struct
kono
parents:
diff changeset
96 {
kono
parents:
diff changeset
97 _uw length;
kono
parents:
diff changeset
98 _uw offset;
kono
parents:
diff changeset
99 } EHT32;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 /* An exception index table entry. */
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 typedef struct __EIT_entry
kono
parents:
diff changeset
104 {
kono
parents:
diff changeset
105 _uw fnoffset;
kono
parents:
diff changeset
106 _uw content;
kono
parents:
diff changeset
107 } __EIT_entry;
kono
parents:
diff changeset
108
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
109 #ifdef __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
110
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
111 /* Only used in FDPIC case. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
112 struct funcdesc_t
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
113 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
114 unsigned int ptr;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
115 unsigned int got;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
116 };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
117 #endif
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
118
111
kono
parents:
diff changeset
119 /* Assembly helper functions. */
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 /* Restore core register state. Never returns. */
kono
parents:
diff changeset
122 void __attribute__((noreturn)) restore_core_regs (struct core_regs *);
kono
parents:
diff changeset
123
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 /* Restore coprocessor state after phase1 unwinding. */
kono
parents:
diff changeset
126 static void restore_non_core_regs (phase1_vrs * vrs);
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 /* A better way to do this would probably be to compare the absolute address
kono
parents:
diff changeset
129 with a segment relative relocation of the same symbol. */
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 extern int __text_start;
kono
parents:
diff changeset
132 extern int __data_start;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 /* The exception index table location. */
kono
parents:
diff changeset
135 extern __EIT_entry __exidx_start;
kono
parents:
diff changeset
136 extern __EIT_entry __exidx_end;
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 /* Core unwinding functions. */
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 /* Calculate the address encoded by a 31-bit self-relative offset at address
kono
parents:
diff changeset
141 P. */
kono
parents:
diff changeset
142 static inline _uw selfrel_offset31 (const _uw *p);
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 static _uw __gnu_unwind_get_pr_addr (int idx);
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 static void _Unwind_DebugHook (void *, void *)
kono
parents:
diff changeset
147 __attribute__ ((__noinline__, __used__, __noclone__));
kono
parents:
diff changeset
148
kono
parents:
diff changeset
149 /* This function is called during unwinding. It is intended as a hook
kono
parents:
diff changeset
150 for a debugger to intercept exceptions. CFA is the CFA of the
kono
parents:
diff changeset
151 target frame. HANDLER is the PC to which control will be
kono
parents:
diff changeset
152 transferred. */
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 static void
kono
parents:
diff changeset
155 _Unwind_DebugHook (void *cfa __attribute__ ((__unused__)),
kono
parents:
diff changeset
156 void *handler __attribute__ ((__unused__)))
kono
parents:
diff changeset
157 {
kono
parents:
diff changeset
158 /* We only want to use stap probes starting with v3. Earlier
kono
parents:
diff changeset
159 versions added too much startup cost. */
kono
parents:
diff changeset
160 #if defined (HAVE_SYS_SDT_H) && defined (STAP_PROBE2) && _SDT_NOTE_TYPE >= 3
kono
parents:
diff changeset
161 STAP_PROBE2 (libgcc, unwind, cfa, handler);
kono
parents:
diff changeset
162 #else
kono
parents:
diff changeset
163 asm ("");
kono
parents:
diff changeset
164 #endif
kono
parents:
diff changeset
165 }
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 /* This is a wrapper to be called when we need to restore core registers.
kono
parents:
diff changeset
168 It will call `_Unwind_DebugHook' before restoring the registers, thus
kono
parents:
diff changeset
169 making it possible to intercept and debug exceptions.
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 When calling `_Unwind_DebugHook', the first argument (the CFA) is zero
kono
parents:
diff changeset
172 because we are not interested in it. However, it must be there (even
kono
parents:
diff changeset
173 being zero) because GDB expects to find it when using the probe. */
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 #define uw_restore_core_regs(TARGET, CORE) \
kono
parents:
diff changeset
176 do \
kono
parents:
diff changeset
177 { \
kono
parents:
diff changeset
178 void *handler = __builtin_frob_return_addr ((void *) VRS_PC (TARGET)); \
kono
parents:
diff changeset
179 _Unwind_DebugHook (0, handler); \
kono
parents:
diff changeset
180 restore_core_regs (CORE); \
kono
parents:
diff changeset
181 } \
kono
parents:
diff changeset
182 while (0)
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 /* Perform a binary search for RETURN_ADDRESS in TABLE. The table contains
kono
parents:
diff changeset
185 NREC entries. */
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 static const __EIT_entry *
kono
parents:
diff changeset
188 search_EIT_table (const __EIT_entry * table, int nrec, _uw return_address)
kono
parents:
diff changeset
189 {
kono
parents:
diff changeset
190 _uw next_fn;
kono
parents:
diff changeset
191 _uw this_fn;
kono
parents:
diff changeset
192 int n, left, right;
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 if (nrec == 0)
kono
parents:
diff changeset
195 return (__EIT_entry *) 0;
kono
parents:
diff changeset
196
kono
parents:
diff changeset
197 left = 0;
kono
parents:
diff changeset
198 right = nrec - 1;
kono
parents:
diff changeset
199
kono
parents:
diff changeset
200 while (1)
kono
parents:
diff changeset
201 {
kono
parents:
diff changeset
202 n = (left + right) / 2;
kono
parents:
diff changeset
203 this_fn = selfrel_offset31 (&table[n].fnoffset);
kono
parents:
diff changeset
204 if (n != nrec - 1)
kono
parents:
diff changeset
205 next_fn = selfrel_offset31 (&table[n + 1].fnoffset) - 1;
kono
parents:
diff changeset
206 else
kono
parents:
diff changeset
207 next_fn = (_uw)0 - 1;
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 if (return_address < this_fn)
kono
parents:
diff changeset
210 {
kono
parents:
diff changeset
211 if (n == left)
kono
parents:
diff changeset
212 return (__EIT_entry *) 0;
kono
parents:
diff changeset
213 right = n - 1;
kono
parents:
diff changeset
214 }
kono
parents:
diff changeset
215 else if (return_address <= next_fn)
kono
parents:
diff changeset
216 return &table[n];
kono
parents:
diff changeset
217 else
kono
parents:
diff changeset
218 left = n + 1;
kono
parents:
diff changeset
219 }
kono
parents:
diff changeset
220 }
kono
parents:
diff changeset
221
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
222 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
223 /* VFP is not restored, but this is sufficient to allow unwinding. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
224 static _Unwind_Reason_Code
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
225 __gnu_personality_sigframe_fdpic (_Unwind_State state,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
226 _Unwind_Control_Block *ucbp,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
227 _Unwind_Context *context)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
228 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
229 unsigned int sp;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
230 unsigned int pc;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
231 unsigned int funcdesc;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
232 unsigned int handler;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
233 unsigned int first_handler_instruction;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
234 int i;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
235
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
236 _Unwind_VRS_Get (context, _UVRSC_CORE, R_SP, _UVRSD_UINT32, &sp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
237 _Unwind_VRS_Get (context, _UVRSC_CORE, R_PC, _UVRSD_UINT32, &pc);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
238
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
239 funcdesc = *(unsigned int *)((pc & ~1) + FDPIC_FUNCDESC_OFFSET);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
240 handler = *(unsigned int *)(funcdesc);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
241 first_handler_instruction = *(unsigned int *)(handler & ~1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
242
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
243 /* Adjust SP to point to the start of registers according to
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
244 signal type. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
245 if (first_handler_instruction == ARM_SET_R7_RT_SIGRETURN
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
246 || first_handler_instruction == THUMB2_SET_R7_RT_SIGRETURN)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
247 sp += ARM_NEW_RT_SIGFRAME_UCONTEXT
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
248 + ARM_UCONTEXT_SIGCONTEXT
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
249 + ARM_SIGCONTEXT_R0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
250 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
251 sp += ARM_UCONTEXT_SIGCONTEXT
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
252 + ARM_SIGCONTEXT_R0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
253 /* Restore regs saved on stack by the kernel. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
254 for (i = 0; i < 16; i++)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
255 _Unwind_VRS_Set (context, _UVRSC_CORE, i, _UVRSD_UINT32, sp + 4 * i);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
256
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
257 return _URC_CONTINUE_UNWIND;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
258 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
259 #endif
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
260
111
kono
parents:
diff changeset
261 /* Find the exception index table eintry for the given address.
kono
parents:
diff changeset
262 Fill in the relevant fields of the UCB.
kono
parents:
diff changeset
263 Returns _URC_FAILURE if an error occurred, _URC_OK on success. */
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 static _Unwind_Reason_Code
kono
parents:
diff changeset
266 get_eit_entry (_Unwind_Control_Block *ucbp, _uw return_address)
kono
parents:
diff changeset
267 {
kono
parents:
diff changeset
268 const __EIT_entry * eitp;
kono
parents:
diff changeset
269 int nrec;
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 /* The return address is the address of the instruction following the
kono
parents:
diff changeset
272 call instruction (plus one in thumb mode). If this was the last
kono
parents:
diff changeset
273 instruction in the function the address will lie in the following
kono
parents:
diff changeset
274 function. Subtract 2 from the address so that it points within the call
kono
parents:
diff changeset
275 instruction itself. */
kono
parents:
diff changeset
276 return_address -= 2;
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 if (__gnu_Unwind_Find_exidx)
kono
parents:
diff changeset
279 {
kono
parents:
diff changeset
280 eitp = (const __EIT_entry *) __gnu_Unwind_Find_exidx (return_address,
kono
parents:
diff changeset
281 &nrec);
kono
parents:
diff changeset
282 if (!eitp)
kono
parents:
diff changeset
283 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
284 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
285 /* If we are unwinding a signal handler then perhaps we have
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
286 reached a trampoline. Try to detect jump to restorer
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
287 sequence. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
288 _uw *pc = (_uw *)((return_address+2) & ~1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
289 if ((pc[0] == FDPIC_LDR_R12_WITH_FUNCDESC
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
290 && pc[1] == FDPIC_LDR_R9_WITH_GOT
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
291 && pc[2] == FDPIC_LDR_PC_WITH_RESTORER)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
292 || (pc[0] == FDPIC_T2_LDR_R12_WITH_FUNCDESC
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
293 && pc[1] == FDPIC_T2_LDR_R9_WITH_GOT
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
294 && pc[2] == FDPIC_T2_LDR_PC_WITH_RESTORER))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
295 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
296 struct funcdesc_t *funcdesc
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
297 = (struct funcdesc_t *) &__gnu_personality_sigframe_fdpic;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
298
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
299 UCB_PR_ADDR (ucbp) = funcdesc->ptr;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
300 UCB_PR_GOT (ucbp) = funcdesc->got;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
301
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
302 return _URC_OK;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
303 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
304 #endif
111
kono
parents:
diff changeset
305 UCB_PR_ADDR (ucbp) = 0;
kono
parents:
diff changeset
306 return _URC_FAILURE;
kono
parents:
diff changeset
307 }
kono
parents:
diff changeset
308 }
kono
parents:
diff changeset
309 else
kono
parents:
diff changeset
310 {
kono
parents:
diff changeset
311 eitp = &__exidx_start;
kono
parents:
diff changeset
312 nrec = &__exidx_end - &__exidx_start;
kono
parents:
diff changeset
313 }
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 eitp = search_EIT_table (eitp, nrec, return_address);
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 if (!eitp)
kono
parents:
diff changeset
318 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
319 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
320 /* If we are unwinding a signal handler then perhaps we have
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
321 reached a trampoline. Try to detect jump to restorer
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
322 sequence. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
323 _uw *pc = (_uw *)((return_address+2) & ~1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
324 if ((pc[0] == FDPIC_LDR_R12_WITH_FUNCDESC
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
325 && pc[1] == FDPIC_LDR_R9_WITH_GOT
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
326 && pc[2] == FDPIC_LDR_PC_WITH_RESTORER)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
327 || (pc[0] == FDPIC_T2_LDR_R12_WITH_FUNCDESC
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
328 && pc[1] == FDPIC_T2_LDR_R9_WITH_GOT
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
329 && pc[2] == FDPIC_T2_LDR_PC_WITH_RESTORER))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
330 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
331 struct funcdesc_t *funcdesc
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
332 = (struct funcdesc_t *) &__gnu_personality_sigframe_fdpic;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
333
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
334 UCB_PR_ADDR (ucbp) = funcdesc->ptr;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
335 UCB_PR_GOT (ucbp) = funcdesc->got;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
336
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
337 return _URC_OK;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
338 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
339 #endif
111
kono
parents:
diff changeset
340 UCB_PR_ADDR (ucbp) = 0;
kono
parents:
diff changeset
341 return _URC_FAILURE;
kono
parents:
diff changeset
342 }
kono
parents:
diff changeset
343 ucbp->pr_cache.fnstart = selfrel_offset31 (&eitp->fnoffset);
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 /* Can this frame be unwound at all? */
kono
parents:
diff changeset
346 if (eitp->content == EXIDX_CANTUNWIND)
kono
parents:
diff changeset
347 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
348 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
349 /* If we are unwinding a signal handler then perhaps we have
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
350 reached a trampoline. Try to detect jump to restorer
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
351 sequence. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
352 _uw *pc = (_uw *)((return_address+2) & ~1);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
353 if ((pc[0] == FDPIC_LDR_R12_WITH_FUNCDESC
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
354 && pc[1] == FDPIC_LDR_R9_WITH_GOT
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
355 && pc[2] == FDPIC_LDR_PC_WITH_RESTORER)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
356 || (pc[0] == FDPIC_T2_LDR_R12_WITH_FUNCDESC
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
357 && pc[1] == FDPIC_T2_LDR_R9_WITH_GOT
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
358 && pc[2] == FDPIC_T2_LDR_PC_WITH_RESTORER))
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
359 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
360 struct funcdesc_t *funcdesc
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
361 = (struct funcdesc_t *) &__gnu_personality_sigframe_fdpic;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
362
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
363 UCB_PR_ADDR (ucbp) = funcdesc->ptr;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
364 UCB_PR_GOT (ucbp) = funcdesc->got;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
365
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
366 return _URC_OK;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
367 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
368 #endif
111
kono
parents:
diff changeset
369 UCB_PR_ADDR (ucbp) = 0;
kono
parents:
diff changeset
370 return _URC_END_OF_STACK;
kono
parents:
diff changeset
371 }
kono
parents:
diff changeset
372
kono
parents:
diff changeset
373 /* Obtain the address of the "real" __EHT_Header word. */
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 if (eitp->content & uint32_highbit)
kono
parents:
diff changeset
376 {
kono
parents:
diff changeset
377 /* It is immediate data. */
kono
parents:
diff changeset
378 ucbp->pr_cache.ehtp = (_Unwind_EHT_Header *)&eitp->content;
kono
parents:
diff changeset
379 ucbp->pr_cache.additional = 1;
kono
parents:
diff changeset
380 }
kono
parents:
diff changeset
381 else
kono
parents:
diff changeset
382 {
kono
parents:
diff changeset
383 /* The low 31 bits of the content field are a self-relative
kono
parents:
diff changeset
384 offset to an _Unwind_EHT_Entry structure. */
kono
parents:
diff changeset
385 ucbp->pr_cache.ehtp =
kono
parents:
diff changeset
386 (_Unwind_EHT_Header *) selfrel_offset31 (&eitp->content);
kono
parents:
diff changeset
387 ucbp->pr_cache.additional = 0;
kono
parents:
diff changeset
388 }
kono
parents:
diff changeset
389
kono
parents:
diff changeset
390 /* Discover the personality routine address. */
kono
parents:
diff changeset
391 if (*ucbp->pr_cache.ehtp & (1u << 31))
kono
parents:
diff changeset
392 {
kono
parents:
diff changeset
393 /* One of the predefined standard routines. */
kono
parents:
diff changeset
394 _uw idx = (*(_uw *) ucbp->pr_cache.ehtp >> 24) & 0xf;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
395 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
396 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
397 struct funcdesc_t *funcdesc
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
398 = (struct funcdesc_t *) __gnu_unwind_get_pr_addr (idx);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
399 if (funcdesc)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
400 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
401 UCB_PR_ADDR (ucbp) = funcdesc->ptr;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
402 UCB_PR_GOT (ucbp) = funcdesc->got;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
403 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
404 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
405 UCB_PR_ADDR (ucbp) = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
406 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
407 #else
111
kono
parents:
diff changeset
408 UCB_PR_ADDR (ucbp) = __gnu_unwind_get_pr_addr (idx);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
409 #endif
111
kono
parents:
diff changeset
410 if (UCB_PR_ADDR (ucbp) == 0)
kono
parents:
diff changeset
411 {
kono
parents:
diff changeset
412 /* Failed */
kono
parents:
diff changeset
413 return _URC_FAILURE;
kono
parents:
diff changeset
414 }
kono
parents:
diff changeset
415 }
kono
parents:
diff changeset
416 else
kono
parents:
diff changeset
417 {
kono
parents:
diff changeset
418 /* Execute region offset to PR */
kono
parents:
diff changeset
419 UCB_PR_ADDR (ucbp) = selfrel_offset31 (ucbp->pr_cache.ehtp);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
420 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
421 UCB_PR_GOT (ucbp)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
422 = (unsigned int) _Unwind_gnu_Find_got ((_Unwind_Ptr) UCB_PR_ADDR (ucbp));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
423 #endif
111
kono
parents:
diff changeset
424 }
kono
parents:
diff changeset
425 return _URC_OK;
kono
parents:
diff changeset
426 }
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 /* Perform phase2 unwinding. VRS is the initial virtual register state. */
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 static void __attribute__((noreturn))
kono
parents:
diff changeset
432 unwind_phase2 (_Unwind_Control_Block * ucbp, phase2_vrs * vrs)
kono
parents:
diff changeset
433 {
kono
parents:
diff changeset
434 _Unwind_Reason_Code pr_result;
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 do
kono
parents:
diff changeset
437 {
kono
parents:
diff changeset
438 /* Find the entry for this routine. */
kono
parents:
diff changeset
439 if (get_eit_entry (ucbp, VRS_PC(vrs)) != _URC_OK)
kono
parents:
diff changeset
440 abort ();
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 UCB_SAVED_CALLSITE_ADDR (ucbp) = VRS_PC(vrs);
kono
parents:
diff changeset
443
kono
parents:
diff changeset
444 /* Call the pr to decide what to do. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
445 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
446 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
447 volatile struct funcdesc_t funcdesc;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
448 funcdesc.ptr = UCB_PR_ADDR (ucbp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
449 funcdesc.got = UCB_PR_GOT (ucbp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
450 pr_result = ((personality_routine) &funcdesc)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
451 (_US_UNWIND_FRAME_STARTING, ucbp, (_Unwind_Context *) vrs);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
452 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
453 #else
111
kono
parents:
diff changeset
454 pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
kono
parents:
diff changeset
455 (_US_UNWIND_FRAME_STARTING, ucbp, (_Unwind_Context *) vrs);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
456 #endif
111
kono
parents:
diff changeset
457 }
kono
parents:
diff changeset
458 while (pr_result == _URC_CONTINUE_UNWIND);
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 if (pr_result != _URC_INSTALL_CONTEXT)
kono
parents:
diff changeset
461 abort();
kono
parents:
diff changeset
462
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
463 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
464 /* r9 could have been lost due to PLT jump. Restore correct value. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
465 vrs->core.r[FDPIC_REGNUM] = _Unwind_gnu_Find_got (VRS_PC (vrs));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
466 #endif
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
467
111
kono
parents:
diff changeset
468 uw_restore_core_regs (vrs, &vrs->core);
kono
parents:
diff changeset
469 }
kono
parents:
diff changeset
470
kono
parents:
diff changeset
471 /* Perform phase2 forced unwinding. */
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 static _Unwind_Reason_Code
kono
parents:
diff changeset
474 unwind_phase2_forced (_Unwind_Control_Block *ucbp, phase2_vrs *entry_vrs,
kono
parents:
diff changeset
475 int resuming)
kono
parents:
diff changeset
476 {
kono
parents:
diff changeset
477 _Unwind_Stop_Fn stop_fn = (_Unwind_Stop_Fn) UCB_FORCED_STOP_FN (ucbp);
kono
parents:
diff changeset
478 void *stop_arg = (void *)UCB_FORCED_STOP_ARG (ucbp);
kono
parents:
diff changeset
479 _Unwind_Reason_Code pr_result = 0;
kono
parents:
diff changeset
480 /* We use phase1_vrs here even though we do not demand save, for the
kono
parents:
diff changeset
481 prev_sp field. */
kono
parents:
diff changeset
482 phase1_vrs saved_vrs, next_vrs;
kono
parents:
diff changeset
483
kono
parents:
diff changeset
484 /* Save the core registers. */
kono
parents:
diff changeset
485 saved_vrs.core = entry_vrs->core;
kono
parents:
diff changeset
486 /* We don't need to demand-save the non-core registers, because we
kono
parents:
diff changeset
487 unwind in a single pass. */
kono
parents:
diff changeset
488 saved_vrs.demand_save_flags = 0;
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 /* Unwind until we reach a propagation barrier. */
kono
parents:
diff changeset
491 do
kono
parents:
diff changeset
492 {
kono
parents:
diff changeset
493 _Unwind_State action;
kono
parents:
diff changeset
494 _Unwind_Reason_Code entry_code;
kono
parents:
diff changeset
495 _Unwind_Reason_Code stop_code;
kono
parents:
diff changeset
496
kono
parents:
diff changeset
497 /* Find the entry for this routine. */
kono
parents:
diff changeset
498 entry_code = get_eit_entry (ucbp, VRS_PC (&saved_vrs));
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 if (resuming)
kono
parents:
diff changeset
501 {
kono
parents:
diff changeset
502 action = _US_UNWIND_FRAME_RESUME | _US_FORCE_UNWIND;
kono
parents:
diff changeset
503 resuming = 0;
kono
parents:
diff changeset
504 }
kono
parents:
diff changeset
505 else
kono
parents:
diff changeset
506 action = _US_UNWIND_FRAME_STARTING | _US_FORCE_UNWIND;
kono
parents:
diff changeset
507
kono
parents:
diff changeset
508 if (entry_code == _URC_OK)
kono
parents:
diff changeset
509 {
kono
parents:
diff changeset
510 UCB_SAVED_CALLSITE_ADDR (ucbp) = VRS_PC (&saved_vrs);
kono
parents:
diff changeset
511
kono
parents:
diff changeset
512 next_vrs = saved_vrs;
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 /* Call the pr to decide what to do. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
515 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
516 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
517 volatile struct funcdesc_t funcdesc;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
518 funcdesc.ptr = UCB_PR_ADDR (ucbp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
519 funcdesc.got = UCB_PR_GOT (ucbp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
520 pr_result = ((personality_routine) &funcdesc)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
521 (action, ucbp, (void *) &next_vrs);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
522 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
523 #else
111
kono
parents:
diff changeset
524 pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
kono
parents:
diff changeset
525 (action, ucbp, (void *) &next_vrs);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
526 #endif
111
kono
parents:
diff changeset
527
kono
parents:
diff changeset
528 saved_vrs.prev_sp = VRS_SP (&next_vrs);
kono
parents:
diff changeset
529 }
kono
parents:
diff changeset
530 else
kono
parents:
diff changeset
531 {
kono
parents:
diff changeset
532 /* Treat any failure as the end of unwinding, to cope more
kono
parents:
diff changeset
533 gracefully with missing EH information. Mixed EH and
kono
parents:
diff changeset
534 non-EH within one object will usually result in failure,
kono
parents:
diff changeset
535 because the .ARM.exidx tables do not indicate the end
kono
parents:
diff changeset
536 of the code to which they apply; but mixed EH and non-EH
kono
parents:
diff changeset
537 shared objects should return an unwind failure at the
kono
parents:
diff changeset
538 entry of a non-EH shared object. */
kono
parents:
diff changeset
539 action |= _US_END_OF_STACK;
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 saved_vrs.prev_sp = VRS_SP (&saved_vrs);
kono
parents:
diff changeset
542 }
kono
parents:
diff changeset
543
kono
parents:
diff changeset
544 stop_code = stop_fn (1, action, ucbp->exception_class, ucbp,
kono
parents:
diff changeset
545 (void *)&saved_vrs, stop_arg);
kono
parents:
diff changeset
546 if (stop_code != _URC_NO_REASON)
kono
parents:
diff changeset
547 return _URC_FAILURE;
kono
parents:
diff changeset
548
kono
parents:
diff changeset
549 if (entry_code != _URC_OK)
kono
parents:
diff changeset
550 return entry_code;
kono
parents:
diff changeset
551
kono
parents:
diff changeset
552 saved_vrs = next_vrs;
kono
parents:
diff changeset
553 }
kono
parents:
diff changeset
554 while (pr_result == _URC_CONTINUE_UNWIND);
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 if (pr_result != _URC_INSTALL_CONTEXT)
kono
parents:
diff changeset
557 {
kono
parents:
diff changeset
558 /* Some sort of failure has occurred in the pr and probably the
kono
parents:
diff changeset
559 pr returned _URC_FAILURE. */
kono
parents:
diff changeset
560 return _URC_FAILURE;
kono
parents:
diff changeset
561 }
kono
parents:
diff changeset
562
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
563 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
564 /* r9 could have been lost due to PLT jump. Restore correct value. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
565 saved_vrs.core.r[FDPIC_REGNUM] = _Unwind_gnu_Find_got (VRS_PC (&saved_vrs));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
566 #endif
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
567
111
kono
parents:
diff changeset
568 uw_restore_core_regs (&saved_vrs, &saved_vrs.core);
kono
parents:
diff changeset
569 }
kono
parents:
diff changeset
570
kono
parents:
diff changeset
571 /* This is a very limited implementation of _Unwind_GetCFA. It returns
kono
parents:
diff changeset
572 the stack pointer as it is about to be unwound, and is only valid
kono
parents:
diff changeset
573 while calling the stop function during forced unwinding. If the
kono
parents:
diff changeset
574 current personality routine result is going to run a cleanup, this
kono
parents:
diff changeset
575 will not be the CFA; but when the frame is really unwound, it will
kono
parents:
diff changeset
576 be. */
kono
parents:
diff changeset
577
kono
parents:
diff changeset
578 _Unwind_Word
kono
parents:
diff changeset
579 _Unwind_GetCFA (_Unwind_Context *context)
kono
parents:
diff changeset
580 {
kono
parents:
diff changeset
581 return ((phase1_vrs *) context)->prev_sp;
kono
parents:
diff changeset
582 }
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 /* Perform phase1 unwinding. UCBP is the exception being thrown, and
kono
parents:
diff changeset
585 entry_VRS is the register state on entry to _Unwind_RaiseException. */
kono
parents:
diff changeset
586
kono
parents:
diff changeset
587 _Unwind_Reason_Code
kono
parents:
diff changeset
588 __gnu_Unwind_RaiseException (_Unwind_Control_Block *, phase2_vrs *);
kono
parents:
diff changeset
589
kono
parents:
diff changeset
590 _Unwind_Reason_Code
kono
parents:
diff changeset
591 __gnu_Unwind_RaiseException (_Unwind_Control_Block * ucbp,
kono
parents:
diff changeset
592 phase2_vrs * entry_vrs)
kono
parents:
diff changeset
593 {
kono
parents:
diff changeset
594 phase1_vrs saved_vrs;
kono
parents:
diff changeset
595 _Unwind_Reason_Code pr_result;
kono
parents:
diff changeset
596
kono
parents:
diff changeset
597 /* Set the pc to the call site. */
kono
parents:
diff changeset
598 VRS_PC (entry_vrs) = VRS_RETURN(entry_vrs);
kono
parents:
diff changeset
599
kono
parents:
diff changeset
600 /* Save the core registers. */
kono
parents:
diff changeset
601 saved_vrs.core = entry_vrs->core;
kono
parents:
diff changeset
602 /* Set demand-save flags. */
kono
parents:
diff changeset
603 saved_vrs.demand_save_flags = ~(_uw) 0;
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 /* Unwind until we reach a propagation barrier. */
kono
parents:
diff changeset
606 do
kono
parents:
diff changeset
607 {
kono
parents:
diff changeset
608 /* Find the entry for this routine. */
kono
parents:
diff changeset
609 if (get_eit_entry (ucbp, VRS_PC (&saved_vrs)) != _URC_OK)
kono
parents:
diff changeset
610 return _URC_FAILURE;
kono
parents:
diff changeset
611
kono
parents:
diff changeset
612 /* Call the pr to decide what to do. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
613 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
614 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
615 volatile struct funcdesc_t funcdesc;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
616 funcdesc.ptr = UCB_PR_ADDR (ucbp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
617 funcdesc.got = UCB_PR_GOT (ucbp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
618 pr_result = ((personality_routine) &funcdesc)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
619 (_US_VIRTUAL_UNWIND_FRAME, ucbp, (void *) &saved_vrs);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
620 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
621 #else
111
kono
parents:
diff changeset
622 pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
kono
parents:
diff changeset
623 (_US_VIRTUAL_UNWIND_FRAME, ucbp, (void *) &saved_vrs);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
624 #endif
111
kono
parents:
diff changeset
625 }
kono
parents:
diff changeset
626 while (pr_result == _URC_CONTINUE_UNWIND);
kono
parents:
diff changeset
627
kono
parents:
diff changeset
628 /* We've unwound as far as we want to go, so restore the original
kono
parents:
diff changeset
629 register state. */
kono
parents:
diff changeset
630 restore_non_core_regs (&saved_vrs);
kono
parents:
diff changeset
631 if (pr_result != _URC_HANDLER_FOUND)
kono
parents:
diff changeset
632 {
kono
parents:
diff changeset
633 /* Some sort of failure has occurred in the pr and probably the
kono
parents:
diff changeset
634 pr returned _URC_FAILURE. */
kono
parents:
diff changeset
635 return _URC_FAILURE;
kono
parents:
diff changeset
636 }
kono
parents:
diff changeset
637
kono
parents:
diff changeset
638 unwind_phase2 (ucbp, entry_vrs);
kono
parents:
diff changeset
639 }
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 /* Resume unwinding after a cleanup has been run. UCBP is the exception
kono
parents:
diff changeset
642 being thrown and ENTRY_VRS is the register state on entry to
kono
parents:
diff changeset
643 _Unwind_Resume. */
kono
parents:
diff changeset
644 _Unwind_Reason_Code
kono
parents:
diff changeset
645 __gnu_Unwind_ForcedUnwind (_Unwind_Control_Block *,
kono
parents:
diff changeset
646 _Unwind_Stop_Fn, void *, phase2_vrs *);
kono
parents:
diff changeset
647
kono
parents:
diff changeset
648 _Unwind_Reason_Code
kono
parents:
diff changeset
649 __gnu_Unwind_ForcedUnwind (_Unwind_Control_Block *ucbp,
kono
parents:
diff changeset
650 _Unwind_Stop_Fn stop_fn, void *stop_arg,
kono
parents:
diff changeset
651 phase2_vrs *entry_vrs)
kono
parents:
diff changeset
652 {
kono
parents:
diff changeset
653 UCB_FORCED_STOP_FN (ucbp) = (_uw) stop_fn;
kono
parents:
diff changeset
654 UCB_FORCED_STOP_ARG (ucbp) = (_uw) stop_arg;
kono
parents:
diff changeset
655
kono
parents:
diff changeset
656 /* Set the pc to the call site. */
kono
parents:
diff changeset
657 VRS_PC (entry_vrs) = VRS_RETURN(entry_vrs);
kono
parents:
diff changeset
658
kono
parents:
diff changeset
659 return unwind_phase2_forced (ucbp, entry_vrs, 0);
kono
parents:
diff changeset
660 }
kono
parents:
diff changeset
661
kono
parents:
diff changeset
662 _Unwind_Reason_Code
kono
parents:
diff changeset
663 __gnu_Unwind_Resume (_Unwind_Control_Block *, phase2_vrs *);
kono
parents:
diff changeset
664
kono
parents:
diff changeset
665 _Unwind_Reason_Code
kono
parents:
diff changeset
666 __gnu_Unwind_Resume (_Unwind_Control_Block * ucbp, phase2_vrs * entry_vrs)
kono
parents:
diff changeset
667 {
kono
parents:
diff changeset
668 _Unwind_Reason_Code pr_result;
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 /* Recover the saved address. */
kono
parents:
diff changeset
671 VRS_PC (entry_vrs) = UCB_SAVED_CALLSITE_ADDR (ucbp);
kono
parents:
diff changeset
672
kono
parents:
diff changeset
673 if (UCB_FORCED_STOP_FN (ucbp))
kono
parents:
diff changeset
674 {
kono
parents:
diff changeset
675 unwind_phase2_forced (ucbp, entry_vrs, 1);
kono
parents:
diff changeset
676
kono
parents:
diff changeset
677 /* We can't return failure at this point. */
kono
parents:
diff changeset
678 abort ();
kono
parents:
diff changeset
679 }
kono
parents:
diff changeset
680
kono
parents:
diff changeset
681 /* Call the cached PR. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
682 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
683 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
684 volatile struct funcdesc_t funcdesc;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
685 funcdesc.ptr = UCB_PR_ADDR (ucbp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
686 funcdesc.got = UCB_PR_GOT (ucbp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
687 pr_result = ((personality_routine) &funcdesc)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
688 (_US_UNWIND_FRAME_RESUME, ucbp, (_Unwind_Context *) entry_vrs);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
689 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
690 #else
111
kono
parents:
diff changeset
691 pr_result = ((personality_routine) UCB_PR_ADDR (ucbp))
kono
parents:
diff changeset
692 (_US_UNWIND_FRAME_RESUME, ucbp, (_Unwind_Context *) entry_vrs);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
693 #endif
111
kono
parents:
diff changeset
694
kono
parents:
diff changeset
695 switch (pr_result)
kono
parents:
diff changeset
696 {
kono
parents:
diff changeset
697 case _URC_INSTALL_CONTEXT:
kono
parents:
diff changeset
698 /* Upload the registers to enter the landing pad. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
699 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
700 /* r9 could have been lost due to PLT jump. Restore correct value. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
701 entry_vrs->core.r[FDPIC_REGNUM] = _Unwind_gnu_Find_got (VRS_PC (entry_vrs));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
702 #endif
111
kono
parents:
diff changeset
703 uw_restore_core_regs (entry_vrs, &entry_vrs->core);
kono
parents:
diff changeset
704
kono
parents:
diff changeset
705 case _URC_CONTINUE_UNWIND:
kono
parents:
diff changeset
706 /* Continue unwinding the next frame. */
kono
parents:
diff changeset
707 unwind_phase2 (ucbp, entry_vrs);
kono
parents:
diff changeset
708
kono
parents:
diff changeset
709 default:
kono
parents:
diff changeset
710 abort ();
kono
parents:
diff changeset
711 }
kono
parents:
diff changeset
712 }
kono
parents:
diff changeset
713
kono
parents:
diff changeset
714 _Unwind_Reason_Code
kono
parents:
diff changeset
715 __gnu_Unwind_Resume_or_Rethrow (_Unwind_Control_Block *, phase2_vrs *);
kono
parents:
diff changeset
716
kono
parents:
diff changeset
717 _Unwind_Reason_Code
kono
parents:
diff changeset
718 __gnu_Unwind_Resume_or_Rethrow (_Unwind_Control_Block * ucbp,
kono
parents:
diff changeset
719 phase2_vrs * entry_vrs)
kono
parents:
diff changeset
720 {
kono
parents:
diff changeset
721 if (!UCB_FORCED_STOP_FN (ucbp))
kono
parents:
diff changeset
722 return __gnu_Unwind_RaiseException (ucbp, entry_vrs);
kono
parents:
diff changeset
723
kono
parents:
diff changeset
724 /* Set the pc to the call site. */
kono
parents:
diff changeset
725 VRS_PC (entry_vrs) = VRS_RETURN (entry_vrs);
kono
parents:
diff changeset
726 /* Continue unwinding the next frame. */
kono
parents:
diff changeset
727 return unwind_phase2_forced (ucbp, entry_vrs, 0);
kono
parents:
diff changeset
728 }
kono
parents:
diff changeset
729
kono
parents:
diff changeset
730 /* Clean up an exception object when unwinding is complete. */
kono
parents:
diff changeset
731 void
kono
parents:
diff changeset
732 _Unwind_Complete (_Unwind_Control_Block * ucbp __attribute__((unused)))
kono
parents:
diff changeset
733 {
kono
parents:
diff changeset
734 }
kono
parents:
diff changeset
735
kono
parents:
diff changeset
736
kono
parents:
diff changeset
737 /* Free an exception. */
kono
parents:
diff changeset
738
kono
parents:
diff changeset
739 void
kono
parents:
diff changeset
740 _Unwind_DeleteException (_Unwind_Exception * exc)
kono
parents:
diff changeset
741 {
kono
parents:
diff changeset
742 if (exc->exception_cleanup)
kono
parents:
diff changeset
743 (*exc->exception_cleanup) (_URC_FOREIGN_EXCEPTION_CAUGHT, exc);
kono
parents:
diff changeset
744 }
kono
parents:
diff changeset
745
kono
parents:
diff changeset
746
kono
parents:
diff changeset
747 /* Perform stack backtrace through unwind data. */
kono
parents:
diff changeset
748 _Unwind_Reason_Code
kono
parents:
diff changeset
749 __gnu_Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument,
kono
parents:
diff changeset
750 phase2_vrs * entry_vrs);
kono
parents:
diff changeset
751 _Unwind_Reason_Code
kono
parents:
diff changeset
752 __gnu_Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument,
kono
parents:
diff changeset
753 phase2_vrs * entry_vrs)
kono
parents:
diff changeset
754 {
kono
parents:
diff changeset
755 phase1_vrs saved_vrs;
kono
parents:
diff changeset
756 _Unwind_Reason_Code code;
kono
parents:
diff changeset
757
kono
parents:
diff changeset
758 _Unwind_Control_Block ucb;
kono
parents:
diff changeset
759 _Unwind_Control_Block *ucbp = &ucb;
kono
parents:
diff changeset
760
kono
parents:
diff changeset
761 /* Set the pc to the call site. */
kono
parents:
diff changeset
762 VRS_PC (entry_vrs) = VRS_RETURN (entry_vrs);
kono
parents:
diff changeset
763
kono
parents:
diff changeset
764 /* Save the core registers. */
kono
parents:
diff changeset
765 saved_vrs.core = entry_vrs->core;
kono
parents:
diff changeset
766 /* Set demand-save flags. */
kono
parents:
diff changeset
767 saved_vrs.demand_save_flags = ~(_uw) 0;
kono
parents:
diff changeset
768
kono
parents:
diff changeset
769 do
kono
parents:
diff changeset
770 {
kono
parents:
diff changeset
771 /* Find the entry for this routine. */
kono
parents:
diff changeset
772 if (get_eit_entry (ucbp, VRS_PC (&saved_vrs)) != _URC_OK)
kono
parents:
diff changeset
773 {
kono
parents:
diff changeset
774 code = _URC_FAILURE;
kono
parents:
diff changeset
775 break;
kono
parents:
diff changeset
776 }
kono
parents:
diff changeset
777
kono
parents:
diff changeset
778 /* The dwarf unwinder assumes the context structure holds things
kono
parents:
diff changeset
779 like the function and LSDA pointers. The ARM implementation
kono
parents:
diff changeset
780 caches these in the exception header (UCB). To avoid
kono
parents:
diff changeset
781 rewriting everything we make the virtual IP register point at
kono
parents:
diff changeset
782 the UCB. */
kono
parents:
diff changeset
783 _Unwind_SetGR((_Unwind_Context *)&saved_vrs, UNWIND_POINTER_REG, (_Unwind_Ptr) ucbp);
kono
parents:
diff changeset
784
kono
parents:
diff changeset
785 /* Call trace function. */
kono
parents:
diff changeset
786 if ((*trace) ((_Unwind_Context *) &saved_vrs, trace_argument)
kono
parents:
diff changeset
787 != _URC_NO_REASON)
kono
parents:
diff changeset
788 {
kono
parents:
diff changeset
789 code = _URC_FAILURE;
kono
parents:
diff changeset
790 break;
kono
parents:
diff changeset
791 }
kono
parents:
diff changeset
792
kono
parents:
diff changeset
793 /* Call the pr to decide what to do. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
794 #if __FDPIC__
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
795 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
796 volatile struct funcdesc_t funcdesc;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
797 funcdesc.ptr = UCB_PR_ADDR (ucbp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
798 funcdesc.got = UCB_PR_GOT (ucbp);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
799 code = ((personality_routine) &funcdesc)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
800 (_US_VIRTUAL_UNWIND_FRAME | _US_FORCE_UNWIND,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
801 ucbp, (void *) &saved_vrs);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
802 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
803 #else
111
kono
parents:
diff changeset
804 code = ((personality_routine) UCB_PR_ADDR (ucbp))
kono
parents:
diff changeset
805 (_US_VIRTUAL_UNWIND_FRAME | _US_FORCE_UNWIND,
kono
parents:
diff changeset
806 ucbp, (void *) &saved_vrs);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
807 #endif
111
kono
parents:
diff changeset
808 }
kono
parents:
diff changeset
809 while (code != _URC_END_OF_STACK
kono
parents:
diff changeset
810 && code != _URC_FAILURE);
kono
parents:
diff changeset
811
kono
parents:
diff changeset
812 restore_non_core_regs (&saved_vrs);
kono
parents:
diff changeset
813 return code;
kono
parents:
diff changeset
814 }
kono
parents:
diff changeset
815
kono
parents:
diff changeset
816
kono
parents:
diff changeset
817 /* Common implementation for ARM ABI defined personality routines.
kono
parents:
diff changeset
818 ID is the index of the personality routine, other arguments are as defined
kono
parents:
diff changeset
819 by __aeabi_unwind_cpp_pr{0,1,2}. */
kono
parents:
diff changeset
820
kono
parents:
diff changeset
821 static _Unwind_Reason_Code
kono
parents:
diff changeset
822 __gnu_unwind_pr_common (_Unwind_State state,
kono
parents:
diff changeset
823 _Unwind_Control_Block *ucbp,
kono
parents:
diff changeset
824 _Unwind_Context *context,
kono
parents:
diff changeset
825 int id)
kono
parents:
diff changeset
826 {
kono
parents:
diff changeset
827 __gnu_unwind_state uws;
kono
parents:
diff changeset
828 _uw *data;
kono
parents:
diff changeset
829 _uw offset;
kono
parents:
diff changeset
830 _uw len;
kono
parents:
diff changeset
831 _uw rtti_count;
kono
parents:
diff changeset
832 int phase2_call_unexpected_after_unwind = 0;
kono
parents:
diff changeset
833 int in_range = 0;
kono
parents:
diff changeset
834 int forced_unwind = state & _US_FORCE_UNWIND;
kono
parents:
diff changeset
835
kono
parents:
diff changeset
836 state &= _US_ACTION_MASK;
kono
parents:
diff changeset
837
kono
parents:
diff changeset
838 data = (_uw *) ucbp->pr_cache.ehtp;
kono
parents:
diff changeset
839 uws.data = *(data++);
kono
parents:
diff changeset
840 uws.next = data;
kono
parents:
diff changeset
841 if (id == 0)
kono
parents:
diff changeset
842 {
kono
parents:
diff changeset
843 uws.data <<= 8;
kono
parents:
diff changeset
844 uws.words_left = 0;
kono
parents:
diff changeset
845 uws.bytes_left = 3;
kono
parents:
diff changeset
846 }
kono
parents:
diff changeset
847 else if (id < 3)
kono
parents:
diff changeset
848 {
kono
parents:
diff changeset
849 uws.words_left = (uws.data >> 16) & 0xff;
kono
parents:
diff changeset
850 uws.data <<= 16;
kono
parents:
diff changeset
851 uws.bytes_left = 2;
kono
parents:
diff changeset
852 data += uws.words_left;
kono
parents:
diff changeset
853 }
kono
parents:
diff changeset
854
kono
parents:
diff changeset
855 /* Restore the saved pointer. */
kono
parents:
diff changeset
856 if (state == _US_UNWIND_FRAME_RESUME)
kono
parents:
diff changeset
857 data = (_uw *) ucbp->cleanup_cache.bitpattern[0];
kono
parents:
diff changeset
858
kono
parents:
diff changeset
859 if ((ucbp->pr_cache.additional & 1) == 0)
kono
parents:
diff changeset
860 {
kono
parents:
diff changeset
861 /* Process descriptors. */
kono
parents:
diff changeset
862 while (*data)
kono
parents:
diff changeset
863 {
kono
parents:
diff changeset
864 _uw addr;
kono
parents:
diff changeset
865 _uw fnstart;
kono
parents:
diff changeset
866
kono
parents:
diff changeset
867 if (id == 2)
kono
parents:
diff changeset
868 {
kono
parents:
diff changeset
869 len = ((EHT32 *) data)->length;
kono
parents:
diff changeset
870 offset = ((EHT32 *) data)->offset;
kono
parents:
diff changeset
871 data += 2;
kono
parents:
diff changeset
872 }
kono
parents:
diff changeset
873 else
kono
parents:
diff changeset
874 {
kono
parents:
diff changeset
875 len = ((EHT16 *) data)->length;
kono
parents:
diff changeset
876 offset = ((EHT16 *) data)->offset;
kono
parents:
diff changeset
877 data++;
kono
parents:
diff changeset
878 }
kono
parents:
diff changeset
879
kono
parents:
diff changeset
880 fnstart = ucbp->pr_cache.fnstart + (offset & ~1);
kono
parents:
diff changeset
881 addr = _Unwind_GetGR (context, R_PC);
kono
parents:
diff changeset
882 in_range = (fnstart <= addr && addr < fnstart + (len & ~1));
kono
parents:
diff changeset
883
kono
parents:
diff changeset
884 switch (((offset & 1) << 1) | (len & 1))
kono
parents:
diff changeset
885 {
kono
parents:
diff changeset
886 case 0:
kono
parents:
diff changeset
887 /* Cleanup. */
kono
parents:
diff changeset
888 if (state != _US_VIRTUAL_UNWIND_FRAME
kono
parents:
diff changeset
889 && in_range)
kono
parents:
diff changeset
890 {
kono
parents:
diff changeset
891 /* Cleanup in range, and we are running cleanups. */
kono
parents:
diff changeset
892 _uw lp;
kono
parents:
diff changeset
893
kono
parents:
diff changeset
894 /* Landing pad address is 31-bit pc-relative offset. */
kono
parents:
diff changeset
895 lp = selfrel_offset31 (data);
kono
parents:
diff changeset
896 data++;
kono
parents:
diff changeset
897 /* Save the exception data pointer. */
kono
parents:
diff changeset
898 ucbp->cleanup_cache.bitpattern[0] = (_uw) data;
kono
parents:
diff changeset
899 if (!__cxa_begin_cleanup (ucbp))
kono
parents:
diff changeset
900 return _URC_FAILURE;
kono
parents:
diff changeset
901 /* Setup the VRS to enter the landing pad. */
kono
parents:
diff changeset
902 _Unwind_SetGR (context, R_PC, lp);
kono
parents:
diff changeset
903 return _URC_INSTALL_CONTEXT;
kono
parents:
diff changeset
904 }
kono
parents:
diff changeset
905 /* Cleanup not in range, or we are in stage 1. */
kono
parents:
diff changeset
906 data++;
kono
parents:
diff changeset
907 break;
kono
parents:
diff changeset
908
kono
parents:
diff changeset
909 case 1:
kono
parents:
diff changeset
910 /* Catch handler. */
kono
parents:
diff changeset
911 if (state == _US_VIRTUAL_UNWIND_FRAME)
kono
parents:
diff changeset
912 {
kono
parents:
diff changeset
913 if (in_range)
kono
parents:
diff changeset
914 {
kono
parents:
diff changeset
915 /* Check for a barrier. */
kono
parents:
diff changeset
916 _uw rtti;
kono
parents:
diff changeset
917 bool is_reference = (data[0] & uint32_highbit) != 0;
kono
parents:
diff changeset
918 void *matched;
kono
parents:
diff changeset
919 enum __cxa_type_match_result match_type;
kono
parents:
diff changeset
920
kono
parents:
diff changeset
921 /* Check for no-throw areas. */
kono
parents:
diff changeset
922 if (data[1] == (_uw) -2)
kono
parents:
diff changeset
923 return _URC_FAILURE;
kono
parents:
diff changeset
924
kono
parents:
diff changeset
925 /* The thrown object immediately follows the ECB. */
kono
parents:
diff changeset
926 matched = (void *)(ucbp + 1);
kono
parents:
diff changeset
927 if (data[1] != (_uw) -1)
kono
parents:
diff changeset
928 {
kono
parents:
diff changeset
929 /* Match a catch specification. */
kono
parents:
diff changeset
930 rtti = _Unwind_decode_typeinfo_ptr (0,
kono
parents:
diff changeset
931 (_uw) &data[1]);
kono
parents:
diff changeset
932 match_type = __cxa_type_match (ucbp,
kono
parents:
diff changeset
933 (type_info *) rtti,
kono
parents:
diff changeset
934 is_reference,
kono
parents:
diff changeset
935 &matched);
kono
parents:
diff changeset
936 }
kono
parents:
diff changeset
937 else
kono
parents:
diff changeset
938 match_type = ctm_succeeded;
kono
parents:
diff changeset
939
kono
parents:
diff changeset
940 if (match_type)
kono
parents:
diff changeset
941 {
kono
parents:
diff changeset
942 ucbp->barrier_cache.sp =
kono
parents:
diff changeset
943 _Unwind_GetGR (context, R_SP);
kono
parents:
diff changeset
944 // ctm_succeeded_with_ptr_to_base really
kono
parents:
diff changeset
945 // means _c_t_m indirected the pointer
kono
parents:
diff changeset
946 // object. We have to reconstruct the
kono
parents:
diff changeset
947 // additional pointer layer by using a temporary.
kono
parents:
diff changeset
948 if (match_type == ctm_succeeded_with_ptr_to_base)
kono
parents:
diff changeset
949 {
kono
parents:
diff changeset
950 ucbp->barrier_cache.bitpattern[2]
kono
parents:
diff changeset
951 = (_uw) matched;
kono
parents:
diff changeset
952 ucbp->barrier_cache.bitpattern[0]
kono
parents:
diff changeset
953 = (_uw) &ucbp->barrier_cache.bitpattern[2];
kono
parents:
diff changeset
954 }
kono
parents:
diff changeset
955 else
kono
parents:
diff changeset
956 ucbp->barrier_cache.bitpattern[0] = (_uw) matched;
kono
parents:
diff changeset
957 ucbp->barrier_cache.bitpattern[1] = (_uw) data;
kono
parents:
diff changeset
958 return _URC_HANDLER_FOUND;
kono
parents:
diff changeset
959 }
kono
parents:
diff changeset
960 }
kono
parents:
diff changeset
961 /* Handler out of range, or not matched. */
kono
parents:
diff changeset
962 }
kono
parents:
diff changeset
963 else if (ucbp->barrier_cache.sp == _Unwind_GetGR (context, R_SP)
kono
parents:
diff changeset
964 && ucbp->barrier_cache.bitpattern[1] == (_uw) data)
kono
parents:
diff changeset
965 {
kono
parents:
diff changeset
966 /* Matched a previous propagation barrier. */
kono
parents:
diff changeset
967 _uw lp;
kono
parents:
diff changeset
968
kono
parents:
diff changeset
969 /* Setup for entry to the handler. */
kono
parents:
diff changeset
970 lp = selfrel_offset31 (data);
kono
parents:
diff changeset
971 _Unwind_SetGR (context, R_PC, lp);
kono
parents:
diff changeset
972 _Unwind_SetGR (context, 0, (_uw) ucbp);
kono
parents:
diff changeset
973 return _URC_INSTALL_CONTEXT;
kono
parents:
diff changeset
974 }
kono
parents:
diff changeset
975 /* Catch handler not matched. Advance to the next descriptor. */
kono
parents:
diff changeset
976 data += 2;
kono
parents:
diff changeset
977 break;
kono
parents:
diff changeset
978
kono
parents:
diff changeset
979 case 2:
kono
parents:
diff changeset
980 rtti_count = data[0] & 0x7fffffff;
kono
parents:
diff changeset
981 /* Exception specification. */
kono
parents:
diff changeset
982 if (state == _US_VIRTUAL_UNWIND_FRAME)
kono
parents:
diff changeset
983 {
kono
parents:
diff changeset
984 if (in_range && (!forced_unwind || !rtti_count))
kono
parents:
diff changeset
985 {
kono
parents:
diff changeset
986 /* Match against the exception specification. */
kono
parents:
diff changeset
987 _uw i;
kono
parents:
diff changeset
988 _uw rtti;
kono
parents:
diff changeset
989 void *matched;
kono
parents:
diff changeset
990
kono
parents:
diff changeset
991 for (i = 0; i < rtti_count; i++)
kono
parents:
diff changeset
992 {
kono
parents:
diff changeset
993 matched = (void *)(ucbp + 1);
kono
parents:
diff changeset
994 rtti = _Unwind_decode_typeinfo_ptr (0,
kono
parents:
diff changeset
995 (_uw) &data[i + 1]);
kono
parents:
diff changeset
996 if (__cxa_type_match (ucbp, (type_info *) rtti, 0,
kono
parents:
diff changeset
997 &matched))
kono
parents:
diff changeset
998 break;
kono
parents:
diff changeset
999 }
kono
parents:
diff changeset
1000
kono
parents:
diff changeset
1001 if (i == rtti_count)
kono
parents:
diff changeset
1002 {
kono
parents:
diff changeset
1003 /* Exception does not match the spec. */
kono
parents:
diff changeset
1004 ucbp->barrier_cache.sp =
kono
parents:
diff changeset
1005 _Unwind_GetGR (context, R_SP);
kono
parents:
diff changeset
1006 ucbp->barrier_cache.bitpattern[0] = (_uw) matched;
kono
parents:
diff changeset
1007 ucbp->barrier_cache.bitpattern[1] = (_uw) data;
kono
parents:
diff changeset
1008 return _URC_HANDLER_FOUND;
kono
parents:
diff changeset
1009 }
kono
parents:
diff changeset
1010 }
kono
parents:
diff changeset
1011 /* Handler out of range, or exception is permitted. */
kono
parents:
diff changeset
1012 }
kono
parents:
diff changeset
1013 else if (ucbp->barrier_cache.sp == _Unwind_GetGR (context, R_SP)
kono
parents:
diff changeset
1014 && ucbp->barrier_cache.bitpattern[1] == (_uw) data)
kono
parents:
diff changeset
1015 {
kono
parents:
diff changeset
1016 /* Matched a previous propagation barrier. */
kono
parents:
diff changeset
1017 _uw lp;
kono
parents:
diff changeset
1018 /* Record the RTTI list for __cxa_call_unexpected. */
kono
parents:
diff changeset
1019 ucbp->barrier_cache.bitpattern[1] = rtti_count;
kono
parents:
diff changeset
1020 ucbp->barrier_cache.bitpattern[2] = 0;
kono
parents:
diff changeset
1021 ucbp->barrier_cache.bitpattern[3] = 4;
kono
parents:
diff changeset
1022 ucbp->barrier_cache.bitpattern[4] = (_uw) &data[1];
kono
parents:
diff changeset
1023
kono
parents:
diff changeset
1024 if (data[0] & uint32_highbit)
kono
parents:
diff changeset
1025 {
kono
parents:
diff changeset
1026 data += rtti_count + 1;
kono
parents:
diff changeset
1027 /* Setup for entry to the handler. */
kono
parents:
diff changeset
1028 lp = selfrel_offset31 (data);
kono
parents:
diff changeset
1029 data++;
kono
parents:
diff changeset
1030 _Unwind_SetGR (context, R_PC, lp);
kono
parents:
diff changeset
1031 _Unwind_SetGR (context, 0, (_uw) ucbp);
kono
parents:
diff changeset
1032 return _URC_INSTALL_CONTEXT;
kono
parents:
diff changeset
1033 }
kono
parents:
diff changeset
1034 else
kono
parents:
diff changeset
1035 phase2_call_unexpected_after_unwind = 1;
kono
parents:
diff changeset
1036 }
kono
parents:
diff changeset
1037 if (data[0] & uint32_highbit)
kono
parents:
diff changeset
1038 data++;
kono
parents:
diff changeset
1039 data += rtti_count + 1;
kono
parents:
diff changeset
1040 break;
kono
parents:
diff changeset
1041
kono
parents:
diff changeset
1042 default:
kono
parents:
diff changeset
1043 /* Should never happen. */
kono
parents:
diff changeset
1044 return _URC_FAILURE;
kono
parents:
diff changeset
1045 }
kono
parents:
diff changeset
1046 /* Finished processing this descriptor. */
kono
parents:
diff changeset
1047 }
kono
parents:
diff changeset
1048 }
kono
parents:
diff changeset
1049
kono
parents:
diff changeset
1050 if (id >= 3)
kono
parents:
diff changeset
1051 {
kono
parents:
diff changeset
1052 /* 24-bit ecoding */
kono
parents:
diff changeset
1053 if (__gnu_unwind_24bit (context, uws.data, id == 4) != _URC_OK)
kono
parents:
diff changeset
1054 return _URC_FAILURE;
kono
parents:
diff changeset
1055 }
kono
parents:
diff changeset
1056 else
kono
parents:
diff changeset
1057 {
kono
parents:
diff changeset
1058 if (__gnu_unwind_execute (context, &uws) != _URC_OK)
kono
parents:
diff changeset
1059 return _URC_FAILURE;
kono
parents:
diff changeset
1060 }
kono
parents:
diff changeset
1061
kono
parents:
diff changeset
1062 if (phase2_call_unexpected_after_unwind)
kono
parents:
diff changeset
1063 {
kono
parents:
diff changeset
1064 /* Enter __cxa_unexpected as if called from the call site. */
kono
parents:
diff changeset
1065 _Unwind_SetGR (context, R_LR, _Unwind_GetGR (context, R_PC));
kono
parents:
diff changeset
1066 _Unwind_SetGR (context, R_PC, (_uw) &__cxa_call_unexpected);
kono
parents:
diff changeset
1067 return _URC_INSTALL_CONTEXT;
kono
parents:
diff changeset
1068 }
kono
parents:
diff changeset
1069
kono
parents:
diff changeset
1070 return _URC_CONTINUE_UNWIND;
kono
parents:
diff changeset
1071 }