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