Merge branch 'x86-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[safe/jmp/linux-2.6] / arch / x86 / math-emu / fpu_entry.c
index cbb8717..5d87f58 100644 (file)
  +---------------------------------------------------------------------------*/
 
 #include <linux/signal.h>
-#include <linux/ptrace.h>
+#include <linux/regset.h>
 
 #include <asm/uaccess.h>
 #include <asm/desc.h>
+#include <asm/user.h>
+#include <asm/i387.h>
 
 #include "fpu_system.h"
 #include "fpu_emu.h"
@@ -126,10 +128,10 @@ static u_char const type_table[64] = {
 u_char emulating = 0;
 #endif /* RE_ENTRANT_CHECKING */
 
-static int valid_prefix(u_char * Byte, u_char __user ** fpu_eip,
+static int valid_prefix(u_char *Byte, u_char __user ** fpu_eip,
                        overrides * override);
 
-asmlinkage void math_emulate(long arg)
+void math_emulate(struct math_emu_info *info)
 {
        u_char FPU_modrm, byte1;
        unsigned short code;
@@ -145,6 +147,13 @@ asmlinkage void math_emulate(long arg)
        unsigned long code_limit = 0;   /* Initialized to stop compiler warnings */
        struct desc_struct code_descriptor;
 
+       if (!used_math()) {
+               if (init_fpu(current)) {
+                       do_group_exit(SIGKILL);
+                       return;
+               }
+       }
+
 #ifdef RE_ENTRANT_CHECKING
        if (emulating) {
                printk("ERROR: wm-FPU-emu is not RE-ENTRANT!\n");
@@ -152,12 +161,7 @@ asmlinkage void math_emulate(long arg)
        RE_ENTRANT_CHECK_ON;
 #endif /* RE_ENTRANT_CHECKING */
 
-       if (!used_math()) {
-               finit();
-               set_used_math();
-       }
-
-       SETUP_DATA_AREA(arg);
+       FPU_info = info;
 
        FPU_ORIG_EIP = FPU_EIP;
 
@@ -198,9 +202,7 @@ asmlinkage void math_emulate(long arg)
                        code_limit = 0xffffffff;
        }
 
-       FPU_lookahead = 1;
-       if (current->ptrace & PT_PTRACED)
-               FPU_lookahead = 0;
+       FPU_lookahead = !(FPU_EFLAGS & X86_EFLAGS_TF);
 
        if (!valid_prefix(&byte1, (u_char __user **) & FPU_EIP,
                          &addr_modes.override)) {
@@ -277,6 +279,7 @@ asmlinkage void math_emulate(long arg)
        entry_sel_off.offset = FPU_ORIG_EIP;
        entry_sel_off.selector = FPU_CS;
        entry_sel_off.opcode = (byte1 << 8) | FPU_modrm;
+       entry_sel_off.empty = 0;
 
        FPU_rm = FPU_modrm & 7;
 
@@ -580,7 +583,7 @@ asmlinkage void math_emulate(long arg)
    all prefix bytes, further changes are needed in the emulator code
    which accesses user address space. Access to separate segments is
    important for msdos emulation. */
-static int valid_prefix(u_char * Byte, u_char __user ** fpu_eip,
+static int valid_prefix(u_char *Byte, u_char __user **fpu_eip,
                        overrides * override)
 {
        u_char byte;
@@ -656,7 +659,7 @@ static int valid_prefix(u_char * Byte, u_char __user ** fpu_eip,
        }
 }
 
-void math_abort(struct info *info, unsigned int signal)
+void math_abort(struct math_emu_info *info, unsigned int signal)
 {
        FPU_EIP = FPU_ORIG_EIP;
        current->thread.trap_no = 16;
@@ -673,31 +676,37 @@ void math_abort(struct info *info, unsigned int signal)
 #define sstatus_word() \
   ((S387->swd & ~SW_Top & 0xffff) | ((S387->ftop << SW_Top_Shift) & SW_Top))
 
-int restore_i387_soft(void *s387, struct _fpstate __user * buf)
+int fpregs_soft_set(struct task_struct *target,
+                   const struct user_regset *regset,
+                   unsigned int pos, unsigned int count,
+                   const void *kbuf, const void __user *ubuf)
 {
-       u_char __user *d = (u_char __user *) buf;
+       struct i387_soft_struct *s387 = &target->thread.xstate->soft;
+       void *space = s387->st_space;
+       int ret;
        int offset, other, i, tags, regnr, tag, newtop;
 
        RE_ENTRANT_CHECK_OFF;
-       FPU_access_ok(VERIFY_READ, d, 7 * 4 + 8 * 10);
-       if (__copy_from_user(&S387->cwd, d, 7 * 4))
-               return -1;
+       ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, s387, 0,
+                                offsetof(struct i387_soft_struct, st_space));
        RE_ENTRANT_CHECK_ON;
 
-       d += 7 * 4;
+       if (ret)
+               return ret;
 
        S387->ftop = (S387->swd >> SW_Top_Shift) & 7;
        offset = (S387->ftop & 7) * 10;
        other = 80 - offset;
 
        RE_ENTRANT_CHECK_OFF;
+
        /* Copy all registers in stack order. */
-       if (__copy_from_user(((u_char *) & S387->st_space) + offset, d, other))
-               return -1;
-       if (offset)
-               if (__copy_from_user
-                   ((u_char *) & S387->st_space, d + other, offset))
-                       return -1;
+       ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
+                                space + offset, 0, other);
+       if (!ret && offset)
+               ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
+                                        space, 0, offset);
+
        RE_ENTRANT_CHECK_ON;
 
        /* The tags may need to be corrected now. */
@@ -716,16 +725,21 @@ int restore_i387_soft(void *s387, struct _fpstate __user * buf)
        }
        S387->twd = tags;
 
-       return 0;
+       return ret;
 }
 
-int save_i387_soft(void *s387, struct _fpstate __user * buf)
+int fpregs_soft_get(struct task_struct *target,
+                   const struct user_regset *regset,
+                   unsigned int pos, unsigned int count,
+                   void *kbuf, void __user *ubuf)
 {
-       u_char __user *d = (u_char __user *) buf;
+       struct i387_soft_struct *s387 = &target->thread.xstate->soft;
+       const void *space = s387->st_space;
+       int ret;
        int offset = (S387->ftop & 7) * 10, other = 80 - offset;
 
        RE_ENTRANT_CHECK_OFF;
-       FPU_access_ok(VERIFY_WRITE, d, 7 * 4 + 8 * 10);
+
 #ifdef PECULIAR_486
        S387->cwd &= ~0xe080;
        /* An 80486 sets nearly all of the reserved bits to 1. */
@@ -735,21 +749,19 @@ int save_i387_soft(void *s387, struct _fpstate __user * buf)
        S387->fcs &= ~0xf8000000;
        S387->fos |= 0xffff0000;
 #endif /* PECULIAR_486 */
-       if (__copy_to_user(d, &S387->cwd, 7 * 4))
-               return -1;
-       RE_ENTRANT_CHECK_ON;
 
-       d += 7 * 4;
+       ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, s387, 0,
+                                 offsetof(struct i387_soft_struct, st_space));
 
-       RE_ENTRANT_CHECK_OFF;
        /* Copy all registers in stack order. */
-       if (__copy_to_user(d, ((u_char *) & S387->st_space) + offset, other))
-               return -1;
-       if (offset)
-               if (__copy_to_user
-                   (d + other, (u_char *) & S387->st_space, offset))
-                       return -1;
+       if (!ret)
+               ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+                                         space + offset, 0, other);
+       if (!ret)
+               ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
+                                         space, 0, offset);
+
        RE_ENTRANT_CHECK_ON;
 
-       return 1;
+       return ret;
 }