signal_32.c 17 KB

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