1 /* 2 * linux/arch/alpha/kernel/signal.c 3 * 4 * Copyright (C) 1995 Linus Torvalds 5 * 6 * 1997-11-02 Modified for POSIX.1b signals by Richard Henderson 7 */ 8 9 #include <linux/sched.h> 10 #include <linux/kernel.h> 11 #include <linux/signal.h> 12 #include <linux/errno.h> 13 #include <linux/wait.h> 14 #include <linux/ptrace.h> 15 #include <linux/unistd.h> 16 #include <linux/mm.h> 17 #include <linux/smp.h> 18 #include <linux/stddef.h> 19 #include <linux/tty.h> 20 #include <linux/binfmts.h> 21 #include <linux/bitops.h> 22 #include <linux/syscalls.h> 23 #include <linux/tracehook.h> 24 25 #include <asm/uaccess.h> 26 #include <asm/sigcontext.h> 27 #include <asm/ucontext.h> 28 29 #include "proto.h" 30 31 32 #define DEBUG_SIG 0 33 34 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) 35 36 asmlinkage void ret_from_sys_call(void); 37 static void do_signal(struct pt_regs *, struct switch_stack *, 38 unsigned long, unsigned long); 39 40 41 /* 42 * The OSF/1 sigprocmask calling sequence is different from the 43 * C sigprocmask() sequence.. 44 * 45 * how: 46 * 1 - SIG_BLOCK 47 * 2 - SIG_UNBLOCK 48 * 3 - SIG_SETMASK 49 * 50 * We change the range to -1 .. 1 in order to let gcc easily 51 * use the conditional move instructions. 52 * 53 * Note that we don't need to acquire the kernel lock for SMP 54 * operation, as all of this is local to this thread. 55 */ 56 SYSCALL_DEFINE3(osf_sigprocmask, int, how, unsigned long, newmask, 57 struct pt_regs *, regs) 58 { 59 unsigned long oldmask = -EINVAL; 60 61 if ((unsigned long)how-1 <= 2) { 62 long sign = how-2; /* -1 .. 1 */ 63 unsigned long block, unblock; 64 65 newmask &= _BLOCKABLE; 66 spin_lock_irq(¤t->sighand->siglock); 67 oldmask = current->blocked.sig[0]; 68 69 unblock = oldmask & ~newmask; 70 block = oldmask | newmask; 71 if (!sign) 72 block = unblock; 73 if (sign <= 0) 74 newmask = block; 75 if (_NSIG_WORDS > 1 && sign > 0) 76 sigemptyset(¤t->blocked); 77 current->blocked.sig[0] = newmask; 78 recalc_sigpending(); 79 spin_unlock_irq(¤t->sighand->siglock); 80 81 regs->r0 = 0; /* special no error return */ 82 } 83 return oldmask; 84 } 85 86 SYSCALL_DEFINE3(osf_sigaction, int, sig, 87 const struct osf_sigaction __user *, act, 88 struct osf_sigaction __user *, oact) 89 { 90 struct k_sigaction new_ka, old_ka; 91 int ret; 92 93 if (act) { 94 old_sigset_t mask; 95 if (!access_ok(VERIFY_READ, act, sizeof(*act)) || 96 __get_user(new_ka.sa.sa_handler, &act->sa_handler) || 97 __get_user(new_ka.sa.sa_flags, &act->sa_flags)) 98 return -EFAULT; 99 __get_user(mask, &act->sa_mask); 100 siginitset(&new_ka.sa.sa_mask, mask); 101 new_ka.ka_restorer = NULL; 102 } 103 104 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); 105 106 if (!ret && oact) { 107 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) || 108 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) || 109 __put_user(old_ka.sa.sa_flags, &oact->sa_flags)) 110 return -EFAULT; 111 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask); 112 } 113 114 return ret; 115 } 116 117 SYSCALL_DEFINE5(rt_sigaction, int, sig, const struct sigaction __user *, act, 118 struct sigaction __user *, oact, 119 size_t, sigsetsize, void __user *, restorer) 120 { 121 struct k_sigaction new_ka, old_ka; 122 int ret; 123 124 /* XXX: Don't preclude handling different sized sigset_t's. */ 125 if (sigsetsize != sizeof(sigset_t)) 126 return -EINVAL; 127 128 if (act) { 129 new_ka.ka_restorer = restorer; 130 if (copy_from_user(&new_ka.sa, act, sizeof(*act))) 131 return -EFAULT; 132 } 133 134 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL); 135 136 if (!ret && oact) { 137 if (copy_to_user(oact, &old_ka.sa, sizeof(*oact))) 138 return -EFAULT; 139 } 140 141 return ret; 142 } 143 144 /* 145 * Atomically swap in the new signal mask, and wait for a signal. 146 */ 147 asmlinkage int 148 do_sigsuspend(old_sigset_t mask, struct pt_regs *regs, struct switch_stack *sw) 149 { 150 mask &= _BLOCKABLE; 151 spin_lock_irq(¤t->sighand->siglock); 152 current->saved_sigmask = current->blocked; 153 siginitset(¤t->blocked, mask); 154 recalc_sigpending(); 155 spin_unlock_irq(¤t->sighand->siglock); 156 157 /* Indicate EINTR on return from any possible signal handler, 158 which will not come back through here, but via sigreturn. */ 159 regs->r0 = EINTR; 160 regs->r19 = 1; 161 162 current->state = TASK_INTERRUPTIBLE; 163 schedule(); 164 set_thread_flag(TIF_RESTORE_SIGMASK); 165 return -ERESTARTNOHAND; 166 } 167 168 asmlinkage int 169 do_rt_sigsuspend(sigset_t __user *uset, size_t sigsetsize, 170 struct pt_regs *regs, struct switch_stack *sw) 171 { 172 sigset_t set; 173 174 /* XXX: Don't preclude handling different sized sigset_t's. */ 175 if (sigsetsize != sizeof(sigset_t)) 176 return -EINVAL; 177 if (copy_from_user(&set, uset, sizeof(set))) 178 return -EFAULT; 179 180 sigdelsetmask(&set, ~_BLOCKABLE); 181 spin_lock_irq(¤t->sighand->siglock); 182 current->saved_sigmask = current->blocked; 183 current->blocked = set; 184 recalc_sigpending(); 185 spin_unlock_irq(¤t->sighand->siglock); 186 187 /* Indicate EINTR on return from any possible signal handler, 188 which will not come back through here, but via sigreturn. */ 189 regs->r0 = EINTR; 190 regs->r19 = 1; 191 192 current->state = TASK_INTERRUPTIBLE; 193 schedule(); 194 set_thread_flag(TIF_RESTORE_SIGMASK); 195 return -ERESTARTNOHAND; 196 } 197 198 asmlinkage int 199 sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss) 200 { 201 return do_sigaltstack(uss, uoss, rdusp()); 202 } 203 204 /* 205 * Do a signal return; undo the signal stack. 206 */ 207 208 #if _NSIG_WORDS > 1 209 # error "Non SA_SIGINFO frame needs rearranging" 210 #endif 211 212 struct sigframe 213 { 214 struct sigcontext sc; 215 unsigned int retcode[3]; 216 }; 217 218 struct rt_sigframe 219 { 220 struct siginfo info; 221 struct ucontext uc; 222 unsigned int retcode[3]; 223 }; 224 225 /* If this changes, userland unwinders that Know Things about our signal 226 frame will break. Do not undertake lightly. It also implies an ABI 227 change wrt the size of siginfo_t, which may cause some pain. */ 228 extern char compile_time_assert 229 [offsetof(struct rt_sigframe, uc.uc_mcontext) == 176 ? 1 : -1]; 230 231 #define INSN_MOV_R30_R16 0x47fe0410 232 #define INSN_LDI_R0 0x201f0000 233 #define INSN_CALLSYS 0x00000083 234 235 static long 236 restore_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, 237 struct switch_stack *sw) 238 { 239 unsigned long usp; 240 long i, err = __get_user(regs->pc, &sc->sc_pc); 241 242 sw->r26 = (unsigned long) ret_from_sys_call; 243 244 err |= __get_user(regs->r0, sc->sc_regs+0); 245 err |= __get_user(regs->r1, sc->sc_regs+1); 246 err |= __get_user(regs->r2, sc->sc_regs+2); 247 err |= __get_user(regs->r3, sc->sc_regs+3); 248 err |= __get_user(regs->r4, sc->sc_regs+4); 249 err |= __get_user(regs->r5, sc->sc_regs+5); 250 err |= __get_user(regs->r6, sc->sc_regs+6); 251 err |= __get_user(regs->r7, sc->sc_regs+7); 252 err |= __get_user(regs->r8, sc->sc_regs+8); 253 err |= __get_user(sw->r9, sc->sc_regs+9); 254 err |= __get_user(sw->r10, sc->sc_regs+10); 255 err |= __get_user(sw->r11, sc->sc_regs+11); 256 err |= __get_user(sw->r12, sc->sc_regs+12); 257 err |= __get_user(sw->r13, sc->sc_regs+13); 258 err |= __get_user(sw->r14, sc->sc_regs+14); 259 err |= __get_user(sw->r15, sc->sc_regs+15); 260 err |= __get_user(regs->r16, sc->sc_regs+16); 261 err |= __get_user(regs->r17, sc->sc_regs+17); 262 err |= __get_user(regs->r18, sc->sc_regs+18); 263 err |= __get_user(regs->r19, sc->sc_regs+19); 264 err |= __get_user(regs->r20, sc->sc_regs+20); 265 err |= __get_user(regs->r21, sc->sc_regs+21); 266 err |= __get_user(regs->r22, sc->sc_regs+22); 267 err |= __get_user(regs->r23, sc->sc_regs+23); 268 err |= __get_user(regs->r24, sc->sc_regs+24); 269 err |= __get_user(regs->r25, sc->sc_regs+25); 270 err |= __get_user(regs->r26, sc->sc_regs+26); 271 err |= __get_user(regs->r27, sc->sc_regs+27); 272 err |= __get_user(regs->r28, sc->sc_regs+28); 273 err |= __get_user(regs->gp, sc->sc_regs+29); 274 err |= __get_user(usp, sc->sc_regs+30); 275 wrusp(usp); 276 277 for (i = 0; i < 31; i++) 278 err |= __get_user(sw->fp[i], sc->sc_fpregs+i); 279 err |= __get_user(sw->fp[31], &sc->sc_fpcr); 280 281 return err; 282 } 283 284 /* Note that this syscall is also used by setcontext(3) to install 285 a given sigcontext. This because it's impossible to set *all* 286 registers and transfer control from userland. */ 287 288 asmlinkage void 289 do_sigreturn(struct sigcontext __user *sc, struct pt_regs *regs, 290 struct switch_stack *sw) 291 { 292 sigset_t set; 293 294 /* Verify that it's a good sigcontext before using it */ 295 if (!access_ok(VERIFY_READ, sc, sizeof(*sc))) 296 goto give_sigsegv; 297 if (__get_user(set.sig[0], &sc->sc_mask)) 298 goto give_sigsegv; 299 300 sigdelsetmask(&set, ~_BLOCKABLE); 301 spin_lock_irq(¤t->sighand->siglock); 302 current->blocked = set; 303 recalc_sigpending(); 304 spin_unlock_irq(¤t->sighand->siglock); 305 306 if (restore_sigcontext(sc, regs, sw)) 307 goto give_sigsegv; 308 309 /* Send SIGTRAP if we're single-stepping: */ 310 if (ptrace_cancel_bpt (current)) { 311 siginfo_t info; 312 313 info.si_signo = SIGTRAP; 314 info.si_errno = 0; 315 info.si_code = TRAP_BRKPT; 316 info.si_addr = (void __user *) regs->pc; 317 info.si_trapno = 0; 318 send_sig_info(SIGTRAP, &info, current); 319 } 320 return; 321 322 give_sigsegv: 323 force_sig(SIGSEGV, current); 324 } 325 326 asmlinkage void 327 do_rt_sigreturn(struct rt_sigframe __user *frame, struct pt_regs *regs, 328 struct switch_stack *sw) 329 { 330 sigset_t set; 331 332 /* Verify that it's a good ucontext_t before using it */ 333 if (!access_ok(VERIFY_READ, &frame->uc, sizeof(frame->uc))) 334 goto give_sigsegv; 335 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) 336 goto give_sigsegv; 337 338 sigdelsetmask(&set, ~_BLOCKABLE); 339 spin_lock_irq(¤t->sighand->siglock); 340 current->blocked = set; 341 recalc_sigpending(); 342 spin_unlock_irq(¤t->sighand->siglock); 343 344 if (restore_sigcontext(&frame->uc.uc_mcontext, regs, sw)) 345 goto give_sigsegv; 346 347 /* Send SIGTRAP if we're single-stepping: */ 348 if (ptrace_cancel_bpt (current)) { 349 siginfo_t info; 350 351 info.si_signo = SIGTRAP; 352 info.si_errno = 0; 353 info.si_code = TRAP_BRKPT; 354 info.si_addr = (void __user *) regs->pc; 355 info.si_trapno = 0; 356 send_sig_info(SIGTRAP, &info, current); 357 } 358 return; 359 360 give_sigsegv: 361 force_sig(SIGSEGV, current); 362 } 363 364 365 /* 366 * Set up a signal frame. 367 */ 368 369 static inline void __user * 370 get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size) 371 { 372 if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp)) 373 sp = current->sas_ss_sp + current->sas_ss_size; 374 375 return (void __user *)((sp - frame_size) & -32ul); 376 } 377 378 static long 379 setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, 380 struct switch_stack *sw, unsigned long mask, unsigned long sp) 381 { 382 long i, err = 0; 383 384 err |= __put_user(on_sig_stack((unsigned long)sc), &sc->sc_onstack); 385 err |= __put_user(mask, &sc->sc_mask); 386 err |= __put_user(regs->pc, &sc->sc_pc); 387 err |= __put_user(8, &sc->sc_ps); 388 389 err |= __put_user(regs->r0 , sc->sc_regs+0); 390 err |= __put_user(regs->r1 , sc->sc_regs+1); 391 err |= __put_user(regs->r2 , sc->sc_regs+2); 392 err |= __put_user(regs->r3 , sc->sc_regs+3); 393 err |= __put_user(regs->r4 , sc->sc_regs+4); 394 err |= __put_user(regs->r5 , sc->sc_regs+5); 395 err |= __put_user(regs->r6 , sc->sc_regs+6); 396 err |= __put_user(regs->r7 , sc->sc_regs+7); 397 err |= __put_user(regs->r8 , sc->sc_regs+8); 398 err |= __put_user(sw->r9 , sc->sc_regs+9); 399 err |= __put_user(sw->r10 , sc->sc_regs+10); 400 err |= __put_user(sw->r11 , sc->sc_regs+11); 401 err |= __put_user(sw->r12 , sc->sc_regs+12); 402 err |= __put_user(sw->r13 , sc->sc_regs+13); 403 err |= __put_user(sw->r14 , sc->sc_regs+14); 404 err |= __put_user(sw->r15 , sc->sc_regs+15); 405 err |= __put_user(regs->r16, sc->sc_regs+16); 406 err |= __put_user(regs->r17, sc->sc_regs+17); 407 err |= __put_user(regs->r18, sc->sc_regs+18); 408 err |= __put_user(regs->r19, sc->sc_regs+19); 409 err |= __put_user(regs->r20, sc->sc_regs+20); 410 err |= __put_user(regs->r21, sc->sc_regs+21); 411 err |= __put_user(regs->r22, sc->sc_regs+22); 412 err |= __put_user(regs->r23, sc->sc_regs+23); 413 err |= __put_user(regs->r24, sc->sc_regs+24); 414 err |= __put_user(regs->r25, sc->sc_regs+25); 415 err |= __put_user(regs->r26, sc->sc_regs+26); 416 err |= __put_user(regs->r27, sc->sc_regs+27); 417 err |= __put_user(regs->r28, sc->sc_regs+28); 418 err |= __put_user(regs->gp , sc->sc_regs+29); 419 err |= __put_user(sp, sc->sc_regs+30); 420 err |= __put_user(0, sc->sc_regs+31); 421 422 for (i = 0; i < 31; i++) 423 err |= __put_user(sw->fp[i], sc->sc_fpregs+i); 424 err |= __put_user(0, sc->sc_fpregs+31); 425 err |= __put_user(sw->fp[31], &sc->sc_fpcr); 426 427 err |= __put_user(regs->trap_a0, &sc->sc_traparg_a0); 428 err |= __put_user(regs->trap_a1, &sc->sc_traparg_a1); 429 err |= __put_user(regs->trap_a2, &sc->sc_traparg_a2); 430 431 return err; 432 } 433 434 static int 435 setup_frame(int sig, struct k_sigaction *ka, sigset_t *set, 436 struct pt_regs *regs, struct switch_stack * sw) 437 { 438 unsigned long oldsp, r26, err = 0; 439 struct sigframe __user *frame; 440 441 oldsp = rdusp(); 442 frame = get_sigframe(ka, oldsp, sizeof(*frame)); 443 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) 444 goto give_sigsegv; 445 446 err |= setup_sigcontext(&frame->sc, regs, sw, set->sig[0], oldsp); 447 if (err) 448 goto give_sigsegv; 449 450 /* Set up to return from userspace. If provided, use a stub 451 already in userspace. */ 452 if (ka->ka_restorer) { 453 r26 = (unsigned long) ka->ka_restorer; 454 } else { 455 err |= __put_user(INSN_MOV_R30_R16, frame->retcode+0); 456 err |= __put_user(INSN_LDI_R0+__NR_sigreturn, frame->retcode+1); 457 err |= __put_user(INSN_CALLSYS, frame->retcode+2); 458 imb(); 459 r26 = (unsigned long) frame->retcode; 460 } 461 462 /* Check that everything was written properly. */ 463 if (err) 464 goto give_sigsegv; 465 466 /* "Return" to the handler */ 467 regs->r26 = r26; 468 regs->r27 = regs->pc = (unsigned long) ka->sa.sa_handler; 469 regs->r16 = sig; /* a0: signal number */ 470 regs->r17 = 0; /* a1: exception code */ 471 regs->r18 = (unsigned long) &frame->sc; /* a2: sigcontext pointer */ 472 wrusp((unsigned long) frame); 473 474 #if DEBUG_SIG 475 printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n", 476 current->comm, current->pid, frame, regs->pc, regs->r26); 477 #endif 478 479 return 0; 480 481 give_sigsegv: 482 force_sigsegv(sig, current); 483 return -EFAULT; 484 } 485 486 static int 487 setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info, 488 sigset_t *set, struct pt_regs *regs, struct switch_stack * sw) 489 { 490 unsigned long oldsp, r26, err = 0; 491 struct rt_sigframe __user *frame; 492 493 oldsp = rdusp(); 494 frame = get_sigframe(ka, oldsp, sizeof(*frame)); 495 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame))) 496 goto give_sigsegv; 497 498 err |= copy_siginfo_to_user(&frame->info, info); 499 500 /* Create the ucontext. */ 501 err |= __put_user(0, &frame->uc.uc_flags); 502 err |= __put_user(0, &frame->uc.uc_link); 503 err |= __put_user(set->sig[0], &frame->uc.uc_osf_sigmask); 504 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp); 505 err |= __put_user(sas_ss_flags(oldsp), &frame->uc.uc_stack.ss_flags); 506 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size); 507 err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, sw, 508 set->sig[0], oldsp); 509 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); 510 if (err) 511 goto give_sigsegv; 512 513 /* Set up to return from userspace. If provided, use a stub 514 already in userspace. */ 515 if (ka->ka_restorer) { 516 r26 = (unsigned long) ka->ka_restorer; 517 } else { 518 err |= __put_user(INSN_MOV_R30_R16, frame->retcode+0); 519 err |= __put_user(INSN_LDI_R0+__NR_rt_sigreturn, 520 frame->retcode+1); 521 err |= __put_user(INSN_CALLSYS, frame->retcode+2); 522 imb(); 523 r26 = (unsigned long) frame->retcode; 524 } 525 526 if (err) 527 goto give_sigsegv; 528 529 /* "Return" to the handler */ 530 regs->r26 = r26; 531 regs->r27 = regs->pc = (unsigned long) ka->sa.sa_handler; 532 regs->r16 = sig; /* a0: signal number */ 533 regs->r17 = (unsigned long) &frame->info; /* a1: siginfo pointer */ 534 regs->r18 = (unsigned long) &frame->uc; /* a2: ucontext pointer */ 535 wrusp((unsigned long) frame); 536 537 #if DEBUG_SIG 538 printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n", 539 current->comm, current->pid, frame, regs->pc, regs->r26); 540 #endif 541 542 return 0; 543 544 give_sigsegv: 545 force_sigsegv(sig, current); 546 return -EFAULT; 547 } 548 549 550 /* 551 * OK, we're invoking a handler. 552 */ 553 static inline int 554 handle_signal(int sig, struct k_sigaction *ka, siginfo_t *info, 555 sigset_t *oldset, struct pt_regs * regs, struct switch_stack *sw) 556 { 557 int ret; 558 559 if (ka->sa.sa_flags & SA_SIGINFO) 560 ret = setup_rt_frame(sig, ka, info, oldset, regs, sw); 561 else 562 ret = setup_frame(sig, ka, oldset, regs, sw); 563 564 if (ret == 0) { 565 spin_lock_irq(¤t->sighand->siglock); 566 sigorsets(¤t->blocked,¤t->blocked,&ka->sa.sa_mask); 567 if (!(ka->sa.sa_flags & SA_NODEFER)) 568 sigaddset(¤t->blocked,sig); 569 recalc_sigpending(); 570 spin_unlock_irq(¤t->sighand->siglock); 571 } 572 573 return ret; 574 } 575 576 static inline void 577 syscall_restart(unsigned long r0, unsigned long r19, 578 struct pt_regs *regs, struct k_sigaction *ka) 579 { 580 switch (regs->r0) { 581 case ERESTARTSYS: 582 if (!(ka->sa.sa_flags & SA_RESTART)) { 583 case ERESTARTNOHAND: 584 regs->r0 = EINTR; 585 break; 586 } 587 /* fallthrough */ 588 case ERESTARTNOINTR: 589 regs->r0 = r0; /* reset v0 and a3 and replay syscall */ 590 regs->r19 = r19; 591 regs->pc -= 4; 592 break; 593 case ERESTART_RESTARTBLOCK: 594 current_thread_info()->restart_block.fn = do_no_restart_syscall; 595 regs->r0 = EINTR; 596 break; 597 } 598 } 599 600 601 /* 602 * Note that 'init' is a special process: it doesn't get signals it doesn't 603 * want to handle. Thus you cannot kill init even with a SIGKILL even by 604 * mistake. 605 * 606 * Note that we go through the signals twice: once to check the signals that 607 * the kernel can handle, and then we build all the user-level signal handling 608 * stack-frames in one go after that. 609 * 610 * "r0" and "r19" are the registers we need to restore for system call 611 * restart. "r0" is also used as an indicator whether we can restart at 612 * all (if we get here from anything but a syscall return, it will be 0) 613 */ 614 static void 615 do_signal(struct pt_regs * regs, struct switch_stack * sw, 616 unsigned long r0, unsigned long r19) 617 { 618 siginfo_t info; 619 int signr; 620 unsigned long single_stepping = ptrace_cancel_bpt(current); 621 struct k_sigaction ka; 622 sigset_t *oldset; 623 624 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 625 oldset = ¤t->saved_sigmask; 626 else 627 oldset = ¤t->blocked; 628 629 /* This lets the debugger run, ... */ 630 signr = get_signal_to_deliver(&info, &ka, regs, NULL); 631 632 /* ... so re-check the single stepping. */ 633 single_stepping |= ptrace_cancel_bpt(current); 634 635 if (signr > 0) { 636 /* Whee! Actually deliver the signal. */ 637 if (r0) 638 syscall_restart(r0, r19, regs, &ka); 639 if (handle_signal(signr, &ka, &info, oldset, regs, sw) == 0) { 640 /* A signal was successfully delivered, and the 641 saved sigmask was stored on the signal frame, 642 and will be restored by sigreturn. So we can 643 simply clear the restore sigmask flag. */ 644 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 645 clear_thread_flag(TIF_RESTORE_SIGMASK); 646 } 647 if (single_stepping) 648 ptrace_set_bpt(current); /* re-set bpt */ 649 return; 650 } 651 652 if (r0) { 653 switch (regs->r0) { 654 case ERESTARTNOHAND: 655 case ERESTARTSYS: 656 case ERESTARTNOINTR: 657 /* Reset v0 and a3 and replay syscall. */ 658 regs->r0 = r0; 659 regs->r19 = r19; 660 regs->pc -= 4; 661 break; 662 case ERESTART_RESTARTBLOCK: 663 /* Force v0 to the restart syscall and reply. */ 664 regs->r0 = __NR_restart_syscall; 665 regs->pc -= 4; 666 break; 667 } 668 } 669 670 /* If there's no signal to deliver, we just restore the saved mask. */ 671 if (test_thread_flag(TIF_RESTORE_SIGMASK)) { 672 clear_thread_flag(TIF_RESTORE_SIGMASK); 673 sigprocmask(SIG_SETMASK, ¤t->saved_sigmask, NULL); 674 } 675 676 if (single_stepping) 677 ptrace_set_bpt(current); /* re-set breakpoint */ 678 } 679 680 void 681 do_notify_resume(struct pt_regs *regs, struct switch_stack *sw, 682 unsigned long thread_info_flags, 683 unsigned long r0, unsigned long r19) 684 { 685 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 686 do_signal(regs, sw, r0, r19); 687 688 if (thread_info_flags & _TIF_NOTIFY_RESUME) { 689 clear_thread_flag(TIF_NOTIFY_RESUME); 690 tracehook_notify_resume(regs); 691 if (current->replacement_session_keyring) 692 key_replace_session_keyring(); 693 } 694 } 695