signal.c 17 KB

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