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" |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 11 | #include "user.h" |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 12 | |
| 13 | /* This is set once at boot time and not changed thereafter */ |
| 14 | |
| 15 | static unsigned long exec_regs[MAX_REG_NR]; |
| 16 | |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 17 | void init_thread_registers(struct uml_pt_regs *to) |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 18 | { |
Jeff Dike | 18baddd | 2007-10-16 01:27:07 -0700 | [diff] [blame] | 19 | memcpy(to->gp, exec_regs, sizeof(to->gp)); |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 20 | } |
| 21 | |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 22 | void save_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_GETREGS, pid, 0, regs->gp); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 27 | if (err < 0) |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 28 | panic("save_registers - saving registers failed, errno = %d\n", |
| 29 | errno); |
| 30 | } |
| 31 | |
Jeff Dike | 77bf440 | 2007-10-16 01:26:58 -0700 | [diff] [blame] | 32 | void restore_registers(int pid, struct uml_pt_regs *regs) |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 33 | { |
| 34 | int err; |
| 35 | |
Jeff Dike | 18baddd | 2007-10-16 01:27:07 -0700 | [diff] [blame] | 36 | err = ptrace(PTRACE_SETREGS, pid, 0, regs->gp); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 37 | if (err < 0) |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 38 | panic("restore_registers - saving registers failed, " |
| 39 | "errno = %d\n", errno); |
| 40 | } |
| 41 | |
| 42 | void init_registers(int pid) |
| 43 | { |
| 44 | int err; |
| 45 | |
| 46 | err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs); |
Jeff Dike | ba180fd | 2007-10-16 01:27:00 -0700 | [diff] [blame] | 47 | if (err) |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 48 | panic("check_ptrace : PTRACE_GETREGS failed, errno = %d", |
| 49 | errno); |
Jeff Dike | a5f6096 | 2007-10-16 01:27:15 -0700 | [diff] [blame] | 50 | |
| 51 | arch_init_registers(pid); |
Jeff Dike | 42daba3 | 2007-10-16 01:26:47 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | void get_safe_registers(unsigned long *regs) |
| 55 | { |
| 56 | memcpy(regs, exec_regs, sizeof(exec_regs)); |
| 57 | } |