unwind.h 8.7 KB

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