pull clearing RESTORE_SIGMASK into block_sigmask()
[cascardo/linux.git] / arch / sh / kernel / signal_64.c
index 3c9a6f7..7075c63 100644 (file)
@@ -43,9 +43,9 @@
 
 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
 
-static int
+static void
 handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
-               sigset_t *oldset, struct pt_regs * regs);
+               struct pt_regs * regs);
 
 static inline void
 handle_syscall_restart(struct pt_regs *regs, struct sigaction *sa)
@@ -83,7 +83,7 @@ handle_syscall_restart(struct pt_regs *regs, struct sigaction *sa)
  * the kernel can handle, and then we build all the user-level signal handling
  * stack-frames in one go after that.
  */
-static int do_signal(struct pt_regs *regs, sigset_t *oldset)
+static void do_signal(struct pt_regs *regs)
 {
        siginfo_t info;
        int signr;
@@ -96,30 +96,15 @@ static int do_signal(struct pt_regs *regs, sigset_t *oldset)
         * if so.
         */
        if (!user_mode(regs))
-               return 1;
-
-       if (current_thread_info()->status & TS_RESTORE_SIGMASK)
-               oldset = &current->saved_sigmask;
-       else if (!oldset)
-               oldset = &current->blocked;
+               return;
 
        signr = get_signal_to_deliver(&info, &ka, regs, 0);
        if (signr > 0) {
                handle_syscall_restart(regs, &ka.sa);
 
                /* Whee!  Actually deliver the signal.  */
-               if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
-                       /*
-                        * If a signal was successfully delivered, the
-                        * saved sigmask is in its frame, and we can
-                        * clear the TS_RESTORE_SIGMASK flag.
-                        */
-                       current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
-
-                       tracehook_signal_handler(signr, &info, &ka, regs,
-                                       test_thread_flag(TIF_SINGLESTEP));
-                       return 1;
-               }
+               handle_signal(signr, &info, &ka, regs);
+               return;
        }
 
        /* Did we come from a system call? */
@@ -142,76 +127,18 @@ static int do_signal(struct pt_regs *regs, sigset_t *oldset)
        }
 
        /* No signal to deliver -- put the saved sigmask back */
-       if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
-               current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
-               sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
-       }
-
-       return 0;
+       restore_saved_sigmask();
 }
 
 /*
  * Atomically swap in the new signal mask, and wait for a signal.
  */
 asmlinkage int
-sys_sigsuspend(old_sigset_t mask,
-              unsigned long r3, unsigned long r4, unsigned long r5,
-              unsigned long r6, unsigned long r7,
-              struct pt_regs * regs)
+sys_sigsuspend(old_sigset_t mask)
 {
-       sigset_t saveset, blocked;
-
-       saveset = current->blocked;
-
-       mask &= _BLOCKABLE;
+       sigset_t blocked;
        siginitset(&blocked, mask);
-       set_current_blocked(&blocked);
-
-       REF_REG_RET = -EINTR;
-       while (1) {
-               current->state = TASK_INTERRUPTIBLE;
-               schedule();
-               set_restore_sigmask();
-               regs->pc += 4;    /* because sys_sigreturn decrements the pc */
-               if (do_signal(regs, &saveset)) {
-                       /* pc now points at signal handler. Need to decrement
-                          it because entry.S will increment it. */
-                       regs->pc -= 4;
-                       return -EINTR;
-               }
-       }
-}
-
-asmlinkage int
-sys_rt_sigsuspend(sigset_t *unewset, size_t sigsetsize,
-                 unsigned long r4, unsigned long r5, unsigned long r6,
-                 unsigned long r7,
-                 struct pt_regs * regs)
-{
-       sigset_t saveset, newset;
-
-       /* XXX: Don't preclude handling different sized sigset_t's.  */
-       if (sigsetsize != sizeof(sigset_t))
-               return -EINVAL;
-
-       if (copy_from_user(&newset, unewset, sizeof(newset)))
-               return -EFAULT;
-       sigdelsetmask(&newset, ~_BLOCKABLE);
-       saveset = current->blocked;
-       set_current_blocked(&newset);
-
-       REF_REG_RET = -EINTR;
-       while (1) {
-               current->state = TASK_INTERRUPTIBLE;
-               schedule();
-               regs->pc += 4;    /* because sys_sigreturn decrements the pc */
-               if (do_signal(regs, &saveset)) {
-                       /* pc now points at signal handler. Need to decrement
-                          it because entry.S will increment it. */
-                       regs->pc -= 4;
-                       return -EINTR;
-               }
-       }
+       return sigsuspend(&blocked);
 }
 
 asmlinkage int
@@ -225,10 +152,10 @@ sys_sigaction(int sig, const struct old_sigaction __user *act,
                old_sigset_t mask;
                if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
                    __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
-                   __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
+                   __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
+                   __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
+                   __get_user(mask, &act->sa_mask))
                        return -EFAULT;
-               __get_user(new_ka.sa.sa_flags, &act->sa_flags);
-               __get_user(mask, &act->sa_mask);
                siginitset(&new_ka.sa.sa_mask, mask);
        }
 
@@ -237,10 +164,10 @@ sys_sigaction(int sig, const struct old_sigaction __user *act,
        if (!ret && oact) {
                if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
                    __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
-                   __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
+                   __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
+                   __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
+                   __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
                        return -EFAULT;
-               __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
-               __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
        }
 
        return ret;
@@ -711,10 +638,11 @@ give_sigsegv:
 /*
  * OK, we're invoking a handler
  */
-static int
+static void
 handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
-               sigset_t *oldset, struct pt_regs * regs)
+               struct pt_regs * regs)
 {
+       sigset_t *oldset = sigmask_to_save();
        int ret;
 
        /* Set up the stack frame */
@@ -723,21 +651,21 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
        else
                ret = setup_frame(sig, ka, oldset, regs);
 
-       if (ret == 0)
-               block_sigmask(ka, sig);
+       if (ret)
+               return;
 
-       return ret;
+       block_sigmask(ka, sig);
+       tracehook_signal_handler(sig, info, ka, regs,
+                       test_thread_flag(TIF_SINGLESTEP));
 }
 
 asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
 {
        if (thread_info_flags & _TIF_SIGPENDING)
-               do_signal(regs, 0);
+               do_signal(regs);
 
        if (thread_info_flags & _TIF_NOTIFY_RESUME) {
                clear_thread_flag(TIF_NOTIFY_RESUME);
                tracehook_notify_resume(regs);
-               if (current->replacement_session_keyring)
-                       key_replace_session_keyring();
        }
 }