1/* -*- mode: C++; c-basic-offset: 4; -*- 2 * 3 * Copyright (c) 2010-2011 Apple Inc. All rights reserved. 4 * 5 * @APPLE_LICENSE_HEADER_START@ 6 * 7 * This file contains Original Code and/or Modifications of Original Code 8 * as defined in and that are subject to the Apple Public Source License 9 * Version 2.0 (the 'License'). You may not use this file except in 10 * compliance with the License. Please obtain a copy of the License at 11 * http://www.opensource.apple.com/apsl/ and read it before using this 12 * file. 13 * 14 * The Original Code and all software distributed under the License are 15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 19 * Please see the License for the specific language governing rights and 20 * limitations under the License. 21 * 22 * @APPLE_LICENSE_HEADER_END@ 23 * 24 * 25 * C interface to libuwind 26 * 27 * Source compatible with Level 1 Base ABI documented at: 28 * http://www.codesourcery.com/public/cxx-abi/abi-eh.html 29 * 30 */ 31 32 33#ifndef __UNWIND_H__ 34#define __UNWIND_H__ 35 36#include <stdint.h> 37#include <stddef.h> 38#include <Availability.h> 39 40 41typedef enum { 42 _URC_NO_REASON = 0, 43 _URC_FOREIGN_EXCEPTION_CAUGHT = 1, 44 _URC_FATAL_PHASE2_ERROR = 2, 45 _URC_FATAL_PHASE1_ERROR = 3, 46 _URC_NORMAL_STOP = 4, 47 _URC_END_OF_STACK = 5, 48 _URC_HANDLER_FOUND = 6, 49 _URC_INSTALL_CONTEXT = 7, 50 _URC_CONTINUE_UNWIND = 8 51} _Unwind_Reason_Code; 52 53typedef enum { 54 _UA_SEARCH_PHASE = 1, 55 _UA_CLEANUP_PHASE = 2, 56 _UA_HANDLER_FRAME = 4, 57 _UA_FORCE_UNWIND = 8, 58 _UA_END_OF_STACK = 16 // gcc extension to C++ ABI 59} _Unwind_Action; 60 61 62struct _Unwind_Context; // opaque 63struct _Unwind_Exception; // forward declaration 64 65struct _Unwind_Exception { 66 uint64_t exception_class; 67 void (*exception_cleanup)(_Unwind_Reason_Code reason, struct _Unwind_Exception* exc); 68 uintptr_t private_1; // non-zero means forced unwind 69 uintptr_t private_2; // holds sp that phase1 found for phase2 to use 70#if !__LP64__ 71 // The gcc implementation of _Unwind_Exception used attribute mode on the above fields 72 // which had the side effect of causing this whole struct to round up to 32 bytes in size. 73 // To be more explicit, we add pad fields added for binary compatibility. 74 uint32_t reserved[3]; 75#endif 76}; 77 78 79typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) 80 (int version, 81 _Unwind_Action actions, 82 uint64_t exceptionClass, 83 struct _Unwind_Exception* exceptionObject, 84 struct _Unwind_Context* context, 85 void* stop_parameter ); 86 87 88typedef _Unwind_Reason_Code (*__personality_routine) 89 (int version, 90 _Unwind_Action actions, 91 uint64_t exceptionClass, 92 struct _Unwind_Exception* exceptionObject, 93 struct _Unwind_Context* context); 94 95 96 97#ifdef __cplusplus 98extern "C" { 99#endif 100 101// 102// The following are the base functions documented by the C++ ABI 103// 104#if __arm__ 105 extern _Unwind_Reason_Code _Unwind_SjLj_RaiseException(struct _Unwind_Exception* exception_object); 106 extern void _Unwind_SjLj_Resume(struct _Unwind_Exception* exception_object); 107#else 108 extern _Unwind_Reason_Code _Unwind_RaiseException(struct _Unwind_Exception* exception_object); 109 extern void _Unwind_Resume(struct _Unwind_Exception* exception_object); 110#endif 111extern void _Unwind_DeleteException(struct _Unwind_Exception* exception_object); 112extern uintptr_t _Unwind_GetGR(struct _Unwind_Context* context, int index); 113extern void _Unwind_SetGR(struct _Unwind_Context* context, int index, uintptr_t new_value); 114extern uintptr_t _Unwind_GetIP(struct _Unwind_Context* context); 115extern void _Unwind_SetIP(struct _Unwind_Context*, uintptr_t new_value); 116extern uintptr_t _Unwind_GetRegionStart(struct _Unwind_Context* context); 117extern uintptr_t _Unwind_GetLanguageSpecificData(struct _Unwind_Context* context); 118#if __arm__ 119 extern _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind(struct _Unwind_Exception* exception_object, _Unwind_Stop_Fn stop, void* stop_parameter ); 120#else 121 extern _Unwind_Reason_Code _Unwind_ForcedUnwind(struct _Unwind_Exception* exception_object, _Unwind_Stop_Fn stop, void* stop_parameter ); 122#endif 123 124#if __arm__ 125 typedef struct _Unwind_FunctionContext* _Unwind_FunctionContext_t; 126 extern void _Unwind_SjLj_Register(_Unwind_FunctionContext_t fc); 127 extern void _Unwind_SjLj_Unregister(_Unwind_FunctionContext_t fc); 128#endif 129 130// 131// The following are semi-suppoted extensions to the C++ ABI 132// 133 134 135// 136// called by __cxa_rethrow(). 137// 138#if __arm__ 139 extern _Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow(struct _Unwind_Exception* exception_object); 140#else 141 extern _Unwind_Reason_Code _Unwind_Resume_or_Rethrow(struct _Unwind_Exception* exception_object); 142#endif 143 144 145// 146// _Unwind_Backtrace() is a gcc extension that walks the stack and calls the 147// _Unwind_Trace_Fn once per frame until it reaches the bottom of the stack 148// or the _Unwind_Trace_Fn function returns something other than _URC_NO_REASON. 149// 150typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)(struct _Unwind_Context*, void*); 151extern _Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void*); 152 153 154// 155// _Unwind_GetCFA is a gcc extension that can be called from within a personality 156// handler to get the CFA (stack pointer before call) of current frame. 157// 158extern uintptr_t _Unwind_GetCFA(struct _Unwind_Context*); 159 160 161// 162// _Unwind_GetIPInfo is a gcc extension that can be called from within a personality 163// handler. Similar to _Unwind_GetIP() but also returns in *ipBefore a non-zero 164// value if the instruction pointer is at or before the instruction causing 165// the unwind. Normally, in a function call, the IP returned is the return address 166// which is after the call instruction and may be past the end of the function 167// containing the call instruction. 168// 169extern uintptr_t _Unwind_GetIPInfo(struct _Unwind_Context* context, int* ipBefore); 170 171 172// 173// __register_frame() is used with dynamically generated code to register the FDE 174// for a generated (JIT) code. The FDE must use pc-rel addressing to point to its 175// function and optional LSDA. __register_frame() has existed in all versions of 176// Mac OS X, but in 10.4 and 10.5 it was buggy and did not actually register the 177// FDE with the unwinder. In 10.6 and later it does register properly. 178// 179extern void __register_frame(const void* fde); 180extern void __deregister_frame(const void* fde); 181 182 183// 184// _Unwind_Find_FDE() will locate the FDE if the pc is in some function that has 185// an associated FDE. Note, Mac OS X 10.6 and later, introduces "compact unwind info" 186// which the runtime uses in preference to dwarf unwind info. This function 187// will only work if the target function has an FDE but no compact unwind info. 188// 189struct dwarf_eh_bases 190{ 191 uintptr_t tbase; 192 uintptr_t dbase; 193 uintptr_t func; 194}; 195extern const void* _Unwind_Find_FDE(const void* pc, struct dwarf_eh_bases*); 196 197 198// 199// This function attempts to find the start (address of first instruction) of 200// a function given an address inside the function. It only works if the function 201// has an FDE (dwarf unwind info). 202// This function is unimplemented on Mac OS X 10.6 and later. Instead, use 203// _Unwind_Find_FDE() and look at the dwarf_eh_bases.func result. 204extern void* _Unwind_FindEnclosingFunction(void* pc); 205 206 207// Mac OS X does not support text-rel and data-rel addressing so these functions are unimplemented 208extern uintptr_t _Unwind_GetDataRelBase(struct _Unwind_Context* context) __attribute__((unavailable)); 209extern uintptr_t _Unwind_GetTextRelBase(struct _Unwind_Context* context) __attribute__((unavailable)); 210 211 212 213// Mac OS X 10.4 and 10.5 had implementations of these functions in libgcc_s.dylib, 214// but they never worked. These functions are no longer available. 215extern void __register_frame_info_bases(const void* fde, void* ob, void* tb, void* db) __attribute__((unavailable)); 216extern void __register_frame_info(const void* fde, void* ob) __attribute__((unavailable)); 217extern void __register_frame_info_table_bases(const void* fde, void* ob,void* tb, void* db) __attribute__((unavailable)); 218extern void __register_frame_info_table(const void* fde, void* ob) __attribute__((unavailable)); 219extern void __register_frame_table(const void* fde) __attribute__((unavailable)); 220extern void* __deregister_frame_info(const void* fde) __attribute__((unavailable)); 221extern void* __deregister_frame_info_bases(const void* fde) __attribute__((unavailable)); 222 223 224#ifdef __cplusplus 225} 226#endif 227 228 229 230#endif // __UNWIND_H__ 231 232 233