xref: /freebsd/contrib/libcxxrt/unwind-itanium.h (revision 72df847a94bccee245a3316e4f848482b9ac2ac2)
17a984708SDavid Chisnall /* libunwind - a platform-independent unwind library
27a984708SDavid Chisnall    Copyright (C) 2003 Hewlett-Packard Co
37a984708SDavid Chisnall 	Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
47a984708SDavid Chisnall 
57a984708SDavid Chisnall This file is part of libunwind.
67a984708SDavid Chisnall 
77a984708SDavid Chisnall Permission is hereby granted, free of charge, to any person obtaining
87a984708SDavid Chisnall a copy of this software and associated documentation files (the
97a984708SDavid Chisnall "Software"), to deal in the Software without restriction, including
107a984708SDavid Chisnall without limitation the rights to use, copy, modify, merge, publish,
117a984708SDavid Chisnall distribute, sublicense, and/or sell copies of the Software, and to
127a984708SDavid Chisnall permit persons to whom the Software is furnished to do so, subject to
137a984708SDavid Chisnall the following conditions:
147a984708SDavid Chisnall 
157a984708SDavid Chisnall The above copyright notice and this permission notice shall be
167a984708SDavid Chisnall included in all copies or substantial portions of the Software.
177a984708SDavid Chisnall 
187a984708SDavid Chisnall THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
197a984708SDavid Chisnall EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
207a984708SDavid Chisnall MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
217a984708SDavid Chisnall NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
227a984708SDavid Chisnall LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
237a984708SDavid Chisnall OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
247a984708SDavid Chisnall WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
257a984708SDavid Chisnall 
267a984708SDavid Chisnall #ifndef _UNWIND_H
277a984708SDavid Chisnall #define _UNWIND_H
287a984708SDavid Chisnall 
297a984708SDavid Chisnall /* For uint64_t */
307a984708SDavid Chisnall #include <stdint.h>
317a984708SDavid Chisnall 
327a984708SDavid Chisnall #ifdef __cplusplus
337a984708SDavid Chisnall extern "C" {
347a984708SDavid Chisnall #endif
357a984708SDavid Chisnall 
367a984708SDavid Chisnall /* Minimal interface as per C++ ABI draft standard:
377a984708SDavid Chisnall 
387a984708SDavid Chisnall 	http://www.codesourcery.com/cxx-abi/abi-eh.html */
397a984708SDavid Chisnall 
407a984708SDavid Chisnall typedef enum
417a984708SDavid Chisnall   {
427a984708SDavid Chisnall     _URC_NO_REASON = 0,
430ee0dbfbSDimitry Andric     _URC_OK = 0,
447a984708SDavid Chisnall     _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
457a984708SDavid Chisnall     _URC_FATAL_PHASE2_ERROR = 2,
467a984708SDavid Chisnall     _URC_FATAL_PHASE1_ERROR = 3,
477a984708SDavid Chisnall     _URC_NORMAL_STOP = 4,
487a984708SDavid Chisnall     _URC_END_OF_STACK = 5,
497a984708SDavid Chisnall     _URC_HANDLER_FOUND = 6,
507a984708SDavid Chisnall     _URC_INSTALL_CONTEXT = 7,
517a984708SDavid Chisnall     _URC_CONTINUE_UNWIND = 8
527a984708SDavid Chisnall   }
537a984708SDavid Chisnall _Unwind_Reason_Code;
547a984708SDavid Chisnall 
557a984708SDavid Chisnall typedef int _Unwind_Action;
567a984708SDavid Chisnall 
577a984708SDavid Chisnall #define _UA_SEARCH_PHASE	1
587a984708SDavid Chisnall #define _UA_CLEANUP_PHASE	2
597a984708SDavid Chisnall #define _UA_HANDLER_FRAME	4
607a984708SDavid Chisnall #define _UA_FORCE_UNWIND	8
617a984708SDavid Chisnall 
627a984708SDavid Chisnall struct _Unwind_Context;		/* opaque data-structure */
637a984708SDavid Chisnall struct _Unwind_Exception;	/* forward-declaration */
647a984708SDavid Chisnall 
657a984708SDavid Chisnall typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
667a984708SDavid Chisnall 					      struct _Unwind_Exception *);
677a984708SDavid Chisnall 
687a984708SDavid Chisnall typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action,
697a984708SDavid Chisnall 						uint64_t,
707a984708SDavid Chisnall 						struct _Unwind_Exception *,
717a984708SDavid Chisnall 						struct _Unwind_Context *,
727a984708SDavid Chisnall 						void *);
737a984708SDavid Chisnall 
747a984708SDavid Chisnall /* The C++ ABI requires exception_class, private_1, and private_2 to
757a984708SDavid Chisnall    be of type uint64 and the entire structure to be
767a984708SDavid Chisnall    double-word-aligned. Please note that exception_class stays 64-bit
777a984708SDavid Chisnall    even on 32-bit machines for gcc compatibility.  */
787a984708SDavid Chisnall struct _Unwind_Exception
797a984708SDavid Chisnall   {
807a984708SDavid Chisnall     uint64_t exception_class;
817a984708SDavid Chisnall     _Unwind_Exception_Cleanup_Fn exception_cleanup;
82*72df847aSDimitry Andric     uintptr_t private_1;
83*72df847aSDimitry Andric     uintptr_t private_2;
84*72df847aSDimitry Andric #if __SIZEOF_POINTER__ == 4
85*72df847aSDimitry Andric     uint32_t reserved[3];
86*72df847aSDimitry Andric #endif
87*72df847aSDimitry Andric   } __attribute__((__aligned__));
887a984708SDavid Chisnall 
897a984708SDavid Chisnall extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
907a984708SDavid Chisnall extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
917a984708SDavid Chisnall 						 _Unwind_Stop_Fn, void *);
927a984708SDavid Chisnall extern void _Unwind_Resume (struct _Unwind_Exception *);
937a984708SDavid Chisnall extern void _Unwind_DeleteException (struct _Unwind_Exception *);
947a984708SDavid Chisnall extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);
957a984708SDavid Chisnall extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);
967a984708SDavid Chisnall extern unsigned long _Unwind_GetIP (struct _Unwind_Context *);
977a984708SDavid Chisnall extern unsigned long _Unwind_GetIPInfo (struct _Unwind_Context *, int *);
987a984708SDavid Chisnall extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);
997a984708SDavid Chisnall extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);
1007a984708SDavid Chisnall extern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *);
1017a984708SDavid Chisnall 
1027a984708SDavid Chisnall #ifdef _GNU_SOURCE
1037a984708SDavid Chisnall 
1047a984708SDavid Chisnall /* Callback for _Unwind_Backtrace().  The backtrace stops immediately
1057a984708SDavid Chisnall    if the callback returns any value other than _URC_NO_REASON. */
1067a984708SDavid Chisnall typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *,
1077a984708SDavid Chisnall 						 void *);
1087a984708SDavid Chisnall 
1097a984708SDavid Chisnall /* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why
1107a984708SDavid Chisnall    _UA_END_OF_STACK exists.  */
1117a984708SDavid Chisnall # define _UA_END_OF_STACK	16
1127a984708SDavid Chisnall 
1137a984708SDavid Chisnall /* If the unwind was initiated due to a forced unwind, resume that
1147a984708SDavid Chisnall    operation, else re-raise the exception.  This is used by
1157a984708SDavid Chisnall    __cxa_rethrow().  */
1167a984708SDavid Chisnall extern _Unwind_Reason_Code
1177a984708SDavid Chisnall 	  _Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
1187a984708SDavid Chisnall 
1197a984708SDavid Chisnall /* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why
1207a984708SDavid Chisnall    _Unwind_GetBSP() exists.  */
1217a984708SDavid Chisnall extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);
1227a984708SDavid Chisnall 
1237a984708SDavid Chisnall /* Return the "canonical frame address" for the given context.
1247a984708SDavid Chisnall    This is used by NPTL... */
1257a984708SDavid Chisnall extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);
1267a984708SDavid Chisnall 
1277a984708SDavid Chisnall /* Return the base-address for data references.  */
1287a984708SDavid Chisnall extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);
1297a984708SDavid Chisnall 
1307a984708SDavid Chisnall /* Return the base-address for text references.  */
1317a984708SDavid Chisnall extern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *);
1327a984708SDavid Chisnall 
1337a984708SDavid Chisnall /* Call _Unwind_Trace_Fn once for each stack-frame, without doing any
1347a984708SDavid Chisnall    cleanup.  The first frame for which the callback is invoked is the
1357a984708SDavid Chisnall    one for the caller of _Unwind_Backtrace().  _Unwind_Backtrace()
1367a984708SDavid Chisnall    returns _URC_END_OF_STACK when the backtrace stopped due to
1377a984708SDavid Chisnall    reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it
1387a984708SDavid Chisnall    stops for any other reason.  */
1397a984708SDavid Chisnall extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
1407a984708SDavid Chisnall 
1417a984708SDavid Chisnall /* Find the start-address of the procedure containing the specified IP
1427a984708SDavid Chisnall    or NULL if it cannot be found (e.g., because the function has no
1437a984708SDavid Chisnall    unwind info).  Note: there is not necessarily a one-to-one
1447a984708SDavid Chisnall    correspondence between source-level functions and procedures: some
1457a984708SDavid Chisnall    functions don't have unwind-info and others are split into multiple
1467a984708SDavid Chisnall    procedures.  */
1477a984708SDavid Chisnall extern void *_Unwind_FindEnclosingFunction (void *);
1487a984708SDavid Chisnall 
1497a984708SDavid Chisnall /* See also Linux Standard Base Spec:
1507a984708SDavid Chisnall     http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */
1517a984708SDavid Chisnall 
1527a984708SDavid Chisnall #endif /* _GNU_SOURCE */
1537a984708SDavid Chisnall 
1547a984708SDavid Chisnall #define DECLARE_PERSONALITY_FUNCTION(name) \
1557a984708SDavid Chisnall _Unwind_Reason_Code name(int version,\
1567a984708SDavid Chisnall                          _Unwind_Action actions,\
1577a984708SDavid Chisnall                          uint64_t exceptionClass,\
1587a984708SDavid Chisnall                          struct _Unwind_Exception *exceptionObject,\
1597a984708SDavid Chisnall                          struct _Unwind_Context *context);
1607a984708SDavid Chisnall #define BEGIN_PERSONALITY_FUNCTION(name) \
1617a984708SDavid Chisnall _Unwind_Reason_Code name(int version,\
1627a984708SDavid Chisnall                          _Unwind_Action actions,\
1637a984708SDavid Chisnall                          uint64_t exceptionClass,\
1647a984708SDavid Chisnall                          struct _Unwind_Exception *exceptionObject,\
1657a984708SDavid Chisnall                          struct _Unwind_Context *context)\
1667a984708SDavid Chisnall {
1677a984708SDavid Chisnall 
1687a984708SDavid Chisnall #define CALL_PERSONALITY_FUNCTION(name) name(version, actions, exceptionClass, exceptionObject, context)
1697a984708SDavid Chisnall 
1707a984708SDavid Chisnall #ifdef __cplusplus
1717a984708SDavid Chisnall }
1727a984708SDavid Chisnall #endif
1737a984708SDavid Chisnall 
1747a984708SDavid Chisnall #endif /* _UNWIND_H */
175