PTRACE_PEEKDATA consolidation
authorAlexey Dobriyan <adobriyan@gmail.com>
Tue, 17 Jul 2007 11:03:43 +0000 (04:03 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Tue, 17 Jul 2007 17:23:03 +0000 (10:23 -0700)
Identical implementations of PTRACE_PEEKDATA go into generic_ptrace_peekdata()
function.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: <linux-arch@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
21 files changed:
arch/arm/kernel/ptrace.c
arch/arm26/kernel/ptrace.c
arch/avr32/kernel/ptrace.c
arch/cris/arch-v10/kernel/ptrace.c
arch/frv/kernel/ptrace.c
arch/i386/kernel/ptrace.c
arch/m32r/kernel/ptrace.c
arch/m68k/kernel/ptrace.c
arch/m68knommu/kernel/ptrace.c
arch/mips/kernel/ptrace.c
arch/parisc/kernel/ptrace.c
arch/powerpc/kernel/ptrace.c
arch/s390/kernel/ptrace.c
arch/sh/kernel/ptrace.c
arch/sh64/kernel/ptrace.c
arch/um/kernel/ptrace.c
arch/v850/kernel/ptrace.c
arch/x86_64/kernel/ptrace.c
arch/xtensa/kernel/ptrace.c
include/linux/ptrace.h
kernel/ptrace.c

index 6f2f46c..9a5d975 100644 (file)
@@ -657,7 +657,6 @@ static int ptrace_setcrunchregs(struct task_struct *tsk, void __user *ufp)
 
 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 {
-       unsigned long tmp;
        int ret;
 
        switch (request) {
@@ -666,12 +665,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                 */
                case PTRACE_PEEKTEXT:
                case PTRACE_PEEKDATA:
-                       ret = access_process_vm(child, addr, &tmp,
-                                               sizeof(unsigned long), 0);
-                       if (ret == sizeof(unsigned long))
-                               ret = put_user(tmp, (unsigned long __user *) data);
-                       else
-                               ret = -EIO;
+                       ret = generic_ptrace_peekdata(child, addr, data);
                        break;
 
                case PTRACE_PEEKUSR:
index 4169279..0d0ead0 100644 (file)
@@ -531,7 +531,6 @@ static int ptrace_setfpregs(struct task_struct *tsk, void *ufp)
 
 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 {
-       unsigned long tmp;
        int ret;
 
        switch (request) {
@@ -540,12 +539,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                 */
                case PTRACE_PEEKTEXT:
                case PTRACE_PEEKDATA:
-                       ret = access_process_vm(child, addr, &tmp,
-                                               sizeof(unsigned long), 0);
-                       if (ret == sizeof(unsigned long))
-                               ret = put_user(tmp, (unsigned long *) data);
-                       else
-                               ret = -EIO;
+                       ret = generic_ptrace_peekdata(child, addr, data);
                        break;
 
                case PTRACE_PEEKUSR:
index 3c36c2d..1043fdc 100644 (file)
@@ -153,7 +153,6 @@ static int ptrace_setregs(struct task_struct *tsk, const void __user *uregs)
 
 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 {
-       unsigned long tmp;
        int ret;
 
        pr_debug("arch_ptrace(%ld, %d, %#lx, %#lx)\n",
@@ -166,11 +165,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        /* Read the word at location addr in the child process */
        case PTRACE_PEEKTEXT:
        case PTRACE_PEEKDATA:
-               ret = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               if (ret == sizeof(tmp))
-                       ret = put_user(tmp, (unsigned long __user *)data);
-               else
-                       ret = -EIO;
+               ret = generic_ptrace_peekdata(child, addr, data);
                break;
 
        case PTRACE_PEEKUSR:
index fd2129a..74b1b4d 100644 (file)
@@ -83,19 +83,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
                /* Read word at location address. */ 
                case PTRACE_PEEKTEXT:
-               case PTRACE_PEEKDATA: {
-                       unsigned long tmp;
-                       int copied;
-
-                       copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-                       ret = -EIO;
-                       
-                       if (copied != sizeof(tmp))
-                               break;
-                       
-                       ret = put_user(tmp,datap);
+               case PTRACE_PEEKDATA:
+                       ret = generic_ptrace_peekdata(child, addr, data);
                        break;
-               }
 
                /* Read the word at location address in the USER area. */
                case PTRACE_PEEKUSR: {
index ce88fb9..a10f309 100644 (file)
@@ -112,20 +112,12 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
                /* when I and D space are separate, these will need to be fixed. */
        case PTRACE_PEEKTEXT: /* read word at location addr. */
-       case PTRACE_PEEKDATA: {
-               int copied;
-
+       case PTRACE_PEEKDATA:
                ret = -EIO;
                if (is_user_addr_valid(child, addr, sizeof(tmp)) < 0)
                        break;
-
-               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               if (copied != sizeof(tmp))
-                       break;
-
-               ret = put_user(tmp,(unsigned long *) data);
+               ret = generic_ptrace_peekdata(child, addr, data);
                break;
-       }
 
                /* read the word at location addr in the USER area. */
        case PTRACE_PEEKUSR: {
index 0c0ceec..f4bcf1d 100644 (file)
@@ -358,17 +358,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
        /* when I and D space are separate, these will need to be fixed. */
        case PTRACE_PEEKTEXT: /* read word at location addr. */ 
-       case PTRACE_PEEKDATA: {
-               unsigned long tmp;
-               int copied;
-
-               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               ret = -EIO;
-               if (copied != sizeof(tmp))
-                       break;
-               ret = put_user(tmp, datap);
+       case PTRACE_PEEKDATA:
+               ret = generic_ptrace_peekdata(child, addr, data);
                break;
-       }
 
        /* read the word at location addr in the USER area. */
        case PTRACE_PEEKUSR: {
index 5f02b31..01a1c9a 100644 (file)
@@ -595,7 +595,6 @@ void ptrace_disable(struct task_struct *child)
 static int
 do_ptrace(long request, struct task_struct *child, long addr, long data)
 {
-       unsigned long tmp;
        int ret;
 
        switch (request) {
@@ -604,11 +603,7 @@ do_ptrace(long request, struct task_struct *child, long addr, long data)
         */
        case PTRACE_PEEKTEXT:
        case PTRACE_PEEKDATA:
-               ret = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               if (ret == sizeof(tmp))
-                       ret = put_user(tmp,(unsigned long __user *) data);
-               else
-                       ret = -EIO;
+               ret = generic_ptrace_peekdata(child, addr, data);
                break;
 
        /*
index cdba9fd..01a3a09 100644 (file)
@@ -128,10 +128,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        /* when I and D space are separate, these will need to be fixed. */
        case PTRACE_PEEKTEXT:   /* read word at location addr. */
        case PTRACE_PEEKDATA:
-               i = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               if (i != sizeof(tmp))
-                       goto out_eio;
-               ret = put_user(tmp, (unsigned long *)data);
+               ret = generic_ptrace_peekdata(child, addr, data);
                break;
 
        /* read the word at location addr in the USER area. */
index f54b6a3..f550e61 100644 (file)
@@ -106,17 +106,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
                /* when I and D space are separate, these will need to be fixed. */
                case PTRACE_PEEKTEXT: /* read word at location addr. */ 
-               case PTRACE_PEEKDATA: {
-                       unsigned long tmp;
-                       int copied;
-
-                       copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-                       ret = -EIO;
-                       if (copied != sizeof(tmp))
-                               break;
-                       ret = put_user(tmp,(unsigned long *) data);
+               case PTRACE_PEEKDATA:
+                       ret = generic_ptrace_peekdata(child, addr, data);
                        break;
-               }
 
                /* read the word at location addr in the USER area. */
                case PTRACE_PEEKUSR: {
index b5a7b46..af9d0be 100644 (file)
@@ -174,17 +174,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
        /* when I and D space are separate, these will need to be fixed. */
        case PTRACE_PEEKTEXT: /* read word at location addr. */
-       case PTRACE_PEEKDATA: {
-               unsigned long tmp;
-               int copied;
-
-               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               ret = -EIO;
-               if (copied != sizeof(tmp))
-                       break;
-               ret = put_user(tmp,(unsigned long __user *) data);
+       case PTRACE_PEEKDATA:
+               ret = generic_ptrace_peekdata(child, addr, data);
                break;
-       }
 
        /* Read the word at location addr in the USER area. */
        case PTRACE_PEEKUSR: {
index 8a0db37..26ec774 100644 (file)
@@ -87,10 +87,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
        case PTRACE_PEEKTEXT: /* read word at location addr. */ 
        case PTRACE_PEEKDATA: {
-               int copied;
-
 #ifdef CONFIG_64BIT
                if (__is_compat_task(child)) {
+                       int copied;
                        unsigned int tmp;
 
                        addr &= 0xffffffffL;
@@ -105,15 +104,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                }
                else
 #endif
-               {
-                       unsigned long tmp;
-
-                       copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-                       ret = -EIO;
-                       if (copied != sizeof(tmp))
-                               goto out_tsk;
-                       ret = put_user(tmp,(unsigned long *) data);
-               }
+                       ret = generic_ptrace_peekdata(child, addr, data);
                goto out_tsk;
        }
 
index 0fb5395..581d427 100644 (file)
@@ -379,17 +379,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
        /* when I and D space are separate, these will need to be fixed. */
        case PTRACE_PEEKTEXT: /* read word at location addr. */
-       case PTRACE_PEEKDATA: {
-               unsigned long tmp;
-               int copied;
-
-               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               ret = -EIO;
-               if (copied != sizeof(tmp))
-                       break;
-               ret = put_user(tmp,(unsigned long __user *) data);
+       case PTRACE_PEEKDATA:
+               ret = generic_ptrace_peekdata(child, addr, data);
                break;
-       }
 
        /* read the word at location addr in the USER area. */
        case PTRACE_PEEKUSR: {
index 2a8f087..28afff4 100644 (file)
@@ -294,7 +294,6 @@ poke_user(struct task_struct *child, addr_t addr, addr_t data)
 static int
 do_ptrace_normal(struct task_struct *child, long request, long addr, long data)
 {
-       unsigned long tmp;
        ptrace_area parea; 
        int copied, ret;
 
@@ -304,10 +303,7 @@ do_ptrace_normal(struct task_struct *child, long request, long addr, long data)
                /* Remove high order bit from address (only for 31 bit). */
                addr &= PSW_ADDR_INSN;
                /* read word at location addr. */
-               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               if (copied != sizeof(tmp))
-                       return -EIO;
-               return put_user(tmp, (unsigned long __force __user *) data);
+               return generic_ptrace_peekdata(child, addr, data);
 
        case PTRACE_PEEKUSR:
                /* read the word at location addr in the USER area. */
index f2eaa48..f23f949 100644 (file)
@@ -91,17 +91,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
        /* when I and D space are separate, these will need to be fixed. */
        case PTRACE_PEEKTEXT: /* read word at location addr. */
-       case PTRACE_PEEKDATA: {
-               unsigned long tmp;
-               int copied;
-
-               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               ret = -EIO;
-               if (copied != sizeof(tmp))
-                       break;
-               ret = put_user(tmp,(unsigned long __user *) data);
-               break;
-       }
+       case PTRACE_PEEKDATA:
+               ret = generic_ptrace_peekdata(child, addr, data);
 
        /* read the word at location addr in the USER area. */
        case PTRACE_PEEKUSR: {
index 4e95e18..12340e4 100644 (file)
@@ -129,17 +129,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
        /* when I and D space are separate, these will need to be fixed. */
        case PTRACE_PEEKTEXT: /* read word at location addr. */
-       case PTRACE_PEEKDATA: {
-               unsigned long tmp;
-               int copied;
-
-               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               ret = -EIO;
-               if (copied != sizeof(tmp))
-                       break;
-               ret = put_user(tmp,(unsigned long *) data);
+       case PTRACE_PEEKDATA:
+               ret = generic_ptrace_peekdata(child, addr, data);
                break;
-       }
 
        /* read the word at location addr in the USER area. */
        case PTRACE_PEEKUSR: {
index 627742d..1966da6 100644 (file)
@@ -52,17 +52,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
                /* when I and D space are separate, these will need to be fixed. */
        case PTRACE_PEEKTEXT: /* read word at location addr. */ 
-       case PTRACE_PEEKDATA: {
-               unsigned long tmp;
-               int copied;
-
-               ret = -EIO;
-               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               if (copied != sizeof(tmp))
-                       break;
-               ret = put_user(tmp, p);
+       case PTRACE_PEEKDATA:
+               ret = generic_ptrace_peekdata(child, addr, data);
                break;
-       }
 
        /* read the word at location addr in the USER area. */
         case PTRACE_PEEKUSR:
index a9b0934..3bedd14 100644 (file)
@@ -117,15 +117,11 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        int rval;
 
        switch (request) {
-               unsigned long val, copied;
+               unsigned long val;
 
        case PTRACE_PEEKTEXT: /* read word at location addr. */
        case PTRACE_PEEKDATA:
-               copied = access_process_vm(child, addr, &val, sizeof(val), 0);
-               rval = -EIO;
-               if (copied != sizeof(val))
-                       break;
-               rval = put_user(val, (unsigned long *)data);
+               rval = generic_ptrace_peekdata(child, addr, data);
                goto out;
 
        case PTRACE_POKETEXT: /* write the word at location addr. */
index 9409117..327ff93 100644 (file)
@@ -313,17 +313,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
        /* when I and D space are separate, these will need to be fixed. */
        case PTRACE_PEEKTEXT: /* read word at location addr. */ 
-       case PTRACE_PEEKDATA: {
-               unsigned long tmp;
-               int copied;
-
-               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               ret = -EIO;
-               if (copied != sizeof(tmp))
-                       break;
-               ret = put_user(tmp,(unsigned long __user *) data);
+       case PTRACE_PEEKDATA:
+               ret = generic_ptrace_peekdata(child, addr, data);
                break;
-       }
 
        /* read the word at location addr in the USER area. */
        case PTRACE_PEEKUSR: {
index 14104ff..af182d3 100644 (file)
@@ -50,18 +50,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
        switch (request) {
        case PTRACE_PEEKTEXT: /* read word at location addr. */
        case PTRACE_PEEKDATA:
-       {
-               unsigned long tmp;
-               int copied;
-
-               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
-               ret = -EIO;
-               if (copied != sizeof(tmp))
-                       break;
-               ret = put_user(tmp,(unsigned long *) data);
-
+               ret = generic_ptrace_peekdata(child, addr, data);
                goto out;
-       }
 
        /* Read the word at location addr in the USER area.  */
 
index eeb1976..477cc8e 100644 (file)
@@ -110,6 +110,7 @@ static inline void ptrace_unlink(struct task_struct *child)
                __ptrace_unlink(child);
 }
 
+int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data);
 
 #ifndef force_successful_syscall_return
 /*
index b1d11f1..1653d35 100644 (file)
@@ -490,3 +490,14 @@ asmlinkage long sys_ptrace(long request, long pid, long addr, long data)
        return ret;
 }
 #endif /* __ARCH_SYS_PTRACE */
+
+int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data)
+{
+       unsigned long tmp;
+       int copied;
+
+       copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
+       if (copied != sizeof(tmp))
+               return -EIO;
+       return put_user(tmp, (unsigned long __user *)data);
+}