1b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino/* libunwind - a platform-independent unwind library 2b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino Copyright (C) 2006-2007 IBM 3b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino Contributed by 4b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino Corey Ashford <cjashfor@us.ibm.com> 5b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino Jose Flavio Aguilar Paulino <jflavio@br.ibm.com> <joseflavio@gmail.com> 6b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 7b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoThis file is part of libunwind. 8b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 9b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoPermission is hereby granted, free of charge, to any person obtaining 10b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinoa copy of this software and associated documentation files (the 11b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino"Software"), to deal in the Software without restriction, including 12b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinowithout limitation the rights to use, copy, modify, merge, publish, 13b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinodistribute, sublicense, and/or sell copies of the Software, and to 14b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinopermit persons to whom the Software is furnished to do so, subject to 15b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinothe following conditions: 16b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 17b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoThe above copyright notice and this permission notice shall be 18b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinoincluded in all copies or substantial portions of the Software. 19b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 20b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 27b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 28b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino#include <stdlib.h> 29b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino#include <string.h> 30b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 31b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino#include "ucontext_i.h" 32b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino#include "unwind_i.h" 33b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 34b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino#ifdef UNW_REMOTE_ONLY 35b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 36b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino/* unw_local_addr_space is a NULL pointer in this case. */ 37b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoPROTECTED unw_addr_space_t unw_local_addr_space; 38b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 39b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino#else /* !UNW_REMOTE_ONLY */ 40b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 41b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinostatic struct unw_addr_space local_addr_space; 42b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 43b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoPROTECTED unw_addr_space_t unw_local_addr_space = &local_addr_space; 44b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 45b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinostatic void * 46b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinouc_addr (ucontext_t *uc, int reg) 47b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino{ 48b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino void *addr; 49b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 50b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino if ((unsigned) (reg - UNW_PPC64_R0) < 32) 51b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino addr = &uc->uc_mcontext.gp_regs[reg - UNW_PPC64_R0]; 52b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 53b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino else if ((unsigned) (reg - UNW_PPC64_F0) < 32) 54b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino addr = &uc->uc_mcontext.fp_regs[reg - UNW_PPC64_F0]; 55b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 56b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino else if ((unsigned) (reg - UNW_PPC64_V0) < 32) 57b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino addr = (uc->uc_mcontext.v_regs == 0) ? NULL : &uc->uc_mcontext.v_regs->vrregs[reg - UNW_PPC64_V0][0]; 58b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 59b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino else 60b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino { 61b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino unsigned gregs_idx; 62b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 63b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino switch (reg) 64b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino { 65b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino case UNW_PPC64_NIP: 66b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino gregs_idx = NIP_IDX; 67b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino break; 68b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino case UNW_PPC64_CTR: 69b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino gregs_idx = CTR_IDX; 70b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino break; 71b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino case UNW_PPC64_LR: 72b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino gregs_idx = LINK_IDX; 73b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino break; 74b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino case UNW_PPC64_XER: 75b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino gregs_idx = XER_IDX; 76b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino break; 77b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino case UNW_PPC64_CR0: 78b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino gregs_idx = CCR_IDX; 79b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino break; 80b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino default: 81b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino return NULL; 82b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino } 83b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino addr = &uc->uc_mcontext.gp_regs[gregs_idx]; 84b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino } 85b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino return addr; 86b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino} 87b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 88b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino# ifdef UNW_LOCAL_ONLY 89b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 90b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoHIDDEN void * 91b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinotdep_uc_addr (ucontext_t *uc, int reg) 92b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino{ 93b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino return uc_addr (uc, reg); 94b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino} 95b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 96b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino# endif /* UNW_LOCAL_ONLY */ 97b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 98b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoHIDDEN unw_dyn_info_list_t _U_dyn_info_list; 99b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 100b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 101b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinostatic void 102b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinoput_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg) 103b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino{ 104b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino /* it's a no-op */ 105b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino} 106b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 107b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinostatic int 108b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinoget_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr, 109b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino void *arg) 110b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino{ 111b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list; 112b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino return 0; 113b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino} 114b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 115b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinostatic int 116b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinoaccess_mem (unw_addr_space_t as, unw_word_t addr, unw_word_t *val, int write, 117b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino void *arg) 118b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino{ 119b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino if (write) 120b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino { 1217d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris /* ANDROID support update. */ 122cdf9ee587b78148c5d48dae1b5ea72ec8df64c96Christopher Ferris#ifdef UNW_LOCAL_ONLY 12318cf8168ef34750ffae6451bded31ff06d2d2763Christopher Ferris if (map_local_is_writable (addr, sizeof(unw_word_t))) 1247d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris { 125cdf9ee587b78148c5d48dae1b5ea72ec8df64c96Christopher Ferris#endif 1267d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris Debug (12, "mem[%lx] <- %lx\n", addr, *val); 1277d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris *(unw_word_t *) addr = *val; 128cdf9ee587b78148c5d48dae1b5ea72ec8df64c96Christopher Ferris#ifdef UNW_LOCAL_ONLY 1297d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris } 1307d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris else 1317d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris { 1327d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris Debug (12, "Unwritable memory mem[%lx] <- %lx\n", addr, *val); 1337d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris return -1; 1347d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris } 135cdf9ee587b78148c5d48dae1b5ea72ec8df64c96Christopher Ferris#endif 1367d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris /* End of ANDROID update. */ 137b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino } 138b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino else 139b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino { 1407d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris /* ANDROID support update. */ 141cdf9ee587b78148c5d48dae1b5ea72ec8df64c96Christopher Ferris#ifdef UNW_LOCAL_ONLY 14218cf8168ef34750ffae6451bded31ff06d2d2763Christopher Ferris if (map_local_is_readable (addr, sizeof(unw_word_t))) 1437d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris { 144cdf9ee587b78148c5d48dae1b5ea72ec8df64c96Christopher Ferris#endif 1457d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris *val = *(unw_word_t *) addr; 1467d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris Debug (12, "mem[%lx] -> %lx\n", addr, *val); 147cdf9ee587b78148c5d48dae1b5ea72ec8df64c96Christopher Ferris#ifdef UNW_LOCAL_ONLY 1487d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris } 1497d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris else 1507d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris { 1517d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris Debug (12, "Unreadable memory mem[%lx] -> XXX\n", addr); 1527d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris return -1; 1537d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris } 154cdf9ee587b78148c5d48dae1b5ea72ec8df64c96Christopher Ferris#endif 1557d46a21e0a2cb561e4cad57b101a7137e01023dcChristopher Ferris /* End of ANDROID update. */ 156b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino } 157b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino return 0; 158b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino} 159b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 160b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinostatic int 161b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinoaccess_reg (unw_addr_space_t as, unw_regnum_t reg, unw_word_t *val, 162b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino int write, void *arg) 163b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino{ 164b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino unw_word_t *addr; 165b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino ucontext_t *uc = arg; 166b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 1670abc36eb1884a9c6ebd3f7a655d2140fd31ed2fcCody P Schafer if (UNW_PPC64_F0 <= reg && reg <= UNW_PPC64_F31) 168b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino goto badreg; 1690abc36eb1884a9c6ebd3f7a655d2140fd31ed2fcCody P Schafer if (UNW_PPC64_V0 <= reg && reg <= UNW_PPC64_V31) 170b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino goto badreg; 171b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 172b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino addr = uc_addr (uc, reg); 173b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino if (!addr) 174b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino goto badreg; 175b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 176b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino if (write) 177b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino { 178b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino *(unw_word_t *) addr = *val; 179b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino Debug (12, "%s <- %lx\n", unw_regname (reg), *val); 180b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino } 181b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino else 182b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino { 183b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino *val = *(unw_word_t *) addr; 184b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino Debug (12, "%s -> %lx\n", unw_regname (reg), *val); 185b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino } 186b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino return 0; 187b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 188b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinobadreg: 189b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino Debug (1, "bad register number %u\n", reg); 190b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino return -UNW_EBADREG; 191b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino} 192b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 193b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinostatic int 194b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinoaccess_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val, 195b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino int write, void *arg) 196b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino{ 197b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino ucontext_t *uc = arg; 198b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino unw_fpreg_t *addr; 199b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 200b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino if ((unsigned) (reg - UNW_PPC64_F0) < 0) 201b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino goto badreg; 202b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 203b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino if ((unsigned) (reg - UNW_PPC64_V0) >= 32) 204b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino goto badreg; 205b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 206b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 207b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino addr = uc_addr (uc, reg); 208b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino if (!addr) 209b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino goto badreg; 210b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 211b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino if (write) 212b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino { 213b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino Debug (12, "%s <- %016Lf\n", unw_regname (reg), *val); 214b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino *(unw_fpreg_t *) addr = *val; 215b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino } 216b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino else 217b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino { 218b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino *val = *(unw_fpreg_t *) addr; 219b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino Debug (12, "%s -> %016Lf\n", unw_regname (reg), *val); 220b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino } 221b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino return 0; 222b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 223b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinobadreg: 224b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino Debug (1, "bad register number %u\n", reg); 225b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino /* attempt to access a non-preserved register */ 226b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino return -UNW_EBADREG; 227b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino} 228b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 229b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinostatic int 230b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinoget_static_proc_name (unw_addr_space_t as, unw_word_t ip, 231b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino char *buf, size_t buf_len, unw_word_t *offp, 232b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino void *arg) 233b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino{ 234ae38b20031a02d3f6f56a8315c1f097ae5293c56Christopher Ferris return _Uelf64_get_proc_name (as, getpid (), ip, buf, buf_len, offp, arg); 235b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino} 236b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 237b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar PaulinoHIDDEN void 238b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulinoppc64_local_addr_space_init (void) 239b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino{ 240b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino memset (&local_addr_space, 0, sizeof (local_addr_space)); 241b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino local_addr_space.caching_policy = UNW_CACHE_GLOBAL; 242b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino local_addr_space.acc.find_proc_info = dwarf_find_proc_info; 243b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino local_addr_space.acc.put_unwind_info = put_unwind_info; 244b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino local_addr_space.acc.get_dyn_info_list_addr = get_dyn_info_list_addr; 245b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino local_addr_space.acc.access_mem = access_mem; 246b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino local_addr_space.acc.access_reg = access_reg; 247b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino local_addr_space.acc.access_fpreg = access_fpreg; 248b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino local_addr_space.acc.resume = ppc64_local_resume; 249b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino local_addr_space.acc.get_proc_name = get_static_proc_name; 250b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino unw_flush_cache (&local_addr_space, 0, 0); 251f4a8df5f4f338f1a12c25213227e98b34b42447fChristopher Ferris 252f4a8df5f4f338f1a12c25213227e98b34b42447fChristopher Ferris map_local_init (); 253b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino} 254b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino 255b33021e4b2f3a92141c01eb24b98bc51a97c498dJose Flavio Aguilar Paulino#endif /* !UNW_REMOTE_ONLY */ 256