1169689Skan/* Exception handling and frame unwind runtime interface routines. 2169689Skan Copyright (C) 2001, 2003, 2004, 2006 Free Software Foundation, Inc. 3169689Skan 4169689Skan This file is part of GCC. 5169689Skan 6169689Skan GCC is free software; you can redistribute it and/or modify it 7169689Skan under the terms of the GNU General Public License as published by 8169689Skan the Free Software Foundation; either version 2, or (at your option) 9169689Skan any later version. 10169689Skan 11169689Skan GCC is distributed in the hope that it will be useful, but WITHOUT 12169689Skan ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13169689Skan or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 14169689Skan License for more details. 15169689Skan 16169689Skan You should have received a copy of the GNU General Public License 17169689Skan along with GCC; see the file COPYING. If not, write to the Free 18169689Skan Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 19169689Skan 02110-1301, USA. */ 20169689Skan 21169689Skan/* As a special exception, if you include this header file into source 22169689Skan files compiled by GCC, this header file does not by itself cause 23169689Skan the resulting executable to be covered by the GNU General Public 24169689Skan License. This exception does not however invalidate any other 25169689Skan reasons why the executable file might be covered by the GNU General 26169689Skan Public License. */ 27169689Skan 28169689Skan/* This is derived from the C++ ABI for IA-64. Where we diverge 29169689Skan for cross-architecture compatibility are noted with "@@@". */ 30169689Skan 31169689Skan#ifndef _UNWIND_H 32169689Skan#define _UNWIND_H 33169689Skan 34169689Skan#ifndef HIDE_EXPORTS 35169689Skan#pragma GCC visibility push(default) 36169689Skan#endif 37169689Skan 38169689Skan#ifdef __cplusplus 39169689Skanextern "C" { 40169689Skan#endif 41169689Skan 42169689Skan/* Level 1: Base ABI */ 43169689Skan 44169689Skan/* @@@ The IA-64 ABI uses uint64 throughout. Most places this is 45169689Skan inefficient for 32-bit and smaller machines. */ 46169689Skantypedef unsigned _Unwind_Word __attribute__((__mode__(__word__))); 47169689Skantypedef signed _Unwind_Sword __attribute__((__mode__(__word__))); 48169689Skan#if defined(__ia64__) && defined(__hpux__) 49169689Skantypedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__))); 50169689Skan#else 51169689Skantypedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__))); 52169689Skan#endif 53169689Skantypedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__))); 54169689Skan 55169689Skan/* @@@ The IA-64 ABI uses a 64-bit word to identify the producer and 56169689Skan consumer of an exception. We'll go along with this for now even on 57169689Skan 32-bit machines. We'll need to provide some other option for 58169689Skan 16-bit machines and for machines with > 8 bits per byte. */ 59169689Skantypedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__))); 60169689Skan 61169689Skan/* The unwind interface uses reason codes in several contexts to 62169689Skan identify the reasons for failures or other actions. */ 63169689Skantypedef enum 64169689Skan{ 65169689Skan _URC_NO_REASON = 0, 66169689Skan _URC_FOREIGN_EXCEPTION_CAUGHT = 1, 67169689Skan _URC_FATAL_PHASE2_ERROR = 2, 68169689Skan _URC_FATAL_PHASE1_ERROR = 3, 69169689Skan _URC_NORMAL_STOP = 4, 70169689Skan _URC_END_OF_STACK = 5, 71169689Skan _URC_HANDLER_FOUND = 6, 72169689Skan _URC_INSTALL_CONTEXT = 7, 73169689Skan _URC_CONTINUE_UNWIND = 8 74169689Skan} _Unwind_Reason_Code; 75169689Skan 76169689Skan 77169689Skan/* The unwind interface uses a pointer to an exception header object 78169689Skan as its representation of an exception being thrown. In general, the 79169689Skan full representation of an exception object is language- and 80169689Skan implementation-specific, but it will be prefixed by a header 81169689Skan understood by the unwind interface. */ 82169689Skan 83169689Skanstruct _Unwind_Exception; 84169689Skan 85169689Skantypedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code, 86169689Skan struct _Unwind_Exception *); 87169689Skan 88169689Skanstruct _Unwind_Exception 89169689Skan{ 90169689Skan _Unwind_Exception_Class exception_class; 91169689Skan _Unwind_Exception_Cleanup_Fn exception_cleanup; 92169689Skan _Unwind_Word private_1; 93169689Skan _Unwind_Word private_2; 94169689Skan 95169689Skan /* @@@ The IA-64 ABI says that this structure must be double-word aligned. 96169689Skan Taking that literally does not make much sense generically. Instead we 97169689Skan provide the maximum alignment required by any type for the machine. */ 98169689Skan} __attribute__((__aligned__)); 99169689Skan 100169689Skan 101169689Skan/* The ACTIONS argument to the personality routine is a bitwise OR of one 102169689Skan or more of the following constants. */ 103169689Skantypedef int _Unwind_Action; 104169689Skan 105169689Skan#define _UA_SEARCH_PHASE 1 106169689Skan#define _UA_CLEANUP_PHASE 2 107169689Skan#define _UA_HANDLER_FRAME 4 108169689Skan#define _UA_FORCE_UNWIND 8 109169689Skan#define _UA_END_OF_STACK 16 110169689Skan 111169689Skan/* This is an opaque type used to refer to a system-specific data 112169689Skan structure used by the system unwinder. This context is created and 113169689Skan destroyed by the system, and passed to the personality routine 114169689Skan during unwinding. */ 115169689Skanstruct _Unwind_Context; 116169689Skan 117169689Skan/* Raise an exception, passing along the given exception object. */ 118169689Skanextern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *); 119169689Skan 120169689Skan/* Raise an exception for forced unwinding. */ 121169689Skan 122169689Skantypedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) 123169689Skan (int, _Unwind_Action, _Unwind_Exception_Class, 124169689Skan struct _Unwind_Exception *, struct _Unwind_Context *, void *); 125169689Skan 126169689Skanextern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *, 127169689Skan _Unwind_Stop_Fn, 128169689Skan void *); 129169689Skan 130169689Skan/* Helper to invoke the exception_cleanup routine. */ 131169689Skanextern void _Unwind_DeleteException (struct _Unwind_Exception *); 132169689Skan 133169689Skan/* Resume propagation of an existing exception. This is used after 134169689Skan e.g. executing cleanup code, and not to implement rethrowing. */ 135169689Skanextern void _Unwind_Resume (struct _Unwind_Exception *); 136169689Skan 137169689Skan/* @@@ Resume propagation of an FORCE_UNWIND exception, or to rethrow 138169689Skan a normal exception that was handled. */ 139169689Skanextern _Unwind_Reason_Code _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *); 140169689Skan 141169689Skan/* @@@ Use unwind data to perform a stack backtrace. The trace callback 142169689Skan is called for every stack frame in the call chain, but no cleanup 143169689Skan actions are performed. */ 144169689Skantypedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) 145169689Skan (struct _Unwind_Context *, void *); 146169689Skan 147169689Skanextern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *); 148169689Skan 149169689Skan/* These functions are used for communicating information about the unwind 150169689Skan context (i.e. the unwind descriptors and the user register state) between 151169689Skan the unwind library and the personality routine and landing pad. Only 152169689Skan selected registers maybe manipulated. */ 153169689Skan 154169689Skanextern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int); 155169689Skanextern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word); 156169689Skan 157169689Skanextern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *); 158169689Skanextern _Unwind_Ptr _Unwind_GetIPInfo (struct _Unwind_Context *, int *); 159169689Skanextern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr); 160169689Skan 161169689Skan/* @@@ Retrieve the CFA of the given context. */ 162169689Skanextern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *); 163169689Skan 164169689Skanextern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *); 165169689Skan 166169689Skanextern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *); 167169689Skan 168169689Skan 169169689Skan/* The personality routine is the function in the C++ (or other language) 170169689Skan runtime library which serves as an interface between the system unwind 171169689Skan library and language-specific exception handling semantics. It is 172169689Skan specific to the code fragment described by an unwind info block, and 173169689Skan it is always referenced via the pointer in the unwind info block, and 174169689Skan hence it has no ABI-specified name. 175169689Skan 176169689Skan Note that this implies that two different C++ implementations can 177169689Skan use different names, and have different contents in the language 178169689Skan specific data area. Moreover, that the language specific data 179169689Skan area contains no version info because name of the function invoked 180169689Skan provides more effective versioning by detecting at link time the 181169689Skan lack of code to handle the different data format. */ 182169689Skan 183169689Skantypedef _Unwind_Reason_Code (*_Unwind_Personality_Fn) 184169689Skan (int, _Unwind_Action, _Unwind_Exception_Class, 185169689Skan struct _Unwind_Exception *, struct _Unwind_Context *); 186169689Skan 187169689Skan/* @@@ The following alternate entry points are for setjmp/longjmp 188169689Skan based unwinding. */ 189169689Skan 190169689Skanstruct SjLj_Function_Context; 191169689Skanextern void _Unwind_SjLj_Register (struct SjLj_Function_Context *); 192169689Skanextern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *); 193169689Skan 194169689Skanextern _Unwind_Reason_Code _Unwind_SjLj_RaiseException 195169689Skan (struct _Unwind_Exception *); 196169689Skanextern _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind 197169689Skan (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *); 198169689Skanextern void _Unwind_SjLj_Resume (struct _Unwind_Exception *); 199169689Skanextern _Unwind_Reason_Code _Unwind_SjLj_Resume_or_Rethrow (struct _Unwind_Exception *); 200169689Skan 201169689Skan/* @@@ The following provide access to the base addresses for text 202169689Skan and data-relative addressing in the LDSA. In order to stay link 203169689Skan compatible with the standard ABI for IA-64, we inline these. */ 204169689Skan 205169689Skan#ifdef __ia64__ 206169689Skan#include <stdlib.h> 207169689Skan 208169689Skanstatic inline _Unwind_Ptr 209169689Skan_Unwind_GetDataRelBase (struct _Unwind_Context *_C) 210169689Skan{ 211169689Skan /* The GP is stored in R1. */ 212169689Skan return _Unwind_GetGR (_C, 1); 213169689Skan} 214169689Skan 215169689Skanstatic inline _Unwind_Ptr 216169689Skan_Unwind_GetTextRelBase (struct _Unwind_Context *_C __attribute__ ((__unused__))) 217169689Skan{ 218169689Skan abort (); 219169689Skan return 0; 220169689Skan} 221169689Skan 222169689Skan/* @@@ Retrieve the Backing Store Pointer of the given context. */ 223169689Skanextern _Unwind_Word _Unwind_GetBSP (struct _Unwind_Context *); 224169689Skan#else 225169689Skanextern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *); 226169689Skanextern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *); 227169689Skan#endif 228169689Skan 229169689Skan/* @@@ Given an address, return the entry point of the function that 230169689Skan contains it. */ 231169689Skanextern void * _Unwind_FindEnclosingFunction (void *pc); 232169689Skan 233169689Skan#ifdef __cplusplus 234169689Skan} 235169689Skan#endif 236169689Skan 237169689Skan#ifndef HIDE_EXPORTS 238169689Skan#pragma GCC visibility pop 239169689Skan#endif 240169689Skan 241169689Skan#endif /* unwind.h */ 242