signal.c 17 KB

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