Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004 PathScale, Inc |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 3 | * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 4 | * Licensed under the GPL |
| 5 | */ |
| 6 | |
| 7 | #include <errno.h> |
| 8 | #include <string.h> |
| 9 | #include <sys/ptrace.h> |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 10 | #include "sysdep/ptrace.h" |
| 11 | |
Jeff Dike | 3e6f2ac | 2008-02-04 22:30:58 -0800 | [diff] [blame] | 12 | int save_registers(int pid, struct uml_pt_regs *regs) |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 13 | { |
| 14 | int err; |
| 15 | |
Jeff Dike | 18baddd | 2007-10-16 01:27:07 -0700 | [diff] [blame] | 16 | err = ptrace(PTRACE_GETREGS, pid, 0, regs->gp); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 17 | if (err < 0) |
Jeff Dike | 3e6f2ac | 2008-02-04 22:30:58 -0800 | [diff] [blame] | 18 | return -errno; |
| 19 | return 0; |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 20 | } |
| 21 | |
Jeff Dike | 3e6f2ac | 2008-02-04 22:30:58 -0800 | [diff] [blame] | 22 | int restore_registers(int pid, struct uml_pt_regs *regs) |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 23 | { |
| 24 | int err; |
| 25 | |
Jeff Dike | 18baddd | 2007-10-16 01:27:07 -0700 | [diff] [blame] | 26 | err = ptrace(PTRACE_SETREGS, pid, 0, regs->gp); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 27 | if (err < 0) |
Jeff Dike | 3e6f2ac | 2008-02-04 22:30:58 -0800 | [diff] [blame] | 28 | return -errno; |
| 29 | return 0; |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 30 | } |
| 31 | |
Jeff Dike | d25f2e1 | 2008-02-04 22:30:57 -0800 | [diff] [blame] | 32 | /* This is set once at boot time and not changed thereafter */ |
| 33 | |
| 34 | static unsigned long exec_regs[MAX_REG_NR]; |
| 35 | |
Jeff Dike | 3e6f2ac | 2008-02-04 22:30:58 -0800 | [diff] [blame] | 36 | int init_registers(int pid) |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 37 | { |
| 38 | int err; |
| 39 | |
| 40 | err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs); |
Jeff Dike | 3e6f2ac | 2008-02-04 22:30:58 -0800 | [diff] [blame] | 41 | if (err < 0) |
| 42 | return -errno; |
Jeff Dike | a5f6096c | 2007-10-16 01:27:15 -0700 | [diff] [blame] | 43 | |
| 44 | arch_init_registers(pid); |
Jeff Dike | 3e6f2ac | 2008-02-04 22:30:58 -0800 | [diff] [blame] | 45 | return 0; |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | void get_safe_registers(unsigned long *regs) |
| 49 | { |
| 50 | memcpy(regs, exec_regs, sizeof(exec_regs)); |
| 51 | } |