signal_32.c 33 KB

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