signal.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /*
  2. * linux/arch/parisc/kernel/signal.c: Architecture-specific signal
  3. * handling support.
  4. *
  5. * Copyright (C) 2000 David Huggins-Daines <dhd@debian.org>
  6. * Copyright (C) 2000 Linuxcare, Inc.
  7. *
  8. * Based on the ia64, i386, and alpha versions.
  9. *
  10. * Like the IA-64, we are a recent enough port (we are *starting*
  11. * with glibc2.2) that we do not need to support the old non-realtime
  12. * Linux signals. Therefore we don't.
  13. */
  14. #include <linux/sched.h>
  15. #include <linux/mm.h>
  16. #include <linux/smp.h>
  17. #include <linux/kernel.h>
  18. #include <linux/signal.h>
  19. #include <linux/errno.h>
  20. #include <linux/wait.h>
  21. #include <linux/ptrace.h>
  22. #include <linux/tracehook.h>
  23. #include <linux/unistd.h>
  24. #include <linux/stddef.h>
  25. #include <linux/compat.h>
  26. #include <linux/elf.h>
  27. #include <asm/ucontext.h>
  28. #include <asm/rt_sigframe.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/pgalloc.h>
  31. #include <asm/cacheflush.h>
  32. #include <asm/asm-offsets.h>
  33. #ifdef CONFIG_COMPAT
  34. #include "signal32.h"
  35. #endif
  36. #define DEBUG_SIG 0
  37. #define DEBUG_SIG_LEVEL 2
  38. #if DEBUG_SIG
  39. #define DBG(LEVEL, ...) \
  40. ((DEBUG_SIG_LEVEL >= LEVEL) \
  41. ? printk(__VA_ARGS__) : (void) 0)
  42. #else
  43. #define DBG(LEVEL, ...)
  44. #endif
  45. /* gcc will complain if a pointer is cast to an integer of different
  46. * size. If you really need to do this (and we do for an ELF32 user
  47. * application in an ELF64 kernel) then you have to do a cast to an
  48. * integer of the same size first. The A() macro accomplishes
  49. * this. */
  50. #define A(__x) ((unsigned long)(__x))
  51. /*
  52. * Do a signal return - restore sigcontext.
  53. */
  54. /* Trampoline for calling rt_sigreturn() */
  55. #define INSN_LDI_R25_0 0x34190000 /* ldi 0,%r25 (in_syscall=0) */
  56. #define INSN_LDI_R25_1 0x34190002 /* ldi 1,%r25 (in_syscall=1) */
  57. #define INSN_LDI_R20 0x3414015a /* ldi __NR_rt_sigreturn,%r20 */
  58. #define INSN_BLE_SR2_R0 0xe4008200 /* be,l 0x100(%sr2,%r0),%sr0,%r31 */
  59. #define INSN_NOP 0x08000240 /* nop */
  60. /* For debugging */
  61. #define INSN_DIE_HORRIBLY 0x68000ccc /* stw %r0,0x666(%sr0,%r0) */
  62. static long
  63. restore_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs)
  64. {
  65. long err = 0;
  66. err |= __copy_from_user(regs->gr, sc->sc_gr, sizeof(regs->gr));
  67. err |= __copy_from_user(regs->fr, sc->sc_fr, sizeof(regs->fr));
  68. err |= __copy_from_user(regs->iaoq, sc->sc_iaoq, sizeof(regs->iaoq));
  69. err |= __copy_from_user(regs->iasq, sc->sc_iasq, sizeof(regs->iasq));
  70. err |= __get_user(regs->sar, &sc->sc_sar);
  71. DBG(2,"restore_sigcontext: iaoq is %#lx / %#lx\n",
  72. regs->iaoq[0],regs->iaoq[1]);
  73. DBG(2,"restore_sigcontext: r28 is %ld\n", regs->gr[28]);
  74. return err;
  75. }
  76. void
  77. sys_rt_sigreturn(struct pt_regs *regs, int in_syscall)
  78. {
  79. struct rt_sigframe __user *frame;
  80. sigset_t set;
  81. unsigned long usp = (regs->gr[30] & ~(0x01UL));
  82. unsigned long sigframe_size = PARISC_RT_SIGFRAME_SIZE;
  83. #ifdef CONFIG_64BIT
  84. compat_sigset_t compat_set;
  85. struct compat_rt_sigframe __user * compat_frame;
  86. if (is_compat_task())
  87. sigframe_size = PARISC_RT_SIGFRAME_SIZE32;
  88. #endif
  89. current->restart_block.fn = do_no_restart_syscall;
  90. /* Unwind the user stack to get the rt_sigframe structure. */
  91. frame = (struct rt_sigframe __user *)
  92. (usp - sigframe_size);
  93. DBG(2,"sys_rt_sigreturn: frame is %p\n", frame);
  94. regs->orig_r28 = 1; /* no restarts for sigreturn */
  95. #ifdef CONFIG_64BIT
  96. compat_frame = (struct compat_rt_sigframe __user *)frame;
  97. if (is_compat_task()) {
  98. DBG(2,"sys_rt_sigreturn: ELF32 process.\n");
  99. if (__copy_from_user(&compat_set, &compat_frame->uc.uc_sigmask, sizeof(compat_set)))
  100. goto give_sigsegv;
  101. sigset_32to64(&set,&compat_set);
  102. } else
  103. #endif
  104. {
  105. if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
  106. goto give_sigsegv;
  107. }
  108. set_current_blocked(&set);
  109. /* Good thing we saved the old gr[30], eh? */
  110. #ifdef CONFIG_64BIT
  111. if (is_compat_task()) {
  112. DBG(1,"sys_rt_sigreturn: compat_frame->uc.uc_mcontext 0x%p\n",
  113. &compat_frame->uc.uc_mcontext);
  114. // FIXME: Load upper half from register file
  115. if (restore_sigcontext32(&compat_frame->uc.uc_mcontext,
  116. &compat_frame->regs, regs))
  117. goto give_sigsegv;
  118. DBG(1,"sys_rt_sigreturn: usp %#08lx stack 0x%p\n",
  119. usp, &compat_frame->uc.uc_stack);
  120. if (compat_restore_altstack(&compat_frame->uc.uc_stack))
  121. goto give_sigsegv;
  122. } else
  123. #endif
  124. {
  125. DBG(1,"sys_rt_sigreturn: frame->uc.uc_mcontext 0x%p\n",
  126. &frame->uc.uc_mcontext);
  127. if (restore_sigcontext(&frame->uc.uc_mcontext, regs))
  128. goto give_sigsegv;
  129. DBG(1,"sys_rt_sigreturn: usp %#08lx stack 0x%p\n",
  130. usp, &frame->uc.uc_stack);
  131. if (restore_altstack(&frame->uc.uc_stack))
  132. goto give_sigsegv;
  133. }
  134. /* If we are on the syscall path IAOQ will not be restored, and
  135. * if we are on the interrupt path we must not corrupt gr31.
  136. */
  137. if (in_syscall)
  138. regs->gr[31] = regs->iaoq[0];
  139. #if DEBUG_SIG
  140. DBG(1,"sys_rt_sigreturn: returning to %#lx, DUMPING REGS:\n", regs->iaoq[0]);
  141. show_regs(regs);
  142. #endif
  143. return;
  144. give_sigsegv:
  145. DBG(1,"sys_rt_sigreturn: Sending SIGSEGV\n");
  146. force_sig(SIGSEGV, current);
  147. return;
  148. }
  149. /*
  150. * Set up a signal frame.
  151. */
  152. static inline void __user *
  153. get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
  154. {
  155. /*FIXME: ELF32 vs. ELF64 has different frame_size, but since we
  156. don't use the parameter it doesn't matter */
  157. DBG(1,"get_sigframe: ka = %#lx, sp = %#lx, frame_size = %#lx\n",
  158. (unsigned long)ka, sp, frame_size);
  159. /* Align alternate stack and reserve 64 bytes for the signal
  160. handler's frame marker. */
  161. if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
  162. sp = (current->sas_ss_sp + 0x7f) & ~0x3f; /* Stacks grow up! */
  163. DBG(1,"get_sigframe: Returning sp = %#lx\n", (unsigned long)sp);
  164. return (void __user *) sp; /* Stacks grow up. Fun. */
  165. }
  166. static long
  167. setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs, int in_syscall)
  168. {
  169. unsigned long flags = 0;
  170. long err = 0;
  171. if (on_sig_stack((unsigned long) sc))
  172. flags |= PARISC_SC_FLAG_ONSTACK;
  173. if (in_syscall) {
  174. flags |= PARISC_SC_FLAG_IN_SYSCALL;
  175. /* regs->iaoq is undefined in the syscall return path */
  176. err |= __put_user(regs->gr[31], &sc->sc_iaoq[0]);
  177. err |= __put_user(regs->gr[31]+4, &sc->sc_iaoq[1]);
  178. err |= __put_user(regs->sr[3], &sc->sc_iasq[0]);
  179. err |= __put_user(regs->sr[3], &sc->sc_iasq[1]);
  180. DBG(1,"setup_sigcontext: iaoq %#lx / %#lx (in syscall)\n",
  181. regs->gr[31], regs->gr[31]+4);
  182. } else {
  183. err |= __copy_to_user(sc->sc_iaoq, regs->iaoq, sizeof(regs->iaoq));
  184. err |= __copy_to_user(sc->sc_iasq, regs->iasq, sizeof(regs->iasq));
  185. DBG(1,"setup_sigcontext: iaoq %#lx / %#lx (not in syscall)\n",
  186. regs->iaoq[0], regs->iaoq[1]);
  187. }
  188. err |= __put_user(flags, &sc->sc_flags);
  189. err |= __copy_to_user(sc->sc_gr, regs->gr, sizeof(regs->gr));
  190. err |= __copy_to_user(sc->sc_fr, regs->fr, sizeof(regs->fr));
  191. err |= __put_user(regs->sar, &sc->sc_sar);
  192. DBG(1,"setup_sigcontext: r28 is %ld\n", regs->gr[28]);
  193. return err;
  194. }
  195. static long
  196. setup_rt_frame(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs,
  197. int in_syscall)
  198. {
  199. struct rt_sigframe __user *frame;
  200. unsigned long rp, usp;
  201. unsigned long haddr, sigframe_size;
  202. int err = 0;
  203. #ifdef CONFIG_64BIT
  204. struct compat_rt_sigframe __user * compat_frame;
  205. compat_sigset_t compat_set;
  206. #endif
  207. usp = (regs->gr[30] & ~(0x01UL));
  208. /*FIXME: frame_size parameter is unused, remove it. */
  209. frame = get_sigframe(&ksig->ka, usp, sizeof(*frame));
  210. DBG(1,"SETUP_RT_FRAME: START\n");
  211. DBG(1,"setup_rt_frame: frame %p info %p\n", frame, ksig->info);
  212. #ifdef CONFIG_64BIT
  213. compat_frame = (struct compat_rt_sigframe __user *)frame;
  214. if (is_compat_task()) {
  215. DBG(1,"setup_rt_frame: frame->info = 0x%p\n", &compat_frame->info);
  216. err |= copy_siginfo_to_user32(&compat_frame->info, &ksig->info);
  217. err |= __compat_save_altstack( &compat_frame->uc.uc_stack, regs->gr[30]);
  218. DBG(1,"setup_rt_frame: frame->uc = 0x%p\n", &compat_frame->uc);
  219. DBG(1,"setup_rt_frame: frame->uc.uc_mcontext = 0x%p\n", &compat_frame->uc.uc_mcontext);
  220. err |= setup_sigcontext32(&compat_frame->uc.uc_mcontext,
  221. &compat_frame->regs, regs, in_syscall);
  222. sigset_64to32(&compat_set,set);
  223. err |= __copy_to_user(&compat_frame->uc.uc_sigmask, &compat_set, sizeof(compat_set));
  224. } else
  225. #endif
  226. {
  227. DBG(1,"setup_rt_frame: frame->info = 0x%p\n", &frame->info);
  228. err |= copy_siginfo_to_user(&frame->info, &ksig->info);
  229. err |= __save_altstack(&frame->uc.uc_stack, regs->gr[30]);
  230. DBG(1,"setup_rt_frame: frame->uc = 0x%p\n", &frame->uc);
  231. DBG(1,"setup_rt_frame: frame->uc.uc_mcontext = 0x%p\n", &frame->uc.uc_mcontext);
  232. err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, in_syscall);
  233. /* FIXME: Should probably be converted as well for the compat case */
  234. err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
  235. }
  236. if (err)
  237. return -EFAULT;
  238. /* Set up to return from userspace. If provided, use a stub
  239. already in userspace. The first words of tramp are used to
  240. save the previous sigrestartblock trampoline that might be
  241. on the stack. We start the sigreturn trampoline at
  242. SIGRESTARTBLOCK_TRAMP+X. */
  243. err |= __put_user(in_syscall ? INSN_LDI_R25_1 : INSN_LDI_R25_0,
  244. &frame->tramp[SIGRESTARTBLOCK_TRAMP+0]);
  245. err |= __put_user(INSN_LDI_R20,
  246. &frame->tramp[SIGRESTARTBLOCK_TRAMP+1]);
  247. err |= __put_user(INSN_BLE_SR2_R0,
  248. &frame->tramp[SIGRESTARTBLOCK_TRAMP+2]);
  249. err |= __put_user(INSN_NOP, &frame->tramp[SIGRESTARTBLOCK_TRAMP+3]);
  250. #if DEBUG_SIG
  251. /* Assert that we're flushing in the correct space... */
  252. {
  253. unsigned long sid;
  254. asm ("mfsp %%sr3,%0" : "=r" (sid));
  255. DBG(1,"setup_rt_frame: Flushing 64 bytes at space %#x offset %p\n",
  256. sid, frame->tramp);
  257. }
  258. #endif
  259. flush_user_dcache_range((unsigned long) &frame->tramp[0],
  260. (unsigned long) &frame->tramp[TRAMP_SIZE]);
  261. flush_user_icache_range((unsigned long) &frame->tramp[0],
  262. (unsigned long) &frame->tramp[TRAMP_SIZE]);
  263. /* TRAMP Words 0-4, Length 5 = SIGRESTARTBLOCK_TRAMP
  264. * TRAMP Words 5-9, Length 4 = SIGRETURN_TRAMP
  265. * So the SIGRETURN_TRAMP is at the end of SIGRESTARTBLOCK_TRAMP
  266. */
  267. rp = (unsigned long) &frame->tramp[SIGRESTARTBLOCK_TRAMP];
  268. if (err)
  269. return -EFAULT;
  270. haddr = A(ksig->ka.sa.sa_handler);
  271. /* The sa_handler may be a pointer to a function descriptor */
  272. #ifdef CONFIG_64BIT
  273. if (is_compat_task()) {
  274. #endif
  275. if (haddr & PA_PLABEL_FDESC) {
  276. Elf32_Fdesc fdesc;
  277. Elf32_Fdesc __user *ufdesc = (Elf32_Fdesc __user *)A(haddr & ~3);
  278. err = __copy_from_user(&fdesc, ufdesc, sizeof(fdesc));
  279. if (err)
  280. return -EFAULT;
  281. haddr = fdesc.addr;
  282. regs->gr[19] = fdesc.gp;
  283. }
  284. #ifdef CONFIG_64BIT
  285. } else {
  286. Elf64_Fdesc fdesc;
  287. Elf64_Fdesc __user *ufdesc = (Elf64_Fdesc __user *)A(haddr & ~3);
  288. err = __copy_from_user(&fdesc, ufdesc, sizeof(fdesc));
  289. if (err)
  290. return -EFAULT;
  291. haddr = fdesc.addr;
  292. regs->gr[19] = fdesc.gp;
  293. DBG(1,"setup_rt_frame: 64 bit signal, exe=%#lx, r19=%#lx, in_syscall=%d\n",
  294. haddr, regs->gr[19], in_syscall);
  295. }
  296. #endif
  297. /* The syscall return path will create IAOQ values from r31.
  298. */
  299. sigframe_size = PARISC_RT_SIGFRAME_SIZE;
  300. #ifdef CONFIG_64BIT
  301. if (is_compat_task())
  302. sigframe_size = PARISC_RT_SIGFRAME_SIZE32;
  303. #endif
  304. if (in_syscall) {
  305. regs->gr[31] = haddr;
  306. #ifdef CONFIG_64BIT
  307. if (!test_thread_flag(TIF_32BIT))
  308. sigframe_size |= 1;
  309. #endif
  310. } else {
  311. unsigned long psw = USER_PSW;
  312. #ifdef CONFIG_64BIT
  313. if (!test_thread_flag(TIF_32BIT))
  314. psw |= PSW_W;
  315. #endif
  316. /* If we are singlestepping, arrange a trap to be delivered
  317. when we return to userspace. Note the semantics -- we
  318. should trap before the first insn in the handler is
  319. executed. Ref:
  320. http://sources.redhat.com/ml/gdb/2004-11/msg00245.html
  321. */
  322. if (pa_psw(current)->r) {
  323. pa_psw(current)->r = 0;
  324. psw |= PSW_R;
  325. mtctl(-1, 0);
  326. }
  327. regs->gr[0] = psw;
  328. regs->iaoq[0] = haddr | 3;
  329. regs->iaoq[1] = regs->iaoq[0] + 4;
  330. }
  331. regs->gr[2] = rp; /* userland return pointer */
  332. regs->gr[26] = ksig->sig; /* signal number */
  333. #ifdef CONFIG_64BIT
  334. if (is_compat_task()) {
  335. regs->gr[25] = A(&compat_frame->info); /* siginfo pointer */
  336. regs->gr[24] = A(&compat_frame->uc); /* ucontext pointer */
  337. } else
  338. #endif
  339. {
  340. regs->gr[25] = A(&frame->info); /* siginfo pointer */
  341. regs->gr[24] = A(&frame->uc); /* ucontext pointer */
  342. }
  343. DBG(1,"setup_rt_frame: making sigreturn frame: %#lx + %#lx = %#lx\n",
  344. regs->gr[30], sigframe_size,
  345. regs->gr[30] + sigframe_size);
  346. /* Raise the user stack pointer to make a proper call frame. */
  347. regs->gr[30] = (A(frame) + sigframe_size);
  348. DBG(1,"setup_rt_frame: sig deliver (%s,%d) frame=0x%p sp=%#lx iaoq=%#lx/%#lx rp=%#lx\n",
  349. current->comm, current->pid, frame, regs->gr[30],
  350. regs->iaoq[0], regs->iaoq[1], rp);
  351. return 0;
  352. }
  353. /*
  354. * OK, we're invoking a handler.
  355. */
  356. static void
  357. handle_signal(struct ksignal *ksig, struct pt_regs *regs, int in_syscall)
  358. {
  359. int ret;
  360. sigset_t *oldset = sigmask_to_save();
  361. DBG(1,"handle_signal: sig=%ld, ka=%p, info=%p, oldset=%p, regs=%p\n",
  362. ksig->sig, ksig->ka, ksig->info, oldset, regs);
  363. /* Set up the stack frame */
  364. ret = setup_rt_frame(ksig, oldset, regs, in_syscall);
  365. signal_setup_done(ret, ksig, test_thread_flag(TIF_SINGLESTEP) ||
  366. test_thread_flag(TIF_BLOCKSTEP));
  367. DBG(1,KERN_DEBUG "do_signal: Exit (success), regs->gr[28] = %ld\n",
  368. regs->gr[28]);
  369. }
  370. static inline void
  371. syscall_restart(struct pt_regs *regs, struct k_sigaction *ka)
  372. {
  373. if (regs->orig_r28)
  374. return;
  375. regs->orig_r28 = 1; /* no more restarts */
  376. /* Check the return code */
  377. switch (regs->gr[28]) {
  378. case -ERESTART_RESTARTBLOCK:
  379. case -ERESTARTNOHAND:
  380. DBG(1,"ERESTARTNOHAND: returning -EINTR\n");
  381. regs->gr[28] = -EINTR;
  382. break;
  383. case -ERESTARTSYS:
  384. if (!(ka->sa.sa_flags & SA_RESTART)) {
  385. DBG(1,"ERESTARTSYS: putting -EINTR\n");
  386. regs->gr[28] = -EINTR;
  387. break;
  388. }
  389. /* fallthrough */
  390. case -ERESTARTNOINTR:
  391. /* A syscall is just a branch, so all
  392. * we have to do is fiddle the return pointer.
  393. */
  394. regs->gr[31] -= 8; /* delayed branching */
  395. break;
  396. }
  397. }
  398. static inline void
  399. insert_restart_trampoline(struct pt_regs *regs)
  400. {
  401. if (regs->orig_r28)
  402. return;
  403. regs->orig_r28 = 1; /* no more restarts */
  404. switch(regs->gr[28]) {
  405. case -ERESTART_RESTARTBLOCK: {
  406. /* Restart the system call - no handlers present */
  407. unsigned int *usp = (unsigned int *)regs->gr[30];
  408. unsigned long start = (unsigned long) &usp[2];
  409. unsigned long end = (unsigned long) &usp[5];
  410. long err = 0;
  411. /* Setup a trampoline to restart the syscall
  412. * with __NR_restart_syscall
  413. *
  414. * 0: <return address (orig r31)>
  415. * 4: <2nd half for 64-bit>
  416. * 8: ldw 0(%sp), %r31
  417. * 12: be 0x100(%sr2, %r0)
  418. * 16: ldi __NR_restart_syscall, %r20
  419. */
  420. #ifdef CONFIG_64BIT
  421. err |= put_user(regs->gr[31] >> 32, &usp[0]);
  422. err |= put_user(regs->gr[31] & 0xffffffff, &usp[1]);
  423. err |= put_user(0x0fc010df, &usp[2]);
  424. #else
  425. err |= put_user(regs->gr[31], &usp[0]);
  426. err |= put_user(0x0fc0109f, &usp[2]);
  427. #endif
  428. err |= put_user(0xe0008200, &usp[3]);
  429. err |= put_user(0x34140000, &usp[4]);
  430. WARN_ON(err);
  431. /* flush data/instruction cache for new insns */
  432. flush_user_dcache_range(start, end);
  433. flush_user_icache_range(start, end);
  434. regs->gr[31] = regs->gr[30] + 8;
  435. return;
  436. }
  437. case -ERESTARTNOHAND:
  438. case -ERESTARTSYS:
  439. case -ERESTARTNOINTR: {
  440. /* Hooray for delayed branching. We don't
  441. * have to restore %r20 (the system call
  442. * number) because it gets loaded in the delay
  443. * slot of the branch external instruction.
  444. */
  445. regs->gr[31] -= 8;
  446. return;
  447. }
  448. default:
  449. break;
  450. }
  451. }
  452. /*
  453. * Note that 'init' is a special process: it doesn't get signals it doesn't
  454. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  455. * mistake.
  456. *
  457. * We need to be able to restore the syscall arguments (r21-r26) to
  458. * restart syscalls. Thus, the syscall path should save them in the
  459. * pt_regs structure (it's okay to do so since they are caller-save
  460. * registers). As noted below, the syscall number gets restored for
  461. * us due to the magic of delayed branching.
  462. */
  463. asmlinkage void
  464. do_signal(struct pt_regs *regs, long in_syscall)
  465. {
  466. struct ksignal ksig;
  467. DBG(1,"\ndo_signal: regs=0x%p, sr7 %#lx, in_syscall=%d\n",
  468. regs, regs->sr[7], in_syscall);
  469. if (get_signal(&ksig)) {
  470. DBG(3,"do_signal: signr = %d, regs->gr[28] = %ld\n", signr, regs->gr[28]);
  471. /* Restart a system call if necessary. */
  472. if (in_syscall)
  473. syscall_restart(regs, &ksig.ka);
  474. handle_signal(&ksig, regs, in_syscall);
  475. return;
  476. }
  477. /* Did we come from a system call? */
  478. if (in_syscall)
  479. insert_restart_trampoline(regs);
  480. DBG(1,"do_signal: Exit (not delivered), regs->gr[28] = %ld\n",
  481. regs->gr[28]);
  482. restore_saved_sigmask();
  483. }
  484. void do_notify_resume(struct pt_regs *regs, long in_syscall)
  485. {
  486. if (test_thread_flag(TIF_SIGPENDING))
  487. do_signal(regs, in_syscall);
  488. if (test_thread_flag(TIF_NOTIFY_RESUME)) {
  489. clear_thread_flag(TIF_NOTIFY_RESUME);
  490. tracehook_notify_resume(regs);
  491. }
  492. }