signal.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. /*
  2. * Architecture-specific signal handling support.
  3. *
  4. * Copyright (C) 1999-2004 Hewlett-Packard Co
  5. * David Mosberger-Tang <davidm@hpl.hp.com>
  6. *
  7. * Derived from i386 and Alpha versions.
  8. */
  9. #include <linux/errno.h>
  10. #include <linux/kernel.h>
  11. #include <linux/mm.h>
  12. #include <linux/ptrace.h>
  13. #include <linux/tracehook.h>
  14. #include <linux/sched.h>
  15. #include <linux/signal.h>
  16. #include <linux/smp.h>
  17. #include <linux/stddef.h>
  18. #include <linux/tty.h>
  19. #include <linux/binfmts.h>
  20. #include <linux/unistd.h>
  21. #include <linux/wait.h>
  22. #include <asm/ia32.h>
  23. #include <asm/intrinsics.h>
  24. #include <asm/uaccess.h>
  25. #include <asm/rse.h>
  26. #include <asm/sigcontext.h>
  27. #include "sigframe.h"
  28. #define DEBUG_SIG 0
  29. #define STACK_ALIGN 16 /* minimal alignment for stack pointer */
  30. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  31. #if _NSIG_WORDS > 1
  32. # define PUT_SIGSET(k,u) __copy_to_user((u)->sig, (k)->sig, sizeof(sigset_t))
  33. # define GET_SIGSET(k,u) __copy_from_user((k)->sig, (u)->sig, sizeof(sigset_t))
  34. #else
  35. # define PUT_SIGSET(k,u) __put_user((k)->sig[0], &(u)->sig[0])
  36. # define GET_SIGSET(k,u) __get_user((k)->sig[0], &(u)->sig[0])
  37. #endif
  38. asmlinkage long
  39. sys_sigaltstack (const stack_t __user *uss, stack_t __user *uoss, long arg2,
  40. long arg3, long arg4, long arg5, long arg6, long arg7,
  41. struct pt_regs regs)
  42. {
  43. return do_sigaltstack(uss, uoss, regs.r12);
  44. }
  45. static long
  46. restore_sigcontext (struct sigcontext __user *sc, struct sigscratch *scr)
  47. {
  48. unsigned long ip, flags, nat, um, cfm, rsc;
  49. long err;
  50. /* Always make any pending restarted system calls return -EINTR */
  51. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  52. /* restore scratch that always needs gets updated during signal delivery: */
  53. err = __get_user(flags, &sc->sc_flags);
  54. err |= __get_user(nat, &sc->sc_nat);
  55. err |= __get_user(ip, &sc->sc_ip); /* instruction pointer */
  56. err |= __get_user(cfm, &sc->sc_cfm);
  57. err |= __get_user(um, &sc->sc_um); /* user mask */
  58. err |= __get_user(rsc, &sc->sc_ar_rsc);
  59. err |= __get_user(scr->pt.ar_unat, &sc->sc_ar_unat);
  60. err |= __get_user(scr->pt.ar_fpsr, &sc->sc_ar_fpsr);
  61. err |= __get_user(scr->pt.ar_pfs, &sc->sc_ar_pfs);
  62. err |= __get_user(scr->pt.pr, &sc->sc_pr); /* predicates */
  63. err |= __get_user(scr->pt.b0, &sc->sc_br[0]); /* b0 (rp) */
  64. err |= __get_user(scr->pt.b6, &sc->sc_br[6]); /* b6 */
  65. err |= __copy_from_user(&scr->pt.r1, &sc->sc_gr[1], 8); /* r1 */
  66. err |= __copy_from_user(&scr->pt.r8, &sc->sc_gr[8], 4*8); /* r8-r11 */
  67. err |= __copy_from_user(&scr->pt.r12, &sc->sc_gr[12], 2*8); /* r12-r13 */
  68. err |= __copy_from_user(&scr->pt.r15, &sc->sc_gr[15], 8); /* r15 */
  69. scr->pt.cr_ifs = cfm | (1UL << 63);
  70. scr->pt.ar_rsc = rsc | (3 << 2); /* force PL3 */
  71. /* establish new instruction pointer: */
  72. scr->pt.cr_iip = ip & ~0x3UL;
  73. ia64_psr(&scr->pt)->ri = ip & 0x3;
  74. scr->pt.cr_ipsr = (scr->pt.cr_ipsr & ~IA64_PSR_UM) | (um & IA64_PSR_UM);
  75. scr->scratch_unat = ia64_put_scratch_nat_bits(&scr->pt, nat);
  76. if (!(flags & IA64_SC_FLAG_IN_SYSCALL)) {
  77. /* Restore most scratch-state only when not in syscall. */
  78. err |= __get_user(scr->pt.ar_ccv, &sc->sc_ar_ccv); /* ar.ccv */
  79. err |= __get_user(scr->pt.b7, &sc->sc_br[7]); /* b7 */
  80. err |= __get_user(scr->pt.r14, &sc->sc_gr[14]); /* r14 */
  81. err |= __copy_from_user(&scr->pt.ar_csd, &sc->sc_ar25, 2*8); /* ar.csd & ar.ssd */
  82. err |= __copy_from_user(&scr->pt.r2, &sc->sc_gr[2], 2*8); /* r2-r3 */
  83. err |= __copy_from_user(&scr->pt.r16, &sc->sc_gr[16], 16*8); /* r16-r31 */
  84. }
  85. if ((flags & IA64_SC_FLAG_FPH_VALID) != 0) {
  86. struct ia64_psr *psr = ia64_psr(&scr->pt);
  87. err |= __copy_from_user(current->thread.fph, &sc->sc_fr[32], 96*16);
  88. psr->mfh = 0; /* drop signal handler's fph contents... */
  89. preempt_disable();
  90. if (psr->dfh)
  91. ia64_drop_fpu(current);
  92. else {
  93. /* We already own the local fph, otherwise psr->dfh wouldn't be 0. */
  94. __ia64_load_fpu(current->thread.fph);
  95. ia64_set_local_fpu_owner(current);
  96. }
  97. preempt_enable();
  98. }
  99. return err;
  100. }
  101. int
  102. copy_siginfo_to_user (siginfo_t __user *to, siginfo_t *from)
  103. {
  104. if (!access_ok(VERIFY_WRITE, to, sizeof(siginfo_t)))
  105. return -EFAULT;
  106. if (from->si_code < 0) {
  107. if (__copy_to_user(to, from, sizeof(siginfo_t)))
  108. return -EFAULT;
  109. return 0;
  110. } else {
  111. int err;
  112. /*
  113. * If you change siginfo_t structure, please be sure this code is fixed
  114. * accordingly. It should never copy any pad contained in the structure
  115. * to avoid security leaks, but must copy the generic 3 ints plus the
  116. * relevant union member.
  117. */
  118. err = __put_user(from->si_signo, &to->si_signo);
  119. err |= __put_user(from->si_errno, &to->si_errno);
  120. err |= __put_user((short)from->si_code, &to->si_code);
  121. switch (from->si_code >> 16) {
  122. case __SI_FAULT >> 16:
  123. err |= __put_user(from->si_flags, &to->si_flags);
  124. err |= __put_user(from->si_isr, &to->si_isr);
  125. case __SI_POLL >> 16:
  126. err |= __put_user(from->si_addr, &to->si_addr);
  127. err |= __put_user(from->si_imm, &to->si_imm);
  128. break;
  129. case __SI_TIMER >> 16:
  130. err |= __put_user(from->si_tid, &to->si_tid);
  131. err |= __put_user(from->si_overrun, &to->si_overrun);
  132. err |= __put_user(from->si_ptr, &to->si_ptr);
  133. break;
  134. case __SI_RT >> 16: /* Not generated by the kernel as of now. */
  135. case __SI_MESGQ >> 16:
  136. err |= __put_user(from->si_uid, &to->si_uid);
  137. err |= __put_user(from->si_pid, &to->si_pid);
  138. err |= __put_user(from->si_ptr, &to->si_ptr);
  139. break;
  140. case __SI_CHLD >> 16:
  141. err |= __put_user(from->si_utime, &to->si_utime);
  142. err |= __put_user(from->si_stime, &to->si_stime);
  143. err |= __put_user(from->si_status, &to->si_status);
  144. default:
  145. err |= __put_user(from->si_uid, &to->si_uid);
  146. err |= __put_user(from->si_pid, &to->si_pid);
  147. break;
  148. }
  149. return err;
  150. }
  151. }
  152. long
  153. ia64_rt_sigreturn (struct sigscratch *scr)
  154. {
  155. extern char ia64_strace_leave_kernel, ia64_leave_kernel;
  156. struct sigcontext __user *sc;
  157. struct siginfo si;
  158. sigset_t set;
  159. long retval;
  160. sc = &((struct sigframe __user *) (scr->pt.r12 + 16))->sc;
  161. /*
  162. * When we return to the previously executing context, r8 and r10 have already
  163. * been setup the way we want them. Indeed, if the signal wasn't delivered while
  164. * in a system call, we must not touch r8 or r10 as otherwise user-level state
  165. * could be corrupted.
  166. */
  167. retval = (long) &ia64_leave_kernel;
  168. if (test_thread_flag(TIF_SYSCALL_TRACE)
  169. || test_thread_flag(TIF_SYSCALL_AUDIT))
  170. /*
  171. * strace expects to be notified after sigreturn returns even though the
  172. * context to which we return may not be in the middle of a syscall.
  173. * Thus, the return-value that strace displays for sigreturn is
  174. * meaningless.
  175. */
  176. retval = (long) &ia64_strace_leave_kernel;
  177. if (!access_ok(VERIFY_READ, sc, sizeof(*sc)))
  178. goto give_sigsegv;
  179. if (GET_SIGSET(&set, &sc->sc_mask))
  180. goto give_sigsegv;
  181. sigdelsetmask(&set, ~_BLOCKABLE);
  182. spin_lock_irq(&current->sighand->siglock);
  183. {
  184. current->blocked = set;
  185. recalc_sigpending();
  186. }
  187. spin_unlock_irq(&current->sighand->siglock);
  188. if (restore_sigcontext(sc, scr))
  189. goto give_sigsegv;
  190. #if DEBUG_SIG
  191. printk("SIG return (%s:%d): sp=%lx ip=%lx\n",
  192. current->comm, current->pid, scr->pt.r12, scr->pt.cr_iip);
  193. #endif
  194. /*
  195. * It is more difficult to avoid calling this function than to
  196. * call it and ignore errors.
  197. */
  198. do_sigaltstack(&sc->sc_stack, NULL, scr->pt.r12);
  199. return retval;
  200. give_sigsegv:
  201. si.si_signo = SIGSEGV;
  202. si.si_errno = 0;
  203. si.si_code = SI_KERNEL;
  204. si.si_pid = task_pid_vnr(current);
  205. si.si_uid = current_uid();
  206. si.si_addr = sc;
  207. force_sig_info(SIGSEGV, &si, current);
  208. return retval;
  209. }
  210. /*
  211. * This does just the minimum required setup of sigcontext.
  212. * Specifically, it only installs data that is either not knowable at
  213. * the user-level or that gets modified before execution in the
  214. * trampoline starts. Everything else is done at the user-level.
  215. */
  216. static long
  217. setup_sigcontext (struct sigcontext __user *sc, sigset_t *mask, struct sigscratch *scr)
  218. {
  219. unsigned long flags = 0, ifs, cfm, nat;
  220. long err = 0;
  221. ifs = scr->pt.cr_ifs;
  222. if (on_sig_stack((unsigned long) sc))
  223. flags |= IA64_SC_FLAG_ONSTACK;
  224. if ((ifs & (1UL << 63)) == 0)
  225. /* if cr_ifs doesn't have the valid bit set, we got here through a syscall */
  226. flags |= IA64_SC_FLAG_IN_SYSCALL;
  227. cfm = ifs & ((1UL << 38) - 1);
  228. ia64_flush_fph(current);
  229. if ((current->thread.flags & IA64_THREAD_FPH_VALID)) {
  230. flags |= IA64_SC_FLAG_FPH_VALID;
  231. err = __copy_to_user(&sc->sc_fr[32], current->thread.fph, 96*16);
  232. }
  233. nat = ia64_get_scratch_nat_bits(&scr->pt, scr->scratch_unat);
  234. err |= __put_user(flags, &sc->sc_flags);
  235. err |= __put_user(nat, &sc->sc_nat);
  236. err |= PUT_SIGSET(mask, &sc->sc_mask);
  237. err |= __put_user(cfm, &sc->sc_cfm);
  238. err |= __put_user(scr->pt.cr_ipsr & IA64_PSR_UM, &sc->sc_um);
  239. err |= __put_user(scr->pt.ar_rsc, &sc->sc_ar_rsc);
  240. err |= __put_user(scr->pt.ar_unat, &sc->sc_ar_unat); /* ar.unat */
  241. err |= __put_user(scr->pt.ar_fpsr, &sc->sc_ar_fpsr); /* ar.fpsr */
  242. err |= __put_user(scr->pt.ar_pfs, &sc->sc_ar_pfs);
  243. err |= __put_user(scr->pt.pr, &sc->sc_pr); /* predicates */
  244. err |= __put_user(scr->pt.b0, &sc->sc_br[0]); /* b0 (rp) */
  245. err |= __put_user(scr->pt.b6, &sc->sc_br[6]); /* b6 */
  246. err |= __copy_to_user(&sc->sc_gr[1], &scr->pt.r1, 8); /* r1 */
  247. err |= __copy_to_user(&sc->sc_gr[8], &scr->pt.r8, 4*8); /* r8-r11 */
  248. err |= __copy_to_user(&sc->sc_gr[12], &scr->pt.r12, 2*8); /* r12-r13 */
  249. err |= __copy_to_user(&sc->sc_gr[15], &scr->pt.r15, 8); /* r15 */
  250. err |= __put_user(scr->pt.cr_iip + ia64_psr(&scr->pt)->ri, &sc->sc_ip);
  251. if (!(flags & IA64_SC_FLAG_IN_SYSCALL)) {
  252. /* Copy scratch regs to sigcontext if the signal didn't interrupt a syscall. */
  253. err |= __put_user(scr->pt.ar_ccv, &sc->sc_ar_ccv); /* ar.ccv */
  254. err |= __put_user(scr->pt.b7, &sc->sc_br[7]); /* b7 */
  255. err |= __put_user(scr->pt.r14, &sc->sc_gr[14]); /* r14 */
  256. err |= __copy_to_user(&sc->sc_ar25, &scr->pt.ar_csd, 2*8); /* ar.csd & ar.ssd */
  257. err |= __copy_to_user(&sc->sc_gr[2], &scr->pt.r2, 2*8); /* r2-r3 */
  258. err |= __copy_to_user(&sc->sc_gr[16], &scr->pt.r16, 16*8); /* r16-r31 */
  259. }
  260. return err;
  261. }
  262. /*
  263. * Check whether the register-backing store is already on the signal stack.
  264. */
  265. static inline int
  266. rbs_on_sig_stack (unsigned long bsp)
  267. {
  268. return (bsp - current->sas_ss_sp < current->sas_ss_size);
  269. }
  270. static long
  271. force_sigsegv_info (int sig, void __user *addr)
  272. {
  273. unsigned long flags;
  274. struct siginfo si;
  275. if (sig == SIGSEGV) {
  276. /*
  277. * Acquiring siglock around the sa_handler-update is almost
  278. * certainly overkill, but this isn't a
  279. * performance-critical path and I'd rather play it safe
  280. * here than having to debug a nasty race if and when
  281. * something changes in kernel/signal.c that would make it
  282. * no longer safe to modify sa_handler without holding the
  283. * lock.
  284. */
  285. spin_lock_irqsave(&current->sighand->siglock, flags);
  286. current->sighand->action[sig - 1].sa.sa_handler = SIG_DFL;
  287. spin_unlock_irqrestore(&current->sighand->siglock, flags);
  288. }
  289. si.si_signo = SIGSEGV;
  290. si.si_errno = 0;
  291. si.si_code = SI_KERNEL;
  292. si.si_pid = task_pid_vnr(current);
  293. si.si_uid = current_uid();
  294. si.si_addr = addr;
  295. force_sig_info(SIGSEGV, &si, current);
  296. return 0;
  297. }
  298. static long
  299. setup_frame (int sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *set,
  300. struct sigscratch *scr)
  301. {
  302. extern char __kernel_sigtramp[];
  303. unsigned long tramp_addr, new_rbs = 0, new_sp;
  304. struct sigframe __user *frame;
  305. long err;
  306. new_sp = scr->pt.r12;
  307. tramp_addr = (unsigned long) __kernel_sigtramp;
  308. if (ka->sa.sa_flags & SA_ONSTACK) {
  309. int onstack = sas_ss_flags(new_sp);
  310. if (onstack == 0) {
  311. new_sp = current->sas_ss_sp + current->sas_ss_size;
  312. /*
  313. * We need to check for the register stack being on the
  314. * signal stack separately, because it's switched
  315. * separately (memory stack is switched in the kernel,
  316. * register stack is switched in the signal trampoline).
  317. */
  318. if (!rbs_on_sig_stack(scr->pt.ar_bspstore))
  319. new_rbs = ALIGN(current->sas_ss_sp,
  320. sizeof(long));
  321. } else if (onstack == SS_ONSTACK) {
  322. unsigned long check_sp;
  323. /*
  324. * If we are on the alternate signal stack and would
  325. * overflow it, don't. Return an always-bogus address
  326. * instead so we will die with SIGSEGV.
  327. */
  328. check_sp = (new_sp - sizeof(*frame)) & -STACK_ALIGN;
  329. if (!likely(on_sig_stack(check_sp)))
  330. return force_sigsegv_info(sig, (void __user *)
  331. check_sp);
  332. }
  333. }
  334. frame = (void __user *) ((new_sp - sizeof(*frame)) & -STACK_ALIGN);
  335. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  336. return force_sigsegv_info(sig, frame);
  337. err = __put_user(sig, &frame->arg0);
  338. err |= __put_user(&frame->info, &frame->arg1);
  339. err |= __put_user(&frame->sc, &frame->arg2);
  340. err |= __put_user(new_rbs, &frame->sc.sc_rbs_base);
  341. err |= __put_user(0, &frame->sc.sc_loadrs); /* initialize to zero */
  342. err |= __put_user(ka->sa.sa_handler, &frame->handler);
  343. err |= copy_siginfo_to_user(&frame->info, info);
  344. err |= __put_user(current->sas_ss_sp, &frame->sc.sc_stack.ss_sp);
  345. err |= __put_user(current->sas_ss_size, &frame->sc.sc_stack.ss_size);
  346. err |= __put_user(sas_ss_flags(scr->pt.r12), &frame->sc.sc_stack.ss_flags);
  347. err |= setup_sigcontext(&frame->sc, set, scr);
  348. if (unlikely(err))
  349. return force_sigsegv_info(sig, frame);
  350. scr->pt.r12 = (unsigned long) frame - 16; /* new stack pointer */
  351. scr->pt.ar_fpsr = FPSR_DEFAULT; /* reset fpsr for signal handler */
  352. scr->pt.cr_iip = tramp_addr;
  353. ia64_psr(&scr->pt)->ri = 0; /* start executing in first slot */
  354. ia64_psr(&scr->pt)->be = 0; /* force little-endian byte-order */
  355. /*
  356. * Force the interruption function mask to zero. This has no effect when a
  357. * system-call got interrupted by a signal (since, in that case, scr->pt_cr_ifs is
  358. * ignored), but it has the desirable effect of making it possible to deliver a
  359. * signal with an incomplete register frame (which happens when a mandatory RSE
  360. * load faults). Furthermore, it has no negative effect on the getting the user's
  361. * dirty partition preserved, because that's governed by scr->pt.loadrs.
  362. */
  363. scr->pt.cr_ifs = (1UL << 63);
  364. /*
  365. * Note: this affects only the NaT bits of the scratch regs (the ones saved in
  366. * pt_regs), which is exactly what we want.
  367. */
  368. scr->scratch_unat = 0; /* ensure NaT bits of r12 is clear */
  369. #if DEBUG_SIG
  370. printk("SIG deliver (%s:%d): sig=%d sp=%lx ip=%lx handler=%p\n",
  371. current->comm, current->pid, sig, scr->pt.r12, frame->sc.sc_ip, frame->handler);
  372. #endif
  373. return 1;
  374. }
  375. static long
  376. handle_signal (unsigned long sig, struct k_sigaction *ka, siginfo_t *info, sigset_t *oldset,
  377. struct sigscratch *scr)
  378. {
  379. if (IS_IA32_PROCESS(&scr->pt)) {
  380. /* send signal to IA-32 process */
  381. if (!ia32_setup_frame1(sig, ka, info, oldset, &scr->pt))
  382. return 0;
  383. } else
  384. /* send signal to IA-64 process */
  385. if (!setup_frame(sig, ka, info, oldset, scr))
  386. return 0;
  387. spin_lock_irq(&current->sighand->siglock);
  388. sigorsets(&current->blocked, &current->blocked, &ka->sa.sa_mask);
  389. if (!(ka->sa.sa_flags & SA_NODEFER))
  390. sigaddset(&current->blocked, sig);
  391. recalc_sigpending();
  392. spin_unlock_irq(&current->sighand->siglock);
  393. /*
  394. * Let tracing know that we've done the handler setup.
  395. */
  396. tracehook_signal_handler(sig, info, ka, &scr->pt,
  397. test_thread_flag(TIF_SINGLESTEP));
  398. return 1;
  399. }
  400. /*
  401. * Note that `init' is a special process: it doesn't get signals it doesn't want to
  402. * handle. Thus you cannot kill init even with a SIGKILL even by mistake.
  403. */
  404. void
  405. ia64_do_signal (struct sigscratch *scr, long in_syscall)
  406. {
  407. struct k_sigaction ka;
  408. sigset_t *oldset;
  409. siginfo_t info;
  410. long restart = in_syscall;
  411. long errno = scr->pt.r8;
  412. # define ERR_CODE(c) (IS_IA32_PROCESS(&scr->pt) ? -(c) : (c))
  413. /*
  414. * In the ia64_leave_kernel code path, we want the common case to go fast, which
  415. * is why we may in certain cases get here from kernel mode. Just return without
  416. * doing anything if so.
  417. */
  418. if (!user_mode(&scr->pt))
  419. return;
  420. if (current_thread_info()->status & TS_RESTORE_SIGMASK)
  421. oldset = &current->saved_sigmask;
  422. else
  423. oldset = &current->blocked;
  424. /*
  425. * This only loops in the rare cases of handle_signal() failing, in which case we
  426. * need to push through a forced SIGSEGV.
  427. */
  428. while (1) {
  429. int signr = get_signal_to_deliver(&info, &ka, &scr->pt, NULL);
  430. /*
  431. * get_signal_to_deliver() may have run a debugger (via notify_parent())
  432. * and the debugger may have modified the state (e.g., to arrange for an
  433. * inferior call), thus it's important to check for restarting _after_
  434. * get_signal_to_deliver().
  435. */
  436. if (IS_IA32_PROCESS(&scr->pt)) {
  437. if (in_syscall) {
  438. if (errno >= 0)
  439. restart = 0;
  440. else
  441. errno = -errno;
  442. }
  443. } else if ((long) scr->pt.r10 != -1)
  444. /*
  445. * A system calls has to be restarted only if one of the error codes
  446. * ERESTARTNOHAND, ERESTARTSYS, or ERESTARTNOINTR is returned. If r10
  447. * isn't -1 then r8 doesn't hold an error code and we don't need to
  448. * restart the syscall, so we can clear the "restart" flag here.
  449. */
  450. restart = 0;
  451. if (signr <= 0)
  452. break;
  453. if (unlikely(restart)) {
  454. switch (errno) {
  455. case ERESTART_RESTARTBLOCK:
  456. case ERESTARTNOHAND:
  457. scr->pt.r8 = ERR_CODE(EINTR);
  458. /* note: scr->pt.r10 is already -1 */
  459. break;
  460. case ERESTARTSYS:
  461. if ((ka.sa.sa_flags & SA_RESTART) == 0) {
  462. scr->pt.r8 = ERR_CODE(EINTR);
  463. /* note: scr->pt.r10 is already -1 */
  464. break;
  465. }
  466. case ERESTARTNOINTR:
  467. if (IS_IA32_PROCESS(&scr->pt)) {
  468. scr->pt.r8 = scr->pt.r1;
  469. scr->pt.cr_iip -= 2;
  470. } else
  471. ia64_decrement_ip(&scr->pt);
  472. restart = 0; /* don't restart twice if handle_signal() fails... */
  473. }
  474. }
  475. /*
  476. * Whee! Actually deliver the signal. If the delivery failed, we need to
  477. * continue to iterate in this loop so we can deliver the SIGSEGV...
  478. */
  479. if (handle_signal(signr, &ka, &info, oldset, scr)) {
  480. /*
  481. * A signal was successfully delivered; the saved
  482. * sigmask will have been stored in the signal frame,
  483. * and will be restored by sigreturn, so we can simply
  484. * clear the TS_RESTORE_SIGMASK flag.
  485. */
  486. current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
  487. return;
  488. }
  489. }
  490. /* Did we come from a system call? */
  491. if (restart) {
  492. /* Restart the system call - no handlers present */
  493. if (errno == ERESTARTNOHAND || errno == ERESTARTSYS || errno == ERESTARTNOINTR
  494. || errno == ERESTART_RESTARTBLOCK)
  495. {
  496. if (IS_IA32_PROCESS(&scr->pt)) {
  497. scr->pt.r8 = scr->pt.r1;
  498. scr->pt.cr_iip -= 2;
  499. if (errno == ERESTART_RESTARTBLOCK)
  500. scr->pt.r8 = 0; /* x86 version of __NR_restart_syscall */
  501. } else {
  502. /*
  503. * Note: the syscall number is in r15 which is saved in
  504. * pt_regs so all we need to do here is adjust ip so that
  505. * the "break" instruction gets re-executed.
  506. */
  507. ia64_decrement_ip(&scr->pt);
  508. if (errno == ERESTART_RESTARTBLOCK)
  509. scr->pt.r15 = __NR_restart_syscall;
  510. }
  511. }
  512. }
  513. /* if there's no signal to deliver, we just put the saved sigmask
  514. * back */
  515. if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
  516. current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
  517. sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
  518. }
  519. }