signal_32.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  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\n",
  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. force_sig(SIGSEGV, current);
  177. return 0;
  178. }
  179. asmlinkage int sys_rt_sigreturn(unsigned long __unused)
  180. {
  181. struct pt_regs *regs = (struct pt_regs *) &__unused;
  182. struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(regs->sp - 4);
  183. sigset_t set;
  184. int ax;
  185. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  186. goto badframe;
  187. if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
  188. goto badframe;
  189. sigdelsetmask(&set, ~_BLOCKABLE);
  190. spin_lock_irq(&current->sighand->siglock);
  191. current->blocked = set;
  192. recalc_sigpending();
  193. spin_unlock_irq(&current->sighand->siglock);
  194. if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ax))
  195. goto badframe;
  196. if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->sp) == -EFAULT)
  197. goto badframe;
  198. return ax;
  199. badframe:
  200. force_sig(SIGSEGV, current);
  201. return 0;
  202. }
  203. /*
  204. * Set up a signal frame.
  205. */
  206. static int
  207. setup_sigcontext(struct sigcontext __user *sc, struct _fpstate __user *fpstate,
  208. struct pt_regs *regs, unsigned long mask)
  209. {
  210. int tmp, err = 0;
  211. err |= __put_user(regs->fs, (unsigned int __user *)&sc->fs);
  212. savesegment(gs, tmp);
  213. err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
  214. err |= __put_user(regs->es, (unsigned int __user *)&sc->es);
  215. err |= __put_user(regs->ds, (unsigned int __user *)&sc->ds);
  216. err |= __put_user(regs->di, &sc->di);
  217. err |= __put_user(regs->si, &sc->si);
  218. err |= __put_user(regs->bp, &sc->bp);
  219. err |= __put_user(regs->sp, &sc->sp);
  220. err |= __put_user(regs->bx, &sc->bx);
  221. err |= __put_user(regs->dx, &sc->dx);
  222. err |= __put_user(regs->cx, &sc->cx);
  223. err |= __put_user(regs->ax, &sc->ax);
  224. err |= __put_user(current->thread.trap_no, &sc->trapno);
  225. err |= __put_user(current->thread.error_code, &sc->err);
  226. err |= __put_user(regs->ip, &sc->ip);
  227. err |= __put_user(regs->cs, (unsigned int __user *)&sc->cs);
  228. err |= __put_user(regs->flags, &sc->flags);
  229. err |= __put_user(regs->sp, &sc->sp_at_signal);
  230. err |= __put_user(regs->ss, (unsigned int __user *)&sc->ss);
  231. tmp = save_i387(fpstate);
  232. if (tmp < 0)
  233. err = 1;
  234. else
  235. err |= __put_user(tmp ? fpstate : NULL, &sc->fpstate);
  236. /* non-iBCS2 extensions.. */
  237. err |= __put_user(mask, &sc->oldmask);
  238. err |= __put_user(current->thread.cr2, &sc->cr2);
  239. return err;
  240. }
  241. /*
  242. * Determine which stack to use..
  243. */
  244. static inline void __user *
  245. get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
  246. {
  247. unsigned long sp;
  248. /* Default to using normal stack */
  249. sp = regs->sp;
  250. /*
  251. * If we are on the alternate signal stack and would overflow it, don't.
  252. * Return an always-bogus address instead so we will die with SIGSEGV.
  253. */
  254. if (on_sig_stack(sp) && !likely(on_sig_stack(sp - frame_size)))
  255. return (void __user *) -1L;
  256. /* This is the X/Open sanctioned signal stack switching. */
  257. if (ka->sa.sa_flags & SA_ONSTACK) {
  258. if (sas_ss_flags(sp) == 0)
  259. sp = current->sas_ss_sp + current->sas_ss_size;
  260. }
  261. /* This is the legacy signal stack switching. */
  262. else if ((regs->ss & 0xffff) != __USER_DS &&
  263. !(ka->sa.sa_flags & SA_RESTORER) &&
  264. ka->sa.sa_restorer) {
  265. sp = (unsigned long) ka->sa.sa_restorer;
  266. }
  267. sp -= frame_size;
  268. /* Align the stack pointer according to the i386 ABI,
  269. * i.e. so that on function entry ((sp + 4) & 15) == 0. */
  270. sp = ((sp + 4) & -16ul) - 4;
  271. return (void __user *) sp;
  272. }
  273. /* These symbols are defined with the addresses in the vsyscall page.
  274. See vsyscall-sigreturn.S. */
  275. extern void __user __kernel_sigreturn;
  276. extern void __user __kernel_rt_sigreturn;
  277. static int setup_frame(int sig, struct k_sigaction *ka,
  278. sigset_t *set, struct pt_regs * regs)
  279. {
  280. void __user *restorer;
  281. struct sigframe __user *frame;
  282. int err = 0;
  283. int usig;
  284. frame = get_sigframe(ka, regs, sizeof(*frame));
  285. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  286. goto give_sigsegv;
  287. usig = current_thread_info()->exec_domain
  288. && current_thread_info()->exec_domain->signal_invmap
  289. && sig < 32
  290. ? current_thread_info()->exec_domain->signal_invmap[sig]
  291. : sig;
  292. err = __put_user(usig, &frame->sig);
  293. if (err)
  294. goto give_sigsegv;
  295. err = setup_sigcontext(&frame->sc, &frame->fpstate, regs, set->sig[0]);
  296. if (err)
  297. goto give_sigsegv;
  298. if (_NSIG_WORDS > 1) {
  299. err = __copy_to_user(&frame->extramask, &set->sig[1],
  300. sizeof(frame->extramask));
  301. if (err)
  302. goto give_sigsegv;
  303. }
  304. if (current->binfmt->hasvdso)
  305. restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
  306. else
  307. restorer = (void *)&frame->retcode;
  308. if (ka->sa.sa_flags & SA_RESTORER)
  309. restorer = ka->sa.sa_restorer;
  310. /* Set up to return from userspace. */
  311. err |= __put_user(restorer, &frame->pretcode);
  312. /*
  313. * This is popl %eax ; movl $,%eax ; int $0x80
  314. *
  315. * WE DO NOT USE IT ANY MORE! It's only left here for historical
  316. * reasons and because gdb uses it as a signature to notice
  317. * signal handler stack frames.
  318. */
  319. err |= __put_user(0xb858, (short __user *)(frame->retcode+0));
  320. err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2));
  321. err |= __put_user(0x80cd, (short __user *)(frame->retcode+6));
  322. if (err)
  323. goto give_sigsegv;
  324. /* Set up registers for signal handler */
  325. regs->sp = (unsigned long) frame;
  326. regs->ip = (unsigned long) ka->sa.sa_handler;
  327. regs->ax = (unsigned long) sig;
  328. regs->dx = (unsigned long) 0;
  329. regs->cx = (unsigned long) 0;
  330. regs->ds = __USER_DS;
  331. regs->es = __USER_DS;
  332. regs->ss = __USER_DS;
  333. regs->cs = __USER_CS;
  334. /*
  335. * Clear TF when entering the signal handler, but
  336. * notify any tracer that was single-stepping it.
  337. * The tracer may want to single-step inside the
  338. * handler too.
  339. */
  340. regs->flags &= ~TF_MASK;
  341. if (test_thread_flag(TIF_SINGLESTEP))
  342. ptrace_notify(SIGTRAP);
  343. #if DEBUG_SIG
  344. printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
  345. current->comm, current->pid, frame, regs->ip, frame->pretcode);
  346. #endif
  347. return 0;
  348. give_sigsegv:
  349. force_sigsegv(sig, current);
  350. return -EFAULT;
  351. }
  352. static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
  353. sigset_t *set, struct pt_regs * regs)
  354. {
  355. void __user *restorer;
  356. struct rt_sigframe __user *frame;
  357. int err = 0;
  358. int usig;
  359. frame = get_sigframe(ka, regs, sizeof(*frame));
  360. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  361. goto give_sigsegv;
  362. usig = current_thread_info()->exec_domain
  363. && current_thread_info()->exec_domain->signal_invmap
  364. && sig < 32
  365. ? current_thread_info()->exec_domain->signal_invmap[sig]
  366. : sig;
  367. err |= __put_user(usig, &frame->sig);
  368. err |= __put_user(&frame->info, &frame->pinfo);
  369. err |= __put_user(&frame->uc, &frame->puc);
  370. err |= copy_siginfo_to_user(&frame->info, info);
  371. if (err)
  372. goto give_sigsegv;
  373. /* Create the ucontext. */
  374. err |= __put_user(0, &frame->uc.uc_flags);
  375. err |= __put_user(0, &frame->uc.uc_link);
  376. err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
  377. err |= __put_user(sas_ss_flags(regs->sp),
  378. &frame->uc.uc_stack.ss_flags);
  379. err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
  380. err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->fpstate,
  381. regs, set->sig[0]);
  382. err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
  383. if (err)
  384. goto give_sigsegv;
  385. /* Set up to return from userspace. */
  386. restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
  387. if (ka->sa.sa_flags & SA_RESTORER)
  388. restorer = ka->sa.sa_restorer;
  389. err |= __put_user(restorer, &frame->pretcode);
  390. /*
  391. * This is movl $,%ax ; int $0x80
  392. *
  393. * WE DO NOT USE IT ANY MORE! It's only left here for historical
  394. * reasons and because gdb uses it as a signature to notice
  395. * signal handler stack frames.
  396. */
  397. err |= __put_user(0xb8, (char __user *)(frame->retcode+0));
  398. err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1));
  399. err |= __put_user(0x80cd, (short __user *)(frame->retcode+5));
  400. if (err)
  401. goto give_sigsegv;
  402. /* Set up registers for signal handler */
  403. regs->sp = (unsigned long) frame;
  404. regs->ip = (unsigned long) ka->sa.sa_handler;
  405. regs->ax = (unsigned long) usig;
  406. regs->dx = (unsigned long) &frame->info;
  407. regs->cx = (unsigned long) &frame->uc;
  408. regs->ds = __USER_DS;
  409. regs->es = __USER_DS;
  410. regs->ss = __USER_DS;
  411. regs->cs = __USER_CS;
  412. /*
  413. * Clear TF when entering the signal handler, but
  414. * notify any tracer that was single-stepping it.
  415. * The tracer may want to single-step inside the
  416. * handler too.
  417. */
  418. regs->flags &= ~TF_MASK;
  419. if (test_thread_flag(TIF_SINGLESTEP))
  420. ptrace_notify(SIGTRAP);
  421. #if DEBUG_SIG
  422. printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
  423. current->comm, current->pid, frame, regs->ip, frame->pretcode);
  424. #endif
  425. return 0;
  426. give_sigsegv:
  427. force_sigsegv(sig, current);
  428. return -EFAULT;
  429. }
  430. /*
  431. * OK, we're invoking a handler
  432. */
  433. static int
  434. handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
  435. sigset_t *oldset, struct pt_regs * regs)
  436. {
  437. int ret;
  438. /* Are we from a system call? */
  439. if (regs->orig_ax >= 0) {
  440. /* If so, check system call restarting.. */
  441. switch (regs->ax) {
  442. case -ERESTART_RESTARTBLOCK:
  443. case -ERESTARTNOHAND:
  444. regs->ax = -EINTR;
  445. break;
  446. case -ERESTARTSYS:
  447. if (!(ka->sa.sa_flags & SA_RESTART)) {
  448. regs->ax = -EINTR;
  449. break;
  450. }
  451. /* fallthrough */
  452. case -ERESTARTNOINTR:
  453. regs->ax = regs->orig_ax;
  454. regs->ip -= 2;
  455. }
  456. }
  457. /*
  458. * If TF is set due to a debugger (TIF_FORCED_TF), clear the TF
  459. * flag so that register information in the sigcontext is correct.
  460. */
  461. if (unlikely(regs->flags & X86_EFLAGS_TF) &&
  462. likely(test_and_clear_thread_flag(TIF_FORCED_TF)))
  463. regs->flags &= ~X86_EFLAGS_TF;
  464. /* Set up the stack frame */
  465. if (ka->sa.sa_flags & SA_SIGINFO)
  466. ret = setup_rt_frame(sig, ka, info, oldset, regs);
  467. else
  468. ret = setup_frame(sig, ka, oldset, regs);
  469. if (ret == 0) {
  470. spin_lock_irq(&current->sighand->siglock);
  471. sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
  472. if (!(ka->sa.sa_flags & SA_NODEFER))
  473. sigaddset(&current->blocked,sig);
  474. recalc_sigpending();
  475. spin_unlock_irq(&current->sighand->siglock);
  476. }
  477. return ret;
  478. }
  479. /*
  480. * Note that 'init' is a special process: it doesn't get signals it doesn't
  481. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  482. * mistake.
  483. */
  484. static void do_signal(struct pt_regs *regs)
  485. {
  486. siginfo_t info;
  487. int signr;
  488. struct k_sigaction ka;
  489. sigset_t *oldset;
  490. /*
  491. * We want the common case to go fast, which
  492. * is why we may in certain cases get here from
  493. * kernel mode. Just return without doing anything
  494. * if so. vm86 regs switched out by assembly code
  495. * before reaching here, so testing against kernel
  496. * CS suffices.
  497. */
  498. if (!user_mode(regs))
  499. return;
  500. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  501. oldset = &current->saved_sigmask;
  502. else
  503. oldset = &current->blocked;
  504. signr = get_signal_to_deliver(&info, &ka, regs, NULL);
  505. if (signr > 0) {
  506. /* Re-enable any watchpoints before delivering the
  507. * signal to user space. The processor register will
  508. * have been cleared if the watchpoint triggered
  509. * inside the kernel.
  510. */
  511. if (unlikely(current->thread.debugreg7))
  512. set_debugreg(current->thread.debugreg7, 7);
  513. /* Whee! Actually deliver the signal. */
  514. if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
  515. /* a signal was successfully delivered; the saved
  516. * sigmask will have been stored in the signal frame,
  517. * and will be restored by sigreturn, so we can simply
  518. * clear the TIF_RESTORE_SIGMASK flag */
  519. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  520. clear_thread_flag(TIF_RESTORE_SIGMASK);
  521. }
  522. return;
  523. }
  524. /* Did we come from a system call? */
  525. if (regs->orig_ax >= 0) {
  526. /* Restart the system call - no handlers present */
  527. switch (regs->ax) {
  528. case -ERESTARTNOHAND:
  529. case -ERESTARTSYS:
  530. case -ERESTARTNOINTR:
  531. regs->ax = regs->orig_ax;
  532. regs->ip -= 2;
  533. break;
  534. case -ERESTART_RESTARTBLOCK:
  535. regs->ax = __NR_restart_syscall;
  536. regs->ip -= 2;
  537. break;
  538. }
  539. }
  540. /* if there's no signal to deliver, we just put the saved sigmask
  541. * back */
  542. if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
  543. clear_thread_flag(TIF_RESTORE_SIGMASK);
  544. sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
  545. }
  546. }
  547. /*
  548. * notification of userspace execution resumption
  549. * - triggered by the TIF_WORK_MASK flags
  550. */
  551. __attribute__((regparm(3)))
  552. void do_notify_resume(struct pt_regs *regs, void *_unused,
  553. __u32 thread_info_flags)
  554. {
  555. /* Pending single-step? */
  556. if (thread_info_flags & _TIF_SINGLESTEP) {
  557. regs->flags |= TF_MASK;
  558. clear_thread_flag(TIF_SINGLESTEP);
  559. }
  560. /* deal with pending signal delivery */
  561. if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
  562. do_signal(regs);
  563. if (thread_info_flags & _TIF_HRTICK_RESCHED)
  564. hrtick_resched();
  565. clear_thread_flag(TIF_IRET);
  566. }