signal.c 17 KB

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