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