xref: /freebsd/contrib/llvm-project/libunwind/src/UnwindLevel1.c (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //
8 // Implements C++ ABI Exception Handling Level 1 as documented at:
9 //      https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
10 // using libunwind
11 //
12 //===----------------------------------------------------------------------===//
13 
14 // ARM EHABI does not specify _Unwind_{Get,Set}{GR,IP}().  Thus, we are
15 // defining inline functions to delegate the function calls to
16 // _Unwind_VRS_{Get,Set}().  However, some applications might declare the
17 // function protetype directly (instead of including <unwind.h>), thus we need
18 // to export these functions from libunwind.so as well.
19 #define _LIBUNWIND_UNWIND_LEVEL1_EXTERNAL_LINKAGE 1
20 
21 #include <inttypes.h>
22 #include <stdint.h>
23 #include <stdbool.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27 
28 #include "cet_unwind.h"
29 #include "config.h"
30 #include "libunwind.h"
31 #include "libunwind_ext.h"
32 #include "unwind.h"
33 
34 #if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
35 
36 #ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND
37 
38 // When CET is enabled, each "call" instruction will push return address to
39 // CET shadow stack, each "ret" instruction will pop current CET shadow stack
40 // top and compare it with target address which program will return.
41 // In exception handing, some stack frames will be skipped before jumping to
42 // landing pad and we must adjust CET shadow stack accordingly.
43 // _LIBUNWIND_POP_CET_SSP is used to adjust CET shadow stack pointer and we
44 // directly jump to __libunwind_Registerts_x86/x86_64_jumpto instead of using
45 // a regular function call to avoid pushing to CET shadow stack again.
46 #if !defined(_LIBUNWIND_USE_CET)
47 #define __unw_phase2_resume(cursor, fn)                                        \
48   do {                                                                         \
49     (void)fn;                                                                  \
50     __unw_resume((cursor));                                                    \
51   } while (0)
52 #elif defined(_LIBUNWIND_TARGET_I386)
53 #define __unw_phase2_resume(cursor, fn)                                        \
54   do {                                                                         \
55     _LIBUNWIND_POP_CET_SSP((fn));                                              \
56     void *cetRegContext = __libunwind_cet_get_registers((cursor));             \
57     void *cetJumpAddress = __libunwind_cet_get_jump_target();                  \
58     __asm__ volatile("push %%edi\n\t"                                          \
59                      "sub $4, %%esp\n\t"                                       \
60                      "jmp *%%edx\n\t" :: "D"(cetRegContext),                   \
61                      "d"(cetJumpAddress));                                     \
62   } while (0)
63 #elif defined(_LIBUNWIND_TARGET_X86_64)
64 #define __unw_phase2_resume(cursor, fn)                                        \
65   do {                                                                         \
66     _LIBUNWIND_POP_CET_SSP((fn));                                              \
67     void *cetRegContext = __libunwind_cet_get_registers((cursor));             \
68     void *cetJumpAddress = __libunwind_cet_get_jump_target();                  \
69     __asm__ volatile("jmpq *%%rdx\n\t" :: "D"(cetRegContext),                  \
70                      "d"(cetJumpAddress));                                     \
71   } while (0)
72 #endif
73 
74 static _Unwind_Reason_Code
75 unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) {
76   __unw_init_local(cursor, uc);
77 
78   // Walk each frame looking for a place to stop.
79   while (true) {
80     // Ask libunwind to get next frame (skip over first which is
81     // _Unwind_RaiseException).
82     int stepResult = __unw_step(cursor);
83     if (stepResult == 0) {
84       _LIBUNWIND_TRACE_UNWINDING(
85           "unwind_phase1(ex_ojb=%p): __unw_step() reached "
86           "bottom => _URC_END_OF_STACK",
87           (void *)exception_object);
88       return _URC_END_OF_STACK;
89     } else if (stepResult < 0) {
90       _LIBUNWIND_TRACE_UNWINDING(
91           "unwind_phase1(ex_ojb=%p): __unw_step failed => "
92           "_URC_FATAL_PHASE1_ERROR",
93           (void *)exception_object);
94       return _URC_FATAL_PHASE1_ERROR;
95     }
96 
97     // See if frame has code to run (has personality routine).
98     unw_proc_info_t frameInfo;
99     unw_word_t sp;
100     if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {
101       _LIBUNWIND_TRACE_UNWINDING(
102           "unwind_phase1(ex_ojb=%p): __unw_get_proc_info "
103           "failed => _URC_FATAL_PHASE1_ERROR",
104           (void *)exception_object);
105       return _URC_FATAL_PHASE1_ERROR;
106     }
107 
108 #ifndef NDEBUG
109     // When tracing, print state information.
110     if (_LIBUNWIND_TRACING_UNWINDING) {
111       char functionBuf[512];
112       const char *functionName = functionBuf;
113       unw_word_t offset;
114       if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf),
115                                &offset) != UNW_ESUCCESS) ||
116           (frameInfo.start_ip + offset > frameInfo.end_ip))
117         functionName = ".anonymous.";
118       unw_word_t pc;
119       __unw_get_reg(cursor, UNW_REG_IP, &pc);
120       _LIBUNWIND_TRACE_UNWINDING(
121           "unwind_phase1(ex_ojb=%p): pc=0x%" PRIxPTR ", start_ip=0x%" PRIxPTR
122           ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR "",
123           (void *)exception_object, pc, frameInfo.start_ip, functionName,
124           frameInfo.lsda, frameInfo.handler);
125     }
126 #endif
127 
128     // If there is a personality routine, ask it if it will want to stop at
129     // this frame.
130     if (frameInfo.handler != 0) {
131       _Unwind_Personality_Fn p =
132           (_Unwind_Personality_Fn)(uintptr_t)(frameInfo.handler);
133       _LIBUNWIND_TRACE_UNWINDING(
134           "unwind_phase1(ex_ojb=%p): calling personality function %p",
135           (void *)exception_object, (void *)(uintptr_t)p);
136       _Unwind_Reason_Code personalityResult =
137           (*p)(1, _UA_SEARCH_PHASE, exception_object->exception_class,
138                exception_object, (struct _Unwind_Context *)(cursor));
139       switch (personalityResult) {
140       case _URC_HANDLER_FOUND:
141         // found a catch clause or locals that need destructing in this frame
142         // stop search and remember stack pointer at the frame
143         __unw_get_reg(cursor, UNW_REG_SP, &sp);
144         exception_object->private_2 = (uintptr_t)sp;
145         _LIBUNWIND_TRACE_UNWINDING(
146             "unwind_phase1(ex_ojb=%p): _URC_HANDLER_FOUND",
147             (void *)exception_object);
148         return _URC_NO_REASON;
149 
150       case _URC_CONTINUE_UNWIND:
151         _LIBUNWIND_TRACE_UNWINDING(
152             "unwind_phase1(ex_ojb=%p): _URC_CONTINUE_UNWIND",
153             (void *)exception_object);
154         // continue unwinding
155         break;
156 
157       default:
158         // something went wrong
159         _LIBUNWIND_TRACE_UNWINDING(
160             "unwind_phase1(ex_ojb=%p): _URC_FATAL_PHASE1_ERROR",
161             (void *)exception_object);
162         return _URC_FATAL_PHASE1_ERROR;
163       }
164     }
165   }
166   return _URC_NO_REASON;
167 }
168 
169 
170 static _Unwind_Reason_Code
171 unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) {
172   __unw_init_local(cursor, uc);
173 
174   _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p)",
175                              (void *)exception_object);
176 
177   // uc is initialized by __unw_getcontext in the parent frame. The first stack
178   // frame walked is unwind_phase2.
179   unsigned framesWalked = 1;
180   // Walk each frame until we reach where search phase said to stop.
181   while (true) {
182 
183     // Ask libunwind to get next frame (skip over first which is
184     // _Unwind_RaiseException).
185     int stepResult = __unw_step(cursor);
186     if (stepResult == 0) {
187       _LIBUNWIND_TRACE_UNWINDING(
188           "unwind_phase2(ex_ojb=%p): __unw_step() reached "
189           "bottom => _URC_END_OF_STACK",
190           (void *)exception_object);
191       return _URC_END_OF_STACK;
192     } else if (stepResult < 0) {
193       _LIBUNWIND_TRACE_UNWINDING(
194           "unwind_phase2(ex_ojb=%p): __unw_step failed => "
195           "_URC_FATAL_PHASE1_ERROR",
196           (void *)exception_object);
197       return _URC_FATAL_PHASE2_ERROR;
198     }
199 
200     // Get info about this frame.
201     unw_word_t sp;
202     unw_proc_info_t frameInfo;
203     __unw_get_reg(cursor, UNW_REG_SP, &sp);
204     if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {
205       _LIBUNWIND_TRACE_UNWINDING(
206           "unwind_phase2(ex_ojb=%p): __unw_get_proc_info "
207           "failed => _URC_FATAL_PHASE1_ERROR",
208           (void *)exception_object);
209       return _URC_FATAL_PHASE2_ERROR;
210     }
211 
212 #ifndef NDEBUG
213     // When tracing, print state information.
214     if (_LIBUNWIND_TRACING_UNWINDING) {
215       char functionBuf[512];
216       const char *functionName = functionBuf;
217       unw_word_t offset;
218       if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf),
219                                &offset) != UNW_ESUCCESS) ||
220           (frameInfo.start_ip + offset > frameInfo.end_ip))
221         functionName = ".anonymous.";
222       _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): start_ip=0x%" PRIxPTR
223                                  ", func=%s, sp=0x%" PRIxPTR ", lsda=0x%" PRIxPTR
224                                  ", personality=0x%" PRIxPTR,
225                                  (void *)exception_object, frameInfo.start_ip,
226                                  functionName, sp, frameInfo.lsda,
227                                  frameInfo.handler);
228     }
229 #endif
230 
231     ++framesWalked;
232     // If there is a personality routine, tell it we are unwinding.
233     if (frameInfo.handler != 0) {
234       _Unwind_Personality_Fn p =
235           (_Unwind_Personality_Fn)(uintptr_t)(frameInfo.handler);
236       _Unwind_Action action = _UA_CLEANUP_PHASE;
237       if (sp == exception_object->private_2) {
238         // Tell personality this was the frame it marked in phase 1.
239         action = (_Unwind_Action)(_UA_CLEANUP_PHASE | _UA_HANDLER_FRAME);
240       }
241        _Unwind_Reason_Code personalityResult =
242           (*p)(1, action, exception_object->exception_class, exception_object,
243                (struct _Unwind_Context *)(cursor));
244       switch (personalityResult) {
245       case _URC_CONTINUE_UNWIND:
246         // Continue unwinding
247         _LIBUNWIND_TRACE_UNWINDING(
248             "unwind_phase2(ex_ojb=%p): _URC_CONTINUE_UNWIND",
249             (void *)exception_object);
250         if (sp == exception_object->private_2) {
251           // Phase 1 said we would stop at this frame, but we did not...
252           _LIBUNWIND_ABORT("during phase1 personality function said it would "
253                            "stop here, but now in phase2 it did not stop here");
254         }
255         break;
256       case _URC_INSTALL_CONTEXT:
257         _LIBUNWIND_TRACE_UNWINDING(
258             "unwind_phase2(ex_ojb=%p): _URC_INSTALL_CONTEXT",
259             (void *)exception_object);
260         // Personality routine says to transfer control to landing pad.
261         // We may get control back if landing pad calls _Unwind_Resume().
262         if (_LIBUNWIND_TRACING_UNWINDING) {
263           unw_word_t pc;
264           __unw_get_reg(cursor, UNW_REG_IP, &pc);
265           __unw_get_reg(cursor, UNW_REG_SP, &sp);
266           _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): re-entering "
267                                      "user code with ip=0x%" PRIxPTR
268                                      ", sp=0x%" PRIxPTR,
269                                      (void *)exception_object, pc, sp);
270         }
271 
272         __unw_phase2_resume(cursor, framesWalked);
273         // __unw_phase2_resume() only returns if there was an error.
274         return _URC_FATAL_PHASE2_ERROR;
275       default:
276         // Personality routine returned an unknown result code.
277         _LIBUNWIND_DEBUG_LOG("personality function returned unknown result %d",
278                              personalityResult);
279         return _URC_FATAL_PHASE2_ERROR;
280       }
281     }
282   }
283 
284   // Clean up phase did not resume at the frame that the search phase
285   // said it would...
286   return _URC_FATAL_PHASE2_ERROR;
287 }
288 
289 static _Unwind_Reason_Code
290 unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor,
291                      _Unwind_Exception *exception_object,
292                      _Unwind_Stop_Fn stop, void *stop_parameter) {
293   __unw_init_local(cursor, uc);
294 
295   // uc is initialized by __unw_getcontext in the parent frame. The first stack
296   // frame walked is unwind_phase2_forced.
297   unsigned framesWalked = 1;
298   // Walk each frame until we reach where search phase said to stop
299   while (__unw_step(cursor) > 0) {
300 
301     // Update info about this frame.
302     unw_proc_info_t frameInfo;
303     if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) {
304       _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): __unw_step "
305                                  "failed => _URC_END_OF_STACK",
306                                  (void *)exception_object);
307       return _URC_FATAL_PHASE2_ERROR;
308     }
309 
310 #ifndef NDEBUG
311     // When tracing, print state information.
312     if (_LIBUNWIND_TRACING_UNWINDING) {
313       char functionBuf[512];
314       const char *functionName = functionBuf;
315       unw_word_t offset;
316       if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf),
317                                &offset) != UNW_ESUCCESS) ||
318           (frameInfo.start_ip + offset > frameInfo.end_ip))
319         functionName = ".anonymous.";
320       _LIBUNWIND_TRACE_UNWINDING(
321           "unwind_phase2_forced(ex_ojb=%p): start_ip=0x%" PRIxPTR
322           ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR,
323           (void *)exception_object, frameInfo.start_ip, functionName,
324           frameInfo.lsda, frameInfo.handler);
325     }
326 #endif
327 
328     // Call stop function at each frame.
329     _Unwind_Action action =
330         (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE);
331     _Unwind_Reason_Code stopResult =
332         (*stop)(1, action, exception_object->exception_class, exception_object,
333                 (struct _Unwind_Context *)(cursor), stop_parameter);
334     _LIBUNWIND_TRACE_UNWINDING(
335         "unwind_phase2_forced(ex_ojb=%p): stop function returned %d",
336         (void *)exception_object, stopResult);
337     if (stopResult != _URC_NO_REASON) {
338       _LIBUNWIND_TRACE_UNWINDING(
339           "unwind_phase2_forced(ex_ojb=%p): stopped by stop function",
340           (void *)exception_object);
341       return _URC_FATAL_PHASE2_ERROR;
342     }
343 
344     ++framesWalked;
345     // If there is a personality routine, tell it we are unwinding.
346     if (frameInfo.handler != 0) {
347       _Unwind_Personality_Fn p =
348           (_Unwind_Personality_Fn)(intptr_t)(frameInfo.handler);
349       _LIBUNWIND_TRACE_UNWINDING(
350           "unwind_phase2_forced(ex_ojb=%p): calling personality function %p",
351           (void *)exception_object, (void *)(uintptr_t)p);
352       _Unwind_Reason_Code personalityResult =
353           (*p)(1, action, exception_object->exception_class, exception_object,
354                (struct _Unwind_Context *)(cursor));
355       switch (personalityResult) {
356       case _URC_CONTINUE_UNWIND:
357         _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
358                                    "personality returned "
359                                    "_URC_CONTINUE_UNWIND",
360                                    (void *)exception_object);
361         // Destructors called, continue unwinding
362         break;
363       case _URC_INSTALL_CONTEXT:
364         _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
365                                    "personality returned "
366                                    "_URC_INSTALL_CONTEXT",
367                                    (void *)exception_object);
368         // We may get control back if landing pad calls _Unwind_Resume().
369         __unw_phase2_resume(cursor, framesWalked);
370         break;
371       default:
372         // Personality routine returned an unknown result code.
373         _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): "
374                                    "personality returned %d, "
375                                    "_URC_FATAL_PHASE2_ERROR",
376                                    (void *)exception_object, personalityResult);
377         return _URC_FATAL_PHASE2_ERROR;
378       }
379     }
380   }
381 
382   // Call stop function one last time and tell it we've reached the end
383   // of the stack.
384   _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): calling stop "
385                              "function with _UA_END_OF_STACK",
386                              (void *)exception_object);
387   _Unwind_Action lastAction =
388       (_Unwind_Action)(_UA_FORCE_UNWIND | _UA_CLEANUP_PHASE | _UA_END_OF_STACK);
389   (*stop)(1, lastAction, exception_object->exception_class, exception_object,
390           (struct _Unwind_Context *)(cursor), stop_parameter);
391 
392   // Clean up phase did not resume at the frame that the search phase said it
393   // would.
394   return _URC_FATAL_PHASE2_ERROR;
395 }
396 
397 
398 /// Called by __cxa_throw.  Only returns if there is a fatal error.
399 _LIBUNWIND_EXPORT _Unwind_Reason_Code
400 _Unwind_RaiseException(_Unwind_Exception *exception_object) {
401   _LIBUNWIND_TRACE_API("_Unwind_RaiseException(ex_obj=%p)",
402                        (void *)exception_object);
403   unw_context_t uc;
404   unw_cursor_t cursor;
405   __unw_getcontext(&uc);
406 
407   // Mark that this is a non-forced unwind, so _Unwind_Resume()
408   // can do the right thing.
409   exception_object->private_1 = 0;
410   exception_object->private_2 = 0;
411 
412   // phase 1: the search phase
413   _Unwind_Reason_Code phase1 = unwind_phase1(&uc, &cursor, exception_object);
414   if (phase1 != _URC_NO_REASON)
415     return phase1;
416 
417   // phase 2: the clean up phase
418   return unwind_phase2(&uc, &cursor, exception_object);
419 }
420 
421 
422 
423 /// When _Unwind_RaiseException() is in phase2, it hands control
424 /// to the personality function at each frame.  The personality
425 /// may force a jump to a landing pad in that function, the landing
426 /// pad code may then call _Unwind_Resume() to continue with the
427 /// unwinding.  Note: the call to _Unwind_Resume() is from compiler
428 /// geneated user code.  All other _Unwind_* routines are called
429 /// by the C++ runtime __cxa_* routines.
430 ///
431 /// Note: re-throwing an exception (as opposed to continuing the unwind)
432 /// is implemented by having the code call __cxa_rethrow() which
433 /// in turn calls _Unwind_Resume_or_Rethrow().
434 _LIBUNWIND_EXPORT void
435 _Unwind_Resume(_Unwind_Exception *exception_object) {
436   _LIBUNWIND_TRACE_API("_Unwind_Resume(ex_obj=%p)", (void *)exception_object);
437   unw_context_t uc;
438   unw_cursor_t cursor;
439   __unw_getcontext(&uc);
440 
441   if (exception_object->private_1 != 0)
442     unwind_phase2_forced(&uc, &cursor, exception_object,
443                          (_Unwind_Stop_Fn) exception_object->private_1,
444                          (void *)exception_object->private_2);
445   else
446     unwind_phase2(&uc, &cursor, exception_object);
447 
448   // Clients assume _Unwind_Resume() does not return, so all we can do is abort.
449   _LIBUNWIND_ABORT("_Unwind_Resume() can't return");
450 }
451 
452 
453 
454 /// Not used by C++.
455 /// Unwinds stack, calling "stop" function at each frame.
456 /// Could be used to implement longjmp().
457 _LIBUNWIND_EXPORT _Unwind_Reason_Code
458 _Unwind_ForcedUnwind(_Unwind_Exception *exception_object,
459                      _Unwind_Stop_Fn stop, void *stop_parameter) {
460   _LIBUNWIND_TRACE_API("_Unwind_ForcedUnwind(ex_obj=%p, stop=%p)",
461                        (void *)exception_object, (void *)(uintptr_t)stop);
462   unw_context_t uc;
463   unw_cursor_t cursor;
464   __unw_getcontext(&uc);
465 
466   // Mark that this is a forced unwind, so _Unwind_Resume() can do
467   // the right thing.
468   exception_object->private_1 = (uintptr_t) stop;
469   exception_object->private_2 = (uintptr_t) stop_parameter;
470 
471   // do it
472   return unwind_phase2_forced(&uc, &cursor, exception_object, stop, stop_parameter);
473 }
474 
475 
476 /// Called by personality handler during phase 2 to get LSDA for current frame.
477 _LIBUNWIND_EXPORT uintptr_t
478 _Unwind_GetLanguageSpecificData(struct _Unwind_Context *context) {
479   unw_cursor_t *cursor = (unw_cursor_t *)context;
480   unw_proc_info_t frameInfo;
481   uintptr_t result = 0;
482   if (__unw_get_proc_info(cursor, &frameInfo) == UNW_ESUCCESS)
483     result = (uintptr_t)frameInfo.lsda;
484   _LIBUNWIND_TRACE_API(
485       "_Unwind_GetLanguageSpecificData(context=%p) => 0x%" PRIxPTR,
486       (void *)context, result);
487 #if !defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND)
488   if (result != 0) {
489     if (*((uint8_t *)result) != 0xFF)
490       _LIBUNWIND_DEBUG_LOG("lsda at 0x%" PRIxPTR " does not start with 0xFF",
491                            result);
492   }
493 #endif
494   return result;
495 }
496 
497 
498 /// Called by personality handler during phase 2 to find the start of the
499 /// function.
500 _LIBUNWIND_EXPORT uintptr_t
501 _Unwind_GetRegionStart(struct _Unwind_Context *context) {
502   unw_cursor_t *cursor = (unw_cursor_t *)context;
503   unw_proc_info_t frameInfo;
504   uintptr_t result = 0;
505   if (__unw_get_proc_info(cursor, &frameInfo) == UNW_ESUCCESS)
506     result = (uintptr_t)frameInfo.start_ip;
507   _LIBUNWIND_TRACE_API("_Unwind_GetRegionStart(context=%p) => 0x%" PRIxPTR,
508                        (void *)context, result);
509   return result;
510 }
511 
512 #endif // !_LIBUNWIND_SUPPORT_SEH_UNWIND
513 
514 /// Called by personality handler during phase 2 if a foreign exception
515 // is caught.
516 _LIBUNWIND_EXPORT void
517 _Unwind_DeleteException(_Unwind_Exception *exception_object) {
518   _LIBUNWIND_TRACE_API("_Unwind_DeleteException(ex_obj=%p)",
519                        (void *)exception_object);
520   if (exception_object->exception_cleanup != NULL)
521     (*exception_object->exception_cleanup)(_URC_FOREIGN_EXCEPTION_CAUGHT,
522                                            exception_object);
523 }
524 
525 /// Called by personality handler during phase 2 to get register values.
526 _LIBUNWIND_EXPORT uintptr_t
527 _Unwind_GetGR(struct _Unwind_Context *context, int index) {
528   unw_cursor_t *cursor = (unw_cursor_t *)context;
529   unw_word_t result;
530   __unw_get_reg(cursor, index, &result);
531   _LIBUNWIND_TRACE_API("_Unwind_GetGR(context=%p, reg=%d) => 0x%" PRIxPTR,
532                        (void *)context, index, result);
533   return (uintptr_t)result;
534 }
535 
536 /// Called by personality handler during phase 2 to alter register values.
537 _LIBUNWIND_EXPORT void _Unwind_SetGR(struct _Unwind_Context *context, int index,
538                                      uintptr_t value) {
539   _LIBUNWIND_TRACE_API("_Unwind_SetGR(context=%p, reg=%d, value=0x%0" PRIxPTR
540                        ")",
541                        (void *)context, index, value);
542   unw_cursor_t *cursor = (unw_cursor_t *)context;
543   __unw_set_reg(cursor, index, value);
544 }
545 
546 /// Called by personality handler during phase 2 to get instruction pointer.
547 _LIBUNWIND_EXPORT uintptr_t _Unwind_GetIP(struct _Unwind_Context *context) {
548   unw_cursor_t *cursor = (unw_cursor_t *)context;
549   unw_word_t result;
550   __unw_get_reg(cursor, UNW_REG_IP, &result);
551   _LIBUNWIND_TRACE_API("_Unwind_GetIP(context=%p) => 0x%" PRIxPTR,
552                        (void *)context, result);
553   return (uintptr_t)result;
554 }
555 
556 /// Called by personality handler during phase 2 to alter instruction pointer,
557 /// such as setting where the landing pad is, so _Unwind_Resume() will
558 /// start executing in the landing pad.
559 _LIBUNWIND_EXPORT void _Unwind_SetIP(struct _Unwind_Context *context,
560                                      uintptr_t value) {
561   _LIBUNWIND_TRACE_API("_Unwind_SetIP(context=%p, value=0x%0" PRIxPTR ")",
562                        (void *)context, value);
563   unw_cursor_t *cursor = (unw_cursor_t *)context;
564   __unw_set_reg(cursor, UNW_REG_IP, value);
565 }
566 
567 #endif // !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__)
568