clang API Documentation

unwind.h
Go to the documentation of this file.
00001 /*===---- unwind.h - Stack unwinding ----------------------------------------===
00002  *
00003  * Permission is hereby granted, free of charge, to any person obtaining a copy
00004  * of this software and associated documentation files (the "Software"), to deal
00005  * in the Software without restriction, including without limitation the rights
00006  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00007  * copies of the Software, and to permit persons to whom the Software is
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The above copyright notice and this permission notice shall be included in
00011  * all copies or substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00014  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00015  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00016  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00017  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00018  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00019  * THE SOFTWARE.
00020  *
00021  *===-----------------------------------------------------------------------===
00022  */
00023 
00024 /* See "Data Definitions for libgcc_s" in the Linux Standard Base.*/
00025 
00026 #ifndef __CLANG_UNWIND_H
00027 #define __CLANG_UNWIND_H
00028 
00029 #if __has_include_next(<unwind.h>)
00030 /* Darwin (from 11.x on) and libunwind provide an unwind.h. If that's available,
00031  * use it. libunwind wraps some of its definitions in #ifdef _GNU_SOURCE,
00032  * so define that around the include.*/
00033 # ifndef _GNU_SOURCE
00034 #  define _SHOULD_UNDEFINE_GNU_SOURCE
00035 #  define _GNU_SOURCE
00036 # endif
00037 // libunwind's unwind.h reflects the current visibility.  However, Mozilla
00038 // builds with -fvisibility=hidden and relies on gcc's unwind.h to reset the
00039 // visibility to default and export its contents.  gcc also allows users to
00040 // override its override by #defining HIDE_EXPORTS (but note, this only obeys
00041 // the user's -fvisibility setting; it doesn't hide any exports on its own).  We
00042 // imitate gcc's header here:
00043 # ifdef HIDE_EXPORTS
00044 #  include_next <unwind.h>
00045 # else
00046 #  pragma GCC visibility push(default)
00047 #  include_next <unwind.h>
00048 #  pragma GCC visibility pop
00049 # endif
00050 # ifdef _SHOULD_UNDEFINE_GNU_SOURCE
00051 #  undef _GNU_SOURCE
00052 #  undef _SHOULD_UNDEFINE_GNU_SOURCE
00053 # endif
00054 #else
00055 
00056 #include <stdint.h>
00057 
00058 #ifdef __cplusplus
00059 extern "C" {
00060 #endif
00061 
00062 /* It is a bit strange for a header to play with the visibility of the
00063    symbols it declares, but this matches gcc's behavior and some programs
00064    depend on it */
00065 #ifndef HIDE_EXPORTS
00066 #pragma GCC visibility push(default)
00067 #endif
00068 
00069 typedef uintptr_t _Unwind_Word;
00070 typedef intptr_t _Unwind_Sword;
00071 typedef uintptr_t _Unwind_Ptr;
00072 typedef uintptr_t _Unwind_Internal_Ptr;
00073 typedef uint64_t _Unwind_Exception_Class;
00074 
00075 typedef intptr_t _sleb128_t;
00076 typedef uintptr_t _uleb128_t;
00077 
00078 struct _Unwind_Context;
00079 struct _Unwind_Exception;
00080 typedef enum {
00081   _URC_NO_REASON = 0,
00082   _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
00083 
00084   _URC_FATAL_PHASE2_ERROR = 2,
00085   _URC_FATAL_PHASE1_ERROR = 3,
00086   _URC_NORMAL_STOP = 4,
00087 
00088   _URC_END_OF_STACK = 5,
00089   _URC_HANDLER_FOUND = 6,
00090   _URC_INSTALL_CONTEXT = 7,
00091   _URC_CONTINUE_UNWIND = 8
00092 } _Unwind_Reason_Code;
00093 
00094 typedef enum {
00095   _UA_SEARCH_PHASE = 1,
00096   _UA_CLEANUP_PHASE = 2,
00097 
00098   _UA_HANDLER_FRAME = 4,
00099   _UA_FORCE_UNWIND = 8,
00100   _UA_END_OF_STACK = 16 /* gcc extension to C++ ABI */
00101 } _Unwind_Action;
00102 
00103 typedef void (*_Unwind_Exception_Cleanup_Fn)(_Unwind_Reason_Code,
00104                                              struct _Unwind_Exception *);
00105 
00106 struct _Unwind_Exception {
00107   _Unwind_Exception_Class exception_class;
00108   _Unwind_Exception_Cleanup_Fn exception_cleanup;
00109   _Unwind_Word private_1;
00110   _Unwind_Word private_2;
00111   /* The Itanium ABI requires that _Unwind_Exception objects are "double-word
00112    * aligned".  GCC has interpreted this to mean "use the maximum useful
00113    * alignment for the target"; so do we. */
00114 } __attribute__((__aligned__));
00115 
00116 typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)(int, _Unwind_Action,
00117                                                _Unwind_Exception_Class,
00118                                                struct _Unwind_Exception *,
00119                                                struct _Unwind_Context *,
00120                                                void *);
00121 
00122 typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)(
00123     int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
00124     struct _Unwind_Context *);
00125 typedef _Unwind_Personality_Fn __personality_routine;
00126 
00127 typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context *,
00128                                                 void *);
00129 
00130 #if defined(__arm__) && !defined(__APPLE__)
00131 
00132 typedef enum {
00133   _UVRSC_CORE = 0,        /* integer register */
00134   _UVRSC_VFP = 1,         /* vfp */
00135   _UVRSC_WMMXD = 3,       /* Intel WMMX data register */
00136   _UVRSC_WMMXC = 4        /* Intel WMMX control register */
00137 } _Unwind_VRS_RegClass;
00138 
00139 typedef enum {
00140   _UVRSD_UINT32 = 0,
00141   _UVRSD_VFPX = 1,
00142   _UVRSD_UINT64 = 3,
00143   _UVRSD_FLOAT = 4,
00144   _UVRSD_DOUBLE = 5
00145 } _Unwind_VRS_DataRepresentation;
00146 
00147 typedef enum {
00148   _UVRSR_OK = 0,
00149   _UVRSR_NOT_IMPLEMENTED = 1,
00150   _UVRSR_FAILED = 2
00151 } _Unwind_VRS_Result;
00152 
00153 _Unwind_VRS_Result _Unwind_VRS_Get(struct _Unwind_Context *__context,
00154   _Unwind_VRS_RegClass __regclass,
00155   uint32_t __regno,
00156   _Unwind_VRS_DataRepresentation __representation,
00157   void *__valuep);
00158 
00159 _Unwind_VRS_Result _Unwind_VRS_Set(struct _Unwind_Context *__context,
00160   _Unwind_VRS_RegClass __regclass,
00161   uint32_t __regno,
00162   _Unwind_VRS_DataRepresentation __representation,
00163   void *__valuep);
00164 
00165 static __inline__
00166 _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *__context, int __index) {
00167   _Unwind_Word __value;
00168   _Unwind_VRS_Get(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value);
00169   return __value;
00170 }
00171 
00172 static __inline__
00173 void _Unwind_SetGR(struct _Unwind_Context *__context, int __index,
00174                    _Unwind_Word __value) {
00175   _Unwind_VRS_Set(__context, _UVRSC_CORE, __index, _UVRSD_UINT32, &__value);
00176 }
00177 
00178 static __inline__
00179 _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *__context) {
00180   _Unwind_Word __ip = _Unwind_GetGR(__context, 15);
00181   return __ip & ~(_Unwind_Word)(0x1); /* Remove thumb mode bit. */
00182 }
00183 
00184 static __inline__
00185 void _Unwind_SetIP(struct _Unwind_Context *__context, _Unwind_Word __value) {
00186   _Unwind_Word __thumb_mode_bit = _Unwind_GetGR(__context, 15) & 0x1;
00187   _Unwind_SetGR(__context, 15, __value | __thumb_mode_bit);
00188 }
00189 #else
00190 _Unwind_Word _Unwind_GetGR(struct _Unwind_Context *, int);
00191 void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Word);
00192 
00193 _Unwind_Word _Unwind_GetIP(struct _Unwind_Context *);
00194 void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Word);
00195 #endif
00196 
00197 
00198 _Unwind_Word _Unwind_GetIPInfo(struct _Unwind_Context *, int *);
00199 
00200 _Unwind_Word _Unwind_GetCFA(struct _Unwind_Context *);
00201 
00202 void *_Unwind_GetLanguageSpecificData(struct _Unwind_Context *);
00203 
00204 _Unwind_Ptr _Unwind_GetRegionStart(struct _Unwind_Context *);
00205 
00206 /* DWARF EH functions; currently not available on Darwin/ARM */
00207 #if !defined(__APPLE__) || !defined(__arm__)
00208 
00209 _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception *);
00210 _Unwind_Reason_Code _Unwind_ForcedUnwind(struct _Unwind_Exception *,
00211                                          _Unwind_Stop_Fn, void *);
00212 void _Unwind_DeleteException(struct _Unwind_Exception *);
00213 void _Unwind_Resume(struct _Unwind_Exception *);
00214 _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(struct _Unwind_Exception *);
00215 
00216 #endif
00217 
00218 _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void *);
00219 
00220 /* setjmp(3)/longjmp(3) stuff */
00221 typedef struct SjLj_Function_Context *_Unwind_FunctionContext_t;
00222 
00223 void _Unwind_SjLj_Register(_Unwind_FunctionContext_t);
00224 void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t);
00225 _Unwind_Reason_Code _Unwind_SjLj_RaiseException(struct _Unwind_Exception *);
00226 _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(struct _Unwind_Exception *,
00227                                               _Unwind_Stop_Fn, void *);
00228 void _Unwind_SjLj_Resume(struct _Unwind_Exception *);
00229 _Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(struct _Unwind_Exception *);
00230 
00231 void *_Unwind_FindEnclosingFunction(void *);
00232 
00233 #ifdef __APPLE__
00234 
00235 _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *)
00236     __attribute__((unavailable));
00237 _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *)
00238     __attribute__((unavailable));
00239 
00240 /* Darwin-specific functions */
00241 void __register_frame(const void *);
00242 void __deregister_frame(const void *);
00243 
00244 struct dwarf_eh_bases {
00245   uintptr_t tbase;
00246   uintptr_t dbase;
00247   uintptr_t func;
00248 };
00249 void *_Unwind_Find_FDE(const void *, struct dwarf_eh_bases *);
00250 
00251 void __register_frame_info_bases(const void *, void *, void *, void *)
00252   __attribute__((unavailable));
00253 void __register_frame_info(const void *, void *) __attribute__((unavailable));
00254 void __register_frame_info_table_bases(const void *, void*, void *, void *)
00255   __attribute__((unavailable));
00256 void __register_frame_info_table(const void *, void *)
00257   __attribute__((unavailable));
00258 void __register_frame_table(const void *) __attribute__((unavailable));
00259 void __deregister_frame_info(const void *) __attribute__((unavailable));
00260 void __deregister_frame_info_bases(const void *)__attribute__((unavailable));
00261 
00262 #else
00263 
00264 _Unwind_Ptr _Unwind_GetDataRelBase(struct _Unwind_Context *);
00265 _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *);
00266 
00267 #endif
00268 
00269 
00270 #ifndef HIDE_EXPORTS
00271 #pragma GCC visibility pop
00272 #endif
00273 
00274 #ifdef __cplusplus
00275 }
00276 #endif
00277 
00278 #endif
00279 
00280 #endif /* __CLANG_UNWIND_H */