x86: i8259: cleanup codingstyle
[safe/jmp/linux-2.6] / arch / x86 / kernel / ptrace.c
index 196cc27..a7835f2 100644 (file)
@@ -103,9 +103,26 @@ static int set_segment_reg(struct task_struct *task,
        if (invalid_selector(value))
                return -EIO;
 
-       if (offset != offsetof(struct user_regs_struct, gs))
+       /*
+        * For %cs and %ss we cannot permit a null selector.
+        * We can permit a bogus selector as long as it has USER_RPL.
+        * Null selectors are fine for other segment registers, but
+        * we will never get back to user mode with invalid %cs or %ss
+        * and will take the trap in iret instead.  Much code relies
+        * on user_mode() to distinguish a user trap frame (which can
+        * safely use invalid selectors) from a kernel trap frame.
+        */
+       switch (offset) {
+       case offsetof(struct user_regs_struct, cs):
+       case offsetof(struct user_regs_struct, ss):
+               if (unlikely(value == 0))
+                       return -EIO;
+
+       default:
                *pt_regs_access(task_pt_regs(task), offset) = value;
-       else {
+               break;
+
+       case offsetof(struct user_regs_struct, gs):
                task->thread.gs = value;
                if (task == current)
                        /*
@@ -227,12 +244,16 @@ static int set_segment_reg(struct task_struct *task,
                 * Can't actually change these in 64-bit mode.
                 */
        case offsetof(struct user_regs_struct,cs):
+               if (unlikely(value == 0))
+                       return -EIO;
 #ifdef CONFIG_IA32_EMULATION
                if (test_tsk_thread_flag(task, TIF_IA32))
                        task_pt_regs(task)->cs = value;
 #endif
                break;
        case offsetof(struct user_regs_struct,ss):
+               if (unlikely(value == 0))
+                       return -EIO;
 #ifdef CONFIG_IA32_EMULATION
                if (test_tsk_thread_flag(task, TIF_IA32))
                        task_pt_regs(task)->ss = value;
@@ -302,6 +323,16 @@ static int putreg(struct task_struct *child,
                return set_flags(child, value);
 
 #ifdef CONFIG_X86_64
+       /*
+        * Orig_ax is really just a flag with small positive and
+        * negative values, so make sure to always sign-extend it
+        * from 32 bits so that it works correctly regardless of
+        * whether we come from a 32-bit environment or not.
+        */
+       case offsetof(struct user_regs_struct, orig_ax):
+               value = (long) (s32) value;
+               break;
+
        case offsetof(struct user_regs_struct,fs_base):
                if (value >= TASK_SIZE_OF(child))
                        return -EIO;
@@ -523,6 +554,8 @@ static int ptrace_set_debugreg(struct task_struct *child,
        return 0;
 }
 
+#ifdef X86_BTS
+
 static int ptrace_bts_get_size(struct task_struct *child)
 {
        if (!child->thread.ds_area_msr)
@@ -558,7 +591,7 @@ static int ptrace_bts_read_record(struct task_struct *child,
 
        retval = ds_read_bts((void *)child->thread.ds_area_msr,
                             bts_index, &ret);
-       if (retval)
+       if (retval < 0)
                return retval;
 
        if (copy_to_user(out, &ret, sizeof(ret)))
@@ -567,21 +600,6 @@ static int ptrace_bts_read_record(struct task_struct *child,
        return sizeof(ret);
 }
 
-static int ptrace_bts_write_record(struct task_struct *child,
-                                  const struct bts_struct *in)
-{
-       int retval;
-
-       if (!child->thread.ds_area_msr)
-               return -ENXIO;
-
-       retval = ds_write_bts((void *)child->thread.ds_area_msr, in);
-       if (retval)
-               return retval;
-
-       return sizeof(*in);
-}
-
 static int ptrace_bts_clear(struct task_struct *child)
 {
        if (!child->thread.ds_area_msr)
@@ -591,6 +609,7 @@ static int ptrace_bts_clear(struct task_struct *child)
 }
 
 static int ptrace_bts_drain(struct task_struct *child,
+                           long size,
                            struct bts_struct __user *out)
 {
        int end, i;
@@ -603,6 +622,9 @@ static int ptrace_bts_drain(struct task_struct *child,
        if (end <= 0)
                return end;
 
+       if (size < (end * sizeof(struct bts_struct)))
+               return -EIO;
+
        for (i = 0; i < end; i++, out++) {
                struct bts_struct ret;
                int retval;
@@ -617,20 +639,26 @@ static int ptrace_bts_drain(struct task_struct *child,
 
        ds_clear(ds);
 
-       return i;
+       return end;
 }
 
 static int ptrace_bts_config(struct task_struct *child,
+                            long cfg_size,
                             const struct ptrace_bts_config __user *ucfg)
 {
        struct ptrace_bts_config cfg;
-       unsigned long debugctl_mask;
-       int bts_size, ret;
+       int bts_size, ret = 0;
        void *ds;
 
+       if (cfg_size < sizeof(cfg))
+               return -EIO;
+
        if (copy_from_user(&cfg, ucfg, sizeof(cfg)))
                return -EFAULT;
 
+       if ((int)cfg.size < 0)
+               return -EINVAL;
+
        bts_size = 0;
        ds = (void *)child->thread.ds_area_msr;
        if (ds) {
@@ -638,67 +666,60 @@ static int ptrace_bts_config(struct task_struct *child,
                if (bts_size < 0)
                        return bts_size;
        }
+       cfg.size = PAGE_ALIGN(cfg.size);
 
        if (bts_size != cfg.size) {
-               ret = ds_free((void **)&child->thread.ds_area_msr);
+               ret = ptrace_bts_realloc(child, cfg.size,
+                                        cfg.flags & PTRACE_BTS_O_CUT_SIZE);
                if (ret < 0)
-                       return ret;
+                       goto errout;
 
-               if (cfg.size > 0)
-                       ret = ds_allocate((void **)&child->thread.ds_area_msr,
-                                         cfg.size);
                ds = (void *)child->thread.ds_area_msr;
-               if (ds)
-                       set_tsk_thread_flag(child, TIF_DS_AREA_MSR);
-               else
-                       clear_tsk_thread_flag(child, TIF_DS_AREA_MSR);
-
-               if (ret < 0)
-                       return ret;
-
-               bts_size = ds_get_bts_size(ds);
-               if (bts_size <= 0)
-                       return bts_size;
        }
 
-       if (ds) {
-               if (cfg.flags & PTRACE_BTS_O_SIGNAL) {
-                       ret = ds_set_overflow(ds, DS_O_SIGNAL);
-               } else {
-                       ret = ds_set_overflow(ds, DS_O_WRAP);
-               }
-               if (ret < 0)
-                       return ret;
-       }
-
-       debugctl_mask = ds_debugctl_mask();
-       if (ds && (cfg.flags & PTRACE_BTS_O_TRACE)) {
-               child->thread.debugctlmsr |= debugctl_mask;
-               set_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
-       } else {
-               /* there is no way for us to check whether we 'own'
-                * the respective bits in the DEBUGCTL MSR, we're
-                * about to clear */
-               child->thread.debugctlmsr &= ~debugctl_mask;
+       if (cfg.flags & PTRACE_BTS_O_SIGNAL)
+               ret = ds_set_overflow(ds, DS_O_SIGNAL);
+       else
+               ret = ds_set_overflow(ds, DS_O_WRAP);
+       if (ret < 0)
+               goto errout;
 
-               if (!child->thread.debugctlmsr)
-                       clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
-       }
+       if (cfg.flags & PTRACE_BTS_O_TRACE)
+               child->thread.debugctlmsr |= ds_debugctl_mask();
+       else
+               child->thread.debugctlmsr &= ~ds_debugctl_mask();
 
-       if (ds && (cfg.flags & PTRACE_BTS_O_SCHED))
+       if (cfg.flags & PTRACE_BTS_O_SCHED)
                set_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
        else
                clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
 
-       return 0;
+       ret = sizeof(cfg);
+
+out:
+       if (child->thread.debugctlmsr)
+               set_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
+       else
+               clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
+
+       return ret;
+
+errout:
+       child->thread.debugctlmsr &= ~ds_debugctl_mask();
+       clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
+       goto out;
 }
 
 static int ptrace_bts_status(struct task_struct *child,
+                            long cfg_size,
                             struct ptrace_bts_config __user *ucfg)
 {
        void *ds = (void *)child->thread.ds_area_msr;
        struct ptrace_bts_config cfg;
 
+       if (cfg_size < sizeof(cfg))
+               return -EIO;
+
        memset(&cfg, 0, sizeof(cfg));
 
        if (ds) {
@@ -715,22 +736,110 @@ static int ptrace_bts_status(struct task_struct *child,
                        cfg.flags |= PTRACE_BTS_O_SCHED;
        }
 
+       cfg.bts_size = sizeof(struct bts_struct);
+
        if (copy_to_user(ucfg, &cfg, sizeof(cfg)))
                return -EFAULT;
 
        return sizeof(cfg);
 }
 
+
+static int ptrace_bts_write_record(struct task_struct *child,
+                                  const struct bts_struct *in)
+{
+       int retval;
+
+       if (!child->thread.ds_area_msr)
+               return -ENXIO;
+
+       retval = ds_write_bts((void *)child->thread.ds_area_msr, in);
+       if (retval)
+               return retval;
+
+       return sizeof(*in);
+}
+
+static int ptrace_bts_realloc(struct task_struct *child,
+                             int size, int reduce_size)
+{
+       unsigned long rlim, vm;
+       int ret, old_size;
+
+       if (size < 0)
+               return -EINVAL;
+
+       old_size = ds_get_bts_size((void *)child->thread.ds_area_msr);
+       if (old_size < 0)
+               return old_size;
+
+       ret = ds_free((void **)&child->thread.ds_area_msr);
+       if (ret < 0)
+               goto out;
+
+       size >>= PAGE_SHIFT;
+       old_size >>= PAGE_SHIFT;
+
+       current->mm->total_vm  -= old_size;
+       current->mm->locked_vm -= old_size;
+
+       if (size == 0)
+               goto out;
+
+       rlim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
+       vm = current->mm->total_vm  + size;
+       if (rlim < vm) {
+               ret = -ENOMEM;
+
+               if (!reduce_size)
+                       goto out;
+
+               size = rlim - current->mm->total_vm;
+               if (size <= 0)
+                       goto out;
+       }
+
+       rlim = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
+       vm = current->mm->locked_vm  + size;
+       if (rlim < vm) {
+               ret = -ENOMEM;
+
+               if (!reduce_size)
+                       goto out;
+
+               size = rlim - current->mm->locked_vm;
+               if (size <= 0)
+                       goto out;
+       }
+
+       ret = ds_allocate((void **)&child->thread.ds_area_msr,
+                         size << PAGE_SHIFT);
+       if (ret < 0)
+               goto out;
+
+       current->mm->total_vm  += size;
+       current->mm->locked_vm += size;
+
+out:
+       if (child->thread.ds_area_msr)
+               set_tsk_thread_flag(child, TIF_DS_AREA_MSR);
+       else
+               clear_tsk_thread_flag(child, TIF_DS_AREA_MSR);
+
+       return ret;
+}
+
 void ptrace_bts_take_timestamp(struct task_struct *tsk,
                               enum bts_qualifier qualifier)
 {
        struct bts_struct rec = {
                .qualifier = qualifier,
-               .variant.jiffies = jiffies
+               .variant.jiffies = jiffies_64
        };
 
        ptrace_bts_write_record(tsk, &rec);
 }
+#endif /* X86_BTS */
 
 /*
  * Called by kernel/ptrace.c when detaching..
@@ -743,25 +852,27 @@ void ptrace_disable(struct task_struct *child)
 #ifdef TIF_SYSCALL_EMU
        clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
 #endif
-       ptrace_bts_config(child, /* options = */ 0);
        if (child->thread.ds_area_msr) {
-           ds_free((void **)&child->thread.ds_area_msr);
-           clear_tsk_thread_flag(child, TIF_DS_AREA_MSR);
+#ifdef X86_BTS
+               ptrace_bts_realloc(child, 0, 0);
+#endif
+               child->thread.debugctlmsr &= ~ds_debugctl_mask();
+               if (!child->thread.debugctlmsr)
+                       clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
+               clear_tsk_thread_flag(child, TIF_BTS_TRACE_TS);
        }
 }
 
+#if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
+static const struct user_regset_view user_x86_32_view; /* Initialized below. */
+#endif
+
 long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 {
-       int i, ret;
+       int ret;
        unsigned long __user *datap = (unsigned long __user *)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:
-               ret = generic_ptrace_peekdata(child, addr, data);
-               break;
-
        /* read the word at location addr in the USER area. */
        case PTRACE_PEEKUSR: {
                unsigned long tmp;
@@ -783,12 +894,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                break;
        }
 
-       /* when I and D space are separate, this will have to be fixed. */
-       case PTRACE_POKETEXT: /* write the word at location addr. */
-       case PTRACE_POKEDATA:
-               ret = generic_ptrace_pokedata(child, addr, data);
-               break;
-
        case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
                ret = -EIO;
                if ((addr & (sizeof(data) - 1)) || addr < 0 ||
@@ -805,82 +910,46 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                }
                break;
 
-       case PTRACE_GETREGS: { /* Get all gp regs from the child. */
-               if (!access_ok(VERIFY_WRITE, datap, sizeof(struct user_regs_struct))) {
-                       ret = -EIO;
-                       break;
-               }
-               for (i = 0; i < sizeof(struct user_regs_struct); i += sizeof(long)) {
-                       __put_user(getreg(child, i), datap);
-                       datap++;
-               }
-               ret = 0;
-               break;
-       }
-
-       case PTRACE_SETREGS: { /* Set all gp regs in the child. */
-               unsigned long tmp;
-               if (!access_ok(VERIFY_READ, datap, sizeof(struct user_regs_struct))) {
-                       ret = -EIO;
-                       break;
-               }
-               for (i = 0; i < sizeof(struct user_regs_struct); i += sizeof(long)) {
-                       __get_user(tmp, datap);
-                       putreg(child, i, tmp);
-                       datap++;
-               }
-               ret = 0;
-               break;
-       }
-
-       case PTRACE_GETFPREGS: { /* Get the child FPU state. */
-               if (!access_ok(VERIFY_WRITE, datap,
-                              sizeof(struct user_i387_struct))) {
-                       ret = -EIO;
-                       break;
-               }
-               ret = 0;
-               if (!tsk_used_math(child))
-                       init_fpu(child);
-               get_fpregs((struct user_i387_struct __user *)data, child);
-               break;
-       }
-
-       case PTRACE_SETFPREGS: { /* Set the child FPU state. */
-               if (!access_ok(VERIFY_READ, datap,
-                              sizeof(struct user_i387_struct))) {
-                       ret = -EIO;
-                       break;
-               }
-               set_stopped_child_used_math(child);
-               set_fpregs(child, (struct user_i387_struct __user *)data);
-               ret = 0;
-               break;
-       }
+       case PTRACE_GETREGS:    /* Get all gp regs from the child. */
+               return copy_regset_to_user(child,
+                                          task_user_regset_view(current),
+                                          REGSET_GENERAL,
+                                          0, sizeof(struct user_regs_struct),
+                                          datap);
+
+       case PTRACE_SETREGS:    /* Set all gp regs in the child. */
+               return copy_regset_from_user(child,
+                                            task_user_regset_view(current),
+                                            REGSET_GENERAL,
+                                            0, sizeof(struct user_regs_struct),
+                                            datap);
+
+       case PTRACE_GETFPREGS:  /* Get the child FPU state. */
+               return copy_regset_to_user(child,
+                                          task_user_regset_view(current),
+                                          REGSET_FP,
+                                          0, sizeof(struct user_i387_struct),
+                                          datap);
+
+       case PTRACE_SETFPREGS:  /* Set the child FPU state. */
+               return copy_regset_from_user(child,
+                                            task_user_regset_view(current),
+                                            REGSET_FP,
+                                            0, sizeof(struct user_i387_struct),
+                                            datap);
 
 #ifdef CONFIG_X86_32
-       case PTRACE_GETFPXREGS: { /* Get the child extended FPU state. */
-               if (!access_ok(VERIFY_WRITE, datap,
-                              sizeof(struct user_fxsr_struct))) {
-                       ret = -EIO;
-                       break;
-               }
-               if (!tsk_used_math(child))
-                       init_fpu(child);
-               ret = get_fpxregs((struct user_fxsr_struct __user *)data, child);
-               break;
-       }
-
-       case PTRACE_SETFPXREGS: { /* Set the child extended FPU state. */
-               if (!access_ok(VERIFY_READ, datap,
-                              sizeof(struct user_fxsr_struct))) {
-                       ret = -EIO;
-                       break;
-               }
-               set_stopped_child_used_math(child);
-               ret = set_fpxregs(child, (struct user_fxsr_struct __user *)data);
-               break;
-       }
+       case PTRACE_GETFPXREGS: /* Get the child extended FPU state. */
+               return copy_regset_to_user(child, &user_x86_32_view,
+                                          REGSET_XFP,
+                                          0, sizeof(struct user_fxsr_struct),
+                                          datap);
+
+       case PTRACE_SETFPXREGS: /* Set the child extended FPU state. */
+               return copy_regset_from_user(child, &user_x86_32_view,
+                                            REGSET_XFP,
+                                            0, sizeof(struct user_fxsr_struct),
+                                            datap);
 #endif
 
 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
@@ -908,14 +977,18 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                break;
 #endif
 
+       /*
+        * These bits need more cooking - not enabled yet:
+        */
+#ifdef X86_BTS
        case PTRACE_BTS_CONFIG:
                ret = ptrace_bts_config
-                       (child, (struct ptrace_bts_config __user *)addr);
+                       (child, data, (struct ptrace_bts_config __user *)addr);
                break;
 
        case PTRACE_BTS_STATUS:
                ret = ptrace_bts_status
-                       (child, (struct ptrace_bts_config __user *)addr);
+                       (child, data, (struct ptrace_bts_config __user *)addr);
                break;
 
        case PTRACE_BTS_SIZE:
@@ -933,8 +1006,9 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
 
        case PTRACE_BTS_DRAIN:
                ret = ptrace_bts_drain
-                       (child, (struct bts_struct __user *) addr);
+                       (child, data, (struct bts_struct __user *) addr);
                break;
+#endif
 
        default:
                ret = ptrace_request(child, request, addr, data);
@@ -982,10 +1056,17 @@ static int putreg32(struct task_struct *child, unsigned regno, u32 value)
        R32(esi, si);
        R32(ebp, bp);
        R32(eax, ax);
-       R32(orig_eax, orig_ax);
        R32(eip, ip);
        R32(esp, sp);
 
+       case offsetof(struct user32, regs.orig_eax):
+               /*
+                * Sign-extend the value so that orig_eax = -1
+                * causes (long)orig_ax < 0 tests to fire correctly.
+                */
+               regs->orig_ax = (long) (s32) value;
+               break;
+
        case offsetof(struct user32, regs.eflags):
                return set_flags(child, value);
 
@@ -1107,7 +1188,7 @@ static int genregs32_set(struct task_struct *target,
        if (kbuf) {
                const compat_ulong_t *k = kbuf;
                while (count > 0 && !ret) {
-                       ret = putreg(target, pos, *k++);
+                       ret = putreg32(target, pos, *k++);
                        count -= sizeof(*k);
                        pos += sizeof(*k);
                }
@@ -1118,7 +1199,7 @@ static int genregs32_set(struct task_struct *target,
                        ret = __get_user(word, u++);
                        if (ret)
                                break;
-                       ret = putreg(target, pos, word);
+                       ret = putreg32(target, pos, word);
                        count -= sizeof(*u);
                        pos += sizeof(*u);
                }
@@ -1126,113 +1207,16 @@ static int genregs32_set(struct task_struct *target,
        return ret;
 }
 
-static long ptrace32_siginfo(unsigned request, u32 pid, u32 addr, u32 data)
-{
-       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) {
-               memset(&ssi, 0, sizeof(siginfo_t));
-               ret = copy_siginfo_from_user32(&ssi, si32);
-               if (ret)
-                       return ret;
-               if (copy_to_user(si, &ssi, sizeof(siginfo_t)))
-                       return -EFAULT;
-       }
-       ret = sys_ptrace(request, pid, addr, (unsigned long)si);
-       if (ret)
-               return ret;
-       if (request == PTRACE_GETSIGINFO) {
-               if (copy_from_user(&ssi, si, sizeof(siginfo_t)))
-                       return -EFAULT;
-               ret = copy_siginfo_to_user32(si32, &ssi);
-       }
-       return ret;
-}
-
-asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
+long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
+                       compat_ulong_t caddr, compat_ulong_t cdata)
 {
-       struct task_struct *child;
-       struct pt_regs *childregs;
+       unsigned long addr = caddr;
+       unsigned long data = cdata;
        void __user *datap = compat_ptr(data);
        int ret;
        __u32 val;
 
        switch (request) {
-       case PTRACE_TRACEME:
-       case PTRACE_ATTACH:
-       case PTRACE_KILL:
-       case PTRACE_CONT:
-       case PTRACE_SINGLESTEP:
-       case PTRACE_SINGLEBLOCK:
-       case PTRACE_DETACH:
-       case PTRACE_SYSCALL:
-       case PTRACE_OLDSETOPTIONS:
-       case PTRACE_SETOPTIONS:
-       case PTRACE_SET_THREAD_AREA:
-       case PTRACE_GET_THREAD_AREA:
-       case PTRACE_BTS_CONFIG:
-       case PTRACE_BTS_STATUS:
-       case PTRACE_BTS_SIZE:
-       case PTRACE_BTS_GET:
-       case PTRACE_BTS_CLEAR:
-       case PTRACE_BTS_DRAIN:
-               return sys_ptrace(request, pid, addr, data);
-
-       default:
-               return -EINVAL;
-
-       case PTRACE_PEEKTEXT:
-       case PTRACE_PEEKDATA:
-       case PTRACE_POKEDATA:
-       case PTRACE_POKETEXT:
-       case PTRACE_POKEUSR:
-       case PTRACE_PEEKUSR:
-       case PTRACE_GETREGS:
-       case PTRACE_SETREGS:
-       case PTRACE_SETFPREGS:
-       case PTRACE_GETFPREGS:
-       case PTRACE_SETFPXREGS:
-       case PTRACE_GETFPXREGS:
-       case PTRACE_GETEVENTMSG:
-               break;
-
-       case PTRACE_SETSIGINFO:
-       case PTRACE_GETSIGINFO:
-               return ptrace32_siginfo(request, pid, addr, data);
-       }
-
-       child = ptrace_get_task_struct(pid);
-       if (IS_ERR(child))
-               return PTR_ERR(child);
-
-       ret = ptrace_check_attach(child, request == PTRACE_KILL);
-       if (ret < 0)
-               goto out;
-
-       childregs = task_pt_regs(child);
-
-       switch (request) {
-       case PTRACE_PEEKDATA:
-       case PTRACE_PEEKTEXT:
-               ret = 0;
-               if (access_process_vm(child, addr, &val, sizeof(u32), 0) !=
-                   sizeof(u32))
-                       ret = -EIO;
-               else
-                       ret = put_user(val, (unsigned int __user *)datap);
-               break;
-
-       case PTRACE_POKEDATA:
-       case PTRACE_POKETEXT:
-               ret = 0;
-               if (access_process_vm(child, addr, &data, sizeof(u32), 1) !=
-                   sizeof(u32))
-                       ret = -EIO;
-               break;
-
        case PTRACE_PEEKUSR:
                ret = getreg32(child, addr, &val);
                if (ret == 0)
@@ -1243,102 +1227,49 @@ asmlinkage long sys32_ptrace(long request, u32 pid, u32 addr, u32 data)
                ret = putreg32(child, addr, data);
                break;
 
-       case PTRACE_GETREGS: { /* Get all gp regs from the child. */
-               int i;
-
-               if (!access_ok(VERIFY_WRITE, datap, 16*4)) {
-                       ret = -EIO;
-                       break;
-               }
-               ret = 0;
-               for (i = 0; i < sizeof(struct user_regs_struct32); i += sizeof(__u32)) {
-                       getreg32(child, i, &val);
-                       ret |= __put_user(val, (u32 __user *)datap);
-                       datap += sizeof(u32);
-               }
-               break;
-       }
-
-       case PTRACE_SETREGS: { /* Set all gp regs in the child. */
-               unsigned long tmp;
-               int i;
-
-               if (!access_ok(VERIFY_READ, datap, 16*4)) {
-                       ret = -EIO;
-                       break;
-               }
-               ret = 0;
-               for (i = 0; i < sizeof(struct user_regs_struct32); i += sizeof(u32)) {
-                       ret |= __get_user(tmp, (u32 __user *)datap);
-                       putreg32(child, i, tmp);
-                       datap += sizeof(u32);
-               }
-               break;
-       }
-
-       case PTRACE_GETFPREGS:
-               ret = -EIO;
-               if (!access_ok(VERIFY_READ, compat_ptr(data),
-                              sizeof(struct user_i387_struct)))
-                       break;
-               save_i387_ia32(child, datap, childregs, 1);
-               ret = 0;
-                       break;
-
-       case PTRACE_SETFPREGS:
-               ret = -EIO;
-               if (!access_ok(VERIFY_WRITE, datap,
-                              sizeof(struct user_i387_struct)))
-                       break;
-               ret = 0;
-               /* don't check EFAULT to be bug-to-bug compatible to i386 */
-               restore_i387_ia32(child, datap, 1);
-               break;
-
-       case PTRACE_GETFPXREGS: {
-               struct user32_fxsr_struct __user *u = datap;
-
-               init_fpu(child);
-               ret = -EIO;
-               if (!access_ok(VERIFY_WRITE, u, sizeof(*u)))
-                       break;
-                       ret = -EFAULT;
-               if (__copy_to_user(u, &child->thread.i387.fxsave, sizeof(*u)))
-                       break;
-               ret = __put_user(childregs->cs, &u->fcs);
-               ret |= __put_user(child->thread.ds, &u->fos);
-               break;
-       }
-       case PTRACE_SETFPXREGS: {
-               struct user32_fxsr_struct __user *u = datap;
-
-               unlazy_fpu(child);
-               ret = -EIO;
-               if (!access_ok(VERIFY_READ, u, sizeof(*u)))
-                       break;
-               /*
-                * no checking to be bug-to-bug compatible with i386.
-                * but silence warning
-                */
-               if (__copy_from_user(&child->thread.i387.fxsave, u, sizeof(*u)))
-                       ;
-               set_stopped_child_used_math(child);
-               child->thread.i387.fxsave.mxcsr &= mxcsr_feature_mask;
-               ret = 0;
-               break;
-       }
+       case PTRACE_GETREGS:    /* Get all gp regs from the child. */
+               return copy_regset_to_user(child, &user_x86_32_view,
+                                          REGSET_GENERAL,
+                                          0, sizeof(struct user_regs_struct32),
+                                          datap);
+
+       case PTRACE_SETREGS:    /* Set all gp regs in the child. */
+               return copy_regset_from_user(child, &user_x86_32_view,
+                                            REGSET_GENERAL, 0,
+                                            sizeof(struct user_regs_struct32),
+                                            datap);
+
+       case PTRACE_GETFPREGS:  /* Get the child FPU state. */
+               return copy_regset_to_user(child, &user_x86_32_view,
+                                          REGSET_FP, 0,
+                                          sizeof(struct user_i387_ia32_struct),
+                                          datap);
+
+       case PTRACE_SETFPREGS:  /* Set the child FPU state. */
+               return copy_regset_from_user(
+                       child, &user_x86_32_view, REGSET_FP,
+                       0, sizeof(struct user_i387_ia32_struct), datap);
+
+       case PTRACE_GETFPXREGS: /* Get the child extended FPU state. */
+               return copy_regset_to_user(child, &user_x86_32_view,
+                                          REGSET_XFP, 0,
+                                          sizeof(struct user32_fxsr_struct),
+                                          datap);
+
+       case PTRACE_SETFPXREGS: /* Set the child extended FPU state. */
+               return copy_regset_from_user(child, &user_x86_32_view,
+                                            REGSET_XFP, 0,
+                                            sizeof(struct user32_fxsr_struct),
+                                            datap);
 
-       case PTRACE_GETEVENTMSG:
-               ret = put_user(child->ptrace_message,
-                              (unsigned int __user *)compat_ptr(data));
-               break;
+       case PTRACE_GET_THREAD_AREA:
+       case PTRACE_SET_THREAD_AREA:
+               return arch_ptrace(child, request, addr, data);
 
        default:
-               BUG();
+               return compat_ptrace_request(child, request, addr, data);
        }
 
- out:
-       put_task_struct(child);
        return ret;
 }
 
@@ -1372,6 +1303,9 @@ static const struct user_regset_view user_x86_64_view = {
 #define genregs32_get          genregs_get
 #define genregs32_set          genregs_set
 
+#define user_i387_ia32_struct  user_i387_struct
+#define user32_fxsr_struct     user_fxsr_struct
+
 #endif /* CONFIG_X86_64 */
 
 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
@@ -1384,17 +1318,18 @@ static const struct user_regset x86_32_regsets[] = {
        },
        [REGSET_FP] = {
                .core_note_type = NT_PRFPREG,
-               .n = sizeof(struct user_i387_struct) / sizeof(u32),
+               .n = sizeof(struct user_i387_ia32_struct) / sizeof(u32),
                .size = sizeof(u32), .align = sizeof(u32),
                .active = fpregs_active, .get = fpregs_get, .set = fpregs_set
        },
        [REGSET_XFP] = {
                .core_note_type = NT_PRXFPREG,
-               .n = sizeof(struct user_i387_struct) / sizeof(u32),
+               .n = sizeof(struct user32_fxsr_struct) / sizeof(u32),
                .size = sizeof(u32), .align = sizeof(u32),
                .active = xfpregs_active, .get = xfpregs_get, .set = xfpregs_set
        },
        [REGSET_TLS] = {
+               .core_note_type = NT_386_TLS,
                .n = GDT_ENTRY_TLS_ENTRIES, .bias = GDT_ENTRY_TLS_MIN,
                .size = sizeof(struct user_desc),
                .align = sizeof(struct user_desc),
@@ -1445,7 +1380,6 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code)
 /* notification of system call entry/exit
  * - triggered by current->work.syscall_trace
  */
-__attribute__((regparm(3)))
 int do_syscall_trace(struct pt_regs *regs, int entryexit)
 {
        int is_sysemu = test_thread_flag(TIF_SYSCALL_EMU);