Rafael Espindola | d85c1e9 | 2011-12-08 05:01:39 +0000 | [diff] [blame] | 1 | /*===---- unwind.h - Stack unwinding ----------------------------------------=== |
| 2 | * |
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 4 | * of this software and associated documentation files (the "Software"), to deal |
| 5 | * in the Software without restriction, including without limitation the rights |
| 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 7 | * copies of the Software, and to permit persons to whom the Software is |
| 8 | * furnished to do so, subject to the following conditions: |
| 9 | * |
| 10 | * The above copyright notice and this permission notice shall be included in |
| 11 | * all copies or substantial portions of the Software. |
| 12 | * |
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 19 | * THE SOFTWARE. |
| 20 | * |
| 21 | *===-----------------------------------------------------------------------=== |
| 22 | */ |
| 23 | |
| 24 | /* See "Data Definitions for libgcc_s" in the Linux Standard Base.*/ |
| 25 | |
Benjamin Kramer | ccdb2a5 | 2013-01-09 19:54:57 +0000 | [diff] [blame] | 26 | #ifndef __CLANG_UNWIND_H |
| 27 | #define __CLANG_UNWIND_H |
| 28 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 29 | #if defined(__APPLE__) && __has_include_next(<unwind.h>) |
| 30 | /* Darwin (from 11.x on) provide an unwind.h. If that's available, |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 31 | * use it. libunwind wraps some of its definitions in #ifdef _GNU_SOURCE, |
Jeffrey Yasskin | f18a87b | 2012-02-21 16:20:12 +0000 | [diff] [blame] | 32 | * so define that around the include.*/ |
| 33 | # ifndef _GNU_SOURCE |
| 34 | # define _SHOULD_UNDEFINE_GNU_SOURCE |
| 35 | # define _GNU_SOURCE |
| 36 | # endif |
Rafael Espindola | be5ff2f | 2012-03-29 03:37:17 +0000 | [diff] [blame] | 37 | // libunwind's unwind.h reflects the current visibility. However, Mozilla |
| 38 | // builds with -fvisibility=hidden and relies on gcc's unwind.h to reset the |
| 39 | // visibility to default and export its contents. gcc also allows users to |
| 40 | // override its override by #defining HIDE_EXPORTS (but note, this only obeys |
| 41 | // the user's -fvisibility setting; it doesn't hide any exports on its own). We |
| 42 | // imitate gcc's header here: |
| 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 |
Jeffrey Yasskin | f18a87b | 2012-02-21 16:20:12 +0000 | [diff] [blame] | 50 | # ifdef _SHOULD_UNDEFINE_GNU_SOURCE |
| 51 | # undef _GNU_SOURCE |
| 52 | # undef _SHOULD_UNDEFINE_GNU_SOURCE |
| 53 | # endif |
Rafael Espindola | d85c1e9 | 2011-12-08 05:01:39 +0000 | [diff] [blame] | 54 | #else |
| 55 | |
| 56 | #include <stdint.h> |
| 57 | |
| 58 | #ifdef __cplusplus |
| 59 | extern "C" { |
| 60 | #endif |
| 61 | |
Rafael Espindola | 9b7568d | 2011-12-09 00:08:01 +0000 | [diff] [blame] | 62 | /* It is a bit strange for a header to play with the visibility of the |
| 63 | symbols it declares, but this matches gcc's behavior and some programs |
| 64 | depend on it */ |
Benjamin Kramer | ccdb2a5 | 2013-01-09 19:54:57 +0000 | [diff] [blame] | 65 | #ifndef HIDE_EXPORTS |
Rafael Espindola | 9b7568d | 2011-12-09 00:08:01 +0000 | [diff] [blame] | 66 | #pragma GCC visibility push(default) |
Benjamin Kramer | ccdb2a5 | 2013-01-09 19:54:57 +0000 | [diff] [blame] | 67 | #endif |
Rafael Espindola | 9b7568d | 2011-12-09 00:08:01 +0000 | [diff] [blame] | 68 | |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 69 | typedef uintptr_t _Unwind_Word; |
| 70 | typedef intptr_t _Unwind_Sword; |
| 71 | typedef uintptr_t _Unwind_Ptr; |
| 72 | typedef uintptr_t _Unwind_Internal_Ptr; |
| 73 | typedef uint64_t _Unwind_Exception_Class; |
| 74 | |
Peter Collingbourne | 347124d | 2013-08-29 01:56:22 +0000 | [diff] [blame] | 75 | typedef intptr_t _sleb128_t; |
| 76 | typedef uintptr_t _uleb128_t; |
| 77 | |
Rafael Espindola | d85c1e9 | 2011-12-08 05:01:39 +0000 | [diff] [blame] | 78 | struct _Unwind_Context; |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 79 | struct _Unwind_Exception; |
Rafael Espindola | d85c1e9 | 2011-12-08 05:01:39 +0000 | [diff] [blame] | 80 | typedef enum { |
| 81 | _URC_NO_REASON = 0, |
| 82 | _URC_FOREIGN_EXCEPTION_CAUGHT = 1, |
| 83 | |
| 84 | _URC_FATAL_PHASE2_ERROR = 2, |
| 85 | _URC_FATAL_PHASE1_ERROR = 3, |
| 86 | _URC_NORMAL_STOP = 4, |
| 87 | |
| 88 | _URC_END_OF_STACK = 5, |
| 89 | _URC_HANDLER_FOUND = 6, |
| 90 | _URC_INSTALL_CONTEXT = 7, |
| 91 | _URC_CONTINUE_UNWIND = 8 |
| 92 | } _Unwind_Reason_Code; |
| 93 | |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 94 | typedef enum { |
| 95 | _UA_SEARCH_PHASE = 1, |
| 96 | _UA_CLEANUP_PHASE = 2, |
| 97 | |
| 98 | _UA_HANDLER_FRAME = 4, |
| 99 | _UA_FORCE_UNWIND = 8, |
| 100 | _UA_END_OF_STACK = 16 /* gcc extension to C++ ABI */ |
| 101 | } _Unwind_Action; |
| 102 | |
| 103 | typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code, |
| 104 | struct _Unwind_Exception *); |
| 105 | |
| 106 | struct _Unwind_Exception { |
| 107 | _Unwind_Exception_Class exception_class; |
| 108 | _Unwind_Exception_Cleanup_Fn exception_cleanup; |
| 109 | _Unwind_Word private_1; |
| 110 | _Unwind_Word private_2; |
| 111 | /* The Itanium ABI requires that _Unwind_Exception objects are "double-word |
| 112 | * aligned". GCC has interpreted this to mean "use the maximum useful |
| 113 | * alignment for the target"; so do we. */ |
| 114 | } __attribute__((__aligned__)); |
| 115 | |
| 116 | typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)(int, _Unwind_Action, |
| 117 | _Unwind_Exception_Class, |
| 118 | struct _Unwind_Exception *, |
| 119 | struct _Unwind_Context *, |
| 120 | void *); |
| 121 | |
Peter Collingbourne | 112586c | 2013-08-28 23:32:22 +0000 | [diff] [blame] | 122 | typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)( |
| 123 | int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *, |
| 124 | struct _Unwind_Context *); |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 125 | typedef _Unwind_Personality_Fn __personality_routine; |
| 126 | |
Peter Collingbourne | 112586c | 2013-08-28 23:32:22 +0000 | [diff] [blame] | 127 | typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *, |
| 128 | void *); |
Evgeniy Stepanov | f5f18bf | 2012-01-19 11:39:05 +0000 | [diff] [blame] | 129 | |
Hans Wennborg | e7346c1 | 2013-09-25 22:34:03 +0000 | [diff] [blame] | 130 | #if defined(__arm__) && !defined(__APPLE__) |
Evgeniy Stepanov | f5f18bf | 2012-01-19 11:39:05 +0000 | [diff] [blame] | 131 | |
Logan Chien | 38c5d0a | 2012-11-14 06:33:58 +0000 | [diff] [blame] | 132 | typedef enum { |
| 133 | _UVRSC_CORE = 0, /* integer register */ |
| 134 | _UVRSC_VFP = 1, /* vfp */ |
| 135 | _UVRSC_WMMXD = 3, /* Intel WMMX data register */ |
| 136 | _UVRSC_WMMXC = 4 /* Intel WMMX control register */ |
| 137 | } _Unwind_VRS_RegClass; |
Evgeniy Stepanov | f5f18bf | 2012-01-19 11:39:05 +0000 | [diff] [blame] | 138 | |
Logan Chien | 38c5d0a | 2012-11-14 06:33:58 +0000 | [diff] [blame] | 139 | typedef enum { |
| 140 | _UVRSD_UINT32 = 0, |
| 141 | _UVRSD_VFPX = 1, |
| 142 | _UVRSD_UINT64 = 3, |
| 143 | _UVRSD_FLOAT = 4, |
| 144 | _UVRSD_DOUBLE = 5 |
| 145 | } _Unwind_VRS_DataRepresentation; |
Evgeniy Stepanov | f5f18bf | 2012-01-19 11:39:05 +0000 | [diff] [blame] | 146 | |
Logan Chien | 38c5d0a | 2012-11-14 06:33:58 +0000 | [diff] [blame] | 147 | typedef enum { |
| 148 | _UVRSR_OK = 0, |
| 149 | _UVRSR_NOT_IMPLEMENTED = 1, |
| 150 | _UVRSR_FAILED = 2 |
| 151 | } _Unwind_VRS_Result; |
Evgeniy Stepanov | f5f18bf | 2012-01-19 11:39:05 +0000 | [diff] [blame] | 152 | |
David Blaikie | 4f918ae | 2013-01-16 23:08:36 +0000 | [diff] [blame] | 153 | _Unwind_VRS_Result _Unwind_VRS_Get(struct _Unwind_Context *__context, |
| 154 | _Unwind_VRS_RegClass __regclass, |
| 155 | uint32_t __regno, |
| 156 | _Unwind_VRS_DataRepresentation __representation, |
| 157 | void *__valuep); |
Evgeniy Stepanov | f5f18bf | 2012-01-19 11:39:05 +0000 | [diff] [blame] | 158 | |
Hans Wennborg | e7346c1 | 2013-09-25 22:34:03 +0000 | [diff] [blame] | 159 | _Unwind_VRS_Result _Unwind_VRS_Set(struct _Unwind_Context *__context, |
| 160 | _Unwind_VRS_RegClass __regclass, |
| 161 | uint32_t __regno, |
| 162 | _Unwind_VRS_DataRepresentation __representation, |
| 163 | void *__valuep); |
Evgeniy Stepanov | f5f18bf | 2012-01-19 11:39:05 +0000 | [diff] [blame] | 164 | |
Hans Wennborg | e7346c1 | 2013-09-25 22:34:03 +0000 | [diff] [blame] | 165 | static __inline__ |
| 166 | _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *__context, int __index) { |
| 167 | _Unwind_Word __value; |
| 168 | _Unwind_VRS_Get(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value); |
| 169 | return __value; |
| 170 | } |
| 171 | |
| 172 | static __inline__ |
| 173 | void _Unwind_SetGR(struct _Unwind_Context *__context, int __index, |
| 174 | _Unwind_Word __value) { |
| 175 | _Unwind_VRS_Set(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value); |
| 176 | } |
| 177 | |
| 178 | static __inline__ |
| 179 | _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *__context) { |
| 180 | _Unwind_Word __ip = _Unwind_GetGR(__context, 15); |
| 181 | return __ip & ~(_Unwind_Word)(0x1); /* Remove thumb mode bit. */ |
| 182 | } |
| 183 | |
| 184 | static __inline__ |
| 185 | void _Unwind_SetIP(struct _Unwind_Context *__context, _Unwind_Word __value) { |
| 186 | _Unwind_Word __thumb_mode_bit = _Unwind_GetGR(__context, 15) & 0x1; |
| 187 | _Unwind_SetGR(__context, 15, __value | __thumb_mode_bit); |
| 188 | } |
| 189 | #else |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 190 | _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *, int); |
| 191 | void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Word); |
| 192 | |
| 193 | _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *); |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 194 | void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Word); |
Hans Wennborg | e7346c1 | 2013-09-25 22:34:03 +0000 | [diff] [blame] | 195 | #endif |
| 196 | |
| 197 | |
| 198 | _Unwind_Word _Unwind_GetIPInfo(struct _Unwind_Context *, int *); |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 199 | |
| 200 | _Unwind_Word _Unwind_GetCFA(struct _Unwind_Context *); |
| 201 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 202 | _Unwind_Word _Unwind_GetBSP(struct _Unwind_Context *); |
| 203 | |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 204 | void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *); |
| 205 | |
| 206 | _Unwind_Ptr _Unwind_GetRegionStart(struct _Unwind_Context *); |
| 207 | |
| 208 | /* DWARF EH functions; currently not available on Darwin/ARM */ |
| 209 | #if !defined(__APPLE__) || !defined(__arm__) |
| 210 | |
| 211 | _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *); |
Peter Collingbourne | 112586c | 2013-08-28 23:32:22 +0000 | [diff] [blame] | 212 | _Unwind_Reason_Code _Unwind_ForcedUnwind(struct _Unwind_Exception *, |
| 213 | _Unwind_Stop_Fn, void *); |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 214 | void _Unwind_DeleteException(struct _Unwind_Exception *); |
| 215 | void _Unwind_Resume(struct _Unwind_Exception *); |
| 216 | _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(struct _Unwind_Exception *); |
Evgeniy Stepanov | f5f18bf | 2012-01-19 11:39:05 +0000 | [diff] [blame] | 217 | |
| 218 | #endif |
| 219 | |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 220 | _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *); |
| 221 | |
| 222 | /* setjmp(3)/longjmp(3) stuff */ |
| 223 | typedef struct SjLj_Function_Context *_Unwind_FunctionContext_t; |
| 224 | |
| 225 | void _Unwind_SjLj_Register(_Unwind_FunctionContext_t); |
| 226 | void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t); |
| 227 | _Unwind_Reason_Code _Unwind_SjLj_RaiseException(struct _Unwind_Exception *); |
Peter Collingbourne | 112586c | 2013-08-28 23:32:22 +0000 | [diff] [blame] | 228 | _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(struct _Unwind_Exception *, |
| 229 | _Unwind_Stop_Fn, void *); |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 230 | void _Unwind_SjLj_Resume(struct _Unwind_Exception *); |
| 231 | _Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(struct _Unwind_Exception *); |
| 232 | |
| 233 | void *_Unwind_FindEnclosingFunction(void *); |
| 234 | |
| 235 | #ifdef __APPLE__ |
| 236 | |
Peter Collingbourne | 112586c | 2013-08-28 23:32:22 +0000 | [diff] [blame] | 237 | _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *) |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 238 | __attribute__((__unavailable__)); |
Peter Collingbourne | 112586c | 2013-08-28 23:32:22 +0000 | [diff] [blame] | 239 | _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *) |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 240 | __attribute__((__unavailable__)); |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 241 | |
| 242 | /* Darwin-specific functions */ |
| 243 | void __register_frame(const void *); |
| 244 | void __deregister_frame(const void *); |
| 245 | |
| 246 | struct dwarf_eh_bases { |
| 247 | uintptr_t tbase; |
| 248 | uintptr_t dbase; |
| 249 | uintptr_t func; |
| 250 | }; |
| 251 | void *_Unwind_Find_FDE(const void *, struct dwarf_eh_bases *); |
| 252 | |
| 253 | void __register_frame_info_bases(const void *, void *, void *, void *) |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 254 | __attribute__((__unavailable__)); |
| 255 | void __register_frame_info(const void *, void *) __attribute__((__unavailable__)); |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 256 | void __register_frame_info_table_bases(const void *, void*, void *, void *) |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 257 | __attribute__((__unavailable__)); |
Peter Collingbourne | 112586c | 2013-08-28 23:32:22 +0000 | [diff] [blame] | 258 | void __register_frame_info_table(const void *, void *) |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 259 | __attribute__((__unavailable__)); |
| 260 | void __register_frame_table(const void *) __attribute__((__unavailable__)); |
| 261 | void __deregister_frame_info(const void *) __attribute__((__unavailable__)); |
| 262 | void __deregister_frame_info_bases(const void *)__attribute__((__unavailable__)); |
Peter Collingbourne | 7dc8e81 | 2013-08-28 23:16:49 +0000 | [diff] [blame] | 263 | |
| 264 | #else |
| 265 | |
| 266 | _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *); |
| 267 | _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *); |
| 268 | |
| 269 | #endif |
| 270 | |
Rafael Espindola | d85c1e9 | 2011-12-08 05:01:39 +0000 | [diff] [blame] | 271 | |
Benjamin Kramer | ccdb2a5 | 2013-01-09 19:54:57 +0000 | [diff] [blame] | 272 | #ifndef HIDE_EXPORTS |
Rafael Espindola | 9b7568d | 2011-12-09 00:08:01 +0000 | [diff] [blame] | 273 | #pragma GCC visibility pop |
Benjamin Kramer | ccdb2a5 | 2013-01-09 19:54:57 +0000 | [diff] [blame] | 274 | #endif |
Rafael Espindola | 9b7568d | 2011-12-09 00:08:01 +0000 | [diff] [blame] | 275 | |
Rafael Espindola | d85c1e9 | 2011-12-08 05:01:39 +0000 | [diff] [blame] | 276 | #ifdef __cplusplus |
| 277 | } |
| 278 | #endif |
| 279 | |
| 280 | #endif |
Benjamin Kramer | ccdb2a5 | 2013-01-09 19:54:57 +0000 | [diff] [blame] | 281 | |
| 282 | #endif /* __CLANG_UNWIND_H */ |