libunwind_i.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2001-2005 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  4. This file is part of libunwind.
  5. Permission is hereby granted, free of charge, to any person obtaining
  6. a copy of this software and associated documentation files (the
  7. "Software"), to deal in the Software without restriction, including
  8. without limitation the rights to use, copy, modify, merge, publish,
  9. distribute, sublicense, and/or sell copies of the Software, and to
  10. permit persons to whom the Software is furnished to do so, subject to
  11. the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  21. #ifndef IA64_LIBUNWIND_I_H
  22. #define IA64_LIBUNWIND_I_H
  23. /* Target-dependent definitions that are internal to libunwind but need
  24. to be shared with target-independent code. */
  25. #include "elf64.h"
  26. #include "mempool.h"
  27. typedef struct
  28. {
  29. /* no ia64-specific fast trace */
  30. }
  31. unw_tdep_frame_t;
  32. enum ia64_pregnum
  33. {
  34. /* primary unat: */
  35. IA64_REG_PRI_UNAT_GR,
  36. IA64_REG_PRI_UNAT_MEM,
  37. /* memory stack (order matters: see build_script() */
  38. IA64_REG_PSP, /* previous memory stack pointer */
  39. /* register stack */
  40. IA64_REG_BSP, /* register stack pointer */
  41. IA64_REG_BSPSTORE,
  42. IA64_REG_PFS, /* previous function state */
  43. IA64_REG_RNAT,
  44. /* instruction pointer: */
  45. IA64_REG_IP,
  46. /* preserved registers: */
  47. IA64_REG_R4, IA64_REG_R5, IA64_REG_R6, IA64_REG_R7,
  48. IA64_REG_NAT4, IA64_REG_NAT5, IA64_REG_NAT6, IA64_REG_NAT7,
  49. IA64_REG_UNAT, IA64_REG_PR, IA64_REG_LC, IA64_REG_FPSR,
  50. IA64_REG_B1, IA64_REG_B2, IA64_REG_B3, IA64_REG_B4, IA64_REG_B5,
  51. IA64_REG_F2, IA64_REG_F3, IA64_REG_F4, IA64_REG_F5,
  52. IA64_REG_F16, IA64_REG_F17, IA64_REG_F18, IA64_REG_F19,
  53. IA64_REG_F20, IA64_REG_F21, IA64_REG_F22, IA64_REG_F23,
  54. IA64_REG_F24, IA64_REG_F25, IA64_REG_F26, IA64_REG_F27,
  55. IA64_REG_F28, IA64_REG_F29, IA64_REG_F30, IA64_REG_F31,
  56. IA64_NUM_PREGS
  57. };
  58. #ifdef UNW_LOCAL_ONLY
  59. typedef unw_word_t ia64_loc_t;
  60. #else /* !UNW_LOCAL_ONLY */
  61. typedef struct ia64_loc
  62. {
  63. unw_word_t w0, w1;
  64. }
  65. ia64_loc_t;
  66. #endif /* !UNW_LOCAL_ONLY */
  67. #include "script.h"
  68. #define ABI_UNKNOWN 0
  69. #define ABI_LINUX 1
  70. #define ABI_HPUX 2
  71. #define ABI_FREEBSD 3
  72. #define ABI_OPENVMS 4
  73. #define ABI_NSK 5 /* Tandem/HP Non-Stop Kernel */
  74. #define ABI_WINDOWS 6
  75. struct unw_addr_space
  76. {
  77. struct unw_accessors acc;
  78. int big_endian;
  79. int abi; /* abi < 0 => unknown, 0 => SysV, 1 => HP-UX, 2 => Windows */
  80. unw_caching_policy_t caching_policy;
  81. #ifdef HAVE_ATOMIC_OPS_H
  82. AO_t cache_generation;
  83. #else
  84. uint32_t cache_generation;
  85. #endif
  86. unw_word_t dyn_generation;
  87. unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
  88. #ifndef UNW_REMOTE_ONLY
  89. unsigned long long shared_object_removals;
  90. #endif
  91. struct ia64_script_cache global_cache;
  92. };
  93. /* Note: The ABI numbers in the ABI-markers (.unwabi directive) are
  94. not the same as the above ABI numbers. */
  95. #define ABI_MARKER_OLD_LINUX_SIGTRAMP ((0 << 8) | 's')
  96. #define ABI_MARKER_OLD_LINUX_INTERRUPT ((0 << 8) | 'i')
  97. #define ABI_MARKER_HP_UX_SIGTRAMP ((1 << 8) | 1)
  98. #define ABI_MARKER_LINUX_SIGTRAMP ((3 << 8) | 's')
  99. #define ABI_MARKER_LINUX_INTERRUPT ((3 << 8) | 'i')
  100. struct cursor
  101. {
  102. void *as_arg; /* argument to address-space callbacks */
  103. unw_addr_space_t as; /* reference to per-address-space info */
  104. /* IP, CFM, and predicate cache (these are always equal to the
  105. values stored in ip_loc, cfm_loc, and pr_loc,
  106. respectively). */
  107. unw_word_t ip; /* instruction pointer value */
  108. unw_word_t cfm; /* current frame mask */
  109. unw_word_t pr; /* current predicate values */
  110. /* current frame info: */
  111. unw_word_t bsp; /* backing store pointer value */
  112. unw_word_t sp; /* stack pointer value */
  113. unw_word_t psp; /* previous sp value */
  114. ia64_loc_t cfm_loc; /* cfm save location (or NULL) */
  115. ia64_loc_t ec_loc; /* ar.ec save location (usually cfm_loc) */
  116. ia64_loc_t loc[IA64_NUM_PREGS];
  117. unw_word_t eh_args[4]; /* exception handler arguments */
  118. unw_word_t sigcontext_addr; /* address of sigcontext or 0 */
  119. unw_word_t sigcontext_off; /* sigcontext-offset relative to signal sp */
  120. short hint;
  121. short prev_script;
  122. uint8_t nat_bitnr[4]; /* NaT bit numbers for r4-r7 */
  123. uint16_t abi_marker; /* abi_marker for current frame (if any) */
  124. uint16_t last_abi_marker; /* last abi_marker encountered so far */
  125. uint8_t eh_valid_mask;
  126. unsigned int pi_valid :1; /* is proc_info valid? */
  127. unsigned int pi_is_dynamic :1; /* proc_info found via dynamic proc info? */
  128. unw_proc_info_t pi; /* info about current procedure */
  129. /* In case of stack-discontiguities, such as those introduced by
  130. signal-delivery on an alternate signal-stack (see
  131. sigaltstack(2)), we use the following data-structure to keep
  132. track of the register-backing-store areas across on which the
  133. current frame may be backed up. Since there are at most 96
  134. stacked registers and since we only have to track the current
  135. frame and only areas that are not empty, this puts an upper
  136. limit on the # of backing-store areas we have to track.
  137. Note that the rbs-area indexed by rbs_curr identifies the
  138. rbs-area that was in effect at the time AR.BSP had the value
  139. c->bsp. However, this rbs area may not actually contain the
  140. value in the register that c->bsp corresponds to because that
  141. register may not have gotten spilled until much later, when a
  142. possibly different rbs-area might have been in effect
  143. already. */
  144. uint8_t rbs_curr; /* index of curr. rbs-area (contains c->bsp) */
  145. uint8_t rbs_left_edge; /* index of inner-most valid rbs-area */
  146. struct rbs_area
  147. {
  148. unw_word_t end;
  149. unw_word_t size;
  150. ia64_loc_t rnat_loc;
  151. }
  152. rbs_area[96 + 2]; /* 96 stacked regs + 1 extra stack on each side... */
  153. };
  154. struct ia64_global_unwind_state
  155. {
  156. pthread_mutex_t lock; /* global data lock */
  157. volatile char needs_initialization;
  158. /* Table of registers that prologues can save (and order in which
  159. they're saved). */
  160. const unsigned char save_order[8];
  161. /*
  162. * uc_addr() may return pointers to these variables. We need to
  163. * make sure they don't get written via ia64_put() or
  164. * ia64_putfp(). To make it possible to test for these variables
  165. * quickly, we collect them in a single sub-structure.
  166. */
  167. struct
  168. {
  169. unw_word_t r0; /* r0 is byte-order neutral */
  170. unw_fpreg_t f0; /* f0 is byte-order neutral */
  171. unw_fpreg_t f1_le, f1_be; /* f1 is byte-order dependent */
  172. }
  173. read_only;
  174. unw_fpreg_t nat_val_le, nat_val_be;
  175. unw_fpreg_t int_val_le, int_val_be;
  176. struct mempool reg_state_pool;
  177. struct mempool labeled_state_pool;
  178. # if UNW_DEBUG
  179. const char *preg_name[IA64_NUM_PREGS];
  180. # endif
  181. };
  182. #define tdep_getcontext_trace unw_getcontext
  183. #define tdep_needs_initialization unw.needs_initialization
  184. #define tdep_init UNW_OBJ(init)
  185. /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
  186. tdep_search_unwind_table. */
  187. #define tdep_search_unwind_table unw_search_ia64_unwind_table
  188. #define tdep_find_unwind_table ia64_find_unwind_table
  189. #define tdep_find_proc_info UNW_OBJ(find_proc_info)
  190. #define tdep_uc_addr UNW_OBJ(uc_addr)
  191. #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
  192. #define tdep_access_reg UNW_OBJ(access_reg)
  193. #define tdep_access_fpreg UNW_OBJ(access_fpreg)
  194. #define tdep_fetch_frame(c,ip,n) do {} while(0)
  195. #define tdep_cache_frame(c,rs) do {} while(0)
  196. #define tdep_reuse_frame(c,rs) do {} while(0)
  197. #define tdep_stash_frame(c,rs) do {} while(0)
  198. #define tdep_trace(cur,addr,n) (-UNW_ENOINFO)
  199. #define tdep_get_as(c) ((c)->as)
  200. #define tdep_get_as_arg(c) ((c)->as_arg)
  201. #define tdep_get_ip(c) ((c)->ip)
  202. #define tdep_big_endian(as) ((c)->as->big_endian != 0)
  203. #ifndef UNW_LOCAL_ONLY
  204. # define tdep_put_unwind_info UNW_OBJ(put_unwind_info)
  205. #endif
  206. /* This can't be an UNW_ARCH_OBJ() because we need separate
  207. unw.initialized flags for the local-only and generic versions of
  208. the library. Also, if we wanted to have a single, shared global
  209. data structure, we couldn't declare "unw" as HIDDEN/PROTECTED. */
  210. #define unw UNW_OBJ(data)
  211. extern void tdep_init (void);
  212. extern int tdep_find_proc_info (unw_addr_space_t as, unw_word_t ip,
  213. unw_proc_info_t *pi, int need_unwind_info,
  214. void *arg);
  215. extern void tdep_put_unwind_info (unw_addr_space_t as,
  216. unw_proc_info_t *pi, void *arg);
  217. extern void *tdep_uc_addr (ucontext_t *uc, unw_regnum_t regnum,
  218. uint8_t *nat_bitnr);
  219. extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
  220. unsigned long *segbase, unsigned long *mapoff,
  221. char *path, size_t pathlen);
  222. extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg,
  223. unw_word_t *valp, int write);
  224. extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg,
  225. unw_fpreg_t *valp, int write);
  226. extern struct ia64_global_unwind_state unw;
  227. /* In user-level, we have no reasonable way of determining the base of
  228. an arbitrary backing-store. We default to half the
  229. address-space. */
  230. #define rbs_get_base(c,bspstore,rbs_basep) \
  231. (*(rbs_basep) = (bspstore) - (((unw_word_t) 1) << 63), 0)
  232. #endif /* IA64_LIBUNWIND_I_H */