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>
|
|
|
|
#include "sysdep/ptrace.h"
|
2007-10-16 02:27:00 -06:00
|
|
|
#include "user.h"
|
2007-10-16 02:26:47 -06:00
|
|
|
|
|
|
|
/* This is set once at boot time and not changed thereafter */
|
|
|
|
|
|
|
|
static unsigned long exec_regs[MAX_REG_NR];
|
|
|
|
|
2007-10-16 02:26:58 -06:00
|
|
|
void init_thread_registers(struct uml_pt_regs *to)
|
2007-10-16 02:26:47 -06:00
|
|
|
{
|
2007-10-16 02:27:07 -06:00
|
|
|
memcpy(to->gp, exec_regs, sizeof(to->gp));
|
2007-10-16 02:26:47 -06:00
|
|
|
}
|
|
|
|
|
2007-10-16 02:26:58 -06:00
|
|
|
void 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)
|
2007-10-16 02:26:47 -06:00
|
|
|
panic("save_registers - saving registers failed, errno = %d\n",
|
|
|
|
errno);
|
|
|
|
}
|
|
|
|
|
2007-10-16 02:26:58 -06:00
|
|
|
void 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)
|
2007-10-16 02:26:47 -06:00
|
|
|
panic("restore_registers - saving registers failed, "
|
|
|
|
"errno = %d\n", errno);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_registers(int pid)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = ptrace(PTRACE_GETREGS, pid, 0, exec_regs);
|
2007-10-16 02:27:00 -06:00
|
|
|
if (err)
|
2007-10-16 02:26:47 -06:00
|
|
|
panic("check_ptrace : PTRACE_GETREGS failed, errno = %d",
|
|
|
|
errno);
|
2007-10-16 02:27:15 -06:00
|
|
|
|
|
|
|
arch_init_registers(pid);
|
2007-10-16 02:26:47 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void get_safe_registers(unsigned long *regs)
|
|
|
|
{
|
|
|
|
memcpy(regs, exec_regs, sizeof(exec_regs));
|
|
|
|
}
|