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