unwind.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /* Header file for the ARM EABI unwinder
  2. Copyright (C) 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
  3. Contributed by Paul Brook
  4. This file is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. In addition to the permissions in the GNU General Public License, the
  9. Free Software Foundation gives you unlimited permission to link the
  10. compiled version of this file into combinations with other programs,
  11. and to distribute those combinations without any restriction coming
  12. from the use of this file. (The General Public License restrictions
  13. do apply in other respects; for example, they cover modification of
  14. the file, and distribution when not linked into a combine
  15. executable.)
  16. This file is distributed in the hope that it will be useful, but
  17. WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program; see the file COPYING. If not, see
  22. <http://www.gnu.org/licenses/>. */
  23. /* Language-independent unwinder header public defines. This contains both
  24. ABI defined objects, and GNU support routines. */
  25. #ifndef UNWIND_ARM_H
  26. #define UNWIND_ARM_H
  27. #define __ARM_EABI_UNWINDER__ 1
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. typedef unsigned _Unwind_Word __attribute__((__mode__(__word__)));
  32. typedef signed _Unwind_Sword __attribute__((__mode__(__word__)));
  33. typedef unsigned _Unwind_Ptr __attribute__((__mode__(__pointer__)));
  34. typedef unsigned _Unwind_Internal_Ptr __attribute__((__mode__(__pointer__)));
  35. typedef _Unwind_Word _uw;
  36. typedef unsigned _uw64 __attribute__((mode(__DI__)));
  37. typedef unsigned _uw16 __attribute__((mode(__HI__)));
  38. typedef unsigned _uw8 __attribute__((mode(__QI__)));
  39. typedef enum
  40. {
  41. _URC_OK = 0, /* operation completed successfully */
  42. _URC_FOREIGN_EXCEPTION_CAUGHT = 1,
  43. _URC_END_OF_STACK = 5,
  44. _URC_HANDLER_FOUND = 6,
  45. _URC_INSTALL_CONTEXT = 7,
  46. _URC_CONTINUE_UNWIND = 8,
  47. _URC_FAILURE = 9 /* unspecified failure of some kind */
  48. }
  49. _Unwind_Reason_Code;
  50. typedef enum
  51. {
  52. _US_VIRTUAL_UNWIND_FRAME = 0,
  53. _US_UNWIND_FRAME_STARTING = 1,
  54. _US_UNWIND_FRAME_RESUME = 2,
  55. _US_ACTION_MASK = 3,
  56. _US_FORCE_UNWIND = 8,
  57. _US_END_OF_STACK = 16
  58. }
  59. _Unwind_State;
  60. /* Provided only for for compatibility with existing code. */
  61. typedef int _Unwind_Action;
  62. #define _UA_SEARCH_PHASE 1
  63. #define _UA_CLEANUP_PHASE 2
  64. #define _UA_HANDLER_FRAME 4
  65. #define _UA_FORCE_UNWIND 8
  66. #define _UA_END_OF_STACK 16
  67. #define _URC_NO_REASON _URC_OK
  68. typedef struct _Unwind_Control_Block _Unwind_Control_Block;
  69. typedef struct _Unwind_Context _Unwind_Context;
  70. typedef _uw _Unwind_EHT_Header;
  71. /* UCB: */
  72. struct _Unwind_Control_Block
  73. {
  74. #ifdef _LIBC
  75. /* For the benefit of code which assumes this is a scalar. All
  76. glibc ever does is clear it. */
  77. _uw64 exception_class;
  78. #else
  79. char exception_class[8];
  80. #endif
  81. void (*exception_cleanup)(_Unwind_Reason_Code, _Unwind_Control_Block *);
  82. /* Unwinder cache, private fields for the unwinder's use */
  83. struct
  84. {
  85. _uw reserved1; /* Forced unwind stop fn, 0 if not forced */
  86. _uw reserved2; /* Personality routine address */
  87. _uw reserved3; /* Saved callsite address */
  88. _uw reserved4; /* Forced unwind stop arg */
  89. _uw reserved5;
  90. }
  91. unwinder_cache;
  92. /* Propagation barrier cache (valid after phase 1): */
  93. struct
  94. {
  95. _uw sp;
  96. _uw bitpattern[5];
  97. }
  98. barrier_cache;
  99. /* Cleanup cache (preserved over cleanup): */
  100. struct
  101. {
  102. _uw bitpattern[4];
  103. }
  104. cleanup_cache;
  105. /* Pr cache (for pr's benefit): */
  106. struct
  107. {
  108. _uw fnstart; /* function start address */
  109. _Unwind_EHT_Header *ehtp; /* pointer to EHT entry header word */
  110. _uw additional; /* additional data */
  111. _uw reserved1;
  112. }
  113. pr_cache;
  114. long long int :0; /* Force alignment to 8-byte boundary */
  115. };
  116. /* Virtual Register Set*/
  117. typedef enum
  118. {
  119. _UVRSC_CORE = 0, /* integer register */
  120. _UVRSC_VFP = 1, /* vfp */
  121. _UVRSC_FPA = 2, /* fpa */
  122. _UVRSC_WMMXD = 3, /* Intel WMMX data register */
  123. _UVRSC_WMMXC = 4 /* Intel WMMX control register */
  124. }
  125. _Unwind_VRS_RegClass;
  126. typedef enum
  127. {
  128. _UVRSD_UINT32 = 0,
  129. _UVRSD_VFPX = 1,
  130. _UVRSD_FPAX = 2,
  131. _UVRSD_UINT64 = 3,
  132. _UVRSD_FLOAT = 4,
  133. _UVRSD_DOUBLE = 5
  134. }
  135. _Unwind_VRS_DataRepresentation;
  136. typedef enum
  137. {
  138. _UVRSR_OK = 0,
  139. _UVRSR_NOT_IMPLEMENTED = 1,
  140. _UVRSR_FAILED = 2
  141. }
  142. _Unwind_VRS_Result;
  143. /* Frame unwinding state. */
  144. typedef struct
  145. {
  146. /* The current word (bytes packed msb first). */
  147. _uw data;
  148. /* Pointer to the next word of data. */
  149. _uw *next;
  150. /* The number of bytes left in this word. */
  151. _uw8 bytes_left;
  152. /* The number of words pointed to by ptr. */
  153. _uw8 words_left;
  154. }
  155. __gnu_unwind_state;
  156. typedef _Unwind_Reason_Code (*personality_routine) (_Unwind_State,
  157. _Unwind_Control_Block *, _Unwind_Context *);
  158. _Unwind_VRS_Result _Unwind_VRS_Set(_Unwind_Context *, _Unwind_VRS_RegClass,
  159. _uw, _Unwind_VRS_DataRepresentation,
  160. void *);
  161. _Unwind_VRS_Result _Unwind_VRS_Get(_Unwind_Context *, _Unwind_VRS_RegClass,
  162. _uw, _Unwind_VRS_DataRepresentation,
  163. void *);
  164. _Unwind_VRS_Result _Unwind_VRS_Pop(_Unwind_Context *, _Unwind_VRS_RegClass,
  165. _uw, _Unwind_VRS_DataRepresentation);
  166. /* Support functions for the PR. */
  167. #define _Unwind_Exception _Unwind_Control_Block
  168. typedef char _Unwind_Exception_Class[8];
  169. void * _Unwind_GetLanguageSpecificData (_Unwind_Context *);
  170. _Unwind_Ptr _Unwind_GetRegionStart (_Unwind_Context *);
  171. /* These two should never be used. */
  172. _Unwind_Ptr _Unwind_GetDataRelBase (_Unwind_Context *);
  173. _Unwind_Ptr _Unwind_GetTextRelBase (_Unwind_Context *);
  174. /* Interface functions: */
  175. _Unwind_Reason_Code _Unwind_RaiseException(_Unwind_Control_Block *ucbp);
  176. void __attribute__((noreturn)) _Unwind_Resume(_Unwind_Control_Block *ucbp);
  177. _Unwind_Reason_Code _Unwind_Resume_or_Rethrow (_Unwind_Control_Block *ucbp);
  178. typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn)
  179. (int, _Unwind_Action, _Unwind_Exception_Class,
  180. _Unwind_Control_Block *, struct _Unwind_Context *, void *);
  181. _Unwind_Reason_Code _Unwind_ForcedUnwind (_Unwind_Control_Block *,
  182. _Unwind_Stop_Fn, void *);
  183. _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *);
  184. void _Unwind_Complete(_Unwind_Control_Block *ucbp);
  185. void _Unwind_DeleteException (_Unwind_Exception *);
  186. _Unwind_Reason_Code __gnu_unwind_frame (_Unwind_Control_Block *,
  187. _Unwind_Context *);
  188. _Unwind_Reason_Code __gnu_unwind_execute (_Unwind_Context *,
  189. __gnu_unwind_state *);
  190. /* Decode an R_ARM_TARGET2 relocation. */
  191. static inline _Unwind_Word
  192. _Unwind_decode_target2 (_Unwind_Word ptr)
  193. {
  194. _Unwind_Word tmp;
  195. tmp = *(_Unwind_Word *) ptr;
  196. /* Zero values are always NULL. */
  197. if (!tmp)
  198. return 0;
  199. #if defined(linux) || defined(__NetBSD__)
  200. /* Pc-relative indirect. */
  201. tmp += ptr;
  202. tmp = *(_Unwind_Word *) tmp;
  203. #elif defined(__symbian__)
  204. /* Absolute pointer. Nothing more to do. */
  205. #else
  206. /* Pc-relative pointer. */
  207. tmp += ptr;
  208. #endif
  209. return tmp;
  210. }
  211. static inline _Unwind_Word
  212. _Unwind_GetGR (_Unwind_Context *context, int regno)
  213. {
  214. _uw val;
  215. _Unwind_VRS_Get (context, _UVRSC_CORE, regno, _UVRSD_UINT32, &val);
  216. return val;
  217. }
  218. /* Return the address of the instruction, not the actual IP value. */
  219. #define _Unwind_GetIP(context) \
  220. (_Unwind_GetGR (context, 15) & ~(_Unwind_Word)1)
  221. static inline void
  222. _Unwind_SetGR (_Unwind_Context *context, int regno, _Unwind_Word val)
  223. {
  224. _Unwind_VRS_Set (context, _UVRSC_CORE, regno, _UVRSD_UINT32, &val);
  225. }
  226. /* The dwarf unwinder doesn't understand arm/thumb state. We assume the
  227. landing pad uses the same instruction set as the call site. */
  228. #define _Unwind_SetIP(context, val) \
  229. _Unwind_SetGR (context, 15, val | (_Unwind_GetGR (context, 15) & 1))
  230. typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn)
  231. (struct _Unwind_Context *, void *);
  232. extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
  233. #ifdef __cplusplus
  234. } /* extern "C" */
  235. #endif
  236. #endif /* defined UNWIND_ARM_H */