signal_32.c 34 KB

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