unwind.h 8.6 KB

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