unwind.h 8.0 KB

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