blob: 830fe6a1518ae71dfa4deef46727b6fd367fbb18 [file] [log] [blame]
Jeff Dike42daba32007-10-16 01:26:47 -07001/*
2 * Copyright (C) 2004 PathScale, Inc
Jeff Dikeba180fd2007-10-16 01:27:00 -07003 * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Jeff Dike42daba32007-10-16 01:26:47 -07004 * Licensed under the GPL
5 */
6
7#include <errno.h>
8#include <string.h>
9#include <sys/ptrace.h>
Jeff Dike42daba32007-10-16 01:26:47 -070010#include "sysdep/ptrace.h"
11
Jeff Dike3e6f2ac2008-02-04 22:30:58 -080012int save_registers(int pid, struct uml_pt_regs *regs)
Jeff Dike42daba32007-10-16 01:26:47 -070013{
14 int err;
15
Jeff Dike18baddd2007-10-16 01:27:07 -070016 err = ptrace(PTRACE_GETREGS, pid, 0, regs->gp);
Jeff Dikeba180fd2007-10-16 01:27:00 -070017 if (err < 0)
Jeff Dike3e6f2ac2008-02-04 22:30:58 -080018 return -errno;
19 return 0;
Jeff Dike42daba32007-10-16 01:26:47 -070020}
21
Jeff Dike3e6f2ac2008-02-04 22:30:58 -080022int restore_registers(int pid, struct uml_pt_regs *regs)
Jeff Dike42daba32007-10-16 01:26:47 -070023{
24 int err;
25
Jeff Dike18baddd2007-10-16 01:27:07 -070026 err = ptrace(PTRACE_SETREGS, pid, 0, regs->gp);
Jeff Dikeba180fd2007-10-16 01:27:00 -070027 if (err < 0)
Jeff Dike3e6f2ac2008-02-04 22:30:58 -080028 return -errno;
29 return 0;
Jeff Dike42daba32007-10-16 01:26:47 -070030}
31
Jeff Diked25f2e12008-02-04 22:30:57 -080032/* This is set once at boot time and not changed thereafter */
33
34static unsigned long exec_regs[MAX_REG_NR];
35
Jeff Dike3e6f2ac2008-02-04 22:30:58 -080036int init_registers(int pid)
Jeff Dike42daba32007-10-16 01:26:47 -070037{
38 int err;
39
40 err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs);
Jeff Dike3e6f2ac2008-02-04 22:30:58 -080041 if (err < 0)
42 return -errno;
Jeff Dikea5f6096c2007-10-16 01:27:15 -070043
44 arch_init_registers(pid);
Jeff Dike3e6f2ac2008-02-04 22:30:58 -080045 return 0;
Jeff Dike42daba32007-10-16 01:26:47 -070046}
47
48void get_safe_registers(unsigned long *regs)
49{
50 memcpy(regs, exec_regs, sizeof(exec_regs));
51}