unwind.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* Exception handling and frame unwind runtime interface routines.
  2. Copyright (C) 2001, 2003 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. /* This is derived from the C++ ABI for IA-64. Where we diverge
  17. for cross-architecture compatibility are noted with "@@@". */
  18. #ifndef _UNWIND_H
  19. #define _UNWIND_H 1
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* Level 1: Base ABI */
  24. /* @@@ The IA-64 ABI uses uint64 throughout. Most places this is
  25. inefficient for 32-bit and smaller machines. */
  26. typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
  27. typedef signed _Unwind_Sword __attribute__((__mode__(__word__)));
  28. #if defined(__ia64__) && defined(__hpux__)
  29. typedef unsigned _Unwind_Ptr __attribute__((__mode__(__word__)));
  30. #else
  31. typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
  32. #endif
  33. typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
  34. /* @@@ The IA-64 ABI uses a 64-bit word to identify the producer and
  35. consumer of an exception. We'll go along with this for now even on
  36. 32-bit machines. We'll need to provide some other option for
  37. 16-bit machines and for machines with > 8 bits per byte. */
  38. typedef unsigned _Unwind_Exception_Class __attribute__((__mode__(__DI__)));
  39. /* The unwind interface uses reason codes in several contexts to
  40. identify the reasons for failures or other actions. */
  41. typedef enum
  42. {
  43. _URC_NO_REASON = 0,
  44. _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
  45. _URC_FATAL_PHASE2_ERROR = 2,
  46. _URC_FATAL_PHASE1_ERROR = 3,
  47. _URC_NORMAL_STOP = 4,
  48. _URC_END_OF_STACK = 5,
  49. _URC_HANDLER_FOUND = 6,
  50. _URC_INSTALL_CONTEXT = 7,
  51. _URC_CONTINUE_UNWIND = 8
  52. } _Unwind_Reason_Code;
  53. /* The unwind interface uses a pointer to an exception header object
  54. as its representation of an exception being thrown. In general, the
  55. full representation of an exception object is language- and
  56. implementation-specific, but it will be prefixed by a header
  57. understood by the unwind interface. */
  58. struct _Unwind_Exception;
  59. typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
  60. struct _Unwind_Exception *);
  61. struct _Unwind_Exception
  62. {
  63. _Unwind_Exception_Class exception_class;
  64. _Unwind_Exception_Cleanup_Fn exception_cleanup;
  65. _Unwind_Word private_1;
  66. _Unwind_Word private_2;
  67. /* @@@ The IA-64 ABI says that this structure must be double-word aligned.
  68. Taking that literally does not make much sense generically. Instead we
  69. provide the maximum alignment required by any type for the machine. */
  70. } __attribute__((__aligned__));
  71. /* The ACTIONS argument to the personality routine is a bitwise OR of one
  72. or more of the following constants. */
  73. typedef int _Unwind_Action;
  74. #define _UA_SEARCH_PHASE 1
  75. #define _UA_CLEANUP_PHASE 2
  76. #define _UA_HANDLER_FRAME 4
  77. #define _UA_FORCE_UNWIND 8
  78. #define _UA_END_OF_STACK 16
  79. /* This is an opaque type used to refer to a system-specific data
  80. structure used by the system unwinder. This context is created and
  81. destroyed by the system, and passed to the personality routine
  82. during unwinding. */
  83. struct _Unwind_Context;
  84. /* Raise an exception, passing along the given exception object. */
  85. extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
  86. /* Raise an exception for forced unwinding. */
  87. typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
  88. (int, _Unwind_Action, _Unwind_Exception_Class,
  89. struct _Unwind_Exception *, struct _Unwind_Context *, void *);
  90. extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
  91. _Unwind_Stop_Fn,
  92. void *);
  93. /* Helper to invoke the exception_cleanup routine. */
  94. extern void _Unwind_DeleteException (struct _Unwind_Exception *);
  95. /* Resume propagation of an existing exception. This is used after
  96. e.g. executing cleanup code, and not to implement rethrowing. */
  97. extern void _Unwind_Resume (struct _Unwind_Exception *);
  98. /* @@@ Use unwind data to perform a stack backtrace. The trace callback
  99. is called for every stack frame in the call chain, but no cleanup
  100. actions are performed. */
  101. typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)
  102. (struct _Unwind_Context *, void *);
  103. extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
  104. /* These functions are used for communicating information about the unwind
  105. context (i.e. the unwind descriptors and the user register state) between
  106. the unwind library and the personality routine and landing pad. Only
  107. selected registers maybe manipulated. */
  108. extern _Unwind_Word _Unwind_GetGR (struct _Unwind_Context *, int);
  109. extern void _Unwind_SetGR (struct _Unwind_Context *, int, _Unwind_Word);
  110. extern _Unwind_Ptr _Unwind_GetIP (struct _Unwind_Context *);
  111. extern void _Unwind_SetIP (struct _Unwind_Context *, _Unwind_Ptr);
  112. /* @@@ Retrieve the CFA of the given context. */
  113. extern _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
  114. extern void *_Unwind_GetLanguageSpecificData (struct _Unwind_Context *);
  115. extern _Unwind_Ptr _Unwind_GetRegionStart (struct _Unwind_Context *);
  116. /* The personality routine is the function in the C++ (or other language)
  117. runtime library which serves as an interface between the system unwind
  118. library and language-specific exception handling semantics. It is
  119. specific to the code fragment described by an unwind info block, and
  120. it is always referenced via the pointer in the unwind info block, and
  121. hence it has no ABI-specified name.
  122. Note that this implies that two different C++ implementations can
  123. use different names, and have different contents in the language
  124. specific data area. Moreover, that the language specific data
  125. area contains no version info because name of the function invoked
  126. provides more effective versioning by detecting at link time the
  127. lack of code to handle the different data format. */
  128. typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
  129. (int, _Unwind_Action, _Unwind_Exception_Class,
  130. struct _Unwind_Exception *, struct _Unwind_Context *);
  131. /* @@@ The following alternate entry points are for setjmp/longjmp
  132. based unwinding. */
  133. struct SjLj_Function_Context;
  134. extern void _Unwind_SjLj_Register (struct SjLj_Function_Context *);
  135. extern void _Unwind_SjLj_Unregister (struct SjLj_Function_Context *);
  136. extern _Unwind_Reason_Code _Unwind_SjLj_RaiseException
  137. (struct _Unwind_Exception *);
  138. extern _Unwind_Reason_Code _Unwind_SjLj_ForcedUnwind
  139. (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *);
  140. extern void _Unwind_SjLj_Resume (struct _Unwind_Exception *);
  141. /* @@@ The following provide access to the base addresses for text
  142. and data-relative addressing in the LDSA. In order to stay link
  143. compatible with the standard ABI for IA-64, we inline these. */
  144. #ifdef __ia64__
  145. #include <stdlib.h>
  146. static inline _Unwind_Ptr
  147. _Unwind_GetDataRelBase (struct _Unwind_Context *_C)
  148. {
  149. /* The GP is stored in R1. */
  150. return _Unwind_GetGR (_C, 1);
  151. }
  152. static inline _Unwind_Ptr
  153. _Unwind_GetTextRelBase (struct _Unwind_Context *_C)
  154. {
  155. abort ();
  156. return 0;
  157. }
  158. /* @@@ Retrieve the Backing Store Pointer of the given context. */
  159. extern _Unwind_Word _Unwind_GetBSP (struct _Unwind_Context *);
  160. #else
  161. extern _Unwind_Ptr _Unwind_GetDataRelBase (struct _Unwind_Context *);
  162. extern _Unwind_Ptr _Unwind_GetTextRelBase (struct _Unwind_Context *);
  163. #endif
  164. /* @@@ Given an address, return the entry point of the function that
  165. contains it. */
  166. extern void * _Unwind_FindEnclosingFunction (void *pc);
  167. #ifdef __cplusplus
  168. }
  169. #endif
  170. #endif /* unwind.h */