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