1 /* libunwind - a platform-independent unwind library 2 Copyright (C) 2003-2005 Hewlett-Packard Co 3 Contributed by David Mosberger-Tang <davidm (at) hpl.hp.com> 4 5 This file is part of libunwind. 6 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: 14 15 The above copyright notice and this permission notice shall be 16 included in all copies or substantial portions of the Software. 17 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. */ 25 26 #ifndef HPPA_LIBUNWIND_I_H 27 #define HPPA_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 /* ANDROID support update. */ 37 #include "map_info.h" 38 /* End of ANDROID update. */ 39 #include "mempool.h" 40 #include "dwarf.h" 41 42 typedef struct 43 { 44 /* no hppa-specific fast trace */ 45 } 46 unw_tdep_frame_t; 47 48 struct unw_addr_space 49 { 50 struct unw_accessors acc; 51 unw_caching_policy_t caching_policy; 52 #ifdef HAVE_ATOMIC_OPS_H 53 AO_t cache_generation; 54 #else 55 uint32_t cache_generation; 56 #endif 57 unw_word_t dyn_generation; /* see dyn-common.h */ 58 unw_word_t dyn_info_list_addr; /* (cached) dyn_info_list_addr */ 59 struct dwarf_rs_cache global_cache; 60 struct unw_debug_frame_list *debug_frames; 61 /* ANDROID support update. */ 62 struct map_info *map_list; 63 /* End of ANDROID update. */ 64 }; 65 66 struct cursor 67 { 68 struct dwarf_cursor dwarf; /* must be first */ 69 70 /* Format of sigcontext structure and address at which it is 71 stored: */ 72 enum 73 { 74 HPPA_SCF_NONE, /* no signal frame encountered */ 75 HPPA_SCF_LINUX_RT_SIGFRAME /* POSIX ucontext_t */ 76 } 77 sigcontext_format; 78 unw_word_t sigcontext_addr; 79 }; 80 81 #define DWARF_GET_LOC(l) ((l).val) 82 83 #ifdef UNW_LOCAL_ONLY 84 # define DWARF_NULL_LOC DWARF_LOC (0, 0) 85 # define DWARF_IS_NULL_LOC(l) (DWARF_GET_LOC (l) == 0) 86 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r) }) 87 # define DWARF_IS_REG_LOC(l) 0 88 # define DWARF_REG_LOC(c,r) (DWARF_LOC((unw_word_t) \ 89 tdep_uc_addr((c)->as_arg, (r)), 0)) 90 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) 91 # define DWARF_FPREG_LOC(c,r) (DWARF_LOC((unw_word_t) \ 92 tdep_uc_addr((c)->as_arg, (r)), 0)) 93 94 static inline int 95 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val) 96 { 97 /* ANDROID support update. */ 98 unw_fpreg_t *addr = (unw_fpreg_t *) (uintptr_t) DWARF_GET_LOC (loc); 99 if (!addr || !map_local_is_readable ((unw_word_t) (uintptr_t) addr, sizeof(unw_fpreg_t))) 100 return -1; 101 102 *val = *addr; 103 return 0; 104 /* End of ANDROID update. */ 105 } 106 107 static inline int 108 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val) 109 { 110 /* ANDROID support update. */ 111 unw_fpreg_t *addr = (unw_fpreg_t *) (uintptr_t) DWARF_GET_LOC (loc); 112 if (!addr || !map_local_is_writable ((unw_word_t) (uintptr_t) addr, sizeof(unw_fpreg_t))) 113 return -1; 114 115 *addr = val; 116 return 0; 117 /* End of ANDROID update. */ 118 } 119 120 static inline int 121 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val) 122 { 123 /* ANDROID support update. */ 124 if (!DWARF_GET_LOC (loc)) 125 return -1; 126 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val, 127 0, c->as_arg); 128 /* End of ANDROID update. */ 129 } 130 131 static inline int 132 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) 133 { 134 /* ANDROID support update. */ 135 if (!DWARF_GET_LOC (loc)) 136 return -1; 137 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val, 138 1, c->as_arg); 139 /* End of ANDROID update. */ 140 } 141 142 #else /* !UNW_LOCAL_ONLY */ 143 # define DWARF_LOC_TYPE_FP (1 << 0) 144 # define DWARF_LOC_TYPE_REG (1 << 1) 145 # define DWARF_NULL_LOC DWARF_LOC (0, 0) 146 # define DWARF_IS_NULL_LOC(l) \ 147 ({ dwarf_loc_t _l = (l); _l.val == 0 && _l.type == 0; }) 148 # define DWARF_LOC(r, t) ((dwarf_loc_t) { .val = (r), .type = (t) }) 149 # define DWARF_IS_REG_LOC(l) (((l).type & DWARF_LOC_TYPE_REG) != 0) 150 # define DWARF_IS_FP_LOC(l) (((l).type & DWARF_LOC_TYPE_FP) != 0) 151 # define DWARF_REG_LOC(c,r) DWARF_LOC((r), DWARF_LOC_TYPE_REG) 152 # define DWARF_MEM_LOC(c,m) DWARF_LOC ((m), 0) 153 # define DWARF_FPREG_LOC(c,r) DWARF_LOC((r), (DWARF_LOC_TYPE_REG \ 154 | DWARF_LOC_TYPE_FP)) 155 156 static inline int 157 dwarf_getfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t *val) 158 { 159 char *valp = (char *) &val; 160 unw_word_t addr; 161 int ret; 162 163 if (DWARF_IS_NULL_LOC (loc)) 164 return -UNW_EBADREG; 165 166 if (DWARF_IS_REG_LOC (loc)) 167 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 168 val, 0, c->as_arg); 169 170 addr = DWARF_GET_LOC (loc); 171 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp, 172 0, c->as_arg)) < 0) 173 return ret; 174 175 return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 0, 176 c->as_arg); 177 } 178 179 static inline int 180 dwarf_putfp (struct dwarf_cursor *c, dwarf_loc_t loc, unw_fpreg_t val) 181 { 182 char *valp = (char *) &val; 183 unw_word_t addr; 184 int ret; 185 186 if (DWARF_IS_NULL_LOC (loc)) 187 return -UNW_EBADREG; 188 189 if (DWARF_IS_REG_LOC (loc)) 190 return (*c->as->acc.access_fpreg) (c->as, DWARF_GET_LOC (loc), 191 &val, 1, c->as_arg); 192 193 addr = DWARF_GET_LOC (loc); 194 if ((ret = (*c->as->acc.access_mem) (c->as, addr + 0, (unw_word_t *) valp, 195 1, c->as_arg)) < 0) 196 return ret; 197 198 return (*c->as->acc.access_mem) (c->as, addr + 4, (unw_word_t *) valp + 1, 199 1, c->as_arg); 200 } 201 202 static inline int 203 dwarf_get (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t *val) 204 { 205 if (DWARF_IS_NULL_LOC (loc)) 206 return -UNW_EBADREG; 207 208 /* If a code-generator were to save a value of type unw_word_t in a 209 floating-point register, we would have to support this case. I 210 suppose it could happen with MMX registers, but does it really 211 happen? */ 212 assert (!DWARF_IS_FP_LOC (loc)); 213 214 if (DWARF_IS_REG_LOC (loc)) 215 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), val, 216 0, c->as_arg); 217 else 218 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), val, 219 0, c->as_arg); 220 } 221 222 static inline int 223 dwarf_put (struct dwarf_cursor *c, dwarf_loc_t loc, unw_word_t val) 224 { 225 if (DWARF_IS_NULL_LOC (loc)) 226 return -UNW_EBADREG; 227 228 /* If a code-generator were to save a value of type unw_word_t in a 229 floating-point register, we would have to support this case. I 230 suppose it could happen with MMX registers, but does it really 231 happen? */ 232 assert (!DWARF_IS_FP_LOC (loc)); 233 234 if (DWARF_IS_REG_LOC (loc)) 235 return (*c->as->acc.access_reg) (c->as, DWARF_GET_LOC (loc), &val, 236 1, c->as_arg); 237 else 238 return (*c->as->acc.access_mem) (c->as, DWARF_GET_LOC (loc), &val, 239 1, c->as_arg); 240 } 241 242 #endif /* !UNW_LOCAL_ONLY */ 243 244 #define tdep_getcontext_trace unw_getcontext 245 #define tdep_init_done UNW_OBJ(init_done) 246 #define tdep_init UNW_OBJ(init) 247 /* Platforms that support UNW_INFO_FORMAT_TABLE need to define 248 tdep_search_unwind_table. */ 249 #define tdep_search_unwind_table dwarf_search_unwind_table 250 #define tdep_find_unwind_table dwarf_find_unwind_table 251 #define tdep_uc_addr UNW_ARCH_OBJ(uc_addr) 252 #define tdep_get_elf_image UNW_ARCH_OBJ(get_elf_image) 253 #define tdep_access_reg UNW_OBJ(access_reg) 254 #define tdep_access_fpreg UNW_OBJ(access_fpreg) 255 #define tdep_fetch_frame(c,ip,n) do {} while(0) 256 #define tdep_cache_frame(c,rs) do {} while(0) 257 #define tdep_reuse_frame(c,rs) do {} while(0) 258 #define tdep_stash_frame(c,rs) do {} while(0) 259 #define tdep_trace(cur,addr,n) (-UNW_ENOINFO) 260 261 #ifdef UNW_LOCAL_ONLY 262 # define tdep_find_proc_info(c,ip,n) \ 263 dwarf_find_proc_info((c)->as, (ip), &(c)->pi, (n), \ 264 (c)->as_arg) 265 # define tdep_put_unwind_info(as,pi,arg) \ 266 dwarf_put_unwind_info((as), (pi), (arg)) 267 #else 268 # define tdep_find_proc_info(c,ip,n) \ 269 (*(c)->as->acc.find_proc_info)((c)->as, (ip), &(c)->pi, (n), \ 270 (c)->as_arg) 271 # define tdep_put_unwind_info(as,pi,arg) \ 272 (*(as)->acc.put_unwind_info)((as), (pi), (arg)) 273 #endif 274 275 #define tdep_get_as(c) ((c)->dwarf.as) 276 #define tdep_get_as_arg(c) ((c)->dwarf.as_arg) 277 #define tdep_get_ip(c) ((c)->dwarf.ip) 278 #define tdep_big_endian(as) 1 279 280 extern int tdep_init_done; 281 282 extern void tdep_init (void); 283 extern int tdep_search_unwind_table (unw_addr_space_t as, unw_word_t ip, 284 unw_dyn_info_t *di, unw_proc_info_t *pi, 285 int need_unwind_info, void *arg); 286 extern void *tdep_uc_addr (ucontext_t *uc, int reg); 287 /* ANDROID support update. */ 288 extern int tdep_get_elf_image (unw_addr_space_t as, struct elf_image *ei, 289 pid_t pid, unw_word_t ip, 290 unsigned long *segbase, unsigned long *mapoff, 291 char **path, void *as_arg); 292 /* End of ANDROID update. */ 293 extern int tdep_access_reg (struct cursor *c, unw_regnum_t reg, 294 unw_word_t *valp, int write); 295 extern int tdep_access_fpreg (struct cursor *c, unw_regnum_t reg, 296 unw_fpreg_t *valp, int write); 297 298 #endif /* HPPA_LIBUNWIND_I_H */ 299