1 /* libunwind - a platform-independent unwind library
2 Copyright (C) 2002-2005 Hewlett-Packard Co
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of libunwind.
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
26 #ifndef X86_LIBUNWIND_I_H
27 #define X86_LIBUNWIND_I_H
29 /* Target-dependent definitions that are internal to libunwind but need
30 to be shared with target-independent code. */
33 #include <libunwind.h>
41 /* no x86-specific fast trace */
47 struct unw_accessors acc
;
48 unw_caching_policy_t caching_policy
;
49 #ifdef HAVE_ATOMIC_OPS_H
50 AO_t cache_generation
;
52 uint32_t cache_generation
;
54 unw_word_t dyn_generation
; /* see dyn-common.h */
55 unw_word_t dyn_info_list_addr
; /* (cached) dyn_info_list_addr */
56 struct dwarf_rs_cache global_cache
;
57 struct unw_debug_frame_list
*debug_frames
;
62 struct dwarf_cursor dwarf
; /* must be first */
64 /* Format of sigcontext structure and address at which it is
68 X86_SCF_NONE
, /* no signal frame encountered */
69 X86_SCF_LINUX_SIGFRAME
, /* Linux x86 sigcontext */
70 X86_SCF_LINUX_RT_SIGFRAME
, /* POSIX ucontext_t */
71 X86_SCF_FREEBSD_SIGFRAME
, /* FreeBSD x86 sigcontext */
72 X86_SCF_FREEBSD_SIGFRAME4
, /* FreeBSD 4.x x86 sigcontext */
73 X86_SCF_FREEBSD_OSIGFRAME
, /* FreeBSD pre-4.x x86 sigcontext */
74 X86_SCF_FREEBSD_SYSCALL
, /* FreeBSD x86 syscall */
77 unw_word_t sigcontext_addr
;
82 static inline ucontext_t
*
83 dwarf_get_uc(const struct dwarf_cursor
*cursor
)
85 const struct cursor
*c
= (struct cursor
*) cursor
->as_arg
;
89 #define DWARF_GET_LOC(l) ((l).val)
92 # define DWARF_NULL_LOC DWARF_LOC (0, 0)
93 # define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0)
94 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) })
95 # define DWARF_IS_REG_LOC(l) 0
96 # define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \
97 tdep_uc_addr(dwarf_get_uc(c), (r)), 0))
98 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
99 # define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \
100 tdep_uc_addr(dwarf_get_uc(c), (r)), 0))
103 dwarf_getfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t
*val
)
105 if (!DWARF_GET_LOC (loc
))
107 *val
= *(unw_fpreg_t
*) DWARF_GET_LOC (loc
);
112 dwarf_putfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t val
)
114 if (!DWARF_GET_LOC (loc
))
116 *(unw_fpreg_t
*) DWARF_GET_LOC (loc
) = val
;
121 dwarf_get (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t
*val
)
123 if (!DWARF_GET_LOC (loc
))
125 return (*c
->as
->acc
.access_mem
) (c
->as
, DWARF_GET_LOC (loc
), val
,
130 dwarf_put (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t val
)
132 if (!DWARF_GET_LOC (loc
))
134 return (*c
->as
->acc
.access_mem
) (c
->as
, DWARF_GET_LOC (loc
), &val
,
138 #else /* !UNW_LOCAL_ONLY */
139 # define DWARF_LOC_TYPE_FP (1 << 0)
140 # define DWARF_LOC_TYPE_REG (1 << 1)
141 # define DWARF_NULL_LOC DWARF_LOC (0, 0)
142 # define DWARF_IS_NULL_LOC(l) \
143 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; })
144 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) })
145 # define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0)
146 # define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0)
147 # define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG)
148 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0)
149 # define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \
150 | DWARF_LOC_TYPE_FP))
153 dwarf_getfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t
*val
)
155 char *valp
= (char *) &val
;
159 if (DWARF_IS_NULL_LOC (loc
))
162 if (DWARF_IS_REG_LOC (loc
))
163 return (*c
->as
->acc
.access_fpreg
) (c
->as
, DWARF_GET_LOC (loc
),
166 addr
= DWARF_GET_LOC (loc
);
167 if ((ret
= (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 0, (unw_word_t
*) valp
,
171 return (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 4, (unw_word_t
*) valp
+ 1, 0,
176 dwarf_putfp (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_fpreg_t val
)
178 char *valp
= (char *) &val
;
182 if (DWARF_IS_NULL_LOC (loc
))
185 if (DWARF_IS_REG_LOC (loc
))
186 return (*c
->as
->acc
.access_fpreg
) (c
->as
, DWARF_GET_LOC (loc
),
189 addr
= DWARF_GET_LOC (loc
);
190 if ((ret
= (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 0, (unw_word_t
*) valp
,
194 return (*c
->as
->acc
.access_mem
) (c
->as
, addr
+ 4, (unw_word_t
*) valp
+ 1,
199 dwarf_get (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t
*val
)
201 if (DWARF_IS_NULL_LOC (loc
))
204 /* If a code-generator were to save a value of type unw_word_t in a
205 floating-point register, we would have to support this case. I
206 suppose it could happen with MMX registers, but does it really
208 assert (!DWARF_IS_FP_LOC (loc
));
210 if (DWARF_IS_REG_LOC (loc
))
211 return (*c
->as
->acc
.access_reg
) (c
->as
, DWARF_GET_LOC (loc
), val
,
214 return (*c
->as
->acc
.access_mem
) (c
->as
, DWARF_GET_LOC (loc
), val
,
219 dwarf_put (struct dwarf_cursor
*c
, dwarf_loc_t loc
, unw_word_t val
)
221 if (DWARF_IS_NULL_LOC (loc
))
224 /* If a code-generator were to save a value of type unw_word_t in a
225 floating-point register, we would have to support this case. I
226 suppose it could happen with MMX registers, but does it really
228 assert (!DWARF_IS_FP_LOC (loc
));
230 if (DWARF_IS_REG_LOC (loc
))
231 return (*c
->as
->acc
.access_reg
) (c
->as
, DWARF_GET_LOC (loc
), &val
,
234 return (*c
->as
->acc
.access_mem
) (c
->as
, DWARF_GET_LOC (loc
), &val
,
238 #endif /* !UNW_LOCAL_ONLY */
240 #define tdep_getcontext_trace unw_getcontext
241 #define tdep_init_done UNW_OBJ(init_done)
242 #define tdep_init UNW_OBJ(init)
243 /* Platforms that support UNW_INFO_FORMAT_TABLE need to define
244 tdep_search_unwind_table. */
245 #define tdep_search_unwind_table dwarf_search_unwind_table
246 #define tdep_find_unwind_table dwarf_find_unwind_table
247 #define tdep_uc_addr UNW_ARCH_OBJ(uc_addr)
248 #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image)
249 #define tdep_access_reg UNW_OBJ(access_reg)
250 #define tdep_access_fpreg UNW_OBJ(access_fpreg)
251 #define tdep_fetch_frame(c,ip,n) do {} while(0)
252 #define tdep_cache_frame(c,rs) do {} while(0)
253 #define tdep_reuse_frame(c,rs) do {} while(0)
254 #define tdep_stash_frame(c,rs) do {} while(0)
255 #define tdep_trace(cur,addr,n) (-UNW_ENOINFO)
257 #ifdef UNW_LOCAL_ONLY
258 # define tdep_find_proc_info(c,ip,n) \
259 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \
261 # define tdep_put_unwind_info(as,pi,arg) \
262 dwarf_put_unwind_info((as), (pi), (arg))
264 # define tdep_find_proc_info(c,ip,n) \
265 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \
267 # define tdep_put_unwind_info(as,pi,arg) \
268 (*(as)->acc.put_unwind_info)((as), (pi), (arg))
271 #define tdep_get_as(c) ((c)->dwarf.as)
272 #define tdep_get_as_arg(c) ((c)->dwarf.as_arg)
273 #define tdep_get_ip(c) ((c)->dwarf.ip)
274 #define tdep_big_endian(as) 0
276 extern int tdep_init_done
;
278 extern void tdep_init (void);
279 extern int tdep_search_unwind_table (unw_addr_space_t as
, unw_word_t ip
,
280 unw_dyn_info_t
*di
, unw_proc_info_t
*pi
,
281 int need_unwind_info
, void *arg
);
282 extern void *tdep_uc_addr (ucontext_t
*uc
, int reg
);
283 extern int tdep_get_elf_image (struct elf_image
*ei
, pid_t pid
, unw_word_t ip
,
284 unsigned long *segbase
, unsigned long *mapoff
,
285 char *path
, size_t pathlen
);
286 extern int tdep_access_reg (struct cursor
*c
, unw_regnum_t reg
,
287 unw_word_t
*valp
, int write
);
288 extern int tdep_access_fpreg (struct cursor
*c
, unw_regnum_t reg
,
289 unw_fpreg_t
*valp
, int write
);
291 #endif /* X86_LIBUNWIND_I_H */