signal_32.c 34 KB

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