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