Deleted Added
full compact
UnwindLevel1-gcc-ext.c (288151) UnwindLevel1-gcc-ext.c (308006)
1//===--------------------- UnwindLevel1-gcc-ext.c -------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//

--- 15 unchanged lines hidden (view full) ---

24#include "unwind.h"
25
26#if _LIBUNWIND_BUILD_ZERO_COST_APIS
27
28/// Called by __cxa_rethrow().
29_LIBUNWIND_EXPORT _Unwind_Reason_Code
30_Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) {
31#if _LIBUNWIND_ARM_EHABI
1//===--------------------- UnwindLevel1-gcc-ext.c -------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//

--- 15 unchanged lines hidden (view full) ---

24#include "unwind.h"
25
26#if _LIBUNWIND_BUILD_ZERO_COST_APIS
27
28/// Called by __cxa_rethrow().
29_LIBUNWIND_EXPORT _Unwind_Reason_Code
30_Unwind_Resume_or_Rethrow(_Unwind_Exception *exception_object) {
31#if _LIBUNWIND_ARM_EHABI
32 _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld\n",
32 _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld",
33 (void *)exception_object,
34 (long)exception_object->unwinder_cache.reserved1);
35#else
33 (void *)exception_object,
34 (long)exception_object->unwinder_cache.reserved1);
35#else
36 _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld\n",
36 _LIBUNWIND_TRACE_API("_Unwind_Resume_or_Rethrow(ex_obj=%p), private_1=%ld",
37 (void *)exception_object,
38 (long)exception_object->private_1);
39#endif
40
41#if _LIBUNWIND_ARM_EHABI
42 // _Unwind_RaiseException on EHABI will always set the reserved1 field to 0,
43 // which is in the same position as private_1 below.
44 return _Unwind_RaiseException(exception_object);

--- 16 unchanged lines hidden (view full) ---

61}
62
63
64/// Called by personality handler during phase 2 to get base address for data
65/// relative encodings.
66_LIBUNWIND_EXPORT uintptr_t
67_Unwind_GetDataRelBase(struct _Unwind_Context *context) {
68 (void)context;
37 (void *)exception_object,
38 (long)exception_object->private_1);
39#endif
40
41#if _LIBUNWIND_ARM_EHABI
42 // _Unwind_RaiseException on EHABI will always set the reserved1 field to 0,
43 // which is in the same position as private_1 below.
44 return _Unwind_RaiseException(exception_object);

--- 16 unchanged lines hidden (view full) ---

61}
62
63
64/// Called by personality handler during phase 2 to get base address for data
65/// relative encodings.
66_LIBUNWIND_EXPORT uintptr_t
67_Unwind_GetDataRelBase(struct _Unwind_Context *context) {
68 (void)context;
69 _LIBUNWIND_TRACE_API("_Unwind_GetDataRelBase(context=%p)\n", (void *)context);
69 _LIBUNWIND_TRACE_API("_Unwind_GetDataRelBase(context=%p)", (void *)context);
70 _LIBUNWIND_ABORT("_Unwind_GetDataRelBase() not implemented");
71}
72
73
74/// Called by personality handler during phase 2 to get base address for text
75/// relative encodings.
76_LIBUNWIND_EXPORT uintptr_t
77_Unwind_GetTextRelBase(struct _Unwind_Context *context) {
78 (void)context;
70 _LIBUNWIND_ABORT("_Unwind_GetDataRelBase() not implemented");
71}
72
73
74/// Called by personality handler during phase 2 to get base address for text
75/// relative encodings.
76_LIBUNWIND_EXPORT uintptr_t
77_Unwind_GetTextRelBase(struct _Unwind_Context *context) {
78 (void)context;
79 _LIBUNWIND_TRACE_API("_Unwind_GetTextRelBase(context=%p)\n", (void *)context);
79 _LIBUNWIND_TRACE_API("_Unwind_GetTextRelBase(context=%p)", (void *)context);
80 _LIBUNWIND_ABORT("_Unwind_GetTextRelBase() not implemented");
81}
82
83
84/// Scans unwind information to find the function that contains the
85/// specified code address "pc".
86_LIBUNWIND_EXPORT void *_Unwind_FindEnclosingFunction(void *pc) {
80 _LIBUNWIND_ABORT("_Unwind_GetTextRelBase() not implemented");
81}
82
83
84/// Scans unwind information to find the function that contains the
85/// specified code address "pc".
86_LIBUNWIND_EXPORT void *_Unwind_FindEnclosingFunction(void *pc) {
87 _LIBUNWIND_TRACE_API("_Unwind_FindEnclosingFunction(pc=%p)\n", pc);
87 _LIBUNWIND_TRACE_API("_Unwind_FindEnclosingFunction(pc=%p)", pc);
88 // This is slow, but works.
89 // We create an unwind cursor then alter the IP to be pc
90 unw_cursor_t cursor;
91 unw_context_t uc;
92 unw_proc_info_t info;
93 unw_getcontext(&uc);
94 unw_init_local(&cursor, &uc);
95 unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc);

--- 7 unchanged lines hidden (view full) ---

103/// returns anything other than _URC_NO_REASON, then walk is terminated.
104_LIBUNWIND_EXPORT _Unwind_Reason_Code
105_Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) {
106 unw_cursor_t cursor;
107 unw_context_t uc;
108 unw_getcontext(&uc);
109 unw_init_local(&cursor, &uc);
110
88 // This is slow, but works.
89 // We create an unwind cursor then alter the IP to be pc
90 unw_cursor_t cursor;
91 unw_context_t uc;
92 unw_proc_info_t info;
93 unw_getcontext(&uc);
94 unw_init_local(&cursor, &uc);
95 unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc);

--- 7 unchanged lines hidden (view full) ---

103/// returns anything other than _URC_NO_REASON, then walk is terminated.
104_LIBUNWIND_EXPORT _Unwind_Reason_Code
105_Unwind_Backtrace(_Unwind_Trace_Fn callback, void *ref) {
106 unw_cursor_t cursor;
107 unw_context_t uc;
108 unw_getcontext(&uc);
109 unw_init_local(&cursor, &uc);
110
111 _LIBUNWIND_TRACE_API("_Unwind_Backtrace(callback=%p)\n",
111 _LIBUNWIND_TRACE_API("_Unwind_Backtrace(callback=%p)",
112 (void *)(uintptr_t)callback);
113
114#if _LIBUNWIND_ARM_EHABI
115 // Create a mock exception object for force unwinding.
116 _Unwind_Exception ex;
117 memset(&ex, '\0', sizeof(ex));
118 ex.exception_class = 0x434C4E47554E5700; // CLNGUNW\0
119#endif
120
121 // walk each frame
122 while (true) {
123 _Unwind_Reason_Code result;
124
125#if !_LIBUNWIND_ARM_EHABI
112 (void *)(uintptr_t)callback);
113
114#if _LIBUNWIND_ARM_EHABI
115 // Create a mock exception object for force unwinding.
116 _Unwind_Exception ex;
117 memset(&ex, '\0', sizeof(ex));
118 ex.exception_class = 0x434C4E47554E5700; // CLNGUNW\0
119#endif
120
121 // walk each frame
122 while (true) {
123 _Unwind_Reason_Code result;
124
125#if !_LIBUNWIND_ARM_EHABI
126 // ask libuwind to get next frame (skip over first frame which is
126 // ask libunwind to get next frame (skip over first frame which is
127 // _Unwind_Backtrace())
128 if (unw_step(&cursor) <= 0) {
129 _LIBUNWIND_TRACE_UNWINDING(" _backtrace: ended because cursor reached "
127 // _Unwind_Backtrace())
128 if (unw_step(&cursor) <= 0) {
129 _LIBUNWIND_TRACE_UNWINDING(" _backtrace: ended because cursor reached "
130 "bottom of stack, returning %d\n",
130 "bottom of stack, returning %d",
131 _URC_END_OF_STACK);
132 return _URC_END_OF_STACK;
133 }
134#else
135 // Get the information for this frame.
136 unw_proc_info_t frameInfo;
137 if (unw_get_proc_info(&cursor, &frameInfo) != UNW_ESUCCESS) {
138 return _URC_END_OF_STACK;

--- 20 unchanged lines hidden (view full) ---

159 // debugging
160 if (_LIBUNWIND_TRACING_UNWINDING) {
161 char functionName[512];
162 unw_proc_info_t frame;
163 unw_word_t offset;
164 unw_get_proc_name(&cursor, functionName, 512, &offset);
165 unw_get_proc_info(&cursor, &frame);
166 _LIBUNWIND_TRACE_UNWINDING(
131 _URC_END_OF_STACK);
132 return _URC_END_OF_STACK;
133 }
134#else
135 // Get the information for this frame.
136 unw_proc_info_t frameInfo;
137 if (unw_get_proc_info(&cursor, &frameInfo) != UNW_ESUCCESS) {
138 return _URC_END_OF_STACK;

--- 20 unchanged lines hidden (view full) ---

159 // debugging
160 if (_LIBUNWIND_TRACING_UNWINDING) {
161 char functionName[512];
162 unw_proc_info_t frame;
163 unw_word_t offset;
164 unw_get_proc_name(&cursor, functionName, 512, &offset);
165 unw_get_proc_info(&cursor, &frame);
166 _LIBUNWIND_TRACE_UNWINDING(
167 " _backtrace: start_ip=0x%llX, func=%s, lsda=0x%llX, context=%p\n",
167 " _backtrace: start_ip=0x%llX, func=%s, lsda=0x%llX, context=%p",
168 (long long)frame.start_ip, functionName, (long long)frame.lsda,
169 (void *)&cursor);
170 }
171
172 // call trace function with this frame
173 result = (*callback)((struct _Unwind_Context *)(&cursor), ref);
174 if (result != _URC_NO_REASON) {
175 _LIBUNWIND_TRACE_UNWINDING(
168 (long long)frame.start_ip, functionName, (long long)frame.lsda,
169 (void *)&cursor);
170 }
171
172 // call trace function with this frame
173 result = (*callback)((struct _Unwind_Context *)(&cursor), ref);
174 if (result != _URC_NO_REASON) {
175 _LIBUNWIND_TRACE_UNWINDING(
176 " _backtrace: ended because callback returned %d\n", result);
176 " _backtrace: ended because callback returned %d", result);
177 return result;
178 }
179 }
180}
181
182
183/// Find dwarf unwind info for an address 'pc' in some function.
184_LIBUNWIND_EXPORT const void *_Unwind_Find_FDE(const void *pc,

--- 5 unchanged lines hidden (view full) ---

190 unw_proc_info_t info;
191 unw_getcontext(&uc);
192 unw_init_local(&cursor, &uc);
193 unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc);
194 unw_get_proc_info(&cursor, &info);
195 bases->tbase = (uintptr_t)info.extra;
196 bases->dbase = 0; // dbase not used on Mac OS X
197 bases->func = (uintptr_t)info.start_ip;
177 return result;
178 }
179 }
180}
181
182
183/// Find dwarf unwind info for an address 'pc' in some function.
184_LIBUNWIND_EXPORT const void *_Unwind_Find_FDE(const void *pc,

--- 5 unchanged lines hidden (view full) ---

190 unw_proc_info_t info;
191 unw_getcontext(&uc);
192 unw_init_local(&cursor, &uc);
193 unw_set_reg(&cursor, UNW_REG_IP, (unw_word_t)(long) pc);
194 unw_get_proc_info(&cursor, &info);
195 bases->tbase = (uintptr_t)info.extra;
196 bases->dbase = 0; // dbase not used on Mac OS X
197 bases->func = (uintptr_t)info.start_ip;
198 _LIBUNWIND_TRACE_API("_Unwind_Find_FDE(pc=%p) => %p\n", pc,
198 _LIBUNWIND_TRACE_API("_Unwind_Find_FDE(pc=%p) => %p", pc,
199 (void *)(long) info.unwind_info);
200 return (void *)(long) info.unwind_info;
201}
202
203/// Returns the CFA (call frame area, or stack pointer at start of function)
204/// for the current context.
205_LIBUNWIND_EXPORT uintptr_t _Unwind_GetCFA(struct _Unwind_Context *context) {
206 unw_cursor_t *cursor = (unw_cursor_t *)context;
207 unw_word_t result;
208 unw_get_reg(cursor, UNW_REG_SP, &result);
199 (void *)(long) info.unwind_info);
200 return (void *)(long) info.unwind_info;
201}
202
203/// Returns the CFA (call frame area, or stack pointer at start of function)
204/// for the current context.
205_LIBUNWIND_EXPORT uintptr_t _Unwind_GetCFA(struct _Unwind_Context *context) {
206 unw_cursor_t *cursor = (unw_cursor_t *)context;
207 unw_word_t result;
208 unw_get_reg(cursor, UNW_REG_SP, &result);
209 _LIBUNWIND_TRACE_API("_Unwind_GetCFA(context=%p) => 0x%" PRIx64 "\n",
209 _LIBUNWIND_TRACE_API("_Unwind_GetCFA(context=%p) => 0x%" PRIx64,
210 (void *)context, (uint64_t)result);
211 return (uintptr_t)result;
212}
213
214
215/// Called by personality handler during phase 2 to get instruction pointer.
216/// ipBefore is a boolean that says if IP is already adjusted to be the call
217/// site address. Normally IP is the return address.
218_LIBUNWIND_EXPORT uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context,
219 int *ipBefore) {
210 (void *)context, (uint64_t)result);
211 return (uintptr_t)result;
212}
213
214
215/// Called by personality handler during phase 2 to get instruction pointer.
216/// ipBefore is a boolean that says if IP is already adjusted to be the call
217/// site address. Normally IP is the return address.
218_LIBUNWIND_EXPORT uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context *context,
219 int *ipBefore) {
220 _LIBUNWIND_TRACE_API("_Unwind_GetIPInfo(context=%p)\n", (void *)context);
220 _LIBUNWIND_TRACE_API("_Unwind_GetIPInfo(context=%p)", (void *)context);
221 *ipBefore = 0;
222 return _Unwind_GetIP(context);
223}
224
225#if _LIBUNWIND_SUPPORT_DWARF_UNWIND
226
227/// Called by programs with dynamic code generators that want
228/// to register a dynamically generated FDE.
229/// This function has existed on Mac OS X since 10.4, but
230/// was broken until 10.6.
231_LIBUNWIND_EXPORT void __register_frame(const void *fde) {
221 *ipBefore = 0;
222 return _Unwind_GetIP(context);
223}
224
225#if _LIBUNWIND_SUPPORT_DWARF_UNWIND
226
227/// Called by programs with dynamic code generators that want
228/// to register a dynamically generated FDE.
229/// This function has existed on Mac OS X since 10.4, but
230/// was broken until 10.6.
231_LIBUNWIND_EXPORT void __register_frame(const void *fde) {
232 _LIBUNWIND_TRACE_API("__register_frame(%p)\n", fde);
232 _LIBUNWIND_TRACE_API("__register_frame(%p)", fde);
233 _unw_add_dynamic_fde((unw_word_t)(uintptr_t) fde);
234}
235
236
237/// Called by programs with dynamic code generators that want
238/// to unregister a dynamically generated FDE.
239/// This function has existed on Mac OS X since 10.4, but
240/// was broken until 10.6.
241_LIBUNWIND_EXPORT void __deregister_frame(const void *fde) {
233 _unw_add_dynamic_fde((unw_word_t)(uintptr_t) fde);
234}
235
236
237/// Called by programs with dynamic code generators that want
238/// to unregister a dynamically generated FDE.
239/// This function has existed on Mac OS X since 10.4, but
240/// was broken until 10.6.
241_LIBUNWIND_EXPORT void __deregister_frame(const void *fde) {
242 _LIBUNWIND_TRACE_API("__deregister_frame(%p)\n", fde);
242 _LIBUNWIND_TRACE_API("__deregister_frame(%p)", fde);
243 _unw_remove_dynamic_fde((unw_word_t)(uintptr_t) fde);
244}
245
246
247// The following register/deregister functions are gcc extensions.
248// They have existed on Mac OS X, but have never worked because Mac OS X
249// before 10.6 used keymgr to track known FDEs, but these functions
250// never got updated to use keymgr.
251// For now, we implement these as do-nothing functions to keep any existing
252// applications working. We also add the not in 10.6 symbol so that nwe
253// application won't be able to use them.
254
255#if _LIBUNWIND_SUPPORT_FRAME_APIS
256_LIBUNWIND_EXPORT void __register_frame_info_bases(const void *fde, void *ob,
257 void *tb, void *db) {
258 (void)fde;
259 (void)ob;
260 (void)tb;
261 (void)db;
243 _unw_remove_dynamic_fde((unw_word_t)(uintptr_t) fde);
244}
245
246
247// The following register/deregister functions are gcc extensions.
248// They have existed on Mac OS X, but have never worked because Mac OS X
249// before 10.6 used keymgr to track known FDEs, but these functions
250// never got updated to use keymgr.
251// For now, we implement these as do-nothing functions to keep any existing
252// applications working. We also add the not in 10.6 symbol so that nwe
253// application won't be able to use them.
254
255#if _LIBUNWIND_SUPPORT_FRAME_APIS
256_LIBUNWIND_EXPORT void __register_frame_info_bases(const void *fde, void *ob,
257 void *tb, void *db) {
258 (void)fde;
259 (void)ob;
260 (void)tb;
261 (void)db;
262 _LIBUNWIND_TRACE_API("__register_frame_info_bases(%p,%p, %p, %p)\n",
262 _LIBUNWIND_TRACE_API("__register_frame_info_bases(%p,%p, %p, %p)",
263 fde, ob, tb, db);
264 // do nothing, this function never worked in Mac OS X
265}
266
267_LIBUNWIND_EXPORT void __register_frame_info(const void *fde, void *ob) {
268 (void)fde;
269 (void)ob;
263 fde, ob, tb, db);
264 // do nothing, this function never worked in Mac OS X
265}
266
267_LIBUNWIND_EXPORT void __register_frame_info(const void *fde, void *ob) {
268 (void)fde;
269 (void)ob;
270 _LIBUNWIND_TRACE_API("__register_frame_info(%p, %p)\n", fde, ob);
270 _LIBUNWIND_TRACE_API("__register_frame_info(%p, %p)", fde, ob);
271 // do nothing, this function never worked in Mac OS X
272}
273
274_LIBUNWIND_EXPORT void __register_frame_info_table_bases(const void *fde,
275 void *ob, void *tb,
276 void *db) {
277 (void)fde;
278 (void)ob;
279 (void)tb;
280 (void)db;
281 _LIBUNWIND_TRACE_API("__register_frame_info_table_bases"
271 // do nothing, this function never worked in Mac OS X
272}
273
274_LIBUNWIND_EXPORT void __register_frame_info_table_bases(const void *fde,
275 void *ob, void *tb,
276 void *db) {
277 (void)fde;
278 (void)ob;
279 (void)tb;
280 (void)db;
281 _LIBUNWIND_TRACE_API("__register_frame_info_table_bases"
282 "(%p,%p, %p, %p)\n", fde, ob, tb, db);
282 "(%p,%p, %p, %p)", fde, ob, tb, db);
283 // do nothing, this function never worked in Mac OS X
284}
285
286_LIBUNWIND_EXPORT void __register_frame_info_table(const void *fde, void *ob) {
287 (void)fde;
288 (void)ob;
283 // do nothing, this function never worked in Mac OS X
284}
285
286_LIBUNWIND_EXPORT void __register_frame_info_table(const void *fde, void *ob) {
287 (void)fde;
288 (void)ob;
289 _LIBUNWIND_TRACE_API("__register_frame_info_table(%p, %p)\n", fde, ob);
289 _LIBUNWIND_TRACE_API("__register_frame_info_table(%p, %p)", fde, ob);
290 // do nothing, this function never worked in Mac OS X
291}
292
293_LIBUNWIND_EXPORT void __register_frame_table(const void *fde) {
294 (void)fde;
290 // do nothing, this function never worked in Mac OS X
291}
292
293_LIBUNWIND_EXPORT void __register_frame_table(const void *fde) {
294 (void)fde;
295 _LIBUNWIND_TRACE_API("__register_frame_table(%p)\n", fde);
295 _LIBUNWIND_TRACE_API("__register_frame_table(%p)", fde);
296 // do nothing, this function never worked in Mac OS X
297}
298
299_LIBUNWIND_EXPORT void *__deregister_frame_info(const void *fde) {
300 (void)fde;
296 // do nothing, this function never worked in Mac OS X
297}
298
299_LIBUNWIND_EXPORT void *__deregister_frame_info(const void *fde) {
300 (void)fde;
301 _LIBUNWIND_TRACE_API("__deregister_frame_info(%p)\n", fde);
301 _LIBUNWIND_TRACE_API("__deregister_frame_info(%p)", fde);
302 // do nothing, this function never worked in Mac OS X
303 return NULL;
304}
305
306_LIBUNWIND_EXPORT void *__deregister_frame_info_bases(const void *fde) {
307 (void)fde;
302 // do nothing, this function never worked in Mac OS X
303 return NULL;
304}
305
306_LIBUNWIND_EXPORT void *__deregister_frame_info_bases(const void *fde) {
307 (void)fde;
308 _LIBUNWIND_TRACE_API("__deregister_frame_info_bases(%p)\n", fde);
308 _LIBUNWIND_TRACE_API("__deregister_frame_info_bases(%p)", fde);
309 // do nothing, this function never worked in Mac OS X
310 return NULL;
311}
312#endif // _LIBUNWIND_SUPPORT_FRAME_APIS
313
314#endif // _LIBUNWIND_SUPPORT_DWARF_UNWIND
315
316#endif // _LIBUNWIND_BUILD_ZERO_COST_APIS
309 // do nothing, this function never worked in Mac OS X
310 return NULL;
311}
312#endif // _LIBUNWIND_SUPPORT_FRAME_APIS
313
314#endif // _LIBUNWIND_SUPPORT_DWARF_UNWIND
315
316#endif // _LIBUNWIND_BUILD_ZERO_COST_APIS