PTRACE_PEEKDATA consolidation
[linux-2.6-block.git] / arch / i386 / kernel / ptrace.c
index f3f94ac5736a254c4a97eb58aa7335a70328df18..f4bcf1da662a713f5cffa514ceb60f107419f86d 100644 (file)
@@ -9,7 +9,6 @@
 #include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/smp.h>
-#include <linux/smp_lock.h>
 #include <linux/errno.h>
 #include <linux/ptrace.h>
 #include <linux/user.h>
@@ -45,7 +44,7 @@
 /*
  * Offset of eflags on child stack..
  */
-#define EFL_OFFSET ((EFL-2)*4-sizeof(struct pt_regs))
+#define EFL_OFFSET offsetof(struct pt_regs, eflags)
 
 static inline struct pt_regs *get_child_regs(struct task_struct *task)
 {
@@ -54,24 +53,24 @@ static inline struct pt_regs *get_child_regs(struct task_struct *task)
 }
 
 /*
- * this routine will get a word off of the processes privileged stack. 
- * the offset is how far from the base addr as stored in the TSS.  
- * this routine assumes that all the privileged stacks are in our
+ * This routine will get a word off of the processes privileged stack.
+ * the offset is bytes into the pt_regs structure on the stack.
+ * This routine assumes that all the privileged stacks are in our
  * data space.
  */   
 static inline int get_stack_long(struct task_struct *task, int offset)
 {
        unsigned char *stack;
 
-       stack = (unsigned char *)task->thread.esp0;
+       stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
        stack += offset;
        return (*((int *)stack));
 }
 
 /*
- * this routine will put a word on the processes privileged stack. 
- * the offset is how far from the base addr as stored in the TSS.  
- * this routine assumes that all the privileged stacks are in our
+ * This routine will put a word on the processes privileged stack.
+ * the offset is bytes into the pt_regs structure on the stack.
+ * This routine assumes that all the privileged stacks are in our
  * data space.
  */
 static inline int put_stack_long(struct task_struct *task, int offset,
@@ -79,7 +78,7 @@ static inline int put_stack_long(struct task_struct *task, int offset,
 {
        unsigned char * stack;
 
-       stack = (unsigned char *) task->thread.esp0;
+       stack = (unsigned char *)task->thread.esp0 - sizeof(struct pt_regs);
        stack += offset;
        *(unsigned long *) stack = data;
        return 0;
@@ -89,14 +88,14 @@ static int putreg(struct task_struct *child,
        unsigned long regno, unsigned long value)
 {
        switch (regno >> 2) {
-               case FS:
+               case GS:
                        if (value && (value & 3) != 3)
                                return -EIO;
-                       child->thread.fs = value;
+                       child->thread.gs = value;
                        return 0;
                case DS:
                case ES:
-               case GS:
+               case FS:
                        if (value && (value & 3) != 3)
                                return -EIO;
                        value &= 0xffff;
@@ -112,9 +111,9 @@ static int putreg(struct task_struct *child,
                        value |= get_stack_long(child, EFL_OFFSET) & ~FLAG_MASK;
                        break;
        }
-       if (regno > ES*4)
+       if (regno > FS*4)
                regno -= 1*4;
-       put_stack_long(child, regno - sizeof(struct pt_regs), value);
+       put_stack_long(child, regno, value);
        return 0;
 }
 
@@ -124,20 +123,19 @@ static unsigned long getreg(struct task_struct *child,
        unsigned long retval = ~0UL;
 
        switch (regno >> 2) {
-               case FS:
-                       retval = child->thread.fs;
+               case GS:
+                       retval = child->thread.gs;
                        break;
                case DS:
                case ES:
-               case GS:
+               case FS:
                case SS:
                case CS:
                        retval = 0xffff;
                        /* fall through */
                default:
-                       if (regno > ES*4)
+                       if (regno > FS*4)
                                regno -= 1*4;
-                       regno = regno - sizeof(struct pt_regs);
                        retval &= get_stack_long(child, regno);
        }
        return retval;
@@ -360,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: {