[MIPS] use compat_siginfo in rt_sigframe_n32
[sfrench/cifs-2.6.git] / arch / mips / kernel / signal32.c
index 151fd2f0893ab7e1c2e2f94f91964d74cdfb1ba7..486b8e5f52d0b5e3f21e17b82f5a70f5cb3a3c17 100644 (file)
@@ -12,7 +12,6 @@
 #include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/smp.h>
-#include <linux/smp_lock.h>
 #include <linux/kernel.h>
 #include <linux/signal.h>
 #include <linux/syscalls.h>
@@ -22,6 +21,7 @@
 #include <linux/compat.h>
 #include <linux/suspend.h>
 #include <linux/compiler.h>
+#include <linux/uaccess.h>
 
 #include <asm/abi.h>
 #include <asm/asm.h>
@@ -29,7 +29,6 @@
 #include <linux/bitops.h>
 #include <asm/cacheflush.h>
 #include <asm/sim.h>
-#include <asm/uaccess.h>
 #include <asm/ucontext.h>
 #include <asm/system.h>
 #include <asm/fpu.h>
 
 #include "signal-common.h"
 
-#define SI_PAD_SIZE32   ((SI_MAX_SIZE/sizeof(int)) - 3)
-
-typedef struct compat_siginfo {
-       int si_signo;
-       int si_code;
-       int si_errno;
-
-       union {
-               int _pad[SI_PAD_SIZE32];
-
-               /* kill() */
-               struct {
-                       compat_pid_t _pid;      /* sender's pid */
-                       compat_uid_t _uid;      /* sender's uid */
-               } _kill;
-
-               /* SIGCHLD */
-               struct {
-                       compat_pid_t _pid;      /* which child */
-                       compat_uid_t _uid;      /* sender's uid */
-                       int _status;            /* exit code */
-                       compat_clock_t _utime;
-                       compat_clock_t _stime;
-               } _sigchld;
-
-               /* IRIX SIGCHLD */
-               struct {
-                       compat_pid_t _pid;      /* which child */
-                       compat_clock_t _utime;
-                       int _status;            /* exit code */
-                       compat_clock_t _stime;
-               } _irix_sigchld;
-
-               /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */
-               struct {
-                       s32 _addr; /* faulting insn/memory ref. */
-               } _sigfault;
-
-               /* SIGPOLL, SIGXFSZ (To do ...)  */
-               struct {
-                       int _band;      /* POLL_IN, POLL_OUT, POLL_MSG */
-                       int _fd;
-               } _sigpoll;
-
-               /* POSIX.1b timers */
-               struct {
-                       timer_t _tid;           /* timer id */
-                       int _overrun;           /* overrun count */
-                       compat_sigval_t _sigval;/* same as below */
-                       int _sys_private;       /* not to be passed to user */
-               } _timer;
-
-               /* POSIX.1b signals */
-               struct {
-                       compat_pid_t _pid;      /* sender's pid */
-                       compat_uid_t _uid;      /* sender's uid */
-                       compat_sigval_t _sigval;
-               } _rt;
-
-       } _sifields;
-} compat_siginfo_t;
-
 /*
  * Including <asm/unistd.h> would give use the 64-bit syscall numbers ...
  */
@@ -176,6 +113,46 @@ struct rt_sigframe32 {
 /*
  * sigcontext handlers
  */
+static int protected_save_fp_context32(struct sigcontext32 __user *sc)
+{
+       int err;
+       while (1) {
+               lock_fpu_owner();
+               own_fpu_inatomic(1);
+               err = save_fp_context32(sc); /* this might fail */
+               unlock_fpu_owner();
+               if (likely(!err))
+                       break;
+               /* touch the sigcontext and try again */
+               err = __put_user(0, &sc->sc_fpregs[0]) |
+                       __put_user(0, &sc->sc_fpregs[31]) |
+                       __put_user(0, &sc->sc_fpc_csr);
+               if (err)
+                       break;  /* really bad sigcontext */
+       }
+       return err;
+}
+
+static int protected_restore_fp_context32(struct sigcontext32 __user *sc)
+{
+       int err, tmp;
+       while (1) {
+               lock_fpu_owner();
+               own_fpu_inatomic(0);
+               err = restore_fp_context32(sc); /* this might fail */
+               unlock_fpu_owner();
+               if (likely(!err))
+                       break;
+               /* touch the sigcontext and try again */
+               err = __get_user(tmp, &sc->sc_fpregs[0]) |
+                       __get_user(tmp, &sc->sc_fpregs[31]) |
+                       __get_user(tmp, &sc->sc_fpc_csr);
+               if (err)
+                       break;  /* really bad sigcontext */
+       }
+       return err;
+}
+
 static int setup_sigcontext32(struct pt_regs *regs,
                              struct sigcontext32 __user *sc)
 {
@@ -209,10 +186,7 @@ static int setup_sigcontext32(struct pt_regs *regs,
                 * Save FPU state to signal context.  Signal handler
                 * will "inherit" current FPU state.
                 */
-               own_fpu(1);
-               enable_fp_in_kernel();
-               err |= save_fp_context32(sc);
-               disable_fp_in_kernel();
+               err |= protected_save_fp_context32(sc);
        }
        return err;
 }
@@ -225,7 +199,7 @@ check_and_restore_fp_context32(struct sigcontext32 __user *sc)
        err = sig = fpcsr_pending(&sc->sc_fpc_csr);
        if (err > 0)
                err = 0;
-       err |= restore_fp_context32(sc);
+       err |= protected_restore_fp_context32(sc);
        return err ?: sig;
 }
 
@@ -261,11 +235,8 @@ static int restore_sigcontext32(struct pt_regs *regs,
 
        if (used_math) {
                /* restore fpu context if we have used it before */
-               own_fpu(0);
-               enable_fp_in_kernel();
                if (!err)
                        err = check_and_restore_fp_context32(sc);
-               disable_fp_in_kernel();
        } else {
                /* signal handler may have used FPU.  Give it up. */
                lose_fpu(0);