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;
123 if (regno > sizeof(struct user32) || (regno & 3))
126 /* Other dummy fields in the virtual user structure are ignored */
135 case offsetof(struct user32, regs.l): *val = stack[offsetof(struct pt_regs, q)/8]; break
137 static int getreg32(struct task_struct *child, unsigned regno, u32 *val)
139 __u64 *stack = (__u64 *)task_pt_regs(child);
142 case offsetof(struct user32, regs.fs):
143 *val = child->thread.fsindex;
145 case offsetof(struct user32, regs.gs):
146 *val = child->thread.gsindex;
148 case offsetof(struct user32, regs.ds):
149 *val = child->thread.ds;
151 case offsetof(struct user32, regs.es):
152 *val = child->thread.es;
164 R32(orig_eax, orig_rax);
169 case offsetof(struct user32, u_debugreg[0]):
170 *val = child->thread.debugreg0;
172 case offsetof(struct user32, u_debugreg[1]):
173 *val = child->thread.debugreg1;
175 case offsetof(struct user32, u_debugreg[2]):
176 *val = child->thread.debugreg2;
178 case offsetof(struct user32, u_debugreg[3]):
179 *val = child->thread.debugreg3;
181 case offsetof(struct user32, u_debugreg[6]):
182 *val = child->thread.debugreg6;
184 case offsetof(struct user32, u_debugreg[7]):
185 *val = child->thread.debugreg7;
189 if (regno > sizeof(struct user32) || (regno & 3))
192 /* Other dummy fields in the virtual user structure are ignored */
201 static long ptrace32_siginfo(unsigned request, u32 pid, u32 addr, u32 data)
204 compat_siginfo_t *si32 = (compat_siginfo_t *)compat_ptr(data);
205 siginfo_t *si = compat_alloc_user_space(sizeof(siginfo_t));
206 if (request == PTRACE_SETSIGINFO) {
207 ret = copy_siginfo_from_user32(si, si32);
211 ret = sys_ptrace(request, pid, addr, (unsigned long)si);
214 if (request == PTRACE_GETSIGINFO)
215 ret = copy_siginfo_to_user32(si32, si);
219 asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
221 struct task_struct *child;
222 struct pt_regs *childregs;
223 void __user *datap = compat_ptr(data);
232 case PTRACE_SINGLESTEP:
235 case PTRACE_SETOPTIONS:
236 return sys_ptrace(request, pid, addr, data);
241 case PTRACE_PEEKTEXT:
242 case PTRACE_PEEKDATA:
243 case PTRACE_POKEDATA:
244 case PTRACE_POKETEXT:
249 case PTRACE_SETFPREGS:
250 case PTRACE_GETFPREGS:
251 case PTRACE_SETFPXREGS:
252 case PTRACE_GETFPXREGS:
253 case PTRACE_GETEVENTMSG:
256 case PTRACE_SETSIGINFO:
257 case PTRACE_GETSIGINFO:
258 return ptrace32_siginfo(request, pid, addr, data);
261 child = ptrace_get_task_struct(pid);
263 return PTR_ERR(child);
265 ret = ptrace_check_attach(child, request == PTRACE_KILL);
269 childregs = task_pt_regs(child);
272 case PTRACE_PEEKDATA:
273 case PTRACE_PEEKTEXT:
275 if (access_process_vm(child, addr, &val, sizeof(u32), 0)!=sizeof(u32))
278 ret = put_user(val, (unsigned int __user *)datap);
281 case PTRACE_POKEDATA:
282 case PTRACE_POKETEXT:
284 if (access_process_vm(child, addr, &data, sizeof(u32), 1)!=sizeof(u32))
289 ret = getreg32(child, addr, &val);
291 ret = put_user(val, (__u32 __user *)datap);
295 ret = putreg32(child, addr, data);
298 case PTRACE_GETREGS: { /* Get all gp regs from the child. */
300 if (!access_ok(VERIFY_WRITE, datap, 16*4)) {
305 for ( i = 0; i <= 16*4 ; i += sizeof(__u32) ) {
306 getreg32(child, i, &val);
307 ret |= __put_user(val,(u32 __user *)datap);
308 datap += sizeof(u32);
313 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
316 if (!access_ok(VERIFY_READ, datap, 16*4)) {
321 for ( i = 0; i <= 16*4; i += sizeof(u32) ) {
322 ret |= __get_user(tmp, (u32 __user *)datap);
323 putreg32(child, i, tmp);
324 datap += sizeof(u32);
329 case PTRACE_GETFPREGS:
331 if (!access_ok(VERIFY_READ, compat_ptr(data),
332 sizeof(struct user_i387_struct)))
334 save_i387_ia32(child, datap, childregs, 1);
338 case PTRACE_SETFPREGS:
340 if (!access_ok(VERIFY_WRITE, datap,
341 sizeof(struct user_i387_struct)))
344 /* don't check EFAULT to be bug-to-bug compatible to i386 */
345 restore_i387_ia32(child, datap, 1);
348 case PTRACE_GETFPXREGS: {
349 struct user32_fxsr_struct __user *u = datap;
352 if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
355 if (__copy_to_user(u, &child->thread.i387.fxsave, sizeof(*u)))
357 ret = __put_user(childregs->cs, &u->fcs);
358 ret |= __put_user(child->thread.ds, &u->fos);
361 case PTRACE_SETFPXREGS: {
362 struct user32_fxsr_struct __user *u = datap;
365 if (!access_ok(VERIFY_READ, u, sizeof(*u)))
367 /* no checking to be bug-to-bug compatible with i386 */
368 __copy_from_user(&child->thread.i387.fxsave, u, sizeof(*u));
369 set_stopped_child_used_math(child);
370 child->thread.i387.fxsave.mxcsr &= mxcsr_feature_mask;
375 case PTRACE_GETEVENTMSG:
376 ret = put_user(child->ptrace_message,(unsigned int __user *)compat_ptr(data));
384 put_task_struct(child);