signal.c 20 KB

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