signal.c 19 KB

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