2 * 32bit ptrace for x86-64.
4 * Copyright 2001,2002 Andi Kleen, SuSE Labs.
5 * Some parts copied from arch/i386/kernel/ptrace.c. See that file for earlier
8 * This allows to access 64bit processes too; but there is no way to see the extended
12 #include <linux/kernel.h>
13 #include <linux/stddef.h>
14 #include <linux/sched.h>
15 #include <linux/syscalls.h>
16 #include <linux/unistd.h>
18 #include <linux/ptrace.h>
19 #include <asm/ptrace.h>
20 #include <asm/compat.h>
21 #include <asm/uaccess.h>
22 #include <asm/user32.h>
24 #include <asm/errno.h>
25 #include <asm/debugreg.h>
27 #include <asm/fpu32.h>
31 * Determines which flags the user has access to [1 = access, 0 = no access].
32 * Prohibits changing ID(21), VIP(20), VIF(19), VM(17), IOPL(12-13), IF(9).
33 * Also masks reserved bits (31-22, 15, 5, 3, 1).
35 #define FLAG_MASK 0x54dd5UL
38 case offsetof(struct user32, regs.l): stack[offsetof(struct pt_regs, q)/8] = val; break
40 static int putreg32(struct task_struct *child, unsigned regno, u32 val)
43 __u64 *stack = (__u64 *)task_pt_regs(child);
46 case offsetof(struct user32, regs.fs):
47 if (val && (val & 3) != 3) return -EIO;
48 child->thread.fsindex = val & 0xffff;
50 case offsetof(struct user32, regs.gs):
51 if (val && (val & 3) != 3) return -EIO;
52 child->thread.gsindex = val & 0xffff;
54 case offsetof(struct user32, regs.ds):
55 if (val && (val & 3) != 3) return -EIO;
56 child->thread.ds = val & 0xffff;
58 case offsetof(struct user32, regs.es):
59 child->thread.es = val & 0xffff;
61 case offsetof(struct user32, regs.ss):
62 if ((val & 3) != 3) return -EIO;
63 stack[offsetof(struct pt_regs, ss)/8] = val & 0xffff;
65 case offsetof(struct user32, regs.cs):
66 if ((val & 3) != 3) return -EIO;
67 stack[offsetof(struct pt_regs, cs)/8] = val & 0xffff;
77 R32(orig_eax, orig_rax);
81 case offsetof(struct user32, regs.eflags): {
82 __u64 *flags = &stack[offsetof(struct pt_regs, eflags)/8];
84 *flags = val | (*flags & ~FLAG_MASK);
88 case offsetof(struct user32, u_debugreg[4]):
89 case offsetof(struct user32, u_debugreg[5]):
92 case offsetof(struct user32, u_debugreg[0]):
93 child->thread.debugreg0 = val;
96 case offsetof(struct user32, u_debugreg[1]):
97 child->thread.debugreg1 = val;
100 case offsetof(struct user32, u_debugreg[2]):
101 child->thread.debugreg2 = val;
104 case offsetof(struct user32, u_debugreg[3]):
105 child->thread.debugreg3 = val;
108 case offsetof(struct user32, u_debugreg[6]):
109 child->thread.debugreg6 = val;
112 case offsetof(struct user32, u_debugreg[7]):
113 val &= ~DR_CONTROL_RESERVED;
114 /* See arch/i386/kernel/ptrace.c for an explanation of
115 * this awkward check.*/
117 if ((0x5454 >> ((val >> (16 + 4*i)) & 0xf)) & 1)
119 child->thread.debugreg7 = val;
121 set_tsk_thread_flag(child, TIF_DEBUG);
123 clear_tsk_thread_flag(child, TIF_DEBUG);
127 if (regno > sizeof(struct user32) || (regno & 3))
130 /* Other dummy fields in the virtual user structure are ignored */
139 case offsetof(struct user32, regs.l): *val = stack[offsetof(struct pt_regs, q)/8]; break
141 static int getreg32(struct task_struct *child, unsigned regno, u32 *val)
143 __u64 *stack = (__u64 *)task_pt_regs(child);
146 case offsetof(struct user32, regs.fs):
147 *val = child->thread.fsindex;
149 case offsetof(struct user32, regs.gs):
150 *val = child->thread.gsindex;
152 case offsetof(struct user32, regs.ds):
153 *val = child->thread.ds;
155 case offsetof(struct user32, regs.es):
156 *val = child->thread.es;
168 R32(orig_eax, orig_rax);
173 case offsetof(struct user32, u_debugreg[0]):
174 *val = child->thread.debugreg0;
176 case offsetof(struct user32, u_debugreg[1]):
177 *val = child->thread.debugreg1;
179 case offsetof(struct user32, u_debugreg[2]):
180 *val = child->thread.debugreg2;
182 case offsetof(struct user32, u_debugreg[3]):
183 *val = child->thread.debugreg3;
185 case offsetof(struct user32, u_debugreg[6]):
186 *val = child->thread.debugreg6;
188 case offsetof(struct user32, u_debugreg[7]):
189 *val = child->thread.debugreg7;
193 if (regno > sizeof(struct user32) || (regno & 3))
196 /* Other dummy fields in the virtual user structure are ignored */
205 static long ptrace32_siginfo(unsigned request, u32 pid, u32 addr, u32 data)
208 compat_siginfo_t __user *si32 = compat_ptr(data);
210 siginfo_t __user *si = compat_alloc_user_space(sizeof(siginfo_t));
211 if (request == PTRACE_SETSIGINFO) {
212 memset(&ssi, 0, sizeof(siginfo_t));
213 ret = copy_siginfo_from_user32(&ssi, si32);
216 if (copy_to_user(si, &ssi, sizeof(siginfo_t)))
219 ret = sys_ptrace(request, pid, addr, (unsigned long)si);
222 if (request == PTRACE_GETSIGINFO) {
223 if (copy_from_user(&ssi, si, sizeof(siginfo_t)))
225 ret = copy_siginfo_to_user32(si32, &ssi);
230 asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
232 struct task_struct *child;
233 struct pt_regs *childregs;
234 void __user *datap = compat_ptr(data);
243 case PTRACE_SINGLESTEP:
246 case PTRACE_SETOPTIONS:
247 case PTRACE_SET_THREAD_AREA:
248 case PTRACE_GET_THREAD_AREA:
249 return sys_ptrace(request, pid, addr, data);
254 case PTRACE_PEEKTEXT:
255 case PTRACE_PEEKDATA:
256 case PTRACE_POKEDATA:
257 case PTRACE_POKETEXT:
262 case PTRACE_SETFPREGS:
263 case PTRACE_GETFPREGS:
264 case PTRACE_SETFPXREGS:
265 case PTRACE_GETFPXREGS:
266 case PTRACE_GETEVENTMSG:
269 case PTRACE_SETSIGINFO:
270 case PTRACE_GETSIGINFO:
271 return ptrace32_siginfo(request, pid, addr, data);
274 child = ptrace_get_task_struct(pid);
276 return PTR_ERR(child);
278 ret = ptrace_check_attach(child, request == PTRACE_KILL);
282 childregs = task_pt_regs(child);
285 case PTRACE_PEEKDATA:
286 case PTRACE_PEEKTEXT:
288 if (access_process_vm(child, addr, &val, sizeof(u32), 0)!=sizeof(u32))
291 ret = put_user(val, (unsigned int __user *)datap);
294 case PTRACE_POKEDATA:
295 case PTRACE_POKETEXT:
297 if (access_process_vm(child, addr, &data, sizeof(u32), 1)!=sizeof(u32))
302 ret = getreg32(child, addr, &val);
304 ret = put_user(val, (__u32 __user *)datap);
308 ret = putreg32(child, addr, data);
311 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
313 if (!access_ok(VERIFY_WRITE, datap, 16*4)) {
318 for ( i = 0; i <= 16*4 ; i += sizeof(__u32) ) {
319 getreg32(child, i, &val);
320 ret |= __put_user(val,(u32 __user *)datap);
321 datap += sizeof(u32);
326 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
329 if (!access_ok(VERIFY_READ, datap, 16*4)) {
334 for ( i = 0; i <= 16*4; i += sizeof(u32) ) {
335 ret |= __get_user(tmp, (u32 __user *)datap);
336 putreg32(child, i, tmp);
337 datap += sizeof(u32);
342 case PTRACE_GETFPREGS:
344 if (!access_ok(VERIFY_READ, compat_ptr(data),
345 sizeof(struct user_i387_struct)))
347 save_i387_ia32(child, datap, childregs, 1);
351 case PTRACE_SETFPREGS:
353 if (!access_ok(VERIFY_WRITE, datap,
354 sizeof(struct user_i387_struct)))
357 /* don't check EFAULT to be bug-to-bug compatible to i386 */
358 restore_i387_ia32(child, datap, 1);
361 case PTRACE_GETFPXREGS: {
362 struct user32_fxsr_struct __user *u = datap;
365 if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
368 if (__copy_to_user(u, &child->thread.i387.fxsave, sizeof(*u)))
370 ret = __put_user(childregs->cs, &u->fcs);
371 ret |= __put_user(child->thread.ds, &u->fos);
374 case PTRACE_SETFPXREGS: {
375 struct user32_fxsr_struct __user *u = datap;
378 if (!access_ok(VERIFY_READ, u, sizeof(*u)))
380 /* no checking to be bug-to-bug compatible with i386. */
381 /* but silence warning */
382 if (__copy_from_user(&child->thread.i387.fxsave, u, sizeof(*u)))
384 set_stopped_child_used_math(child);
385 child->thread.i387.fxsave.mxcsr &= mxcsr_feature_mask;
390 case PTRACE_GETEVENTMSG:
391 ret = put_user(child->ptrace_message,(unsigned int __user *)compat_ptr(data));
399 put_task_struct(child);