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