aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/alpha/kernel/signal.c18
-rw-r--r--arch/arm/kernel/signal.c47
-rw-r--r--arch/avr32/kernel/entry-avr32b.S4
-rw-r--r--arch/avr32/kernel/signal.c41
-rw-r--r--arch/blackfin/include/asm/thread_info.h2
-rw-r--r--arch/blackfin/kernel/signal.c67
-rw-r--r--arch/blackfin/mach-common/entry.S2
-rw-r--r--arch/c6x/kernel/signal.c43
-rw-r--r--arch/cris/arch-v10/kernel/signal.c34
-rw-r--r--arch/cris/arch-v32/kernel/signal.c36
-rw-r--r--arch/frv/include/asm/thread_info.h16
-rw-r--r--arch/frv/kernel/entry.S29
-rw-r--r--arch/frv/kernel/signal.c57
-rw-r--r--arch/h8300/kernel/signal.c28
-rw-r--r--arch/hexagon/kernel/signal.c48
-rw-r--r--arch/ia64/include/asm/thread_info.h18
-rw-r--r--arch/ia64/kernel/signal.c34
-rw-r--r--arch/m32r/kernel/signal.c32
-rw-r--r--arch/m68k/kernel/signal.c24
-rw-r--r--arch/microblaze/include/asm/thread_info.h18
-rw-r--r--arch/microblaze/kernel/signal.c36
-rw-r--r--arch/mips/kernel/signal-common.h2
-rw-r--r--arch/mips/kernel/signal.c38
-rw-r--r--arch/mips/kernel/signal32.c2
-rw-r--r--arch/mips/kernel/signal_n32.c1
-rw-r--r--arch/mn10300/kernel/signal.c39
-rw-r--r--arch/openrisc/kernel/signal.c40
-rw-r--r--arch/parisc/include/asm/thread_info.h2
-rw-r--r--arch/parisc/kernel/entry.S4
-rw-r--r--arch/parisc/kernel/signal.c47
-rw-r--r--arch/parisc/kernel/signal32.c2
-rw-r--r--arch/powerpc/include/asm/thread_info.h18
-rw-r--r--arch/powerpc/kernel/signal.c36
-rw-r--r--arch/powerpc/kernel/signal.h3
-rw-r--r--arch/powerpc/kernel/signal_32.c4
-rw-r--r--arch/powerpc/kernel/signal_64.c4
-rw-r--r--arch/s390/kernel/compat_signal.c12
-rw-r--r--arch/s390/kernel/entry.h2
-rw-r--r--arch/s390/kernel/signal.c47
-rw-r--r--arch/score/kernel/signal.c40
-rw-r--r--arch/sh/include/asm/thread_info.h19
-rw-r--r--arch/sh/kernel/signal_32.c43
-rw-r--r--arch/sh/kernel/signal_64.c47
-rw-r--r--arch/sparc/include/asm/thread_info_32.h3
-rw-r--r--arch/sparc/include/asm/thread_info_64.h18
-rw-r--r--arch/sparc/kernel/signal32.c27
-rw-r--r--arch/sparc/kernel/signal_32.c39
-rw-r--r--arch/sparc/kernel/signal_64.c34
-rw-r--r--arch/tile/include/asm/thread_info.h18
-rw-r--r--arch/tile/kernel/compat_signal.c3
-rw-r--r--arch/tile/kernel/signal.c42
-rw-r--r--arch/um/include/shared/frame_kern.h3
-rw-r--r--arch/um/kernel/signal.c37
-rw-r--r--arch/unicore32/kernel/signal.c47
-rw-r--r--arch/x86/ia32/ia32_signal.c2
-rw-r--r--arch/x86/include/asm/sighandling.h2
-rw-r--r--arch/x86/include/asm/thread_info.h18
-rw-r--r--arch/x86/kernel/entry_32.S13
-rw-r--r--arch/x86/kernel/signal.c60
-rw-r--r--arch/x86/um/signal.c2
-rw-r--r--arch/xtensa/kernel/signal.c21
-rw-r--r--fs/compat.c4
-rw-r--r--fs/eventpoll.c4
-rw-r--r--fs/select.c4
-rw-r--r--include/linux/sched.h14
-rw-r--r--include/linux/signal.h5
-rw-r--r--include/linux/thread_info.h19
-rw-r--r--kernel/signal.c48
68 files changed, 482 insertions, 1091 deletions
diff --git a/arch/alpha/kernel/signal.c b/arch/alpha/kernel/signal.c
index f6db3032ddf0..a8c97d42ec8e 100644
--- a/arch/alpha/kernel/signal.c
+++ b/arch/alpha/kernel/signal.c
@@ -226,7 +226,6 @@ do_sigreturn(struct sigcontext __user *sc, struct pt_regs *regs,
226 if (__get_user(set.sig[0], &sc->sc_mask)) 226 if (__get_user(set.sig[0], &sc->sc_mask))
227 goto give_sigsegv; 227 goto give_sigsegv;
228 228
229 sigdelsetmask(&set, ~_BLOCKABLE);
230 set_current_blocked(&set); 229 set_current_blocked(&set);
231 230
232 if (restore_sigcontext(sc, regs, sw)) 231 if (restore_sigcontext(sc, regs, sw))
@@ -261,7 +260,6 @@ do_rt_sigreturn(struct rt_sigframe __user *frame, struct pt_regs *regs,
261 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 260 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
262 goto give_sigsegv; 261 goto give_sigsegv;
263 262
264 sigdelsetmask(&set, ~_BLOCKABLE);
265 set_current_blocked(&set); 263 set_current_blocked(&set);
266 264
267 if (restore_sigcontext(&frame->uc.uc_mcontext, regs, sw)) 265 if (restore_sigcontext(&frame->uc.uc_mcontext, regs, sw))
@@ -468,12 +466,9 @@ static inline void
468handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info, 466handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
469 struct pt_regs * regs, struct switch_stack *sw) 467 struct pt_regs * regs, struct switch_stack *sw)
470{ 468{
471 sigset_t *oldset = &current->blocked; 469 sigset_t *oldset = sigmask_to_save();
472 int ret; 470 int ret;
473 471
474 if (test_thread_flag(TIF_RESTORE_SIGMASK))
475 oldset = &current->saved_sigmask;
476
477 if (ka->sa.sa_flags & SA_SIGINFO) 472 if (ka->sa.sa_flags & SA_SIGINFO)
478 ret = setup_rt_frame(sig, ka, info, oldset, regs, sw); 473 ret = setup_rt_frame(sig, ka, info, oldset, regs, sw);
479 else 474 else
@@ -483,12 +478,7 @@ handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
483 force_sigsegv(sig, current); 478 force_sigsegv(sig, current);
484 return; 479 return;
485 } 480 }
486 block_sigmask(ka, sig); 481 signal_delivered(sig, info, ka, regs, 0);
487 /* A signal was successfully delivered, and the
488 saved sigmask was stored on the signal frame,
489 and will be restored by sigreturn. So we can
490 simply clear the restore sigmask flag. */
491 clear_thread_flag(TIF_RESTORE_SIGMASK);
492} 482}
493 483
494static inline void 484static inline void
@@ -572,9 +562,7 @@ do_signal(struct pt_regs * regs, struct switch_stack * sw,
572 } 562 }
573 563
574 /* If there's no signal to deliver, we just restore the saved mask. */ 564 /* If there's no signal to deliver, we just restore the saved mask. */
575 if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK)) 565 restore_saved_sigmask();
576 set_current_blocked(&current->saved_sigmask);
577
578 if (single_stepping) 566 if (single_stepping)
579 ptrace_set_bpt(current); /* re-set breakpoint */ 567 ptrace_set_bpt(current); /* re-set breakpoint */
580} 568}
diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
index 63f327dd5198..fd2392a17ac1 100644
--- a/arch/arm/kernel/signal.c
+++ b/arch/arm/kernel/signal.c
@@ -22,8 +22,6 @@
22 22
23#include "signal.h" 23#include "signal.h"
24 24
25#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
26
27/* 25/*
28 * For ARM syscalls, we encode the syscall number into the instruction. 26 * For ARM syscalls, we encode the syscall number into the instruction.
29 */ 27 */
@@ -210,10 +208,8 @@ static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
210 int err; 208 int err;
211 209
212 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set)); 210 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
213 if (err == 0) { 211 if (err == 0)
214 sigdelsetmask(&set, ~_BLOCKABLE);
215 set_current_blocked(&set); 212 set_current_blocked(&set);
216 }
217 213
218 __get_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err); 214 __get_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
219 __get_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err); 215 __get_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
@@ -528,13 +524,13 @@ setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
528/* 524/*
529 * OK, we're invoking a handler 525 * OK, we're invoking a handler
530 */ 526 */
531static int 527static void
532handle_signal(unsigned long sig, struct k_sigaction *ka, 528handle_signal(unsigned long sig, struct k_sigaction *ka,
533 siginfo_t *info, sigset_t *oldset, 529 siginfo_t *info, struct pt_regs *regs)
534 struct pt_regs * regs)
535{ 530{
536 struct thread_info *thread = current_thread_info(); 531 struct thread_info *thread = current_thread_info();
537 struct task_struct *tsk = current; 532 struct task_struct *tsk = current;
533 sigset_t *oldset = sigmask_to_save();
538 int usig = sig; 534 int usig = sig;
539 int ret; 535 int ret;
540 536
@@ -559,17 +555,9 @@ handle_signal(unsigned long sig, struct k_sigaction *ka,
559 555
560 if (ret != 0) { 556 if (ret != 0) {
561 force_sigsegv(sig, tsk); 557 force_sigsegv(sig, tsk);
562 return ret; 558 return;
563 } 559 }
564 560 signal_delivered(sig, info, ka, regs, 0);
565 /*
566 * Block the signal if we were successful.
567 */
568 block_sigmask(ka, sig);
569
570 tracehook_signal_handler(sig, info, ka, regs, 0);
571
572 return 0;
573} 561}
574 562
575/* 563/*
@@ -617,8 +605,6 @@ static void do_signal(struct pt_regs *regs, int syscall)
617 */ 605 */
618 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 606 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
619 if (signr > 0) { 607 if (signr > 0) {
620 sigset_t *oldset;
621
622 /* 608 /*
623 * Depending on the signal settings we may need to revert the 609 * Depending on the signal settings we may need to revert the
624 * decision to restart the system call. But skip this if a 610 * decision to restart the system call. But skip this if a
@@ -635,20 +621,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
635 clear_thread_flag(TIF_SYSCALL_RESTARTSYS); 621 clear_thread_flag(TIF_SYSCALL_RESTARTSYS);
636 } 622 }
637 623
638 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 624 handle_signal(signr, &ka, &info, regs);
639 oldset = &current->saved_sigmask;
640 else
641 oldset = &current->blocked;
642 if (handle_signal(signr, &ka, &info, oldset, regs) == 0) {
643 /*
644 * A signal was successfully delivered; the saved
645 * sigmask will have been stored in the signal frame,
646 * and will be restored by sigreturn, so we can simply
647 * clear the TIF_RESTORE_SIGMASK flag.
648 */
649 if (test_thread_flag(TIF_RESTORE_SIGMASK))
650 clear_thread_flag(TIF_RESTORE_SIGMASK);
651 }
652 return; 625 return;
653 } 626 }
654 627
@@ -663,11 +636,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
663 set_thread_flag(TIF_SYSCALL_RESTARTSYS); 636 set_thread_flag(TIF_SYSCALL_RESTARTSYS);
664 } 637 }
665 638
666 /* If there's no signal to deliver, we just put the saved sigmask 639 restore_saved_sigmask();
667 * back.
668 */
669 if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK))
670 set_current_blocked(&current->saved_sigmask);
671} 640}
672 641
673asmlinkage void 642asmlinkage void
diff --git a/arch/avr32/kernel/entry-avr32b.S b/arch/avr32/kernel/entry-avr32b.S
index 5e6beb2597a8..df2884181313 100644
--- a/arch/avr32/kernel/entry-avr32b.S
+++ b/arch/avr32/kernel/entry-avr32b.S
@@ -281,7 +281,7 @@ syscall_exit_work:
281 ld.w r1, r0[TI_flags] 281 ld.w r1, r0[TI_flags]
282 rjmp 1b 282 rjmp 1b
283 283
2842: mov r2, _TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NOTIFY_RESUME 2842: mov r2, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
285 tst r1, r2 285 tst r1, r2
286 breq 3f 286 breq 3f
287 unmask_interrupts 287 unmask_interrupts
@@ -587,7 +587,7 @@ fault_exit_work:
587 ld.w r1, r0[TI_flags] 587 ld.w r1, r0[TI_flags]
588 rjmp fault_exit_work 588 rjmp fault_exit_work
589 589
5901: mov r2, _TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NOTIFY_RESUME 5901: mov r2, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
591 tst r1, r2 591 tst r1, r2
592 breq 2f 592 breq 2f
593 unmask_interrupts 593 unmask_interrupts
diff --git a/arch/avr32/kernel/signal.c b/arch/avr32/kernel/signal.c
index e7595ef74f51..c140f9b41dce 100644
--- a/arch/avr32/kernel/signal.c
+++ b/arch/avr32/kernel/signal.c
@@ -22,8 +22,6 @@
22#include <asm/ucontext.h> 22#include <asm/ucontext.h>
23#include <asm/syscalls.h> 23#include <asm/syscalls.h>
24 24
25#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
26
27asmlinkage int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, 25asmlinkage int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
28 struct pt_regs *regs) 26 struct pt_regs *regs)
29{ 27{
@@ -89,7 +87,6 @@ asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
89 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 87 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
90 goto badframe; 88 goto badframe;
91 89
92 sigdelsetmask(&set, ~_BLOCKABLE);
93 set_current_blocked(&set); 90 set_current_blocked(&set);
94 91
95 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 92 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -224,30 +221,27 @@ static inline void setup_syscall_restart(struct pt_regs *regs)
224 221
225static inline void 222static inline void
226handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info, 223handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
227 sigset_t *oldset, struct pt_regs *regs, int syscall) 224 struct pt_regs *regs, int syscall)
228{ 225{
229 int ret; 226 int ret;
230 227
231 /* 228 /*
232 * Set up the stack frame 229 * Set up the stack frame
233 */ 230 */
234 ret = setup_rt_frame(sig, ka, info, oldset, regs); 231 ret = setup_rt_frame(sig, ka, info, sigmask_to_save(), regs);
235 232
236 /* 233 /*
237 * Check that the resulting registers are sane 234 * Check that the resulting registers are sane
238 */ 235 */
239 ret |= !valid_user_regs(regs); 236 ret |= !valid_user_regs(regs);
240 237
241 if (ret != 0) {
242 force_sigsegv(sig, current);
243 return;
244 }
245
246 /* 238 /*
247 * Block the signal if we were successful. 239 * Block the signal if we were successful.
248 */ 240 */
249 block_sigmask(ka, sig); 241 if (ret != 0)
250 clear_thread_flag(TIF_RESTORE_SIGMASK); 242 force_sigsegv(sig, current);
243 else
244 signal_delivered(sig, info, ka, regs, 0);
251} 245}
252 246
253/* 247/*
@@ -255,7 +249,7 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
255 * doesn't want to handle. Thus you cannot kill init even with a 249 * doesn't want to handle. Thus you cannot kill init even with a
256 * SIGKILL even by mistake. 250 * SIGKILL even by mistake.
257 */ 251 */
258int do_signal(struct pt_regs *regs, sigset_t *oldset, int syscall) 252static void do_signal(struct pt_regs *regs, int syscall)
259{ 253{
260 siginfo_t info; 254 siginfo_t info;
261 int signr; 255 int signr;
@@ -267,12 +261,7 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset, int syscall)
267 * without doing anything if so. 261 * without doing anything if so.
268 */ 262 */
269 if (!user_mode(regs)) 263 if (!user_mode(regs))
270 return 0; 264 return;
271
272 if (test_thread_flag(TIF_RESTORE_SIGMASK))
273 oldset = &current->saved_sigmask;
274 else if (!oldset)
275 oldset = &current->blocked;
276 265
277 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 266 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
278 if (syscall) { 267 if (syscall) {
@@ -297,15 +286,11 @@ int do_signal(struct pt_regs *regs, sigset_t *oldset, int syscall)
297 286
298 if (signr == 0) { 287 if (signr == 0) {
299 /* No signal to deliver -- put the saved sigmask back */ 288 /* No signal to deliver -- put the saved sigmask back */
300 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 289 restore_saved_sigmask();
301 clear_thread_flag(TIF_RESTORE_SIGMASK); 290 return;
302 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
303 }
304 return 0;
305 } 291 }
306 292
307 handle_signal(signr, &ka, &info, oldset, regs, syscall); 293 handle_signal(signr, &ka, &info, regs, syscall);
308 return 1;
309} 294}
310 295
311asmlinkage void do_notify_resume(struct pt_regs *regs, struct thread_info *ti) 296asmlinkage void do_notify_resume(struct pt_regs *regs, struct thread_info *ti)
@@ -315,8 +300,8 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, struct thread_info *ti)
315 if ((sysreg_read(SR) & MODE_MASK) == MODE_SUPERVISOR) 300 if ((sysreg_read(SR) & MODE_MASK) == MODE_SUPERVISOR)
316 syscall = 1; 301 syscall = 1;
317 302
318 if (ti->flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 303 if (ti->flags & _TIF_SIGPENDING))
319 do_signal(regs, &current->blocked, syscall); 304 do_signal(regs, syscall);
320 305
321 if (ti->flags & _TIF_NOTIFY_RESUME) { 306 if (ti->flags & _TIF_NOTIFY_RESUME) {
322 clear_thread_flag(TIF_NOTIFY_RESUME); 307 clear_thread_flag(TIF_NOTIFY_RESUME);
diff --git a/arch/blackfin/include/asm/thread_info.h b/arch/blackfin/include/asm/thread_info.h
index 02560fd8a121..53ad10005ae3 100644
--- a/arch/blackfin/include/asm/thread_info.h
+++ b/arch/blackfin/include/asm/thread_info.h
@@ -100,7 +100,6 @@ static inline struct thread_info *current_thread_info(void)
100 TIF_NEED_RESCHED */ 100 TIF_NEED_RESCHED */
101#define TIF_MEMDIE 4 /* is terminating due to OOM killer */ 101#define TIF_MEMDIE 4 /* is terminating due to OOM killer */
102#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */ 102#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */
103#define TIF_FREEZE 6 /* is freezing for suspend */
104#define TIF_IRQ_SYNC 7 /* sync pipeline stage */ 103#define TIF_IRQ_SYNC 7 /* sync pipeline stage */
105#define TIF_NOTIFY_RESUME 8 /* callback before returning to user */ 104#define TIF_NOTIFY_RESUME 8 /* callback before returning to user */
106#define TIF_SINGLESTEP 9 105#define TIF_SINGLESTEP 9
@@ -111,7 +110,6 @@ static inline struct thread_info *current_thread_info(void)
111#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED) 110#define _TIF_NEED_RESCHED (1<<TIF_NEED_RESCHED)
112#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG) 111#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
113#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK) 112#define _TIF_RESTORE_SIGMASK (1<<TIF_RESTORE_SIGMASK)
114#define _TIF_FREEZE (1<<TIF_FREEZE)
115#define _TIF_IRQ_SYNC (1<<TIF_IRQ_SYNC) 113#define _TIF_IRQ_SYNC (1<<TIF_IRQ_SYNC)
116#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME) 114#define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
117#define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP) 115#define _TIF_SINGLESTEP (1<<TIF_SINGLESTEP)
diff --git a/arch/blackfin/kernel/signal.c b/arch/blackfin/kernel/signal.c
index fc9ecce8b6ce..6682b73a8523 100644
--- a/arch/blackfin/kernel/signal.c
+++ b/arch/blackfin/kernel/signal.c
@@ -19,8 +19,6 @@
19#include <asm/fixed_code.h> 19#include <asm/fixed_code.h>
20#include <asm/syscall.h> 20#include <asm/syscall.h>
21 21
22#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
23
24/* Location of the trace bit in SYSCFG. */ 22/* Location of the trace bit in SYSCFG. */
25#define TRACE_BITS 0x0001 23#define TRACE_BITS 0x0001
26 24
@@ -98,7 +96,6 @@ asmlinkage int do_rt_sigreturn(unsigned long __unused)
98 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 96 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
99 goto badframe; 97 goto badframe;
100 98
101 sigdelsetmask(&set, ~_BLOCKABLE);
102 set_current_blocked(&set); 99 set_current_blocked(&set);
103 100
104 if (rt_restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0)) 101 if (rt_restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0))
@@ -190,17 +187,22 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t * info,
190 err |= copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); 187 err |= copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
191 188
192 if (err) 189 if (err)
193 goto give_sigsegv; 190 return -EFAULT;
194 191
195 /* Set up registers for signal handler */ 192 /* Set up registers for signal handler */
196 wrusp((unsigned long)frame);
197 if (current->personality & FDPIC_FUNCPTRS) { 193 if (current->personality & FDPIC_FUNCPTRS) {
198 struct fdpic_func_descriptor __user *funcptr = 194 struct fdpic_func_descriptor __user *funcptr =
199 (struct fdpic_func_descriptor *) ka->sa.sa_handler; 195 (struct fdpic_func_descriptor *) ka->sa.sa_handler;
200 __get_user(regs->pc, &funcptr->text); 196 u32 pc, p3;
201 __get_user(regs->p3, &funcptr->GOT); 197 err |= __get_user(pc, &funcptr->text);
198 err |= __get_user(p3, &funcptr->GOT);
199 if (err)
200 return -EFAULT;
201 regs->pc = pc;
202 regs->p3 = p3;
202 } else 203 } else
203 regs->pc = (unsigned long)ka->sa.sa_handler; 204 regs->pc = (unsigned long)ka->sa.sa_handler;
205 wrusp((unsigned long)frame);
204 regs->rets = SIGRETURN_STUB; 206 regs->rets = SIGRETURN_STUB;
205 207
206 regs->r0 = frame->sig; 208 regs->r0 = frame->sig;
@@ -208,10 +210,6 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t * info,
208 regs->r2 = (unsigned long)(&frame->uc); 210 regs->r2 = (unsigned long)(&frame->uc);
209 211
210 return 0; 212 return 0;
211
212 give_sigsegv:
213 force_sigsegv(sig, current);
214 return -EFAULT;
215} 213}
216 214
217static inline void 215static inline void
@@ -247,24 +245,21 @@ handle_restart(struct pt_regs *regs, struct k_sigaction *ka, int has_handler)
247/* 245/*
248 * OK, we're invoking a handler 246 * OK, we're invoking a handler
249 */ 247 */
250static int 248static void
251handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka, 249handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka,
252 sigset_t *oldset, struct pt_regs *regs) 250 struct pt_regs *regs)
253{ 251{
254 int ret;
255
256 /* are we from a system call? to see pt_regs->orig_p0 */ 252 /* are we from a system call? to see pt_regs->orig_p0 */
257 if (regs->orig_p0 >= 0) 253 if (regs->orig_p0 >= 0)
258 /* If so, check system call restarting.. */ 254 /* If so, check system call restarting.. */
259 handle_restart(regs, ka, 1); 255 handle_restart(regs, ka, 1);
260 256
261 /* set up the stack frame */ 257 /* set up the stack frame */
262 ret = setup_rt_frame(sig, ka, info, oldset, regs); 258 if (setup_rt_frame(sig, ka, info, sigmask_to_save(), regs) < 0)
263 259 force_sigsegv(sig, current);
264 if (ret == 0) 260 else
265 block_sigmask(ka, sig); 261 signal_delivered(sig, info, ka, regs,
266 262 test_thread_flag(TIF_SINGLESTEP));
267 return ret;
268} 263}
269 264
270/* 265/*
@@ -281,37 +276,16 @@ asmlinkage void do_signal(struct pt_regs *regs)
281 siginfo_t info; 276 siginfo_t info;
282 int signr; 277 int signr;
283 struct k_sigaction ka; 278 struct k_sigaction ka;
284 sigset_t *oldset;
285 279
286 current->thread.esp0 = (unsigned long)regs; 280 current->thread.esp0 = (unsigned long)regs;
287 281
288 if (try_to_freeze())
289 goto no_signal;
290
291 if (test_thread_flag(TIF_RESTORE_SIGMASK))
292 oldset = &current->saved_sigmask;
293 else
294 oldset = &current->blocked;
295
296 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 282 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
297 if (signr > 0) { 283 if (signr > 0) {
298 /* Whee! Actually deliver the signal. */ 284 /* Whee! Actually deliver the signal. */
299 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 285 handle_signal(signr, &info, &ka, regs);
300 /* a signal was successfully delivered; the saved
301 * sigmask will have been stored in the signal frame,
302 * and will be restored by sigreturn, so we can simply
303 * clear the TIF_RESTORE_SIGMASK flag */
304 if (test_thread_flag(TIF_RESTORE_SIGMASK))
305 clear_thread_flag(TIF_RESTORE_SIGMASK);
306
307 tracehook_signal_handler(signr, &info, &ka, regs,
308 test_thread_flag(TIF_SINGLESTEP));
309 }
310
311 return; 286 return;
312 } 287 }
313 288
314 no_signal:
315 /* Did we come from a system call? */ 289 /* Did we come from a system call? */
316 if (regs->orig_p0 >= 0) 290 if (regs->orig_p0 >= 0)
317 /* Restart the system call - no handlers present */ 291 /* Restart the system call - no handlers present */
@@ -319,10 +293,7 @@ asmlinkage void do_signal(struct pt_regs *regs)
319 293
320 /* if there's no signal to deliver, we just put the saved sigmask 294 /* if there's no signal to deliver, we just put the saved sigmask
321 * back */ 295 * back */
322 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 296 restore_saved_sigmask();
323 clear_thread_flag(TIF_RESTORE_SIGMASK);
324 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
325 }
326} 297}
327 298
328/* 299/*
@@ -330,7 +301,7 @@ asmlinkage void do_signal(struct pt_regs *regs)
330 */ 301 */
331asmlinkage void do_notify_resume(struct pt_regs *regs) 302asmlinkage void do_notify_resume(struct pt_regs *regs)
332{ 303{
333 if (test_thread_flag(TIF_SIGPENDING) || test_thread_flag(TIF_RESTORE_SIGMASK)) 304 if (test_thread_flag(TIF_SIGPENDING))
334 do_signal(regs); 305 do_signal(regs);
335 306
336 if (test_thread_flag(TIF_NOTIFY_RESUME)) { 307 if (test_thread_flag(TIF_NOTIFY_RESUME)) {
diff --git a/arch/blackfin/mach-common/entry.S b/arch/blackfin/mach-common/entry.S
index 80aa2535e2c9..04c2fbe41a7f 100644
--- a/arch/blackfin/mach-common/entry.S
+++ b/arch/blackfin/mach-common/entry.S
@@ -711,8 +711,6 @@ ENTRY(_system_call)
711 jump .Lresume_userspace_1; 711 jump .Lresume_userspace_1;
712 712
713.Lsyscall_sigpending: 713.Lsyscall_sigpending:
714 cc = BITTST(r7, TIF_RESTORE_SIGMASK);
715 if cc jump .Lsyscall_do_signals;
716 cc = BITTST(r7, TIF_SIGPENDING); 714 cc = BITTST(r7, TIF_SIGPENDING);
717 if cc jump .Lsyscall_do_signals; 715 if cc jump .Lsyscall_do_signals;
718 cc = BITTST(r7, TIF_NOTIFY_RESUME); 716 cc = BITTST(r7, TIF_NOTIFY_RESUME);
diff --git a/arch/c6x/kernel/signal.c b/arch/c6x/kernel/signal.c
index 9493f0bbf0a6..3d8f3c22a94f 100644
--- a/arch/c6x/kernel/signal.c
+++ b/arch/c6x/kernel/signal.c
@@ -20,8 +20,6 @@
20#include <asm/cacheflush.h> 20#include <asm/cacheflush.h>
21 21
22 22
23#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
24
25/* 23/*
26 * Do a signal return, undo the signal stack. 24 * Do a signal return, undo the signal stack.
27 */ 25 */
@@ -87,7 +85,6 @@ asmlinkage int do_rt_sigreturn(struct pt_regs *regs)
87 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 85 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
88 goto badframe; 86 goto badframe;
89 87
90 sigdelsetmask(&set, ~_BLOCKABLE);
91 set_current_blocked(&set); 88 set_current_blocked(&set);
92 89
93 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 90 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -248,10 +245,9 @@ do_restart:
248/* 245/*
249 * handle the actual delivery of a signal to userspace 246 * handle the actual delivery of a signal to userspace
250 */ 247 */
251static int handle_signal(int sig, 248static void handle_signal(int sig,
252 siginfo_t *info, struct k_sigaction *ka, 249 siginfo_t *info, struct k_sigaction *ka,
253 sigset_t *oldset, struct pt_regs *regs, 250 struct pt_regs *regs, int syscall)
254 int syscall)
255{ 251{
256 int ret; 252 int ret;
257 253
@@ -278,11 +274,9 @@ static int handle_signal(int sig,
278 } 274 }
279 275
280 /* Set up the stack frame */ 276 /* Set up the stack frame */
281 ret = setup_rt_frame(sig, ka, info, oldset, regs); 277 if (setup_rt_frame(sig, ka, info, sigmask_to_save(), regs) < 0)
282 if (ret == 0) 278 return;
283 block_sigmask(ka, sig); 279 signal_delivered(sig, info, ka, regs, 0);
284
285 return ret;
286} 280}
287 281
288/* 282/*
@@ -292,7 +286,6 @@ static void do_signal(struct pt_regs *regs, int syscall)
292{ 286{
293 struct k_sigaction ka; 287 struct k_sigaction ka;
294 siginfo_t info; 288 siginfo_t info;
295 sigset_t *oldset;
296 int signr; 289 int signr;
297 290
298 /* we want the common case to go fast, which is why we may in certain 291 /* we want the common case to go fast, which is why we may in certain
@@ -300,25 +293,9 @@ static void do_signal(struct pt_regs *regs, int syscall)
300 if (!user_mode(regs)) 293 if (!user_mode(regs))
301 return; 294 return;
302 295
303 if (test_thread_flag(TIF_RESTORE_SIGMASK))
304 oldset = &current->saved_sigmask;
305 else
306 oldset = &current->blocked;
307
308 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 296 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
309 if (signr > 0) { 297 if (signr > 0) {
310 if (handle_signal(signr, &info, &ka, oldset, 298 handle_signal(signr, &info, &ka, regs, syscall);
311 regs, syscall) == 0) {
312 /* a signal was successfully delivered; the saved
313 * sigmask will have been stored in the signal frame,
314 * and will be restored by sigreturn, so we can simply
315 * clear the TIF_RESTORE_SIGMASK flag */
316 if (test_thread_flag(TIF_RESTORE_SIGMASK))
317 clear_thread_flag(TIF_RESTORE_SIGMASK);
318
319 tracehook_signal_handler(signr, &info, &ka, regs, 0);
320 }
321
322 return; 299 return;
323 } 300 }
324 301
@@ -343,10 +320,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
343 320
344 /* if there's no signal to deliver, we just put the saved sigmask 321 /* if there's no signal to deliver, we just put the saved sigmask
345 * back */ 322 * back */
346 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 323 restore_saved_sigmask();
347 clear_thread_flag(TIF_RESTORE_SIGMASK);
348 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
349 }
350} 324}
351 325
352/* 326/*
@@ -357,8 +331,7 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags,
357 int syscall) 331 int syscall)
358{ 332{
359 /* deal with pending signal delivery */ 333 /* deal with pending signal delivery */
360 if (thread_info_flags & ((1 << TIF_SIGPENDING) | 334 if (thread_info_flags & (1 << TIF_SIGPENDING))
361 (1 << TIF_RESTORE_SIGMASK)))
362 do_signal(regs, syscall); 335 do_signal(regs, syscall);
363 336
364 if (thread_info_flags & (1 << TIF_NOTIFY_RESUME)) { 337 if (thread_info_flags & (1 << TIF_NOTIFY_RESUME)) {
diff --git a/arch/cris/arch-v10/kernel/signal.c b/arch/cris/arch-v10/kernel/signal.c
index e16f8f297f61..0bb477c13a4e 100644
--- a/arch/cris/arch-v10/kernel/signal.c
+++ b/arch/cris/arch-v10/kernel/signal.c
@@ -31,8 +31,6 @@
31 31
32#define DEBUG_SIG 0 32#define DEBUG_SIG 0
33 33
34#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
35
36/* a syscall in Linux/CRIS is a break 13 instruction which is 2 bytes */ 34/* a syscall in Linux/CRIS is a break 13 instruction which is 2 bytes */
37/* manipulate regs so that upon return, it will be re-executed */ 35/* manipulate regs so that upon return, it will be re-executed */
38 36
@@ -176,7 +174,6 @@ asmlinkage int sys_sigreturn(long r10, long r11, long r12, long r13, long mof,
176 sizeof(frame->extramask)))) 174 sizeof(frame->extramask))))
177 goto badframe; 175 goto badframe;
178 176
179 sigdelsetmask(&set, ~_BLOCKABLE);
180 set_current_blocked(&set); 177 set_current_blocked(&set);
181 178
182 if (restore_sigcontext(regs, &frame->sc)) 179 if (restore_sigcontext(regs, &frame->sc))
@@ -212,7 +209,6 @@ asmlinkage int sys_rt_sigreturn(long r10, long r11, long r12, long r13,
212 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 209 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
213 goto badframe; 210 goto badframe;
214 211
215 sigdelsetmask(&set, ~_BLOCKABLE);
216 set_current_blocked(&set); 212 set_current_blocked(&set);
217 213
218 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 214 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -415,10 +411,11 @@ give_sigsegv:
415 * OK, we're invoking a handler 411 * OK, we're invoking a handler
416 */ 412 */
417 413
418static inline int handle_signal(int canrestart, unsigned long sig, 414static inline void handle_signal(int canrestart, unsigned long sig,
419 siginfo_t *info, struct k_sigaction *ka, 415 siginfo_t *info, struct k_sigaction *ka,
420 sigset_t *oldset, struct pt_regs *regs) 416 struct pt_regs *regs)
421{ 417{
418 sigset_t *oldset = sigmask_to_save();
422 int ret; 419 int ret;
423 420
424 /* Are we from a system call? */ 421 /* Are we from a system call? */
@@ -456,9 +453,7 @@ static inline int handle_signal(int canrestart, unsigned long sig,
456 ret = setup_frame(sig, ka, oldset, regs); 453 ret = setup_frame(sig, ka, oldset, regs);
457 454
458 if (ret == 0) 455 if (ret == 0)
459 block_sigmask(ka, sig); 456 signal_delivered(sig, info, ka, regs, 0);
460
461 return ret;
462} 457}
463 458
464/* 459/*
@@ -478,7 +473,6 @@ void do_signal(int canrestart, struct pt_regs *regs)
478 siginfo_t info; 473 siginfo_t info;
479 int signr; 474 int signr;
480 struct k_sigaction ka; 475 struct k_sigaction ka;
481 sigset_t *oldset;
482 476
483 /* 477 /*
484 * We want the common case to go fast, which 478 * We want the common case to go fast, which
@@ -489,23 +483,10 @@ void do_signal(int canrestart, struct pt_regs *regs)
489 if (!user_mode(regs)) 483 if (!user_mode(regs))
490 return; 484 return;
491 485
492 if (test_thread_flag(TIF_RESTORE_SIGMASK))
493 oldset = &current->saved_sigmask;
494 else
495 oldset = &current->blocked;
496
497 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 486 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
498 if (signr > 0) { 487 if (signr > 0) {
499 /* Whee! Actually deliver the signal. */ 488 /* Whee! Actually deliver the signal. */
500 if (handle_signal(canrestart, signr, &info, &ka, 489 handle_signal(canrestart, signr, &info, &ka, regs);
501 oldset, regs)) {
502 /* a signal was successfully delivered; the saved
503 * sigmask will have been stored in the signal frame,
504 * and will be restored by sigreturn, so we can simply
505 * clear the TIF_RESTORE_SIGMASK flag */
506 if (test_thread_flag(TIF_RESTORE_SIGMASK))
507 clear_thread_flag(TIF_RESTORE_SIGMASK);
508 }
509 return; 490 return;
510 } 491 }
511 492
@@ -525,8 +506,5 @@ void do_signal(int canrestart, struct pt_regs *regs)
525 506
526 /* if there's no signal to deliver, we just put the saved sigmask 507 /* if there's no signal to deliver, we just put the saved sigmask
527 * back */ 508 * back */
528 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 509 restore_saved_sigmask();
529 clear_thread_flag(TIF_RESTORE_SIGMASK);
530 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
531 }
532} 510}
diff --git a/arch/cris/arch-v32/kernel/signal.c b/arch/cris/arch-v32/kernel/signal.c
index b338d8fc0c12..b60d1b65a426 100644
--- a/arch/cris/arch-v32/kernel/signal.c
+++ b/arch/cris/arch-v32/kernel/signal.c
@@ -24,9 +24,6 @@
24 24
25extern unsigned long cris_signal_return_page; 25extern unsigned long cris_signal_return_page;
26 26
27/* Flag to check if a signal is blockable. */
28#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
29
30/* 27/*
31 * A syscall in CRIS is really a "break 13" instruction, which is 2 28 * A syscall in CRIS is really a "break 13" instruction, which is 2
32 * bytes. The registers is manipulated so upon return the instruction 29 * bytes. The registers is manipulated so upon return the instruction
@@ -167,7 +164,6 @@ sys_sigreturn(long r10, long r11, long r12, long r13, long mof, long srp,
167 sizeof(frame->extramask)))) 164 sizeof(frame->extramask))))
168 goto badframe; 165 goto badframe;
169 166
170 sigdelsetmask(&set, ~_BLOCKABLE);
171 set_current_blocked(&set); 167 set_current_blocked(&set);
172 168
173 if (restore_sigcontext(regs, &frame->sc)) 169 if (restore_sigcontext(regs, &frame->sc))
@@ -208,7 +204,6 @@ sys_rt_sigreturn(long r10, long r11, long r12, long r13, long mof, long srp,
208 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 204 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
209 goto badframe; 205 goto badframe;
210 206
211 sigdelsetmask(&set, ~_BLOCKABLE);
212 set_current_blocked(&set); 207 set_current_blocked(&set);
213 208
214 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 209 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -434,11 +429,12 @@ give_sigsegv:
434} 429}
435 430
436/* Invoke a signal handler to, well, handle the signal. */ 431/* Invoke a signal handler to, well, handle the signal. */
437static inline int 432static inline void
438handle_signal(int canrestart, unsigned long sig, 433handle_signal(int canrestart, unsigned long sig,
439 siginfo_t *info, struct k_sigaction *ka, 434 siginfo_t *info, struct k_sigaction *ka,
440 sigset_t *oldset, struct pt_regs * regs) 435 struct pt_regs * regs)
441{ 436{
437 sigset_t *oldset = sigmask_to_save();
442 int ret; 438 int ret;
443 439
444 /* Check if this got called from a system call. */ 440 /* Check if this got called from a system call. */
@@ -489,9 +485,7 @@ handle_signal(int canrestart, unsigned long sig,
489 ret = setup_frame(sig, ka, oldset, regs); 485 ret = setup_frame(sig, ka, oldset, regs);
490 486
491 if (ret == 0) 487 if (ret == 0)
492 block_sigmask(ka, sig); 488 signal_delivered(sig, info, ka, regs, 0);
493
494 return ret;
495} 489}
496 490
497/* 491/*
@@ -511,7 +505,6 @@ do_signal(int canrestart, struct pt_regs *regs)
511 int signr; 505 int signr;
512 siginfo_t info; 506 siginfo_t info;
513 struct k_sigaction ka; 507 struct k_sigaction ka;
514 sigset_t *oldset;
515 508
516 /* 509 /*
517 * The common case should go fast, which is why this point is 510 * The common case should go fast, which is why this point is
@@ -521,25 +514,11 @@ do_signal(int canrestart, struct pt_regs *regs)
521 if (!user_mode(regs)) 514 if (!user_mode(regs))
522 return; 515 return;
523 516
524 if (test_thread_flag(TIF_RESTORE_SIGMASK))
525 oldset = &current->saved_sigmask;
526 else
527 oldset = &current->blocked;
528
529 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 517 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
530 518
531 if (signr > 0) { 519 if (signr > 0) {
532 /* Whee! Actually deliver the signal. */ 520 /* Whee! Actually deliver the signal. */
533 if (handle_signal(canrestart, signr, &info, &ka, 521 handle_signal(canrestart, signr, &info, &ka, regs);
534 oldset, regs)) {
535 /* a signal was successfully delivered; the saved
536 * sigmask will have been stored in the signal frame,
537 * and will be restored by sigreturn, so we can simply
538 * clear the TIF_RESTORE_SIGMASK flag */
539 if (test_thread_flag(TIF_RESTORE_SIGMASK))
540 clear_thread_flag(TIF_RESTORE_SIGMASK);
541 }
542
543 return; 522 return;
544 } 523 }
545 524
@@ -560,10 +539,7 @@ do_signal(int canrestart, struct pt_regs *regs)
560 539
561 /* if there's no signal to deliver, we just put the saved sigmask 540 /* if there's no signal to deliver, we just put the saved sigmask
562 * back */ 541 * back */
563 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 542 restore_saved_sigmask();
564 clear_thread_flag(TIF_RESTORE_SIGMASK);
565 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
566 }
567} 543}
568 544
569asmlinkage void 545asmlinkage void
diff --git a/arch/frv/include/asm/thread_info.h b/arch/frv/include/asm/thread_info.h
index 54ab13a0de41..0ff03a33c81e 100644
--- a/arch/frv/include/asm/thread_info.h
+++ b/arch/frv/include/asm/thread_info.h
@@ -94,8 +94,8 @@ register struct thread_info *__current_thread_info asm("gr15");
94#define TIF_NEED_RESCHED 3 /* rescheduling necessary */ 94#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
95#define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */ 95#define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */
96#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */ 96#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */
97#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */ 97#define TIF_POLLING_NRFLAG 6 /* true if poll_idle() is polling TIF_NEED_RESCHED */
98#define TIF_MEMDIE 17 /* is terminating due to OOM killer */ 98#define TIF_MEMDIE 7 /* is terminating due to OOM killer */
99 99
100#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) 100#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
101#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME) 101#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
@@ -105,8 +105,16 @@ register struct thread_info *__current_thread_info asm("gr15");
105#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK) 105#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
106#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) 106#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
107 107
108#define _TIF_WORK_MASK 0x0000FFFE /* work to do on interrupt/exception return */ 108/* work to do on interrupt/exception return */
109#define _TIF_ALLWORK_MASK 0x0000FFFF /* work to do on any return to u-space */ 109#define _TIF_WORK_MASK \
110 (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_SINGLESTEP)
111
112/* work to do on any return to u-space */
113#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_SYSCALL_TRACE)
114
115#if _TIF_ALLWORK_MASK >= 0x2000
116#error "_TIF_ALLWORK_MASK won't fit in an ANDI now (see entry.S)"
117#endif
110 118
111/* 119/*
112 * Thread-synchronous status. 120 * Thread-synchronous status.
diff --git a/arch/frv/kernel/entry.S b/arch/frv/kernel/entry.S
index 5ba23f715ea5..7d5e000fd32e 100644
--- a/arch/frv/kernel/entry.S
+++ b/arch/frv/kernel/entry.S
@@ -905,18 +905,19 @@ __syscall_call:
905__syscall_exit: 905__syscall_exit:
906 LEDS 0x6300 906 LEDS 0x6300
907 907
908 sti gr8,@(gr28,#REG_GR(8)) ; save return value 908 # keep current PSR in GR23
909 movsg psr,gr23
909 910
910 # rebuild saved psr - execve will change it for init/main.c
911 ldi @(gr28,#REG_PSR),gr22 911 ldi @(gr28,#REG_PSR),gr22
912
913 sti.p gr8,@(gr28,#REG_GR(8)) ; save return value
914
915 # rebuild saved psr - execve will change it for init/main.c
912 srli gr22,#1,gr5 916 srli gr22,#1,gr5
913 andi.p gr22,#~PSR_PS,gr22 917 andi.p gr22,#~PSR_PS,gr22
914 andi gr5,#PSR_PS,gr5 918 andi gr5,#PSR_PS,gr5
915 or gr5,gr22,gr22 919 or gr5,gr22,gr22
916 ori gr22,#PSR_S,gr22 920 ori.p gr22,#PSR_S,gr22
917
918 # keep current PSR in GR23
919 movsg psr,gr23
920 921
921 # make sure we don't miss an interrupt setting need_resched or sigpending between 922 # make sure we don't miss an interrupt setting need_resched or sigpending between
922 # sampling and the RETT 923 # sampling and the RETT
@@ -924,9 +925,7 @@ __syscall_exit:
924 movgs gr23,psr 925 movgs gr23,psr
925 926
926 ldi @(gr15,#TI_FLAGS),gr4 927 ldi @(gr15,#TI_FLAGS),gr4
927 sethi.p %hi(_TIF_ALLWORK_MASK),gr5 928 andicc gr4,#_TIF_ALLWORK_MASK,gr0,icc0
928 setlo %lo(_TIF_ALLWORK_MASK),gr5
929 andcc gr4,gr5,gr0,icc0
930 bne icc0,#0,__syscall_exit_work 929 bne icc0,#0,__syscall_exit_work
931 930
932 # restore all registers and return 931 # restore all registers and return
@@ -1111,9 +1110,7 @@ __entry_resume_userspace:
1111__entry_return_from_user_interrupt: 1110__entry_return_from_user_interrupt:
1112 LEDS 0x6402 1111 LEDS 0x6402
1113 ldi @(gr15,#TI_FLAGS),gr4 1112 ldi @(gr15,#TI_FLAGS),gr4
1114 sethi.p %hi(_TIF_WORK_MASK),gr5 1113 andicc gr4,#_TIF_WORK_MASK,gr0,icc0
1115 setlo %lo(_TIF_WORK_MASK),gr5
1116 andcc gr4,gr5,gr0,icc0
1117 beq icc0,#1,__entry_return_direct 1114 beq icc0,#1,__entry_return_direct
1118 1115
1119__entry_work_pending: 1116__entry_work_pending:
@@ -1133,9 +1130,7 @@ __entry_work_resched:
1133 1130
1134 LEDS 0x6401 1131 LEDS 0x6401
1135 ldi @(gr15,#TI_FLAGS),gr4 1132 ldi @(gr15,#TI_FLAGS),gr4
1136 sethi.p %hi(_TIF_WORK_MASK),gr5 1133 andicc gr4,#_TIF_WORK_MASK,gr0,icc0
1137 setlo %lo(_TIF_WORK_MASK),gr5
1138 andcc gr4,gr5,gr0,icc0
1139 beq icc0,#1,__entry_return_direct 1134 beq icc0,#1,__entry_return_direct
1140 andicc gr4,#_TIF_NEED_RESCHED,gr0,icc0 1135 andicc gr4,#_TIF_NEED_RESCHED,gr0,icc0
1141 bne icc0,#1,__entry_work_resched 1136 bne icc0,#1,__entry_work_resched
@@ -1163,7 +1158,9 @@ __syscall_trace_entry:
1163 # perform syscall exit tracing 1158 # perform syscall exit tracing
1164__syscall_exit_work: 1159__syscall_exit_work:
1165 LEDS 0x6340 1160 LEDS 0x6340
1166 andicc gr4,#_TIF_SYSCALL_TRACE,gr0,icc0 1161 andicc gr22,#PSR_PS,gr0,icc1 ; don't handle on return to kernel mode
1162 andicc.p gr4,#_TIF_SYSCALL_TRACE,gr0,icc0
1163 bne icc1,#0,__entry_return_direct
1167 beq icc0,#1,__entry_work_pending 1164 beq icc0,#1,__entry_work_pending
1168 1165
1169 movsg psr,gr23 1166 movsg psr,gr23
diff --git a/arch/frv/kernel/signal.c b/arch/frv/kernel/signal.c
index 595bf1e5a5dc..f3b9064c548c 100644
--- a/arch/frv/kernel/signal.c
+++ b/arch/frv/kernel/signal.c
@@ -28,8 +28,6 @@
28 28
29#define DEBUG_SIG 0 29#define DEBUG_SIG 0
30 30
31#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
32
33struct fdpic_func_descriptor { 31struct fdpic_func_descriptor {
34 unsigned long text; 32 unsigned long text;
35 unsigned long GOT; 33 unsigned long GOT;
@@ -149,7 +147,6 @@ asmlinkage int sys_sigreturn(void)
149 __copy_from_user(&set.sig[1], &frame->extramask, sizeof(frame->extramask))) 147 __copy_from_user(&set.sig[1], &frame->extramask, sizeof(frame->extramask)))
150 goto badframe; 148 goto badframe;
151 149
152 sigdelsetmask(&set, ~_BLOCKABLE);
153 set_current_blocked(&set); 150 set_current_blocked(&set);
154 151
155 if (restore_sigcontext(&frame->sc, &gr8)) 152 if (restore_sigcontext(&frame->sc, &gr8))
@@ -172,7 +169,6 @@ asmlinkage int sys_rt_sigreturn(void)
172 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 169 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
173 goto badframe; 170 goto badframe;
174 171
175 sigdelsetmask(&set, ~_BLOCKABLE);
176 set_current_blocked(&set); 172 set_current_blocked(&set);
177 173
178 if (restore_sigcontext(&frame->uc.uc_mcontext, &gr8)) 174 if (restore_sigcontext(&frame->uc.uc_mcontext, &gr8))
@@ -426,9 +422,10 @@ give_sigsegv:
426/* 422/*
427 * OK, we're invoking a handler 423 * OK, we're invoking a handler
428 */ 424 */
429static int handle_signal(unsigned long sig, siginfo_t *info, 425static void handle_signal(unsigned long sig, siginfo_t *info,
430 struct k_sigaction *ka, sigset_t *oldset) 426 struct k_sigaction *ka)
431{ 427{
428 sigset_t *oldset = sigmask_to_save();
432 int ret; 429 int ret;
433 430
434 /* Are we from a system call? */ 431 /* Are we from a system call? */
@@ -460,11 +457,11 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
460 else 457 else
461 ret = setup_frame(sig, ka, oldset); 458 ret = setup_frame(sig, ka, oldset);
462 459
463 if (ret == 0) 460 if (ret)
464 block_sigmask(ka, sig); 461 return;
465
466 return ret;
467 462
463 signal_delivered(sig, info, ka, __frame,
464 test_thread_flag(TIF_SINGLESTEP));
468} /* end handle_signal() */ 465} /* end handle_signal() */
469 466
470/*****************************************************************************/ 467/*****************************************************************************/
@@ -477,44 +474,14 @@ static void do_signal(void)
477{ 474{
478 struct k_sigaction ka; 475 struct k_sigaction ka;
479 siginfo_t info; 476 siginfo_t info;
480 sigset_t *oldset;
481 int signr; 477 int signr;
482 478
483 /*
484 * We want the common case to go fast, which
485 * is why we may in certain cases get here from
486 * kernel mode. Just return without doing anything
487 * if so.
488 */
489 if (!user_mode(__frame))
490 return;
491
492 if (try_to_freeze())
493 goto no_signal;
494
495 if (test_thread_flag(TIF_RESTORE_SIGMASK))
496 oldset = &current->saved_sigmask;
497 else
498 oldset = &current->blocked;
499
500 signr = get_signal_to_deliver(&info, &ka, __frame, NULL); 479 signr = get_signal_to_deliver(&info, &ka, __frame, NULL);
501 if (signr > 0) { 480 if (signr > 0) {
502 if (handle_signal(signr, &info, &ka, oldset) == 0) { 481 handle_signal(signr, &info, &ka);
503 /* a signal was successfully delivered; the saved
504 * sigmask will have been stored in the signal frame,
505 * and will be restored by sigreturn, so we can simply
506 * clear the TIF_RESTORE_SIGMASK flag */
507 if (test_thread_flag(TIF_RESTORE_SIGMASK))
508 clear_thread_flag(TIF_RESTORE_SIGMASK);
509
510 tracehook_signal_handler(signr, &info, &ka, __frame,
511 test_thread_flag(TIF_SINGLESTEP));
512 }
513
514 return; 482 return;
515 } 483 }
516 484
517no_signal:
518 /* Did we come from a system call? */ 485 /* Did we come from a system call? */
519 if (__frame->syscallno != -1) { 486 if (__frame->syscallno != -1) {
520 /* Restart the system call - no handlers present */ 487 /* Restart the system call - no handlers present */
@@ -536,11 +503,7 @@ no_signal:
536 503
537 /* if there's no signal to deliver, we just put the saved sigmask 504 /* if there's no signal to deliver, we just put the saved sigmask
538 * back */ 505 * back */
539 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 506 restore_saved_sigmask();
540 clear_thread_flag(TIF_RESTORE_SIGMASK);
541 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
542 }
543
544} /* end do_signal() */ 507} /* end do_signal() */
545 508
546/*****************************************************************************/ 509/*****************************************************************************/
@@ -555,7 +518,7 @@ asmlinkage void do_notify_resume(__u32 thread_info_flags)
555 clear_thread_flag(TIF_SINGLESTEP); 518 clear_thread_flag(TIF_SINGLESTEP);
556 519
557 /* deal with pending signal delivery */ 520 /* deal with pending signal delivery */
558 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 521 if (thread_info_flags & _TIF_SIGPENDING))
559 do_signal(); 522 do_signal();
560 523
561 /* deal with notification on about to resume userspace execution */ 524 /* deal with notification on about to resume userspace execution */
diff --git a/arch/h8300/kernel/signal.c b/arch/h8300/kernel/signal.c
index e58992ad789e..fca10378701b 100644
--- a/arch/h8300/kernel/signal.c
+++ b/arch/h8300/kernel/signal.c
@@ -47,8 +47,6 @@
47#include <asm/traps.h> 47#include <asm/traps.h>
48#include <asm/ucontext.h> 48#include <asm/ucontext.h>
49 49
50#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
51
52/* 50/*
53 * Atomically swap in the new signal mask, and wait for a signal. 51 * Atomically swap in the new signal mask, and wait for a signal.
54 */ 52 */
@@ -186,7 +184,6 @@ asmlinkage int do_sigreturn(unsigned long __unused,...)
186 sizeof(frame->extramask)))) 184 sizeof(frame->extramask))))
187 goto badframe; 185 goto badframe;
188 186
189 sigdelsetmask(&set, ~_BLOCKABLE);
190 set_current_blocked(&set); 187 set_current_blocked(&set);
191 188
192 if (restore_sigcontext(regs, &frame->sc, &er0)) 189 if (restore_sigcontext(regs, &frame->sc, &er0))
@@ -211,7 +208,6 @@ asmlinkage int do_rt_sigreturn(unsigned long __unused,...)
211 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 208 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
212 goto badframe; 209 goto badframe;
213 210
214 sigdelsetmask(&set, ~_BLOCKABLE);
215 set_current_blocked(&set); 211 set_current_blocked(&set);
216 212
217 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &er0)) 213 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &er0))
@@ -412,8 +408,9 @@ give_sigsegv:
412 */ 408 */
413static void 409static void
414handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, 410handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
415 sigset_t *oldset, struct pt_regs * regs) 411 struct pt_regs * regs)
416{ 412{
413 sigset_t *oldset = sigmask_to_save();
417 int ret; 414 int ret;
418 /* are we from a system call? */ 415 /* are we from a system call? */
419 if (regs->orig_er0 >= 0) { 416 if (regs->orig_er0 >= 0) {
@@ -441,10 +438,8 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
441 else 438 else
442 ret = setup_frame(sig, ka, oldset, regs); 439 ret = setup_frame(sig, ka, oldset, regs);
443 440
444 if (!ret) { 441 if (!ret)
445 block_sigmask(ka, sig); 442 signal_delivered(sig, info, ka, regs, 0);
446 clear_thread_flag(TIF_RESTORE_SIGMASK);
447 }
448} 443}
449 444
450/* 445/*
@@ -457,7 +452,6 @@ statis void do_signal(struct pt_regs *regs)
457 siginfo_t info; 452 siginfo_t info;
458 int signr; 453 int signr;
459 struct k_sigaction ka; 454 struct k_sigaction ka;
460 sigset_t *oldset;
461 455
462 /* 456 /*
463 * We want the common case to go fast, which 457 * We want the common case to go fast, which
@@ -468,23 +462,14 @@ statis void do_signal(struct pt_regs *regs)
468 if ((regs->ccr & 0x10)) 462 if ((regs->ccr & 0x10))
469 return; 463 return;
470 464
471 if (try_to_freeze())
472 goto no_signal;
473
474 current->thread.esp0 = (unsigned long) regs; 465 current->thread.esp0 = (unsigned long) regs;
475 466
476 if (test_thread_flag(TIF_RESTORE_SIGMASK))
477 oldset = &current->saved_sigmask;
478 else
479 oldset = &current->blocked;
480
481 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 467 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
482 if (signr > 0) { 468 if (signr > 0) {
483 /* Whee! Actually deliver the signal. */ 469 /* Whee! Actually deliver the signal. */
484 handle_signal(signr, &info, &ka, oldset, regs); 470 handle_signal(signr, &info, &ka, regs);
485 return; 471 return;
486 } 472 }
487 no_signal:
488 /* Did we come from a system call? */ 473 /* Did we come from a system call? */
489 if (regs->orig_er0 >= 0) { 474 if (regs->orig_er0 >= 0) {
490 /* Restart the system call - no handlers present */ 475 /* Restart the system call - no handlers present */
@@ -501,8 +486,7 @@ statis void do_signal(struct pt_regs *regs)
501 } 486 }
502 487
503 /* If there's no signal to deliver, we just restore the saved mask. */ 488 /* If there's no signal to deliver, we just restore the saved mask. */
504 if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK)) 489 restore_saved_sigmask();
505 set_current_blocked(&current->saved_sigmask);
506} 490}
507 491
508asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags) 492asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags)
diff --git a/arch/hexagon/kernel/signal.c b/arch/hexagon/kernel/signal.c
index 21a3018cb9bf..304b0808d072 100644
--- a/arch/hexagon/kernel/signal.c
+++ b/arch/hexagon/kernel/signal.c
@@ -31,8 +31,6 @@
31#include <asm/signal.h> 31#include <asm/signal.h>
32#include <asm/vdso.h> 32#include <asm/vdso.h>
33 33
34#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
35
36struct rt_sigframe { 34struct rt_sigframe {
37 unsigned long tramp[2]; 35 unsigned long tramp[2];
38 struct siginfo info; 36 struct siginfo info;
@@ -149,11 +147,9 @@ sigsegv:
149/* 147/*
150 * Setup invocation of signal handler 148 * Setup invocation of signal handler
151 */ 149 */
152static int handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka, 150static void handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka,
153 sigset_t *oldset, struct pt_regs *regs) 151 struct pt_regs *regs)
154{ 152{
155 int rc;
156
157 /* 153 /*
158 * If we're handling a signal that aborted a system call, 154 * If we're handling a signal that aborted a system call,
159 * set up the error return value before adding the signal 155 * set up the error return value before adding the signal
@@ -186,15 +182,12 @@ static int handle_signal(int sig, siginfo_t *info, struct k_sigaction *ka,
186 * Set up the stack frame; not doing the SA_SIGINFO thing. We 182 * Set up the stack frame; not doing the SA_SIGINFO thing. We
187 * only set up the rt_frame flavor. 183 * only set up the rt_frame flavor.
188 */ 184 */
189 rc = setup_rt_frame(sig, ka, info, oldset, regs);
190
191 /* If there was an error on setup, no signal was delivered. */ 185 /* If there was an error on setup, no signal was delivered. */
192 if (rc) 186 if (setup_rt_frame(sig, ka, info, sigmask_to_save(), regs) < 0)
193 return rc; 187 return;
194
195 block_sigmask(ka, sig);
196 188
197 return 0; 189 signal_delivered(sig, info, ka, regs,
190 test_thread_flag(TIF_SINGLESTEP));
198} 191}
199 192
200/* 193/*
@@ -209,34 +202,13 @@ static void do_signal(struct pt_regs *regs)
209 if (!user_mode(regs)) 202 if (!user_mode(regs))
210 return; 203 return;
211 204
212 if (try_to_freeze())
213 goto no_signal;
214
215 signo = get_signal_to_deliver(&info, &sigact, regs, NULL); 205 signo = get_signal_to_deliver(&info, &sigact, regs, NULL);
216 206
217 if (signo > 0) { 207 if (signo > 0) {
218 sigset_t *oldset; 208 handle_signal(signo, &info, &sigact, regs);
219
220 if (test_thread_flag(TIF_RESTORE_SIGMASK))
221 oldset = &current->saved_sigmask;
222 else
223 oldset = &current->blocked;
224
225 if (handle_signal(signo, &info, &sigact, oldset, regs) == 0) {
226 /*
227 * Successful delivery case. The saved sigmask is
228 * stored in the signal frame, and will be restored
229 * by sigreturn. We can clear the TIF flag.
230 */
231 clear_thread_flag(TIF_RESTORE_SIGMASK);
232
233 tracehook_signal_handler(signo, &info, &sigact, regs,
234 test_thread_flag(TIF_SINGLESTEP));
235 }
236 return; 209 return;
237 } 210 }
238 211
239no_signal:
240 /* 212 /*
241 * If we came from a system call, handle the restart. 213 * If we came from a system call, handle the restart.
242 */ 214 */
@@ -259,10 +231,7 @@ no_signal:
259 231
260no_restart: 232no_restart:
261 /* If there's no signal to deliver, put the saved sigmask back */ 233 /* If there's no signal to deliver, put the saved sigmask back */
262 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 234 restore_saved_sigmask();
263 clear_thread_flag(TIF_RESTORE_SIGMASK);
264 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
265 }
266} 235}
267 236
268void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags) 237void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
@@ -301,7 +270,6 @@ asmlinkage int sys_rt_sigreturn(void)
301 if (__copy_from_user(&blocked, &frame->uc.uc_sigmask, sizeof(blocked))) 270 if (__copy_from_user(&blocked, &frame->uc.uc_sigmask, sizeof(blocked)))
302 goto badframe; 271 goto badframe;
303 272
304 sigdelsetmask(&blocked, ~_BLOCKABLE);
305 set_current_blocked(&blocked); 273 set_current_blocked(&blocked);
306 274
307 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 275 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
diff --git a/arch/ia64/include/asm/thread_info.h b/arch/ia64/include/asm/thread_info.h
index 310d9734f02d..f7ee85378311 100644
--- a/arch/ia64/include/asm/thread_info.h
+++ b/arch/ia64/include/asm/thread_info.h
@@ -141,7 +141,23 @@ static inline void set_restore_sigmask(void)
141{ 141{
142 struct thread_info *ti = current_thread_info(); 142 struct thread_info *ti = current_thread_info();
143 ti->status |= TS_RESTORE_SIGMASK; 143 ti->status |= TS_RESTORE_SIGMASK;
144 set_bit(TIF_SIGPENDING, &ti->flags); 144 WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
145}
146static inline void clear_restore_sigmask(void)
147{
148 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
149}
150static inline bool test_restore_sigmask(void)
151{
152 return current_thread_info()->status & TS_RESTORE_SIGMASK;
153}
154static inline bool test_and_clear_restore_sigmask(void)
155{
156 struct thread_info *ti = current_thread_info();
157 if (!(ti->status & TS_RESTORE_SIGMASK))
158 return false;
159 ti->status &= ~TS_RESTORE_SIGMASK;
160 return true;
145} 161}
146#endif /* !__ASSEMBLY__ */ 162#endif /* !__ASSEMBLY__ */
147 163
diff --git a/arch/ia64/kernel/signal.c b/arch/ia64/kernel/signal.c
index 7523501d3bc0..a199be1fe619 100644
--- a/arch/ia64/kernel/signal.c
+++ b/arch/ia64/kernel/signal.c
@@ -30,7 +30,6 @@
30 30
31#define DEBUG_SIG 0 31#define DEBUG_SIG 0
32#define STACK_ALIGN 16 /* minimal alignment for stack pointer */ 32#define STACK_ALIGN 16 /* minimal alignment for stack pointer */
33#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
34 33
35#if _NSIG_WORDS > 1 34#if _NSIG_WORDS > 1
36# define PUT_SIGSET(k,u) __copy_to_user((u)->sig, (k)->sig, sizeof(sigset_t)) 35# define PUT_SIGSET(k,u) __copy_to_user((u)->sig, (k)->sig, sizeof(sigset_t))
@@ -200,7 +199,6 @@ ia64_rt_sigreturn (struct sigscratch *scr)
200 if (GET_SIGSET(&set, &sc->sc_mask)) 199 if (GET_SIGSET(&set, &sc->sc_mask))
201 goto give_sigsegv; 200 goto give_sigsegv;
202 201
203 sigdelsetmask(&set, ~_BLOCKABLE);
204 set_current_blocked(&set); 202 set_current_blocked(&set);
205 203
206 if (restore_sigcontext(sc, scr)) 204 if (restore_sigcontext(sc, scr))
@@ -415,18 +413,13 @@ setup_frame (int sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *set,
415} 413}
416 414
417static long 415static long
418handle_signal (unsigned long sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *oldset, 416handle_signal (unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
419 struct sigscratch *scr) 417 struct sigscratch *scr)
420{ 418{
421 if (!setup_frame(sig, ka, info, oldset, scr)) 419 if (!setup_frame(sig, ka, info, sigmask_to_save(), scr))
422 return 0; 420 return 0;
423 421
424 block_sigmask(ka, sig); 422 signal_delivered(sig, info, ka, &scr->pt,
425
426 /*
427 * Let tracing know that we've done the handler setup.
428 */
429 tracehook_signal_handler(sig, info, ka, &scr->pt,
430 test_thread_flag(TIF_SINGLESTEP)); 423 test_thread_flag(TIF_SINGLESTEP));
431 424
432 return 1; 425 return 1;
@@ -440,7 +433,6 @@ void
440ia64_do_signal (struct sigscratch *scr, long in_syscall) 433ia64_do_signal (struct sigscratch *scr, long in_syscall)
441{ 434{
442 struct k_sigaction ka; 435 struct k_sigaction ka;
443 sigset_t *oldset;
444 siginfo_t info; 436 siginfo_t info;
445 long restart = in_syscall; 437 long restart = in_syscall;
446 long errno = scr->pt.r8; 438 long errno = scr->pt.r8;
@@ -453,11 +445,6 @@ ia64_do_signal (struct sigscratch *scr, long in_syscall)
453 if (!user_mode(&scr->pt)) 445 if (!user_mode(&scr->pt))
454 return; 446 return;
455 447
456 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
457 oldset = &current->saved_sigmask;
458 else
459 oldset = &current->blocked;
460
461 /* 448 /*
462 * This only loops in the rare cases of handle_signal() failing, in which case we 449 * This only loops in the rare cases of handle_signal() failing, in which case we
463 * need to push through a forced SIGSEGV. 450 * need to push through a forced SIGSEGV.
@@ -507,16 +494,8 @@ ia64_do_signal (struct sigscratch *scr, long in_syscall)
507 * Whee! Actually deliver the signal. If the delivery failed, we need to 494 * Whee! Actually deliver the signal. If the delivery failed, we need to
508 * continue to iterate in this loop so we can deliver the SIGSEGV... 495 * continue to iterate in this loop so we can deliver the SIGSEGV...
509 */ 496 */
510 if (handle_signal(signr, &ka, &info, oldset, scr)) { 497 if (handle_signal(signr, &ka, &info, scr))
511 /*
512 * A signal was successfully delivered; the saved
513 * sigmask will have been stored in the signal frame,
514 * and will be restored by sigreturn, so we can simply
515 * clear the TS_RESTORE_SIGMASK flag.
516 */
517 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
518 return; 498 return;
519 }
520 } 499 }
521 500
522 /* Did we come from a system call? */ 501 /* Did we come from a system call? */
@@ -538,8 +517,5 @@ ia64_do_signal (struct sigscratch *scr, long in_syscall)
538 517
539 /* if there's no signal to deliver, we just put the saved sigmask 518 /* if there's no signal to deliver, we just put the saved sigmask
540 * back */ 519 * back */
541 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 520 restore_saved_sigmask();
542 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
543 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
544 }
545} 521}
diff --git a/arch/m32r/kernel/signal.c b/arch/m32r/kernel/signal.c
index 64804f1f5141..f3fb2c029cfc 100644
--- a/arch/m32r/kernel/signal.c
+++ b/arch/m32r/kernel/signal.c
@@ -28,8 +28,6 @@
28 28
29#define DEBUG_SIG 0 29#define DEBUG_SIG 0
30 30
31#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
32
33asmlinkage int 31asmlinkage int
34sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, 32sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
35 unsigned long r2, unsigned long r3, unsigned long r4, 33 unsigned long r2, unsigned long r3, unsigned long r4,
@@ -111,7 +109,6 @@ sys_rt_sigreturn(unsigned long r0, unsigned long r1,
111 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 109 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
112 goto badframe; 110 goto badframe;
113 111
114 sigdelsetmask(&set, ~_BLOCKABLE);
115 set_current_blocked(&set); 112 set_current_blocked(&set);
116 113
117 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &result)) 114 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &result))
@@ -267,9 +264,9 @@ static int prev_insn(struct pt_regs *regs)
267 * OK, we're invoking a handler 264 * OK, we're invoking a handler
268 */ 265 */
269 266
270static int 267static void
271handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info, 268handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
272 sigset_t *oldset, struct pt_regs *regs) 269 struct pt_regs *regs)
273{ 270{
274 /* Are we from a system call? */ 271 /* Are we from a system call? */
275 if (regs->syscall_nr >= 0) { 272 if (regs->syscall_nr >= 0) {
@@ -294,11 +291,10 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
294 } 291 }
295 292
296 /* Set up the stack frame */ 293 /* Set up the stack frame */
297 if (setup_rt_frame(sig, ka, info, oldset, regs)) 294 if (setup_rt_frame(sig, ka, info, sigmask_to_save(), regs))
298 return -EFAULT; 295 return;
299 296
300 block_sigmask(ka, sig); 297 signal_delivered(sig, info, ka, regs, 0);
301 return 0;
302} 298}
303 299
304/* 300/*
@@ -311,7 +307,6 @@ static void do_signal(struct pt_regs *regs)
311 siginfo_t info; 307 siginfo_t info;
312 int signr; 308 int signr;
313 struct k_sigaction ka; 309 struct k_sigaction ka;
314 sigset_t *oldset;
315 310
316 /* 311 /*
317 * We want the common case to go fast, which 312 * We want the common case to go fast, which
@@ -322,14 +317,6 @@ static void do_signal(struct pt_regs *regs)
322 if (!user_mode(regs)) 317 if (!user_mode(regs))
323 return; 318 return;
324 319
325 if (try_to_freeze())
326 goto no_signal;
327
328 if (test_thread_flag(TIF_RESTORE_SIGMASK))
329 oldset = &current->saved_sigmask;
330 else
331 oldset = &current->blocked;
332
333 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 320 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
334 if (signr > 0) { 321 if (signr > 0) {
335 /* Re-enable any watchpoints before delivering the 322 /* Re-enable any watchpoints before delivering the
@@ -339,13 +326,11 @@ static void do_signal(struct pt_regs *regs)
339 */ 326 */
340 327
341 /* Whee! Actually deliver the signal. */ 328 /* Whee! Actually deliver the signal. */
342 if (handle_signal(signr, &ka, &info, oldset, regs) == 0) 329 handle_signal(signr, &ka, &info, regs);
343 clear_thread_flag(TIF_RESTORE_SIGMASK);
344 330
345 return; 331 return;
346 } 332 }
347 333
348 no_signal:
349 /* Did we come from a system call? */ 334 /* Did we come from a system call? */
350 if (regs->syscall_nr >= 0) { 335 if (regs->syscall_nr >= 0) {
351 /* Restart the system call - no handlers present */ 336 /* Restart the system call - no handlers present */
@@ -360,10 +345,7 @@ static void do_signal(struct pt_regs *regs)
360 prev_insn(regs); 345 prev_insn(regs);
361 } 346 }
362 } 347 }
363 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 348 restore_saved_sigmask();
364 clear_thread_flag(TIF_RESTORE_SIGMASK);
365 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
366 }
367} 349}
368 350
369/* 351/*
diff --git a/arch/m68k/kernel/signal.c b/arch/m68k/kernel/signal.c
index 973eec60cad4..710a528b928b 100644
--- a/arch/m68k/kernel/signal.c
+++ b/arch/m68k/kernel/signal.c
@@ -51,8 +51,6 @@
51#include <asm/traps.h> 51#include <asm/traps.h>
52#include <asm/ucontext.h> 52#include <asm/ucontext.h>
53 53
54#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
55
56#ifdef CONFIG_MMU 54#ifdef CONFIG_MMU
57 55
58/* 56/*
@@ -795,7 +793,6 @@ asmlinkage int do_sigreturn(unsigned long __unused)
795 sizeof(frame->extramask)))) 793 sizeof(frame->extramask))))
796 goto badframe; 794 goto badframe;
797 795
798 sigdelsetmask(&set, ~_BLOCKABLE);
799 set_current_blocked(&set); 796 set_current_blocked(&set);
800 797
801 if (restore_sigcontext(regs, &frame->sc, frame + 1)) 798 if (restore_sigcontext(regs, &frame->sc, frame + 1))
@@ -820,7 +817,6 @@ asmlinkage int do_rt_sigreturn(unsigned long __unused)
820 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 817 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
821 goto badframe; 818 goto badframe;
822 819
823 sigdelsetmask(&set, ~_BLOCKABLE);
824 set_current_blocked(&set); 820 set_current_blocked(&set);
825 821
826 if (rt_restore_ucontext(regs, sw, &frame->uc)) 822 if (rt_restore_ucontext(regs, sw, &frame->uc))
@@ -1123,8 +1119,9 @@ handle_restart(struct pt_regs *regs, struct k_sigaction *ka, int has_handler)
1123 */ 1119 */
1124static void 1120static void
1125handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info, 1121handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
1126 sigset_t *oldset, struct pt_regs *regs) 1122 struct pt_regs *regs)
1127{ 1123{
1124 sigset_t *oldset = sigmask_to_save();
1128 int err; 1125 int err;
1129 /* are we from a system call? */ 1126 /* are we from a system call? */
1130 if (regs->orig_d0 >= 0) 1127 if (regs->orig_d0 >= 0)
@@ -1140,14 +1137,12 @@ handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info,
1140 if (err) 1137 if (err)
1141 return; 1138 return;
1142 1139
1143 block_sigmask(ka, sig); 1140 signal_delivered(sig, info, ka, regs, 0);
1144 1141
1145 if (test_thread_flag(TIF_DELAYED_TRACE)) { 1142 if (test_thread_flag(TIF_DELAYED_TRACE)) {
1146 regs->sr &= ~0x8000; 1143 regs->sr &= ~0x8000;
1147 send_sig(SIGTRAP, current, 1); 1144 send_sig(SIGTRAP, current, 1);
1148 } 1145 }
1149
1150 clear_thread_flag(TIF_RESTORE_SIGMASK);
1151} 1146}
1152 1147
1153/* 1148/*
@@ -1160,19 +1155,13 @@ static void do_signal(struct pt_regs *regs)
1160 siginfo_t info; 1155 siginfo_t info;
1161 struct k_sigaction ka; 1156 struct k_sigaction ka;
1162 int signr; 1157 int signr;
1163 sigset_t *oldset;
1164 1158
1165 current->thread.esp0 = (unsigned long) regs; 1159 current->thread.esp0 = (unsigned long) regs;
1166 1160
1167 if (test_thread_flag(TIF_RESTORE_SIGMASK))
1168 oldset = &current->saved_sigmask;
1169 else
1170 oldset = &current->blocked;
1171
1172 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 1161 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
1173 if (signr > 0) { 1162 if (signr > 0) {
1174 /* Whee! Actually deliver the signal. */ 1163 /* Whee! Actually deliver the signal. */
1175 handle_signal(signr, &ka, &info, oldset, regs); 1164 handle_signal(signr, &ka, &info, regs);
1176 return; 1165 return;
1177 } 1166 }
1178 1167
@@ -1182,10 +1171,7 @@ static void do_signal(struct pt_regs *regs)
1182 handle_restart(regs, NULL, 0); 1171 handle_restart(regs, NULL, 0);
1183 1172
1184 /* If there's no signal to deliver, we just restore the saved mask. */ 1173 /* If there's no signal to deliver, we just restore the saved mask. */
1185 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 1174 restore_saved_sigmask();
1186 clear_thread_flag(TIF_RESTORE_SIGMASK);
1187 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
1188 }
1189} 1175}
1190 1176
1191void do_notify_resume(struct pt_regs *regs) 1177void do_notify_resume(struct pt_regs *regs)
diff --git a/arch/microblaze/include/asm/thread_info.h b/arch/microblaze/include/asm/thread_info.h
index 1a8ab6a5c03f..6c610234ffab 100644
--- a/arch/microblaze/include/asm/thread_info.h
+++ b/arch/microblaze/include/asm/thread_info.h
@@ -166,7 +166,23 @@ static inline void set_restore_sigmask(void)
166{ 166{
167 struct thread_info *ti = current_thread_info(); 167 struct thread_info *ti = current_thread_info();
168 ti->status |= TS_RESTORE_SIGMASK; 168 ti->status |= TS_RESTORE_SIGMASK;
169 set_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags); 169 WARN_ON(!test_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags));
170}
171static inline void clear_restore_sigmask(void)
172{
173 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
174}
175static inline bool test_restore_sigmask(void)
176{
177 return current_thread_info()->status & TS_RESTORE_SIGMASK;
178}
179static inline bool test_and_clear_restore_sigmask(void)
180{
181 struct thread_info *ti = current_thread_info();
182 if (!(ti->status & TS_RESTORE_SIGMASK))
183 return false;
184 ti->status &= ~TS_RESTORE_SIGMASK;
185 return true;
170} 186}
171#endif 187#endif
172 188
diff --git a/arch/microblaze/kernel/signal.c b/arch/microblaze/kernel/signal.c
index 5d796e32786e..76b9722557db 100644
--- a/arch/microblaze/kernel/signal.c
+++ b/arch/microblaze/kernel/signal.c
@@ -41,8 +41,6 @@
41#include <asm/cacheflush.h> 41#include <asm/cacheflush.h>
42#include <asm/syscalls.h> 42#include <asm/syscalls.h>
43 43
44#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
45
46asmlinkage long 44asmlinkage long
47sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, 45sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
48 struct pt_regs *regs) 46 struct pt_regs *regs)
@@ -106,7 +104,6 @@ asmlinkage long sys_rt_sigreturn(struct pt_regs *regs)
106 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 104 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
107 goto badframe; 105 goto badframe;
108 106
109 sigdelsetmask(&set, ~_BLOCKABLE);
110 set_current_blocked(&set); 107 set_current_blocked(&set);
111 108
112 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &rval)) 109 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &rval))
@@ -310,10 +307,11 @@ do_restart:
310 * OK, we're invoking a handler 307 * OK, we're invoking a handler
311 */ 308 */
312 309
313static int 310static void
314handle_signal(unsigned long sig, struct k_sigaction *ka, 311handle_signal(unsigned long sig, struct k_sigaction *ka,
315 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) 312 siginfo_t *info, struct pt_regs *regs)
316{ 313{
314 sigset_t *oldset = sigmask_to_save();
317 int ret; 315 int ret;
318 316
319 /* Set up the stack frame */ 317 /* Set up the stack frame */
@@ -323,11 +321,9 @@ handle_signal(unsigned long sig, struct k_sigaction *ka,
323 ret = setup_rt_frame(sig, ka, NULL, oldset, regs); 321 ret = setup_rt_frame(sig, ka, NULL, oldset, regs);
324 322
325 if (ret) 323 if (ret)
326 return ret; 324 return;
327
328 block_sigmask(ka, sig);
329 325
330 return 0; 326 signal_delivered(sig, info, ka, regs, 0);
331} 327}
332 328
333/* 329/*
@@ -344,33 +340,18 @@ static void do_signal(struct pt_regs *regs, int in_syscall)
344 siginfo_t info; 340 siginfo_t info;
345 int signr; 341 int signr;
346 struct k_sigaction ka; 342 struct k_sigaction ka;
347 sigset_t *oldset;
348#ifdef DEBUG_SIG 343#ifdef DEBUG_SIG
349 printk(KERN_INFO "do signal: %p %d\n", regs, in_syscall); 344 printk(KERN_INFO "do signal: %p %d\n", regs, in_syscall);
350 printk(KERN_INFO "do signal2: %lx %lx %ld [%lx]\n", regs->pc, regs->r1, 345 printk(KERN_INFO "do signal2: %lx %lx %ld [%lx]\n", regs->pc, regs->r1,
351 regs->r12, current_thread_info()->flags); 346 regs->r12, current_thread_info()->flags);
352#endif 347#endif
353 348
354 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
355 oldset = &current->saved_sigmask;
356 else
357 oldset = &current->blocked;
358
359 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 349 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
360 if (signr > 0) { 350 if (signr > 0) {
361 /* Whee! Actually deliver the signal. */ 351 /* Whee! Actually deliver the signal. */
362 if (in_syscall) 352 if (in_syscall)
363 handle_restart(regs, &ka, 1); 353 handle_restart(regs, &ka, 1);
364 if (!handle_signal(signr, &ka, &info, oldset, regs)) { 354 handle_signal(signr, &ka, &info, regs);
365 /*
366 * A signal was successfully delivered; the saved
367 * sigmask will have been stored in the signal frame,
368 * and will be restored by sigreturn, so we can simply
369 * clear the TS_RESTORE_SIGMASK flag.
370 */
371 current_thread_info()->status &=
372 ~TS_RESTORE_SIGMASK;
373 }
374 return; 355 return;
375 } 356 }
376 357
@@ -381,10 +362,7 @@ static void do_signal(struct pt_regs *regs, int in_syscall)
381 * If there's no signal to deliver, we just put the saved sigmask 362 * If there's no signal to deliver, we just put the saved sigmask
382 * back. 363 * back.
383 */ 364 */
384 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 365 restore_saved_sigmask();
385 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
386 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
387 }
388} 366}
389 367
390void do_notify_resume(struct pt_regs *regs, int in_syscall) 368void do_notify_resume(struct pt_regs *regs, int in_syscall)
diff --git a/arch/mips/kernel/signal-common.h b/arch/mips/kernel/signal-common.h
index 10263b405981..9c60d09e62a7 100644
--- a/arch/mips/kernel/signal-common.h
+++ b/arch/mips/kernel/signal-common.h
@@ -19,8 +19,6 @@
19# define DEBUGP(fmt, args...) 19# define DEBUGP(fmt, args...)
20#endif 20#endif
21 21
22#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
23
24/* 22/*
25 * Determine which stack to use.. 23 * Determine which stack to use..
26 */ 24 */
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 8a6e6d116ab0..f2c09cfc60ac 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -339,7 +339,6 @@ asmlinkage void sys_sigreturn(nabi_no_regargs struct pt_regs regs)
339 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked))) 339 if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
340 goto badframe; 340 goto badframe;
341 341
342 sigdelsetmask(&blocked, ~_BLOCKABLE);
343 set_current_blocked(&blocked); 342 set_current_blocked(&blocked);
344 343
345 sig = restore_sigcontext(&regs, &frame->sf_sc); 344 sig = restore_sigcontext(&regs, &frame->sf_sc);
@@ -375,7 +374,6 @@ asmlinkage void sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
375 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set))) 374 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
376 goto badframe; 375 goto badframe;
377 376
378 sigdelsetmask(&set, ~_BLOCKABLE);
379 set_current_blocked(&set); 377 set_current_blocked(&set);
380 378
381 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext); 379 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext);
@@ -514,9 +512,10 @@ struct mips_abi mips_abi = {
514 .restart = __NR_restart_syscall 512 .restart = __NR_restart_syscall
515}; 513};
516 514
517static int handle_signal(unsigned long sig, siginfo_t *info, 515static void handle_signal(unsigned long sig, siginfo_t *info,
518 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs) 516 struct k_sigaction *ka, struct pt_regs *regs)
519{ 517{
518 sigset_t *oldset = sigmask_to_save();
520 int ret; 519 int ret;
521 struct mips_abi *abi = current->thread.abi; 520 struct mips_abi *abi = current->thread.abi;
522 void *vdso = current->mm->context.vdso; 521 void *vdso = current->mm->context.vdso;
@@ -550,17 +549,14 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
550 ka, regs, sig, oldset); 549 ka, regs, sig, oldset);
551 550
552 if (ret) 551 if (ret)
553 return ret; 552 return;
554
555 block_sigmask(ka, sig);
556 553
557 return ret; 554 signal_delivered(sig, info, ka, regs, 0);
558} 555}
559 556
560static void do_signal(struct pt_regs *regs) 557static void do_signal(struct pt_regs *regs)
561{ 558{
562 struct k_sigaction ka; 559 struct k_sigaction ka;
563 sigset_t *oldset;
564 siginfo_t info; 560 siginfo_t info;
565 int signr; 561 int signr;
566 562
@@ -572,25 +568,10 @@ static void do_signal(struct pt_regs *regs)
572 if (!user_mode(regs)) 568 if (!user_mode(regs))
573 return; 569 return;
574 570
575 if (test_thread_flag(TIF_RESTORE_SIGMASK))
576 oldset = &current->saved_sigmask;
577 else
578 oldset = &current->blocked;
579
580 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 571 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
581 if (signr > 0) { 572 if (signr > 0) {
582 /* Whee! Actually deliver the signal. */ 573 /* Whee! Actually deliver the signal. */
583 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 574 handle_signal(signr, &info, &ka, regs);
584 /*
585 * A signal was successfully delivered; the saved
586 * sigmask will have been stored in the signal frame,
587 * and will be restored by sigreturn, so we can simply
588 * clear the TIF_RESTORE_SIGMASK flag.
589 */
590 if (test_thread_flag(TIF_RESTORE_SIGMASK))
591 clear_thread_flag(TIF_RESTORE_SIGMASK);
592 }
593
594 return; 575 return;
595 } 576 }
596 577
@@ -614,10 +595,7 @@ static void do_signal(struct pt_regs *regs)
614 * If there's no signal to deliver, we just put the saved sigmask 595 * If there's no signal to deliver, we just put the saved sigmask
615 * back 596 * back
616 */ 597 */
617 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 598 restore_saved_sigmask();
618 clear_thread_flag(TIF_RESTORE_SIGMASK);
619 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
620 }
621} 599}
622 600
623/* 601/*
@@ -630,7 +608,7 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
630 local_irq_enable(); 608 local_irq_enable();
631 609
632 /* deal with pending signal delivery */ 610 /* deal with pending signal delivery */
633 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 611 if (thread_info_flags & _TIF_SIGPENDING)
634 do_signal(regs); 612 do_signal(regs);
635 613
636 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 614 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
diff --git a/arch/mips/kernel/signal32.c b/arch/mips/kernel/signal32.c
index b4fe2eacbd5d..da1b56a39ac7 100644
--- a/arch/mips/kernel/signal32.c
+++ b/arch/mips/kernel/signal32.c
@@ -465,7 +465,6 @@ asmlinkage void sys32_sigreturn(nabi_no_regargs struct pt_regs regs)
465 if (__copy_conv_sigset_from_user(&blocked, &frame->sf_mask)) 465 if (__copy_conv_sigset_from_user(&blocked, &frame->sf_mask))
466 goto badframe; 466 goto badframe;
467 467
468 sigdelsetmask(&blocked, ~_BLOCKABLE);
469 set_current_blocked(&blocked); 468 set_current_blocked(&blocked);
470 469
471 sig = restore_sigcontext32(&regs, &frame->sf_sc); 470 sig = restore_sigcontext32(&regs, &frame->sf_sc);
@@ -503,7 +502,6 @@ asmlinkage void sys32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
503 if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask)) 502 if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask))
504 goto badframe; 503 goto badframe;
505 504
506 sigdelsetmask(&set, ~_BLOCKABLE);
507 set_current_blocked(&set); 505 set_current_blocked(&set);
508 506
509 sig = restore_sigcontext32(&regs, &frame->rs_uc.uc_mcontext); 507 sig = restore_sigcontext32(&regs, &frame->rs_uc.uc_mcontext);
diff --git a/arch/mips/kernel/signal_n32.c b/arch/mips/kernel/signal_n32.c
index 63ffac9af7c5..3574c145511b 100644
--- a/arch/mips/kernel/signal_n32.c
+++ b/arch/mips/kernel/signal_n32.c
@@ -109,7 +109,6 @@ asmlinkage void sysn32_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
109 if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask)) 109 if (__copy_conv_sigset_from_user(&set, &frame->rs_uc.uc_sigmask))
110 goto badframe; 110 goto badframe;
111 111
112 sigdelsetmask(&set, ~_BLOCKABLE);
113 set_current_blocked(&set); 112 set_current_blocked(&set);
114 113
115 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext); 114 sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext);
diff --git a/arch/mn10300/kernel/signal.c b/arch/mn10300/kernel/signal.c
index b8b6aa1a6837..6ab0bee2a54f 100644
--- a/arch/mn10300/kernel/signal.c
+++ b/arch/mn10300/kernel/signal.c
@@ -31,8 +31,6 @@
31 31
32#define DEBUG_SIG 0 32#define DEBUG_SIG 0
33 33
34#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
35
36/* 34/*
37 * atomically swap in the new signal mask, and wait for a signal. 35 * atomically swap in the new signal mask, and wait for a signal.
38 */ 36 */
@@ -163,7 +161,6 @@ asmlinkage long sys_sigreturn(void)
163 sizeof(frame->extramask))) 161 sizeof(frame->extramask)))
164 goto badframe; 162 goto badframe;
165 163
166 sigdelsetmask(&set, ~_BLOCKABLE);
167 set_current_blocked(&set); 164 set_current_blocked(&set);
168 165
169 if (restore_sigcontext(current_frame(), &frame->sc, &d0)) 166 if (restore_sigcontext(current_frame(), &frame->sc, &d0))
@@ -191,7 +188,6 @@ asmlinkage long sys_rt_sigreturn(void)
191 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 188 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
192 goto badframe; 189 goto badframe;
193 190
194 sigdelsetmask(&set, ~_BLOCKABLE);
195 set_current_blocked(&set); 191 set_current_blocked(&set);
196 192
197 if (restore_sigcontext(current_frame(), &frame->uc.uc_mcontext, &d0)) 193 if (restore_sigcontext(current_frame(), &frame->uc.uc_mcontext, &d0))
@@ -430,8 +426,9 @@ static inline void stepback(struct pt_regs *regs)
430 */ 426 */
431static int handle_signal(int sig, 427static int handle_signal(int sig,
432 siginfo_t *info, struct k_sigaction *ka, 428 siginfo_t *info, struct k_sigaction *ka,
433 sigset_t *oldset, struct pt_regs *regs) 429 struct pt_regs *regs)
434{ 430{
431 sigset_t *oldset = sigmask_to_save();
435 int ret; 432 int ret;
436 433
437 /* Are we from a system call? */ 434 /* Are we from a system call? */
@@ -461,11 +458,11 @@ static int handle_signal(int sig,
461 ret = setup_rt_frame(sig, ka, info, oldset, regs); 458 ret = setup_rt_frame(sig, ka, info, oldset, regs);
462 else 459 else
463 ret = setup_frame(sig, ka, oldset, regs); 460 ret = setup_frame(sig, ka, oldset, regs);
461 if (ret)
462 return;
464 463
465 if (ret == 0) 464 signal_delivered(sig, info, ka, regs,
466 block_sigmask(ka, sig); 465 test_thread_flag(TIF_SINGLESTEP));
467
468 return ret;
469} 466}
470 467
471/* 468/*
@@ -475,7 +472,6 @@ static void do_signal(struct pt_regs *regs)
475{ 472{
476 struct k_sigaction ka; 473 struct k_sigaction ka;
477 siginfo_t info; 474 siginfo_t info;
478 sigset_t *oldset;
479 int signr; 475 int signr;
480 476
481 /* we want the common case to go fast, which is why we may in certain 477 /* we want the common case to go fast, which is why we may in certain
@@ -483,23 +479,9 @@ static void do_signal(struct pt_regs *regs)
483 if (!user_mode(regs)) 479 if (!user_mode(regs))
484 return; 480 return;
485 481
486 if (test_thread_flag(TIF_RESTORE_SIGMASK))
487 oldset = &current->saved_sigmask;
488 else
489 oldset = &current->blocked;
490
491 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 482 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
492 if (signr > 0) { 483 if (signr > 0) {
493 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 484 if (handle_signal(signr, &info, &ka, regs) == 0) {
494 /* a signal was successfully delivered; the saved
495 * sigmask will have been stored in the signal frame,
496 * and will be restored by sigreturn, so we can simply
497 * clear the TIF_RESTORE_SIGMASK flag */
498 if (test_thread_flag(TIF_RESTORE_SIGMASK))
499 clear_thread_flag(TIF_RESTORE_SIGMASK);
500
501 tracehook_signal_handler(signr, &info, &ka, regs,
502 test_thread_flag(TIF_SINGLESTEP));
503 } 485 }
504 486
505 return; 487 return;
@@ -525,10 +507,7 @@ static void do_signal(struct pt_regs *regs)
525 507
526 /* if there's no signal to deliver, we just put the saved sigmask 508 /* if there's no signal to deliver, we just put the saved sigmask
527 * back */ 509 * back */
528 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 510 restore_saved_sigmask();
529 clear_thread_flag(TIF_RESTORE_SIGMASK);
530 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
531 }
532} 511}
533 512
534/* 513/*
@@ -548,7 +527,7 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags)
548 } 527 }
549 528
550 /* deal with pending signal delivery */ 529 /* deal with pending signal delivery */
551 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 530 if (thread_info_flags & _TIF_SIGPENDING)
552 do_signal(regs); 531 do_signal(regs);
553 532
554 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 533 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
diff --git a/arch/openrisc/kernel/signal.c b/arch/openrisc/kernel/signal.c
index 9ae611522953..30110297f4f9 100644
--- a/arch/openrisc/kernel/signal.c
+++ b/arch/openrisc/kernel/signal.c
@@ -33,8 +33,6 @@
33 33
34#define DEBUG_SIG 0 34#define DEBUG_SIG 0
35 35
36#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
37
38asmlinkage long 36asmlinkage long
39_sys_sigaltstack(const stack_t *uss, stack_t *uoss, struct pt_regs *regs) 37_sys_sigaltstack(const stack_t *uss, stack_t *uoss, struct pt_regs *regs)
40{ 38{
@@ -101,7 +99,6 @@ asmlinkage long _sys_rt_sigreturn(struct pt_regs *regs)
101 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 99 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
102 goto badframe; 100 goto badframe;
103 101
104 sigdelsetmask(&set, ~_BLOCKABLE);
105 set_current_blocked(&set); 102 set_current_blocked(&set);
106 103
107 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 104 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -251,20 +248,19 @@ give_sigsegv:
251 return -EFAULT; 248 return -EFAULT;
252} 249}
253 250
254static inline int 251static inline void
255handle_signal(unsigned long sig, 252handle_signal(unsigned long sig,
256 siginfo_t *info, struct k_sigaction *ka, 253 siginfo_t *info, struct k_sigaction *ka,
257 sigset_t *oldset, struct pt_regs *regs) 254 struct pt_regs *regs)
258{ 255{
259 int ret; 256 int ret;
260 257
261 ret = setup_rt_frame(sig, ka, info, oldset, regs); 258 ret = setup_rt_frame(sig, ka, info, sigmask_to_save(), regs);
262 if (ret) 259 if (ret)
263 return ret; 260 return;
264
265 block_sigmask(ka, sig);
266 261
267 return 0; 262 signal_delivered(sig, info, ka, regs,
263 test_thread_flag(TIF_SINGLESTEP));
268} 264}
269 265
270/* 266/*
@@ -339,30 +335,10 @@ void do_signal(struct pt_regs *regs)
339 if (signr <= 0) { 335 if (signr <= 0) {
340 /* no signal to deliver so we just put the saved sigmask 336 /* no signal to deliver so we just put the saved sigmask
341 * back */ 337 * back */
342 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 338 restore_saved_sigmask();
343 clear_thread_flag(TIF_RESTORE_SIGMASK);
344 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
345 }
346
347 } else { /* signr > 0 */ 339 } else { /* signr > 0 */
348 sigset_t *oldset;
349
350 if (current_thread_info()->flags & _TIF_RESTORE_SIGMASK)
351 oldset = &current->saved_sigmask;
352 else
353 oldset = &current->blocked;
354
355 /* Whee! Actually deliver the signal. */ 340 /* Whee! Actually deliver the signal. */
356 if (!handle_signal(signr, &info, &ka, oldset, regs)) { 341 handle_signal(signr, &info, &ka, regs);
357 /* a signal was successfully delivered; the saved
358 * sigmask will have been stored in the signal frame,
359 * and will be restored by sigreturn, so we can simply
360 * clear the TIF_RESTORE_SIGMASK flag */
361 clear_thread_flag(TIF_RESTORE_SIGMASK);
362 }
363
364 tracehook_signal_handler(signr, &info, &ka, regs,
365 test_thread_flag(TIF_SINGLESTEP));
366 } 342 }
367 343
368 return; 344 return;
diff --git a/arch/parisc/include/asm/thread_info.h b/arch/parisc/include/asm/thread_info.h
index 83ae7dd4d99e..22b4726dee49 100644
--- a/arch/parisc/include/asm/thread_info.h
+++ b/arch/parisc/include/asm/thread_info.h
@@ -74,7 +74,7 @@ struct thread_info {
74#define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP) 74#define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP)
75 75
76#define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | \ 76#define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | \
77 _TIF_NEED_RESCHED | _TIF_RESTORE_SIGMASK) 77 _TIF_NEED_RESCHED)
78 78
79#endif /* __KERNEL__ */ 79#endif /* __KERNEL__ */
80 80
diff --git a/arch/parisc/kernel/entry.S b/arch/parisc/kernel/entry.S
index c7fbc96472f3..18670a078849 100644
--- a/arch/parisc/kernel/entry.S
+++ b/arch/parisc/kernel/entry.S
@@ -924,7 +924,7 @@ intr_check_sig:
924 /* As above */ 924 /* As above */
925 mfctl %cr30,%r1 925 mfctl %cr30,%r1
926 LDREG TI_FLAGS(%r1),%r19 926 LDREG TI_FLAGS(%r1),%r19
927 ldi (_TIF_SIGPENDING|_TIF_RESTORE_SIGMASK|_TIF_NOTIFY_RESUME), %r20 927 ldi (_TIF_SIGPENDING|_TIF_NOTIFY_RESUME), %r20
928 and,COND(<>) %r19, %r20, %r0 928 and,COND(<>) %r19, %r20, %r0
929 b,n intr_restore /* skip past if we've nothing to do */ 929 b,n intr_restore /* skip past if we've nothing to do */
930 930
@@ -2032,7 +2032,7 @@ syscall_check_resched:
2032 .import do_signal,code 2032 .import do_signal,code
2033syscall_check_sig: 2033syscall_check_sig:
2034 LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19 2034 LDREG TI_FLAGS-THREAD_SZ_ALGN-FRAME_SIZE(%r30),%r19
2035 ldi (_TIF_SIGPENDING|_TIF_RESTORE_SIGMASK|_TIF_NOTIFY_RESUME), %r26 2035 ldi (_TIF_SIGPENDING|_TIF_NOTIFY_RESUME), %r26
2036 and,COND(<>) %r19, %r26, %r0 2036 and,COND(<>) %r19, %r26, %r0
2037 b,n syscall_restore /* skip past if we've nothing to do */ 2037 b,n syscall_restore /* skip past if we've nothing to do */
2038 2038
diff --git a/arch/parisc/kernel/signal.c b/arch/parisc/kernel/signal.c
index e7a7cd3e1120..594459bde14e 100644
--- a/arch/parisc/kernel/signal.c
+++ b/arch/parisc/kernel/signal.c
@@ -48,9 +48,6 @@
48#define DBG(LEVEL, ...) 48#define DBG(LEVEL, ...)
49#endif 49#endif
50 50
51
52#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
53
54/* gcc will complain if a pointer is cast to an integer of different 51/* gcc will complain if a pointer is cast to an integer of different
55 * size. If you really need to do this (and we do for an ELF32 user 52 * size. If you really need to do this (and we do for an ELF32 user
56 * application in an ELF64 kernel) then you have to do a cast to an 53 * application in an ELF64 kernel) then you have to do a cast to an
@@ -131,7 +128,6 @@ sys_rt_sigreturn(struct pt_regs *regs, int in_syscall)
131 goto give_sigsegv; 128 goto give_sigsegv;
132 } 129 }
133 130
134 sigdelsetmask(&set, ~_BLOCKABLE);
135 set_current_blocked(&set); 131 set_current_blocked(&set);
136 132
137 /* Good thing we saved the old gr[30], eh? */ 133 /* Good thing we saved the old gr[30], eh? */
@@ -443,8 +439,9 @@ give_sigsegv:
443 439
444static long 440static long
445handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, 441handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
446 sigset_t *oldset, struct pt_regs *regs, int in_syscall) 442 struct pt_regs *regs, int in_syscall)
447{ 443{
444 sigset_t *oldset = sigmask_to_save();
448 DBG(1,"handle_signal: sig=%ld, ka=%p, info=%p, oldset=%p, regs=%p\n", 445 DBG(1,"handle_signal: sig=%ld, ka=%p, info=%p, oldset=%p, regs=%p\n",
449 sig, ka, info, oldset, regs); 446 sig, ka, info, oldset, regs);
450 447
@@ -452,12 +449,13 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
452 if (!setup_rt_frame(sig, ka, info, oldset, regs, in_syscall)) 449 if (!setup_rt_frame(sig, ka, info, oldset, regs, in_syscall))
453 return 0; 450 return 0;
454 451
455 block_sigmask(ka, sig); 452 signal_delivered(sig, info, ka, regs,
456
457 tracehook_signal_handler(sig, info, ka, regs,
458 test_thread_flag(TIF_SINGLESTEP) || 453 test_thread_flag(TIF_SINGLESTEP) ||
459 test_thread_flag(TIF_BLOCKSTEP)); 454 test_thread_flag(TIF_BLOCKSTEP));
460 455
456 DBG(1,KERN_DEBUG "do_signal: Exit (success), regs->gr[28] = %ld\n",
457 regs->gr[28]);
458
461 return 1; 459 return 1;
462} 460}
463 461
@@ -568,28 +566,17 @@ do_signal(struct pt_regs *regs, long in_syscall)
568 siginfo_t info; 566 siginfo_t info;
569 struct k_sigaction ka; 567 struct k_sigaction ka;
570 int signr; 568 int signr;
571 sigset_t *oldset;
572 569
573 DBG(1,"\ndo_signal: oldset=0x%p, regs=0x%p, sr7 %#lx, in_syscall=%d\n", 570 DBG(1,"\ndo_signal: regs=0x%p, sr7 %#lx, in_syscall=%d\n",
574 oldset, regs, regs->sr[7], in_syscall); 571 regs, regs->sr[7], in_syscall);
575 572
576 /* Everyone else checks to see if they are in kernel mode at 573 /* Everyone else checks to see if they are in kernel mode at
577 this point and exits if that's the case. I'm not sure why 574 this point and exits if that's the case. I'm not sure why
578 we would be called in that case, but for some reason we 575 we would be called in that case, but for some reason we
579 are. */ 576 are. */
580 577
581 if (test_thread_flag(TIF_RESTORE_SIGMASK))
582 oldset = &current->saved_sigmask;
583 else
584 oldset = &current->blocked;
585
586 DBG(1,"do_signal: oldset %08lx / %08lx\n",
587 oldset->sig[0], oldset->sig[1]);
588
589
590 /* May need to force signal if handle_signal failed to deliver */ 578 /* May need to force signal if handle_signal failed to deliver */
591 while (1) { 579 while (1) {
592
593 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 580 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
594 DBG(3,"do_signal: signr = %d, regs->gr[28] = %ld\n", signr, regs->gr[28]); 581 DBG(3,"do_signal: signr = %d, regs->gr[28] = %ld\n", signr, regs->gr[28]);
595 582
@@ -603,14 +590,8 @@ do_signal(struct pt_regs *regs, long in_syscall)
603 /* Whee! Actually deliver the signal. If the 590 /* Whee! Actually deliver the signal. If the
604 delivery failed, we need to continue to iterate in 591 delivery failed, we need to continue to iterate in
605 this loop so we can deliver the SIGSEGV... */ 592 this loop so we can deliver the SIGSEGV... */
606 if (handle_signal(signr, &info, &ka, oldset, 593 if (handle_signal(signr, &info, &ka, regs, in_syscall))
607 regs, in_syscall)) {
608 DBG(1,KERN_DEBUG "do_signal: Exit (success), regs->gr[28] = %ld\n",
609 regs->gr[28]);
610 if (test_thread_flag(TIF_RESTORE_SIGMASK))
611 clear_thread_flag(TIF_RESTORE_SIGMASK);
612 return; 594 return;
613 }
614 } 595 }
615 /* end of while(1) looping forever if we can't force a signal */ 596 /* end of while(1) looping forever if we can't force a signal */
616 597
@@ -621,18 +602,12 @@ do_signal(struct pt_regs *regs, long in_syscall)
621 DBG(1,"do_signal: Exit (not delivered), regs->gr[28] = %ld\n", 602 DBG(1,"do_signal: Exit (not delivered), regs->gr[28] = %ld\n",
622 regs->gr[28]); 603 regs->gr[28]);
623 604
624 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 605 restore_saved_sigmask();
625 clear_thread_flag(TIF_RESTORE_SIGMASK);
626 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
627 }
628
629 return;
630} 606}
631 607
632void do_notify_resume(struct pt_regs *regs, long in_syscall) 608void do_notify_resume(struct pt_regs *regs, long in_syscall)
633{ 609{
634 if (test_thread_flag(TIF_SIGPENDING) || 610 if (test_thread_flag(TIF_SIGPENDING))
635 test_thread_flag(TIF_RESTORE_SIGMASK))
636 do_signal(regs, in_syscall); 611 do_signal(regs, in_syscall);
637 612
638 if (test_thread_flag(TIF_NOTIFY_RESUME)) { 613 if (test_thread_flag(TIF_NOTIFY_RESUME)) {
diff --git a/arch/parisc/kernel/signal32.c b/arch/parisc/kernel/signal32.c
index e14132430762..fd49aeda9eb8 100644
--- a/arch/parisc/kernel/signal32.c
+++ b/arch/parisc/kernel/signal32.c
@@ -47,8 +47,6 @@
47#define DBG(LEVEL, ...) 47#define DBG(LEVEL, ...)
48#endif 48#endif
49 49
50#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
51
52inline void 50inline void
53sigset_32to64(sigset_t *s64, compat_sigset_t *s32) 51sigset_32to64(sigset_t *s64, compat_sigset_t *s32)
54{ 52{
diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
index a556ccc16b58..68831e9cf82f 100644
--- a/arch/powerpc/include/asm/thread_info.h
+++ b/arch/powerpc/include/asm/thread_info.h
@@ -140,7 +140,23 @@ static inline void set_restore_sigmask(void)
140{ 140{
141 struct thread_info *ti = current_thread_info(); 141 struct thread_info *ti = current_thread_info();
142 ti->local_flags |= _TLF_RESTORE_SIGMASK; 142 ti->local_flags |= _TLF_RESTORE_SIGMASK;
143 set_bit(TIF_SIGPENDING, &ti->flags); 143 WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
144}
145static inline void clear_restore_sigmask(void)
146{
147 current_thread_info()->local_flags &= ~_TLF_RESTORE_SIGMASK;
148}
149static inline bool test_restore_sigmask(void)
150{
151 return current_thread_info()->local_flags & _TLF_RESTORE_SIGMASK;
152}
153static inline bool test_and_clear_restore_sigmask(void)
154{
155 struct thread_info *ti = current_thread_info();
156 if (!(ti->local_flags & _TLF_RESTORE_SIGMASK))
157 return false;
158 ti->local_flags &= ~_TLF_RESTORE_SIGMASK;
159 return true;
144} 160}
145 161
146static inline bool test_thread_local_flags(unsigned int flags) 162static inline bool test_thread_local_flags(unsigned int flags)
diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
index bfc3ec1382fb..5c023c9cf16e 100644
--- a/arch/powerpc/kernel/signal.c
+++ b/arch/powerpc/kernel/signal.c
@@ -51,16 +51,6 @@ void __user * get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
51 return (void __user *)newsp; 51 return (void __user *)newsp;
52} 52}
53 53
54
55/*
56 * Restore the user process's signal mask
57 */
58void restore_sigmask(sigset_t *set)
59{
60 sigdelsetmask(set, ~_BLOCKABLE);
61 set_current_blocked(set);
62}
63
64static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka, 54static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka,
65 int has_handler) 55 int has_handler)
66{ 56{
@@ -114,30 +104,21 @@ static void check_syscall_restart(struct pt_regs *regs, struct k_sigaction *ka,
114 104
115static int do_signal(struct pt_regs *regs) 105static int do_signal(struct pt_regs *regs)
116{ 106{
117 sigset_t *oldset; 107 sigset_t *oldset = sigmask_to_save();
118 siginfo_t info; 108 siginfo_t info;
119 int signr; 109 int signr;
120 struct k_sigaction ka; 110 struct k_sigaction ka;
121 int ret; 111 int ret;
122 int is32 = is_32bit_task(); 112 int is32 = is_32bit_task();
123 113
124 if (current_thread_info()->local_flags & _TLF_RESTORE_SIGMASK)
125 oldset = &current->saved_sigmask;
126 else
127 oldset = &current->blocked;
128
129 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 114 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
130 115
131 /* Is there any syscall restart business here ? */ 116 /* Is there any syscall restart business here ? */
132 check_syscall_restart(regs, &ka, signr > 0); 117 check_syscall_restart(regs, &ka, signr > 0);
133 118
134 if (signr <= 0) { 119 if (signr <= 0) {
135 struct thread_info *ti = current_thread_info();
136 /* No signal to deliver -- put the saved sigmask back */ 120 /* No signal to deliver -- put the saved sigmask back */
137 if (ti->local_flags & _TLF_RESTORE_SIGMASK) { 121 restore_saved_sigmask();
138 ti->local_flags &= ~_TLF_RESTORE_SIGMASK;
139 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
140 }
141 regs->trap = 0; 122 regs->trap = 0;
142 return 0; /* no signals delivered */ 123 return 0; /* no signals delivered */
143 } 124 }
@@ -167,18 +148,7 @@ static int do_signal(struct pt_regs *regs)
167 148
168 regs->trap = 0; 149 regs->trap = 0;
169 if (ret) { 150 if (ret) {
170 block_sigmask(&ka, signr); 151 signal_delivered(signr, &info, &ka, regs,
171
172 /*
173 * A signal was successfully delivered; the saved sigmask is in
174 * its frame, and we can clear the TLF_RESTORE_SIGMASK flag.
175 */
176 current_thread_info()->local_flags &= ~_TLF_RESTORE_SIGMASK;
177
178 /*
179 * Let tracing know that we've done the handler setup.
180 */
181 tracehook_signal_handler(signr, &info, &ka, regs,
182 test_thread_flag(TIF_SINGLESTEP)); 152 test_thread_flag(TIF_SINGLESTEP));
183 } 153 }
184 154
diff --git a/arch/powerpc/kernel/signal.h b/arch/powerpc/kernel/signal.h
index 8dde973aaaf5..e00acb413934 100644
--- a/arch/powerpc/kernel/signal.h
+++ b/arch/powerpc/kernel/signal.h
@@ -10,13 +10,10 @@
10#ifndef _POWERPC_ARCH_SIGNAL_H 10#ifndef _POWERPC_ARCH_SIGNAL_H
11#define _POWERPC_ARCH_SIGNAL_H 11#define _POWERPC_ARCH_SIGNAL_H
12 12
13#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
14
15extern void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags); 13extern void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags);
16 14
17extern void __user * get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, 15extern void __user * get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
18 size_t frame_size, int is_32); 16 size_t frame_size, int is_32);
19extern void restore_sigmask(sigset_t *set);
20 17
21extern int handle_signal32(unsigned long sig, struct k_sigaction *ka, 18extern int handle_signal32(unsigned long sig, struct k_sigaction *ka,
22 siginfo_t *info, sigset_t *oldset, 19 siginfo_t *info, sigset_t *oldset,
diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index 61f6aff25edc..8b4c049aee20 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -919,7 +919,7 @@ static int do_setcontext(struct ucontext __user *ucp, struct pt_regs *regs, int
919 if (!access_ok(VERIFY_READ, mcp, sizeof(*mcp))) 919 if (!access_ok(VERIFY_READ, mcp, sizeof(*mcp)))
920 return -EFAULT; 920 return -EFAULT;
921#endif 921#endif
922 restore_sigmask(&set); 922 set_current_blocked(&set);
923 if (restore_user_regs(regs, mcp, sig)) 923 if (restore_user_regs(regs, mcp, sig))
924 return -EFAULT; 924 return -EFAULT;
925 925
@@ -1273,7 +1273,7 @@ long sys_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8,
1273 set.sig[0] = sigctx.oldmask; 1273 set.sig[0] = sigctx.oldmask;
1274 set.sig[1] = sigctx._unused[3]; 1274 set.sig[1] = sigctx._unused[3];
1275#endif 1275#endif
1276 restore_sigmask(&set); 1276 set_current_blocked(&set);
1277 1277
1278 sr = (struct mcontext __user *)from_user_ptr(sigctx.regs); 1278 sr = (struct mcontext __user *)from_user_ptr(sigctx.regs);
1279 addr = sr; 1279 addr = sr;
diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
index 2692efdb154e..d183f8719a50 100644
--- a/arch/powerpc/kernel/signal_64.c
+++ b/arch/powerpc/kernel/signal_64.c
@@ -335,7 +335,7 @@ int sys_swapcontext(struct ucontext __user *old_ctx,
335 335
336 if (__copy_from_user(&set, &new_ctx->uc_sigmask, sizeof(set))) 336 if (__copy_from_user(&set, &new_ctx->uc_sigmask, sizeof(set)))
337 do_exit(SIGSEGV); 337 do_exit(SIGSEGV);
338 restore_sigmask(&set); 338 set_current_blocked(&set);
339 if (restore_sigcontext(regs, NULL, 0, &new_ctx->uc_mcontext)) 339 if (restore_sigcontext(regs, NULL, 0, &new_ctx->uc_mcontext))
340 do_exit(SIGSEGV); 340 do_exit(SIGSEGV);
341 341
@@ -364,7 +364,7 @@ int sys_rt_sigreturn(unsigned long r3, unsigned long r4, unsigned long r5,
364 364
365 if (__copy_from_user(&set, &uc->uc_sigmask, sizeof(set))) 365 if (__copy_from_user(&set, &uc->uc_sigmask, sizeof(set)))
366 goto badframe; 366 goto badframe;
367 restore_sigmask(&set); 367 set_current_blocked(&set);
368 if (restore_sigcontext(regs, NULL, 1, &uc->uc_mcontext)) 368 if (restore_sigcontext(regs, NULL, 1, &uc->uc_mcontext))
369 goto badframe; 369 goto badframe;
370 370
diff --git a/arch/s390/kernel/compat_signal.c b/arch/s390/kernel/compat_signal.c
index 377c096ca4a7..3c0c19830c37 100644
--- a/arch/s390/kernel/compat_signal.c
+++ b/arch/s390/kernel/compat_signal.c
@@ -32,8 +32,6 @@
32#include "compat_ptrace.h" 32#include "compat_ptrace.h"
33#include "entry.h" 33#include "entry.h"
34 34
35#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
36
37typedef struct 35typedef struct
38{ 36{
39 __u8 callee_used_stack[__SIGNAL_FRAMESIZE32]; 37 __u8 callee_used_stack[__SIGNAL_FRAMESIZE32];
@@ -364,7 +362,6 @@ asmlinkage long sys32_sigreturn(void)
364 goto badframe; 362 goto badframe;
365 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE32)) 363 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE32))
366 goto badframe; 364 goto badframe;
367 sigdelsetmask(&set, ~_BLOCKABLE);
368 set_current_blocked(&set); 365 set_current_blocked(&set);
369 if (restore_sigregs32(regs, &frame->sregs)) 366 if (restore_sigregs32(regs, &frame->sregs))
370 goto badframe; 367 goto badframe;
@@ -390,7 +387,6 @@ asmlinkage long sys32_rt_sigreturn(void)
390 goto badframe; 387 goto badframe;
391 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 388 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
392 goto badframe; 389 goto badframe;
393 sigdelsetmask(&set, ~_BLOCKABLE);
394 set_current_blocked(&set); 390 set_current_blocked(&set);
395 if (restore_sigregs32(regs, &frame->uc.uc_mcontext)) 391 if (restore_sigregs32(regs, &frame->uc.uc_mcontext))
396 goto badframe; 392 goto badframe;
@@ -572,7 +568,7 @@ give_sigsegv:
572 * OK, we're invoking a handler 568 * OK, we're invoking a handler
573 */ 569 */
574 570
575int handle_signal32(unsigned long sig, struct k_sigaction *ka, 571void handle_signal32(unsigned long sig, struct k_sigaction *ka,
576 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) 572 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs)
577{ 573{
578 int ret; 574 int ret;
@@ -583,8 +579,8 @@ int handle_signal32(unsigned long sig, struct k_sigaction *ka,
583 else 579 else
584 ret = setup_frame32(sig, ka, oldset, regs); 580 ret = setup_frame32(sig, ka, oldset, regs);
585 if (ret) 581 if (ret)
586 return ret; 582 return;
587 block_sigmask(ka, sig); 583 signal_delivered(sig, info, ka, regs,
588 return 0; 584 test_thread_flag(TIF_SINGLE_STEP));
589} 585}
590 586
diff --git a/arch/s390/kernel/entry.h b/arch/s390/kernel/entry.h
index 6cdddac93a2e..f66a229ab0b3 100644
--- a/arch/s390/kernel/entry.h
+++ b/arch/s390/kernel/entry.h
@@ -31,7 +31,7 @@ void do_per_trap(struct pt_regs *regs);
31void syscall_trace(struct pt_regs *regs, int entryexit); 31void syscall_trace(struct pt_regs *regs, int entryexit);
32void kernel_stack_overflow(struct pt_regs * regs); 32void kernel_stack_overflow(struct pt_regs * regs);
33void do_signal(struct pt_regs *regs); 33void do_signal(struct pt_regs *regs);
34int handle_signal32(unsigned long sig, struct k_sigaction *ka, 34void handle_signal32(unsigned long sig, struct k_sigaction *ka,
35 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs); 35 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs);
36void do_notify_resume(struct pt_regs *regs); 36void do_notify_resume(struct pt_regs *regs);
37 37
diff --git a/arch/s390/kernel/signal.c b/arch/s390/kernel/signal.c
index 42a6e8b47f06..ac565b44aabb 100644
--- a/arch/s390/kernel/signal.c
+++ b/arch/s390/kernel/signal.c
@@ -33,9 +33,6 @@
33#include <asm/switch_to.h> 33#include <asm/switch_to.h>
34#include "entry.h" 34#include "entry.h"
35 35
36#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
37
38
39typedef struct 36typedef struct
40{ 37{
41 __u8 callee_used_stack[__SIGNAL_FRAMESIZE]; 38 __u8 callee_used_stack[__SIGNAL_FRAMESIZE];
@@ -169,7 +166,6 @@ SYSCALL_DEFINE0(sigreturn)
169 goto badframe; 166 goto badframe;
170 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE)) 167 if (__copy_from_user(&set.sig, &frame->sc.oldmask, _SIGMASK_COPY_SIZE))
171 goto badframe; 168 goto badframe;
172 sigdelsetmask(&set, ~_BLOCKABLE);
173 set_current_blocked(&set); 169 set_current_blocked(&set);
174 if (restore_sigregs(regs, &frame->sregs)) 170 if (restore_sigregs(regs, &frame->sregs))
175 goto badframe; 171 goto badframe;
@@ -189,7 +185,6 @@ SYSCALL_DEFINE0(rt_sigreturn)
189 goto badframe; 185 goto badframe;
190 if (__copy_from_user(&set.sig, &frame->uc.uc_sigmask, sizeof(set))) 186 if (__copy_from_user(&set.sig, &frame->uc.uc_sigmask, sizeof(set)))
191 goto badframe; 187 goto badframe;
192 sigdelsetmask(&set, ~_BLOCKABLE);
193 set_current_blocked(&set); 188 set_current_blocked(&set);
194 if (restore_sigregs(regs, &frame->uc.uc_mcontext)) 189 if (restore_sigregs(regs, &frame->uc.uc_mcontext))
195 goto badframe; 190 goto badframe;
@@ -367,7 +362,7 @@ give_sigsegv:
367 return -EFAULT; 362 return -EFAULT;
368} 363}
369 364
370static int handle_signal(unsigned long sig, struct k_sigaction *ka, 365static void handle_signal(unsigned long sig, struct k_sigaction *ka,
371 siginfo_t *info, sigset_t *oldset, 366 siginfo_t *info, sigset_t *oldset,
372 struct pt_regs *regs) 367 struct pt_regs *regs)
373{ 368{
@@ -379,9 +374,9 @@ static int handle_signal(unsigned long sig, struct k_sigaction *ka,
379 else 374 else
380 ret = setup_frame(sig, ka, oldset, regs); 375 ret = setup_frame(sig, ka, oldset, regs);
381 if (ret) 376 if (ret)
382 return ret; 377 return;
383 block_sigmask(ka, sig); 378 signal_delivered(sig, info, ka, regs,
384 return 0; 379 test_thread_flag(TIF_SINGLE_STEP));
385} 380}
386 381
387/* 382/*
@@ -398,12 +393,7 @@ void do_signal(struct pt_regs *regs)
398 siginfo_t info; 393 siginfo_t info;
399 int signr; 394 int signr;
400 struct k_sigaction ka; 395 struct k_sigaction ka;
401 sigset_t *oldset; 396 sigset_t *oldset = sigmask_to_save();
402
403 if (test_thread_flag(TIF_RESTORE_SIGMASK))
404 oldset = &current->saved_sigmask;
405 else
406 oldset = &current->blocked;
407 397
408 /* 398 /*
409 * Get signal to deliver. When running under ptrace, at this point 399 * Get signal to deliver. When running under ptrace, at this point
@@ -441,24 +431,10 @@ void do_signal(struct pt_regs *regs)
441 /* No longer in a system call */ 431 /* No longer in a system call */
442 clear_thread_flag(TIF_SYSCALL); 432 clear_thread_flag(TIF_SYSCALL);
443 433
444 if ((is_compat_task() ? 434 if (is_compat_task())
445 handle_signal32(signr, &ka, &info, oldset, regs) : 435 handle_signal32(signr, &ka, &info, oldset, regs);
446 handle_signal(signr, &ka, &info, oldset, regs)) == 0) { 436 else
447 /* 437 handle_signal(signr, &ka, &info, oldset, regs);
448 * A signal was successfully delivered; the saved
449 * sigmask will have been stored in the signal frame,
450 * and will be restored by sigreturn, so we can simply
451 * clear the TIF_RESTORE_SIGMASK flag.
452 */
453 if (test_thread_flag(TIF_RESTORE_SIGMASK))
454 clear_thread_flag(TIF_RESTORE_SIGMASK);
455
456 /*
457 * Let tracing know that we've done the handler setup.
458 */
459 tracehook_signal_handler(signr, &info, &ka, regs,
460 test_thread_flag(TIF_SINGLE_STEP));
461 }
462 return; 438 return;
463 } 439 }
464 440
@@ -484,10 +460,7 @@ void do_signal(struct pt_regs *regs)
484 /* 460 /*
485 * If there's no signal to deliver, we just put the saved sigmask back. 461 * If there's no signal to deliver, we just put the saved sigmask back.
486 */ 462 */
487 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 463 restore_saved_sigmask();
488 clear_thread_flag(TIF_RESTORE_SIGMASK);
489 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
490 }
491} 464}
492 465
493void do_notify_resume(struct pt_regs *regs) 466void do_notify_resume(struct pt_regs *regs)
diff --git a/arch/score/kernel/signal.c b/arch/score/kernel/signal.c
index 302838d3acf6..e382c52ca0d9 100644
--- a/arch/score/kernel/signal.c
+++ b/arch/score/kernel/signal.c
@@ -34,8 +34,6 @@
34#include <asm/syscalls.h> 34#include <asm/syscalls.h>
35#include <asm/ucontext.h> 35#include <asm/ucontext.h>
36 36
37#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
38
39struct rt_sigframe { 37struct rt_sigframe {
40 u32 rs_ass[4]; /* argument save space */ 38 u32 rs_ass[4]; /* argument save space */
41 u32 rs_code[2]; /* signal trampoline */ 39 u32 rs_code[2]; /* signal trampoline */
@@ -162,7 +160,6 @@ score_rt_sigreturn(struct pt_regs *regs)
162 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set))) 160 if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
163 goto badframe; 161 goto badframe;
164 162
165 sigdelsetmask(&set, ~_BLOCKABLE);
166 set_current_blocked(&set); 163 set_current_blocked(&set);
167 164
168 sig = restore_sigcontext(regs, &frame->rs_uc.uc_mcontext); 165 sig = restore_sigcontext(regs, &frame->rs_uc.uc_mcontext);
@@ -241,11 +238,9 @@ give_sigsegv:
241 return -EFAULT; 238 return -EFAULT;
242} 239}
243 240
244static int handle_signal(unsigned long sig, siginfo_t *info, 241static void handle_signal(unsigned long sig, siginfo_t *info,
245 struct k_sigaction *ka, sigset_t *oldset, struct pt_regs *regs) 242 struct k_sigaction *ka, struct pt_regs *regs)
246{ 243{
247 int ret;
248
249 if (regs->is_syscall) { 244 if (regs->is_syscall) {
250 switch (regs->regs[4]) { 245 switch (regs->regs[4]) {
251 case ERESTART_RESTARTBLOCK: 246 case ERESTART_RESTARTBLOCK:
@@ -269,18 +264,15 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
269 /* 264 /*
270 * Set up the stack frame 265 * Set up the stack frame
271 */ 266 */
272 ret = setup_rt_frame(ka, regs, sig, oldset, info); 267 if (setup_rt_frame(ka, regs, sig, sigmask_to_save(), info) < 0)
273 268 return;
274 if (ret == 0)
275 block_sigmask(ka, sig);
276 269
277 return ret; 270 signal_delivered(sig, info, ka, regs, 0);
278} 271}
279 272
280static void do_signal(struct pt_regs *regs) 273static void do_signal(struct pt_regs *regs)
281{ 274{
282 struct k_sigaction ka; 275 struct k_sigaction ka;
283 sigset_t *oldset;
284 siginfo_t info; 276 siginfo_t info;
285 int signr; 277 int signr;
286 278
@@ -292,25 +284,10 @@ static void do_signal(struct pt_regs *regs)
292 if (!user_mode(regs)) 284 if (!user_mode(regs))
293 return; 285 return;
294 286
295 if (test_thread_flag(TIF_RESTORE_SIGMASK))
296 oldset = &current->saved_sigmask;
297 else
298 oldset = &current->blocked;
299
300 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 287 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
301 if (signr > 0) { 288 if (signr > 0) {
302 /* Actually deliver the signal. */ 289 /* Actually deliver the signal. */
303 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 290 handle_signal(signr, &info, &ka, regs);
304 /*
305 * A signal was successfully delivered; the saved
306 * sigmask will have been stored in the signal frame,
307 * and will be restored by sigreturn, so we can simply
308 * clear the TIF_RESTORE_SIGMASK flag.
309 */
310 if (test_thread_flag(TIF_RESTORE_SIGMASK))
311 clear_thread_flag(TIF_RESTORE_SIGMASK);
312 }
313
314 return; 291 return;
315 } 292 }
316 293
@@ -337,10 +314,7 @@ static void do_signal(struct pt_regs *regs)
337 * If there's no signal to deliver, we just put the saved sigmask 314 * If there's no signal to deliver, we just put the saved sigmask
338 * back 315 * back
339 */ 316 */
340 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 317 restore_saved_sigmask();
341 clear_thread_flag(TIF_RESTORE_SIGMASK);
342 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
343 }
344} 318}
345 319
346/* 320/*
diff --git a/arch/sh/include/asm/thread_info.h b/arch/sh/include/asm/thread_info.h
index 0c04ffc4f12c..bc13b57cdc83 100644
--- a/arch/sh/include/asm/thread_info.h
+++ b/arch/sh/include/asm/thread_info.h
@@ -169,7 +169,7 @@ static inline void set_restore_sigmask(void)
169{ 169{
170 struct thread_info *ti = current_thread_info(); 170 struct thread_info *ti = current_thread_info();
171 ti->status |= TS_RESTORE_SIGMASK; 171 ti->status |= TS_RESTORE_SIGMASK;
172 set_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags); 172 WARN_ON(!test_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags));
173} 173}
174 174
175#define TI_FLAG_FAULT_CODE_SHIFT 24 175#define TI_FLAG_FAULT_CODE_SHIFT 24
@@ -189,6 +189,23 @@ static inline unsigned int get_thread_fault_code(void)
189 struct thread_info *ti = current_thread_info(); 189 struct thread_info *ti = current_thread_info();
190 return ti->flags >> TI_FLAG_FAULT_CODE_SHIFT; 190 return ti->flags >> TI_FLAG_FAULT_CODE_SHIFT;
191} 191}
192
193static inline void clear_restore_sigmask(void)
194{
195 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
196}
197static inline bool test_restore_sigmask(void)
198{
199 return current_thread_info()->status & TS_RESTORE_SIGMASK;
200}
201static inline bool test_and_clear_restore_sigmask(void)
202{
203 struct thread_info *ti = current_thread_info();
204 if (!(ti->status & TS_RESTORE_SIGMASK))
205 return false;
206 ti->status &= ~TS_RESTORE_SIGMASK;
207 return true;
208}
192#endif /* !__ASSEMBLY__ */ 209#endif /* !__ASSEMBLY__ */
193 210
194#endif /* __KERNEL__ */ 211#endif /* __KERNEL__ */
diff --git a/arch/sh/kernel/signal_32.c b/arch/sh/kernel/signal_32.c
index 9d7bfd66f189..d6b7b6154f87 100644
--- a/arch/sh/kernel/signal_32.c
+++ b/arch/sh/kernel/signal_32.c
@@ -32,8 +32,6 @@
32#include <asm/syscalls.h> 32#include <asm/syscalls.h>
33#include <asm/fpu.h> 33#include <asm/fpu.h>
34 34
35#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
36
37struct fdpic_func_descriptor { 35struct fdpic_func_descriptor {
38 unsigned long text; 36 unsigned long text;
39 unsigned long GOT; 37 unsigned long GOT;
@@ -226,7 +224,6 @@ asmlinkage int sys_sigreturn(unsigned long r4, unsigned long r5,
226 sizeof(frame->extramask)))) 224 sizeof(frame->extramask))))
227 goto badframe; 225 goto badframe;
228 226
229 sigdelsetmask(&set, ~_BLOCKABLE);
230 set_current_blocked(&set); 227 set_current_blocked(&set);
231 228
232 if (restore_sigcontext(regs, &frame->sc, &r0)) 229 if (restore_sigcontext(regs, &frame->sc, &r0))
@@ -256,7 +253,6 @@ asmlinkage int sys_rt_sigreturn(unsigned long r4, unsigned long r5,
256 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 253 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
257 goto badframe; 254 goto badframe;
258 255
259 sigdelsetmask(&set, ~_BLOCKABLE);
260 set_current_blocked(&set); 256 set_current_blocked(&set);
261 257
262 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0)) 258 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &r0))
@@ -522,10 +518,11 @@ handle_syscall_restart(unsigned long save_r0, struct pt_regs *regs,
522/* 518/*
523 * OK, we're invoking a handler 519 * OK, we're invoking a handler
524 */ 520 */
525static int 521static void
526handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info, 522handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
527 sigset_t *oldset, struct pt_regs *regs, unsigned int save_r0) 523 struct pt_regs *regs, unsigned int save_r0)
528{ 524{
525 sigset_t *oldset = sigmask_to_save();
529 int ret; 526 int ret;
530 527
531 /* Set up the stack frame */ 528 /* Set up the stack frame */
@@ -534,10 +531,10 @@ handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
534 else 531 else
535 ret = setup_frame(sig, ka, oldset, regs); 532 ret = setup_frame(sig, ka, oldset, regs);
536 533
537 if (ret == 0) 534 if (ret)
538 block_sigmask(ka, sig); 535 return;
539 536 signal_delivered(sig, info, ka, regs,
540 return ret; 537 test_thread_flag(TIF_SINGLESTEP));
541} 538}
542 539
543/* 540/*
@@ -554,7 +551,6 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
554 siginfo_t info; 551 siginfo_t info;
555 int signr; 552 int signr;
556 struct k_sigaction ka; 553 struct k_sigaction ka;
557 sigset_t *oldset;
558 554
559 /* 555 /*
560 * We want the common case to go fast, which 556 * We want the common case to go fast, which
@@ -565,30 +561,12 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
565 if (!user_mode(regs)) 561 if (!user_mode(regs))
566 return; 562 return;
567 563
568 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
569 oldset = &current->saved_sigmask;
570 else
571 oldset = &current->blocked;
572
573 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 564 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
574 if (signr > 0) { 565 if (signr > 0) {
575 handle_syscall_restart(save_r0, regs, &ka.sa); 566 handle_syscall_restart(save_r0, regs, &ka.sa);
576 567
577 /* Whee! Actually deliver the signal. */ 568 /* Whee! Actually deliver the signal. */
578 if (handle_signal(signr, &ka, &info, oldset, 569 handle_signal(signr, &ka, &info, regs, save_r0);
579 regs, save_r0) == 0) {
580 /*
581 * A signal was successfully delivered; the saved
582 * sigmask will have been stored in the signal frame,
583 * and will be restored by sigreturn, so we can simply
584 * clear the TS_RESTORE_SIGMASK flag
585 */
586 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
587
588 tracehook_signal_handler(signr, &info, &ka, regs,
589 test_thread_flag(TIF_SINGLESTEP));
590 }
591
592 return; 570 return;
593 } 571 }
594 572
@@ -610,10 +588,7 @@ static void do_signal(struct pt_regs *regs, unsigned int save_r0)
610 * If there's no signal to deliver, we just put the saved sigmask 588 * If there's no signal to deliver, we just put the saved sigmask
611 * back. 589 * back.
612 */ 590 */
613 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 591 restore_saved_sigmask();
614 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
615 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
616 }
617} 592}
618 593
619asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned int save_r0, 594asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned int save_r0,
diff --git a/arch/sh/kernel/signal_64.c b/arch/sh/kernel/signal_64.c
index aa6428430842..6b5b3dfe886b 100644
--- a/arch/sh/kernel/signal_64.c
+++ b/arch/sh/kernel/signal_64.c
@@ -41,11 +41,9 @@
41 41
42#define DEBUG_SIG 0 42#define DEBUG_SIG 0
43 43
44#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) 44static void
45
46static int
47handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, 45handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
48 sigset_t *oldset, struct pt_regs * regs); 46 struct pt_regs * regs);
49 47
50static inline void 48static inline void
51handle_syscall_restart(struct pt_regs *regs, struct sigaction *sa) 49handle_syscall_restart(struct pt_regs *regs, struct sigaction *sa)
@@ -88,7 +86,6 @@ static void do_signal(struct pt_regs *regs)
88 siginfo_t info; 86 siginfo_t info;
89 int signr; 87 int signr;
90 struct k_sigaction ka; 88 struct k_sigaction ka;
91 sigset_t *oldset;
92 89
93 /* 90 /*
94 * We want the common case to go fast, which 91 * We want the common case to go fast, which
@@ -99,28 +96,13 @@ static void do_signal(struct pt_regs *regs)
99 if (!user_mode(regs)) 96 if (!user_mode(regs))
100 return; 97 return;
101 98
102 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
103 oldset = &current->saved_sigmask;
104 else
105 oldset = &current->blocked;
106
107 signr = get_signal_to_deliver(&info, &ka, regs, 0); 99 signr = get_signal_to_deliver(&info, &ka, regs, 0);
108 if (signr > 0) { 100 if (signr > 0) {
109 handle_syscall_restart(regs, &ka.sa); 101 handle_syscall_restart(regs, &ka.sa);
110 102
111 /* Whee! Actually deliver the signal. */ 103 /* Whee! Actually deliver the signal. */
112 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 104 handle_signal(signr, &info, &ka, regs);
113 /* 105 return;
114 * If a signal was successfully delivered, the
115 * saved sigmask is in its frame, and we can
116 * clear the TS_RESTORE_SIGMASK flag.
117 */
118 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
119
120 tracehook_signal_handler(signr, &info, &ka, regs,
121 test_thread_flag(TIF_SINGLESTEP));
122 return;
123 }
124 } 106 }
125 107
126 /* Did we come from a system call? */ 108 /* Did we come from a system call? */
@@ -143,12 +125,7 @@ static void do_signal(struct pt_regs *regs)
143 } 125 }
144 126
145 /* No signal to deliver -- put the saved sigmask back */ 127 /* No signal to deliver -- put the saved sigmask back */
146 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 128 restore_saved_sigmask();
147 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
148 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
149 }
150
151 return;
152} 129}
153 130
154/* 131/*
@@ -351,7 +328,6 @@ asmlinkage int sys_sigreturn(unsigned long r2, unsigned long r3,
351 sizeof(frame->extramask)))) 328 sizeof(frame->extramask))))
352 goto badframe; 329 goto badframe;
353 330
354 sigdelsetmask(&set, ~_BLOCKABLE);
355 set_current_blocked(&set); 331 set_current_blocked(&set);
356 332
357 if (restore_sigcontext(regs, &frame->sc, &ret)) 333 if (restore_sigcontext(regs, &frame->sc, &ret))
@@ -384,7 +360,6 @@ asmlinkage int sys_rt_sigreturn(unsigned long r2, unsigned long r3,
384 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 360 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
385 goto badframe; 361 goto badframe;
386 362
387 sigdelsetmask(&set, ~_BLOCKABLE);
388 set_current_blocked(&set); 363 set_current_blocked(&set);
389 364
390 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ret)) 365 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ret))
@@ -659,10 +634,11 @@ give_sigsegv:
659/* 634/*
660 * OK, we're invoking a handler 635 * OK, we're invoking a handler
661 */ 636 */
662static int 637static void
663handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, 638handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
664 sigset_t *oldset, struct pt_regs * regs) 639 struct pt_regs * regs)
665{ 640{
641 sigset_t *oldset = sigmask_to_save();
666 int ret; 642 int ret;
667 643
668 /* Set up the stack frame */ 644 /* Set up the stack frame */
@@ -671,10 +647,11 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
671 else 647 else
672 ret = setup_frame(sig, ka, oldset, regs); 648 ret = setup_frame(sig, ka, oldset, regs);
673 649
674 if (ret == 0) 650 if (ret)
675 block_sigmask(ka, sig); 651 return;
676 652
677 return ret; 653 signal_delivered(sig, info, ka, regs,
654 test_thread_flag(TIF_SINGLESTEP));
678} 655}
679 656
680asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags) 657asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
index 5af664932452..e6cd224506a9 100644
--- a/arch/sparc/include/asm/thread_info_32.h
+++ b/arch/sparc/include/asm/thread_info_32.h
@@ -131,8 +131,7 @@ register struct thread_info *current_thread_info_reg asm("g6");
131#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG) 131#define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
132 132
133#define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | \ 133#define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | \
134 _TIF_SIGPENDING | \ 134 _TIF_SIGPENDING)
135 _TIF_RESTORE_SIGMASK)
136 135
137#endif /* __KERNEL__ */ 136#endif /* __KERNEL__ */
138 137
diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
index 7f0981b09451..cfa8c38fb9c8 100644
--- a/arch/sparc/include/asm/thread_info_64.h
+++ b/arch/sparc/include/asm/thread_info_64.h
@@ -238,7 +238,23 @@ static inline void set_restore_sigmask(void)
238{ 238{
239 struct thread_info *ti = current_thread_info(); 239 struct thread_info *ti = current_thread_info();
240 ti->status |= TS_RESTORE_SIGMASK; 240 ti->status |= TS_RESTORE_SIGMASK;
241 set_bit(TIF_SIGPENDING, &ti->flags); 241 WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
242}
243static inline void clear_restore_sigmask(void)
244{
245 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
246}
247static inline bool test_restore_sigmask(void)
248{
249 return current_thread_info()->status & TS_RESTORE_SIGMASK;
250}
251static inline bool test_and_clear_restore_sigmask(void)
252{
253 struct thread_info *ti = current_thread_info();
254 if (!(ti->status & TS_RESTORE_SIGMASK))
255 return false;
256 ti->status &= ~TS_RESTORE_SIGMASK;
257 return true;
242} 258}
243#endif /* !__ASSEMBLY__ */ 259#endif /* !__ASSEMBLY__ */
244 260
diff --git a/arch/sparc/kernel/signal32.c b/arch/sparc/kernel/signal32.c
index bb1513e45f1a..a53e0a5fd3a3 100644
--- a/arch/sparc/kernel/signal32.c
+++ b/arch/sparc/kernel/signal32.c
@@ -32,8 +32,6 @@
32 32
33#include "sigutil.h" 33#include "sigutil.h"
34 34
35#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
36
37/* This magic should be in g_upper[0] for all upper parts 35/* This magic should be in g_upper[0] for all upper parts
38 * to be valid. 36 * to be valid.
39 */ 37 */
@@ -274,7 +272,6 @@ void do_sigreturn32(struct pt_regs *regs)
274 case 2: set.sig[1] = seta[2] + (((long)seta[3]) << 32); 272 case 2: set.sig[1] = seta[2] + (((long)seta[3]) << 32);
275 case 1: set.sig[0] = seta[0] + (((long)seta[1]) << 32); 273 case 1: set.sig[0] = seta[0] + (((long)seta[1]) << 32);
276 } 274 }
277 sigdelsetmask(&set, ~_BLOCKABLE);
278 set_current_blocked(&set); 275 set_current_blocked(&set);
279 return; 276 return;
280 277
@@ -376,7 +373,6 @@ asmlinkage void do_rt_sigreturn32(struct pt_regs *regs)
376 case 2: set.sig[1] = seta.sig[2] + (((long)seta.sig[3]) << 32); 373 case 2: set.sig[1] = seta.sig[2] + (((long)seta.sig[3]) << 32);
377 case 1: set.sig[0] = seta.sig[0] + (((long)seta.sig[1]) << 32); 374 case 1: set.sig[0] = seta.sig[0] + (((long)seta.sig[1]) << 32);
378 } 375 }
379 sigdelsetmask(&set, ~_BLOCKABLE);
380 set_current_blocked(&set); 376 set_current_blocked(&set);
381 return; 377 return;
382segv: 378segv:
@@ -775,7 +771,7 @@ sigsegv:
775 return -EFAULT; 771 return -EFAULT;
776} 772}
777 773
778static inline int handle_signal32(unsigned long signr, struct k_sigaction *ka, 774static inline void handle_signal32(unsigned long signr, struct k_sigaction *ka,
779 siginfo_t *info, 775 siginfo_t *info,
780 sigset_t *oldset, struct pt_regs *regs) 776 sigset_t *oldset, struct pt_regs *regs)
781{ 777{
@@ -787,12 +783,9 @@ static inline int handle_signal32(unsigned long signr, struct k_sigaction *ka,
787 err = setup_frame32(ka, regs, signr, oldset); 783 err = setup_frame32(ka, regs, signr, oldset);
788 784
789 if (err) 785 if (err)
790 return err; 786 return;
791
792 block_sigmask(ka, signr);
793 tracehook_signal_handler(signr, info, ka, regs, 0);
794 787
795 return 0; 788 signal_delivered(signr, info, ka, regs, 0);
796} 789}
797 790
798static inline void syscall_restart32(unsigned long orig_i0, struct pt_regs *regs, 791static inline void syscall_restart32(unsigned long orig_i0, struct pt_regs *regs,
@@ -841,14 +834,7 @@ void do_signal32(sigset_t *oldset, struct pt_regs * regs)
841 if (signr > 0) { 834 if (signr > 0) {
842 if (restart_syscall) 835 if (restart_syscall)
843 syscall_restart32(orig_i0, regs, &ka.sa); 836 syscall_restart32(orig_i0, regs, &ka.sa);
844 if (handle_signal32(signr, &ka, &info, oldset, regs) == 0) { 837 handle_signal32(signr, &ka, &info, oldset, regs);
845 /* A signal was successfully delivered; the saved
846 * sigmask will have been stored in the signal frame,
847 * and will be restored by sigreturn, so we can simply
848 * clear the TS_RESTORE_SIGMASK flag.
849 */
850 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
851 }
852 return; 838 return;
853 } 839 }
854 if (restart_syscall && 840 if (restart_syscall &&
@@ -872,10 +858,7 @@ void do_signal32(sigset_t *oldset, struct pt_regs * regs)
872 /* If there's no signal to deliver, we just put the saved sigmask 858 /* If there's no signal to deliver, we just put the saved sigmask
873 * back 859 * back
874 */ 860 */
875 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 861 restore_saved_sigmask();
876 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
877 set_current_blocked(&current->saved_sigmask);
878 }
879} 862}
880 863
881struct sigstack32 { 864struct sigstack32 {
diff --git a/arch/sparc/kernel/signal_32.c b/arch/sparc/kernel/signal_32.c
index 6b42e8622d12..68f9c8650af4 100644
--- a/arch/sparc/kernel/signal_32.c
+++ b/arch/sparc/kernel/signal_32.c
@@ -29,8 +29,6 @@
29 29
30#include "sigutil.h" 30#include "sigutil.h"
31 31
32#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
33
34extern void fpsave(unsigned long *fpregs, unsigned long *fsr, 32extern void fpsave(unsigned long *fpregs, unsigned long *fsr,
35 void *fpqueue, unsigned long *fpqdepth); 33 void *fpqueue, unsigned long *fpqdepth);
36extern void fpload(unsigned long *fpregs, unsigned long *fsr); 34extern void fpload(unsigned long *fpregs, unsigned long *fsr);
@@ -130,7 +128,6 @@ asmlinkage void do_sigreturn(struct pt_regs *regs)
130 if (err) 128 if (err)
131 goto segv_and_exit; 129 goto segv_and_exit;
132 130
133 sigdelsetmask(&set, ~_BLOCKABLE);
134 set_current_blocked(&set); 131 set_current_blocked(&set);
135 return; 132 return;
136 133
@@ -197,7 +194,6 @@ asmlinkage void do_rt_sigreturn(struct pt_regs *regs)
197 goto segv; 194 goto segv;
198 } 195 }
199 196
200 sigdelsetmask(&set, ~_BLOCKABLE);
201 set_current_blocked(&set); 197 set_current_blocked(&set);
202 return; 198 return;
203segv: 199segv:
@@ -449,10 +445,11 @@ sigsegv:
449 return -EFAULT; 445 return -EFAULT;
450} 446}
451 447
452static inline int 448static inline void
453handle_signal(unsigned long signr, struct k_sigaction *ka, 449handle_signal(unsigned long signr, struct k_sigaction *ka,
454 siginfo_t *info, sigset_t *oldset, struct pt_regs *regs) 450 siginfo_t *info, struct pt_regs *regs)
455{ 451{
452 sigset_t *oldset = sigmask_to_save();
456 int err; 453 int err;
457 454
458 if (ka->sa.sa_flags & SA_SIGINFO) 455 if (ka->sa.sa_flags & SA_SIGINFO)
@@ -461,12 +458,9 @@ handle_signal(unsigned long signr, struct k_sigaction *ka,
461 err = setup_frame(ka, regs, signr, oldset); 458 err = setup_frame(ka, regs, signr, oldset);
462 459
463 if (err) 460 if (err)
464 return err; 461 return;
465
466 block_sigmask(ka, signr);
467 tracehook_signal_handler(signr, info, ka, regs, 0);
468 462
469 return 0; 463 signal_delivered(signr, info, ka, regs, 0);
470} 464}
471 465
472static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs, 466static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
@@ -498,7 +492,6 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
498{ 492{
499 struct k_sigaction ka; 493 struct k_sigaction ka;
500 int restart_syscall; 494 int restart_syscall;
501 sigset_t *oldset;
502 siginfo_t info; 495 siginfo_t info;
503 int signr; 496 int signr;
504 497
@@ -523,11 +516,6 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
523 if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C)) 516 if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C))
524 regs->u_regs[UREG_G6] = orig_i0; 517 regs->u_regs[UREG_G6] = orig_i0;
525 518
526 if (test_thread_flag(TIF_RESTORE_SIGMASK))
527 oldset = &current->saved_sigmask;
528 else
529 oldset = &current->blocked;
530
531 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 519 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
532 520
533 /* If the debugger messes with the program counter, it clears 521 /* If the debugger messes with the program counter, it clears
@@ -544,15 +532,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
544 if (signr > 0) { 532 if (signr > 0) {
545 if (restart_syscall) 533 if (restart_syscall)
546 syscall_restart(orig_i0, regs, &ka.sa); 534 syscall_restart(orig_i0, regs, &ka.sa);
547 if (handle_signal(signr, &ka, &info, oldset, regs) == 0) { 535 handle_signal(signr, &ka, &info, regs);
548 /* a signal was successfully delivered; the saved
549 * sigmask will have been stored in the signal frame,
550 * and will be restored by sigreturn, so we can simply
551 * clear the TIF_RESTORE_SIGMASK flag.
552 */
553 if (test_thread_flag(TIF_RESTORE_SIGMASK))
554 clear_thread_flag(TIF_RESTORE_SIGMASK);
555 }
556 return; 536 return;
557 } 537 }
558 if (restart_syscall && 538 if (restart_syscall &&
@@ -576,16 +556,13 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
576 /* if there's no signal to deliver, we just put the saved sigmask 556 /* if there's no signal to deliver, we just put the saved sigmask
577 * back 557 * back
578 */ 558 */
579 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 559 restore_saved_sigmask();
580 clear_thread_flag(TIF_RESTORE_SIGMASK);
581 set_current_blocked(&current->saved_sigmask);
582 }
583} 560}
584 561
585void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, 562void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0,
586 unsigned long thread_info_flags) 563 unsigned long thread_info_flags)
587{ 564{
588 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 565 if (thread_info_flags & _TIF_SIGPENDING)
589 do_signal(regs, orig_i0); 566 do_signal(regs, orig_i0);
590 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 567 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
591 clear_thread_flag(TIF_NOTIFY_RESUME); 568 clear_thread_flag(TIF_NOTIFY_RESUME);
diff --git a/arch/sparc/kernel/signal_64.c b/arch/sparc/kernel/signal_64.c
index c82cf1cc3965..867de2f8189c 100644
--- a/arch/sparc/kernel/signal_64.c
+++ b/arch/sparc/kernel/signal_64.c
@@ -38,8 +38,6 @@
38#include "systbls.h" 38#include "systbls.h"
39#include "sigutil.h" 39#include "sigutil.h"
40 40
41#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
42
43/* {set, get}context() needed for 64-bit SparcLinux userland. */ 41/* {set, get}context() needed for 64-bit SparcLinux userland. */
44asmlinkage void sparc64_set_context(struct pt_regs *regs) 42asmlinkage void sparc64_set_context(struct pt_regs *regs)
45{ 43{
@@ -71,7 +69,6 @@ asmlinkage void sparc64_set_context(struct pt_regs *regs)
71 if (__copy_from_user(&set, &ucp->uc_sigmask, sizeof(sigset_t))) 69 if (__copy_from_user(&set, &ucp->uc_sigmask, sizeof(sigset_t)))
72 goto do_sigsegv; 70 goto do_sigsegv;
73 } 71 }
74 sigdelsetmask(&set, ~_BLOCKABLE);
75 set_current_blocked(&set); 72 set_current_blocked(&set);
76 } 73 }
77 if (test_thread_flag(TIF_32BIT)) { 74 if (test_thread_flag(TIF_32BIT)) {
@@ -315,7 +312,6 @@ void do_rt_sigreturn(struct pt_regs *regs)
315 /* Prevent syscall restart. */ 312 /* Prevent syscall restart. */
316 pt_regs_clear_syscall(regs); 313 pt_regs_clear_syscall(regs);
317 314
318 sigdelsetmask(&set, ~_BLOCKABLE);
319 set_current_blocked(&set); 315 set_current_blocked(&set);
320 return; 316 return;
321segv: 317segv:
@@ -466,7 +462,7 @@ sigsegv:
466 return -EFAULT; 462 return -EFAULT;
467} 463}
468 464
469static inline int handle_signal(unsigned long signr, struct k_sigaction *ka, 465static inline void handle_signal(unsigned long signr, struct k_sigaction *ka,
470 siginfo_t *info, 466 siginfo_t *info,
471 sigset_t *oldset, struct pt_regs *regs) 467 sigset_t *oldset, struct pt_regs *regs)
472{ 468{
@@ -475,12 +471,9 @@ static inline int handle_signal(unsigned long signr, struct k_sigaction *ka,
475 err = setup_rt_frame(ka, regs, signr, oldset, 471 err = setup_rt_frame(ka, regs, signr, oldset,
476 (ka->sa.sa_flags & SA_SIGINFO) ? info : NULL); 472 (ka->sa.sa_flags & SA_SIGINFO) ? info : NULL);
477 if (err) 473 if (err)
478 return err; 474 return;
479
480 block_sigmask(ka, signr);
481 tracehook_signal_handler(signr, info, ka, regs, 0);
482 475
483 return 0; 476 signal_delivered(signr, info, ka, regs, 0);
484} 477}
485 478
486static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs, 479static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
@@ -512,7 +505,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
512{ 505{
513 struct k_sigaction ka; 506 struct k_sigaction ka;
514 int restart_syscall; 507 int restart_syscall;
515 sigset_t *oldset; 508 sigset_t *oldset = sigmask_to_save();
516 siginfo_t info; 509 siginfo_t info;
517 int signr; 510 int signr;
518 511
@@ -538,11 +531,6 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
538 (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY))) 531 (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY)))
539 regs->u_regs[UREG_G6] = orig_i0; 532 regs->u_regs[UREG_G6] = orig_i0;
540 533
541 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
542 oldset = &current->saved_sigmask;
543 else
544 oldset = &current->blocked;
545
546#ifdef CONFIG_COMPAT 534#ifdef CONFIG_COMPAT
547 if (test_thread_flag(TIF_32BIT)) { 535 if (test_thread_flag(TIF_32BIT)) {
548 extern void do_signal32(sigset_t *, struct pt_regs *); 536 extern void do_signal32(sigset_t *, struct pt_regs *);
@@ -563,14 +551,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
563 if (signr > 0) { 551 if (signr > 0) {
564 if (restart_syscall) 552 if (restart_syscall)
565 syscall_restart(orig_i0, regs, &ka.sa); 553 syscall_restart(orig_i0, regs, &ka.sa);
566 if (handle_signal(signr, &ka, &info, oldset, regs) == 0) { 554 handle_signal(signr, &ka, &info, oldset, regs);
567 /* A signal was successfully delivered; the saved
568 * sigmask will have been stored in the signal frame,
569 * and will be restored by sigreturn, so we can simply
570 * clear the TS_RESTORE_SIGMASK flag.
571 */
572 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
573 }
574 return; 555 return;
575 } 556 }
576 if (restart_syscall && 557 if (restart_syscall &&
@@ -594,10 +575,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
594 /* If there's no signal to deliver, we just put the saved sigmask 575 /* If there's no signal to deliver, we just put the saved sigmask
595 * back 576 * back
596 */ 577 */
597 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 578 restore_saved_sigmask();
598 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
599 set_current_blocked(&current->saved_sigmask);
600 }
601} 579}
602 580
603void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags) 581void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags)
diff --git a/arch/tile/include/asm/thread_info.h b/arch/tile/include/asm/thread_info.h
index 656c486e64fa..7e1fef36bde6 100644
--- a/arch/tile/include/asm/thread_info.h
+++ b/arch/tile/include/asm/thread_info.h
@@ -166,7 +166,23 @@ static inline void set_restore_sigmask(void)
166{ 166{
167 struct thread_info *ti = current_thread_info(); 167 struct thread_info *ti = current_thread_info();
168 ti->status |= TS_RESTORE_SIGMASK; 168 ti->status |= TS_RESTORE_SIGMASK;
169 set_bit(TIF_SIGPENDING, &ti->flags); 169 WARN_ON(!test_bit(TIF_SIGPENDING, &ti->flags));
170}
171static inline void clear_restore_sigmask(void)
172{
173 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
174}
175static inline bool test_restore_sigmask(void)
176{
177 return current_thread_info()->status & TS_RESTORE_SIGMASK;
178}
179static inline bool test_and_clear_restore_sigmask(void)
180{
181 struct thread_info *ti = current_thread_info();
182 if (!(ti->status & TS_RESTORE_SIGMASK))
183 return false;
184 ti->status &= ~TS_RESTORE_SIGMASK;
185 return true;
170} 186}
171#endif /* !__ASSEMBLY__ */ 187#endif /* !__ASSEMBLY__ */
172 188
diff --git a/arch/tile/kernel/compat_signal.c b/arch/tile/kernel/compat_signal.c
index cdef6e5ec022..474571b84085 100644
--- a/arch/tile/kernel/compat_signal.c
+++ b/arch/tile/kernel/compat_signal.c
@@ -118,8 +118,6 @@ struct compat_rt_sigframe {
118 struct compat_ucontext uc; 118 struct compat_ucontext uc;
119}; 119};
120 120
121#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
122
123long compat_sys_rt_sigaction(int sig, struct compat_sigaction __user *act, 121long compat_sys_rt_sigaction(int sig, struct compat_sigaction __user *act,
124 struct compat_sigaction __user *oact, 122 struct compat_sigaction __user *oact,
125 size_t sigsetsize) 123 size_t sigsetsize)
@@ -302,7 +300,6 @@ long compat_sys_rt_sigreturn(struct pt_regs *regs)
302 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 300 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
303 goto badframe; 301 goto badframe;
304 302
305 sigdelsetmask(&set, ~_BLOCKABLE);
306 set_current_blocked(&set); 303 set_current_blocked(&set);
307 304
308 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 305 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
diff --git a/arch/tile/kernel/signal.c b/arch/tile/kernel/signal.c
index f79d4b88c747..e29b0553211d 100644
--- a/arch/tile/kernel/signal.c
+++ b/arch/tile/kernel/signal.c
@@ -37,8 +37,6 @@
37 37
38#define DEBUG_SIG 0 38#define DEBUG_SIG 0
39 39
40#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
41
42SYSCALL_DEFINE3(sigaltstack, const stack_t __user *, uss, 40SYSCALL_DEFINE3(sigaltstack, const stack_t __user *, uss,
43 stack_t __user *, uoss, struct pt_regs *, regs) 41 stack_t __user *, uoss, struct pt_regs *, regs)
44{ 42{
@@ -96,7 +94,6 @@ SYSCALL_DEFINE1(rt_sigreturn, struct pt_regs *, regs)
96 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 94 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
97 goto badframe; 95 goto badframe;
98 96
99 sigdelsetmask(&set, ~_BLOCKABLE);
100 set_current_blocked(&set); 97 set_current_blocked(&set);
101 98
102 if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) 99 if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
@@ -242,10 +239,11 @@ give_sigsegv:
242 * OK, we're invoking a handler 239 * OK, we're invoking a handler
243 */ 240 */
244 241
245static int handle_signal(unsigned long sig, siginfo_t *info, 242static void handle_signal(unsigned long sig, siginfo_t *info,
246 struct k_sigaction *ka, sigset_t *oldset, 243 struct k_sigaction *ka,
247 struct pt_regs *regs) 244 struct pt_regs *regs)
248{ 245{
246 sigset_t *oldset = sigmask_to_save();
249 int ret; 247 int ret;
250 248
251 /* Are we from a system call? */ 249 /* Are we from a system call? */
@@ -278,15 +276,9 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
278 else 276 else
279#endif 277#endif
280 ret = setup_rt_frame(sig, ka, info, oldset, regs); 278 ret = setup_rt_frame(sig, ka, info, oldset, regs);
281 if (ret == 0) { 279 if (ret)
282 /* This code is only called from system calls or from 280 return;
283 * the work_pending path in the return-to-user code, and 281 signal_delivered(sig, info, ka, regs, 0);
284 * either way we can re-enable interrupts unconditionally.
285 */
286 block_sigmask(ka, sig);
287 }
288
289 return ret;
290} 282}
291 283
292/* 284/*
@@ -299,7 +291,6 @@ void do_signal(struct pt_regs *regs)
299 siginfo_t info; 291 siginfo_t info;
300 int signr; 292 int signr;
301 struct k_sigaction ka; 293 struct k_sigaction ka;
302 sigset_t *oldset;
303 294
304 /* 295 /*
305 * i386 will check if we're coming from kernel mode and bail out 296 * i386 will check if we're coming from kernel mode and bail out
@@ -308,24 +299,10 @@ void do_signal(struct pt_regs *regs)
308 * helpful, we can reinstate the check on "!user_mode(regs)". 299 * helpful, we can reinstate the check on "!user_mode(regs)".
309 */ 300 */
310 301
311 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
312 oldset = &current->saved_sigmask;
313 else
314 oldset = &current->blocked;
315
316 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 302 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
317 if (signr > 0) { 303 if (signr > 0) {
318 /* Whee! Actually deliver the signal. */ 304 /* Whee! Actually deliver the signal. */
319 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) { 305 handle_signal(signr, &info, &ka, regs);
320 /*
321 * A signal was successfully delivered; the saved
322 * sigmask will have been stored in the signal frame,
323 * and will be restored by sigreturn, so we can simply
324 * clear the TS_RESTORE_SIGMASK flag.
325 */
326 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
327 }
328
329 goto done; 306 goto done;
330 } 307 }
331 308
@@ -350,10 +327,7 @@ void do_signal(struct pt_regs *regs)
350 } 327 }
351 328
352 /* If there's no signal to deliver, just put the saved sigmask back. */ 329 /* If there's no signal to deliver, just put the saved sigmask back. */
353 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 330 restore_saved_sigmask();
354 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
355 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
356 }
357 331
358done: 332done:
359 /* Avoid double syscall restart if there are nested signals. */ 333 /* Avoid double syscall restart if there are nested signals. */
diff --git a/arch/um/include/shared/frame_kern.h b/arch/um/include/shared/frame_kern.h
index 76078490c258..e584e40ee832 100644
--- a/arch/um/include/shared/frame_kern.h
+++ b/arch/um/include/shared/frame_kern.h
@@ -6,9 +6,6 @@
6#ifndef __FRAME_KERN_H_ 6#ifndef __FRAME_KERN_H_
7#define __FRAME_KERN_H_ 7#define __FRAME_KERN_H_
8 8
9#define _S(nr) (1<<((nr)-1))
10#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
11
12extern int setup_signal_stack_sc(unsigned long stack_top, int sig, 9extern int setup_signal_stack_sc(unsigned long stack_top, int sig,
13 struct k_sigaction *ka, 10 struct k_sigaction *ka,
14 struct pt_regs *regs, 11 struct pt_regs *regs,
diff --git a/arch/um/kernel/signal.c b/arch/um/kernel/signal.c
index 292e706016c5..7362d58efc29 100644
--- a/arch/um/kernel/signal.c
+++ b/arch/um/kernel/signal.c
@@ -15,17 +15,13 @@
15EXPORT_SYMBOL(block_signals); 15EXPORT_SYMBOL(block_signals);
16EXPORT_SYMBOL(unblock_signals); 16EXPORT_SYMBOL(unblock_signals);
17 17
18#define _S(nr) (1<<((nr)-1))
19
20#define _BLOCKABLE (~(_S(SIGKILL) | _S(SIGSTOP)))
21
22/* 18/*
23 * OK, we're invoking a handler 19 * OK, we're invoking a handler
24 */ 20 */
25static int handle_signal(struct pt_regs *regs, unsigned long signr, 21static void handle_signal(struct pt_regs *regs, unsigned long signr,
26 struct k_sigaction *ka, siginfo_t *info, 22 struct k_sigaction *ka, siginfo_t *info)
27 sigset_t *oldset)
28{ 23{
24 sigset_t *oldset = sigmask_to_save();
29 unsigned long sp; 25 unsigned long sp;
30 int err; 26 int err;
31 27
@@ -65,9 +61,7 @@ static int handle_signal(struct pt_regs *regs, unsigned long signr,
65 if (err) 61 if (err)
66 force_sigsegv(signr, current); 62 force_sigsegv(signr, current);
67 else 63 else
68 block_sigmask(ka, signr); 64 signal_delivered(signr, info, ka, regs, 0);
69
70 return err;
71} 65}
72 66
73static int kern_do_signal(struct pt_regs *regs) 67static int kern_do_signal(struct pt_regs *regs)
@@ -77,24 +71,9 @@ static int kern_do_signal(struct pt_regs *regs)
77 int sig, handled_sig = 0; 71 int sig, handled_sig = 0;
78 72
79 while ((sig = get_signal_to_deliver(&info, &ka_copy, regs, NULL)) > 0) { 73 while ((sig = get_signal_to_deliver(&info, &ka_copy, regs, NULL)) > 0) {
80 sigset_t *oldset;
81 if (test_thread_flag(TIF_RESTORE_SIGMASK))
82 oldset = &current->saved_sigmask;
83 else
84 oldset = &current->blocked;
85 handled_sig = 1; 74 handled_sig = 1;
86 /* Whee! Actually deliver the signal. */ 75 /* Whee! Actually deliver the signal. */
87 if (!handle_signal(regs, sig, &ka_copy, &info, oldset)) { 76 handle_signal(regs, sig, &ka_copy, &info);
88 /*
89 * a signal was successfully delivered; the saved
90 * sigmask will have been stored in the signal frame,
91 * and will be restored by sigreturn, so we can simply
92 * clear the TIF_RESTORE_SIGMASK flag
93 */
94 if (test_thread_flag(TIF_RESTORE_SIGMASK))
95 clear_thread_flag(TIF_RESTORE_SIGMASK);
96 break;
97 }
98 } 77 }
99 78
100 /* Did we come from a system call? */ 79 /* Did we come from a system call? */
@@ -130,10 +109,8 @@ static int kern_do_signal(struct pt_regs *regs)
130 * if there's no signal to deliver, we just put the saved sigmask 109 * if there's no signal to deliver, we just put the saved sigmask
131 * back 110 * back
132 */ 111 */
133 if (!handled_sig && test_thread_flag(TIF_RESTORE_SIGMASK)) { 112 if (!handled_sig)
134 clear_thread_flag(TIF_RESTORE_SIGMASK); 113 restore_saved_sigmask();
135 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
136 }
137 return handled_sig; 114 return handled_sig;
138} 115}
139 116
diff --git a/arch/unicore32/kernel/signal.c b/arch/unicore32/kernel/signal.c
index 28782ad47b93..8adedb37720a 100644
--- a/arch/unicore32/kernel/signal.c
+++ b/arch/unicore32/kernel/signal.c
@@ -21,8 +21,6 @@
21#include <asm/cacheflush.h> 21#include <asm/cacheflush.h>
22#include <asm/ucontext.h> 22#include <asm/ucontext.h>
23 23
24#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
25
26/* 24/*
27 * For UniCore syscalls, we encode the syscall number into the instruction. 25 * For UniCore syscalls, we encode the syscall number into the instruction.
28 */ 26 */
@@ -61,10 +59,8 @@ static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
61 int err; 59 int err;
62 60
63 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set)); 61 err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
64 if (err == 0) { 62 if (err == 0)
65 sigdelsetmask(&set, ~_BLOCKABLE);
66 set_current_blocked(&set); 63 set_current_blocked(&set);
67 }
68 64
69 err |= __get_user(regs->UCreg_00, &sf->uc.uc_mcontext.regs.UCreg_00); 65 err |= __get_user(regs->UCreg_00, &sf->uc.uc_mcontext.regs.UCreg_00);
70 err |= __get_user(regs->UCreg_01, &sf->uc.uc_mcontext.regs.UCreg_01); 66 err |= __get_user(regs->UCreg_01, &sf->uc.uc_mcontext.regs.UCreg_01);
@@ -312,13 +308,12 @@ static inline void setup_syscall_restart(struct pt_regs *regs)
312/* 308/*
313 * OK, we're invoking a handler 309 * OK, we're invoking a handler
314 */ 310 */
315static int handle_signal(unsigned long sig, struct k_sigaction *ka, 311static void handle_signal(unsigned long sig, struct k_sigaction *ka,
316 siginfo_t *info, sigset_t *oldset, 312 siginfo_t *info, struct pt_regs *regs, int syscall)
317 struct pt_regs *regs, int syscall)
318{ 313{
319 struct thread_info *thread = current_thread_info(); 314 struct thread_info *thread = current_thread_info();
320 struct task_struct *tsk = current; 315 struct task_struct *tsk = current;
321 sigset_t blocked; 316 sigset_t *oldset = sigmask_to_save();
322 int usig = sig; 317 int usig = sig;
323 int ret; 318 int ret;
324 319
@@ -364,15 +359,10 @@ static int handle_signal(unsigned long sig, struct k_sigaction *ka,
364 359
365 if (ret != 0) { 360 if (ret != 0) {
366 force_sigsegv(sig, tsk); 361 force_sigsegv(sig, tsk);
367 return ret; 362 return;
368 } 363 }
369 364
370 /* 365 signal_delivered(sig, info, ka, regs, 0);
371 * Block the signal if we were successful.
372 */
373 block_sigmask(ka, sig);
374
375 return 0;
376} 366}
377 367
378/* 368/*
@@ -399,32 +389,12 @@ static void do_signal(struct pt_regs *regs, int syscall)
399 if (!user_mode(regs)) 389 if (!user_mode(regs))
400 return; 390 return;
401 391
402 if (try_to_freeze())
403 goto no_signal;
404
405 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 392 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
406 if (signr > 0) { 393 if (signr > 0) {
407 sigset_t *oldset; 394 handle_signal(signr, &ka, &info, regs, syscall);
408
409 if (test_thread_flag(TIF_RESTORE_SIGMASK))
410 oldset = &current->saved_sigmask;
411 else
412 oldset = &current->blocked;
413 if (handle_signal(signr, &ka, &info, oldset, regs, syscall)
414 == 0) {
415 /*
416 * A signal was successfully delivered; the saved
417 * sigmask will have been stored in the signal frame,
418 * and will be restored by sigreturn, so we can simply
419 * clear the TIF_RESTORE_SIGMASK flag.
420 */
421 if (test_thread_flag(TIF_RESTORE_SIGMASK))
422 clear_thread_flag(TIF_RESTORE_SIGMASK);
423 }
424 return; 395 return;
425 } 396 }
426 397
427 no_signal:
428 /* 398 /*
429 * No signal to deliver to the process - restart the syscall. 399 * No signal to deliver to the process - restart the syscall.
430 */ 400 */
@@ -451,8 +421,7 @@ static void do_signal(struct pt_regs *regs, int syscall)
451 /* If there's no signal to deliver, we just put the saved 421 /* If there's no signal to deliver, we just put the saved
452 * sigmask back. 422 * sigmask back.
453 */ 423 */
454 if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK)) 424 restore_saved_sigmask();
455 set_current_blocked(&current->saved_sigmask);
456} 425}
457 426
458asmlinkage void do_notify_resume(struct pt_regs *regs, 427asmlinkage void do_notify_resume(struct pt_regs *regs,
diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
index 98bd70faccc5..daeca56211e3 100644
--- a/arch/x86/ia32/ia32_signal.c
+++ b/arch/x86/ia32/ia32_signal.c
@@ -273,7 +273,6 @@ asmlinkage long sys32_sigreturn(struct pt_regs *regs)
273 sizeof(frame->extramask)))) 273 sizeof(frame->extramask))))
274 goto badframe; 274 goto badframe;
275 275
276 sigdelsetmask(&set, ~_BLOCKABLE);
277 set_current_blocked(&set); 276 set_current_blocked(&set);
278 277
279 if (ia32_restore_sigcontext(regs, &frame->sc, &ax)) 278 if (ia32_restore_sigcontext(regs, &frame->sc, &ax))
@@ -299,7 +298,6 @@ asmlinkage long sys32_rt_sigreturn(struct pt_regs *regs)
299 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 298 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
300 goto badframe; 299 goto badframe;
301 300
302 sigdelsetmask(&set, ~_BLOCKABLE);
303 set_current_blocked(&set); 301 set_current_blocked(&set);
304 302
305 if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) 303 if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
diff --git a/arch/x86/include/asm/sighandling.h b/arch/x86/include/asm/sighandling.h
index ada93b3b8c66..beff97f7df37 100644
--- a/arch/x86/include/asm/sighandling.h
+++ b/arch/x86/include/asm/sighandling.h
@@ -7,8 +7,6 @@
7 7
8#include <asm/processor-flags.h> 8#include <asm/processor-flags.h>
9 9
10#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
11
12#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \ 10#define __FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_OF | \
13 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \ 11 X86_EFLAGS_DF | X86_EFLAGS_TF | X86_EFLAGS_SF | \
14 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \ 12 X86_EFLAGS_ZF | X86_EFLAGS_AF | X86_EFLAGS_PF | \
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 5c25de07cba8..89f794f007ec 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -248,7 +248,23 @@ static inline void set_restore_sigmask(void)
248{ 248{
249 struct thread_info *ti = current_thread_info(); 249 struct thread_info *ti = current_thread_info();
250 ti->status |= TS_RESTORE_SIGMASK; 250 ti->status |= TS_RESTORE_SIGMASK;
251 set_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags); 251 WARN_ON(!test_bit(TIF_SIGPENDING, (unsigned long *)&ti->flags));
252}
253static inline void clear_restore_sigmask(void)
254{
255 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
256}
257static inline bool test_restore_sigmask(void)
258{
259 return current_thread_info()->status & TS_RESTORE_SIGMASK;
260}
261static inline bool test_and_clear_restore_sigmask(void)
262{
263 struct thread_info *ti = current_thread_info();
264 if (!(ti->status & TS_RESTORE_SIGMASK))
265 return false;
266 ti->status &= ~TS_RESTORE_SIGMASK;
267 return true;
252} 268}
253 269
254static inline bool is_ia32_task(void) 270static inline bool is_ia32_task(void)
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
index 01ccf9b71473..623f28837476 100644
--- a/arch/x86/kernel/entry_32.S
+++ b/arch/x86/kernel/entry_32.S
@@ -316,7 +316,6 @@ ret_from_exception:
316 preempt_stop(CLBR_ANY) 316 preempt_stop(CLBR_ANY)
317ret_from_intr: 317ret_from_intr:
318 GET_THREAD_INFO(%ebp) 318 GET_THREAD_INFO(%ebp)
319resume_userspace_sig:
320#ifdef CONFIG_VM86 319#ifdef CONFIG_VM86
321 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS 320 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
322 movb PT_CS(%esp), %al 321 movb PT_CS(%esp), %al
@@ -615,9 +614,13 @@ work_notifysig: # deal with pending signals and
615 # vm86-space 614 # vm86-space
616 TRACE_IRQS_ON 615 TRACE_IRQS_ON
617 ENABLE_INTERRUPTS(CLBR_NONE) 616 ENABLE_INTERRUPTS(CLBR_NONE)
617 movb PT_CS(%esp), %bl
618 andb $SEGMENT_RPL_MASK, %bl
619 cmpb $USER_RPL, %bl
620 jb resume_kernel
618 xorl %edx, %edx 621 xorl %edx, %edx
619 call do_notify_resume 622 call do_notify_resume
620 jmp resume_userspace_sig 623 jmp resume_userspace
621 624
622 ALIGN 625 ALIGN
623work_notifysig_v86: 626work_notifysig_v86:
@@ -630,9 +633,13 @@ work_notifysig_v86:
630#endif 633#endif
631 TRACE_IRQS_ON 634 TRACE_IRQS_ON
632 ENABLE_INTERRUPTS(CLBR_NONE) 635 ENABLE_INTERRUPTS(CLBR_NONE)
636 movb PT_CS(%esp), %bl
637 andb $SEGMENT_RPL_MASK, %bl
638 cmpb $USER_RPL, %bl
639 jb resume_kernel
633 xorl %edx, %edx 640 xorl %edx, %edx
634 call do_notify_resume 641 call do_notify_resume
635 jmp resume_userspace_sig 642 jmp resume_userspace
636END(work_pending) 643END(work_pending)
637 644
638 # perform syscall exit tracing 645 # perform syscall exit tracing
diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index 2e937a5ad531..21af737053aa 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -555,7 +555,6 @@ unsigned long sys_sigreturn(struct pt_regs *regs)
555 sizeof(frame->extramask)))) 555 sizeof(frame->extramask))))
556 goto badframe; 556 goto badframe;
557 557
558 sigdelsetmask(&set, ~_BLOCKABLE);
559 set_current_blocked(&set); 558 set_current_blocked(&set);
560 559
561 if (restore_sigcontext(regs, &frame->sc, &ax)) 560 if (restore_sigcontext(regs, &frame->sc, &ax))
@@ -581,7 +580,6 @@ long sys_rt_sigreturn(struct pt_regs *regs)
581 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 580 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
582 goto badframe; 581 goto badframe;
583 582
584 sigdelsetmask(&set, ~_BLOCKABLE);
585 set_current_blocked(&set); 583 set_current_blocked(&set);
586 584
587 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) 585 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
@@ -647,42 +645,28 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
647 struct pt_regs *regs) 645 struct pt_regs *regs)
648{ 646{
649 int usig = signr_convert(sig); 647 int usig = signr_convert(sig);
650 sigset_t *set = &current->blocked; 648 sigset_t *set = sigmask_to_save();
651 int ret;
652
653 if (current_thread_info()->status & TS_RESTORE_SIGMASK)
654 set = &current->saved_sigmask;
655 649
656 /* Set up the stack frame */ 650 /* Set up the stack frame */
657 if (is_ia32) { 651 if (is_ia32) {
658 if (ka->sa.sa_flags & SA_SIGINFO) 652 if (ka->sa.sa_flags & SA_SIGINFO)
659 ret = ia32_setup_rt_frame(usig, ka, info, set, regs); 653 return ia32_setup_rt_frame(usig, ka, info, set, regs);
660 else 654 else
661 ret = ia32_setup_frame(usig, ka, set, regs); 655 return ia32_setup_frame(usig, ka, set, regs);
662#ifdef CONFIG_X86_X32_ABI 656#ifdef CONFIG_X86_X32_ABI
663 } else if (is_x32) { 657 } else if (is_x32) {
664 ret = x32_setup_rt_frame(usig, ka, info, 658 return x32_setup_rt_frame(usig, ka, info,
665 (compat_sigset_t *)set, regs); 659 (compat_sigset_t *)set, regs);
666#endif 660#endif
667 } else { 661 } else {
668 ret = __setup_rt_frame(sig, ka, info, set, regs); 662 return __setup_rt_frame(sig, ka, info, set, regs);
669 }
670
671 if (ret) {
672 force_sigsegv(sig, current);
673 return -EFAULT;
674 } 663 }
675
676 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
677 return ret;
678} 664}
679 665
680static int 666static void
681handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka, 667handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
682 struct pt_regs *regs) 668 struct pt_regs *regs)
683{ 669{
684 int ret;
685
686 /* Are we from a system call? */ 670 /* Are we from a system call? */
687 if (syscall_get_nr(current, regs) >= 0) { 671 if (syscall_get_nr(current, regs) >= 0) {
688 /* If so, check system call restarting.. */ 672 /* If so, check system call restarting.. */
@@ -713,10 +697,10 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
713 likely(test_and_clear_thread_flag(TIF_FORCED_TF))) 697 likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
714 regs->flags &= ~X86_EFLAGS_TF; 698 regs->flags &= ~X86_EFLAGS_TF;
715 699
716 ret = setup_rt_frame(sig, ka, info, regs); 700 if (setup_rt_frame(sig, ka, info, regs) < 0) {
717 701 force_sigsegv(sig, current);
718 if (ret) 702 return;
719 return ret; 703 }
720 704
721 /* 705 /*
722 * Clear the direction flag as per the ABI for function entry. 706 * Clear the direction flag as per the ABI for function entry.
@@ -731,12 +715,8 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
731 */ 715 */
732 regs->flags &= ~X86_EFLAGS_TF; 716 regs->flags &= ~X86_EFLAGS_TF;
733 717
734 block_sigmask(ka, sig); 718 signal_delivered(sig, info, ka, regs,
735 719 test_thread_flag(TIF_SINGLESTEP));
736 tracehook_signal_handler(sig, info, ka, regs,
737 test_thread_flag(TIF_SINGLESTEP));
738
739 return 0;
740} 720}
741 721
742#ifdef CONFIG_X86_32 722#ifdef CONFIG_X86_32
@@ -757,16 +737,6 @@ static void do_signal(struct pt_regs *regs)
757 siginfo_t info; 737 siginfo_t info;
758 int signr; 738 int signr;
759 739
760 /*
761 * We want the common case to go fast, which is why we may in certain
762 * cases get here from kernel mode. Just return without doing anything
763 * if so.
764 * X86_32: vm86 regs switched out by assembly code before reaching
765 * here, so testing against kernel CS suffices.
766 */
767 if (!user_mode(regs))
768 return;
769
770 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 740 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
771 if (signr > 0) { 741 if (signr > 0) {
772 /* Whee! Actually deliver the signal. */ 742 /* Whee! Actually deliver the signal. */
@@ -796,10 +766,7 @@ static void do_signal(struct pt_regs *regs)
796 * If there's no signal to deliver, we just put the saved sigmask 766 * If there's no signal to deliver, we just put the saved sigmask
797 * back. 767 * back.
798 */ 768 */
799 if (current_thread_info()->status & TS_RESTORE_SIGMASK) { 769 restore_saved_sigmask();
800 current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
801 set_current_blocked(&current->saved_sigmask);
802 }
803} 770}
804 771
805/* 772/*
@@ -934,7 +901,6 @@ asmlinkage long sys32_x32_rt_sigreturn(struct pt_regs *regs)
934 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 901 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
935 goto badframe; 902 goto badframe;
936 903
937 sigdelsetmask(&set, ~_BLOCKABLE);
938 set_current_blocked(&set); 904 set_current_blocked(&set);
939 905
940 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax)) 906 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
diff --git a/arch/x86/um/signal.c b/arch/x86/um/signal.c
index bb0fb03b9f85..a508cea13503 100644
--- a/arch/x86/um/signal.c
+++ b/arch/x86/um/signal.c
@@ -486,7 +486,6 @@ long sys_sigreturn(struct pt_regs *regs)
486 copy_from_user(&set.sig[1], extramask, sig_size)) 486 copy_from_user(&set.sig[1], extramask, sig_size))
487 goto segfault; 487 goto segfault;
488 488
489 sigdelsetmask(&set, ~_BLOCKABLE);
490 set_current_blocked(&set); 489 set_current_blocked(&set);
491 490
492 if (copy_sc_from_user(&current->thread.regs, sc)) 491 if (copy_sc_from_user(&current->thread.regs, sc))
@@ -600,7 +599,6 @@ long sys_rt_sigreturn(struct pt_regs *regs)
600 if (copy_from_user(&set, &uc->uc_sigmask, sizeof(set))) 599 if (copy_from_user(&set, &uc->uc_sigmask, sizeof(set)))
601 goto segfault; 600 goto segfault;
602 601
603 sigdelsetmask(&set, ~_BLOCKABLE);
604 set_current_blocked(&set); 602 set_current_blocked(&set);
605 603
606 if (copy_sc_from_user(&current->thread.regs, &uc->uc_mcontext)) 604 if (copy_sc_from_user(&current->thread.regs, &uc->uc_mcontext))
diff --git a/arch/xtensa/kernel/signal.c b/arch/xtensa/kernel/signal.c
index ea7e17778a75..b9f8e5850d3a 100644
--- a/arch/xtensa/kernel/signal.c
+++ b/arch/xtensa/kernel/signal.c
@@ -30,8 +30,6 @@
30 30
31#define DEBUG_SIG 0 31#define DEBUG_SIG 0
32 32
33#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
34
35extern struct task_struct *coproc_owners[]; 33extern struct task_struct *coproc_owners[];
36 34
37struct rt_sigframe 35struct rt_sigframe
@@ -261,7 +259,6 @@ asmlinkage long xtensa_rt_sigreturn(long a0, long a1, long a2, long a3,
261 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 259 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
262 goto badframe; 260 goto badframe;
263 261
264 sigdelsetmask(&set, ~_BLOCKABLE);
265 set_current_blocked(&set); 262 set_current_blocked(&set);
266 263
267 if (restore_sigcontext(regs, frame)) 264 if (restore_sigcontext(regs, frame))
@@ -452,15 +449,6 @@ static void do_signal(struct pt_regs *regs)
452 siginfo_t info; 449 siginfo_t info;
453 int signr; 450 int signr;
454 struct k_sigaction ka; 451 struct k_sigaction ka;
455 sigset_t oldset;
456
457 if (try_to_freeze())
458 goto no_signal;
459
460 if (test_thread_flag(TIF_RESTORE_SIGMASK))
461 oldset = &current->saved_sigmask;
462 else
463 oldset = &current->blocked;
464 452
465 task_pt_regs(current)->icountlevel = 0; 453 task_pt_regs(current)->icountlevel = 0;
466 454
@@ -501,19 +489,17 @@ static void do_signal(struct pt_regs *regs)
501 489
502 /* Whee! Actually deliver the signal. */ 490 /* Whee! Actually deliver the signal. */
503 /* Set up the stack frame */ 491 /* Set up the stack frame */
504 ret = setup_frame(signr, &ka, &info, oldset, regs); 492 ret = setup_frame(signr, &ka, &info, sigmask_to_save(), regs);
505 if (ret) 493 if (ret)
506 return; 494 return;
507 495
508 clear_thread_flag(TIF_RESTORE_SIGMASK); 496 signal_delivered(signr, info, ka, regs, 0);
509 block_sigmask(&ka, signr);
510 if (current->ptrace & PT_SINGLESTEP) 497 if (current->ptrace & PT_SINGLESTEP)
511 task_pt_regs(current)->icountlevel = 1; 498 task_pt_regs(current)->icountlevel = 1;
512 499
513 return; 500 return;
514 } 501 }
515 502
516no_signal:
517 /* Did we come from a system call? */ 503 /* Did we come from a system call? */
518 if ((signed) regs->syscall >= 0) { 504 if ((signed) regs->syscall >= 0) {
519 /* Restart the system call - no handlers present */ 505 /* Restart the system call - no handlers present */
@@ -532,8 +518,7 @@ no_signal:
532 } 518 }
533 519
534 /* If there's no signal to deliver, we just restore the saved mask. */ 520 /* If there's no signal to deliver, we just restore the saved mask. */
535 if (test_and_clear_thread_flag(TIF_RESTORE_SIGMASK)) 521 restore_saved_sigmask();
536 set_current_blocked(&current->saved_sigmask);
537 522
538 if (current->ptrace & PT_SINGLESTEP) 523 if (current->ptrace & PT_SINGLESTEP)
539 task_pt_regs(current)->icountlevel = 1; 524 task_pt_regs(current)->icountlevel = 1;
diff --git a/fs/compat.c b/fs/compat.c
index 3004d2bad13f..6161255fac45 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1542,7 +1542,6 @@ asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg)
1542 compat_ptr(a.exp), compat_ptr(a.tvp)); 1542 compat_ptr(a.exp), compat_ptr(a.tvp));
1543} 1543}
1544 1544
1545#ifdef HAVE_SET_RESTORE_SIGMASK
1546static long do_compat_pselect(int n, compat_ulong_t __user *inp, 1545static long do_compat_pselect(int n, compat_ulong_t __user *inp,
1547 compat_ulong_t __user *outp, compat_ulong_t __user *exp, 1546 compat_ulong_t __user *outp, compat_ulong_t __user *exp,
1548 struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask, 1547 struct compat_timespec __user *tsp, compat_sigset_t __user *sigmask,
@@ -1665,11 +1664,9 @@ asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds,
1665 1664
1666 return ret; 1665 return ret;
1667} 1666}
1668#endif /* HAVE_SET_RESTORE_SIGMASK */
1669 1667
1670#ifdef CONFIG_EPOLL 1668#ifdef CONFIG_EPOLL
1671 1669
1672#ifdef HAVE_SET_RESTORE_SIGMASK
1673asmlinkage long compat_sys_epoll_pwait(int epfd, 1670asmlinkage long compat_sys_epoll_pwait(int epfd,
1674 struct compat_epoll_event __user *events, 1671 struct compat_epoll_event __user *events,
1675 int maxevents, int timeout, 1672 int maxevents, int timeout,
@@ -1713,7 +1710,6 @@ asmlinkage long compat_sys_epoll_pwait(int epfd,
1713 1710
1714 return err; 1711 return err;
1715} 1712}
1716#endif /* HAVE_SET_RESTORE_SIGMASK */
1717 1713
1718#endif /* CONFIG_EPOLL */ 1714#endif /* CONFIG_EPOLL */
1719 1715
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 079d1be65ba9..74598f67efeb 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -1853,8 +1853,6 @@ error_return:
1853 return error; 1853 return error;
1854} 1854}
1855 1855
1856#ifdef HAVE_SET_RESTORE_SIGMASK
1857
1858/* 1856/*
1859 * Implement the event wait interface for the eventpoll file. It is the kernel 1857 * Implement the event wait interface for the eventpoll file. It is the kernel
1860 * part of the user space epoll_pwait(2). 1858 * part of the user space epoll_pwait(2).
@@ -1899,8 +1897,6 @@ SYSCALL_DEFINE6(epoll_pwait, int, epfd, struct epoll_event __user *, events,
1899 return error; 1897 return error;
1900} 1898}
1901 1899
1902#endif /* HAVE_SET_RESTORE_SIGMASK */
1903
1904static int __init eventpoll_init(void) 1900static int __init eventpoll_init(void)
1905{ 1901{
1906 struct sysinfo si; 1902 struct sysinfo si;
diff --git a/fs/select.c b/fs/select.c
index 17d33d09fc16..bae321569dfa 100644
--- a/fs/select.c
+++ b/fs/select.c
@@ -614,7 +614,6 @@ SYSCALL_DEFINE5(select, int, n, fd_set __user *, inp, fd_set __user *, outp,
614 return ret; 614 return ret;
615} 615}
616 616
617#ifdef HAVE_SET_RESTORE_SIGMASK
618static long do_pselect(int n, fd_set __user *inp, fd_set __user *outp, 617static long do_pselect(int n, fd_set __user *inp, fd_set __user *outp,
619 fd_set __user *exp, struct timespec __user *tsp, 618 fd_set __user *exp, struct timespec __user *tsp,
620 const sigset_t __user *sigmask, size_t sigsetsize) 619 const sigset_t __user *sigmask, size_t sigsetsize)
@@ -686,7 +685,6 @@ SYSCALL_DEFINE6(pselect6, int, n, fd_set __user *, inp, fd_set __user *, outp,
686 685
687 return do_pselect(n, inp, outp, exp, tsp, up, sigsetsize); 686 return do_pselect(n, inp, outp, exp, tsp, up, sigsetsize);
688} 687}
689#endif /* HAVE_SET_RESTORE_SIGMASK */
690 688
691#ifdef __ARCH_WANT_SYS_OLD_SELECT 689#ifdef __ARCH_WANT_SYS_OLD_SELECT
692struct sel_arg_struct { 690struct sel_arg_struct {
@@ -941,7 +939,6 @@ SYSCALL_DEFINE3(poll, struct pollfd __user *, ufds, unsigned int, nfds,
941 return ret; 939 return ret;
942} 940}
943 941
944#ifdef HAVE_SET_RESTORE_SIGMASK
945SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, unsigned int, nfds, 942SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, unsigned int, nfds,
946 struct timespec __user *, tsp, const sigset_t __user *, sigmask, 943 struct timespec __user *, tsp, const sigset_t __user *, sigmask,
947 size_t, sigsetsize) 944 size_t, sigsetsize)
@@ -992,4 +989,3 @@ SYSCALL_DEFINE5(ppoll, struct pollfd __user *, ufds, unsigned int, nfds,
992 989
993 return ret; 990 return ret;
994} 991}
995#endif /* HAVE_SET_RESTORE_SIGMASK */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 660c8ae93471..f34437e835a7 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2207,6 +2207,20 @@ extern int send_sigqueue(struct sigqueue *, struct task_struct *, int group);
2207extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *); 2207extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
2208extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long); 2208extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
2209 2209
2210static inline void restore_saved_sigmask(void)
2211{
2212 if (test_and_clear_restore_sigmask())
2213 __set_current_blocked(&current->saved_sigmask);
2214}
2215
2216static inline sigset_t *sigmask_to_save(void)
2217{
2218 sigset_t *res = &current->blocked;
2219 if (unlikely(test_restore_sigmask()))
2220 res = &current->saved_sigmask;
2221 return res;
2222}
2223
2210static inline int kill_cad_pid(int sig, int priv) 2224static inline int kill_cad_pid(int sig, int priv)
2211{ 2225{
2212 return kill_pid(cad_pid, sig, priv); 2226 return kill_pid(cad_pid, sig, priv);
diff --git a/include/linux/signal.h b/include/linux/signal.h
index 17046cc484bc..26b424adc842 100644
--- a/include/linux/signal.h
+++ b/include/linux/signal.h
@@ -250,12 +250,13 @@ extern long do_sigpending(void __user *, unsigned long);
250extern int do_sigtimedwait(const sigset_t *, siginfo_t *, 250extern int do_sigtimedwait(const sigset_t *, siginfo_t *,
251 const struct timespec *); 251 const struct timespec *);
252extern int sigprocmask(int, sigset_t *, sigset_t *); 252extern int sigprocmask(int, sigset_t *, sigset_t *);
253extern void set_current_blocked(const sigset_t *); 253extern void set_current_blocked(sigset_t *);
254extern void __set_current_blocked(const sigset_t *);
254extern int show_unhandled_signals; 255extern int show_unhandled_signals;
255extern int sigsuspend(sigset_t *); 256extern int sigsuspend(sigset_t *);
256 257
257extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie); 258extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
258extern void block_sigmask(struct k_sigaction *ka, int signr); 259extern void signal_delivered(int sig, siginfo_t *info, struct k_sigaction *ka, struct pt_regs *regs, int stepping);
259extern void exit_signals(struct task_struct *tsk); 260extern void exit_signals(struct task_struct *tsk);
260 261
261extern struct kmem_cache *sighand_cachep; 262extern struct kmem_cache *sighand_cachep;
diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index db78775eff3b..ccc1899bd62e 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -8,6 +8,7 @@
8#define _LINUX_THREAD_INFO_H 8#define _LINUX_THREAD_INFO_H
9 9
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/bug.h>
11 12
12struct timespec; 13struct timespec;
13struct compat_timespec; 14struct compat_timespec;
@@ -125,10 +126,26 @@ static inline int test_ti_thread_flag(struct thread_info *ti, int flag)
125static inline void set_restore_sigmask(void) 126static inline void set_restore_sigmask(void)
126{ 127{
127 set_thread_flag(TIF_RESTORE_SIGMASK); 128 set_thread_flag(TIF_RESTORE_SIGMASK);
128 set_thread_flag(TIF_SIGPENDING); 129 WARN_ON(!test_thread_flag(TIF_SIGPENDING));
130}
131static inline void clear_restore_sigmask(void)
132{
133 clear_thread_flag(TIF_RESTORE_SIGMASK);
134}
135static inline bool test_restore_sigmask(void)
136{
137 return test_thread_flag(TIF_RESTORE_SIGMASK);
138}
139static inline bool test_and_clear_restore_sigmask(void)
140{
141 return test_and_clear_thread_flag(TIF_RESTORE_SIGMASK);
129} 142}
130#endif /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */ 143#endif /* TIF_RESTORE_SIGMASK && !HAVE_SET_RESTORE_SIGMASK */
131 144
145#ifndef HAVE_SET_RESTORE_SIGMASK
146#error "no set_restore_sigmask() provided and default one won't work"
147#endif
148
132#endif /* __KERNEL__ */ 149#endif /* __KERNEL__ */
133 150
134#endif /* _LINUX_THREAD_INFO_H */ 151#endif /* _LINUX_THREAD_INFO_H */
diff --git a/kernel/signal.c b/kernel/signal.c
index 08dfbd748cd2..677102789cf2 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -2368,24 +2368,34 @@ relock:
2368} 2368}
2369 2369
2370/** 2370/**
2371 * block_sigmask - add @ka's signal mask to current->blocked 2371 * signal_delivered -
2372 * @ka: action for @signr 2372 * @sig: number of signal being delivered
2373 * @signr: signal that has been successfully delivered 2373 * @info: siginfo_t of signal being delivered
2374 * @ka: sigaction setting that chose the handler
2375 * @regs: user register state
2376 * @stepping: nonzero if debugger single-step or block-step in use
2374 * 2377 *
2375 * This function should be called when a signal has succesfully been 2378 * This function should be called when a signal has succesfully been
2376 * delivered. It adds the mask of signals for @ka to current->blocked 2379 * delivered. It updates the blocked signals accordingly (@ka->sa.sa_mask
2377 * so that they are blocked during the execution of the signal 2380 * is always blocked, and the signal itself is blocked unless %SA_NODEFER
2378 * handler. In addition, @signr will be blocked unless %SA_NODEFER is 2381 * is set in @ka->sa.sa_flags. Tracing is notified.
2379 * set in @ka->sa.sa_flags.
2380 */ 2382 */
2381void block_sigmask(struct k_sigaction *ka, int signr) 2383void signal_delivered(int sig, siginfo_t *info, struct k_sigaction *ka,
2384 struct pt_regs *regs, int stepping)
2382{ 2385{
2383 sigset_t blocked; 2386 sigset_t blocked;
2384 2387
2388 /* A signal was successfully delivered, and the
2389 saved sigmask was stored on the signal frame,
2390 and will be restored by sigreturn. So we can
2391 simply clear the restore sigmask flag. */
2392 clear_restore_sigmask();
2393
2385 sigorsets(&blocked, &current->blocked, &ka->sa.sa_mask); 2394 sigorsets(&blocked, &current->blocked, &ka->sa.sa_mask);
2386 if (!(ka->sa.sa_flags & SA_NODEFER)) 2395 if (!(ka->sa.sa_flags & SA_NODEFER))
2387 sigaddset(&blocked, signr); 2396 sigaddset(&blocked, sig);
2388 set_current_blocked(&blocked); 2397 set_current_blocked(&blocked);
2398 tracehook_signal_handler(sig, info, ka, regs, stepping);
2389} 2399}
2390 2400
2391/* 2401/*
@@ -2518,7 +2528,16 @@ static void __set_task_blocked(struct task_struct *tsk, const sigset_t *newset)
2518 * It is wrong to change ->blocked directly, this helper should be used 2528 * It is wrong to change ->blocked directly, this helper should be used
2519 * to ensure the process can't miss a shared signal we are going to block. 2529 * to ensure the process can't miss a shared signal we are going to block.
2520 */ 2530 */
2521void set_current_blocked(const sigset_t *newset) 2531void set_current_blocked(sigset_t *newset)
2532{
2533 struct task_struct *tsk = current;
2534 sigdelsetmask(newset, sigmask(SIGKILL) | sigmask(SIGSTOP));
2535 spin_lock_irq(&tsk->sighand->siglock);
2536 __set_task_blocked(tsk, newset);
2537 spin_unlock_irq(&tsk->sighand->siglock);
2538}
2539
2540void __set_current_blocked(const sigset_t *newset)
2522{ 2541{
2523 struct task_struct *tsk = current; 2542 struct task_struct *tsk = current;
2524 2543
@@ -2558,7 +2577,7 @@ int sigprocmask(int how, sigset_t *set, sigset_t *oldset)
2558 return -EINVAL; 2577 return -EINVAL;
2559 } 2578 }
2560 2579
2561 set_current_blocked(&newset); 2580 __set_current_blocked(&newset);
2562 return 0; 2581 return 0;
2563} 2582}
2564 2583
@@ -3132,7 +3151,7 @@ SYSCALL_DEFINE3(sigprocmask, int, how, old_sigset_t __user *, nset,
3132 return -EINVAL; 3151 return -EINVAL;
3133 } 3152 }
3134 3153
3135 set_current_blocked(&new_blocked); 3154 __set_current_blocked(&new_blocked);
3136 } 3155 }
3137 3156
3138 if (oset) { 3157 if (oset) {
@@ -3196,7 +3215,6 @@ SYSCALL_DEFINE1(ssetmask, int, newmask)
3196 int old = current->blocked.sig[0]; 3215 int old = current->blocked.sig[0];
3197 sigset_t newset; 3216 sigset_t newset;
3198 3217
3199 siginitset(&newset, newmask & ~(sigmask(SIGKILL) | sigmask(SIGSTOP)));
3200 set_current_blocked(&newset); 3218 set_current_blocked(&newset);
3201 3219
3202 return old; 3220 return old;
@@ -3235,11 +3253,8 @@ SYSCALL_DEFINE0(pause)
3235 3253
3236#endif 3254#endif
3237 3255
3238#ifdef HAVE_SET_RESTORE_SIGMASK
3239int sigsuspend(sigset_t *set) 3256int sigsuspend(sigset_t *set)
3240{ 3257{
3241 sigdelsetmask(set, sigmask(SIGKILL)|sigmask(SIGSTOP));
3242
3243 current->saved_sigmask = current->blocked; 3258 current->saved_sigmask = current->blocked;
3244 set_current_blocked(set); 3259 set_current_blocked(set);
3245 3260
@@ -3248,7 +3263,6 @@ int sigsuspend(sigset_t *set)
3248 set_restore_sigmask(); 3263 set_restore_sigmask();
3249 return -ERESTARTNOHAND; 3264 return -ERESTARTNOHAND;
3250} 3265}
3251#endif
3252 3266
3253#ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND 3267#ifdef __ARCH_WANT_SYS_RT_SIGSUSPEND
3254/** 3268/**