signal_32.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. /*
  2. * Copyright (C) 1991, 1992 Linus Torvalds
  3. *
  4. * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
  5. * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
  6. */
  7. #include <linux/sched.h>
  8. #include <linux/mm.h>
  9. #include <linux/smp.h>
  10. #include <linux/kernel.h>
  11. #include <linux/signal.h>
  12. #include <linux/errno.h>
  13. #include <linux/wait.h>
  14. #include <linux/unistd.h>
  15. #include <linux/stddef.h>
  16. #include <linux/personality.h>
  17. #include <linux/suspend.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/elf.h>
  20. #include <linux/binfmts.h>
  21. #include <asm/processor.h>
  22. #include <asm/ucontext.h>
  23. #include <asm/uaccess.h>
  24. #include <asm/i387.h>
  25. #include <asm/vdso.h>
  26. #include "sigframe_32.h"
  27. #define DEBUG_SIG 0
  28. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  29. /*
  30. * Atomically swap in the new signal mask, and wait for a signal.
  31. */
  32. asmlinkage int
  33. sys_sigsuspend(int history0, int history1, old_sigset_t mask)
  34. {
  35. mask &= _BLOCKABLE;
  36. spin_lock_irq(&current->sighand->siglock);
  37. current->saved_sigmask = current->blocked;
  38. siginitset(&current->blocked, mask);
  39. recalc_sigpending();
  40. spin_unlock_irq(&current->sighand->siglock);
  41. current->state = TASK_INTERRUPTIBLE;
  42. schedule();
  43. set_thread_flag(TIF_RESTORE_SIGMASK);
  44. return -ERESTARTNOHAND;
  45. }
  46. asmlinkage int
  47. sys_sigaction(int sig, const struct old_sigaction __user *act,
  48. struct old_sigaction __user *oact)
  49. {
  50. struct k_sigaction new_ka, old_ka;
  51. int ret;
  52. if (act) {
  53. old_sigset_t mask;
  54. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  55. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  56. __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
  57. return -EFAULT;
  58. __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  59. __get_user(mask, &act->sa_mask);
  60. siginitset(&new_ka.sa.sa_mask, mask);
  61. }
  62. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  63. if (!ret && oact) {
  64. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  65. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  66. __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
  67. return -EFAULT;
  68. __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  69. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  70. }
  71. return ret;
  72. }
  73. asmlinkage int
  74. sys_sigaltstack(unsigned long bx)
  75. {
  76. /* This is needed to make gcc realize it doesn't own the "struct pt_regs" */
  77. struct pt_regs *regs = (struct pt_regs *)&bx;
  78. const stack_t __user *uss = (const stack_t __user *)bx;
  79. stack_t __user *uoss = (stack_t __user *)regs->cx;
  80. return do_sigaltstack(uss, uoss, regs->sp);
  81. }
  82. /*
  83. * Do a signal return; undo the signal stack.
  84. */
  85. static int
  86. restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *peax)
  87. {
  88. unsigned int err = 0;
  89. /* Always make any pending restarted system calls return -EINTR */
  90. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  91. #define COPY(x) err |= __get_user(regs->x, &sc->x)
  92. #define COPY_SEG(seg) \
  93. { unsigned short tmp; \
  94. err |= __get_user(tmp, &sc->seg); \
  95. regs->seg = tmp; }
  96. #define COPY_SEG_STRICT(seg) \
  97. { unsigned short tmp; \
  98. err |= __get_user(tmp, &sc->seg); \
  99. regs->seg = tmp|3; }
  100. #define GET_SEG(seg) \
  101. { unsigned short tmp; \
  102. err |= __get_user(tmp, &sc->seg); \
  103. loadsegment(seg,tmp); }
  104. #define FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_RF | \
  105. X86_EFLAGS_OF | X86_EFLAGS_DF | \
  106. X86_EFLAGS_TF | X86_EFLAGS_SF | X86_EFLAGS_ZF | \
  107. X86_EFLAGS_AF | X86_EFLAGS_PF | X86_EFLAGS_CF)
  108. GET_SEG(gs);
  109. COPY_SEG(fs);
  110. COPY_SEG(es);
  111. COPY_SEG(ds);
  112. COPY(di);
  113. COPY(si);
  114. COPY(bp);
  115. COPY(sp);
  116. COPY(bx);
  117. COPY(dx);
  118. COPY(cx);
  119. COPY(ip);
  120. COPY_SEG_STRICT(cs);
  121. COPY_SEG_STRICT(ss);
  122. {
  123. unsigned int tmpflags;
  124. err |= __get_user(tmpflags, &sc->flags);
  125. regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
  126. regs->orig_ax = -1; /* disable syscall checks */
  127. }
  128. {
  129. struct _fpstate __user * buf;
  130. err |= __get_user(buf, &sc->fpstate);
  131. if (buf) {
  132. if (!access_ok(VERIFY_READ, buf, sizeof(*buf)))
  133. goto badframe;
  134. err |= restore_i387(buf);
  135. } else {
  136. struct task_struct *me = current;
  137. if (used_math()) {
  138. clear_fpu(me);
  139. clear_used_math();
  140. }
  141. }
  142. }
  143. err |= __get_user(*peax, &sc->ax);
  144. return err;
  145. badframe:
  146. return 1;
  147. }
  148. asmlinkage int sys_sigreturn(unsigned long __unused)
  149. {
  150. struct pt_regs *regs = (struct pt_regs *) &__unused;
  151. struct sigframe __user *frame = (struct sigframe __user *)(regs->sp - 8);
  152. sigset_t set;
  153. int ax;
  154. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  155. goto badframe;
  156. if (__get_user(set.sig[0], &frame->sc.oldmask)
  157. || (_NSIG_WORDS > 1
  158. && __copy_from_user(&set.sig[1], &frame->extramask,
  159. sizeof(frame->extramask))))
  160. goto badframe;
  161. sigdelsetmask(&set, ~_BLOCKABLE);
  162. spin_lock_irq(&current->sighand->siglock);
  163. current->blocked = set;
  164. recalc_sigpending();
  165. spin_unlock_irq(&current->sighand->siglock);
  166. if (restore_sigcontext(regs, &frame->sc, &ax))
  167. goto badframe;
  168. return ax;
  169. badframe:
  170. if (show_unhandled_signals && printk_ratelimit()) {
  171. printk("%s%s[%d] bad frame in sigreturn frame:%p ip:%lx"
  172. " sp:%lx oeax:%lx",
  173. task_pid_nr(current) > 1 ? KERN_INFO : KERN_EMERG,
  174. current->comm, task_pid_nr(current), frame, regs->ip,
  175. regs->sp, regs->orig_ax);
  176. print_vma_addr(" in ", regs->ip);
  177. printk("\n");
  178. }
  179. force_sig(SIGSEGV, current);
  180. return 0;
  181. }
  182. asmlinkage int sys_rt_sigreturn(unsigned long __unused)
  183. {
  184. struct pt_regs *regs = (struct pt_regs *) &__unused;
  185. struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(regs->sp - 4);
  186. sigset_t set;
  187. int ax;
  188. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  189. goto badframe;
  190. if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
  191. goto badframe;
  192. sigdelsetmask(&set, ~_BLOCKABLE);
  193. spin_lock_irq(&current->sighand->siglock);
  194. current->blocked = set;
  195. recalc_sigpending();
  196. spin_unlock_irq(&current->sighand->siglock);
  197. if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
  198. goto badframe;
  199. if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
  200. goto badframe;
  201. return ax;
  202. badframe:
  203. force_sig(SIGSEGV, current);
  204. return 0;
  205. }
  206. /*
  207. * Set up a signal frame.
  208. */
  209. static int
  210. setup_sigcontext(struct sigcontext __user *sc, struct _fpstate __user *fpstate,
  211. struct pt_regs *regs, unsigned long mask)
  212. {
  213. int tmp, err = 0;
  214. err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs);
  215. savesegment(gs, tmp);
  216. err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
  217. err |= __put_user(regs->es, (unsigned int __user *)&sc->es);
  218. err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds);
  219. err |= __put_user(regs->di, &sc->di);
  220. err |= __put_user(regs->si, &sc->si);
  221. err |= __put_user(regs->bp, &sc->bp);
  222. err |= __put_user(regs->sp, &sc->sp);
  223. err |= __put_user(regs->bx, &sc->bx);
  224. err |= __put_user(regs->dx, &sc->dx);
  225. err |= __put_user(regs->cx, &sc->cx);
  226. err |= __put_user(regs->ax, &sc->ax);
  227. err |= __put_user(current->thread.trap_no, &sc->trapno);
  228. err |= __put_user(current->thread.error_code, &sc->err);
  229. err |= __put_user(regs->ip, &sc->ip);
  230. err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs);
  231. err |= __put_user(regs->flags, &sc->flags);
  232. err |= __put_user(regs->sp, &sc->sp_at_signal);
  233. err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss);
  234. tmp = save_i387(fpstate);
  235. if (tmp < 0)
  236. err = 1;
  237. else
  238. err |= __put_user(tmp ? fpstate : NULL, &sc->fpstate);
  239. /* non-iBCS2 extensions.. */
  240. err |= __put_user(mask, &sc->oldmask);
  241. err |= __put_user(current->thread.cr2, &sc->cr2);
  242. return err;
  243. }
  244. /*
  245. * Determine which stack to use..
  246. */
  247. static inline void __user *
  248. get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
  249. {
  250. unsigned long sp;
  251. /* Default to using normal stack */
  252. sp = regs->sp;
  253. /*
  254. * If we are on the alternate signal stack and would overflow it, don't.
  255. * Return an always-bogus address instead so we will die with SIGSEGV.
  256. */
  257. if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
  258. return (void __user *) -1L;
  259. /* This is the X/Open sanctioned signal stack switching. */
  260. if (ka->sa.sa_flags & SA_ONSTACK) {
  261. if (sas_ss_flags(sp) == 0)
  262. sp = current->sas_ss_sp + current->sas_ss_size;
  263. }
  264. /* This is the legacy signal stack switching. */
  265. else if ((regs->ss & 0xffff) != __USER_DS &&
  266. !(ka->sa.sa_flags & SA_RESTORER) &&
  267. ka->sa.sa_restorer) {
  268. sp = (unsigned long) ka->sa.sa_restorer;
  269. }
  270. sp -= frame_size;
  271. /* Align the stack pointer according to the i386 ABI,
  272. * i.e. so that on function entry ((sp + 4) & 15) == 0. */
  273. sp = ((sp + 4) & -16ul) - 4;
  274. return (void __user *) sp;
  275. }
  276. /* These symbols are defined with the addresses in the vsyscall page.
  277. See vsyscall-sigreturn.S. */
  278. extern void __user __kernel_sigreturn;
  279. extern void __user __kernel_rt_sigreturn;
  280. static int setup_frame(int sig, struct k_sigaction *ka,
  281. sigset_t *set, struct pt_regs * regs)
  282. {
  283. void __user *restorer;
  284. struct sigframe __user *frame;
  285. int err = 0;
  286. int usig;
  287. frame = get_sigframe(ka, regs, sizeof(*frame));
  288. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  289. goto give_sigsegv;
  290. usig = 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 = __put_user(usig, &frame->sig);
  296. if (err)
  297. goto give_sigsegv;
  298. err = setup_sigcontext(&frame->sc, &frame->fpstate, regs, set->sig[0]);
  299. if (err)
  300. goto give_sigsegv;
  301. if (_NSIG_WORDS > 1) {
  302. err = __copy_to_user(&frame->extramask, &set->sig[1],
  303. sizeof(frame->extramask));
  304. if (err)
  305. goto give_sigsegv;
  306. }
  307. if (current->binfmt->hasvdso)
  308. restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
  309. else
  310. restorer = &frame->retcode;
  311. if (ka->sa.sa_flags & SA_RESTORER)
  312. restorer = ka->sa.sa_restorer;
  313. /* Set up to return from userspace. */
  314. err |= __put_user(restorer, &frame->pretcode);
  315. /*
  316. * This is popl %eax ; movl $,%eax ; int $0x80
  317. *
  318. * WE DO NOT USE IT ANY MORE! It's only left here for historical
  319. * reasons and because gdb uses it as a signature to notice
  320. * signal handler stack frames.
  321. */
  322. err |= __put_user(0xb858, (short __user *)(frame->retcode+0));
  323. err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2));
  324. err |= __put_user(0x80cd, (short __user *)(frame->retcode+6));
  325. if (err)
  326. goto give_sigsegv;
  327. /* Set up registers for signal handler */
  328. regs->sp = (unsigned long) frame;
  329. regs->ip = (unsigned long) ka->sa.sa_handler;
  330. regs->ax = (unsigned long) sig;
  331. regs->dx = (unsigned long) 0;
  332. regs->cx = (unsigned long) 0;
  333. regs->ds = __USER_DS;
  334. regs->es = __USER_DS;
  335. regs->ss = __USER_DS;
  336. regs->cs = __USER_CS;
  337. /*
  338. * Clear TF when entering the signal handler, but
  339. * notify any tracer that was single-stepping it.
  340. * The tracer may want to single-step inside the
  341. * handler too.
  342. */
  343. regs->flags &= ~TF_MASK;
  344. if (test_thread_flag(TIF_SINGLESTEP))
  345. ptrace_notify(SIGTRAP);
  346. #if DEBUG_SIG
  347. printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
  348. current->comm, current->pid, frame, regs->ip, frame->pretcode);
  349. #endif
  350. return 0;
  351. give_sigsegv:
  352. force_sigsegv(sig, current);
  353. return -EFAULT;
  354. }
  355. static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
  356. sigset_t *set, struct pt_regs * regs)
  357. {
  358. void __user *restorer;
  359. struct rt_sigframe __user *frame;
  360. int err = 0;
  361. int usig;
  362. frame = get_sigframe(ka, regs, sizeof(*frame));
  363. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  364. goto give_sigsegv;
  365. usig = current_thread_info()->exec_domain
  366. && current_thread_info()->exec_domain->signal_invmap
  367. && sig < 32
  368. ? current_thread_info()->exec_domain->signal_invmap[sig]
  369. : sig;
  370. err |= __put_user(usig, &frame->sig);
  371. err |= __put_user(&frame->info, &frame->pinfo);
  372. err |= __put_user(&frame->uc, &frame->puc);
  373. err |= copy_siginfo_to_user(&frame->info, info);
  374. if (err)
  375. goto give_sigsegv;
  376. /* Create the ucontext. */
  377. err |= __put_user(0, &frame->uc.uc_flags);
  378. err |= __put_user(0, &frame->uc.uc_link);
  379. err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
  380. err |= __put_user(sas_ss_flags(regs->sp),
  381. &frame->uc.uc_stack.ss_flags);
  382. err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
  383. err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->fpstate,
  384. regs, set->sig[0]);
  385. err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
  386. if (err)
  387. goto give_sigsegv;
  388. /* Set up to return from userspace. */
  389. restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
  390. if (ka->sa.sa_flags & SA_RESTORER)
  391. restorer = ka->sa.sa_restorer;
  392. err |= __put_user(restorer, &frame->pretcode);
  393. /*
  394. * This is movl $,%ax ; int $0x80
  395. *
  396. * WE DO NOT USE IT ANY MORE! It's only left here for historical
  397. * reasons and because gdb uses it as a signature to notice
  398. * signal handler stack frames.
  399. */
  400. err |= __put_user(0xb8, (char __user *)(frame->retcode+0));
  401. err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1));
  402. err |= __put_user(0x80cd, (short __user *)(frame->retcode+5));
  403. if (err)
  404. goto give_sigsegv;
  405. /* Set up registers for signal handler */
  406. regs->sp = (unsigned long) frame;
  407. regs->ip = (unsigned long) ka->sa.sa_handler;
  408. regs->ax = (unsigned long) usig;
  409. regs->dx = (unsigned long) &frame->info;
  410. regs->cx = (unsigned long) &frame->uc;
  411. regs->ds = __USER_DS;
  412. regs->es = __USER_DS;
  413. regs->ss = __USER_DS;
  414. regs->cs = __USER_CS;
  415. /*
  416. * Clear TF when entering the signal handler, but
  417. * notify any tracer that was single-stepping it.
  418. * The tracer may want to single-step inside the
  419. * handler too.
  420. */
  421. regs->flags &= ~TF_MASK;
  422. if (test_thread_flag(TIF_SINGLESTEP))
  423. ptrace_notify(SIGTRAP);
  424. #if DEBUG_SIG
  425. printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
  426. current->comm, current->pid, frame, regs->ip, frame->pretcode);
  427. #endif
  428. return 0;
  429. give_sigsegv:
  430. force_sigsegv(sig, current);
  431. return -EFAULT;
  432. }
  433. /*
  434. * OK, we're invoking a handler
  435. */
  436. static int
  437. handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
  438. sigset_t *oldset, struct pt_regs * regs)
  439. {
  440. int ret;
  441. /* Are we from a system call? */
  442. if (regs->orig_ax >= 0) {
  443. /* If so, check system call restarting.. */
  444. switch (regs->ax) {
  445. case -ERESTART_RESTARTBLOCK:
  446. case -ERESTARTNOHAND:
  447. regs->ax = -EINTR;
  448. break;
  449. case -ERESTARTSYS:
  450. if (!(ka->sa.sa_flags & SA_RESTART)) {
  451. regs->ax = -EINTR;
  452. break;
  453. }
  454. /* fallthrough */
  455. case -ERESTARTNOINTR:
  456. regs->ax = regs->orig_ax;
  457. regs->ip -= 2;
  458. }
  459. }
  460. /*
  461. * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
  462. * flag so that register information in the sigcontext is correct.
  463. */
  464. if (unlikely(regs->flags & X86_EFLAGS_TF) &&
  465. likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
  466. regs->flags &= ~X86_EFLAGS_TF;
  467. /* Set up the stack frame */
  468. if (ka->sa.sa_flags & SA_SIGINFO)
  469. ret = setup_rt_frame(sig, ka, info, oldset, regs);
  470. else
  471. ret = setup_frame(sig, ka, oldset, regs);
  472. if (ret == 0) {
  473. spin_lock_irq(&current->sighand->siglock);
  474. sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
  475. if (!(ka->sa.sa_flags & SA_NODEFER))
  476. sigaddset(&current->blocked,sig);
  477. recalc_sigpending();
  478. spin_unlock_irq(&current->sighand->siglock);
  479. }
  480. return ret;
  481. }
  482. /*
  483. * Note that 'init' is a special process: it doesn't get signals it doesn't
  484. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  485. * mistake.
  486. */
  487. static void do_signal(struct pt_regs *regs)
  488. {
  489. siginfo_t info;
  490. int signr;
  491. struct k_sigaction ka;
  492. sigset_t *oldset;
  493. /*
  494. * We want the common case to go fast, which
  495. * is why we may in certain cases get here from
  496. * kernel mode. Just return without doing anything
  497. * if so. vm86 regs switched out by assembly code
  498. * before reaching here, so testing against kernel
  499. * CS suffices.
  500. */
  501. if (!user_mode(regs))
  502. return;
  503. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  504. oldset = &current->saved_sigmask;
  505. else
  506. oldset = &current->blocked;
  507. signr = get_signal_to_deliver(&info, &ka, regs, NULL);
  508. if (signr > 0) {
  509. /* Re-enable any watchpoints before delivering the
  510. * signal to user space. The processor register will
  511. * have been cleared if the watchpoint triggered
  512. * inside the kernel.
  513. */
  514. if (unlikely(current->thread.debugreg7))
  515. set_debugreg(current->thread.debugreg7, 7);
  516. /* Whee! Actually deliver the signal. */
  517. if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
  518. /* a signal was successfully delivered; the saved
  519. * sigmask will have been stored in the signal frame,
  520. * and will be restored by sigreturn, so we can simply
  521. * clear the TIF_RESTORE_SIGMASK flag */
  522. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  523. clear_thread_flag(TIF_RESTORE_SIGMASK);
  524. }
  525. return;
  526. }
  527. /* Did we come from a system call? */
  528. if (regs->orig_ax >= 0) {
  529. /* Restart the system call - no handlers present */
  530. switch (regs->ax) {
  531. case -ERESTARTNOHAND:
  532. case -ERESTARTSYS:
  533. case -ERESTARTNOINTR:
  534. regs->ax = regs->orig_ax;
  535. regs->ip -= 2;
  536. break;
  537. case -ERESTART_RESTARTBLOCK:
  538. regs->ax = __NR_restart_syscall;
  539. regs->ip -= 2;
  540. break;
  541. }
  542. }
  543. /* if there's no signal to deliver, we just put the saved sigmask
  544. * back */
  545. if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
  546. clear_thread_flag(TIF_RESTORE_SIGMASK);
  547. sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
  548. }
  549. }
  550. /*
  551. * notification of userspace execution resumption
  552. * - triggered by the TIF_WORK_MASK flags
  553. */
  554. __attribute__((regparm(3)))
  555. void do_notify_resume(struct pt_regs *regs, void *_unused,
  556. __u32 thread_info_flags)
  557. {
  558. /* Pending single-step? */
  559. if (thread_info_flags & _TIF_SINGLESTEP) {
  560. regs->flags |= TF_MASK;
  561. clear_thread_flag(TIF_SINGLESTEP);
  562. }
  563. /* deal with pending signal delivery */
  564. if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
  565. do_signal(regs);
  566. if (thread_info_flags & _TIF_HRTICK_RESCHED)
  567. hrtick_resched();
  568. clear_thread_flag(TIF_IRET);
  569. }