libunwind_i.h revision 37be21c01ebe23402d4b5f1391e7a83da34e8c32
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> 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 26#ifndef X86_LIBUNWIND_I_H 27#define X86_LIBUNWIND_I_H 28 29/* Target-dependent definitions that are internal to libunwind but need 30 to be shared with target-independent code. */ 31 32#include <stdlib.h> 33#include <libunwind.h> 34 35#include "elf32.h" 36#include "dwarf.h" 37 38struct unw_addr_space 39 { 40 struct unw_accessors acc; 41 unw_caching_policy_t caching_policy; 42#ifdef HAVE_ATOMIC_OPS_H 43 AO_t cache_generation; 44#else 45 uint32_t cache_generation; 46#endif 47 unw_word_t dyn_generation; /* see dyn-common.h */ 48 unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */ 49 }; 50 51struct cursor 52 { 53 struct dwarf_cursor dwarf; /* must be first */ 54 55 /* Format of sigcontext structure and address at which it is 56 stored: */ 57 enum 58 { 59 X86_SCF_NONE, /* no signal frame encountered */ 60 X86_SCF_LINUX_SIGFRAME, /* classic x86 sigcontext */ 61 X86_SCF_LINUX_RT_SIGFRAME /* POSIX ucontext_t */ 62 } 63 sigcontext_format; 64 unw_word_t sigcontext_addr; 65 }; 66 67#define DWARF_GET_LOC(l) ((l).val) 68 69#ifdef UNW_LOCAL_ONLY 70# define DWARF_NULL_LOC DWARF_LOC (0, 0) 71# define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0) 72# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) }) 73# define DWARF_IS_REG_LOC(l) 0 74# define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \ 75 tdep_uc_addr((c)->as_arg, (r)), 0)) 76# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) 77# define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \ 78 tdep_uc_addr((c)->as_arg, (r)), 0)) 79 80static inline int 81dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val) 82{ 83 if (!DWARF_GET_LOC (loc)) 84 return -1; 85 *val = *(unw_fpreg_t *) DWARF_GET_LOC (loc); 86 return 0; 87} 88 89static inline int 90dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val) 91{ 92 if (!DWARF_GET_LOC (loc)) 93 return -1; 94 *(unw_fpreg_t *) DWARF_GET_LOC (loc) = val; 95 return 0; 96} 97 98static inline int 99dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val) 100{ 101 if (!DWARF_GET_LOC (loc)) 102 return -1; 103 *val = *(unw_word_t *) DWARF_GET_LOC (loc); 104 return 0; 105} 106 107static inline int 108dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) 109{ 110 if (!DWARF_GET_LOC (loc)) 111 return -1; 112 *(unw_word_t *) DWARF_GET_LOC (loc) = val; 113 return 0; 114} 115 116#else /* !UNW_LOCAL_ONLY */ 117# define DWARF_LOC_TYPE_FP (1 << 0) 118# define DWARF_LOC_TYPE_REG (1 << 1) 119# define DWARF_NULL_LOC DWARF_LOC (0, 0) 120# define DWARF_IS_NULL_LOC(l) \ 121 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; }) 122# define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) }) 123# define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0) 124# define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0) 125# define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG) 126# define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) 127# define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \ 128 | DWARF_LOC_TYPE_FP)) 129 130static inline int 131dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val) 132{ 133 char *valp = (char *) &val; 134 unw_word_t addr; 135 int ret; 136 137 if (DWARF_IS_NULL_LOC (loc)) 138 return -UNW_EBADREG; 139 140 if (DWARF_IS_REG_LOC (loc)) 141 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 142 val, 0, c->as_arg); 143 144 addr = DWARF_GET_LOC (loc); 145 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp, 146 0, c->as_arg)) < 0) 147 return ret; 148 149 return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 0, 150 c->as_arg); 151} 152 153static inline int 154dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val) 155{ 156 char *valp = (char *) &val; 157 unw_word_t addr; 158 int ret; 159 160 if (DWARF_IS_NULL_LOC (loc)) 161 return -UNW_EBADREG; 162 163 if (DWARF_IS_REG_LOC (loc)) 164 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 165 &val, 1, c->as_arg); 166 167 addr = DWARF_GET_LOC (loc); 168 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp, 169 1, c->as_arg)) < 0) 170 return ret; 171 172 return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 173 1, c->as_arg); 174} 175 176static inline int 177dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val) 178{ 179 if (DWARF_IS_NULL_LOC (loc)) 180 return -UNW_EBADREG; 181 182 /* If a code-generator were to save a value of type unw_word_t in a 183 floating-point register, we would have to support this case. I 184 suppose it could happen with MMX registers, but does it really 185 happen? */ 186 assert (!DWARF_IS_FP_LOC (loc)); 187 188 if (DWARF_IS_REG_LOC (loc)) 189 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val, 190 0, c->as_arg); 191 else 192 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val, 193 0, c->as_arg); 194} 195 196static inline int 197dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) 198{ 199 if (DWARF_IS_NULL_LOC (loc)) 200 return -UNW_EBADREG; 201 202 /* If a code-generator were to save a value of type unw_word_t in a 203 floating-point register, we would have to support this case. I 204 suppose it could happen with MMX registers, but does it really 205 happen? */ 206 assert (!DWARF_IS_FP_LOC (loc)); 207 208 if (DWARF_IS_REG_LOC (loc)) 209 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val, 210 1, c->as_arg); 211 else 212 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val, 213 1, c->as_arg); 214} 215 216#endif /* !UNW_LOCAL_ONLY */ 217 218#define tdep_needs_initialization UNW_OBJ(needs_initialization) 219#define tdep_init UNW_OBJ(init) 220/* Platforms that support UNW_INFO_FORMAT_TABLE need to define 221 tdep_search_unwind_table. */ 222#define tdep_search_unwind_table dwarf_search_unwind_table 223#define tdep_uc_addr UNW_ARCH_OBJ(uc_addr) 224#define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image) 225#define tdep_access_reg UNW_OBJ(access_reg) 226#define tdep_access_fpreg UNW_OBJ(access_fpreg) 227 228#ifdef UNW_LOCAL_ONLY 229# define tdep_find_proc_info(c,ip,n) \ 230 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \ 231 (c)->as_arg) 232# define tdep_put_unwind_info(as,pi,arg) \ 233 dwarf_put_unwind_info((as), (pi), (arg)) 234#else 235# define tdep_find_proc_info(c,ip,n) \ 236 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \ 237 (c)->as_arg) 238# define tdep_put_unwind_info(as,pi,arg) \ 239 (*(as)->acc.put_unwind_info)((as), (pi), (arg)) 240#endif 241 242#define tdep_get_as(c) ((c)->dwarf.as) 243#define tdep_get_as_arg(c) ((c)->dwarf.as_arg) 244#define tdep_get_ip(c) ((c)->dwarf.ip) 245#define tdep_big_endian(as) 0 246 247extern int tdep_needs_initialization; 248 249extern void tdep_init (void); 250extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, 251 unw_dyn_info_t *di, unw_proc_info_t *pi, 252 int need_unwind_info, void *arg); 253extern void *tdep_uc_addr (ucontext_t *uc, int reg); 254extern int tdep_get_elf_image (struct elf_image *ei, pid_t pid, unw_word_t ip, 255 unsigned long *segbase, unsigned long *mapoff); 256extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg, 257 unw_word_t *valp, int write); 258extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, 259 unw_fpreg_t *valp, int write); 260 261#endif /* X86_LIBUNWIND_I_H */ 262