signal_32.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259
  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. /*
  439. * Do this before updating the thread state in
  440. * current->thread.fpr/vr/evr. That way, if we get preempted
  441. * and another task grabs the FPU/Altivec/SPE, it won't be
  442. * tempted to save the current CPU state into the thread_struct
  443. * and corrupt what we are writing there.
  444. */
  445. discard_lazy_cpu_state();
  446. /* force the process to reload the FP registers from
  447. current->thread when it next does FP instructions */
  448. regs->msr &= ~(MSR_FP | MSR_FE0 | MSR_FE1);
  449. if (__copy_from_user(current->thread.fpr, &sr->mc_fregs,
  450. sizeof(sr->mc_fregs)))
  451. return 1;
  452. #ifdef CONFIG_ALTIVEC
  453. /* force the process to reload the altivec registers from
  454. current->thread when it next does altivec instructions */
  455. regs->msr &= ~MSR_VEC;
  456. if (!__get_user(msr, &sr->mc_gregs[PT_MSR]) && (msr & MSR_VEC) != 0) {
  457. /* restore altivec registers from the stack */
  458. if (__copy_from_user(current->thread.vr, &sr->mc_vregs,
  459. sizeof(sr->mc_vregs)))
  460. return 1;
  461. } else if (current->thread.used_vr)
  462. memset(current->thread.vr, 0, ELF_NVRREG * sizeof(vector128));
  463. /* Always get VRSAVE back */
  464. if (__get_user(current->thread.vrsave, (u32 __user *)&sr->mc_vregs[32]))
  465. return 1;
  466. #endif /* CONFIG_ALTIVEC */
  467. #ifdef CONFIG_SPE
  468. /* force the process to reload the spe registers from
  469. current->thread when it next does spe instructions */
  470. regs->msr &= ~MSR_SPE;
  471. if (!__get_user(msr, &sr->mc_gregs[PT_MSR]) && (msr & MSR_SPE) != 0) {
  472. /* restore spe registers from the stack */
  473. if (__copy_from_user(current->thread.evr, &sr->mc_vregs,
  474. ELF_NEVRREG * sizeof(u32)))
  475. return 1;
  476. } else if (current->thread.used_spe)
  477. memset(current->thread.evr, 0, ELF_NEVRREG * sizeof(u32));
  478. /* Always get SPEFSCR back */
  479. if (__get_user(current->thread.spefscr, (u32 __user *)&sr->mc_vregs + ELF_NEVRREG))
  480. return 1;
  481. #endif /* CONFIG_SPE */
  482. return 0;
  483. }
  484. #ifdef CONFIG_PPC64
  485. long compat_sys_rt_sigaction(int sig, const struct sigaction32 __user *act,
  486. struct sigaction32 __user *oact, size_t sigsetsize)
  487. {
  488. struct k_sigaction new_ka, old_ka;
  489. int ret;
  490. /* XXX: Don't preclude handling different sized sigset_t's. */
  491. if (sigsetsize != sizeof(compat_sigset_t))
  492. return -EINVAL;
  493. if (act) {
  494. compat_uptr_t handler;
  495. ret = get_user(handler, &act->sa_handler);
  496. new_ka.sa.sa_handler = compat_ptr(handler);
  497. ret |= get_sigset_t(&new_ka.sa.sa_mask, &act->sa_mask);
  498. ret |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  499. if (ret)
  500. return -EFAULT;
  501. }
  502. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  503. if (!ret && oact) {
  504. ret = put_user((long)old_ka.sa.sa_handler, &oact->sa_handler);
  505. ret |= put_sigset_t(&oact->sa_mask, &old_ka.sa.sa_mask);
  506. ret |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  507. }
  508. return ret;
  509. }
  510. /*
  511. * Note: it is necessary to treat how as an unsigned int, with the
  512. * corresponding cast to a signed int to insure that the proper
  513. * conversion (sign extension) between the register representation
  514. * of a signed int (msr in 32-bit mode) and the register representation
  515. * of a signed int (msr in 64-bit mode) is performed.
  516. */
  517. long compat_sys_rt_sigprocmask(u32 how, compat_sigset_t __user *set,
  518. compat_sigset_t __user *oset, size_t sigsetsize)
  519. {
  520. sigset_t s;
  521. sigset_t __user *up;
  522. int ret;
  523. mm_segment_t old_fs = get_fs();
  524. if (set) {
  525. if (get_sigset_t(&s, set))
  526. return -EFAULT;
  527. }
  528. set_fs(KERNEL_DS);
  529. /* This is valid because of the set_fs() */
  530. up = (sigset_t __user *) &s;
  531. ret = sys_rt_sigprocmask((int)how, set ? up : NULL, oset ? up : NULL,
  532. sigsetsize);
  533. set_fs(old_fs);
  534. if (ret)
  535. return ret;
  536. if (oset) {
  537. if (put_sigset_t(oset, &s))
  538. return -EFAULT;
  539. }
  540. return 0;
  541. }
  542. long compat_sys_rt_sigpending(compat_sigset_t __user *set, compat_size_t sigsetsize)
  543. {
  544. sigset_t s;
  545. int ret;
  546. mm_segment_t old_fs = get_fs();
  547. set_fs(KERNEL_DS);
  548. /* The __user pointer cast is valid because of the set_fs() */
  549. ret = sys_rt_sigpending((sigset_t __user *) &s, sigsetsize);
  550. set_fs(old_fs);
  551. if (!ret) {
  552. if (put_sigset_t(set, &s))
  553. return -EFAULT;
  554. }
  555. return ret;
  556. }
  557. int copy_siginfo_to_user32(struct compat_siginfo __user *d, siginfo_t *s)
  558. {
  559. int err;
  560. if (!access_ok (VERIFY_WRITE, d, sizeof(*d)))
  561. return -EFAULT;
  562. /* If you change siginfo_t structure, please be sure
  563. * this code is fixed accordingly.
  564. * It should never copy any pad contained in the structure
  565. * to avoid security leaks, but must copy the generic
  566. * 3 ints plus the relevant union member.
  567. * This routine must convert siginfo from 64bit to 32bit as well
  568. * at the same time.
  569. */
  570. err = __put_user(s->si_signo, &d->si_signo);
  571. err |= __put_user(s->si_errno, &d->si_errno);
  572. err |= __put_user((short)s->si_code, &d->si_code);
  573. if (s->si_code < 0)
  574. err |= __copy_to_user(&d->_sifields._pad, &s->_sifields._pad,
  575. SI_PAD_SIZE32);
  576. else switch(s->si_code >> 16) {
  577. case __SI_CHLD >> 16:
  578. err |= __put_user(s->si_pid, &d->si_pid);
  579. err |= __put_user(s->si_uid, &d->si_uid);
  580. err |= __put_user(s->si_utime, &d->si_utime);
  581. err |= __put_user(s->si_stime, &d->si_stime);
  582. err |= __put_user(s->si_status, &d->si_status);
  583. break;
  584. case __SI_FAULT >> 16:
  585. err |= __put_user((unsigned int)(unsigned long)s->si_addr,
  586. &d->si_addr);
  587. break;
  588. case __SI_POLL >> 16:
  589. err |= __put_user(s->si_band, &d->si_band);
  590. err |= __put_user(s->si_fd, &d->si_fd);
  591. break;
  592. case __SI_TIMER >> 16:
  593. err |= __put_user(s->si_tid, &d->si_tid);
  594. err |= __put_user(s->si_overrun, &d->si_overrun);
  595. err |= __put_user(s->si_int, &d->si_int);
  596. break;
  597. case __SI_RT >> 16: /* This is not generated by the kernel as of now. */
  598. case __SI_MESGQ >> 16:
  599. err |= __put_user(s->si_int, &d->si_int);
  600. /* fallthrough */
  601. case __SI_KILL >> 16:
  602. default:
  603. err |= __put_user(s->si_pid, &d->si_pid);
  604. err |= __put_user(s->si_uid, &d->si_uid);
  605. break;
  606. }
  607. return err;
  608. }
  609. #define copy_siginfo_to_user copy_siginfo_to_user32
  610. /*
  611. * Note: it is necessary to treat pid and sig as unsigned ints, with the
  612. * corresponding cast to a signed int to insure that the proper conversion
  613. * (sign extension) between the register representation of a signed int
  614. * (msr in 32-bit mode) and the register representation of a signed int
  615. * (msr in 64-bit mode) is performed.
  616. */
  617. long compat_sys_rt_sigqueueinfo(u32 pid, u32 sig, compat_siginfo_t __user *uinfo)
  618. {
  619. siginfo_t info;
  620. int ret;
  621. mm_segment_t old_fs = get_fs();
  622. if (copy_from_user (&info, uinfo, 3*sizeof(int)) ||
  623. copy_from_user (info._sifields._pad, uinfo->_sifields._pad, SI_PAD_SIZE32))
  624. return -EFAULT;
  625. set_fs (KERNEL_DS);
  626. /* The __user pointer cast is valid becasuse of the set_fs() */
  627. ret = sys_rt_sigqueueinfo((int)pid, (int)sig, (siginfo_t __user *) &info);
  628. set_fs (old_fs);
  629. return ret;
  630. }
  631. /*
  632. * Start Alternate signal stack support
  633. *
  634. * System Calls
  635. * sigaltatck compat_sys_sigaltstack
  636. */
  637. int compat_sys_sigaltstack(u32 __new, u32 __old, int r5,
  638. int r6, int r7, int r8, struct pt_regs *regs)
  639. {
  640. stack_32_t __user * newstack = (stack_32_t __user *)(long) __new;
  641. stack_32_t __user * oldstack = (stack_32_t __user *)(long) __old;
  642. stack_t uss, uoss;
  643. int ret;
  644. mm_segment_t old_fs;
  645. unsigned long sp;
  646. compat_uptr_t ss_sp;
  647. /*
  648. * set sp to the user stack on entry to the system call
  649. * the system call router sets R9 to the saved registers
  650. */
  651. sp = regs->gpr[1];
  652. /* Put new stack info in local 64 bit stack struct */
  653. if (newstack) {
  654. if (get_user(ss_sp, &newstack->ss_sp) ||
  655. __get_user(uss.ss_flags, &newstack->ss_flags) ||
  656. __get_user(uss.ss_size, &newstack->ss_size))
  657. return -EFAULT;
  658. uss.ss_sp = compat_ptr(ss_sp);
  659. }
  660. old_fs = get_fs();
  661. set_fs(KERNEL_DS);
  662. /* The __user pointer casts are valid because of the set_fs() */
  663. ret = do_sigaltstack(
  664. newstack ? (stack_t __user *) &uss : NULL,
  665. oldstack ? (stack_t __user *) &uoss : NULL,
  666. sp);
  667. set_fs(old_fs);
  668. /* Copy the stack information to the user output buffer */
  669. if (!ret && oldstack &&
  670. (put_user((long)uoss.ss_sp, &oldstack->ss_sp) ||
  671. __put_user(uoss.ss_flags, &oldstack->ss_flags) ||
  672. __put_user(uoss.ss_size, &oldstack->ss_size)))
  673. return -EFAULT;
  674. return ret;
  675. }
  676. #endif /* CONFIG_PPC64 */
  677. /*
  678. * Restore the user process's signal mask
  679. */
  680. #ifdef CONFIG_PPC64
  681. extern void restore_sigmask(sigset_t *set);
  682. #else /* CONFIG_PPC64 */
  683. static void restore_sigmask(sigset_t *set)
  684. {
  685. sigdelsetmask(set, ~_BLOCKABLE);
  686. spin_lock_irq(&current->sighand->siglock);
  687. current->blocked = *set;
  688. recalc_sigpending();
  689. spin_unlock_irq(&current->sighand->siglock);
  690. }
  691. #endif
  692. /*
  693. * Set up a signal frame for a "real-time" signal handler
  694. * (one which gets siginfo).
  695. */
  696. static int handle_rt_signal(unsigned long sig, struct k_sigaction *ka,
  697. siginfo_t *info, sigset_t *oldset,
  698. struct pt_regs *regs, unsigned long newsp)
  699. {
  700. struct rt_sigframe __user *rt_sf;
  701. struct mcontext __user *frame;
  702. unsigned long origsp = newsp;
  703. /* Set up Signal Frame */
  704. /* Put a Real Time Context onto stack */
  705. newsp -= sizeof(*rt_sf);
  706. rt_sf = (struct rt_sigframe __user *)newsp;
  707. /* create a stack frame for the caller of the handler */
  708. newsp -= __SIGNAL_FRAMESIZE + 16;
  709. if (!access_ok(VERIFY_WRITE, (void __user *)newsp, origsp - newsp))
  710. goto badframe;
  711. /* Put the siginfo & fill in most of the ucontext */
  712. if (copy_siginfo_to_user(&rt_sf->info, info)
  713. || __put_user(0, &rt_sf->uc.uc_flags)
  714. || __put_user(0, &rt_sf->uc.uc_link)
  715. || __put_user(current->sas_ss_sp, &rt_sf->uc.uc_stack.ss_sp)
  716. || __put_user(sas_ss_flags(regs->gpr[1]),
  717. &rt_sf->uc.uc_stack.ss_flags)
  718. || __put_user(current->sas_ss_size, &rt_sf->uc.uc_stack.ss_size)
  719. || __put_user(to_user_ptr(&rt_sf->uc.uc_mcontext),
  720. &rt_sf->uc.uc_regs)
  721. || put_sigset_t(&rt_sf->uc.uc_sigmask, oldset))
  722. goto badframe;
  723. /* Save user registers on the stack */
  724. frame = &rt_sf->uc.uc_mcontext;
  725. if (vdso32_rt_sigtramp && current->thread.vdso_base) {
  726. if (save_user_regs(regs, frame, 0))
  727. goto badframe;
  728. regs->link = current->thread.vdso_base + vdso32_rt_sigtramp;
  729. } else {
  730. if (save_user_regs(regs, frame, __NR_rt_sigreturn))
  731. goto badframe;
  732. regs->link = (unsigned long) frame->tramp;
  733. }
  734. current->thread.fpscr.val = 0; /* turn off all fp exceptions */
  735. if (put_user(regs->gpr[1], (u32 __user *)newsp))
  736. goto badframe;
  737. regs->gpr[1] = newsp;
  738. regs->gpr[3] = sig;
  739. regs->gpr[4] = (unsigned long) &rt_sf->info;
  740. regs->gpr[5] = (unsigned long) &rt_sf->uc;
  741. regs->gpr[6] = (unsigned long) rt_sf;
  742. regs->nip = (unsigned long) ka->sa.sa_handler;
  743. regs->trap = 0;
  744. return 1;
  745. badframe:
  746. #ifdef DEBUG_SIG
  747. printk("badframe in handle_rt_signal, regs=%p frame=%p newsp=%lx\n",
  748. regs, frame, newsp);
  749. #endif
  750. force_sigsegv(sig, current);
  751. return 0;
  752. }
  753. static int do_setcontext(struct ucontext __user *ucp, struct pt_regs *regs, int sig)
  754. {
  755. sigset_t set;
  756. struct mcontext __user *mcp;
  757. if (get_sigset_t(&set, &ucp->uc_sigmask))
  758. return -EFAULT;
  759. #ifdef CONFIG_PPC64
  760. {
  761. u32 cmcp;
  762. if (__get_user(cmcp, &ucp->uc_regs))
  763. return -EFAULT;
  764. mcp = (struct mcontext __user *)(u64)cmcp;
  765. }
  766. #else
  767. if (__get_user(mcp, &ucp->uc_regs))
  768. return -EFAULT;
  769. #endif
  770. restore_sigmask(&set);
  771. if (restore_user_regs(regs, mcp, sig))
  772. return -EFAULT;
  773. return 0;
  774. }
  775. long sys_swapcontext(struct ucontext __user *old_ctx,
  776. struct ucontext __user *new_ctx,
  777. int ctx_size, int r6, int r7, int r8, struct pt_regs *regs)
  778. {
  779. unsigned char tmp;
  780. /* Context size is for future use. Right now, we only make sure
  781. * we are passed something we understand
  782. */
  783. if (ctx_size < sizeof(struct ucontext))
  784. return -EINVAL;
  785. if (old_ctx != NULL) {
  786. if (!access_ok(VERIFY_WRITE, old_ctx, sizeof(*old_ctx))
  787. || save_user_regs(regs, &old_ctx->uc_mcontext, 0)
  788. || put_sigset_t(&old_ctx->uc_sigmask, &current->blocked)
  789. || __put_user(to_user_ptr(&old_ctx->uc_mcontext),
  790. &old_ctx->uc_regs))
  791. return -EFAULT;
  792. }
  793. if (new_ctx == NULL)
  794. return 0;
  795. if (!access_ok(VERIFY_READ, new_ctx, sizeof(*new_ctx))
  796. || __get_user(tmp, (u8 __user *) new_ctx)
  797. || __get_user(tmp, (u8 __user *) (new_ctx + 1) - 1))
  798. return -EFAULT;
  799. /*
  800. * If we get a fault copying the context into the kernel's
  801. * image of the user's registers, we can't just return -EFAULT
  802. * because the user's registers will be corrupted. For instance
  803. * the NIP value may have been updated but not some of the
  804. * other registers. Given that we have done the access_ok
  805. * and successfully read the first and last bytes of the region
  806. * above, this should only happen in an out-of-memory situation
  807. * or if another thread unmaps the region containing the context.
  808. * We kill the task with a SIGSEGV in this situation.
  809. */
  810. if (do_setcontext(new_ctx, regs, 0))
  811. do_exit(SIGSEGV);
  812. set_thread_flag(TIF_RESTOREALL);
  813. return 0;
  814. }
  815. long sys_rt_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8,
  816. struct pt_regs *regs)
  817. {
  818. struct rt_sigframe __user *rt_sf;
  819. /* Always make any pending restarted system calls return -EINTR */
  820. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  821. rt_sf = (struct rt_sigframe __user *)
  822. (regs->gpr[1] + __SIGNAL_FRAMESIZE + 16);
  823. if (!access_ok(VERIFY_READ, rt_sf, sizeof(*rt_sf)))
  824. goto bad;
  825. if (do_setcontext(&rt_sf->uc, regs, 1))
  826. goto bad;
  827. /*
  828. * It's not clear whether or why it is desirable to save the
  829. * sigaltstack setting on signal delivery and restore it on
  830. * signal return. But other architectures do this and we have
  831. * always done it up until now so it is probably better not to
  832. * change it. -- paulus
  833. */
  834. #ifdef CONFIG_PPC64
  835. /*
  836. * We use the compat_sys_ version that does the 32/64 bits conversion
  837. * and takes userland pointer directly. What about error checking ?
  838. * nobody does any...
  839. */
  840. compat_sys_sigaltstack((u32)(u64)&rt_sf->uc.uc_stack, 0, 0, 0, 0, 0, regs);
  841. #else
  842. do_sigaltstack(&rt_sf->uc.uc_stack, NULL, regs->gpr[1]);
  843. #endif
  844. set_thread_flag(TIF_RESTOREALL);
  845. return 0;
  846. bad:
  847. force_sig(SIGSEGV, current);
  848. return 0;
  849. }
  850. #ifdef CONFIG_PPC32
  851. int sys_debug_setcontext(struct ucontext __user *ctx,
  852. int ndbg, struct sig_dbg_op __user *dbg,
  853. int r6, int r7, int r8,
  854. struct pt_regs *regs)
  855. {
  856. struct sig_dbg_op op;
  857. int i;
  858. unsigned long new_msr = regs->msr;
  859. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  860. unsigned long new_dbcr0 = current->thread.dbcr0;
  861. #endif
  862. for (i=0; i<ndbg; i++) {
  863. if (__copy_from_user(&op, dbg, sizeof(op)))
  864. return -EFAULT;
  865. switch (op.dbg_type) {
  866. case SIG_DBG_SINGLE_STEPPING:
  867. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  868. if (op.dbg_value) {
  869. new_msr |= MSR_DE;
  870. new_dbcr0 |= (DBCR0_IDM | DBCR0_IC);
  871. } else {
  872. new_msr &= ~MSR_DE;
  873. new_dbcr0 &= ~(DBCR0_IDM | DBCR0_IC);
  874. }
  875. #else
  876. if (op.dbg_value)
  877. new_msr |= MSR_SE;
  878. else
  879. new_msr &= ~MSR_SE;
  880. #endif
  881. break;
  882. case SIG_DBG_BRANCH_TRACING:
  883. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  884. return -EINVAL;
  885. #else
  886. if (op.dbg_value)
  887. new_msr |= MSR_BE;
  888. else
  889. new_msr &= ~MSR_BE;
  890. #endif
  891. break;
  892. default:
  893. return -EINVAL;
  894. }
  895. }
  896. /* We wait until here to actually install the values in the
  897. registers so if we fail in the above loop, it will not
  898. affect the contents of these registers. After this point,
  899. failure is a problem, anyway, and it's very unlikely unless
  900. the user is really doing something wrong. */
  901. regs->msr = new_msr;
  902. #if defined(CONFIG_4xx) || defined(CONFIG_BOOKE)
  903. current->thread.dbcr0 = new_dbcr0;
  904. #endif
  905. /*
  906. * If we get a fault copying the context into the kernel's
  907. * image of the user's registers, we can't just return -EFAULT
  908. * because the user's registers will be corrupted. For instance
  909. * the NIP value may have been updated but not some of the
  910. * other registers. Given that we have done the access_ok
  911. * and successfully read the first and last bytes of the region
  912. * above, this should only happen in an out-of-memory situation
  913. * or if another thread unmaps the region containing the context.
  914. * We kill the task with a SIGSEGV in this situation.
  915. */
  916. if (do_setcontext(ctx, regs, 1)) {
  917. force_sig(SIGSEGV, current);
  918. goto out;
  919. }
  920. /*
  921. * It's not clear whether or why it is desirable to save the
  922. * sigaltstack setting on signal delivery and restore it on
  923. * signal return. But other architectures do this and we have
  924. * always done it up until now so it is probably better not to
  925. * change it. -- paulus
  926. */
  927. do_sigaltstack(&ctx->uc_stack, NULL, regs->gpr[1]);
  928. set_thread_flag(TIF_RESTOREALL);
  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. if (vdso32_sigtramp && current->thread.vdso_base) {
  967. if (save_user_regs(regs, &frame->mctx, 0))
  968. goto badframe;
  969. regs->link = current->thread.vdso_base + vdso32_sigtramp;
  970. } else {
  971. if (save_user_regs(regs, &frame->mctx, __NR_sigreturn))
  972. goto badframe;
  973. regs->link = (unsigned long) frame->mctx.tramp;
  974. }
  975. current->thread.fpscr.val = 0; /* turn off all fp exceptions */
  976. if (put_user(regs->gpr[1], (u32 __user *)newsp))
  977. goto badframe;
  978. regs->gpr[1] = newsp;
  979. regs->gpr[3] = sig;
  980. regs->gpr[4] = (unsigned long) sc;
  981. regs->nip = (unsigned long) ka->sa.sa_handler;
  982. regs->trap = 0;
  983. return 1;
  984. badframe:
  985. #ifdef DEBUG_SIG
  986. printk("badframe in handle_signal, regs=%p frame=%p newsp=%lx\n",
  987. regs, frame, newsp);
  988. #endif
  989. force_sigsegv(sig, current);
  990. return 0;
  991. }
  992. /*
  993. * Do a signal return; undo the signal stack.
  994. */
  995. long sys_sigreturn(int r3, int r4, int r5, int r6, int r7, int r8,
  996. struct pt_regs *regs)
  997. {
  998. struct sigcontext __user *sc;
  999. struct sigcontext sigctx;
  1000. struct mcontext __user *sr;
  1001. sigset_t set;
  1002. /* Always make any pending restarted system calls return -EINTR */
  1003. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  1004. sc = (struct sigcontext __user *)(regs->gpr[1] + __SIGNAL_FRAMESIZE);
  1005. if (copy_from_user(&sigctx, sc, sizeof(sigctx)))
  1006. goto badframe;
  1007. #ifdef CONFIG_PPC64
  1008. /*
  1009. * Note that PPC32 puts the upper 32 bits of the sigmask in the
  1010. * unused part of the signal stackframe
  1011. */
  1012. set.sig[0] = sigctx.oldmask + ((long)(sigctx._unused[3]) << 32);
  1013. #else
  1014. set.sig[0] = sigctx.oldmask;
  1015. set.sig[1] = sigctx._unused[3];
  1016. #endif
  1017. restore_sigmask(&set);
  1018. sr = (struct mcontext __user *)from_user_ptr(sigctx.regs);
  1019. if (!access_ok(VERIFY_READ, sr, sizeof(*sr))
  1020. || restore_user_regs(regs, sr, 1))
  1021. goto badframe;
  1022. set_thread_flag(TIF_RESTOREALL);
  1023. return 0;
  1024. badframe:
  1025. force_sig(SIGSEGV, current);
  1026. return 0;
  1027. }
  1028. /*
  1029. * Note that 'init' is a special process: it doesn't get signals it doesn't
  1030. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  1031. * mistake.
  1032. */
  1033. int do_signal(sigset_t *oldset, struct pt_regs *regs)
  1034. {
  1035. siginfo_t info;
  1036. struct k_sigaction ka;
  1037. unsigned int frame, newsp;
  1038. int signr, ret;
  1039. #ifdef CONFIG_PPC32
  1040. if (try_to_freeze()) {
  1041. signr = 0;
  1042. if (!signal_pending(current))
  1043. goto no_signal;
  1044. }
  1045. #endif
  1046. if (!oldset)
  1047. oldset = &current->blocked;
  1048. newsp = frame = 0;
  1049. signr = get_signal_to_deliver(&info, &ka, regs, NULL);
  1050. #ifdef CONFIG_PPC32
  1051. no_signal:
  1052. #endif
  1053. if (TRAP(regs) == 0x0C00 /* System Call! */
  1054. && regs->ccr & 0x10000000 /* error signalled */
  1055. && ((ret = regs->gpr[3]) == ERESTARTSYS
  1056. || ret == ERESTARTNOHAND || ret == ERESTARTNOINTR
  1057. || ret == ERESTART_RESTARTBLOCK)) {
  1058. if (signr > 0
  1059. && (ret == ERESTARTNOHAND || ret == ERESTART_RESTARTBLOCK
  1060. || (ret == ERESTARTSYS
  1061. && !(ka.sa.sa_flags & SA_RESTART)))) {
  1062. /* make the system call return an EINTR error */
  1063. regs->result = -EINTR;
  1064. regs->gpr[3] = EINTR;
  1065. /* note that the cr0.SO bit is already set */
  1066. } else {
  1067. regs->nip -= 4; /* Back up & retry system call */
  1068. regs->result = 0;
  1069. regs->trap = 0;
  1070. if (ret == ERESTART_RESTARTBLOCK)
  1071. regs->gpr[0] = __NR_restart_syscall;
  1072. else
  1073. regs->gpr[3] = regs->orig_gpr3;
  1074. }
  1075. }
  1076. if (signr == 0)
  1077. return 0; /* no signals delivered */
  1078. if ((ka.sa.sa_flags & SA_ONSTACK) && current->sas_ss_size
  1079. && !on_sig_stack(regs->gpr[1]))
  1080. newsp = current->sas_ss_sp + current->sas_ss_size;
  1081. else
  1082. newsp = regs->gpr[1];
  1083. newsp &= ~0xfUL;
  1084. #ifdef CONFIG_PPC64
  1085. /*
  1086. * Reenable the DABR before delivering the signal to
  1087. * user space. The DABR will have been cleared if it
  1088. * triggered inside the kernel.
  1089. */
  1090. if (current->thread.dabr)
  1091. set_dabr(current->thread.dabr);
  1092. #endif
  1093. /* Whee! Actually deliver the signal. */
  1094. if (ka.sa.sa_flags & SA_SIGINFO)
  1095. ret = handle_rt_signal(signr, &ka, &info, oldset, regs, newsp);
  1096. else
  1097. ret = handle_signal(signr, &ka, &info, oldset, regs, newsp);
  1098. if (ret) {
  1099. spin_lock_irq(&current->sighand->siglock);
  1100. sigorsets(&current->blocked, &current->blocked,
  1101. &ka.sa.sa_mask);
  1102. if (!(ka.sa.sa_flags & SA_NODEFER))
  1103. sigaddset(&current->blocked, signr);
  1104. recalc_sigpending();
  1105. spin_unlock_irq(&current->sighand->siglock);
  1106. }
  1107. return ret;
  1108. }