regs.c revision c897cb796dc4a7d256cbfbf0137ef7cdff9e8ece
1#include "config.h" 2 3#include <sys/types.h> 4#include <sys/ptrace.h> 5#include <asm/ptrace.h> 6 7#include "proc.h" 8#include "common.h" 9 10#if (!defined(PTRACE_PEEKUSER) && defined(PTRACE_PEEKUSR)) 11# define PTRACE_PEEKUSER PTRACE_PEEKUSR 12#endif 13 14#if (!defined(PTRACE_POKEUSER) && defined(PTRACE_POKEUSR)) 15# define PTRACE_POKEUSER PTRACE_POKEUSR 16#endif 17 18#define off_pc ((void *)60) 19#define off_lr ((void *)56) 20#define off_sp ((void *)52) 21 22void * 23get_instruction_pointer(Process *proc) { 24 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, off_pc, 0); 25} 26 27void 28set_instruction_pointer(Process *proc, void *addr) { 29 ptrace(PTRACE_POKEUSER, proc->pid, off_pc, addr); 30} 31 32void * 33get_stack_pointer(Process *proc) { 34 return (void *)ptrace(PTRACE_PEEKUSER, proc->pid, off_sp, 0); 35} 36 37/* really, this is given the *stack_pointer expecting 38 * a CISC architecture; in our case, we don't need that */ 39void * 40get_return_addr(Process *proc, void *stack_pointer) { 41 long addr = ptrace(PTRACE_PEEKUSER, proc->pid, off_lr, 0); 42 43 /* Remember & unset the thumb mode bit. XXX This is really a 44 * bit of a hack, as we assume that the following 45 * insert_breakpoint call will be related to this address. 46 * This interface should really be get_return_breakpoint, or 47 * maybe install_return_breakpoint. */ 48 proc->thumb_mode = addr & 1; 49 if (proc->thumb_mode) 50 addr &= ~1; 51 52 return (void *)addr; 53} 54 55void 56set_return_addr(Process *proc, void *addr) { 57 long iaddr = (int)addr | proc->thumb_mode; 58 ptrace(PTRACE_POKEUSER, proc->pid, off_lr, (void *)iaddr); 59} 60