1
/* libunwind - a platform-independent unwind library
2
Copyright (C) 2002-2004 Hewlett-Packard Co
3
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5
Modified for x86_64 by Max Asbock <masbock@us.ibm.com>
7
This file is part of libunwind.
9
Permission is hereby granted, free of charge, to any person obtaining
10
a copy of this software and associated documentation files (the
11
"Software"), to deal in the Software without restriction, including
12
without limitation the rights to use, copy, modify, merge, publish,
13
distribute, sublicense, and/or sell copies of the Software, and to
14
permit persons to whom the Software is furnished to do so, subject to
15
the following conditions:
17
The above copyright notice and this permission notice shall be
18
included in all copies or substantial portions of the Software.
20
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
31
/* Target-dependent definitions that are internal to libunwind but need
32
to be shared with target-independent code. */
35
#include <libunwind.h>
42
struct unw_accessors acc;
43
unw_caching_policy_t caching_policy;
44
uint32_t cache_generation;
45
unw_word_t dyn_generation; /* see dyn-common.h */
46
unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */
51
struct dwarf_cursor dwarf; /* must be first */
53
/* Format of sigcontext structure and address at which it is
57
X86_64_SCF_NONE, /* no signal frame encountered */
58
X86_64_SCF_LINUX_RT_SIGFRAME /* POSIX ucontext_t */
61
unw_word_t sigcontext_addr;
64
#define DWARF_GET_LOC(l) ((l).val)
67
# define DWARF_NULL_LOC DWARF_LOC (0, 0)
68
# define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
69
# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
70
# define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \
71
tdep_uc_addr((c)->as_arg, (r)), 0))
72
# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
73
# define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
74
tdep_uc_addr((c)->as_arg, (r)), 0))
77
dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
79
if (!DWARF_GET_LOC (loc))
81
*val = *(unw_fpreg_t *) DWARF_GET_LOC (loc);
86
dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
88
if (!DWARF_GET_LOC (loc))
90
*(unw_fpreg_t *) DWARF_GET_LOC (loc) = val;
95
dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
97
if (!DWARF_GET_LOC (loc))
99
*val = *(unw_word_t *) DWARF_GET_LOC (loc);
104
dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
106
if (!DWARF_GET_LOC (loc))
108
*(unw_word_t *) DWARF_GET_LOC (loc) = val;
112
#else /* !UNW_LOCAL_ONLY */
113
# define DWARF_LOC_TYPE_FP (1 << 0)
114
# define DWARF_LOC_TYPE_REG (1 << 1)
115
# define DWARF_NULL_LOC DWARF_LOC (0, 0)
116
# define DWARF_IS_NULL_LOC(l) \
117
({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
118
# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
119
# define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
120
# define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
121
# define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
122
# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
123
# define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
124
| DWARF_LOC_TYPE_FP))
127
dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val)
129
if (DWARF_IS_NULL_LOC (loc))
137
dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val)
139
if (DWARF_IS_NULL_LOC (loc))
147
dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val)
149
if (DWARF_IS_NULL_LOC (loc))
152
if (DWARF_IS_FP_LOC (loc))
156
if (DWARF_IS_REG_LOC (loc))
157
return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val,
160
return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val,
165
dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val)
167
if (DWARF_IS_NULL_LOC (loc))
170
if (DWARF_IS_FP_LOC (loc))
174
if (DWARF_IS_REG_LOC (loc))
175
return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val,
178
return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val,
182
#endif /* !UNW_LOCAL_ONLY */
184
#define tdep_needs_initialization UNW_OBJ(needs_initialization)
185
#define tdep_init UNW_OBJ(init)
186
/* Platforms that support UNW_INFO_FORMAT_TABLE need to define
187
tdep_search_unwind_table. */
188
#define tdep_search_unwind_table dwarf_search_unwind_table
189
#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
190
#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
191
#define tdep_access_reg UNW_OBJ(access_reg)
192
#define tdep_access_fpreg UNW_OBJ(access_fpreg)
194
#ifdef UNW_LOCAL_ONLY
195
# define tdep_find_proc_info(c,ip,n) \
196
dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
198
# define tdep_put_unwind_info(c,pi) \
199
dwarf_put_unwind_info((c)->as, (pi), (c)->as_arg)
201
# define tdep_find_proc_info(c,ip,n) \
202
(*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
204
# define tdep_put_unwind_info(c,pi) \
205
(*(c)->as->acc.put_unwind_info)((c)->as, (pi), (c)->as_arg)
208
#define tdep_get_as(c) ((c)->dwarf.as)
209
#define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
210
#define tdep_get_ip(c) ((c)->dwarf.ip)
211
#define tdep_big_endian(as) 0
213
extern int tdep_needs_initialization;
215
extern void tdep_init (void);
216
extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip,
217
unw_dyn_info_t *di, unw_proc_info_t *pi,
218
int need_unwind_info, void *arg);
219
extern void *tdep_uc_addr (ucontext_t *uc, int reg);
220
extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip,
221
unsigned long *segbase, unsigned long *mapoff);
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);
227
#endif /* TDEP_X86_64_H */