memcg: replace ss->id_lock with a rwlock
[pandora-kernel.git] / arch / um / os-Linux / sys-i386 / registers.c
1 /*
2  * Copyright (C) 2004 PathScale, Inc
3  * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4  * Licensed under the GPL
5  */
6
7 #include <errno.h>
8 #include <sys/ptrace.h>
9 #include <sys/user.h>
10 #include "kern_constants.h"
11 #include "longjmp.h"
12 #include "user.h"
13 #include "sysdep/ptrace_user.h"
14
15 int save_fp_registers(int pid, unsigned long *fp_regs)
16 {
17         if (ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0)
18                 return -errno;
19         return 0;
20 }
21
22 int restore_fp_registers(int pid, unsigned long *fp_regs)
23 {
24         if (ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0)
25                 return -errno;
26         return 0;
27 }
28
29 int save_fpx_registers(int pid, unsigned long *fp_regs)
30 {
31         if (ptrace(PTRACE_GETFPXREGS, pid, 0, fp_regs) < 0)
32                 return -errno;
33         return 0;
34 }
35
36 int restore_fpx_registers(int pid, unsigned long *fp_regs)
37 {
38         if (ptrace(PTRACE_SETFPXREGS, pid, 0, fp_regs) < 0)
39                 return -errno;
40         return 0;
41 }
42
43 unsigned long get_thread_reg(int reg, jmp_buf *buf)
44 {
45         switch (reg) {
46         case EIP:
47                 return buf[0]->__eip;
48         case UESP:
49                 return buf[0]->__esp;
50         case EBP:
51                 return buf[0]->__ebp;
52         default:
53                 printk(UM_KERN_ERR "get_thread_regs - unknown register %d\n",
54                        reg);
55                 return 0;
56         }
57 }
58
59 int have_fpx_regs = 1;
60
61 int get_fp_registers(int pid, unsigned long *regs)
62 {
63         if (have_fpx_regs)
64                 return save_fpx_registers(pid, regs);
65         else
66                 return save_fp_registers(pid, regs);
67 }
68
69 int put_fp_registers(int pid, unsigned long *regs)
70 {
71         if (have_fpx_regs)
72                 return restore_fpx_registers(pid, regs);
73         else
74                 return restore_fp_registers(pid, regs);
75 }
76
77 void arch_init_registers(int pid)
78 {
79         struct user_fpxregs_struct fpx_regs;
80         int err;
81
82         err = ptrace(PTRACE_GETFPXREGS, pid, 0, &fpx_regs);
83         if (!err)
84                 return;
85
86         if (errno != EIO)
87                 panic("check_ptrace : PTRACE_GETFPXREGS failed, errno = %d",
88                       errno);
89
90         have_fpx_regs = 0;
91 }