signal.c 18 KB

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