2007-10-16 16:26:47 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 PathScale, Inc
|
2007-10-16 16:27:00 +08:00
|
|
|
* Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
|
2007-10-16 16:26:47 +08:00
|
|
|
* Licensed under the GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ptrace.h>
|
2012-10-08 10:27:32 +08:00
|
|
|
#include <sysdep/ptrace.h>
|
|
|
|
#include <sysdep/ptrace_user.h>
|
|
|
|
#include <registers.h>
|
2007-10-16 16:26:47 +08:00
|
|
|
|
2008-02-05 14:30:58 +08:00
|
|
|
int save_registers(int pid, struct uml_pt_regs *regs)
|
2007-10-16 16:26:47 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2007-10-16 16:27:07 +08:00
|
|
|
err = ptrace(PTRACE_GETREGS, pid, 0, regs->gp);
|
2007-10-16 16:27:00 +08:00
|
|
|
if (err < 0)
|
2008-02-05 14:30:58 +08:00
|
|
|
return -errno;
|
|
|
|
return 0;
|
2007-10-16 16:26:47 +08:00
|
|
|
}
|
|
|
|
|
2008-02-05 14:30:58 +08:00
|
|
|
int restore_registers(int pid, struct uml_pt_regs *regs)
|
2007-10-16 16:26:47 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2007-10-16 16:27:07 +08:00
|
|
|
err = ptrace(PTRACE_SETREGS, pid, 0, regs->gp);
|
2007-10-16 16:27:00 +08:00
|
|
|
if (err < 0)
|
2008-02-05 14:30:58 +08:00
|
|
|
return -errno;
|
|
|
|
return 0;
|
2007-10-16 16:26:47 +08:00
|
|
|
}
|
|
|
|
|
2008-02-05 14:30:57 +08:00
|
|
|
/* This is set once at boot time and not changed thereafter */
|
|
|
|
|
|
|
|
static unsigned long exec_regs[MAX_REG_NR];
|
2011-09-15 07:21:23 +08:00
|
|
|
static unsigned long exec_fp_regs[FP_SIZE];
|
2008-02-05 14:30:57 +08:00
|
|
|
|
2008-02-05 14:30:58 +08:00
|
|
|
int init_registers(int pid)
|
2007-10-16 16:26:47 +08:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs);
|
2008-02-05 14:30:58 +08:00
|
|
|
if (err < 0)
|
|
|
|
return -errno;
|
2007-10-16 16:27:15 +08:00
|
|
|
|
|
|
|
arch_init_registers(pid);
|
2011-09-15 07:21:23 +08:00
|
|
|
get_fp_registers(pid, exec_fp_regs);
|
2008-02-05 14:30:58 +08:00
|
|
|
return 0;
|
2007-10-16 16:26:47 +08:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:21:23 +08:00
|
|
|
void get_safe_registers(unsigned long *regs, unsigned long *fp_regs)
|
2007-10-16 16:26:47 +08:00
|
|
|
{
|
|
|
|
memcpy(regs, exec_regs, sizeof(exec_regs));
|
2011-09-15 07:21:23 +08:00
|
|
|
|
|
|
|
if (fp_regs)
|
|
|
|
memcpy(fp_regs, exec_fp_regs, sizeof(exec_fp_regs));
|
2007-10-16 16:26:47 +08:00
|
|
|
}
|