signal_32.c 17 KB

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