regs.c revision 366c2f46d844f040458df9b7e35fc3b8527ed2d3
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 60 19#define off_lr 56 20#define off_sp 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 proc->thumb_mode = addr & 1; 44 if (proc->thumb_mode) 45 addr &= ~1; 46 return (void *)addr; 47} 48 49void 50set_return_addr(Process *proc, void *addr) { 51 long iaddr = (int)addr | proc->thumb_mode; 52 ptrace(PTRACE_POKEUSER, proc->pid, off_lr, (void *)iaddr); 53} 54