| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | #ifndef __CLANG_UNWIND_H |
| 27 | #define __CLANG_UNWIND_H |
| 28 | |
| 29 | #if defined(__APPLE__) && __has_include_next(<unwind.h>) |
| 30 | |
| 31 | |
| 32 | |
| 33 | # ifndef _GNU_SOURCE |
| 34 | # define _SHOULD_UNDEFINE_GNU_SOURCE |
| 35 | # define _GNU_SOURCE |
| 36 | # endif |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | # ifdef HIDE_EXPORTS |
| 44 | # include_next <unwind.h> |
| 45 | # else |
| 46 | # pragma GCC visibility push(default) |
| 47 | # include_next <unwind.h> |
| 48 | # pragma GCC visibility pop |
| 49 | # endif |
| 50 | # ifdef _SHOULD_UNDEFINE_GNU_SOURCE |
| 51 | # undef _GNU_SOURCE |
| 52 | # undef _SHOULD_UNDEFINE_GNU_SOURCE |
| 53 | # endif |
| 54 | #else |
| 55 | |
| 56 | #include <stdint.h> |
| 57 | |
| 58 | #ifdef __cplusplus |
| 59 | extern "C" { |
| 60 | #endif |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | #ifndef HIDE_EXPORTS |
| 66 | #pragma GCC visibility push(default) |
| 67 | #endif |
| 68 | |
| 69 | typedef uintptr_t _Unwind_Word __attribute__((__mode__(__unwind_word__))); |
| 70 | typedef intptr_t _Unwind_Sword __attribute__((__mode__(__unwind_word__))); |
| 71 | typedef uintptr_t _Unwind_Ptr; |
| 72 | typedef uintptr_t _Unwind_Internal_Ptr; |
| 73 | typedef uint64_t _Unwind_Exception_Class; |
| 74 | |
| 75 | typedef intptr_t _sleb128_t; |
| 76 | typedef uintptr_t _uleb128_t; |
| 77 | |
| 78 | struct _Unwind_Context; |
| 79 | #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__)) |
| 80 | struct _Unwind_Control_Block; |
| 81 | typedef struct _Unwind_Control_Block _Unwind_Exception; |
| 82 | #else |
| 83 | struct _Unwind_Exception; |
| 84 | typedef struct _Unwind_Exception _Unwind_Exception; |
| 85 | #endif |
| 86 | typedef enum { |
| 87 | _URC_NO_REASON = 0, |
| 88 | #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \ |
| 89 | !defined(__ARM_DWARF_EH__) |
| 90 | _URC_OK = 0, |
| 91 | #endif |
| 92 | _URC_FOREIGN_EXCEPTION_CAUGHT = 1, |
| 93 | |
| 94 | _URC_FATAL_PHASE2_ERROR = 2, |
| 95 | _URC_FATAL_PHASE1_ERROR = 3, |
| 96 | _URC_NORMAL_STOP = 4, |
| 97 | |
| 98 | _URC_END_OF_STACK = 5, |
| 99 | _URC_HANDLER_FOUND = 6, |
| 100 | _URC_INSTALL_CONTEXT = 7, |
| 101 | _URC_CONTINUE_UNWIND = 8, |
| 102 | #if defined(__arm__) && !defined(__USING_SJLJ_EXCEPTIONS__) && \ |
| 103 | !defined(__ARM_DWARF_EH__) |
| 104 | _URC_FAILURE = 9 |
| 105 | #endif |
| 106 | } _Unwind_Reason_Code; |
| 107 | |
| 108 | typedef enum { |
| 109 | _UA_SEARCH_PHASE = 1, |
| 110 | _UA_CLEANUP_PHASE = 2, |
| 111 | |
| 112 | _UA_HANDLER_FRAME = 4, |
| 113 | _UA_FORCE_UNWIND = 8, |
| 114 | _UA_END_OF_STACK = 16 |
| 115 | } _Unwind_Action; |
| 116 | |
| 117 | typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code, |
| 118 | _Unwind_Exception *); |
| 119 | |
| 120 | #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__)) |
| 121 | typedef struct _Unwind_Control_Block _Unwind_Control_Block; |
| 122 | typedef uint32_t _Unwind_EHT_Header; |
| 123 | |
| 124 | struct _Unwind_Control_Block { |
| 125 | uint64_t exception_class; |
| 126 | void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block *); |
| 127 | |
| 128 | struct { |
| 129 | uint32_t reserved1; |
| 130 | uint32_t reserved2; |
| 131 | uint32_t reserved3; |
| 132 | uint32_t reserved4; |
| 133 | uint32_t reserved5; |
| 134 | } unwinder_cache; |
| 135 | |
| 136 | struct { |
| 137 | uint32_t sp; |
| 138 | uint32_t bitpattern[5]; |
| 139 | } barrier_cache; |
| 140 | |
| 141 | struct { |
| 142 | uint32_t bitpattern[4]; |
| 143 | } cleanup_cache; |
| 144 | |
| 145 | struct { |
| 146 | uint32_t fnstart; |
| 147 | _Unwind_EHT_Header *ehtp; |
| 148 | uint32_t additional; |
| 149 | uint32_t reserved1; |
| 150 | } pr_cache; |
| 151 | long long int : 0; |
| 152 | } __attribute__((__aligned__(8))); |
| 153 | #else |
| 154 | struct _Unwind_Exception { |
| 155 | _Unwind_Exception_Class exception_class; |
| 156 | _Unwind_Exception_Cleanup_Fn exception_cleanup; |
| 157 | #if !defined (__USING_SJLJ_EXCEPTIONS__) && defined (__SEH__) |
| 158 | _Unwind_Word private_[6]; |
| 159 | #else |
| 160 | _Unwind_Word private_1; |
| 161 | _Unwind_Word private_2; |
| 162 | #endif |
| 163 | |
| 164 | |
| 165 | |
| 166 | } __attribute__((__aligned__)); |
| 167 | #endif |
| 168 | |
| 169 | typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)(int, _Unwind_Action, |
| 170 | _Unwind_Exception_Class, |
| 171 | _Unwind_Exception *, |
| 172 | struct _Unwind_Context *, |
| 173 | void *); |
| 174 | |
| 175 | typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(int, _Unwind_Action, |
| 176 | _Unwind_Exception_Class, |
| 177 | _Unwind_Exception *, |
| 178 | struct _Unwind_Context *); |
| 179 | typedef _Unwind_Personality_Fn __personality_routine; |
| 180 | |
| 181 | typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *, |
| 182 | void *); |
| 183 | |
| 184 | #if defined(__arm__) && !(defined(__USING_SJLJ_EXCEPTIONS__) || defined(__ARM_DWARF_EH__)) |
| 185 | typedef enum { |
| 186 | _UVRSC_CORE = 0, |
| 187 | _UVRSC_VFP = 1, |
| 188 | _UVRSC_WMMXD = 3, |
| 189 | _UVRSC_WMMXC = 4 |
| 190 | } _Unwind_VRS_RegClass; |
| 191 | |
| 192 | typedef enum { |
| 193 | _UVRSD_UINT32 = 0, |
| 194 | _UVRSD_VFPX = 1, |
| 195 | _UVRSD_UINT64 = 3, |
| 196 | _UVRSD_FLOAT = 4, |
| 197 | _UVRSD_DOUBLE = 5 |
| 198 | } _Unwind_VRS_DataRepresentation; |
| 199 | |
| 200 | typedef enum { |
| 201 | _UVRSR_OK = 0, |
| 202 | _UVRSR_NOT_IMPLEMENTED = 1, |
| 203 | _UVRSR_FAILED = 2 |
| 204 | } _Unwind_VRS_Result; |
| 205 | |
| 206 | typedef uint32_t _Unwind_State; |
| 207 | #define _US_VIRTUAL_UNWIND_FRAME ((_Unwind_State)0) |
| 208 | #define _US_UNWIND_FRAME_STARTING ((_Unwind_State)1) |
| 209 | #define _US_UNWIND_FRAME_RESUME ((_Unwind_State)2) |
| 210 | #define _US_ACTION_MASK ((_Unwind_State)3) |
| 211 | #define _US_FORCE_UNWIND ((_Unwind_State)8) |
| 212 | |
| 213 | _Unwind_VRS_Result _Unwind_VRS_Get(struct _Unwind_Context *__context, |
| 214 | _Unwind_VRS_RegClass __regclass, |
| 215 | uint32_t __regno, |
| 216 | _Unwind_VRS_DataRepresentation __representation, |
| 217 | void *__valuep); |
| 218 | |
| 219 | _Unwind_VRS_Result _Unwind_VRS_Set(struct _Unwind_Context *__context, |
| 220 | _Unwind_VRS_RegClass __regclass, |
| 221 | uint32_t __regno, |
| 222 | _Unwind_VRS_DataRepresentation __representation, |
| 223 | void *__valuep); |
| 224 | |
| 225 | static __inline__ |
| 226 | _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *__context, int __index) { |
| 227 | _Unwind_Word __value; |
| 228 | _Unwind_VRS_Get(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value); |
| 229 | return __value; |
| 230 | } |
| 231 | |
| 232 | static __inline__ |
| 233 | void _Unwind_SetGR(struct _Unwind_Context *__context, int __index, |
| 234 | _Unwind_Word __value) { |
| 235 | _Unwind_VRS_Set(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value); |
| 236 | } |
| 237 | |
| 238 | static __inline__ |
| 239 | _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *__context) { |
| 240 | _Unwind_Word __ip = _Unwind_GetGR(__context, 15); |
| 241 | return __ip & ~(_Unwind_Word)(0x1); |
| 242 | } |
| 243 | |
| 244 | static __inline__ |
| 245 | void _Unwind_SetIP(struct _Unwind_Context *__context, _Unwind_Word __value) { |
| 246 | _Unwind_Word __thumb_mode_bit = _Unwind_GetGR(__context, 15) & 0x1; |
| 247 | _Unwind_SetGR(__context, 15, __value | __thumb_mode_bit); |
| 248 | } |
| 249 | #else |
| 250 | _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *, int); |
| 251 | void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Word); |
| 252 | |
| 253 | _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *); |
| 254 | void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Word); |
| 255 | #endif |
| 256 | |
| 257 | |
| 258 | _Unwind_Word _Unwind_GetIPInfo(struct _Unwind_Context *, int *); |
| 259 | |
| 260 | _Unwind_Word _Unwind_GetCFA(struct _Unwind_Context *); |
| 261 | |
| 262 | _Unwind_Word _Unwind_GetBSP(struct _Unwind_Context *); |
| 263 | |
| 264 | void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *); |
| 265 | |
| 266 | _Unwind_Ptr _Unwind_GetRegionStart(struct _Unwind_Context *); |
| 267 | |
| 268 | |
| 269 | #if !defined(__APPLE__) || !defined(__arm__) |
| 270 | _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Exception *); |
| 271 | _Unwind_Reason_Code _Unwind_ForcedUnwind(_Unwind_Exception *, _Unwind_Stop_Fn, |
| 272 | void *); |
| 273 | void _Unwind_DeleteException(_Unwind_Exception *); |
| 274 | void _Unwind_Resume(_Unwind_Exception *); |
| 275 | _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception *); |
| 276 | |
| 277 | #endif |
| 278 | |
| 279 | _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *); |
| 280 | |
| 281 | |
| 282 | typedef struct SjLj_Function_Context *_Unwind_FunctionContext_t; |
| 283 | |
| 284 | void _Unwind_SjLj_Register(_Unwind_FunctionContext_t); |
| 285 | void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t); |
| 286 | _Unwind_Reason_Code _Unwind_SjLj_RaiseException(_Unwind_Exception *); |
| 287 | _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(_Unwind_Exception *, |
| 288 | _Unwind_Stop_Fn, void *); |
| 289 | void _Unwind_SjLj_Resume(_Unwind_Exception *); |
| 290 | _Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(_Unwind_Exception *); |
| 291 | |
| 292 | void *_Unwind_FindEnclosingFunction(void *); |
| 293 | |
| 294 | #ifdef __APPLE__ |
| 295 | |
| 296 | _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *) |
| 297 | __attribute__((__unavailable__)); |
| 298 | _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *) |
| 299 | __attribute__((__unavailable__)); |
| 300 | |
| 301 | |
| 302 | void __register_frame(const void *); |
| 303 | void __deregister_frame(const void *); |
| 304 | |
| 305 | struct dwarf_eh_bases { |
| 306 | uintptr_t tbase; |
| 307 | uintptr_t dbase; |
| 308 | uintptr_t func; |
| 309 | }; |
| 310 | void *_Unwind_Find_FDE(const void *, struct dwarf_eh_bases *); |
| 311 | |
| 312 | void __register_frame_info_bases(const void *, void *, void *, void *) |
| 313 | __attribute__((__unavailable__)); |
| 314 | void __register_frame_info(const void *, void *) __attribute__((__unavailable__)); |
| 315 | void __register_frame_info_table_bases(const void *, void*, void *, void *) |
| 316 | __attribute__((__unavailable__)); |
| 317 | void __register_frame_info_table(const void *, void *) |
| 318 | __attribute__((__unavailable__)); |
| 319 | void __register_frame_table(const void *) __attribute__((__unavailable__)); |
| 320 | void __deregister_frame_info(const void *) __attribute__((__unavailable__)); |
| 321 | void __deregister_frame_info_bases(const void *)__attribute__((__unavailable__)); |
| 322 | |
| 323 | #else |
| 324 | |
| 325 | _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *); |
| 326 | _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *); |
| 327 | |
| 328 | #endif |
| 329 | |
| 330 | |
| 331 | #ifndef HIDE_EXPORTS |
| 332 | #pragma GCC visibility pop |
| 333 | #endif |
| 334 | |
| 335 | #ifdef __cplusplus |
| 336 | } |
| 337 | #endif |
| 338 | |
| 339 | #endif |
| 340 | |
| 341 | #endif |
| 342 | |