Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal

Pull third pile of signal handling patches from Al Viro:
"This time it's mostly helpers and conversions to them; there's a lot
of stuff remaining in the tree, but that'll either go in -rc2
(isolated bug fixes, ideally via arch maintainers' trees) or will sit
there until the next cycle."

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/signal:
x86: get rid of calling do_notify_resume() when returning to kernel mode
blackfin: check __get_user() return value
whack-a-mole with TIF_FREEZE
FRV: Optimise the system call exit path in entry.S [ver #2]
FRV: Shrink TIF_WORK_MASK [ver #2]
FRV: Prevent syscall exit tracing and notify_resume at end of kernel exceptions
new helper: signal_delivered()
powerpc: get rid of restore_sigmask()
most of set_current_blocked() callers want SIGKILL/SIGSTOP removed from set
set_restore_sigmask() is never called without SIGPENDING (and never should be)
TIF_RESTORE_SIGMASK can be set only when TIF_SIGPENDING is set
don't call try_to_freeze() from do_signal()
pull clearing RESTORE_SIGMASK into block_sigmask()
sh64: failure to build sigframe != signal without handler
openrisc: tracehook_signal_handler() is supposed to be called on success
new helper: sigmask_to_save()
new helper: restore_saved_sigmask()
new helpers: {clear,test,test_and_clear}_restore_sigmask()
HAVE_RESTORE_SIGMASK is defined on all architectures now

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