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 12 int save_registers(int pid, struct uml_pt_regs *regs) 13 { 14 int err; 15 16 err = ptrace(PTRACE_GETREGS, pid, 0, regs->gp); 17 if (err < 0) 18 return -errno; 19 return 0; 20 } 21 22 int restore_registers(int pid, struct uml_pt_regs *regs) 23 { 24 int err; 25 26 err = ptrace(PTRACE_SETREGS, pid, 0, regs->gp); 27 if (err < 0) 28 return -errno; 29 return 0; 30 } 31 32 /* This is set once at boot time and not changed thereafter */ 33 34 static unsigned long exec_regs[MAX_REG_NR]; 35 36 int init_registers(int pid) 37 { 38 int err; 39 40 err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs); 41 if (err < 0) 42 return -errno; 43 44 arch_init_registers(pid); 45 return 0; 46 } 47 48 void get_safe_registers(unsigned long *regs) 49 { 50 memcpy(regs, exec_regs, sizeof(exec_regs)); 51 } 52