Commit 5a4646a4 authored by Roland McGrath's avatar Roland McGrath Committed by Ingo Molnar

x86: x86 ptrace user_regset

This cleans up the PTRACE_*REGS* request code so each one is just a
simple call to copy_regset_to_user or copy_regset_from_user.  The
ptrace layouts already match the user_regset formats (core dump formats).
Signed-off-by: default avatarRoland McGrath <roland@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 975511be
...@@ -750,9 +750,13 @@ void ptrace_disable(struct task_struct *child) ...@@ -750,9 +750,13 @@ void ptrace_disable(struct task_struct *child)
} }
} }
#if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
static const struct user_regset_view user_x86_32_view; /* Initialized below. */
#endif
long arch_ptrace(struct task_struct *child, long request, long addr, long data) long arch_ptrace(struct task_struct *child, long request, long addr, long data)
{ {
int i, ret; int ret;
unsigned long __user *datap = (unsigned long __user *)data; unsigned long __user *datap = (unsigned long __user *)data;
switch (request) { switch (request) {
...@@ -805,82 +809,46 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) ...@@ -805,82 +809,46 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
} }
break; break;
case PTRACE_GETREGS: { /* Get all gp regs from the child. */ case PTRACE_GETREGS: /* Get all gp regs from the child. */
if (!access_ok(VERIFY_WRITE, datap, sizeof(struct user_regs_struct))) { return copy_regset_to_user(child,
ret = -EIO; task_user_regset_view(current),
break; REGSET_GENERAL,
} 0, sizeof(struct user_regs_struct),
for (i = 0; i < sizeof(struct user_regs_struct); i += sizeof(long)) { datap);
__put_user(getreg(child, i), datap);
datap++;
}
ret = 0;
break;
}
case PTRACE_SETREGS: { /* Set all gp regs in the child. */ case PTRACE_SETREGS: /* Set all gp regs in the child. */
unsigned long tmp; return copy_regset_from_user(child,
if (!access_ok(VERIFY_READ, datap, sizeof(struct user_regs_struct))) { task_user_regset_view(current),
ret = -EIO; REGSET_GENERAL,
break; 0, sizeof(struct user_regs_struct),
} datap);
for (i = 0; i < sizeof(struct user_regs_struct); i += sizeof(long)) {
__get_user(tmp, datap);
putreg(child, i, tmp);
datap++;
}
ret = 0;
break;
}
case PTRACE_GETFPREGS: { /* Get the child FPU state. */ case PTRACE_GETFPREGS: /* Get the child FPU state. */
if (!access_ok(VERIFY_WRITE, datap, return copy_regset_to_user(child,
sizeof(struct user_i387_struct))) { task_user_regset_view(current),
ret = -EIO; REGSET_FP,
break; 0, sizeof(struct user_i387_struct),
} datap);
ret = 0;
if (!tsk_used_math(child))
init_fpu(child);
get_fpregs((struct user_i387_struct __user *)data, child);
break;
}
case PTRACE_SETFPREGS: { /* Set the child FPU state. */ case PTRACE_SETFPREGS: /* Set the child FPU state. */
if (!access_ok(VERIFY_READ, datap, return copy_regset_from_user(child,
sizeof(struct user_i387_struct))) { task_user_regset_view(current),
ret = -EIO; REGSET_FP,
break; 0, sizeof(struct user_i387_struct),
} datap);
set_stopped_child_used_math(child);
set_fpregs(child, (struct user_i387_struct __user *)data);
ret = 0;
break;
}
#ifdef CONFIG_X86_32 #ifdef CONFIG_X86_32
case PTRACE_GETFPXREGS: { /* Get the child extended FPU state. */ case PTRACE_GETFPXREGS: /* Get the child extended FPU state. */
if (!access_ok(VERIFY_WRITE, datap, return copy_regset_to_user(child, &user_x86_32_view,
sizeof(struct user_fxsr_struct))) { REGSET_XFP,
ret = -EIO; 0, sizeof(struct user_fxsr_struct),
break; datap);
}
if (!tsk_used_math(child))
init_fpu(child);
ret = get_fpxregs((struct user_fxsr_struct __user *)data, child);
break;
}
case PTRACE_SETFPXREGS: { /* Set the child extended FPU state. */ case PTRACE_SETFPXREGS: /* Set the child extended FPU state. */
if (!access_ok(VERIFY_READ, datap, return copy_regset_from_user(child, &user_x86_32_view,
sizeof(struct user_fxsr_struct))) { REGSET_XFP,
ret = -EIO; 0, sizeof(struct user_fxsr_struct),
break; datap);
}
set_stopped_child_used_math(child);
ret = set_fpxregs(child, (struct user_fxsr_struct __user *)data);
break;
}
#endif #endif
#if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
...@@ -1243,90 +1211,40 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data) ...@@ -1243,90 +1211,40 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
ret = putreg32(child, addr, data); ret = putreg32(child, addr, data);
break; break;
case PTRACE_GETREGS: { /* Get all gp regs from the child. */ case PTRACE_GETREGS: /* Get all gp regs from the child. */
int i; return copy_regset_to_user(child, &user_x86_32_view,
REGSET_GENERAL,
if (!access_ok(VERIFY_WRITE, datap, 16*4)) { 0, sizeof(struct user_regs_struct32),
ret = -EIO; datap);
break;
} case PTRACE_SETREGS: /* Set all gp regs in the child. */
ret = 0; return copy_regset_from_user(child, &user_x86_32_view,
for (i = 0; i < sizeof(struct user_regs_struct32); i += sizeof(__u32)) { REGSET_GENERAL, 0,
getreg32(child, i, &val); sizeof(struct user_regs_struct32),
ret |= __put_user(val, (u32 __user *)datap); datap);
datap += sizeof(u32);
} case PTRACE_GETFPREGS: /* Get the child FPU state. */
break; return copy_regset_to_user(child, &user_x86_32_view,
} REGSET_FP, 0,
sizeof(struct user_i387_ia32_struct),
case PTRACE_SETREGS: { /* Set all gp regs in the child. */ datap);
unsigned long tmp;
int i; case PTRACE_SETFPREGS: /* Set the child FPU state. */
return copy_regset_from_user(
if (!access_ok(VERIFY_READ, datap, 16*4)) { child, &user_x86_32_view, REGSET_FP,
ret = -EIO; 0, sizeof(struct user_i387_ia32_struct), datap);
break;
} case PTRACE_GETFPXREGS: /* Get the child extended FPU state. */
ret = 0; return copy_regset_to_user(child, &user_x86_32_view,
for (i = 0; i < sizeof(struct user_regs_struct32); i += sizeof(u32)) { REGSET_XFP, 0,
ret |= __get_user(tmp, (u32 __user *)datap); sizeof(struct user32_fxsr_struct),
putreg32(child, i, tmp); datap);
datap += sizeof(u32);
} case PTRACE_SETFPXREGS: /* Set the child extended FPU state. */
break; return copy_regset_from_user(child, &user_x86_32_view,
} REGSET_XFP, 0,
sizeof(struct user32_fxsr_struct),
case PTRACE_GETFPREGS: datap);
ret = -EIO;
if (!access_ok(VERIFY_READ, compat_ptr(data),
sizeof(struct user_i387_struct)))
break;
save_i387_ia32(child, datap, childregs, 1);
ret = 0;
break;
case PTRACE_SETFPREGS:
ret = -EIO;
if (!access_ok(VERIFY_WRITE, datap,
sizeof(struct user_i387_struct)))
break;
ret = 0;
/* don't check EFAULT to be bug-to-bug compatible to i386 */
restore_i387_ia32(child, datap, 1);
break;
case PTRACE_GETFPXREGS: {
struct user32_fxsr_struct __user *u = datap;
init_fpu(child);
ret = -EIO;
if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
break;
ret = -EFAULT;
if (__copy_to_user(u, &child->thread.i387.fxsave, sizeof(*u)))
break;
ret = __put_user(childregs->cs, &u->fcs);
ret |= __put_user(child->thread.ds, &u->fos);
break;
}
case PTRACE_SETFPXREGS: {
struct user32_fxsr_struct __user *u = datap;
unlazy_fpu(child);
ret = -EIO;
if (!access_ok(VERIFY_READ, u, sizeof(*u)))
break;
/*
* no checking to be bug-to-bug compatible with i386.
* but silence warning
*/
if (__copy_from_user(&child->thread.i387.fxsave, u, sizeof(*u)))
;
set_stopped_child_used_math(child);
child->thread.i387.fxsave.mxcsr &= mxcsr_feature_mask;
ret = 0;
break;
}
case PTRACE_GETEVENTMSG: case PTRACE_GETEVENTMSG:
ret = put_user(child->ptrace_message, ret = put_user(child->ptrace_message,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment