1 /* 2 * This file is part of ltrace. 3 * Copyright (C) 2010 Edgar E. Iglesias 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License as 7 * published by the Free Software Foundation; either version 2 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, but 11 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18 * 02110-1301 USA 19 */ 20 21 #if HAVE_CONFIG_H 22 #include "config.h" 23 #endif 24 25 #include <sys/types.h> 26 #include <sys/ptrace.h> 27 #include <asm/ptrace.h> 28 29 #include "proc.h" 30 #include "common.h" 31 32 #if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) 33 # define PTRACE_PEEKUSER PTRACE_PEEKUSR 34 #endif 35 36 #if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR)) 37 # define PTRACE_POKEUSER PTRACE_POKEUSR 38 #endif 39 40 void *get_instruction_pointer(struct process *proc) 41 { 42 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_PPC, 0); 43 } 44 45 void set_instruction_pointer(struct process *proc, void *addr) 46 { 47 ptrace(PTRACE_POKEUSER, proc->pid, 4 * PT_PPC, addr); 48 } 49 50 void *get_stack_pointer(struct process *proc) 51 { 52 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_USP, 0); 53 } 54 55 void *get_return_addr(struct process *proc, void *stack_pointer) 56 { 57 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, 4 * PT_SRP, 0); 58 } 59