signal_32.c 34 KB

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