Louis Dionne | 7f068e5 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 61860a5 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 6 | // |
| 7 | // |
| 8 | // Implements C++ ABI Exception Handling Level 1 as documented at: |
Louis Dionne | 59d0c60 | 2019-04-11 16:37:07 +0000 | [diff] [blame] | 9 | // https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 10 | // using libunwind |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Logan Chien | 5456e8d | 2015-07-24 00:16:48 +0000 | [diff] [blame] | 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 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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 | |
gejin | 7f49316 | 2021-08-26 16:20:38 +0800 | [diff] [blame] | 28 | #include "cet_unwind.h" |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 29 | #include "config.h" |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 30 | #include "libunwind.h" |
| 31 | #include "libunwind_ext.h" |
| 32 | #include "unwind.h" |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 33 | |
Martin Storsjo | 9f16c6c | 2017-09-26 08:07:26 +0000 | [diff] [blame] | 34 | #if !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 35 | |
Charles Davis | fa2e620 | 2018-08-30 21:29:00 +0000 | [diff] [blame] | 36 | #ifndef _LIBUNWIND_SUPPORT_SEH_UNWIND |
| 37 | |
gejin | 7f49316 | 2021-08-26 16:20:38 +0800 | [diff] [blame] | 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) |
kristina | 6e7aaea | 2022-04-08 17:04:35 +0100 | [diff] [blame] | 47 | #define __unw_phase2_resume(cursor, fn) \ |
| 48 | do { \ |
| 49 | (void)fn; \ |
| 50 | __unw_resume((cursor)); \ |
| 51 | } while (0) |
gejin | 7f49316 | 2021-08-26 16:20:38 +0800 | [diff] [blame] | 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 | |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 74 | static _Unwind_Reason_Code |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 75 | unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 76 | __unw_init_local(cursor, uc); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 77 | |
| 78 | // Walk each frame looking for a place to stop. |
Fangrui Song | 45db2df | 2020-11-21 12:38:00 -0800 | [diff] [blame] | 79 | while (true) { |
Ed Maste | 6f72338 | 2016-08-30 13:08:21 +0000 | [diff] [blame] | 80 | // Ask libunwind to get next frame (skip over first which is |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 81 | // _Unwind_RaiseException). |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 82 | int stepResult = __unw_step(cursor); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 83 | if (stepResult == 0) { |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 84 | _LIBUNWIND_TRACE_UNWINDING( |
| 85 | "unwind_phase1(ex_ojb=%p): __unw_step() reached " |
| 86 | "bottom => _URC_END_OF_STACK", |
| 87 | (void *)exception_object); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 88 | return _URC_END_OF_STACK; |
| 89 | } else if (stepResult < 0) { |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 90 | _LIBUNWIND_TRACE_UNWINDING( |
| 91 | "unwind_phase1(ex_ojb=%p): __unw_step failed => " |
| 92 | "_URC_FATAL_PHASE1_ERROR", |
| 93 | (void *)exception_object); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 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); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 105 | return _URC_FATAL_PHASE1_ERROR; |
| 106 | } |
| 107 | |
Daniel Kiss | 7729bc9 | 2021-08-11 10:11:31 +0200 | [diff] [blame] | 108 | #ifndef NDEBUG |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 114 | if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf), |
| 115 | &offset) != UNW_ESUCCESS) || |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 116 | (frameInfo.start_ip + offset > frameInfo.end_ip)) |
| 117 | functionName = ".anonymous."; |
| 118 | unw_word_t pc; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 119 | __unw_get_reg(cursor, UNW_REG_IP, &pc); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 120 | _LIBUNWIND_TRACE_UNWINDING( |
Martin Storsjo | 97e2d98 | 2017-10-30 19:06:34 +0000 | [diff] [blame] | 121 | "unwind_phase1(ex_ojb=%p): pc=0x%" PRIxPTR ", start_ip=0x%" PRIxPTR |
| 122 | ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR "", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 123 | (void *)exception_object, pc, frameInfo.start_ip, functionName, |
| 124 | frameInfo.lsda, frameInfo.handler); |
| 125 | } |
Daniel Kiss | 7729bc9 | 2021-08-11 10:11:31 +0200 | [diff] [blame] | 126 | #endif |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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) { |
Saleem Abdulrasool | 214b72e | 2020-02-10 08:52:31 -0800 | [diff] [blame] | 131 | _Unwind_Personality_Fn p = |
| 132 | (_Unwind_Personality_Fn)(uintptr_t)(frameInfo.handler); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 133 | _LIBUNWIND_TRACE_UNWINDING( |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 134 | "unwind_phase1(ex_ojb=%p): calling personality function %p", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 135 | (void *)exception_object, (void *)(uintptr_t)p); |
| 136 | _Unwind_Reason_Code personalityResult = |
| 137 | (*p)(1, _UA_SEARCH_PHASE, exception_object->exception_class, |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 138 | exception_object, (struct _Unwind_Context *)(cursor)); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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 |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 143 | __unw_get_reg(cursor, UNW_REG_SP, &sp); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 144 | exception_object->private_2 = (uintptr_t)sp; |
| 145 | _LIBUNWIND_TRACE_UNWINDING( |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 146 | "unwind_phase1(ex_ojb=%p): _URC_HANDLER_FOUND", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 147 | (void *)exception_object); |
| 148 | return _URC_NO_REASON; |
| 149 | |
| 150 | case _URC_CONTINUE_UNWIND: |
| 151 | _LIBUNWIND_TRACE_UNWINDING( |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 152 | "unwind_phase1(ex_ojb=%p): _URC_CONTINUE_UNWIND", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 153 | (void *)exception_object); |
| 154 | // continue unwinding |
| 155 | break; |
| 156 | |
| 157 | default: |
| 158 | // something went wrong |
| 159 | _LIBUNWIND_TRACE_UNWINDING( |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 160 | "unwind_phase1(ex_ojb=%p): _URC_FATAL_PHASE1_ERROR", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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 |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 171 | unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception *exception_object) { |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 172 | __unw_init_local(cursor, uc); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 173 | |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 174 | _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 175 | (void *)exception_object); |
| 176 | |
gejin | 7f49316 | 2021-08-26 16:20:38 +0800 | [diff] [blame] | 177 | // uc is initialized by __unw_getcontext in the parent frame. The first stack |
| 178 | // frame walked is unwind_phase2. |
| 179 | unsigned framesWalked = 1; |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 180 | // Walk each frame until we reach where search phase said to stop. |
| 181 | while (true) { |
| 182 | |
Ed Maste | 6f72338 | 2016-08-30 13:08:21 +0000 | [diff] [blame] | 183 | // Ask libunwind to get next frame (skip over first which is |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 184 | // _Unwind_RaiseException). |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 185 | int stepResult = __unw_step(cursor); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 186 | if (stepResult == 0) { |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 187 | _LIBUNWIND_TRACE_UNWINDING( |
| 188 | "unwind_phase2(ex_ojb=%p): __unw_step() reached " |
| 189 | "bottom => _URC_END_OF_STACK", |
| 190 | (void *)exception_object); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 191 | return _URC_END_OF_STACK; |
| 192 | } else if (stepResult < 0) { |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 193 | _LIBUNWIND_TRACE_UNWINDING( |
| 194 | "unwind_phase2(ex_ojb=%p): __unw_step failed => " |
| 195 | "_URC_FATAL_PHASE1_ERROR", |
| 196 | (void *)exception_object); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 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); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 209 | return _URC_FATAL_PHASE2_ERROR; |
| 210 | } |
| 211 | |
Daniel Kiss | 7729bc9 | 2021-08-11 10:11:31 +0200 | [diff] [blame] | 212 | #ifndef NDEBUG |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 218 | if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf), |
| 219 | &offset) != UNW_ESUCCESS) || |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 220 | (frameInfo.start_ip + offset > frameInfo.end_ip)) |
| 221 | functionName = ".anonymous."; |
Martin Storsjo | 97e2d98 | 2017-10-30 19:06:34 +0000 | [diff] [blame] | 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, |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 225 | (void *)exception_object, frameInfo.start_ip, |
| 226 | functionName, sp, frameInfo.lsda, |
| 227 | frameInfo.handler); |
| 228 | } |
Daniel Kiss | 7729bc9 | 2021-08-11 10:11:31 +0200 | [diff] [blame] | 229 | #endif |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 230 | |
gejin | 7f49316 | 2021-08-26 16:20:38 +0800 | [diff] [blame] | 231 | ++framesWalked; |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 232 | // If there is a personality routine, tell it we are unwinding. |
| 233 | if (frameInfo.handler != 0) { |
Saleem Abdulrasool | 214b72e | 2020-02-10 08:52:31 -0800 | [diff] [blame] | 234 | _Unwind_Personality_Fn p = |
| 235 | (_Unwind_Personality_Fn)(uintptr_t)(frameInfo.handler); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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, |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 243 | (struct _Unwind_Context *)(cursor)); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 244 | switch (personalityResult) { |
| 245 | case _URC_CONTINUE_UNWIND: |
| 246 | // Continue unwinding |
| 247 | _LIBUNWIND_TRACE_UNWINDING( |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 248 | "unwind_phase2(ex_ojb=%p): _URC_CONTINUE_UNWIND", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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( |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 258 | "unwind_phase2(ex_ojb=%p): _URC_INSTALL_CONTEXT", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 264 | __unw_get_reg(cursor, UNW_REG_IP, &pc); |
| 265 | __unw_get_reg(cursor, UNW_REG_SP, &sp); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 266 | _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): re-entering " |
Martin Storsjo | 97e2d98 | 2017-10-30 19:06:34 +0000 | [diff] [blame] | 267 | "user code with ip=0x%" PRIxPTR |
| 268 | ", sp=0x%" PRIxPTR, |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 269 | (void *)exception_object, pc, sp); |
| 270 | } |
gejin | 7f49316 | 2021-08-26 16:20:38 +0800 | [diff] [blame] | 271 | |
| 272 | __unw_phase2_resume(cursor, framesWalked); |
| 273 | // __unw_phase2_resume() only returns if there was an error. |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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 |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 290 | unwind_phase2_forced(unw_context_t *uc, unw_cursor_t *cursor, |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 291 | _Unwind_Exception *exception_object, |
| 292 | _Unwind_Stop_Fn stop, void *stop_parameter) { |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 293 | __unw_init_local(cursor, uc); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 294 | |
gejin | 7f49316 | 2021-08-26 16:20:38 +0800 | [diff] [blame] | 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; |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 298 | // Walk each frame until we reach where search phase said to stop |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 299 | while (__unw_step(cursor) > 0) { |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 300 | |
| 301 | // Update info about this frame. |
| 302 | unw_proc_info_t frameInfo; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 303 | if (__unw_get_proc_info(cursor, &frameInfo) != UNW_ESUCCESS) { |
| 304 | _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): __unw_step " |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 305 | "failed => _URC_END_OF_STACK", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 306 | (void *)exception_object); |
| 307 | return _URC_FATAL_PHASE2_ERROR; |
| 308 | } |
| 309 | |
Daniel Kiss | 7729bc9 | 2021-08-11 10:11:31 +0200 | [diff] [blame] | 310 | #ifndef NDEBUG |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 316 | if ((__unw_get_proc_name(cursor, functionBuf, sizeof(functionBuf), |
| 317 | &offset) != UNW_ESUCCESS) || |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 318 | (frameInfo.start_ip + offset > frameInfo.end_ip)) |
| 319 | functionName = ".anonymous."; |
| 320 | _LIBUNWIND_TRACE_UNWINDING( |
Martin Storsjo | 97e2d98 | 2017-10-30 19:06:34 +0000 | [diff] [blame] | 321 | "unwind_phase2_forced(ex_ojb=%p): start_ip=0x%" PRIxPTR |
| 322 | ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR, |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 323 | (void *)exception_object, frameInfo.start_ip, functionName, |
| 324 | frameInfo.lsda, frameInfo.handler); |
| 325 | } |
Daniel Kiss | 7729bc9 | 2021-08-11 10:11:31 +0200 | [diff] [blame] | 326 | #endif |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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, |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 333 | (struct _Unwind_Context *)(cursor), stop_parameter); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 334 | _LIBUNWIND_TRACE_UNWINDING( |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 335 | "unwind_phase2_forced(ex_ojb=%p): stop function returned %d", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 336 | (void *)exception_object, stopResult); |
| 337 | if (stopResult != _URC_NO_REASON) { |
| 338 | _LIBUNWIND_TRACE_UNWINDING( |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 339 | "unwind_phase2_forced(ex_ojb=%p): stopped by stop function", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 340 | (void *)exception_object); |
| 341 | return _URC_FATAL_PHASE2_ERROR; |
| 342 | } |
| 343 | |
gejin | 7f49316 | 2021-08-26 16:20:38 +0800 | [diff] [blame] | 344 | ++framesWalked; |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 345 | // If there is a personality routine, tell it we are unwinding. |
| 346 | if (frameInfo.handler != 0) { |
Saleem Abdulrasool | 214b72e | 2020-02-10 08:52:31 -0800 | [diff] [blame] | 347 | _Unwind_Personality_Fn p = |
| 348 | (_Unwind_Personality_Fn)(intptr_t)(frameInfo.handler); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 349 | _LIBUNWIND_TRACE_UNWINDING( |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 350 | "unwind_phase2_forced(ex_ojb=%p): calling personality function %p", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 351 | (void *)exception_object, (void *)(uintptr_t)p); |
| 352 | _Unwind_Reason_Code personalityResult = |
| 353 | (*p)(1, action, exception_object->exception_class, exception_object, |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 354 | (struct _Unwind_Context *)(cursor)); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 355 | switch (personalityResult) { |
| 356 | case _URC_CONTINUE_UNWIND: |
| 357 | _LIBUNWIND_TRACE_UNWINDING("unwind_phase2_forced(ex_ojb=%p): " |
| 358 | "personality returned " |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 359 | "_URC_CONTINUE_UNWIND", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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 " |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 366 | "_URC_INSTALL_CONTEXT", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 367 | (void *)exception_object); |
| 368 | // We may get control back if landing pad calls _Unwind_Resume(). |
gejin | 7f49316 | 2021-08-26 16:20:38 +0800 | [diff] [blame] | 369 | __unw_phase2_resume(cursor, framesWalked); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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, " |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 375 | "_URC_FATAL_PHASE2_ERROR", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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 " |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 385 | "function with _UA_END_OF_STACK", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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, |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 390 | (struct _Unwind_Context *)(cursor), stop_parameter); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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) { |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 401 | _LIBUNWIND_TRACE_API("_Unwind_RaiseException(ex_obj=%p)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 402 | (void *)exception_object); |
| 403 | unw_context_t uc; |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 404 | unw_cursor_t cursor; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 405 | __unw_getcontext(&uc); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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 |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 413 | _Unwind_Reason_Code phase1 = unwind_phase1(&uc, &cursor, exception_object); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 414 | if (phase1 != _URC_NO_REASON) |
| 415 | return phase1; |
| 416 | |
| 417 | // phase 2: the clean up phase |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 418 | return unwind_phase2(&uc, &cursor, exception_object); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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) { |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 436 | _LIBUNWIND_TRACE_API("_Unwind_Resume(ex_obj=%p)", (void *)exception_object); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 437 | unw_context_t uc; |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 438 | unw_cursor_t cursor; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 439 | __unw_getcontext(&uc); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 440 | |
| 441 | if (exception_object->private_1 != 0) |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 442 | unwind_phase2_forced(&uc, &cursor, exception_object, |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 443 | (_Unwind_Stop_Fn) exception_object->private_1, |
| 444 | (void *)exception_object->private_2); |
| 445 | else |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 446 | unwind_phase2(&uc, &cursor, exception_object); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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) { |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 460 | _LIBUNWIND_TRACE_API("_Unwind_ForcedUnwind(ex_obj=%p, stop=%p)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 461 | (void *)exception_object, (void *)(uintptr_t)stop); |
| 462 | unw_context_t uc; |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 463 | unw_cursor_t cursor; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 464 | __unw_getcontext(&uc); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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 |
Asiri Rathnayake | 2ae6e62 | 2016-06-14 15:51:01 +0000 | [diff] [blame] | 472 | return unwind_phase2_forced(&uc, &cursor, exception_object, stop, stop_parameter); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 482 | if (__unw_get_proc_info(cursor, &frameInfo) == UNW_ESUCCESS) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 483 | result = (uintptr_t)frameInfo.lsda; |
| 484 | _LIBUNWIND_TRACE_API( |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 485 | "_Unwind_GetLanguageSpecificData(context=%p) => 0x%" PRIxPTR, |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 486 | (void *)context, result); |
Xing Xue | bbcbce9 | 2022-04-13 11:01:59 -0400 | [diff] [blame] | 487 | #if !defined(_LIBUNWIND_SUPPORT_TBTAB_UNWIND) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 488 | if (result != 0) { |
| 489 | if (*((uint8_t *)result) != 0xFF) |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 490 | _LIBUNWIND_DEBUG_LOG("lsda at 0x%" PRIxPTR " does not start with 0xFF", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 491 | result); |
| 492 | } |
Xing Xue | bbcbce9 | 2022-04-13 11:01:59 -0400 | [diff] [blame] | 493 | #endif |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 505 | if (__unw_get_proc_info(cursor, &frameInfo) == UNW_ESUCCESS) |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 506 | result = (uintptr_t)frameInfo.start_ip; |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 507 | _LIBUNWIND_TRACE_API("_Unwind_GetRegionStart(context=%p) => 0x%" PRIxPTR, |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 508 | (void *)context, result); |
| 509 | return result; |
| 510 | } |
| 511 | |
Charles Davis | fa2e620 | 2018-08-30 21:29:00 +0000 | [diff] [blame] | 512 | #endif // !_LIBUNWIND_SUPPORT_SEH_UNWIND |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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) { |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 518 | _LIBUNWIND_TRACE_API("_Unwind_DeleteException(ex_obj=%p)", |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 530 | __unw_get_reg(cursor, index, &result); |
Martin Storsjo | 97e2d98 | 2017-10-30 19:06:34 +0000 | [diff] [blame] | 531 | _LIBUNWIND_TRACE_API("_Unwind_GetGR(context=%p, reg=%d) => 0x%" PRIxPTR, |
| 532 | (void *)context, index, result); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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) { |
Martin Storsjo | 97e2d98 | 2017-10-30 19:06:34 +0000 | [diff] [blame] | 539 | _LIBUNWIND_TRACE_API("_Unwind_SetGR(context=%p, reg=%d, value=0x%0" PRIxPTR |
Ed Maste | 41bc5a7 | 2016-08-30 15:38:10 +0000 | [diff] [blame] | 540 | ")", |
Martin Storsjo | 97e2d98 | 2017-10-30 19:06:34 +0000 | [diff] [blame] | 541 | (void *)context, index, value); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 542 | unw_cursor_t *cursor = (unw_cursor_t *)context; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 543 | __unw_set_reg(cursor, index, value); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 550 | __unw_get_reg(cursor, UNW_REG_IP, &result); |
Martin Storsjo | 97e2d98 | 2017-10-30 19:06:34 +0000 | [diff] [blame] | 551 | _LIBUNWIND_TRACE_API("_Unwind_GetIP(context=%p) => 0x%" PRIxPTR, |
| 552 | (void *)context, result); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 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) { |
Martin Storsjo | 97e2d98 | 2017-10-30 19:06:34 +0000 | [diff] [blame] | 561 | _LIBUNWIND_TRACE_API("_Unwind_SetIP(context=%p, value=0x%0" PRIxPTR ")", |
| 562 | (void *)context, value); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 563 | unw_cursor_t *cursor = (unw_cursor_t *)context; |
Petr Hosek | 9bbfad5 | 2019-04-03 21:50:03 +0000 | [diff] [blame] | 564 | __unw_set_reg(cursor, UNW_REG_IP, value); |
Saleem Abdulrasool | 1755266 | 2015-04-24 19:39:17 +0000 | [diff] [blame] | 565 | } |
| 566 | |
Martin Storsjo | 9f16c6c | 2017-09-26 08:07:26 +0000 | [diff] [blame] | 567 | #endif // !defined(_LIBUNWIND_ARM_EHABI) && !defined(__USING_SJLJ_EXCEPTIONS__) |