signal_32.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. /*
  2. * Signal handling for 32bit PPC and 32bit tasks on 64bit PPC
  3. *
  4. * PowerPC version
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. * Copyright (C) 2001 IBM
  7. * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  8. * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
  9. *
  10. * Derived from "arch/i386/kernel/signal.c"
  11. * Copyright (C) 1991, 1992 Linus Torvalds
  12. * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. */
  19. #include <linux/config.h>
  20. #include <linux/sched.h>
  21. #include <linux/mm.h>
  22. #include <linux/smp.h>
  23. #include <linux/smp_lock.h>
  24. #include <linux/kernel.h>
  25. #include <linux/signal.h>
  26. #include <linux/errno.h>
  27. #include <linux/elf.h>
  28. #ifdef CONFIG_PPC64
  29. #include <linux/syscalls.h>
  30. #include <linux/compat.h>
  31. #include <linux/ptrace.h>
  32. #else
  33. #include <linux/wait.h>
  34. #include <linux/ptrace.h>
  35. #include <linux/unistd.h>
  36. #include <linux/stddef.h>
  37. #include <linux/tty.h>
  38. #include <linux/binfmts.h>
  39. #include <linux/suspend.h>
  40. #endif
  41. #include <asm/uaccess.h>
  42. #include <asm/cacheflush.h>
  43. #include <asm/syscalls.h>
  44. #include <asm/sigcontext.h>
  45. #include <asm/vdso.h>
  46. #ifdef CONFIG_PPC64
  47. #include "ppc32.h"
  48. #include <asm/unistd.h>
  49. #else
  50. #include <asm/ucontext.h>
  51. #include <asm/pgtable.h>
  52. #endif
  53. #undef DEBUG_SIG
  54. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  55. #ifdef CONFIG_PPC64
  56. #define do_signal do_signal32
  57. #define sys_sigsuspend compat_sys_sigsuspend
  58. #define sys_rt_sigsuspend compat_sys_rt_sigsuspend
  59. #define sys_rt_sigreturn compat_sys_rt_sigreturn
  60. #define sys_sigaction compat_sys_sigaction
  61. #define sys_swapcontext compat_sys_swapcontext
  62. #define sys_sigreturn compat_sys_sigreturn
  63. #define old_sigaction old_sigaction32
  64. #define sigcontext sigcontext32
  65. #define mcontext mcontext32
  66. #define ucontext ucontext32
  67. /*
  68. * Returning 0 means we return to userspace via
  69. * ret_from_except and thus restore all user
  70. * registers from *regs. This is what we need
  71. * to do when a signal has been delivered.
  72. */
  73. #define GP_REGS_SIZE min(sizeof(elf_gregset_t32), sizeof(struct pt_regs32))
  74. #undef __SIGNAL_FRAMESIZE
  75. #define __SIGNAL_FRAMESIZE __SIGNAL_FRAMESIZE32
  76. #undef ELF_NVRREG
  77. #define ELF_NVRREG ELF_NVRREG32
  78. /*
  79. * Functions for flipping sigsets (thanks to brain dead generic
  80. * implementation that makes things simple for little endian only)
  81. */
  82. static inline int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set)
  83. {
  84. compat_sigset_t cset;
  85. switch (_NSIG_WORDS) {
  86. case 4: cset.sig[5] = set->sig[3] & 0xffffffffull;
  87. cset.sig[7] = set->sig[3] >> 32;
  88. case 3: cset.sig[4] = set->sig[2] & 0xffffffffull;
  89. cset.sig[5] = set->sig[2] >> 32;
  90. case 2: cset.sig[2] = set->sig[1] & 0xffffffffull;
  91. cset.sig[3] = set->sig[1] >> 32;
  92. case 1: cset.sig[0] = set->sig[0] & 0xffffffffull;
  93. cset.sig[1] = set->sig[0] >> 32;
  94. }
  95. return copy_to_user(uset, &cset, sizeof(*uset));
  96. }
  97. static inline int get_sigset_t(sigset_t *set,
  98. const compat_sigset_t __user *uset)
  99. {
  100. compat_sigset_t s32;
  101. if (copy_from_user(&s32, uset, sizeof(*uset)))
  102. return -EFAULT;
  103. /*
  104. * Swap the 2 words of the 64-bit sigset_t (they are stored
  105. * in the "wrong" endian in 32-bit user storage).
  106. */
  107. switch (_NSIG_WORDS) {
  108. case 4: set->sig[3] = s32.sig[6] | (((long)s32.sig[7]) << 32);
  109. case 3: set->sig[2] = s32.sig[4] | (((long)s32.sig[5]) << 32);
  110. case 2: set->sig[1] = s32.sig[2] | (((long)s32.sig[3]) << 32);
  111. case 1: set->sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
  112. }
  113. return 0;
  114. }
  115. static inline int get_old_sigaction(struct k_sigaction *new_ka,
  116. struct old_sigaction __user *act)
  117. {
  118. compat_old_sigset_t mask;
  119. compat_uptr_t handler, restorer;
  120. if (get_user(handler, &act->sa_handler) ||
  121. __get_user(restorer, &act->sa_restorer) ||
  122. __get_user(new_ka->sa.sa_flags, &act->sa_flags) ||
  123. __get_user(mask, &act->sa_mask))
  124. return -EFAULT;
  125. new_ka->sa.sa_handler = compat_ptr(handler);
  126. new_ka->sa.sa_restorer = compat_ptr(restorer);
  127. siginitset(&new_ka->sa.sa_mask, mask);
  128. return 0;
  129. }
  130. #define to_user_ptr(p) ptr_to_compat(p)
  131. #define from_user_ptr(p) compat_ptr(p)
  132. static inline int save_general_regs(struct pt_regs *regs,
  133. struct mcontext __user *frame)
  134. {
  135. elf_greg_t64 *gregs = (elf_greg_t64 *)regs;
  136. int i;
  137. WARN_ON(!FULL_REGS(regs));
  138. for (i = 0; i <= PT_RESULT; i ++) {
  139. if (i == 14 && !FULL_REGS(regs))
  140. i = 32;
  141. if (__put_user((unsigned int)gregs[i], &frame->mc_gregs[i]))
  142. return -EFAULT;
  143. }
  144. return 0;
  145. }
  146. static inline int restore_general_regs(struct pt_regs *regs,
  147. struct mcontext __user *sr)
  148. {
  149. elf_greg_t64 *gregs = (elf_greg_t64 *)regs;
  150. int i;
  151. for (i = 0; i <= PT_RESULT; i++) {
  152. if ((i == PT_MSR) || (i == PT_SOFTE))
  153. continue;
  154. if (__get_user(gregs[i], &sr->mc_gregs[i]))
  155. return -EFAULT;
  156. }
  157. return 0;
  158. }
  159. #else /* CONFIG_PPC64 */
  160. #define GP_REGS_SIZE min(sizeof(elf_gregset_t), sizeof(struct pt_regs))
  161. static inline int put_sigset_t(sigset_t __user *uset, sigset_t *set)
  162. {
  163. return copy_to_user(uset, set, sizeof(*uset));
  164. }
  165. static inline int get_sigset_t(sigset_t *set, const sigset_t __user *uset)
  166. {
  167. return copy_from_user(set, uset, sizeof(*uset));
  168. }
  169. static inline int get_old_sigaction(struct k_sigaction *new_ka,
  170. struct old_sigaction __user *act)
  171. {
  172. old_sigset_t mask;
  173. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  174. __get_user(new_ka->sa.sa_handler, &act->sa_handler) ||
  175. __get_user(new_ka->sa.sa_restorer, &act->sa_restorer))
  176. return -EFAULT;
  177. __get_user(new_ka->sa.sa_flags, &act->sa_flags);
  178. __get_user(mask, &act->sa_mask);
  179. siginitset(&new_ka->sa.sa_mask, mask);
  180. return 0;
  181. }
  182. #define to_user_ptr(p) ((unsigned long)(p))
  183. #define from_user_ptr(p) ((void __user *)(p))
  184. static inline int save_general_regs(struct pt_regs *regs,
  185. struct mcontext __user *frame)
  186. {
  187. WARN_ON(!FULL_REGS(regs));
  188. return __copy_to_user(&frame->mc_gregs, regs, GP_REGS_SIZE);
  189. }
  190. static inline int restore_general_regs(struct pt_regs *regs,
  191. struct mcontext __user *sr)
  192. {
  193. /* copy up to but not including MSR */
  194. if (__copy_from_user(regs, &sr->mc_gregs,
  195. PT_MSR * sizeof(elf_greg_t)))
  196. return -EFAULT;
  197. /* copy from orig_r3 (the word after the MSR) up to the end */
  198. if (__copy_from_user(&regs->orig_gpr3, &sr->mc_gregs[PT_ORIG_R3],
  199. GP_REGS_SIZE - PT_ORIG_R3 * sizeof(elf_greg_t)))
  200. return -EFAULT;
  201. return 0;
  202. }
  203. #endif /* CONFIG_PPC64 */
  204. int do_signal(sigset_t *oldset, struct pt_regs *regs);
  205. /*
  206. * Atomically swap in the new signal mask, and wait for a signal.
  207. */
  208. long sys_sigsuspend(old_sigset_t mask)
  209. {
  210. mask &= _BLOCKABLE;
  211. spin_lock_irq(&current->sighand->siglock);
  212. current->saved_sigmask = current->blocked;
  213. siginitset(&current->blocked, mask);
  214. recalc_sigpending();
  215. spin_unlock_irq(&current->sighand->siglock);
  216. current->state = TASK_INTERRUPTIBLE;
  217. schedule();
  218. set_thread_flag(TIF_RESTORE_SIGMASK);
  219. return -ERESTARTNOHAND;
  220. }
  221. #ifdef CONFIG_PPC32
  222. long sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss, int r5,
  223. int r6, int r7, int r8, struct pt_regs *regs)
  224. {
  225. return do_sigaltstack(uss, uoss, regs->gpr[1]);
  226. }
  227. #endif
  228. long sys_sigaction(int sig, struct old_sigaction __user *act,
  229. struct old_sigaction __user *oact)
  230. {
  231. struct k_sigaction new_ka, old_ka;
  232. int ret;
  233. #ifdef CONFIG_PPC64
  234. if (sig < 0)
  235. sig = -sig;
  236. #endif
  237. if (act) {
  238. if (get_old_sigaction(&new_ka, act))
  239. return -EFAULT;
  240. }
  241. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  242. if (!ret && oact) {
  243. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  244. __put_user(to_user_ptr(old_ka.sa.sa_handler),
  245. &oact->sa_handler) ||
  246. __put_user(to_user_ptr(old_ka.sa.sa_restorer),
  247. &oact->sa_restorer) ||
  248. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  249. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
  250. return -EFAULT;
  251. }
  252. return ret;
  253. }
  254. /*
  255. * When we have signals to deliver, we set up on the
  256. * user stack, going down from the original stack pointer:
  257. * a sigregs struct
  258. * a sigcontext struct
  259. * a gap of __SIGNAL_FRAMESIZE bytes
  260. *
  261. * Each of these things must be a multiple of 16 bytes in size.
  262. *
  263. */
  264. struct sigregs {
  265. struct mcontext mctx; /* all the register values */
  266. /*
  267. * Programs using the rs6000/xcoff abi can save up to 19 gp
  268. * regs and 18 fp regs below sp before decrementing it.
  269. */
  270. int abigap[56];
  271. };
  272. /* We use the mc_pad field for the signal return trampoline. */
  273. #define tramp mc_pad
  274. /*
  275. * When we have rt signals to deliver, we set up on the
  276. * user stack, going down from the original stack pointer:
  277. * one rt_sigframe struct (siginfo + ucontext + ABI gap)
  278. * a gap of __SIGNAL_FRAMESIZE+16 bytes
  279. * (the +16 is to get the siginfo and ucontext in the same
  280. * positions as in older kernels).
  281. *
  282. * Each of these things must be a multiple of 16 bytes in size.
  283. *
  284. */
  285. struct rt_sigframe {
  286. #ifdef CONFIG_PPC64
  287. compat_siginfo_t info;
  288. #else
  289. struct siginfo info;
  290. #endif
  291. struct ucontext uc;
  292. /*
  293. * Programs using the rs6000/xcoff abi can save up to 19 gp
  294. * regs and 18 fp regs below sp before decrementing it.
  295. */
  296. int abigap[56];
  297. };
  298. /*
  299. * Save the current user registers on the user stack.
  300. * We only save the altivec/spe registers if the process has used
  301. * altivec/spe instructions at some point.
  302. */
  303. static int save_user_regs(struct pt_regs *regs, struct mcontext __user *frame,
  304. int sigret)
  305. {
  306. /* Make sure floating point registers are stored in regs */
  307. flush_fp_to_thread(current);
  308. /* save general and floating-point registers */
  309. if (save_general_regs(regs, frame) ||
  310. __copy_to_user(&frame->mc_fregs, current->thread.fpr,
  311. ELF_NFPREG * sizeof(double)))
  312. return 1;
  313. #ifdef CONFIG_ALTIVEC
  314. /* save altivec registers */
  315. if (current->thread.used_vr) {
  316. flush_altivec_to_thread(current);
  317. if (__copy_to_user(&frame->mc_vregs, current->thread.vr,
  318. ELF_NVRREG * sizeof(vector128)))
  319. return 1;
  320. /* set MSR_VEC in the saved MSR value to indicate that
  321. frame->mc_vregs contains valid data */
  322. if (__put_user(regs->msr | MSR_VEC, &frame->mc_gregs[PT_MSR]))
  323. return 1;
  324. }
  325. /* else assert((regs->msr & MSR_VEC) == 0) */
  326. /* We always copy to/from vrsave, it's 0 if we don't have or don't
  327. * use altivec. Since VSCR only contains 32 bits saved in the least
  328. * significant bits of a vector, we "cheat" and stuff VRSAVE in the
  329. * most significant bits of that same vector. --BenH
  330. */
  331. if (__put_user(current->thread.vrsave, (u32 __user *)&frame->mc_vregs[32]))
  332. return 1;
  333. #endif /* CONFIG_ALTIVEC */
  334. #ifdef CONFIG_SPE
  335. /* save spe registers */
  336. if (current->thread.used_spe) {
  337. flush_spe_to_thread(current);
  338. if (__copy_to_user(&frame->mc_vregs, current->thread.evr,
  339. ELF_NEVRREG * sizeof(u32)))
  340. return 1;
  341. /* set MSR_SPE in the saved MSR value to indicate that
  342. frame->mc_vregs contains valid data */
  343. if (__put_user(regs->msr | MSR_SPE, &frame->mc_gregs[PT_MSR]))
  344. return 1;
  345. }
  346. /* else assert((regs->msr & MSR_SPE) == 0) */
  347. /* We always copy to/from spefscr */
  348. if (__put_user(current->thread.spefscr, (u32 __user *)&frame->mc_vregs + ELF_NEVRREG))
  349. return 1;
  350. #endif /* CONFIG_SPE */
  351. if (sigret) {
  352. /* Set up the sigreturn trampoline: li r0,sigret; sc */
  353. if (__put_user(0x38000000UL + sigret, &frame->tramp[0])
  354. || __put_user(0x44000002UL, &frame->tramp[1]))
  355. return 1;
  356. flush_icache_range((unsigned long) &frame->tramp[0],
  357. (unsigned long) &frame->tramp[2]);
  358. }
  359. return 0;
  360. }
  361. /*
  362. * Restore the current user register values from the user stack,
  363. * (except for MSR).
  364. */
  365. static long restore_user_regs(struct pt_regs *regs,
  366. struct mcontext __user *sr, int sig)
  367. {
  368. long err;
  369. unsigned int save_r2 = 0;
  370. #if defined(CONFIG_ALTIVEC) || defined(CONFIG_SPE)
  371. unsigned long msr;
  372. #endif
  373. /*
  374. * restore general registers but not including MSR or SOFTE. Also
  375. * take care of keeping r2 (TLS) intact if not a signal
  376. */
  377. if (!sig)
  378. save_r2 = (unsigned int)regs->gpr[2];
  379. err = restore_general_regs(regs, sr);
  380. if (!sig)
  381. regs->gpr[2] = (unsigned long) save_r2;
  382. if (err)
  383. return 1;
  384. /*
  385. * Do this before updating the thread state in
  386. * current->thread.fpr/vr/evr. That way, if we get preempted
  387. * and another task grabs the FPU/Altivec/SPE, it won't be
  388. * tempted to save the current CPU state into the thread_struct
  389. * and corrupt what we are writing there.
  390. */
  391. discard_lazy_cpu_state();
  392. /* force the process to reload the FP registers from
  393. current->thread when it next does FP instructions */
  394. regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1);
  395. if (__copy_from_user(current->thread.fpr, &sr->mc_fregs,
  396. sizeof(sr->mc_fregs)))
  397. return 1;
  398. #ifdef CONFIG_ALTIVEC
  399. /* force the process to reload the altivec registers from
  400. current->thread when it next does altivec instructions */
  401. regs->msr &= ~MSR_VEC;
  402. if (!__get_user(msr, &sr->mc_gregs[PT_MSR]) && (msr & MSR_VEC) != 0) {
  403. /* restore altivec registers from the stack */
  404. if (__copy_from_user(current->thread.vr, &sr->mc_vregs,
  405. sizeof(sr->mc_vregs)))
  406. return 1;
  407. } else if (current->thread.used_vr)
  408. memset(current->thread.vr, 0, ELF_NVRREG * sizeof(vector128));
  409. /* Always get VRSAVE back */
  410. if (__get_user(current->thread.vrsave, (u32 __user *)&sr->mc_vregs[32]))
  411. return 1;
  412. #endif /* CONFIG_ALTIVEC */
  413. #ifdef CONFIG_SPE
  414. /* force the process to reload the spe registers from
  415. current->thread when it next does spe instructions */
  416. regs->msr &= ~MSR_SPE;
  417. if (!__get_user(msr, &sr->mc_gregs[PT_MSR]) && (msr & MSR_SPE) != 0) {
  418. /* restore spe registers from the stack */
  419. if (__copy_from_user(current->thread.evr, &sr->mc_vregs,
  420. ELF_NEVRREG * sizeof(u32)))
  421. return 1;
  422. } else if (current->thread.used_spe)
  423. memset(current->thread.evr, 0, ELF_NEVRREG * sizeof(u32));
  424. /* Always get SPEFSCR back */
  425. if (__get_user(current->thread.spefscr, (u32 __user *)&sr->mc_vregs + ELF_NEVRREG))
  426. return 1;
  427. #endif /* CONFIG_SPE */
  428. return 0;
  429. }
  430. #ifdef CONFIG_PPC64
  431. long compat_sys_rt_sigaction(int sig, const struct sigaction32 __user *act,
  432. struct sigaction32 __user *oact, size_t sigsetsize)
  433. {
  434. struct k_sigaction new_ka, old_ka;
  435. int ret;
  436. /* XXX: Don't preclude handling different sized sigset_t's. */
  437. if (sigsetsize != sizeof(compat_sigset_t))
  438. return -EINVAL;
  439. if (act) {
  440. compat_uptr_t handler;
  441. ret = get_user(handler, &act->sa_handler);
  442. new_ka.sa.sa_handler = compat_ptr(handler);
  443. ret |= get_sigset_t(&new_ka.sa.sa_mask, &act->sa_mask);
  444. ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  445. if (ret)
  446. return -EFAULT;
  447. }
  448. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  449. if (!ret && oact) {
  450. ret = put_user(to_user_ptr(old_ka.sa.sa_handler), &oact->sa_handler);
  451. ret |= put_sigset_t(&oact->sa_mask, &old_ka.sa.sa_mask);
  452. ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  453. }
  454. return ret;
  455. }
  456. /*
  457. * Note: it is necessary to treat how as an unsigned int, with the
  458. * corresponding cast to a signed int to insure that the proper
  459. * conversion (sign extension) between the register representation
  460. * of a signed int (msr in 32-bit mode) and the register representation
  461. * of a signed int (msr in 64-bit mode) is performed.
  462. */
  463. long compat_sys_rt_sigprocmask(u32 how, compat_sigset_t __user *set,
  464. compat_sigset_t __user *oset, size_t sigsetsize)
  465. {
  466. sigset_t s;
  467. sigset_t __user *up;
  468. int ret;
  469. mm_segment_t old_fs = get_fs();
  470. if (set) {
  471. if (get_sigset_t(&s, set))
  472. return -EFAULT;
  473. }
  474. set_fs(KERNEL_DS);
  475. /* This is valid because of the set_fs() */
  476. up = (sigset_t __user *) &s;
  477. ret = sys_rt_sigprocmask((int)how, set ? up : NULL, oset ? up : NULL,
  478. sigsetsize);
  479. set_fs(old_fs);
  480. if (ret)
  481. return ret;
  482. if (oset) {
  483. if (put_sigset_t(oset, &s))
  484. return -EFAULT;
  485. }
  486. return 0;
  487. }
  488. long compat_sys_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
  489. {
  490. sigset_t s;
  491. int ret;
  492. mm_segment_t old_fs = get_fs();
  493. set_fs(KERNEL_DS);
  494. /* The __user pointer cast is valid because of the set_fs() */
  495. ret = sys_rt_sigpending((sigset_t __user *) &s, sigsetsize);
  496. set_fs(old_fs);
  497. if (!ret) {
  498. if (put_sigset_t(set, &s))
  499. return -EFAULT;
  500. }
  501. return ret;
  502. }
  503. int copy_siginfo_to_user32(struct compat_siginfo __user *d, siginfo_t *s)
  504. {
  505. int err;
  506. if (!access_ok (VERIFY_WRITE, d, sizeof(*d)))
  507. return -EFAULT;
  508. /* If you change siginfo_t structure, please be sure
  509. * this code is fixed accordingly.
  510. * It should never copy any pad contained in the structure
  511. * to avoid security leaks, but must copy the generic
  512. * 3 ints plus the relevant union member.
  513. * This routine must convert siginfo from 64bit to 32bit as well
  514. * at the same time.
  515. */
  516. err = __put_user(s->si_signo, &d->si_signo);
  517. err |= __put_user(s->si_errno, &d->si_errno);
  518. err |= __put_user((short)s->si_code, &d->si_code);
  519. if (s->si_code < 0)
  520. err |= __copy_to_user(&d->_sifields._pad, &s->_sifields._pad,
  521. SI_PAD_SIZE32);
  522. else switch(s->si_code >> 16) {
  523. case __SI_CHLD >> 16:
  524. err |= __put_user(s->si_pid, &d->si_pid);
  525. err |= __put_user(s->si_uid, &d->si_uid);
  526. err |= __put_user(s->si_utime, &d->si_utime);
  527. err |= __put_user(s->si_stime, &d->si_stime);
  528. err |= __put_user(s->si_status, &d->si_status);
  529. break;
  530. case __SI_FAULT >> 16:
  531. err |= __put_user((unsigned int)(unsigned long)s->si_addr,
  532. &d->si_addr);
  533. break;
  534. case __SI_POLL >> 16:
  535. err |= __put_user(s->si_band, &d->si_band);
  536. err |= __put_user(s->si_fd, &d->si_fd);
  537. break;
  538. case __SI_TIMER >> 16:
  539. err |= __put_user(s->si_tid, &d->si_tid);
  540. err |= __put_user(s->si_overrun, &d->si_overrun);
  541. err |= __put_user(s->si_int, &d->si_int);
  542. break;
  543. case __SI_RT >> 16: /* This is not generated by the kernel as of now. */
  544. case __SI_MESGQ >> 16:
  545. err |= __put_user(s->si_int, &d->si_int);
  546. /* fallthrough */
  547. case __SI_KILL >> 16:
  548. default:
  549. err |= __put_user(s->si_pid, &d->si_pid);
  550. err |= __put_user(s->si_uid, &d->si_uid);
  551. break;
  552. }
  553. return err;
  554. }
  555. #define copy_siginfo_to_user copy_siginfo_to_user32
  556. /*
  557. * Note: it is necessary to treat pid and sig as unsigned ints, with the
  558. * corresponding cast to a signed int to insure that the proper conversion
  559. * (sign extension) between the register representation of a signed int
  560. * (msr in 32-bit mode) and the register representation of a signed int
  561. * (msr in 64-bit mode) is performed.
  562. */
  563. long compat_sys_rt_sigqueueinfo(u32 pid, u32 sig, compat_siginfo_t __user *uinfo)
  564. {
  565. siginfo_t info;
  566. int ret;
  567. mm_segment_t old_fs = get_fs();
  568. if (copy_from_user (&info, uinfo, 3*sizeof(int)) ||
  569. copy_from_user (info._sifields._pad, uinfo->_sifields._pad, SI_PAD_SIZE32))
  570. return -EFAULT;
  571. set_fs (KERNEL_DS);
  572. /* The __user pointer cast is valid becasuse of the set_fs() */
  573. ret = sys_rt_sigqueueinfo((int)pid, (int)sig, (siginfo_t __user *) &info);
  574. set_fs (old_fs);
  575. return ret;
  576. }
  577. /*
  578. * Start Alternate signal stack support
  579. *
  580. * System Calls
  581. * sigaltatck compat_sys_sigaltstack
  582. */
  583. int compat_sys_sigaltstack(u32 __new, u32 __old, int r5,
  584. int r6, int r7, int r8, struct pt_regs *regs)
  585. {
  586. stack_32_t __user * newstack = compat_ptr(__new);
  587. stack_32_t __user * oldstack = compat_ptr(__old);
  588. stack_t uss, uoss;
  589. int ret;
  590. mm_segment_t old_fs;
  591. unsigned long sp;
  592. compat_uptr_t ss_sp;
  593. /*
  594. * set sp to the user stack on entry to the system call
  595. * the system call router sets R9 to the saved registers
  596. */
  597. sp = regs->gpr[1];
  598. /* Put new stack info in local 64 bit stack struct */
  599. if (newstack) {
  600. if (get_user(ss_sp, &newstack->ss_sp) ||
  601. __get_user(uss.ss_flags, &newstack->ss_flags) ||
  602. __get_user(uss.ss_size, &newstack->ss_size))
  603. return -EFAULT;
  604. uss.ss_sp = compat_ptr(ss_sp);
  605. }
  606. old_fs = get_fs();
  607. set_fs(KERNEL_DS);
  608. /* The __user pointer casts are valid because of the set_fs() */
  609. ret = do_sigaltstack(
  610. newstack ? (stack_t __user *) &uss : NULL,
  611. oldstack ? (stack_t __user *) &uoss : NULL,
  612. sp);
  613. set_fs(old_fs);
  614. /* Copy the stack information to the user output buffer */
  615. if (!ret && oldstack &&
  616. (put_user(ptr_to_compat(uoss.ss_sp), &oldstack->ss_sp) ||
  617. __put_user(uoss.ss_flags, &oldstack->ss_flags) ||
  618. __put_user(uoss.ss_size, &oldstack->ss_size)))
  619. return -EFAULT;
  620. return ret;
  621. }
  622. #endif /* CONFIG_PPC64 */
  623. /*
  624. * Restore the user process's signal mask
  625. */
  626. #ifdef CONFIG_PPC64
  627. extern void restore_sigmask(sigset_t *set);
  628. #else /* CONFIG_PPC64 */
  629. static void restore_sigmask(sigset_t *set)
  630. {
  631. sigdelsetmask(set, ~_BLOCKABLE);
  632. spin_lock_irq(&current->sighand->siglock);
  633. current->blocked = *set;
  634. recalc_sigpending();
  635. spin_unlock_irq(&current->sighand->siglock);
  636. }
  637. #endif
  638. /*
  639. * Set up a signal frame for a "real-time" signal handler
  640. * (one which gets siginfo).
  641. */
  642. static int handle_rt_signal(unsigned long sig, struct k_sigaction *ka,
  643. siginfo_t *info, sigset_t *oldset,
  644. struct pt_regs *regs, unsigned long newsp)
  645. {
  646. struct rt_sigframe __user *rt_sf;
  647. struct mcontext __user *frame;
  648. unsigned long origsp = newsp;
  649. /* Set up Signal Frame */
  650. /* Put a Real Time Context onto stack */
  651. newsp -= sizeof(*rt_sf);
  652. rt_sf = (struct rt_sigframe __user *)newsp;
  653. /* create a stack frame for the caller of the handler */
  654. newsp -= __SIGNAL_FRAMESIZE + 16;
  655. if (!access_ok(VERIFY_WRITE, (void __user *)newsp, origsp - newsp))
  656. goto badframe;
  657. /* Put the siginfo & fill in most of the ucontext */
  658. if (copy_siginfo_to_user(&rt_sf->info, info)
  659. || __put_user(0, &rt_sf->uc.uc_flags)
  660. || __put_user(0, &rt_sf->uc.uc_link)
  661. || __put_user(current->sas_ss_sp, &rt_sf->uc.uc_stack.ss_sp)
  662. || __put_user(sas_ss_flags(regs->gpr[1]),
  663. &rt_sf->uc.uc_stack.ss_flags)
  664. || __put_user(current->sas_ss_size, &rt_sf->uc.uc_stack.ss_size)
  665. || __put_user(to_user_ptr(&rt_sf->uc.uc_mcontext),
  666. &rt_sf->uc.uc_regs)
  667. || put_sigset_t(&rt_sf->uc.uc_sigmask, oldset))
  668. goto badframe;
  669. /* Save user registers on the stack */
  670. frame = &rt_sf->uc.uc_mcontext;
  671. if (vdso32_rt_sigtramp && current->thread.vdso_base) {
  672. if (save_user_regs(regs, frame, 0))
  673. goto badframe;
  674. regs->link = current->thread.vdso_base + vdso32_rt_sigtramp;
  675. } else {
  676. if (save_user_regs(regs, frame, __NR_rt_sigreturn))
  677. goto badframe;
  678. regs->link = (unsigned long) frame->tramp;
  679. }
  680. current->thread.fpscr.val = 0; /* turn off all fp exceptions */
  681. if (put_user(regs->gpr[1], (u32 __user *)newsp))
  682. goto badframe;
  683. regs->gpr[1] = newsp;
  684. regs->gpr[3] = sig;
  685. regs->gpr[4] = (unsigned long) &rt_sf->info;
  686. regs->gpr[5] = (unsigned long) &rt_sf->uc;
  687. regs->gpr[6] = (unsigned long) rt_sf;
  688. regs->nip = (unsigned long) ka->sa.sa_handler;
  689. regs->trap = 0;
  690. return 1;
  691. badframe:
  692. #ifdef DEBUG_SIG
  693. printk("badframe in handle_rt_signal, regs=%p frame=%p newsp=%lx\n",
  694. regs, frame, newsp);
  695. #endif
  696. force_sigsegv(sig, current);
  697. return 0;
  698. }
  699. static int do_setcontext(struct ucontext __user *ucp, struct pt_regs *regs, int sig)
  700. {
  701. sigset_t set;
  702. struct mcontext __user *mcp;
  703. if (get_sigset_t(&set, &ucp->uc_sigmask))
  704. return -EFAULT;
  705. #ifdef CONFIG_PPC64
  706. {
  707. u32 cmcp;
  708. if (__get_user(cmcp, &ucp->uc_regs))
  709. return -EFAULT;
  710. mcp = (struct mcontext __user *)(u64)cmcp;
  711. /* no need to check access_ok(mcp), since mcp < 4GB */
  712. }
  713. #else
  714. if (__get_user(mcp, &ucp->uc_regs))
  715. return -EFAULT;
  716. if (!access_ok(VERIFY_READ, mcp, sizeof(*mcp)))
  717. return -EFAULT;
  718. #endif
  719. restore_sigmask(&set);
  720. if (restore_user_regs(regs, mcp, sig))
  721. return -EFAULT;
  722. return 0;
  723. }
  724. long sys_swapcontext(struct ucontext __user *old_ctx,
  725. struct ucontext __user *new_ctx,
  726. int ctx_size, int r6, int r7, int r8, struct pt_regs *regs)
  727. {
  728. unsigned char tmp;
  729. /* Context size is for future use. Right now, we only make sure
  730. * we are passed something we understand
  731. */
  732. if (ctx_size < sizeof(struct ucontext))
  733. return -EINVAL;
  734. if (old_ctx != NULL) {
  735. if (!access_ok(VERIFY_WRITE, old_ctx, sizeof(*old_ctx))
  736. || save_user_regs(regs, &old_ctx->uc_mcontext, 0)
  737. || put_sigset_t(&old_ctx->uc_sigmask, &current->blocked)
  738. || __put_user(to_user_ptr(&old_ctx->uc_mcontext),
  739. &old_ctx->uc_regs))
  740. return -EFAULT;
  741. }
  742. if (new_ctx == NULL)
  743. return 0;
  744. if (!access_ok(VERIFY_READ, new_ctx, sizeof(*new_ctx))
  745. || __get_user(tmp, (u8 __user *) new_ctx)
  746. || __get_user(tmp, (u8 __user *) (new_ctx + 1) - 1))
  747. return -EFAULT;
  748. /*
  749. * If we get a fault copying the context into the kernel's
  750. * image of the user's registers, we can't just return -EFAULT
  751. * because the user's registers will be corrupted. For instance
  752. * the NIP value may have been updated but not some of the
  753. * other registers. Given that we have done the access_ok
  754. * and successfully read the first and last bytes of the region
  755. * above, this should only happen in an out-of-memory situation
  756. * or if another thread unmaps the region containing the context.
  757. * We kill the task with a SIGSEGV in this situation.
  758. */
  759. if (do_setcontext(new_ctx, regs, 0))
  760. do_exit(SIGSEGV);
  761. set_thread_flag(TIF_RESTOREALL);
  762. return 0;
  763. }
  764. long sys_rt_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8,
  765. struct pt_regs *regs)
  766. {
  767. struct rt_sigframe __user *rt_sf;
  768. /* Always make any pending restarted system calls return -EINTR */
  769. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  770. rt_sf = (struct rt_sigframe __user *)
  771. (regs->gpr[1] + __SIGNAL_FRAMESIZE + 16);
  772. if (!access_ok(VERIFY_READ, rt_sf, sizeof(*rt_sf)))
  773. goto bad;
  774. if (do_setcontext(&rt_sf->uc, regs, 1))
  775. goto bad;
  776. /*
  777. * It's not clear whether or why it is desirable to save the
  778. * sigaltstack setting on signal delivery and restore it on
  779. * signal return. But other architectures do this and we have
  780. * always done it up until now so it is probably better not to
  781. * change it. -- paulus
  782. */
  783. #ifdef CONFIG_PPC64
  784. /*
  785. * We use the compat_sys_ version that does the 32/64 bits conversion
  786. * and takes userland pointer directly. What about error checking ?
  787. * nobody does any...
  788. */
  789. compat_sys_sigaltstack((u32)(u64)&rt_sf->uc.uc_stack, 0, 0, 0, 0, 0, regs);
  790. #else
  791. do_sigaltstack(&rt_sf->uc.uc_stack, NULL, regs->gpr[1]);
  792. #endif
  793. set_thread_flag(TIF_RESTOREALL);
  794. return 0;
  795. bad:
  796. force_sig(SIGSEGV, current);
  797. return 0;
  798. }
  799. #ifdef CONFIG_PPC32
  800. int sys_debug_setcontext(struct ucontext __user *ctx,
  801. int ndbg, struct sig_dbg_op __user *dbg,
  802. int r6, int r7, int r8,
  803. struct pt_regs *regs)
  804. {
  805. struct sig_dbg_op op;
  806. int i;
  807. unsigned char tmp;
  808. unsigned long new_msr = regs->msr;
  809. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  810. unsigned long new_dbcr0 = current->thread.dbcr0;
  811. #endif
  812. for (i=0; i<ndbg; i++) {
  813. if (copy_from_user(&op, dbg + i, sizeof(op)))
  814. return -EFAULT;
  815. switch (op.dbg_type) {
  816. case SIG_DBG_SINGLE_STEPPING:
  817. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  818. if (op.dbg_value) {
  819. new_msr |= MSR_DE;
  820. new_dbcr0 |= (DBCR0_IDM | DBCR0_IC);
  821. } else {
  822. new_msr &= ~MSR_DE;
  823. new_dbcr0 &= ~(DBCR0_IDM | DBCR0_IC);
  824. }
  825. #else
  826. if (op.dbg_value)
  827. new_msr |= MSR_SE;
  828. else
  829. new_msr &= ~MSR_SE;
  830. #endif
  831. break;
  832. case SIG_DBG_BRANCH_TRACING:
  833. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  834. return -EINVAL;
  835. #else
  836. if (op.dbg_value)
  837. new_msr |= MSR_BE;
  838. else
  839. new_msr &= ~MSR_BE;
  840. #endif
  841. break;
  842. default:
  843. return -EINVAL;
  844. }
  845. }
  846. /* We wait until here to actually install the values in the
  847. registers so if we fail in the above loop, it will not
  848. affect the contents of these registers. After this point,
  849. failure is a problem, anyway, and it's very unlikely unless
  850. the user is really doing something wrong. */
  851. regs->msr = new_msr;
  852. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  853. current->thread.dbcr0 = new_dbcr0;
  854. #endif
  855. if (!access_ok(VERIFY_READ, ctx, sizeof(*ctx))
  856. || __get_user(tmp, (u8 __user *) ctx)
  857. || __get_user(tmp, (u8 __user *) (ctx + 1) - 1))
  858. return -EFAULT;
  859. /*
  860. * If we get a fault copying the context into the kernel's
  861. * image of the user's registers, we can't just return -EFAULT
  862. * because the user's registers will be corrupted. For instance
  863. * the NIP value may have been updated but not some of the
  864. * other registers. Given that we have done the access_ok
  865. * and successfully read the first and last bytes of the region
  866. * above, this should only happen in an out-of-memory situation
  867. * or if another thread unmaps the region containing the context.
  868. * We kill the task with a SIGSEGV in this situation.
  869. */
  870. if (do_setcontext(ctx, regs, 1)) {
  871. force_sig(SIGSEGV, current);
  872. goto out;
  873. }
  874. /*
  875. * It's not clear whether or why it is desirable to save the
  876. * sigaltstack setting on signal delivery and restore it on
  877. * signal return. But other architectures do this and we have
  878. * always done it up until now so it is probably better not to
  879. * change it. -- paulus
  880. */
  881. do_sigaltstack(&ctx->uc_stack, NULL, regs->gpr[1]);
  882. set_thread_flag(TIF_RESTOREALL);
  883. out:
  884. return 0;
  885. }
  886. #endif
  887. /*
  888. * OK, we're invoking a handler
  889. */
  890. static int handle_signal(unsigned long sig, struct k_sigaction *ka,
  891. siginfo_t *info, sigset_t *oldset, struct pt_regs *regs,
  892. unsigned long newsp)
  893. {
  894. struct sigcontext __user *sc;
  895. struct sigregs __user *frame;
  896. unsigned long origsp = newsp;
  897. /* Set up Signal Frame */
  898. newsp -= sizeof(struct sigregs);
  899. frame = (struct sigregs __user *) newsp;
  900. /* Put a sigcontext on the stack */
  901. newsp -= sizeof(*sc);
  902. sc = (struct sigcontext __user *) newsp;
  903. /* create a stack frame for the caller of the handler */
  904. newsp -= __SIGNAL_FRAMESIZE;
  905. if (!access_ok(VERIFY_WRITE, (void __user *) newsp, origsp - newsp))
  906. goto badframe;
  907. #if _NSIG != 64
  908. #error "Please adjust handle_signal()"
  909. #endif
  910. if (__put_user(to_user_ptr(ka->sa.sa_handler), &sc->handler)
  911. || __put_user(oldset->sig[0], &sc->oldmask)
  912. #ifdef CONFIG_PPC64
  913. || __put_user((oldset->sig[0] >> 32), &sc->_unused[3])
  914. #else
  915. || __put_user(oldset->sig[1], &sc->_unused[3])
  916. #endif
  917. || __put_user(to_user_ptr(frame), &sc->regs)
  918. || __put_user(sig, &sc->signal))
  919. goto badframe;
  920. if (vdso32_sigtramp && current->thread.vdso_base) {
  921. if (save_user_regs(regs, &frame->mctx, 0))
  922. goto badframe;
  923. regs->link = current->thread.vdso_base + vdso32_sigtramp;
  924. } else {
  925. if (save_user_regs(regs, &frame->mctx, __NR_sigreturn))
  926. goto badframe;
  927. regs->link = (unsigned long) frame->mctx.tramp;
  928. }
  929. current->thread.fpscr.val = 0; /* turn off all fp exceptions */
  930. if (put_user(regs->gpr[1], (u32 __user *)newsp))
  931. goto badframe;
  932. regs->gpr[1] = newsp;
  933. regs->gpr[3] = sig;
  934. regs->gpr[4] = (unsigned long) sc;
  935. regs->nip = (unsigned long) ka->sa.sa_handler;
  936. regs->trap = 0;
  937. return 1;
  938. badframe:
  939. #ifdef DEBUG_SIG
  940. printk("badframe in handle_signal, regs=%p frame=%p newsp=%lx\n",
  941. regs, frame, newsp);
  942. #endif
  943. force_sigsegv(sig, current);
  944. return 0;
  945. }
  946. /*
  947. * Do a signal return; undo the signal stack.
  948. */
  949. long sys_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8,
  950. struct pt_regs *regs)
  951. {
  952. struct sigcontext __user *sc;
  953. struct sigcontext sigctx;
  954. struct mcontext __user *sr;
  955. sigset_t set;
  956. /* Always make any pending restarted system calls return -EINTR */
  957. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  958. sc = (struct sigcontext __user *)(regs->gpr[1] + __SIGNAL_FRAMESIZE);
  959. if (copy_from_user(&sigctx, sc, sizeof(sigctx)))
  960. goto badframe;
  961. #ifdef CONFIG_PPC64
  962. /*
  963. * Note that PPC32 puts the upper 32 bits of the sigmask in the
  964. * unused part of the signal stackframe
  965. */
  966. set.sig[0] = sigctx.oldmask + ((long)(sigctx._unused[3]) << 32);
  967. #else
  968. set.sig[0] = sigctx.oldmask;
  969. set.sig[1] = sigctx._unused[3];
  970. #endif
  971. restore_sigmask(&set);
  972. sr = (struct mcontext __user *)from_user_ptr(sigctx.regs);
  973. if (!access_ok(VERIFY_READ, sr, sizeof(*sr))
  974. || restore_user_regs(regs, sr, 1))
  975. goto badframe;
  976. set_thread_flag(TIF_RESTOREALL);
  977. return 0;
  978. badframe:
  979. force_sig(SIGSEGV, current);
  980. return 0;
  981. }
  982. /*
  983. * Note that 'init' is a special process: it doesn't get signals it doesn't
  984. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  985. * mistake.
  986. */
  987. int do_signal(sigset_t *oldset, struct pt_regs *regs)
  988. {
  989. siginfo_t info;
  990. struct k_sigaction ka;
  991. unsigned int newsp;
  992. int signr, ret;
  993. #ifdef CONFIG_PPC32
  994. if (try_to_freeze()) {
  995. signr = 0;
  996. if (!signal_pending(current))
  997. goto no_signal;
  998. }
  999. #endif
  1000. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  1001. oldset = &current->saved_sigmask;
  1002. else if (!oldset)
  1003. oldset = &current->blocked;
  1004. signr = get_signal_to_deliver(&info, &ka, regs, NULL);
  1005. #ifdef CONFIG_PPC32
  1006. no_signal:
  1007. #endif
  1008. if (TRAP(regs) == 0x0C00 /* System Call! */
  1009. && regs->ccr & 0x10000000 /* error signalled */
  1010. && ((ret = regs->gpr[3]) == ERESTARTSYS
  1011. || ret == ERESTARTNOHAND || ret == ERESTARTNOINTR
  1012. || ret == ERESTART_RESTARTBLOCK)) {
  1013. if (signr > 0
  1014. && (ret == ERESTARTNOHAND || ret == ERESTART_RESTARTBLOCK
  1015. || (ret == ERESTARTSYS
  1016. && !(ka.sa.sa_flags & SA_RESTART)))) {
  1017. /* make the system call return an EINTR error */
  1018. regs->result = -EINTR;
  1019. regs->gpr[3] = EINTR;
  1020. /* note that the cr0.SO bit is already set */
  1021. } else {
  1022. regs->nip -= 4; /* Back up & retry system call */
  1023. regs->result = 0;
  1024. regs->trap = 0;
  1025. if (ret == ERESTART_RESTARTBLOCK)
  1026. regs->gpr[0] = __NR_restart_syscall;
  1027. else
  1028. regs->gpr[3] = regs->orig_gpr3;
  1029. }
  1030. }
  1031. if (signr == 0) {
  1032. /* No signal to deliver -- put the saved sigmask back */
  1033. if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
  1034. clear_thread_flag(TIF_RESTORE_SIGMASK);
  1035. sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
  1036. }
  1037. return 0; /* no signals delivered */
  1038. }
  1039. if ((ka.sa.sa_flags & SA_ONSTACK) && current->sas_ss_size
  1040. && !on_sig_stack(regs->gpr[1]))
  1041. newsp = current->sas_ss_sp + current->sas_ss_size;
  1042. else
  1043. newsp = regs->gpr[1];
  1044. newsp &= ~0xfUL;
  1045. #ifdef CONFIG_PPC64
  1046. /*
  1047. * Reenable the DABR before delivering the signal to
  1048. * user space. The DABR will have been cleared if it
  1049. * triggered inside the kernel.
  1050. */
  1051. if (current->thread.dabr)
  1052. set_dabr(current->thread.dabr);
  1053. #endif
  1054. /* Whee! Actually deliver the signal. */
  1055. if (ka.sa.sa_flags & SA_SIGINFO)
  1056. ret = handle_rt_signal(signr, &ka, &info, oldset, regs, newsp);
  1057. else
  1058. ret = handle_signal(signr, &ka, &info, oldset, regs, newsp);
  1059. if (ret) {
  1060. spin_lock_irq(&current->sighand->siglock);
  1061. sigorsets(&current->blocked, &current->blocked,
  1062. &ka.sa.sa_mask);
  1063. if (!(ka.sa.sa_flags & SA_NODEFER))
  1064. sigaddset(&current->blocked, signr);
  1065. recalc_sigpending();
  1066. spin_unlock_irq(&current->sighand->siglock);
  1067. /* A signal was successfully delivered; the saved sigmask is in
  1068. its frame, and we can clear the TIF_RESTORE_SIGMASK flag */
  1069. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  1070. clear_thread_flag(TIF_RESTORE_SIGMASK);
  1071. }
  1072. return ret;
  1073. }