signal_32.c 34 KB

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