registers.c 975 字节
Newer Older
L
Linus Torvalds 已提交
1
/*
J
Jeff Dike 已提交
2
 * Copyright (C) 2006 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
L
Linus Torvalds 已提交
3 4 5 6
 * Licensed under the GPL
 */

#include <errno.h>
J
Jeff Dike 已提交
7
#include <sys/ptrace.h>
J
Jeff Dike 已提交
8 9
#define __FRAME_OFFSETS
#include <asm/ptrace.h>
10
#include "longjmp.h"
L
Linus Torvalds 已提交
11

J
Jeff Dike 已提交
12 13
int save_fp_registers(int pid, unsigned long *fp_regs)
{
J
Jeff Dike 已提交
14
	if (ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0)
J
Jeff Dike 已提交
15 16 17 18 19 20
		return -errno;
	return 0;
}

int restore_fp_registers(int pid, unsigned long *fp_regs)
{
J
Jeff Dike 已提交
21
	if (ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0)
J
Jeff Dike 已提交
22 23 24 25
		return -errno;
	return 0;
}

J
Jeff Dike 已提交
26
unsigned long get_thread_reg(int reg, jmp_buf *buf)
27
{
J
Jeff Dike 已提交
28 29 30 31 32 33 34
	switch (reg) {
	case RIP:
		return buf[0]->__rip;
	case RSP:
		return buf[0]->__rsp;
	case RBP:
		return buf[0]->__rbp;
J
Jeff Dike 已提交
35
	default:
J
Jeff Dike 已提交
36 37
		printk(UM_KERN_ERR "get_thread_regs - unknown register %d\n",
		       reg);
J
Jeff Dike 已提交
38 39
		return 0;
	}
40
}
J
Jeff Dike 已提交
41 42 43 44 45 46 47 48 49 50

int get_fp_registers(int pid, unsigned long *regs)
{
	return save_fp_registers(pid, regs);
}

int put_fp_registers(int pid, unsigned long *regs)
{
	return restore_fp_registers(pid, regs);
}