signal_32.c 34 KB

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