signal_32.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /*
  2. * linux/arch/sh/kernel/signal.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. *
  6. * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
  7. *
  8. * SuperH version: Copyright (C) 1999, 2000 Niibe Yutaka & Kaz Kojima
  9. *
  10. */
  11. #include <linux/sched.h>
  12. #include <linux/mm.h>
  13. #include <linux/smp.h>
  14. #include <linux/kernel.h>
  15. #include <linux/signal.h>
  16. #include <linux/errno.h>
  17. #include <linux/wait.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/unistd.h>
  20. #include <linux/stddef.h>
  21. #include <linux/tty.h>
  22. #include <linux/elf.h>
  23. #include <linux/personality.h>
  24. #include <linux/binfmts.h>
  25. #include <linux/freezer.h>
  26. #include <linux/io.h>
  27. #include <linux/tracehook.h>
  28. #include <asm/system.h>
  29. #include <asm/ucontext.h>
  30. #include <asm/uaccess.h>
  31. #include <asm/pgtable.h>
  32. #include <asm/cacheflush.h>
  33. #include <asm/syscalls.h>
  34. #include <asm/fpu.h>
  35. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  36. struct fdpic_func_descriptor {
  37. unsigned long text;
  38. unsigned long GOT;
  39. };
  40. /*
  41. * The following define adds a 64 byte gap between the signal
  42. * stack frame and previous contents of the stack. This allows
  43. * frame unwinding in a function epilogue but only if a frame
  44. * pointer is used in the function. This is necessary because
  45. * current gcc compilers (<4.3) do not generate unwind info on
  46. * SH for function epilogues.
  47. */
  48. #define UNWINDGUARD 64
  49. /*
  50. * Atomically swap in the new signal mask, and wait for a signal.
  51. */
  52. asmlinkage int
  53. sys_sigsuspend(old_sigset_t mask,
  54. unsigned long r5, unsigned long r6, unsigned long r7,
  55. struct pt_regs __regs)
  56. {
  57. mask &= _BLOCKABLE;
  58. spin_lock_irq(&current->sighand->siglock);
  59. current->saved_sigmask = current->blocked;
  60. siginitset(&current->blocked, mask);
  61. recalc_sigpending();
  62. spin_unlock_irq(&current->sighand->siglock);
  63. current->state = TASK_INTERRUPTIBLE;
  64. schedule();
  65. set_thread_flag(TIF_RESTORE_SIGMASK);
  66. return -ERESTARTNOHAND;
  67. }
  68. asmlinkage int
  69. sys_sigaction(int sig, const struct old_sigaction __user *act,
  70. struct old_sigaction __user *oact)
  71. {
  72. struct k_sigaction new_ka, old_ka;
  73. int ret;
  74. if (act) {
  75. old_sigset_t mask;
  76. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  77. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  78. __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
  79. return -EFAULT;
  80. __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  81. __get_user(mask, &act->sa_mask);
  82. siginitset(&new_ka.sa.sa_mask, mask);
  83. }
  84. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  85. if (!ret && oact) {
  86. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  87. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  88. __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
  89. return -EFAULT;
  90. __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  91. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  92. }
  93. return ret;
  94. }
  95. asmlinkage int
  96. sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
  97. unsigned long r6, unsigned long r7,
  98. struct pt_regs __regs)
  99. {
  100. struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
  101. return do_sigaltstack(uss, uoss, regs->regs[15]);
  102. }
  103. /*
  104. * Do a signal return; undo the signal stack.
  105. */
  106. #define MOVW(n) (0x9300|((n)-2)) /* Move mem word at PC+n to R3 */
  107. #if defined(CONFIG_CPU_SH2)
  108. #define TRAP_NOARG 0xc320 /* Syscall w/no args (NR in R3) */
  109. #else
  110. #define TRAP_NOARG 0xc310 /* Syscall w/no args (NR in R3) */
  111. #endif
  112. #define OR_R0_R0 0x200b /* or r0,r0 (insert to avoid hardware bug) */
  113. struct sigframe
  114. {
  115. struct sigcontext sc;
  116. unsigned long extramask[_NSIG_WORDS-1];
  117. u16 retcode[8];
  118. };
  119. struct rt_sigframe
  120. {
  121. struct siginfo info;
  122. struct ucontext uc;
  123. u16 retcode[8];
  124. };
  125. #ifdef CONFIG_SH_FPU
  126. static inline int restore_sigcontext_fpu(struct sigcontext __user *sc)
  127. {
  128. struct task_struct *tsk = current;
  129. if (!(boot_cpu_data.flags & CPU_HAS_FPU))
  130. return 0;
  131. set_used_math();
  132. return __copy_from_user(&tsk->thread.fpu.hard, &sc->sc_fpregs[0],
  133. sizeof(long)*(16*2+2));
  134. }
  135. static inline int save_sigcontext_fpu(struct sigcontext __user *sc,
  136. struct pt_regs *regs)
  137. {
  138. struct task_struct *tsk = current;
  139. if (!(boot_cpu_data.flags & CPU_HAS_FPU))
  140. return 0;
  141. if (!used_math()) {
  142. __put_user(0, &sc->sc_ownedfp);
  143. return 0;
  144. }
  145. __put_user(1, &sc->sc_ownedfp);
  146. /* This will cause a "finit" to be triggered by the next
  147. attempted FPU operation by the 'current' process.
  148. */
  149. clear_used_math();
  150. unlazy_fpu(tsk, regs);
  151. return __copy_to_user(&sc->sc_fpregs[0], &tsk->thread.fpu.hard,
  152. sizeof(long)*(16*2+2));
  153. }
  154. #endif /* CONFIG_SH_FPU */
  155. static int
  156. restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *r0_p)
  157. {
  158. unsigned int err = 0;
  159. #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
  160. COPY(regs[1]);
  161. COPY(regs[2]); COPY(regs[3]);
  162. COPY(regs[4]); COPY(regs[5]);
  163. COPY(regs[6]); COPY(regs[7]);
  164. COPY(regs[8]); COPY(regs[9]);
  165. COPY(regs[10]); COPY(regs[11]);
  166. COPY(regs[12]); COPY(regs[13]);
  167. COPY(regs[14]); COPY(regs[15]);
  168. COPY(gbr); COPY(mach);
  169. COPY(macl); COPY(pr);
  170. COPY(sr); COPY(pc);
  171. #undef COPY
  172. #ifdef CONFIG_SH_FPU
  173. if (boot_cpu_data.flags & CPU_HAS_FPU) {
  174. int owned_fp;
  175. struct task_struct *tsk = current;
  176. regs->sr |= SR_FD; /* Release FPU */
  177. clear_fpu(tsk, regs);
  178. clear_used_math();
  179. __get_user (owned_fp, &sc->sc_ownedfp);
  180. if (owned_fp)
  181. err |= restore_sigcontext_fpu(sc);
  182. }
  183. #endif
  184. regs->tra = -1; /* disable syscall checks */
  185. err |= __get_user(*r0_p, &sc->sc_regs[0]);
  186. return err;
  187. }
  188. asmlinkage int sys_sigreturn(unsigned long r4, unsigned long r5,
  189. unsigned long r6, unsigned long r7,
  190. struct pt_regs __regs)
  191. {
  192. struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
  193. struct sigframe __user *frame = (struct sigframe __user *)regs->regs[15];
  194. sigset_t set;
  195. int r0;
  196. /* Always make any pending restarted system calls return -EINTR */
  197. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  198. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  199. goto badframe;
  200. if (__get_user(set.sig[0], &frame->sc.oldmask)
  201. || (_NSIG_WORDS > 1
  202. && __copy_from_user(&set.sig[1], &frame->extramask,
  203. sizeof(frame->extramask))))
  204. goto badframe;
  205. sigdelsetmask(&set, ~_BLOCKABLE);
  206. spin_lock_irq(&current->sighand->siglock);
  207. current->blocked = set;
  208. recalc_sigpending();
  209. spin_unlock_irq(&current->sighand->siglock);
  210. if (restore_sigcontext(regs, &frame->sc, &r0))
  211. goto badframe;
  212. return r0;
  213. badframe:
  214. force_sig(SIGSEGV, current);
  215. return 0;
  216. }
  217. asmlinkage int sys_rt_sigreturn(unsigned long r4, unsigned long r5,
  218. unsigned long r6, unsigned long r7,
  219. struct pt_regs __regs)
  220. {
  221. struct pt_regs *regs = RELOC_HIDE(&__regs, 0);
  222. struct rt_sigframe __user *frame = (struct rt_sigframe __user *)regs->regs[15];
  223. sigset_t set;
  224. int r0;
  225. /* Always make any pending restarted system calls return -EINTR */
  226. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  227. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  228. goto badframe;
  229. if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
  230. goto badframe;
  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(regs, &frame->uc.uc_mcontext, &r0))
  237. goto badframe;
  238. if (do_sigaltstack(&frame->uc.uc_stack, NULL,
  239. regs->regs[15]) == -EFAULT)
  240. goto badframe;
  241. return r0;
  242. badframe:
  243. force_sig(SIGSEGV, current);
  244. return 0;
  245. }
  246. /*
  247. * Set up a signal frame.
  248. */
  249. static int
  250. setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
  251. unsigned long mask)
  252. {
  253. int err = 0;
  254. #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
  255. COPY(regs[0]); COPY(regs[1]);
  256. COPY(regs[2]); COPY(regs[3]);
  257. COPY(regs[4]); COPY(regs[5]);
  258. COPY(regs[6]); COPY(regs[7]);
  259. COPY(regs[8]); COPY(regs[9]);
  260. COPY(regs[10]); COPY(regs[11]);
  261. COPY(regs[12]); COPY(regs[13]);
  262. COPY(regs[14]); COPY(regs[15]);
  263. COPY(gbr); COPY(mach);
  264. COPY(macl); COPY(pr);
  265. COPY(sr); COPY(pc);
  266. #undef COPY
  267. #ifdef CONFIG_SH_FPU
  268. err |= save_sigcontext_fpu(sc, regs);
  269. #endif
  270. /* non-iBCS2 extensions.. */
  271. err |= __put_user(mask, &sc->oldmask);
  272. return err;
  273. }
  274. /*
  275. * Determine which stack to use..
  276. */
  277. static inline void __user *
  278. get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
  279. {
  280. if (ka->sa.sa_flags & SA_ONSTACK) {
  281. if (sas_ss_flags(sp) == 0)
  282. sp = current->sas_ss_sp + current->sas_ss_size;
  283. }
  284. return (void __user *)((sp - (frame_size+UNWINDGUARD)) & -8ul);
  285. }
  286. /* These symbols are defined with the addresses in the vsyscall page.
  287. See vsyscall-trapa.S. */
  288. extern void __kernel_sigreturn(void);
  289. extern void __kernel_rt_sigreturn(void);
  290. static int setup_frame(int sig, struct k_sigaction *ka,
  291. sigset_t *set, struct pt_regs *regs)
  292. {
  293. struct sigframe __user *frame;
  294. int err = 0;
  295. int signal;
  296. frame = get_sigframe(ka, regs->regs[15], sizeof(*frame));
  297. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  298. goto give_sigsegv;
  299. signal = current_thread_info()->exec_domain
  300. && current_thread_info()->exec_domain->signal_invmap
  301. && sig < 32
  302. ? current_thread_info()->exec_domain->signal_invmap[sig]
  303. : sig;
  304. err |= setup_sigcontext(&frame->sc, regs, set->sig[0]);
  305. if (_NSIG_WORDS > 1)
  306. err |= __copy_to_user(frame->extramask, &set->sig[1],
  307. sizeof(frame->extramask));
  308. /* Set up to return from userspace. If provided, use a stub
  309. already in userspace. */
  310. if (ka->sa.sa_flags & SA_RESTORER) {
  311. regs->pr = (unsigned long) ka->sa.sa_restorer;
  312. #ifdef CONFIG_VSYSCALL
  313. } else if (likely(current->mm->context.vdso)) {
  314. regs->pr = VDSO_SYM(&__kernel_sigreturn);
  315. #endif
  316. } else {
  317. /* Generate return code (system call to sigreturn) */
  318. err |= __put_user(MOVW(7), &frame->retcode[0]);
  319. err |= __put_user(TRAP_NOARG, &frame->retcode[1]);
  320. err |= __put_user(OR_R0_R0, &frame->retcode[2]);
  321. err |= __put_user(OR_R0_R0, &frame->retcode[3]);
  322. err |= __put_user(OR_R0_R0, &frame->retcode[4]);
  323. err |= __put_user(OR_R0_R0, &frame->retcode[5]);
  324. err |= __put_user(OR_R0_R0, &frame->retcode[6]);
  325. err |= __put_user((__NR_sigreturn), &frame->retcode[7]);
  326. regs->pr = (unsigned long) frame->retcode;
  327. flush_icache_range(regs->pr, regs->pr + sizeof(frame->retcode));
  328. }
  329. if (err)
  330. goto give_sigsegv;
  331. /* Set up registers for signal handler */
  332. regs->regs[15] = (unsigned long) frame;
  333. regs->regs[4] = signal; /* Arg for signal handler */
  334. regs->regs[5] = 0;
  335. regs->regs[6] = (unsigned long) &frame->sc;
  336. if (current->personality & FDPIC_FUNCPTRS) {
  337. struct fdpic_func_descriptor __user *funcptr =
  338. (struct fdpic_func_descriptor __user *)ka->sa.sa_handler;
  339. __get_user(regs->pc, &funcptr->text);
  340. __get_user(regs->regs[12], &funcptr->GOT);
  341. } else
  342. regs->pc = (unsigned long)ka->sa.sa_handler;
  343. set_fs(USER_DS);
  344. pr_debug("SIG deliver (%s:%d): sp=%p pc=%08lx pr=%08lx\n",
  345. current->comm, task_pid_nr(current), frame, regs->pc, regs->pr);
  346. return 0;
  347. give_sigsegv:
  348. force_sigsegv(sig, current);
  349. return -EFAULT;
  350. }
  351. static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
  352. sigset_t *set, struct pt_regs *regs)
  353. {
  354. struct rt_sigframe __user *frame;
  355. int err = 0;
  356. int signal;
  357. frame = get_sigframe(ka, regs->regs[15], sizeof(*frame));
  358. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  359. goto give_sigsegv;
  360. signal = current_thread_info()->exec_domain
  361. && current_thread_info()->exec_domain->signal_invmap
  362. && sig < 32
  363. ? current_thread_info()->exec_domain->signal_invmap[sig]
  364. : sig;
  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(NULL, &frame->uc.uc_link);
  369. err |= __put_user((void *)current->sas_ss_sp,
  370. &frame->uc.uc_stack.ss_sp);
  371. err |= __put_user(sas_ss_flags(regs->regs[15]),
  372. &frame->uc.uc_stack.ss_flags);
  373. err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
  374. err |= setup_sigcontext(&frame->uc.uc_mcontext,
  375. regs, set->sig[0]);
  376. err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
  377. /* Set up to return from userspace. If provided, use a stub
  378. already in userspace. */
  379. if (ka->sa.sa_flags & SA_RESTORER) {
  380. regs->pr = (unsigned long) ka->sa.sa_restorer;
  381. #ifdef CONFIG_VSYSCALL
  382. } else if (likely(current->mm->context.vdso)) {
  383. regs->pr = VDSO_SYM(&__kernel_rt_sigreturn);
  384. #endif
  385. } else {
  386. /* Generate return code (system call to rt_sigreturn) */
  387. err |= __put_user(MOVW(7), &frame->retcode[0]);
  388. err |= __put_user(TRAP_NOARG, &frame->retcode[1]);
  389. err |= __put_user(OR_R0_R0, &frame->retcode[2]);
  390. err |= __put_user(OR_R0_R0, &frame->retcode[3]);
  391. err |= __put_user(OR_R0_R0, &frame->retcode[4]);
  392. err |= __put_user(OR_R0_R0, &frame->retcode[5]);
  393. err |= __put_user(OR_R0_R0, &frame->retcode[6]);
  394. err |= __put_user((__NR_rt_sigreturn), &frame->retcode[7]);
  395. regs->pr = (unsigned long) frame->retcode;
  396. flush_icache_range(regs->pr, regs->pr + sizeof(frame->retcode));
  397. }
  398. if (err)
  399. goto give_sigsegv;
  400. /* Set up registers for signal handler */
  401. regs->regs[15] = (unsigned long) frame;
  402. regs->regs[4] = signal; /* Arg for signal handler */
  403. regs->regs[5] = (unsigned long) &frame->info;
  404. regs->regs[6] = (unsigned long) &frame->uc;
  405. if (current->personality & FDPIC_FUNCPTRS) {
  406. struct fdpic_func_descriptor __user *funcptr =
  407. (struct fdpic_func_descriptor __user *)ka->sa.sa_handler;
  408. __get_user(regs->pc, &funcptr->text);
  409. __get_user(regs->regs[12], &funcptr->GOT);
  410. } else
  411. regs->pc = (unsigned long)ka->sa.sa_handler;
  412. set_fs(USER_DS);
  413. pr_debug("SIG deliver (%s:%d): sp=%p pc=%08lx pr=%08lx\n",
  414. current->comm, task_pid_nr(current), frame, regs->pc, regs->pr);
  415. return 0;
  416. give_sigsegv:
  417. force_sigsegv(sig, current);
  418. return -EFAULT;
  419. }
  420. static inline void
  421. handle_syscall_restart(unsigned long save_r0, struct pt_regs *regs,
  422. struct sigaction *sa)
  423. {
  424. /* If we're not from a syscall, bail out */
  425. if (regs->tra < 0)
  426. return;
  427. /* check for system call restart.. */
  428. switch (regs->regs[0]) {
  429. case -ERESTART_RESTARTBLOCK:
  430. case -ERESTARTNOHAND:
  431. no_system_call_restart:
  432. regs->regs[0] = -EINTR;
  433. break;
  434. case -ERESTARTSYS:
  435. if (!(sa->sa_flags & SA_RESTART))
  436. goto no_system_call_restart;
  437. /* fallthrough */
  438. case -ERESTARTNOINTR:
  439. regs->regs[0] = save_r0;
  440. regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
  441. break;
  442. }
  443. }
  444. /*
  445. * OK, we're invoking a handler
  446. */
  447. static int
  448. handle_signal(unsigned long sig, struct k_sigaction *ka, siginfo_t *info,
  449. sigset_t *oldset, struct pt_regs *regs, unsigned int save_r0)
  450. {
  451. int ret;
  452. /* Set up the stack frame */
  453. if (ka->sa.sa_flags & SA_SIGINFO)
  454. ret = setup_rt_frame(sig, ka, info, oldset, regs);
  455. else
  456. ret = setup_frame(sig, ka, oldset, regs);
  457. if (ka->sa.sa_flags & SA_ONESHOT)
  458. ka->sa.sa_handler = SIG_DFL;
  459. if (ret == 0) {
  460. spin_lock_irq(&current->sighand->siglock);
  461. sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
  462. if (!(ka->sa.sa_flags & SA_NODEFER))
  463. sigaddset(&current->blocked,sig);
  464. recalc_sigpending();
  465. spin_unlock_irq(&current->sighand->siglock);
  466. }
  467. return ret;
  468. }
  469. /*
  470. * Note that 'init' is a special process: it doesn't get signals it doesn't
  471. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  472. * mistake.
  473. *
  474. * Note that we go through the signals twice: once to check the signals that
  475. * the kernel can handle, and then we build all the user-level signal handling
  476. * stack-frames in one go after that.
  477. */
  478. static void do_signal(struct pt_regs *regs, unsigned int save_r0)
  479. {
  480. siginfo_t info;
  481. int signr;
  482. struct k_sigaction ka;
  483. sigset_t *oldset;
  484. /*
  485. * We want the common case to go fast, which
  486. * is why we may in certain cases get here from
  487. * kernel mode. Just return without doing anything
  488. * if so.
  489. */
  490. if (!user_mode(regs))
  491. return;
  492. if (try_to_freeze())
  493. goto no_signal;
  494. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  495. oldset = &current->saved_sigmask;
  496. else
  497. oldset = &current->blocked;
  498. signr = get_signal_to_deliver(&info, &ka, regs, NULL);
  499. if (signr > 0) {
  500. handle_syscall_restart(save_r0, regs, &ka.sa);
  501. /* Whee! Actually deliver the signal. */
  502. if (handle_signal(signr, &ka, &info, oldset,
  503. regs, save_r0) == 0) {
  504. /* a signal was successfully delivered; the saved
  505. * sigmask will have been stored in the signal frame,
  506. * and will be restored by sigreturn, so we can simply
  507. * clear the TIF_RESTORE_SIGMASK flag */
  508. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  509. clear_thread_flag(TIF_RESTORE_SIGMASK);
  510. tracehook_signal_handler(signr, &info, &ka, regs,
  511. test_thread_flag(TIF_SINGLESTEP));
  512. }
  513. return;
  514. }
  515. no_signal:
  516. /* Did we come from a system call? */
  517. if (regs->tra >= 0) {
  518. /* Restart the system call - no handlers present */
  519. if (regs->regs[0] == -ERESTARTNOHAND ||
  520. regs->regs[0] == -ERESTARTSYS ||
  521. regs->regs[0] == -ERESTARTNOINTR) {
  522. regs->regs[0] = save_r0;
  523. regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
  524. } else if (regs->regs[0] == -ERESTART_RESTARTBLOCK) {
  525. regs->pc -= instruction_size(ctrl_inw(regs->pc - 4));
  526. regs->regs[3] = __NR_restart_syscall;
  527. }
  528. }
  529. /* if there's no signal to deliver, we just put the saved sigmask
  530. * back */
  531. if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
  532. clear_thread_flag(TIF_RESTORE_SIGMASK);
  533. sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
  534. }
  535. }
  536. asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned int save_r0,
  537. unsigned long thread_info_flags)
  538. {
  539. /* deal with pending signal delivery */
  540. if (thread_info_flags & _TIF_SIGPENDING)
  541. do_signal(regs, save_r0);
  542. if (thread_info_flags & _TIF_NOTIFY_RESUME) {
  543. clear_thread_flag(TIF_NOTIFY_RESUME);
  544. tracehook_notify_resume(regs);
  545. if (current->replacement_session_keyring)
  546. key_replace_session_keyring();
  547. }
  548. }