signal.c 18 KB

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