]> err.no Git - linux-2.6/blob - arch/um/sys-i386/ptrace.c
uml: floating point signal delivery fixes
[linux-2.6] / arch / um / sys-i386 / ptrace.c
1 /*
2  * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3  * Licensed under the GPL
4  */
5
6 #include "linux/mm.h"
7 #include "linux/sched.h"
8 #include "asm/uaccess.h"
9
10 extern int arch_switch_tls(struct task_struct *from, struct task_struct *to);
11
12 void arch_switch_to(struct task_struct *from, struct task_struct *to)
13 {
14         int err = arch_switch_tls(from, to);
15         if (!err)
16                 return;
17
18         if (err != -EINVAL)
19                 printk(KERN_WARNING "arch_switch_tls failed, errno %d, "
20                        "not EINVAL\n", -err);
21         else
22                 printk(KERN_WARNING "arch_switch_tls failed, errno = EINVAL\n");
23 }
24
25 int is_syscall(unsigned long addr)
26 {
27         unsigned short instr;
28         int n;
29
30         n = copy_from_user(&instr, (void __user *) addr, sizeof(instr));
31         if (n) {
32                 /* access_process_vm() grants access to vsyscall and stub,
33                  * while copy_from_user doesn't. Maybe access_process_vm is
34                  * slow, but that doesn't matter, since it will be called only
35                  * in case of singlestepping, if copy_from_user failed.
36                  */
37                 n = access_process_vm(current, addr, &instr, sizeof(instr), 0);
38                 if (n != sizeof(instr)) {
39                         printk(KERN_ERR "is_syscall : failed to read "
40                                "instruction from 0x%lx\n", addr);
41                         return 1;
42                 }
43         }
44         /* int 0x80 or sysenter */
45         return (instr == 0x80cd) || (instr == 0x340f);
46 }
47
48 /* determines which flags the user has access to. */
49 /* 1 = access 0 = no access */
50 #define FLAG_MASK 0x00044dd5
51
52 int putreg(struct task_struct *child, int regno, unsigned long value)
53 {
54         regno >>= 2;
55         switch (regno) {
56         case FS:
57                 if (value && (value & 3) != 3)
58                         return -EIO;
59                 PT_REGS_FS(&child->thread.regs) = value;
60                 return 0;
61         case GS:
62                 if (value && (value & 3) != 3)
63                         return -EIO;
64                 PT_REGS_GS(&child->thread.regs) = value;
65                 return 0;
66         case DS:
67         case ES:
68                 if (value && (value & 3) != 3)
69                         return -EIO;
70                 value &= 0xffff;
71                 break;
72         case SS:
73         case CS:
74                 if ((value & 3) != 3)
75                         return -EIO;
76                 value &= 0xffff;
77                 break;
78         case EFL:
79                 value &= FLAG_MASK;
80                 value |= PT_REGS_EFLAGS(&child->thread.regs);
81                 break;
82         }
83         PT_REGS_SET(&child->thread.regs, regno, value);
84         return 0;
85 }
86
87 int poke_user(struct task_struct *child, long addr, long data)
88 {
89         if ((addr & 3) || addr < 0)
90                 return -EIO;
91
92         if (addr < MAX_REG_OFFSET)
93                 return putreg(child, addr, data);
94         else if ((addr >= offsetof(struct user, u_debugreg[0])) &&
95                  (addr <= offsetof(struct user, u_debugreg[7]))) {
96                 addr -= offsetof(struct user, u_debugreg[0]);
97                 addr = addr >> 2;
98                 if ((addr == 4) || (addr == 5))
99                         return -EIO;
100                 child->thread.arch.debugregs[addr] = data;
101                 return 0;
102         }
103         return -EIO;
104 }
105
106 unsigned long getreg(struct task_struct *child, int regno)
107 {
108         unsigned long retval = ~0UL;
109
110         regno >>= 2;
111         switch (regno) {
112         case FS:
113         case GS:
114         case DS:
115         case ES:
116         case SS:
117         case CS:
118                 retval = 0xffff;
119                 /* fall through */
120         default:
121                 retval &= PT_REG(&child->thread.regs, regno);
122         }
123         return retval;
124 }
125
126 /* read the word at location addr in the USER area. */
127 int peek_user(struct task_struct *child, long addr, long data)
128 {
129         unsigned long tmp;
130
131         if ((addr & 3) || addr < 0)
132                 return -EIO;
133
134         tmp = 0;  /* Default return condition */
135         if (addr < MAX_REG_OFFSET) {
136                 tmp = getreg(child, addr);
137         }
138         else if ((addr >= offsetof(struct user, u_debugreg[0])) &&
139                  (addr <= offsetof(struct user, u_debugreg[7]))) {
140                 addr -= offsetof(struct user, u_debugreg[0]);
141                 addr = addr >> 2;
142                 tmp = child->thread.arch.debugregs[addr];
143         }
144         return put_user(tmp, (unsigned long __user *) data);
145 }
146
147 static inline int convert_fxsr_to_user(struct _fpstate __user *buf,
148                                        struct pt_regs *regs)
149 {
150         return 0;
151 }
152
153 static inline int convert_fxsr_from_user(struct pt_regs *regs,
154                                          struct _fpstate __user *buf)
155 {
156         return 0;
157 }
158
159 int get_fpregs(unsigned long buf, struct task_struct *child)
160 {
161         int err;
162
163         err = convert_fxsr_to_user((struct _fpstate __user *) buf,
164                                    &child->thread.regs);
165         if (err)
166                 return -EFAULT;
167         return 0;
168 }
169
170 int set_fpregs(unsigned long buf, struct task_struct *child)
171 {
172         int err;
173
174         err = convert_fxsr_from_user(&child->thread.regs,
175                                      (struct _fpstate __user *) buf);
176         if (err)
177                 return -EFAULT;
178         return 0;
179 }
180
181 int get_fpxregs(unsigned long buf, struct task_struct *tsk)
182 {
183         return 0;
184 }
185
186 int set_fpxregs(unsigned long buf, struct task_struct *tsk)
187 {
188         return 0;
189 }
190
191 #ifdef notdef
192 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
193 {
194         fpu->cwd = (((SC_FP_CW(PT_REGS_SC(regs)) & 0xffff) << 16) |
195                     (SC_FP_SW(PT_REGS_SC(regs)) & 0xffff));
196         fpu->swd = SC_FP_CSSEL(PT_REGS_SC(regs)) & 0xffff;
197         fpu->twd = SC_FP_IPOFF(PT_REGS_SC(regs));
198         fpu->fip = SC_FP_CSSEL(PT_REGS_SC(regs)) & 0xffff;
199         fpu->fcs = SC_FP_DATAOFF(PT_REGS_SC(regs));
200         fpu->foo = SC_FP_DATASEL(PT_REGS_SC(regs));
201         fpu->fos = 0;
202         memcpy(fpu->st_space, (void *) SC_FP_ST(PT_REGS_SC(regs)),
203                sizeof(fpu->st_space));
204         return 1;
205 }
206 #endif
207
208 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu )
209 {
210         return 1;
211 }