libunwind-common.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2001-2004 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <[email protected]>
  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. /* ANDROID support update. */
  22. #include <sys/types.h>
  23. /* End of ANDROID update. */
  24. #define UNW_VERSION_MAJOR 1
  25. #define UNW_VERSION_MINOR 1
  26. #define UNW_VERSION_EXTRA
  27. #define UNW_VERSION_CODE(maj,min) (((maj) << 16) | (min))
  28. #define UNW_VERSION UNW_VERSION_CODE(UNW_VERSION_MAJOR, UNW_VERSION_MINOR)
  29. #define UNW_PASTE2(x,y) x##y
  30. #define UNW_PASTE(x,y) UNW_PASTE2(x,y)
  31. #define UNW_OBJ(fn) UNW_PASTE(UNW_PREFIX, fn)
  32. #define UNW_ARCH_OBJ(fn) UNW_PASTE(UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_), fn)
  33. #ifdef UNW_LOCAL_ONLY
  34. # ifdef UNW_ADDITIONAL_PREFIX
  35. # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_UUL,UNW_TARGET),_)
  36. # else
  37. # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_UL,UNW_TARGET),_)
  38. # endif
  39. #else /* !UNW_LOCAL_ONLY */
  40. # ifdef UNW_ADDITIONAL_PREFIX
  41. # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_UU,UNW_TARGET),_)
  42. # else
  43. # define UNW_PREFIX UNW_PASTE(UNW_PASTE(_U,UNW_TARGET),_)
  44. # endif
  45. #endif /* !UNW_LOCAL_ONLY */
  46. /* Error codes. The unwind routines return the *negated* values of
  47. these error codes on error and a non-negative value on success. */
  48. typedef enum
  49. {
  50. UNW_ESUCCESS = 0, /* no error */
  51. UNW_EUNSPEC, /* unspecified (general) error */
  52. UNW_ENOMEM, /* out of memory */
  53. UNW_EBADREG, /* bad register number */
  54. UNW_EREADONLYREG, /* attempt to write read-only register */
  55. UNW_ESTOPUNWIND, /* stop unwinding */
  56. UNW_EINVALIDIP, /* invalid IP */
  57. UNW_EBADFRAME, /* bad frame */
  58. UNW_EINVAL, /* unsupported operation or bad value */
  59. UNW_EBADVERSION, /* unwind info has unsupported version */
  60. UNW_ENOINFO /* no unwind info found */
  61. }
  62. unw_error_t;
  63. /* The following enum defines the indices for a couple of
  64. (pseudo-)registers which have the same meaning across all
  65. platforms. (RO) means read-only. (RW) means read-write. General
  66. registers (aka "integer registers") are expected to start with
  67. index 0. The number of such registers is architecture-dependent.
  68. The remaining indices can be used as an architecture sees fit. The
  69. last valid register index is given by UNW_REG_LAST. */
  70. typedef enum
  71. {
  72. UNW_REG_IP = UNW_TDEP_IP, /* (rw) instruction pointer (pc) */
  73. UNW_REG_SP = UNW_TDEP_SP, /* (ro) stack pointer */
  74. UNW_REG_EH = UNW_TDEP_EH, /* (rw) exception-handling reg base */
  75. UNW_REG_LAST = UNW_TDEP_LAST_REG
  76. }
  77. unw_frame_regnum_t;
  78. /* Number of exception-handler argument registers: */
  79. #define UNW_NUM_EH_REGS UNW_TDEP_NUM_EH_REGS
  80. typedef enum
  81. {
  82. UNW_CACHE_NONE, /* no caching */
  83. UNW_CACHE_GLOBAL, /* shared global cache */
  84. UNW_CACHE_PER_THREAD /* per-thread caching */
  85. }
  86. unw_caching_policy_t;
  87. typedef int unw_regnum_t;
  88. /* The unwind cursor starts at the youngest (most deeply nested) frame
  89. and is used to track the frame state as the unwinder steps from
  90. frame to frame. It is safe to make (shallow) copies of variables
  91. of this type. */
  92. typedef struct unw_cursor
  93. {
  94. unw_word_t opaque[UNW_TDEP_CURSOR_LEN];
  95. }
  96. unw_cursor_t;
  97. /* This type encapsulates the entire (preserved) machine-state. */
  98. typedef unw_tdep_context_t unw_context_t;
  99. /* unw_getcontext() fills the unw_context_t pointed to by UC with the
  100. machine state as it exists at the call-site. For implementation
  101. reasons, this needs to be a target-dependent macro. It's easiest
  102. to think of unw_getcontext() as being identical to getcontext(). */
  103. #define unw_getcontext(uc) unw_tdep_getcontext(uc)
  104. /* Return 1 if register number R is a floating-point register, zero
  105. otherwise.
  106. This routine is signal-safe. */
  107. #define unw_is_fpreg(r) unw_tdep_is_fpreg(r)
  108. typedef unw_tdep_fpreg_t unw_fpreg_t;
  109. typedef struct unw_addr_space *unw_addr_space_t;
  110. /* Each target may define it's own set of flags, but bits 0-15 are
  111. reserved for general libunwind-use. */
  112. #define UNW_PI_FLAG_FIRST_TDEP_BIT 16
  113. /* The information comes from a .debug_frame section. */
  114. #define UNW_PI_FLAG_DEBUG_FRAME 32
  115. typedef struct unw_proc_info
  116. {
  117. unw_word_t start_ip; /* first IP covered by this procedure */
  118. unw_word_t end_ip; /* first IP NOT covered by this procedure */
  119. unw_word_t lsda; /* address of lang.-spec. data area (if any) */
  120. unw_word_t handler; /* optional personality routine */
  121. unw_word_t gp; /* global-pointer value for this procedure */
  122. unw_word_t flags; /* misc. flags */
  123. int format; /* unwind-info format (arch-specific) */
  124. int unwind_info_size; /* size of the information (if applicable) */
  125. void *unwind_info; /* unwind-info (arch-specific) */
  126. unw_tdep_proc_info_t extra; /* target-dependent auxiliary proc-info */
  127. }
  128. unw_proc_info_t;
  129. /* These are backend callback routines that provide access to the
  130. state of a "remote" process. This can be used, for example, to
  131. unwind another process through the ptrace() interface. */
  132. typedef struct unw_accessors
  133. {
  134. /* Look up the unwind info associated with instruction-pointer IP.
  135. On success, the routine fills in the PROC_INFO structure. */
  136. int (*find_proc_info) (unw_addr_space_t, unw_word_t, unw_proc_info_t *,
  137. int, void *);
  138. /* Release any resources (e.g., memory) that were allocated for
  139. the unwind info returned in by a previous call to
  140. find_proc_info() with NEED_UNWIND_INFO set to 1. */
  141. void (*put_unwind_info) (unw_addr_space_t, unw_proc_info_t *, void *);
  142. /* Return the list-head of the dynamically registered unwind
  143. info. */
  144. int (*get_dyn_info_list_addr) (unw_addr_space_t, unw_word_t *, void *);
  145. /* Access aligned word at address ADDR. The value is returned
  146. according to the endianness of the host (e.g., if the host is
  147. little-endian and the target is big-endian, access_mem() needs
  148. to byte-swap the value before returning it). */
  149. int (*access_mem) (unw_addr_space_t, unw_word_t, unw_word_t *, int,
  150. void *);
  151. /* Access register number REG at address ADDR. */
  152. int (*access_reg) (unw_addr_space_t, unw_regnum_t, unw_word_t *, int,
  153. void *);
  154. /* Access register number REG at address ADDR. */
  155. int (*access_fpreg) (unw_addr_space_t, unw_regnum_t,
  156. unw_fpreg_t *, int, void *);
  157. int (*resume) (unw_addr_space_t, unw_cursor_t *, void *);
  158. /* Optional call back to obtain the name of a (static) procedure.
  159. Dynamically generated procedures are handled automatically by
  160. libunwind. This callback is optional and may be set to
  161. NULL. */
  162. int (*get_proc_name) (unw_addr_space_t, unw_word_t, char *, size_t,
  163. unw_word_t *, void *);
  164. }
  165. unw_accessors_t;
  166. typedef enum unw_save_loc_type
  167. {
  168. UNW_SLT_NONE, /* register is not saved ("not an l-value") */
  169. UNW_SLT_MEMORY, /* register has been saved in memory */
  170. UNW_SLT_REG /* register has been saved in (another) register */
  171. }
  172. unw_save_loc_type_t;
  173. typedef struct unw_save_loc
  174. {
  175. unw_save_loc_type_t type;
  176. union
  177. {
  178. unw_word_t addr; /* valid if type==UNW_SLT_MEMORY */
  179. unw_regnum_t regnum; /* valid if type==UNW_SLT_REG */
  180. }
  181. u;
  182. unw_tdep_save_loc_t extra; /* target-dependent additional information */
  183. }
  184. unw_save_loc_t;
  185. /* ANDROID support update. */
  186. typedef struct unw_map_cursor
  187. {
  188. void *map_list;
  189. void *cur_map;
  190. }
  191. unw_map_cursor_t;
  192. typedef struct unw_map
  193. {
  194. unw_word_t start;
  195. unw_word_t end;
  196. unw_word_t offset;
  197. unw_word_t load_base;
  198. char *path;
  199. int flags;
  200. }
  201. unw_map_t;
  202. /* End of ANDROID update. */
  203. /* These routines work both for local and remote unwinding. */
  204. #define unw_local_access_addr_space_init UNW_OBJ(local_access_addr_space_init)
  205. #define unw_local_addr_space UNW_OBJ(local_addr_space)
  206. #define unw_create_addr_space UNW_OBJ(create_addr_space)
  207. #define unw_destroy_addr_space UNW_OBJ(destroy_addr_space)
  208. #define unw_get_accessors UNW_ARCH_OBJ(get_accessors)
  209. #define unw_init_local UNW_OBJ(init_local)
  210. #define unw_init_remote UNW_OBJ(init_remote)
  211. #define unw_step UNW_OBJ(step)
  212. #define unw_resume UNW_OBJ(resume)
  213. #define unw_get_proc_info UNW_OBJ(get_proc_info)
  214. #define unw_get_proc_info_by_ip UNW_OBJ(get_proc_info_by_ip)
  215. #define unw_get_reg UNW_OBJ(get_reg)
  216. #define unw_set_reg UNW_OBJ(set_reg)
  217. #define unw_get_fpreg UNW_OBJ(get_fpreg)
  218. #define unw_set_fpreg UNW_OBJ(set_fpreg)
  219. #define unw_get_save_loc UNW_OBJ(get_save_loc)
  220. #define unw_is_signal_frame UNW_OBJ(is_signal_frame)
  221. #define unw_handle_signal_frame UNW_OBJ(handle_signal_frame)
  222. #define unw_get_proc_name UNW_OBJ(get_proc_name)
  223. #define unw_get_proc_name_by_ip UNW_OBJ(get_proc_name_by_ip)
  224. #define unw_set_caching_policy UNW_OBJ(set_caching_policy)
  225. #define unw_regname UNW_ARCH_OBJ(regname)
  226. #define unw_flush_cache UNW_ARCH_OBJ(flush_cache)
  227. #define unw_strerror UNW_ARCH_OBJ(strerror)
  228. extern void unw_local_access_addr_space_init (unw_addr_space_t);
  229. extern unw_addr_space_t unw_create_addr_space (unw_accessors_t *, int);
  230. extern void unw_destroy_addr_space (unw_addr_space_t);
  231. extern unw_accessors_t *unw_get_accessors (unw_addr_space_t);
  232. extern void unw_flush_cache (unw_addr_space_t, unw_word_t, unw_word_t);
  233. extern int unw_set_caching_policy (unw_addr_space_t, unw_caching_policy_t);
  234. extern const char *unw_regname (unw_regnum_t);
  235. extern int unw_init_local (unw_cursor_t *, unw_context_t *);
  236. extern int unw_init_remote (unw_cursor_t *, unw_addr_space_t, void *);
  237. extern int unw_step (unw_cursor_t *);
  238. extern int unw_resume (unw_cursor_t *);
  239. extern int unw_get_proc_info (unw_cursor_t *, unw_proc_info_t *);
  240. extern int unw_get_proc_info_by_ip (unw_addr_space_t, unw_word_t,
  241. unw_proc_info_t *, void *);
  242. extern int unw_get_reg (unw_cursor_t *, int, unw_word_t *);
  243. extern int unw_set_reg (unw_cursor_t *, int, unw_word_t);
  244. extern int unw_get_fpreg (unw_cursor_t *, int, unw_fpreg_t *);
  245. extern int unw_set_fpreg (unw_cursor_t *, int, unw_fpreg_t);
  246. extern int unw_get_save_loc (unw_cursor_t *, int, unw_save_loc_t *);
  247. extern int unw_is_signal_frame (unw_cursor_t *);
  248. extern int unw_handle_signal_frame (unw_cursor_t *);
  249. extern int unw_get_proc_name (unw_cursor_t *, char *, size_t, unw_word_t *);
  250. extern int unw_get_proc_name_by_ip (unw_addr_space_t, unw_word_t, char *,
  251. size_t, unw_word_t *, void *);
  252. extern const char *unw_strerror (int);
  253. extern int unw_backtrace (void **, int);
  254. /* ANDROID support update. */
  255. extern int unw_map_local_cursor_valid (unw_map_cursor_t *);
  256. extern void unw_map_local_cursor_get (unw_map_cursor_t *);
  257. extern int unw_map_local_cursor_get_next (unw_map_cursor_t *, unw_map_t *);
  258. extern int unw_map_local_create (void);
  259. extern void unw_map_local_destroy (void);
  260. extern void unw_map_set (unw_addr_space_t, unw_map_cursor_t *);
  261. extern void unw_map_cursor_reset (unw_map_cursor_t *);
  262. extern void unw_map_cursor_clear (unw_map_cursor_t *);
  263. extern int unw_map_cursor_create (unw_map_cursor_t *, pid_t);
  264. extern void unw_map_cursor_destroy (unw_map_cursor_t *);
  265. extern int unw_map_cursor_get_next (unw_map_cursor_t *, unw_map_t *);
  266. /* End of ANDROID update. */
  267. extern unw_addr_space_t unw_local_addr_space;