fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / i386 / kernel / ptrace.c
index 0c6074f..a8e5723 100644 (file)
@@ -41,7 +41,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)
 {
@@ -50,24 +50,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,
@@ -75,7 +75,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;
@@ -90,13 +90,9 @@ static int putreg(struct task_struct *child,
                                return -EIO;
                        child->thread.fs = value;
                        return 0;
-               case GS:
-                       if (value && (value & 3) != 3)
-                               return -EIO;
-                       child->thread.gs = value;
-                       return 0;
                case DS:
                case ES:
+               case GS:
                        if (value && (value & 3) != 3)
                                return -EIO;
                        value &= 0xffff;
@@ -113,9 +109,9 @@ static int putreg(struct task_struct *child,
                        clear_tsk_thread_flag(child, TIF_FORCED_TF);
                        break;
        }
-       if (regno > GS*4)
-               regno -= 2*4;
-       put_stack_long(child, regno - sizeof(struct pt_regs), value);
+       if (regno > ES*4)
+               regno -= 1*4;
+       put_stack_long(child, regno, value);
        return 0;
 }
 
@@ -128,24 +124,21 @@ static unsigned long getreg(struct task_struct *child,
                case FS:
                        retval = child->thread.fs;
                        break;
-               case GS:
-                       retval = child->thread.gs;
-                       break;
                case EFL:
                        if (test_tsk_thread_flag(child, TIF_FORCED_TF))
                                retval &= ~X86_EFLAGS_TF;
                        goto fetch;
                case DS:
                case ES:
+               case GS:
                case SS:
                case CS:
                        retval = 0xffff;
                        /* fall through */
                default:
-               fetch:
-                       if (regno > GS*4)
-                               regno -= 2*4;
-                       regno = regno - sizeof(struct pt_regs);
+fetch:
+                       if (regno > ES*4)
+                               regno -= 1*4;
                        retval &= get_stack_long(child, regno);
                        break;
        }
@@ -188,17 +181,17 @@ static unsigned long convert_eip_to_linear(struct task_struct *child, struct pt_
        return addr;
 }
 
-static inline int is_at_popf(struct task_struct *child, struct pt_regs *regs)
+static inline int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
 {
        int i, copied;
-       unsigned char opcode[16];
+       unsigned char opcode[15];
        unsigned long addr = convert_eip_to_linear(child, regs);
 
        copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
        for (i = 0; i < copied; i++) {
                switch (opcode[i]) {
-               /* popf */
-               case 0x9d:
+               /* popf and iret */
+               case 0x9d: case 0xcf:
                        return 1;
                /* opcode and address size prefixes */
                case 0x66: case 0x67:
@@ -250,7 +243,7 @@ void tracehook_enable_single_step(struct task_struct *child)
         * don't mark it as being "us" that set it, so that we
         * won't clear it by hand later.
         */
-       if (is_at_popf(child, regs))
+       if (is_setting_trap_flag(child, regs))
                return;
        
        set_tsk_thread_flag(child, TIF_FORCED_TF);
@@ -540,7 +533,7 @@ dbregs_set(struct task_struct *target,
                else
                        clear_tsk_thread_flag(target, TIF_DEBUG);
 
-       set:
+set:
                target->thread.debugreg[pos] = val;
                if (target == current)
                        switch (pos) {
@@ -726,22 +719,22 @@ static const struct utrace_regset native_regsets[] = {
 
 const struct utrace_regset_view utrace_i386_native = {
        .name = "i386", .e_machine = EM_386,
-       .regsets = native_regsets,
-       .n = sizeof native_regsets / sizeof native_regsets[0],
+       .regsets = native_regsets, .n = ARRAY_SIZE(native_regsets)
 };
 EXPORT_SYMBOL_GPL(utrace_i386_native);
 
 #ifdef CONFIG_PTRACE
 static const struct ptrace_layout_segment i386_uarea[] = {
        {0, FRAME_SIZE*4, 0, 0},
+       {FRAME_SIZE*4, offsetof(struct user, u_debugreg[0]), -1, 0},
        {offsetof(struct user, u_debugreg[0]),
         offsetof(struct user, u_debugreg[8]), 4, 0},
        {0, 0, -1, 0}
 };
 
-fastcall int arch_ptrace(long *req, struct task_struct *child,
-                        struct utrace_attached_engine *engine,
-                        unsigned long addr, unsigned long data, long *val)
+int arch_ptrace(long *req, struct task_struct *child,
+               struct utrace_attached_engine *engine,
+               unsigned long addr, unsigned long data, long *val)
 {
        switch (*req) {
        case PTRACE_PEEKUSR: