Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
registers.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2004 PathScale, Inc
3  * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4  * Licensed under the GPL
5  */
6 
7 #include <errno.h>
8 #include <string.h>
9 #include <sys/ptrace.h>
10 #include <sysdep/ptrace.h>
11 #include <sysdep/ptrace_user.h>
12 #include <registers.h>
13 
15 {
16  int err;
17 
18  err = ptrace(PTRACE_GETREGS, pid, 0, regs->gp);
19  if (err < 0)
20  return -errno;
21  return 0;
22 }
23 
25 {
26  int err;
27 
28  err = ptrace(PTRACE_SETREGS, pid, 0, regs->gp);
29  if (err < 0)
30  return -errno;
31  return 0;
32 }
33 
34 /* This is set once at boot time and not changed thereafter */
35 
36 static unsigned long exec_regs[MAX_REG_NR];
37 static unsigned long exec_fp_regs[FP_SIZE];
38 
40 {
41  int err;
42 
43  err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs);
44  if (err < 0)
45  return -errno;
46 
48  get_fp_registers(pid, exec_fp_regs);
49  return 0;
50 }
51 
52 void get_safe_registers(unsigned long *regs, unsigned long *fp_regs)
53 {
54  memcpy(regs, exec_regs, sizeof(exec_regs));
55 
56  if (fp_regs)
57  memcpy(fp_regs, exec_fp_regs, sizeof(exec_fp_regs));
58 }