signal.c 19 KB

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