_UPT_access_mem.c revision 3d6f7479b04b153f43bc9918a1bad25e3e8d2cd7
1/* libunwind - a platform-independent unwind library 2 Copyright (C) 2003-2004 Hewlett-Packard Co 3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 4 Copyright (C) 2010 Konstantin Belousov <kib@freebsd.org> 5 6This file is part of libunwind. 7 8Permission is hereby granted, free of charge, to any person obtaining 9a copy of this software and associated documentation files (the 10"Software"), to deal in the Software without restriction, including 11without limitation the rights to use, copy, modify, merge, publish, 12distribute, sublicense, and/or sell copies of the Software, and to 13permit persons to whom the Software is furnished to do so, subject to 14the following conditions: 15 16The above copyright notice and this permission notice shall be 17included in all copies or substantial portions of the Software. 18 19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 26 27#include "_UPT_internal.h" 28 29#if HAVE_DECL_PTRACE_POKEDATA || HAVE_TTRACE 30int 31_UPT_access_mem (unw_addr_space_t as, unw_word_t addr, unw_word_t *val, 32 int write, void *arg) 33{ 34 struct UPT_info *ui = arg; 35 if (!ui) 36 return -UNW_EINVAL; 37 38 pid_t pid = ui->pid; 39 40 errno = 0; 41 if (write) 42 { 43 Debug (16, "mem[%lx] <- %lx\n", (long) addr, (long) *val); 44#ifdef HAVE_TTRACE 45# warning No support for ttrace() yet. 46#else 47 ptrace (PTRACE_POKEDATA, pid, addr, *val); 48 if (errno) 49 return -UNW_EINVAL; 50#endif 51 } 52 else 53 { 54#ifdef HAVE_TTRACE 55# warning No support for ttrace() yet. 56#else 57 *val = ptrace (PTRACE_PEEKDATA, pid, addr, 0); 58 if (errno) 59 return -UNW_EINVAL; 60#endif 61 Debug (16, "mem[%lx] -> %lx\n", (long) addr, (long) *val); 62 } 63 return 0; 64} 65#elif HAVE_DECL_PT_IO 66int 67_UPT_access_mem (unw_addr_space_t as, unw_word_t addr, unw_word_t *val, 68 int write, void *arg) 69{ 70 struct UPT_info *ui = arg; 71 if (!ui) 72 return -UNW_EINVAL; 73 pid_t pid = ui->pid; 74 struct ptrace_io_desc iod; 75 76 iod.piod_offs = (void *)addr; 77 iod.piod_addr = val; 78 iod.piod_len = sizeof(*val); 79 iod.piod_op = write ? PIOD_WRITE_D : PIOD_READ_D; 80 if (write) 81 Debug (16, "mem[%lx] <- %lx\n", (long) addr, (long) *val); 82 if (ptrace(PT_IO, pid, (caddr_t)&iod, 0) == -1) 83 return -UNW_EINVAL; 84 if (!write) 85 Debug (16, "mem[%lx] -> %lx\n", (long) addr, (long) *val); 86 return 0; 87} 88#else 89#error Fix me 90#endif 91