signal_64.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*
  2. * arch/sparc64/kernel/signal.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. * Copyright (C) 1995, 2008 David S. Miller (davem@davemloft.net)
  6. * Copyright (C) 1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
  7. * Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
  8. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  9. */
  10. #ifdef CONFIG_COMPAT
  11. #include <linux/compat.h> /* for compat_old_sigset_t */
  12. #endif
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/signal.h>
  16. #include <linux/errno.h>
  17. #include <linux/wait.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/tracehook.h>
  20. #include <linux/unistd.h>
  21. #include <linux/mm.h>
  22. #include <linux/tty.h>
  23. #include <linux/binfmts.h>
  24. #include <linux/bitops.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/ptrace.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/fpumacro.h>
  29. #include <asm/uctx.h>
  30. #include <asm/siginfo.h>
  31. #include <asm/visasm.h>
  32. #include <asm/switch_to.h>
  33. #include <asm/cacheflush.h>
  34. #include "entry.h"
  35. #include "systbls.h"
  36. #include "sigutil.h"
  37. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  38. /* {set, get}context() needed for 64-bit SparcLinux userland. */
  39. asmlinkage void sparc64_set_context(struct pt_regs *regs)
  40. {
  41. struct ucontext __user *ucp = (struct ucontext __user *)
  42. regs->u_regs[UREG_I0];
  43. mc_gregset_t __user *grp;
  44. unsigned long pc, npc, tstate;
  45. unsigned long fp, i7;
  46. unsigned char fenab;
  47. int err;
  48. flush_user_windows();
  49. if (get_thread_wsaved() ||
  50. (((unsigned long)ucp) & (sizeof(unsigned long)-1)) ||
  51. (!__access_ok(ucp, sizeof(*ucp))))
  52. goto do_sigsegv;
  53. grp = &ucp->uc_mcontext.mc_gregs;
  54. err = __get_user(pc, &((*grp)[MC_PC]));
  55. err |= __get_user(npc, &((*grp)[MC_NPC]));
  56. if (err || ((pc | npc) & 3))
  57. goto do_sigsegv;
  58. if (regs->u_regs[UREG_I1]) {
  59. sigset_t set;
  60. if (_NSIG_WORDS == 1) {
  61. if (__get_user(set.sig[0], &ucp->uc_sigmask.sig[0]))
  62. goto do_sigsegv;
  63. } else {
  64. if (__copy_from_user(&set, &ucp->uc_sigmask, sizeof(sigset_t)))
  65. goto do_sigsegv;
  66. }
  67. sigdelsetmask(&set, ~_BLOCKABLE);
  68. set_current_blocked(&set);
  69. }
  70. if (test_thread_flag(TIF_32BIT)) {
  71. pc &= 0xffffffff;
  72. npc &= 0xffffffff;
  73. }
  74. regs->tpc = pc;
  75. regs->tnpc = npc;
  76. err |= __get_user(regs->y, &((*grp)[MC_Y]));
  77. err |= __get_user(tstate, &((*grp)[MC_TSTATE]));
  78. regs->tstate &= ~(TSTATE_ASI | TSTATE_ICC | TSTATE_XCC);
  79. regs->tstate |= (tstate & (TSTATE_ASI | TSTATE_ICC | TSTATE_XCC));
  80. err |= __get_user(regs->u_regs[UREG_G1], (&(*grp)[MC_G1]));
  81. err |= __get_user(regs->u_regs[UREG_G2], (&(*grp)[MC_G2]));
  82. err |= __get_user(regs->u_regs[UREG_G3], (&(*grp)[MC_G3]));
  83. err |= __get_user(regs->u_regs[UREG_G4], (&(*grp)[MC_G4]));
  84. err |= __get_user(regs->u_regs[UREG_G5], (&(*grp)[MC_G5]));
  85. err |= __get_user(regs->u_regs[UREG_G6], (&(*grp)[MC_G6]));
  86. /* Skip %g7 as that's the thread register in userspace. */
  87. err |= __get_user(regs->u_regs[UREG_I0], (&(*grp)[MC_O0]));
  88. err |= __get_user(regs->u_regs[UREG_I1], (&(*grp)[MC_O1]));
  89. err |= __get_user(regs->u_regs[UREG_I2], (&(*grp)[MC_O2]));
  90. err |= __get_user(regs->u_regs[UREG_I3], (&(*grp)[MC_O3]));
  91. err |= __get_user(regs->u_regs[UREG_I4], (&(*grp)[MC_O4]));
  92. err |= __get_user(regs->u_regs[UREG_I5], (&(*grp)[MC_O5]));
  93. err |= __get_user(regs->u_regs[UREG_I6], (&(*grp)[MC_O6]));
  94. err |= __get_user(regs->u_regs[UREG_I7], (&(*grp)[MC_O7]));
  95. err |= __get_user(fp, &(ucp->uc_mcontext.mc_fp));
  96. err |= __get_user(i7, &(ucp->uc_mcontext.mc_i7));
  97. err |= __put_user(fp,
  98. (&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[6])));
  99. err |= __put_user(i7,
  100. (&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[7])));
  101. err |= __get_user(fenab, &(ucp->uc_mcontext.mc_fpregs.mcfpu_enab));
  102. if (fenab) {
  103. unsigned long *fpregs = current_thread_info()->fpregs;
  104. unsigned long fprs;
  105. fprs_write(0);
  106. err |= __get_user(fprs, &(ucp->uc_mcontext.mc_fpregs.mcfpu_fprs));
  107. if (fprs & FPRS_DL)
  108. err |= copy_from_user(fpregs,
  109. &(ucp->uc_mcontext.mc_fpregs.mcfpu_fregs),
  110. (sizeof(unsigned int) * 32));
  111. if (fprs & FPRS_DU)
  112. err |= copy_from_user(fpregs+16,
  113. ((unsigned long __user *)&(ucp->uc_mcontext.mc_fpregs.mcfpu_fregs))+16,
  114. (sizeof(unsigned int) * 32));
  115. err |= __get_user(current_thread_info()->xfsr[0],
  116. &(ucp->uc_mcontext.mc_fpregs.mcfpu_fsr));
  117. err |= __get_user(current_thread_info()->gsr[0],
  118. &(ucp->uc_mcontext.mc_fpregs.mcfpu_gsr));
  119. regs->tstate &= ~TSTATE_PEF;
  120. }
  121. if (err)
  122. goto do_sigsegv;
  123. return;
  124. do_sigsegv:
  125. force_sig(SIGSEGV, current);
  126. }
  127. asmlinkage void sparc64_get_context(struct pt_regs *regs)
  128. {
  129. struct ucontext __user *ucp = (struct ucontext __user *)
  130. regs->u_regs[UREG_I0];
  131. mc_gregset_t __user *grp;
  132. mcontext_t __user *mcp;
  133. unsigned long fp, i7;
  134. unsigned char fenab;
  135. int err;
  136. synchronize_user_stack();
  137. if (get_thread_wsaved() || clear_user(ucp, sizeof(*ucp)))
  138. goto do_sigsegv;
  139. #if 1
  140. fenab = 0; /* IMO get_context is like any other system call, thus modifies FPU state -jj */
  141. #else
  142. fenab = (current_thread_info()->fpsaved[0] & FPRS_FEF);
  143. #endif
  144. mcp = &ucp->uc_mcontext;
  145. grp = &mcp->mc_gregs;
  146. /* Skip over the trap instruction, first. */
  147. if (test_thread_flag(TIF_32BIT)) {
  148. regs->tpc = (regs->tnpc & 0xffffffff);
  149. regs->tnpc = (regs->tnpc + 4) & 0xffffffff;
  150. } else {
  151. regs->tpc = regs->tnpc;
  152. regs->tnpc += 4;
  153. }
  154. err = 0;
  155. if (_NSIG_WORDS == 1)
  156. err |= __put_user(current->blocked.sig[0],
  157. (unsigned long __user *)&ucp->uc_sigmask);
  158. else
  159. err |= __copy_to_user(&ucp->uc_sigmask, &current->blocked,
  160. sizeof(sigset_t));
  161. err |= __put_user(regs->tstate, &((*grp)[MC_TSTATE]));
  162. err |= __put_user(regs->tpc, &((*grp)[MC_PC]));
  163. err |= __put_user(regs->tnpc, &((*grp)[MC_NPC]));
  164. err |= __put_user(regs->y, &((*grp)[MC_Y]));
  165. err |= __put_user(regs->u_regs[UREG_G1], &((*grp)[MC_G1]));
  166. err |= __put_user(regs->u_regs[UREG_G2], &((*grp)[MC_G2]));
  167. err |= __put_user(regs->u_regs[UREG_G3], &((*grp)[MC_G3]));
  168. err |= __put_user(regs->u_regs[UREG_G4], &((*grp)[MC_G4]));
  169. err |= __put_user(regs->u_regs[UREG_G5], &((*grp)[MC_G5]));
  170. err |= __put_user(regs->u_regs[UREG_G6], &((*grp)[MC_G6]));
  171. err |= __put_user(regs->u_regs[UREG_G7], &((*grp)[MC_G7]));
  172. err |= __put_user(regs->u_regs[UREG_I0], &((*grp)[MC_O0]));
  173. err |= __put_user(regs->u_regs[UREG_I1], &((*grp)[MC_O1]));
  174. err |= __put_user(regs->u_regs[UREG_I2], &((*grp)[MC_O2]));
  175. err |= __put_user(regs->u_regs[UREG_I3], &((*grp)[MC_O3]));
  176. err |= __put_user(regs->u_regs[UREG_I4], &((*grp)[MC_O4]));
  177. err |= __put_user(regs->u_regs[UREG_I5], &((*grp)[MC_O5]));
  178. err |= __put_user(regs->u_regs[UREG_I6], &((*grp)[MC_O6]));
  179. err |= __put_user(regs->u_regs[UREG_I7], &((*grp)[MC_O7]));
  180. err |= __get_user(fp,
  181. (&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[6])));
  182. err |= __get_user(i7,
  183. (&(((struct reg_window __user *)(STACK_BIAS+regs->u_regs[UREG_I6]))->ins[7])));
  184. err |= __put_user(fp, &(mcp->mc_fp));
  185. err |= __put_user(i7, &(mcp->mc_i7));
  186. err |= __put_user(fenab, &(mcp->mc_fpregs.mcfpu_enab));
  187. if (fenab) {
  188. unsigned long *fpregs = current_thread_info()->fpregs;
  189. unsigned long fprs;
  190. fprs = current_thread_info()->fpsaved[0];
  191. if (fprs & FPRS_DL)
  192. err |= copy_to_user(&(mcp->mc_fpregs.mcfpu_fregs), fpregs,
  193. (sizeof(unsigned int) * 32));
  194. if (fprs & FPRS_DU)
  195. err |= copy_to_user(
  196. ((unsigned long __user *)&(mcp->mc_fpregs.mcfpu_fregs))+16, fpregs+16,
  197. (sizeof(unsigned int) * 32));
  198. err |= __put_user(current_thread_info()->xfsr[0], &(mcp->mc_fpregs.mcfpu_fsr));
  199. err |= __put_user(current_thread_info()->gsr[0], &(mcp->mc_fpregs.mcfpu_gsr));
  200. err |= __put_user(fprs, &(mcp->mc_fpregs.mcfpu_fprs));
  201. }
  202. if (err)
  203. goto do_sigsegv;
  204. return;
  205. do_sigsegv:
  206. force_sig(SIGSEGV, current);
  207. }
  208. struct rt_signal_frame {
  209. struct sparc_stackf ss;
  210. siginfo_t info;
  211. struct pt_regs regs;
  212. __siginfo_fpu_t __user *fpu_save;
  213. stack_t stack;
  214. sigset_t mask;
  215. __siginfo_rwin_t *rwin_save;
  216. };
  217. static long _sigpause_common(old_sigset_t set)
  218. {
  219. sigset_t blocked;
  220. current->saved_sigmask = current->blocked;
  221. set &= _BLOCKABLE;
  222. siginitset(&blocked, set);
  223. set_current_blocked(&blocked);
  224. current->state = TASK_INTERRUPTIBLE;
  225. schedule();
  226. set_restore_sigmask();
  227. return -ERESTARTNOHAND;
  228. }
  229. asmlinkage long sys_sigpause(unsigned int set)
  230. {
  231. return _sigpause_common(set);
  232. }
  233. asmlinkage long sys_sigsuspend(old_sigset_t set)
  234. {
  235. return _sigpause_common(set);
  236. }
  237. void do_rt_sigreturn(struct pt_regs *regs)
  238. {
  239. struct rt_signal_frame __user *sf;
  240. unsigned long tpc, tnpc, tstate;
  241. __siginfo_fpu_t __user *fpu_save;
  242. __siginfo_rwin_t __user *rwin_save;
  243. sigset_t set;
  244. int err;
  245. /* Always make any pending restarted system calls return -EINTR */
  246. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  247. synchronize_user_stack ();
  248. sf = (struct rt_signal_frame __user *)
  249. (regs->u_regs [UREG_FP] + STACK_BIAS);
  250. /* 1. Make sure we are not getting garbage from the user */
  251. if (((unsigned long) sf) & 3)
  252. goto segv;
  253. err = get_user(tpc, &sf->regs.tpc);
  254. err |= __get_user(tnpc, &sf->regs.tnpc);
  255. if (test_thread_flag(TIF_32BIT)) {
  256. tpc &= 0xffffffff;
  257. tnpc &= 0xffffffff;
  258. }
  259. err |= ((tpc | tnpc) & 3);
  260. /* 2. Restore the state */
  261. err |= __get_user(regs->y, &sf->regs.y);
  262. err |= __get_user(tstate, &sf->regs.tstate);
  263. err |= copy_from_user(regs->u_regs, sf->regs.u_regs, sizeof(regs->u_regs));
  264. /* User can only change condition codes and %asi in %tstate. */
  265. regs->tstate &= ~(TSTATE_ASI | TSTATE_ICC | TSTATE_XCC);
  266. regs->tstate |= (tstate & (TSTATE_ASI | TSTATE_ICC | TSTATE_XCC));
  267. err |= __get_user(fpu_save, &sf->fpu_save);
  268. if (!err && fpu_save)
  269. err |= restore_fpu_state(regs, fpu_save);
  270. err |= __copy_from_user(&set, &sf->mask, sizeof(sigset_t));
  271. if (err || do_sigaltstack(&sf->stack, NULL, (unsigned long)sf) == -EFAULT)
  272. goto segv;
  273. err |= __get_user(rwin_save, &sf->rwin_save);
  274. if (!err && rwin_save) {
  275. if (restore_rwin_state(rwin_save))
  276. goto segv;
  277. }
  278. regs->tpc = tpc;
  279. regs->tnpc = tnpc;
  280. /* Prevent syscall restart. */
  281. pt_regs_clear_syscall(regs);
  282. sigdelsetmask(&set, ~_BLOCKABLE);
  283. set_current_blocked(&set);
  284. return;
  285. segv:
  286. force_sig(SIGSEGV, current);
  287. }
  288. /* Checks if the fp is valid */
  289. static int invalid_frame_pointer(void __user *fp)
  290. {
  291. if (((unsigned long) fp) & 15)
  292. return 1;
  293. return 0;
  294. }
  295. static inline void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, unsigned long framesize)
  296. {
  297. unsigned long sp = regs->u_regs[UREG_FP] + STACK_BIAS;
  298. /*
  299. * If we are on the alternate signal stack and would overflow it, don't.
  300. * Return an always-bogus address instead so we will die with SIGSEGV.
  301. */
  302. if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
  303. return (void __user *) -1L;
  304. /* This is the X/Open sanctioned signal stack switching. */
  305. if (ka->sa.sa_flags & SA_ONSTACK) {
  306. if (sas_ss_flags(sp) == 0)
  307. sp = current->sas_ss_sp + current->sas_ss_size;
  308. }
  309. sp -= framesize;
  310. /* Always align the stack frame. This handles two cases. First,
  311. * sigaltstack need not be mindful of platform specific stack
  312. * alignment. Second, if we took this signal because the stack
  313. * is not aligned properly, we'd like to take the signal cleanly
  314. * and report that.
  315. */
  316. sp &= ~15UL;
  317. return (void __user *) sp;
  318. }
  319. static inline int
  320. setup_rt_frame(struct k_sigaction *ka, struct pt_regs *regs,
  321. int signo, sigset_t *oldset, siginfo_t *info)
  322. {
  323. struct rt_signal_frame __user *sf;
  324. int wsaved, err, sf_size;
  325. void __user *tail;
  326. /* 1. Make sure everything is clean */
  327. synchronize_user_stack();
  328. save_and_clear_fpu();
  329. wsaved = get_thread_wsaved();
  330. sf_size = sizeof(struct rt_signal_frame);
  331. if (current_thread_info()->fpsaved[0] & FPRS_FEF)
  332. sf_size += sizeof(__siginfo_fpu_t);
  333. if (wsaved)
  334. sf_size += sizeof(__siginfo_rwin_t);
  335. sf = (struct rt_signal_frame __user *)
  336. get_sigframe(ka, regs, sf_size);
  337. if (invalid_frame_pointer (sf))
  338. goto sigill;
  339. tail = (sf + 1);
  340. /* 2. Save the current process state */
  341. err = copy_to_user(&sf->regs, regs, sizeof (*regs));
  342. if (current_thread_info()->fpsaved[0] & FPRS_FEF) {
  343. __siginfo_fpu_t __user *fpu_save = tail;
  344. tail += sizeof(__siginfo_fpu_t);
  345. err |= save_fpu_state(regs, fpu_save);
  346. err |= __put_user((u64)fpu_save, &sf->fpu_save);
  347. } else {
  348. err |= __put_user(0, &sf->fpu_save);
  349. }
  350. if (wsaved) {
  351. __siginfo_rwin_t __user *rwin_save = tail;
  352. tail += sizeof(__siginfo_rwin_t);
  353. err |= save_rwin_state(wsaved, rwin_save);
  354. err |= __put_user((u64)rwin_save, &sf->rwin_save);
  355. set_thread_wsaved(0);
  356. } else {
  357. err |= __put_user(0, &sf->rwin_save);
  358. }
  359. /* Setup sigaltstack */
  360. err |= __put_user(current->sas_ss_sp, &sf->stack.ss_sp);
  361. err |= __put_user(sas_ss_flags(regs->u_regs[UREG_FP]), &sf->stack.ss_flags);
  362. err |= __put_user(current->sas_ss_size, &sf->stack.ss_size);
  363. err |= copy_to_user(&sf->mask, oldset, sizeof(sigset_t));
  364. if (!wsaved) {
  365. err |= copy_in_user((u64 __user *)sf,
  366. (u64 __user *)(regs->u_regs[UREG_FP] +
  367. STACK_BIAS),
  368. sizeof(struct reg_window));
  369. } else {
  370. struct reg_window *rp;
  371. rp = &current_thread_info()->reg_window[wsaved - 1];
  372. err |= copy_to_user(sf, rp, sizeof(struct reg_window));
  373. }
  374. if (info)
  375. err |= copy_siginfo_to_user(&sf->info, info);
  376. else {
  377. err |= __put_user(signo, &sf->info.si_signo);
  378. err |= __put_user(SI_NOINFO, &sf->info.si_code);
  379. }
  380. if (err)
  381. goto sigsegv;
  382. /* 3. signal handler back-trampoline and parameters */
  383. regs->u_regs[UREG_FP] = ((unsigned long) sf) - STACK_BIAS;
  384. regs->u_regs[UREG_I0] = signo;
  385. regs->u_regs[UREG_I1] = (unsigned long) &sf->info;
  386. /* The sigcontext is passed in this way because of how it
  387. * is defined in GLIBC's /usr/include/bits/sigcontext.h
  388. * for sparc64. It includes the 128 bytes of siginfo_t.
  389. */
  390. regs->u_regs[UREG_I2] = (unsigned long) &sf->info;
  391. /* 5. signal handler */
  392. regs->tpc = (unsigned long) ka->sa.sa_handler;
  393. regs->tnpc = (regs->tpc + 4);
  394. if (test_thread_flag(TIF_32BIT)) {
  395. regs->tpc &= 0xffffffff;
  396. regs->tnpc &= 0xffffffff;
  397. }
  398. /* 4. return to kernel instructions */
  399. regs->u_regs[UREG_I7] = (unsigned long)ka->ka_restorer;
  400. return 0;
  401. sigill:
  402. do_exit(SIGILL);
  403. return -EINVAL;
  404. sigsegv:
  405. force_sigsegv(signo, current);
  406. return -EFAULT;
  407. }
  408. static inline int handle_signal(unsigned long signr, struct k_sigaction *ka,
  409. siginfo_t *info,
  410. sigset_t *oldset, struct pt_regs *regs)
  411. {
  412. int err;
  413. err = setup_rt_frame(ka, regs, signr, oldset,
  414. (ka->sa.sa_flags & SA_SIGINFO) ? info : NULL);
  415. if (err)
  416. return err;
  417. block_sigmask(ka, signr);
  418. tracehook_signal_handler(signr, info, ka, regs, 0);
  419. return 0;
  420. }
  421. static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
  422. struct sigaction *sa)
  423. {
  424. switch (regs->u_regs[UREG_I0]) {
  425. case ERESTART_RESTARTBLOCK:
  426. case ERESTARTNOHAND:
  427. no_system_call_restart:
  428. regs->u_regs[UREG_I0] = EINTR;
  429. regs->tstate |= (TSTATE_ICARRY|TSTATE_XCARRY);
  430. break;
  431. case ERESTARTSYS:
  432. if (!(sa->sa_flags & SA_RESTART))
  433. goto no_system_call_restart;
  434. /* fallthrough */
  435. case ERESTARTNOINTR:
  436. regs->u_regs[UREG_I0] = orig_i0;
  437. regs->tpc -= 4;
  438. regs->tnpc -= 4;
  439. }
  440. }
  441. /* Note that 'init' is a special process: it doesn't get signals it doesn't
  442. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  443. * mistake.
  444. */
  445. static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
  446. {
  447. struct k_sigaction ka;
  448. int restart_syscall;
  449. sigset_t *oldset;
  450. siginfo_t info;
  451. int signr;
  452. /* It's a lot of work and synchronization to add a new ptrace
  453. * register for GDB to save and restore in order to get
  454. * orig_i0 correct for syscall restarts when debugging.
  455. *
  456. * Although it should be the case that most of the global
  457. * registers are volatile across a system call, glibc already
  458. * depends upon that fact that we preserve them. So we can't
  459. * just use any global register to save away the orig_i0 value.
  460. *
  461. * In particular %g2, %g3, %g4, and %g5 are all assumed to be
  462. * preserved across a system call trap by various pieces of
  463. * code in glibc.
  464. *
  465. * %g7 is used as the "thread register". %g6 is not used in
  466. * any fixed manner. %g6 is used as a scratch register and
  467. * a compiler temporary, but it's value is never used across
  468. * a system call. Therefore %g6 is usable for orig_i0 storage.
  469. */
  470. if (pt_regs_is_syscall(regs) &&
  471. (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY)))
  472. regs->u_regs[UREG_G6] = orig_i0;
  473. if (current_thread_info()->status & TS_RESTORE_SIGMASK)
  474. oldset = &current->saved_sigmask;
  475. else
  476. oldset = &current->blocked;
  477. #ifdef CONFIG_COMPAT
  478. if (test_thread_flag(TIF_32BIT)) {
  479. extern void do_signal32(sigset_t *, struct pt_regs *);
  480. do_signal32(oldset, regs);
  481. return;
  482. }
  483. #endif
  484. signr = get_signal_to_deliver(&info, &ka, regs, NULL);
  485. restart_syscall = 0;
  486. if (pt_regs_is_syscall(regs) &&
  487. (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY))) {
  488. restart_syscall = 1;
  489. orig_i0 = regs->u_regs[UREG_G6];
  490. }
  491. if (signr > 0) {
  492. if (restart_syscall)
  493. syscall_restart(orig_i0, regs, &ka.sa);
  494. if (handle_signal(signr, &ka, &info, oldset, regs) == 0) {
  495. /* A signal was successfully delivered; the saved
  496. * sigmask will have been stored in the signal frame,
  497. * and will be restored by sigreturn, so we can simply
  498. * clear the TS_RESTORE_SIGMASK flag.
  499. */
  500. current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
  501. }
  502. return;
  503. }
  504. if (restart_syscall &&
  505. (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
  506. regs->u_regs[UREG_I0] == ERESTARTSYS ||
  507. regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
  508. /* replay the system call when we are done */
  509. regs->u_regs[UREG_I0] = orig_i0;
  510. regs->tpc -= 4;
  511. regs->tnpc -= 4;
  512. pt_regs_clear_syscall(regs);
  513. }
  514. if (restart_syscall &&
  515. regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
  516. regs->u_regs[UREG_G1] = __NR_restart_syscall;
  517. regs->tpc -= 4;
  518. regs->tnpc -= 4;
  519. pt_regs_clear_syscall(regs);
  520. }
  521. /* If there's no signal to deliver, we just put the saved sigmask
  522. * back
  523. */
  524. if (current_thread_info()->status & TS_RESTORE_SIGMASK) {
  525. current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
  526. set_current_blocked(&current->saved_sigmask);
  527. }
  528. }
  529. void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags)
  530. {
  531. if (thread_info_flags & _TIF_SIGPENDING)
  532. do_signal(regs, orig_i0);
  533. if (thread_info_flags & _TIF_NOTIFY_RESUME) {
  534. clear_thread_flag(TIF_NOTIFY_RESUME);
  535. tracehook_notify_resume(regs);
  536. if (current->replacement_session_keyring)
  537. key_replace_session_keyring();
  538. }
  539. }