]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
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 6f2f46c2e406ee844632da068353b0167735886e..9a5d9754c2a274e155bd712fe98bcb62664930ca 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 416927956721ac311f39a5400b9ddd832e792787..0d0ead0e0a74db0c402aba36ca3c290dc6ef25a0 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 3c36c2d1614827894a4bfff8d823ce9bf194d1ba..1043fdc2df7ff476444fd845171640611247ec7b 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 fd2129a04586551bc24ae0d2278ac43b1e48426a..74b1b4dc822527a5f901d899233bc5f187735fe9 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 ce88fb95ee59e5ce213d3c4a660e27e3fe9b4cbf..a10f3092fad4b2f535f38c87ce57afae4cfc4b89 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 0c0ceec5de009e025c214b4c0f8af7f9d607510e..f4bcf1da662a713f5cffa514ceb60f107419f86d 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 5f02b31448752e514b290c2c5023f72a89ab9059..01a1c9ac8458610226ea3213570ca32071e80ea3 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 cdba9fd6d82fa66013a247f0a7bfdfc126970d0e..01a3a09c53d9c381e5dc7dac8fe303dfe87f4ca3 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 f54b6a3dfecb1726a88e5978bd0e6d42fa1f4ddc..f550e614aa787d352ae7ec80db5dc3bb8503fdba 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 b5a7b46bbc49e0f6adb676c08c9f09aee5925823..af9d0bec8731b825829ddfcf48c187614694b71a 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 8a0db376e91e3e17f290b4db7ad3eddb0089789e..26ec774c5027fd9b8377c99a6c77df4ba9ffd484 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 0fb53950da439fb4ba1bd669a5e3f0111d09bc98..581d427148e70f33caebfd685349fb705a49872b 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 2a8f0872ea8b2dbd435f8b4879f8fce11d448187..28afff4e5d1b3594f33b2f0141a5d4d7fe53e4f7 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 f2eaa485d04d3d5e4ae320aba5eb614a9b99c814..f23f949576a52b106c1a4dfc82be5de89d4c6c39 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 4e95e18b46d90308fa01093bb27f5aa2c80c9f15..12340e499bfba166f38bb8c37cdcd4aaae1789fe 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 627742d894347c7ca6eb51f989b1e4c259de0909..1966da6eb36395157aa0858d24d0f3dde16ef966 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 a9b09343097d18442c511439737a69ca708280bf..3bedd144e52d2e4cf1048827636fedf105de01f9 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 9409117b9f1901c357a1e47c75909e8fa146d34e..327ff93a38b68077a656fac9f47fe98066c93482 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 14104ff630930a2f098017818bee98fbbc92069a..af182d3a700086def4a8e2180c19c92d1a05f969 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 eeb1976ef7bf2069a587c4a042624599c0c59099..477cc8ed6bcb2d2fdd5b57d41d85fe9e4a3cc5d9 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 b1d11f1c7cf743a6d76f48fd1678d29314eb7b96..1653d35419a1cdd60aae7af2b592254fcc125273 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);
+}