Commit 5de15d42 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Ingo Molnar

x86: clean up arch/x86/ia32/ptrace32.c

White space and coding style clenaup.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 2da06b4e
/* /*
* 32bit ptrace for x86-64. * 32bit ptrace for x86-64.
* *
* Copyright 2001,2002 Andi Kleen, SuSE Labs. * Copyright 2001,2002 Andi Kleen, SuSE Labs.
* Some parts copied from arch/i386/kernel/ptrace.c. See that file for earlier * Some parts copied from arch/i386/kernel/ptrace.c. See that file for earlier
* copyright. * copyright.
* *
* This allows to access 64bit processes too; but there is no way to see the extended * This allows to access 64bit processes too; but there is no way to
* register contents. * see the extended register contents.
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/stddef.h> #include <linux/stddef.h>
...@@ -35,8 +35,9 @@ ...@@ -35,8 +35,9 @@
*/ */
#define FLAG_MASK 0x54dd5UL #define FLAG_MASK 0x54dd5UL
#define R32(l,q) \ #define R32(l,q) \
case offsetof(struct user32, regs.l): stack[offsetof(struct pt_regs, q)/8] = val; break case offsetof(struct user32, regs.l): \
stack[offsetof(struct pt_regs, q) / 8] = val; break
static int putreg32(struct task_struct *child, unsigned regno, u32 val) static int putreg32(struct task_struct *child, unsigned regno, u32 val)
{ {
...@@ -45,30 +46,35 @@ static int putreg32(struct task_struct *child, unsigned regno, u32 val) ...@@ -45,30 +46,35 @@ static int putreg32(struct task_struct *child, unsigned regno, u32 val)
switch (regno) { switch (regno) {
case offsetof(struct user32, regs.fs): case offsetof(struct user32, regs.fs):
if (val && (val & 3) != 3) return -EIO; if (val && (val & 3) != 3)
return -EIO;
child->thread.fsindex = val & 0xffff; child->thread.fsindex = val & 0xffff;
break; break;
case offsetof(struct user32, regs.gs): case offsetof(struct user32, regs.gs):
if (val && (val & 3) != 3) return -EIO; if (val && (val & 3) != 3)
return -EIO;
child->thread.gsindex = val & 0xffff; child->thread.gsindex = val & 0xffff;
break; break;
case offsetof(struct user32, regs.ds): case offsetof(struct user32, regs.ds):
if (val && (val & 3) != 3) return -EIO; if (val && (val & 3) != 3)
return -EIO;
child->thread.ds = val & 0xffff; child->thread.ds = val & 0xffff;
break; break;
case offsetof(struct user32, regs.es): case offsetof(struct user32, regs.es):
child->thread.es = val & 0xffff; child->thread.es = val & 0xffff;
break; break;
case offsetof(struct user32, regs.ss): case offsetof(struct user32, regs.ss):
if ((val & 3) != 3) return -EIO; if ((val & 3) != 3)
stack[offsetof(struct pt_regs, ss)/8] = val & 0xffff; return -EIO;
stack[offsetof(struct pt_regs, ss)/8] = val & 0xffff;
break; break;
case offsetof(struct user32, regs.cs): case offsetof(struct user32, regs.cs):
if ((val & 3) != 3) return -EIO; if ((val & 3) != 3)
return -EIO;
stack[offsetof(struct pt_regs, cs)/8] = val & 0xffff; stack[offsetof(struct pt_regs, cs)/8] = val & 0xffff;
break; break;
R32(ebx, rbx); R32(ebx, rbx);
R32(ecx, rcx); R32(ecx, rcx);
R32(edx, rdx); R32(edx, rdx);
R32(edi, rdi); R32(edi, rdi);
...@@ -81,12 +87,13 @@ static int putreg32(struct task_struct *child, unsigned regno, u32 val) ...@@ -81,12 +87,13 @@ static int putreg32(struct task_struct *child, unsigned regno, u32 val)
case offsetof(struct user32, regs.eflags): { case offsetof(struct user32, regs.eflags): {
__u64 *flags = &stack[offsetof(struct pt_regs, eflags)/8]; __u64 *flags = &stack[offsetof(struct pt_regs, eflags)/8];
val &= FLAG_MASK; val &= FLAG_MASK;
*flags = val | (*flags & ~FLAG_MASK); *flags = val | (*flags & ~FLAG_MASK);
break; break;
} }
case offsetof(struct user32, u_debugreg[4]): case offsetof(struct user32, u_debugreg[4]):
case offsetof(struct user32, u_debugreg[5]): case offsetof(struct user32, u_debugreg[5]):
return -EIO; return -EIO;
...@@ -108,36 +115,40 @@ static int putreg32(struct task_struct *child, unsigned regno, u32 val) ...@@ -108,36 +115,40 @@ static int putreg32(struct task_struct *child, unsigned regno, u32 val)
case offsetof(struct user32, u_debugreg[6]): case offsetof(struct user32, u_debugreg[6]):
child->thread.debugreg6 = val; child->thread.debugreg6 = val;
break; break;
case offsetof(struct user32, u_debugreg[7]): case offsetof(struct user32, u_debugreg[7]):
val &= ~DR_CONTROL_RESERVED; val &= ~DR_CONTROL_RESERVED;
/* See arch/i386/kernel/ptrace.c for an explanation of /* See arch/i386/kernel/ptrace.c for an explanation of
* this awkward check.*/ * this awkward check.*/
for(i=0; i<4; i++) for (i = 0; i < 4; i++)
if ((0x5454 >> ((val >> (16 + 4*i)) & 0xf)) & 1) if ((0x5454 >> ((val >> (16 + 4*i)) & 0xf)) & 1)
return -EIO; return -EIO;
child->thread.debugreg7 = val; child->thread.debugreg7 = val;
if (val) if (val)
set_tsk_thread_flag(child, TIF_DEBUG); set_tsk_thread_flag(child, TIF_DEBUG);
else else
clear_tsk_thread_flag(child, TIF_DEBUG); clear_tsk_thread_flag(child, TIF_DEBUG);
break; break;
default: default:
if (regno > sizeof(struct user32) || (regno & 3)) if (regno > sizeof(struct user32) || (regno & 3))
return -EIO; return -EIO;
/* Other dummy fields in the virtual user structure are ignored */ /*
break; * Other dummy fields in the virtual user structure
* are ignored
*/
break;
} }
return 0; return 0;
} }
#undef R32 #undef R32
#define R32(l,q) \ #define R32(l,q) \
case offsetof(struct user32, regs.l): *val = stack[offsetof(struct pt_regs, q)/8]; break case offsetof(struct user32, regs.l): \
*val = stack[offsetof(struct pt_regs, q)/8]; break
static int getreg32(struct task_struct *child, unsigned regno, u32 *val) static int getreg32(struct task_struct *child, unsigned regno, u32 *val)
{ {
...@@ -145,7 +156,7 @@ static int getreg32(struct task_struct *child, unsigned regno, u32 *val) ...@@ -145,7 +156,7 @@ static int getreg32(struct task_struct *child, unsigned regno, u32 *val)
switch (regno) { switch (regno) {
case offsetof(struct user32, regs.fs): case offsetof(struct user32, regs.fs):
*val = child->thread.fsindex; *val = child->thread.fsindex;
break; break;
case offsetof(struct user32, regs.gs): case offsetof(struct user32, regs.gs):
*val = child->thread.gsindex; *val = child->thread.gsindex;
...@@ -159,7 +170,7 @@ static int getreg32(struct task_struct *child, unsigned regno, u32 *val) ...@@ -159,7 +170,7 @@ static int getreg32(struct task_struct *child, unsigned regno, u32 *val)
R32(cs, cs); R32(cs, cs);
R32(ss, ss); R32(ss, ss);
R32(ebx, rbx); R32(ebx, rbx);
R32(ecx, rcx); R32(ecx, rcx);
R32(edx, rdx); R32(edx, rdx);
R32(edi, rdi); R32(edi, rdi);
...@@ -171,32 +182,35 @@ static int getreg32(struct task_struct *child, unsigned regno, u32 *val) ...@@ -171,32 +182,35 @@ static int getreg32(struct task_struct *child, unsigned regno, u32 *val)
R32(eflags, eflags); R32(eflags, eflags);
R32(esp, rsp); R32(esp, rsp);
case offsetof(struct user32, u_debugreg[0]): case offsetof(struct user32, u_debugreg[0]):
*val = child->thread.debugreg0; *val = child->thread.debugreg0;
break; break;
case offsetof(struct user32, u_debugreg[1]): case offsetof(struct user32, u_debugreg[1]):
*val = child->thread.debugreg1; *val = child->thread.debugreg1;
break; break;
case offsetof(struct user32, u_debugreg[2]): case offsetof(struct user32, u_debugreg[2]):
*val = child->thread.debugreg2; *val = child->thread.debugreg2;
break; break;
case offsetof(struct user32, u_debugreg[3]): case offsetof(struct user32, u_debugreg[3]):
*val = child->thread.debugreg3; *val = child->thread.debugreg3;
break; break;
case offsetof(struct user32, u_debugreg[6]): case offsetof(struct user32, u_debugreg[6]):
*val = child->thread.debugreg6; *val = child->thread.debugreg6;
break; break;
case offsetof(struct user32, u_debugreg[7]): case offsetof(struct user32, u_debugreg[7]):
*val = child->thread.debugreg7; *val = child->thread.debugreg7;
break; break;
default: default:
if (regno > sizeof(struct user32) || (regno & 3)) if (regno > sizeof(struct user32) || (regno & 3))
return -EIO; return -EIO;
/* Other dummy fields in the virtual user structure are ignored */ /*
* Other dummy fields in the virtual user structure
* are ignored
*/
*val = 0; *val = 0;
break; break;
} }
return 0; return 0;
} }
...@@ -205,10 +219,11 @@ static int getreg32(struct task_struct *child, unsigned regno, u32 *val) ...@@ -205,10 +219,11 @@ static int getreg32(struct task_struct *child, unsigned regno, u32 *val)
static long ptrace32_siginfo(unsigned request, u32 pid, u32 addr, u32 data) static long ptrace32_siginfo(unsigned request, u32 pid, u32 addr, u32 data)
{ {
int ret;
compat_siginfo_t __user *si32 = compat_ptr(data);
siginfo_t ssi;
siginfo_t __user *si = compat_alloc_user_space(sizeof(siginfo_t)); siginfo_t __user *si = compat_alloc_user_space(sizeof(siginfo_t));
compat_siginfo_t __user *si32 = compat_ptr(data);
siginfo_t ssi;
int ret;
if (request == PTRACE_SETSIGINFO) { if (request == PTRACE_SETSIGINFO) {
memset(&ssi, 0, sizeof(siginfo_t)); memset(&ssi, 0, sizeof(siginfo_t));
ret = copy_siginfo_from_user32(&ssi, si32); ret = copy_siginfo_from_user32(&ssi, si32);
...@@ -231,12 +246,12 @@ static long ptrace32_siginfo(unsigned request, u32 pid, u32 addr, u32 data) ...@@ -231,12 +246,12 @@ static long ptrace32_siginfo(unsigned request, u32 pid, u32 addr, u32 data)
asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data) asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
{ {
struct task_struct *child; struct task_struct *child;
struct pt_regs *childregs; struct pt_regs *childregs;
void __user *datap = compat_ptr(data); void __user *datap = compat_ptr(data);
int ret; int ret;
__u32 val; __u32 val;
switch (request) { switch (request) {
case PTRACE_TRACEME: case PTRACE_TRACEME:
case PTRACE_ATTACH: case PTRACE_ATTACH:
case PTRACE_KILL: case PTRACE_KILL:
...@@ -248,7 +263,7 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data) ...@@ -248,7 +263,7 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
case PTRACE_SETOPTIONS: case PTRACE_SETOPTIONS:
case PTRACE_SET_THREAD_AREA: case PTRACE_SET_THREAD_AREA:
case PTRACE_GET_THREAD_AREA: case PTRACE_GET_THREAD_AREA:
return sys_ptrace(request, pid, addr, data); return sys_ptrace(request, pid, addr, data);
default: default:
return -EINVAL; return -EINVAL;
...@@ -257,7 +272,7 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data) ...@@ -257,7 +272,7 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
case PTRACE_PEEKDATA: case PTRACE_PEEKDATA:
case PTRACE_POKEDATA: case PTRACE_POKEDATA:
case PTRACE_POKETEXT: case PTRACE_POKETEXT:
case PTRACE_POKEUSR: case PTRACE_POKEUSR:
case PTRACE_PEEKUSR: case PTRACE_PEEKUSR:
case PTRACE_GETREGS: case PTRACE_GETREGS:
case PTRACE_SETREGS: case PTRACE_SETREGS:
...@@ -287,17 +302,19 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data) ...@@ -287,17 +302,19 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
case PTRACE_PEEKDATA: case PTRACE_PEEKDATA:
case PTRACE_PEEKTEXT: case PTRACE_PEEKTEXT:
ret = 0; ret = 0;
if (access_process_vm(child, addr, &val, sizeof(u32), 0)!=sizeof(u32)) if (access_process_vm(child, addr, &val, sizeof(u32), 0) !=
sizeof(u32))
ret = -EIO; ret = -EIO;
else else
ret = put_user(val, (unsigned int __user *)datap); ret = put_user(val, (unsigned int __user *)datap);
break; break;
case PTRACE_POKEDATA: case PTRACE_POKEDATA:
case PTRACE_POKETEXT: case PTRACE_POKETEXT:
ret = 0; ret = 0;
if (access_process_vm(child, addr, &data, sizeof(u32), 1)!=sizeof(u32)) if (access_process_vm(child, addr, &data, sizeof(u32), 1) !=
ret = -EIO; sizeof(u32))
ret = -EIO;
break; break;
case PTRACE_PEEKUSR: case PTRACE_PEEKUSR:
...@@ -312,14 +329,15 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data) ...@@ -312,14 +329,15 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
case PTRACE_GETREGS: { /* Get all gp regs from the child. */ case PTRACE_GETREGS: { /* Get all gp regs from the child. */
int i; int i;
if (!access_ok(VERIFY_WRITE, datap, 16*4)) {
if (!access_ok(VERIFY_WRITE, datap, 16*4)) {
ret = -EIO; ret = -EIO;
break; break;
} }
ret = 0; ret = 0;
for ( i = 0; i <= 16*4 ; i += sizeof(__u32) ) { for (i = 0; i <= 16*4; i += sizeof(__u32)) {
getreg32(child, i, &val); getreg32(child, i, &val);
ret |= __put_user(val,(u32 __user *)datap); ret |= __put_user(val, (u32 __user *)datap);
datap += sizeof(u32); datap += sizeof(u32);
} }
break; break;
...@@ -328,12 +346,13 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data) ...@@ -328,12 +346,13 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
case PTRACE_SETREGS: { /* Set all gp regs in the child. */ case PTRACE_SETREGS: { /* Set all gp regs in the child. */
unsigned long tmp; unsigned long tmp;
int i; int i;
if (!access_ok(VERIFY_READ, datap, 16*4)) {
if (!access_ok(VERIFY_READ, datap, 16*4)) {
ret = -EIO; ret = -EIO;
break; break;
} }
ret = 0; ret = 0;
for ( i = 0; i <= 16*4; i += sizeof(u32) ) { for (i = 0; i <= 16*4; i += sizeof(u32)) {
ret |= __get_user(tmp, (u32 __user *)datap); ret |= __get_user(tmp, (u32 __user *)datap);
putreg32(child, i, tmp); putreg32(child, i, tmp);
datap += sizeof(u32); datap += sizeof(u32);
...@@ -342,17 +361,17 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data) ...@@ -342,17 +361,17 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
} }
case PTRACE_GETFPREGS: case PTRACE_GETFPREGS:
ret = -EIO; ret = -EIO;
if (!access_ok(VERIFY_READ, compat_ptr(data), if (!access_ok(VERIFY_READ, compat_ptr(data),
sizeof(struct user_i387_struct))) sizeof(struct user_i387_struct)))
break; break;
save_i387_ia32(child, datap, childregs, 1); save_i387_ia32(child, datap, childregs, 1);
ret = 0; ret = 0;
break; break;
case PTRACE_SETFPREGS: case PTRACE_SETFPREGS:
ret = -EIO; ret = -EIO;
if (!access_ok(VERIFY_WRITE, datap, if (!access_ok(VERIFY_WRITE, datap,
sizeof(struct user_i387_struct))) sizeof(struct user_i387_struct)))
break; break;
ret = 0; ret = 0;
...@@ -360,9 +379,10 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data) ...@@ -360,9 +379,10 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
restore_i387_ia32(child, datap, 1); restore_i387_ia32(child, datap, 1);
break; break;
case PTRACE_GETFPXREGS: { case PTRACE_GETFPXREGS: {
struct user32_fxsr_struct __user *u = datap; struct user32_fxsr_struct __user *u = datap;
init_fpu(child);
init_fpu(child);
ret = -EIO; ret = -EIO;
if (!access_ok(VERIFY_WRITE, u, sizeof(*u))) if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
break; break;
...@@ -370,27 +390,31 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data) ...@@ -370,27 +390,31 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
if (__copy_to_user(u, &child->thread.i387.fxsave, sizeof(*u))) if (__copy_to_user(u, &child->thread.i387.fxsave, sizeof(*u)))
break; break;
ret = __put_user(childregs->cs, &u->fcs); ret = __put_user(childregs->cs, &u->fcs);
ret |= __put_user(child->thread.ds, &u->fos); ret |= __put_user(child->thread.ds, &u->fos);
break; break;
} }
case PTRACE_SETFPXREGS: { case PTRACE_SETFPXREGS: {
struct user32_fxsr_struct __user *u = datap; struct user32_fxsr_struct __user *u = datap;
unlazy_fpu(child); unlazy_fpu(child);
ret = -EIO; ret = -EIO;
if (!access_ok(VERIFY_READ, u, sizeof(*u))) if (!access_ok(VERIFY_READ, u, sizeof(*u)))
break; break;
/* no checking to be bug-to-bug compatible with i386. */ /*
/* but silence warning */ * no checking to be bug-to-bug compatible with i386.
* but silence warning
*/
if (__copy_from_user(&child->thread.i387.fxsave, u, sizeof(*u))) if (__copy_from_user(&child->thread.i387.fxsave, u, sizeof(*u)))
; ;
set_stopped_child_used_math(child); set_stopped_child_used_math(child);
child->thread.i387.fxsave.mxcsr &= mxcsr_feature_mask; child->thread.i387.fxsave.mxcsr &= mxcsr_feature_mask;
ret = 0; ret = 0;
break; break;
} }
case PTRACE_GETEVENTMSG: case PTRACE_GETEVENTMSG:
ret = put_user(child->ptrace_message,(unsigned int __user *)compat_ptr(data)); ret = put_user(child->ptrace_message,
(unsigned int __user *)compat_ptr(data));
break; break;
default: default:
......
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