signal.c 17 KB

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