sh: convert /proc/cpu/aligmnent, /proc/cpu/kernel_alignment to seq_file
[safe/jmp/linux-2.6] / arch / mips / kernel / signal32.c
index 53a337c..2e74075 100644 (file)
 #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>
 #include <linux/errno.h>
 #include <linux/wait.h>
 #include <linux/ptrace.h>
-#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 +28,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 +112,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 +185,7 @@ static int setup_sigcontext32(struct pt_regs *regs,
                 * Save FPU state to signal context.  Signal handler
                 * will "inherit" current FPU state.
                 */
-               preempt_disable();
-               own_fpu(1);
-               err |= save_fp_context32(sc);
-               preempt_enable();
+               err |= protected_save_fp_context32(sc);
        }
        return err;
 }
@@ -225,10 +198,7 @@ check_and_restore_fp_context32(struct sigcontext32 __user *sc)
        err = sig = fpcsr_pending(&sc->sc_fpc_csr);
        if (err > 0)
                err = 0;
-       preempt_disable();
-       own_fpu(0);
-       err |= restore_fp_context32(sc);
-       preempt_enable();
+       err |= protected_restore_fp_context32(sc);
        return err ?: sig;
 }
 
@@ -291,11 +261,11 @@ static inline int put_sigset(const sigset_t *kbuf, compat_sigset_t __user *ubuf)
        default:
                __put_sigset_unknown_nsig();
        case 2:
-               err |= __put_user (kbuf->sig[1] >> 32, &ubuf->sig[3]);
-               err |= __put_user (kbuf->sig[1] & 0xffffffff, &ubuf->sig[2]);
+               err |= __put_user(kbuf->sig[1] >> 32, &ubuf->sig[3]);
+               err |= __put_user(kbuf->sig[1] & 0xffffffff, &ubuf->sig[2]);
        case 1:
-               err |= __put_user (kbuf->sig[0] >> 32, &ubuf->sig[1]);
-               err |= __put_user (kbuf->sig[0] & 0xffffffff, &ubuf->sig[0]);
+               err |= __put_user(kbuf->sig[0] >> 32, &ubuf->sig[1]);
+               err |= __put_user(kbuf->sig[0] & 0xffffffff, &ubuf->sig[0]);
        }
 
        return err;
@@ -313,12 +283,12 @@ static inline int get_sigset(sigset_t *kbuf, const compat_sigset_t __user *ubuf)
        default:
                __get_sigset_unknown_nsig();
        case 2:
-               err |= __get_user (sig[3], &ubuf->sig[3]);
-               err |= __get_user (sig[2], &ubuf->sig[2]);
+               err |= __get_user(sig[3], &ubuf->sig[3]);
+               err |= __get_user(sig[2], &ubuf->sig[2]);
                kbuf->sig[1] = sig[2] | (sig[3] << 32);
        case 1:
-               err |= __get_user (sig[1], &ubuf->sig[1]);
-               err |= __get_user (sig[0], &ubuf->sig[0]);
+               err |= __get_user(sig[1], &ubuf->sig[1]);
+               err |= __get_user(sig[0], &ubuf->sig[0]);
                kbuf->sig[0] = sig[0] | (sig[1] << 32);
        }
 
@@ -379,8 +349,8 @@ asmlinkage int sys32_rt_sigsuspend(nabi_no_regargs struct pt_regs regs)
        return -ERESTARTNOHAND;
 }
 
-asmlinkage int sys32_sigaction(int sig, const struct sigaction32 __user *act,
-                               struct sigaction32 __user *oact)
+SYSCALL_DEFINE3(32_sigaction, long, sig, const struct sigaction32 __user *, act,
+       struct sigaction32 __user *, oact)
 {
        struct k_sigaction new_ka, old_ka;
        int ret;
@@ -442,10 +412,10 @@ asmlinkage int sys32_sigaltstack(nabi_no_regargs struct pt_regs regs)
                        return -EFAULT;
        }
 
-       set_fs (KERNEL_DS);
+       set_fs(KERNEL_DS);
        ret = do_sigaltstack(uss ? (stack_t __user *)&kss : NULL,
                             uoss ? (stack_t __user *)&koss : NULL, usp);
-       set_fs (old_fs);
+       set_fs(old_fs);
 
        if (!ret && uoss) {
                if (!access_ok(VERIFY_WRITE, uoss, sizeof(*uoss)))
@@ -512,6 +482,18 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
        return err;
 }
 
+int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
+{
+       memset(to, 0, sizeof *to);
+
+       if (copy_from_user(to, from, 3*sizeof(int)) ||
+           copy_from_user(to->_sifields._pad,
+                          from->_sifields._pad, SI_PAD_SIZE32))
+               return -EFAULT;
+
+       return 0;
+}
+
 asmlinkage void sys32_sigreturn(nabi_no_regargs struct pt_regs regs)
 {
        struct sigframe32 __user *frame;
@@ -589,9 +571,9 @@ asmlinkage void sys32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
        /* It is more difficult to avoid calling this function than to
           call it and ignore errors.  */
        old_fs = get_fs();
-       set_fs (KERNEL_DS);
+       set_fs(KERNEL_DS);
        do_sigaltstack((stack_t __user *)&st, NULL, regs.regs[29]);
-       set_fs (old_fs);
+       set_fs(old_fs);
 
        /*
         * Don't let your children do this ...
@@ -722,9 +704,9 @@ struct mips_abi mips_abi_32 = {
        .restart        = __NR_O32_restart_syscall
 };
 
-asmlinkage int sys32_rt_sigaction(int sig, const struct sigaction32 __user *act,
-                                 struct sigaction32 __user *oact,
-                                 unsigned int sigsetsize)
+SYSCALL_DEFINE4(32_rt_sigaction, int, sig,
+       const struct sigaction32 __user *, act,
+       struct sigaction32 __user *, oact, unsigned int, sigsetsize)
 {
        struct k_sigaction new_sa, old_sa;
        int ret = -EINVAL;
@@ -766,8 +748,8 @@ out:
        return ret;
 }
 
-asmlinkage int sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
-       compat_sigset_t __user *oset, unsigned int sigsetsize)
+SYSCALL_DEFINE4(32_rt_sigprocmask, int, how, compat_sigset_t __user *, set,
+       compat_sigset_t __user *, oset, unsigned int, sigsetsize)
 {
        sigset_t old_set, new_set;
        int ret;
@@ -776,11 +758,11 @@ asmlinkage int sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
        if (set && get_sigset(&new_set, set))
                return -EFAULT;
 
-       set_fs (KERNEL_DS);
+       set_fs(KERNEL_DS);
        ret = sys_rt_sigprocmask(how, set ? (sigset_t __user *)&new_set : NULL,
                                 oset ? (sigset_t __user *)&old_set : NULL,
                                 sigsetsize);
-       set_fs (old_fs);
+       set_fs(old_fs);
 
        if (!ret && oset && put_sigset(&old_set, oset))
                return -EFAULT;
@@ -788,16 +770,16 @@ asmlinkage int sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
        return ret;
 }
 
-asmlinkage int sys32_rt_sigpending(compat_sigset_t __user *uset,
-       unsigned int sigsetsize)
+SYSCALL_DEFINE2(32_rt_sigpending, compat_sigset_t __user *, uset,
+       unsigned int, sigsetsize)
 {
        int ret;
        sigset_t set;
        mm_segment_t old_fs = get_fs();
 
-       set_fs (KERNEL_DS);
+       set_fs(KERNEL_DS);
        ret = sys_rt_sigpending((sigset_t __user *)&set, sigsetsize);
-       set_fs (old_fs);
+       set_fs(old_fs);
 
        if (!ret && put_sigset(&set, uset))
                return -EFAULT;
@@ -805,25 +787,25 @@ asmlinkage int sys32_rt_sigpending(compat_sigset_t __user *uset,
        return ret;
 }
 
-asmlinkage int sys32_rt_sigqueueinfo(int pid, int sig, compat_siginfo_t __user *uinfo)
+SYSCALL_DEFINE3(32_rt_sigqueueinfo, int, pid, int, sig,
+       compat_siginfo_t __user *, uinfo)
 {
        siginfo_t info;
        int ret;
        mm_segment_t old_fs = get_fs();
 
-       if (copy_from_user (&info, uinfo, 3*sizeof(int)) ||
-           copy_from_user (info._sifields._pad, uinfo->_sifields._pad, SI_PAD_SIZE))
+       if (copy_from_user(&info, uinfo, 3*sizeof(int)) ||
+           copy_from_user(info._sifields._pad, uinfo->_sifields._pad, SI_PAD_SIZE))
                return -EFAULT;
-       set_fs (KERNEL_DS);
+       set_fs(KERNEL_DS);
        ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
-       set_fs (old_fs);
+       set_fs(old_fs);
        return ret;
 }
 
-asmlinkage long
-sys32_waitid(int which, compat_pid_t pid,
-            compat_siginfo_t __user *uinfo, int options,
-            struct compat_rusage __user *uru)
+SYSCALL_DEFINE5(32_waitid, int, which, compat_pid_t, pid,
+            compat_siginfo_t __user *, uinfo, int, options,
+            struct compat_rusage __user *, uru)
 {
        siginfo_t info;
        struct rusage ru;
@@ -831,10 +813,10 @@ sys32_waitid(int which, compat_pid_t pid,
        mm_segment_t old_fs = get_fs();
 
        info.si_signo = 0;
-       set_fs (KERNEL_DS);
+       set_fs(KERNEL_DS);
        ret = sys_waitid(which, pid, (siginfo_t __user *) &info, options,
                         uru ? (struct rusage __user *) &ru : NULL);
-       set_fs (old_fs);
+       set_fs(old_fs);
 
        if (ret < 0 || info.si_signo == 0)
                return ret;