signal32.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * Based on arch/arm/kernel/signal.c
  3. *
  4. * Copyright (C) 1995-2009 Russell King
  5. * Copyright (C) 2012 ARM Ltd.
  6. * Modified by Will Deacon <will.deacon@arm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <linux/compat.h>
  21. #include <linux/signal.h>
  22. #include <linux/syscalls.h>
  23. #include <linux/ratelimit.h>
  24. #include <asm/fpsimd.h>
  25. #include <asm/signal32.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/unistd32.h>
  28. struct compat_old_sigaction {
  29. compat_uptr_t sa_handler;
  30. compat_old_sigset_t sa_mask;
  31. compat_ulong_t sa_flags;
  32. compat_uptr_t sa_restorer;
  33. };
  34. struct compat_sigcontext {
  35. /* We always set these two fields to 0 */
  36. compat_ulong_t trap_no;
  37. compat_ulong_t error_code;
  38. compat_ulong_t oldmask;
  39. compat_ulong_t arm_r0;
  40. compat_ulong_t arm_r1;
  41. compat_ulong_t arm_r2;
  42. compat_ulong_t arm_r3;
  43. compat_ulong_t arm_r4;
  44. compat_ulong_t arm_r5;
  45. compat_ulong_t arm_r6;
  46. compat_ulong_t arm_r7;
  47. compat_ulong_t arm_r8;
  48. compat_ulong_t arm_r9;
  49. compat_ulong_t arm_r10;
  50. compat_ulong_t arm_fp;
  51. compat_ulong_t arm_ip;
  52. compat_ulong_t arm_sp;
  53. compat_ulong_t arm_lr;
  54. compat_ulong_t arm_pc;
  55. compat_ulong_t arm_cpsr;
  56. compat_ulong_t fault_address;
  57. };
  58. struct compat_ucontext {
  59. compat_ulong_t uc_flags;
  60. struct compat_ucontext *uc_link;
  61. compat_stack_t uc_stack;
  62. struct compat_sigcontext uc_mcontext;
  63. compat_sigset_t uc_sigmask;
  64. int __unused[32 - (sizeof (compat_sigset_t) / sizeof (int))];
  65. compat_ulong_t uc_regspace[128] __attribute__((__aligned__(8)));
  66. };
  67. struct compat_vfp_sigframe {
  68. compat_ulong_t magic;
  69. compat_ulong_t size;
  70. struct compat_user_vfp {
  71. compat_u64 fpregs[32];
  72. compat_ulong_t fpscr;
  73. } ufp;
  74. struct compat_user_vfp_exc {
  75. compat_ulong_t fpexc;
  76. compat_ulong_t fpinst;
  77. compat_ulong_t fpinst2;
  78. } ufp_exc;
  79. } __attribute__((__aligned__(8)));
  80. #define VFP_MAGIC 0x56465001
  81. #define VFP_STORAGE_SIZE sizeof(struct compat_vfp_sigframe)
  82. struct compat_aux_sigframe {
  83. struct compat_vfp_sigframe vfp;
  84. /* Something that isn't a valid magic number for any coprocessor. */
  85. unsigned long end_magic;
  86. } __attribute__((__aligned__(8)));
  87. struct compat_sigframe {
  88. struct compat_ucontext uc;
  89. compat_ulong_t retcode[2];
  90. };
  91. struct compat_rt_sigframe {
  92. struct compat_siginfo info;
  93. struct compat_sigframe sig;
  94. };
  95. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  96. /*
  97. * For ARM syscalls, the syscall number has to be loaded into r7.
  98. * We do not support an OABI userspace.
  99. */
  100. #define MOV_R7_NR_SIGRETURN (0xe3a07000 | __NR_compat_sigreturn)
  101. #define SVC_SYS_SIGRETURN (0xef000000 | __NR_compat_sigreturn)
  102. #define MOV_R7_NR_RT_SIGRETURN (0xe3a07000 | __NR_compat_rt_sigreturn)
  103. #define SVC_SYS_RT_SIGRETURN (0xef000000 | __NR_compat_rt_sigreturn)
  104. /*
  105. * For Thumb syscalls, we also pass the syscall number via r7. We therefore
  106. * need two 16-bit instructions.
  107. */
  108. #define SVC_THUMB_SIGRETURN (((0xdf00 | __NR_compat_sigreturn) << 16) | \
  109. 0x2700 | __NR_compat_sigreturn)
  110. #define SVC_THUMB_RT_SIGRETURN (((0xdf00 | __NR_compat_rt_sigreturn) << 16) | \
  111. 0x2700 | __NR_compat_rt_sigreturn)
  112. const compat_ulong_t aarch32_sigret_code[6] = {
  113. /*
  114. * AArch32 sigreturn code.
  115. * We don't construct an OABI SWI - instead we just set the imm24 field
  116. * to the EABI syscall number so that we create a sane disassembly.
  117. */
  118. MOV_R7_NR_SIGRETURN, SVC_SYS_SIGRETURN, SVC_THUMB_SIGRETURN,
  119. MOV_R7_NR_RT_SIGRETURN, SVC_SYS_RT_SIGRETURN, SVC_THUMB_RT_SIGRETURN,
  120. };
  121. static inline int put_sigset_t(compat_sigset_t __user *uset, sigset_t *set)
  122. {
  123. compat_sigset_t cset;
  124. cset.sig[0] = set->sig[0] & 0xffffffffull;
  125. cset.sig[1] = set->sig[0] >> 32;
  126. return copy_to_user(uset, &cset, sizeof(*uset));
  127. }
  128. static inline int get_sigset_t(sigset_t *set,
  129. const compat_sigset_t __user *uset)
  130. {
  131. compat_sigset_t s32;
  132. if (copy_from_user(&s32, uset, sizeof(*uset)))
  133. return -EFAULT;
  134. set->sig[0] = s32.sig[0] | (((long)s32.sig[1]) << 32);
  135. return 0;
  136. }
  137. int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from)
  138. {
  139. int err;
  140. if (!access_ok(VERIFY_WRITE, to, sizeof(*to)))
  141. return -EFAULT;
  142. /* If you change siginfo_t structure, please be sure
  143. * this code is fixed accordingly.
  144. * It should never copy any pad contained in the structure
  145. * to avoid security leaks, but must copy the generic
  146. * 3 ints plus the relevant union member.
  147. * This routine must convert siginfo from 64bit to 32bit as well
  148. * at the same time.
  149. */
  150. err = __put_user(from->si_signo, &to->si_signo);
  151. err |= __put_user(from->si_errno, &to->si_errno);
  152. err |= __put_user((short)from->si_code, &to->si_code);
  153. if (from->si_code < 0)
  154. err |= __copy_to_user(&to->_sifields._pad, &from->_sifields._pad,
  155. SI_PAD_SIZE);
  156. else switch (from->si_code & __SI_MASK) {
  157. case __SI_KILL:
  158. err |= __put_user(from->si_pid, &to->si_pid);
  159. err |= __put_user(from->si_uid, &to->si_uid);
  160. break;
  161. case __SI_TIMER:
  162. err |= __put_user(from->si_tid, &to->si_tid);
  163. err |= __put_user(from->si_overrun, &to->si_overrun);
  164. err |= __put_user((compat_uptr_t)(unsigned long)from->si_ptr,
  165. &to->si_ptr);
  166. break;
  167. case __SI_POLL:
  168. err |= __put_user(from->si_band, &to->si_band);
  169. err |= __put_user(from->si_fd, &to->si_fd);
  170. break;
  171. case __SI_FAULT:
  172. err |= __put_user((compat_uptr_t)(unsigned long)from->si_addr,
  173. &to->si_addr);
  174. #ifdef BUS_MCEERR_AO
  175. /*
  176. * Other callers might not initialize the si_lsb field,
  177. * so check explicitely for the right codes here.
  178. */
  179. if (from->si_code == BUS_MCEERR_AR || from->si_code == BUS_MCEERR_AO)
  180. err |= __put_user(from->si_addr_lsb, &to->si_addr_lsb);
  181. #endif
  182. break;
  183. case __SI_CHLD:
  184. err |= __put_user(from->si_pid, &to->si_pid);
  185. err |= __put_user(from->si_uid, &to->si_uid);
  186. err |= __put_user(from->si_status, &to->si_status);
  187. err |= __put_user(from->si_utime, &to->si_utime);
  188. err |= __put_user(from->si_stime, &to->si_stime);
  189. break;
  190. case __SI_RT: /* This is not generated by the kernel as of now. */
  191. case __SI_MESGQ: /* But this is */
  192. err |= __put_user(from->si_pid, &to->si_pid);
  193. err |= __put_user(from->si_uid, &to->si_uid);
  194. err |= __put_user((compat_uptr_t)(unsigned long)from->si_ptr, &to->si_ptr);
  195. break;
  196. default: /* this is just in case for now ... */
  197. err |= __put_user(from->si_pid, &to->si_pid);
  198. err |= __put_user(from->si_uid, &to->si_uid);
  199. break;
  200. }
  201. return err;
  202. }
  203. int copy_siginfo_from_user32(siginfo_t *to, compat_siginfo_t __user *from)
  204. {
  205. memset(to, 0, sizeof *to);
  206. if (copy_from_user(to, from, __ARCH_SI_PREAMBLE_SIZE) ||
  207. copy_from_user(to->_sifields._pad,
  208. from->_sifields._pad, SI_PAD_SIZE))
  209. return -EFAULT;
  210. return 0;
  211. }
  212. /*
  213. * VFP save/restore code.
  214. */
  215. static int compat_preserve_vfp_context(struct compat_vfp_sigframe __user *frame)
  216. {
  217. struct fpsimd_state *fpsimd = &current->thread.fpsimd_state;
  218. compat_ulong_t magic = VFP_MAGIC;
  219. compat_ulong_t size = VFP_STORAGE_SIZE;
  220. compat_ulong_t fpscr, fpexc;
  221. int err = 0;
  222. /*
  223. * Save the hardware registers to the fpsimd_state structure.
  224. * Note that this also saves V16-31, which aren't visible
  225. * in AArch32.
  226. */
  227. fpsimd_save_state(fpsimd);
  228. /* Place structure header on the stack */
  229. __put_user_error(magic, &frame->magic, err);
  230. __put_user_error(size, &frame->size, err);
  231. /*
  232. * Now copy the FP registers. Since the registers are packed,
  233. * we can copy the prefix we want (V0-V15) as it is.
  234. * FIXME: Won't work if big endian.
  235. */
  236. err |= __copy_to_user(&frame->ufp.fpregs, fpsimd->vregs,
  237. sizeof(frame->ufp.fpregs));
  238. /* Create an AArch32 fpscr from the fpsr and the fpcr. */
  239. fpscr = (fpsimd->fpsr & VFP_FPSCR_STAT_MASK) |
  240. (fpsimd->fpcr & VFP_FPSCR_CTRL_MASK);
  241. __put_user_error(fpscr, &frame->ufp.fpscr, err);
  242. /*
  243. * The exception register aren't available so we fake up a
  244. * basic FPEXC and zero everything else.
  245. */
  246. fpexc = (1 << 30);
  247. __put_user_error(fpexc, &frame->ufp_exc.fpexc, err);
  248. __put_user_error(0, &frame->ufp_exc.fpinst, err);
  249. __put_user_error(0, &frame->ufp_exc.fpinst2, err);
  250. return err ? -EFAULT : 0;
  251. }
  252. static int compat_restore_vfp_context(struct compat_vfp_sigframe __user *frame)
  253. {
  254. struct fpsimd_state fpsimd;
  255. compat_ulong_t magic = VFP_MAGIC;
  256. compat_ulong_t size = VFP_STORAGE_SIZE;
  257. compat_ulong_t fpscr;
  258. int err = 0;
  259. __get_user_error(magic, &frame->magic, err);
  260. __get_user_error(size, &frame->size, err);
  261. if (err)
  262. return -EFAULT;
  263. if (magic != VFP_MAGIC || size != VFP_STORAGE_SIZE)
  264. return -EINVAL;
  265. /*
  266. * Copy the FP registers into the start of the fpsimd_state.
  267. * FIXME: Won't work if big endian.
  268. */
  269. err |= __copy_from_user(fpsimd.vregs, frame->ufp.fpregs,
  270. sizeof(frame->ufp.fpregs));
  271. /* Extract the fpsr and the fpcr from the fpscr */
  272. __get_user_error(fpscr, &frame->ufp.fpscr, err);
  273. fpsimd.fpsr = fpscr & VFP_FPSCR_STAT_MASK;
  274. fpsimd.fpcr = fpscr & VFP_FPSCR_CTRL_MASK;
  275. /*
  276. * We don't need to touch the exception register, so
  277. * reload the hardware state.
  278. */
  279. if (!err) {
  280. preempt_disable();
  281. fpsimd_load_state(&fpsimd);
  282. preempt_enable();
  283. }
  284. return err ? -EFAULT : 0;
  285. }
  286. asmlinkage int compat_sys_sigaction(int sig,
  287. const struct compat_old_sigaction __user *act,
  288. struct compat_old_sigaction __user *oact)
  289. {
  290. struct k_sigaction new_ka, old_ka;
  291. int ret;
  292. compat_old_sigset_t mask;
  293. compat_uptr_t handler, restorer;
  294. if (act) {
  295. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  296. __get_user(handler, &act->sa_handler) ||
  297. __get_user(restorer, &act->sa_restorer) ||
  298. __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  299. __get_user(mask, &act->sa_mask))
  300. return -EFAULT;
  301. new_ka.sa.sa_handler = compat_ptr(handler);
  302. new_ka.sa.sa_restorer = compat_ptr(restorer);
  303. siginitset(&new_ka.sa.sa_mask, mask);
  304. }
  305. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  306. if (!ret && oact) {
  307. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  308. __put_user(ptr_to_compat(old_ka.sa.sa_handler),
  309. &oact->sa_handler) ||
  310. __put_user(ptr_to_compat(old_ka.sa.sa_restorer),
  311. &oact->sa_restorer) ||
  312. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  313. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
  314. return -EFAULT;
  315. }
  316. return ret;
  317. }
  318. static int compat_restore_sigframe(struct pt_regs *regs,
  319. struct compat_sigframe __user *sf)
  320. {
  321. int err;
  322. sigset_t set;
  323. struct compat_aux_sigframe __user *aux;
  324. err = get_sigset_t(&set, &sf->uc.uc_sigmask);
  325. if (err == 0) {
  326. sigdelsetmask(&set, ~_BLOCKABLE);
  327. set_current_blocked(&set);
  328. }
  329. __get_user_error(regs->regs[0], &sf->uc.uc_mcontext.arm_r0, err);
  330. __get_user_error(regs->regs[1], &sf->uc.uc_mcontext.arm_r1, err);
  331. __get_user_error(regs->regs[2], &sf->uc.uc_mcontext.arm_r2, err);
  332. __get_user_error(regs->regs[3], &sf->uc.uc_mcontext.arm_r3, err);
  333. __get_user_error(regs->regs[4], &sf->uc.uc_mcontext.arm_r4, err);
  334. __get_user_error(regs->regs[5], &sf->uc.uc_mcontext.arm_r5, err);
  335. __get_user_error(regs->regs[6], &sf->uc.uc_mcontext.arm_r6, err);
  336. __get_user_error(regs->regs[7], &sf->uc.uc_mcontext.arm_r7, err);
  337. __get_user_error(regs->regs[8], &sf->uc.uc_mcontext.arm_r8, err);
  338. __get_user_error(regs->regs[9], &sf->uc.uc_mcontext.arm_r9, err);
  339. __get_user_error(regs->regs[10], &sf->uc.uc_mcontext.arm_r10, err);
  340. __get_user_error(regs->regs[11], &sf->uc.uc_mcontext.arm_fp, err);
  341. __get_user_error(regs->regs[12], &sf->uc.uc_mcontext.arm_ip, err);
  342. __get_user_error(regs->compat_sp, &sf->uc.uc_mcontext.arm_sp, err);
  343. __get_user_error(regs->compat_lr, &sf->uc.uc_mcontext.arm_lr, err);
  344. __get_user_error(regs->pc, &sf->uc.uc_mcontext.arm_pc, err);
  345. __get_user_error(regs->pstate, &sf->uc.uc_mcontext.arm_cpsr, err);
  346. /*
  347. * Avoid compat_sys_sigreturn() restarting.
  348. */
  349. regs->syscallno = ~0UL;
  350. err |= !valid_user_regs(&regs->user_regs);
  351. aux = (struct compat_aux_sigframe __user *) sf->uc.uc_regspace;
  352. if (err == 0)
  353. err |= compat_restore_vfp_context(&aux->vfp);
  354. return err;
  355. }
  356. asmlinkage int compat_sys_sigreturn(struct pt_regs *regs)
  357. {
  358. struct compat_sigframe __user *frame;
  359. /* Always make any pending restarted system calls return -EINTR */
  360. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  361. /*
  362. * Since we stacked the signal on a 64-bit boundary,
  363. * then 'sp' should be word aligned here. If it's
  364. * not, then the user is trying to mess with us.
  365. */
  366. if (regs->compat_sp & 7)
  367. goto badframe;
  368. frame = (struct compat_sigframe __user *)regs->compat_sp;
  369. if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
  370. goto badframe;
  371. if (compat_restore_sigframe(regs, frame))
  372. goto badframe;
  373. return regs->regs[0];
  374. badframe:
  375. if (show_unhandled_signals)
  376. pr_info_ratelimited("%s[%d]: bad frame in %s: pc=%08llx sp=%08llx\n",
  377. current->comm, task_pid_nr(current), __func__,
  378. regs->pc, regs->sp);
  379. force_sig(SIGSEGV, current);
  380. return 0;
  381. }
  382. asmlinkage int compat_sys_rt_sigreturn(struct pt_regs *regs)
  383. {
  384. struct compat_rt_sigframe __user *frame;
  385. /* Always make any pending restarted system calls return -EINTR */
  386. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  387. /*
  388. * Since we stacked the signal on a 64-bit boundary,
  389. * then 'sp' should be word aligned here. If it's
  390. * not, then the user is trying to mess with us.
  391. */
  392. if (regs->compat_sp & 7)
  393. goto badframe;
  394. frame = (struct compat_rt_sigframe __user *)regs->compat_sp;
  395. if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
  396. goto badframe;
  397. if (compat_restore_sigframe(regs, &frame->sig))
  398. goto badframe;
  399. if (compat_restore_altstack(&frame->sig.uc.uc_stack))
  400. goto badframe;
  401. return regs->regs[0];
  402. badframe:
  403. if (show_unhandled_signals)
  404. pr_info_ratelimited("%s[%d]: bad frame in %s: pc=%08llx sp=%08llx\n",
  405. current->comm, task_pid_nr(current), __func__,
  406. regs->pc, regs->sp);
  407. force_sig(SIGSEGV, current);
  408. return 0;
  409. }
  410. static void __user *compat_get_sigframe(struct k_sigaction *ka,
  411. struct pt_regs *regs,
  412. int framesize)
  413. {
  414. compat_ulong_t sp = regs->compat_sp;
  415. void __user *frame;
  416. /*
  417. * This is the X/Open sanctioned signal stack switching.
  418. */
  419. if ((ka->sa.sa_flags & SA_ONSTACK) && !sas_ss_flags(sp))
  420. sp = current->sas_ss_sp + current->sas_ss_size;
  421. /*
  422. * ATPCS B01 mandates 8-byte alignment
  423. */
  424. frame = compat_ptr((compat_uptr_t)((sp - framesize) & ~7));
  425. /*
  426. * Check that we can actually write to the signal frame.
  427. */
  428. if (!access_ok(VERIFY_WRITE, frame, framesize))
  429. frame = NULL;
  430. return frame;
  431. }
  432. static void compat_setup_return(struct pt_regs *regs, struct k_sigaction *ka,
  433. compat_ulong_t __user *rc, void __user *frame,
  434. int usig)
  435. {
  436. compat_ulong_t handler = ptr_to_compat(ka->sa.sa_handler);
  437. compat_ulong_t retcode;
  438. compat_ulong_t spsr = regs->pstate & ~PSR_f;
  439. int thumb;
  440. /* Check if the handler is written for ARM or Thumb */
  441. thumb = handler & 1;
  442. if (thumb) {
  443. spsr |= COMPAT_PSR_T_BIT;
  444. spsr &= ~COMPAT_PSR_IT_MASK;
  445. } else {
  446. spsr &= ~COMPAT_PSR_T_BIT;
  447. }
  448. if (ka->sa.sa_flags & SA_RESTORER) {
  449. retcode = ptr_to_compat(ka->sa.sa_restorer);
  450. } else {
  451. /* Set up sigreturn pointer */
  452. unsigned int idx = thumb << 1;
  453. if (ka->sa.sa_flags & SA_SIGINFO)
  454. idx += 3;
  455. retcode = AARCH32_VECTORS_BASE +
  456. AARCH32_KERN_SIGRET_CODE_OFFSET +
  457. (idx << 2) + thumb;
  458. }
  459. regs->regs[0] = usig;
  460. regs->compat_sp = ptr_to_compat(frame);
  461. regs->compat_lr = retcode;
  462. regs->pc = handler;
  463. regs->pstate = spsr;
  464. }
  465. static int compat_setup_sigframe(struct compat_sigframe __user *sf,
  466. struct pt_regs *regs, sigset_t *set)
  467. {
  468. struct compat_aux_sigframe __user *aux;
  469. int err = 0;
  470. __put_user_error(regs->regs[0], &sf->uc.uc_mcontext.arm_r0, err);
  471. __put_user_error(regs->regs[1], &sf->uc.uc_mcontext.arm_r1, err);
  472. __put_user_error(regs->regs[2], &sf->uc.uc_mcontext.arm_r2, err);
  473. __put_user_error(regs->regs[3], &sf->uc.uc_mcontext.arm_r3, err);
  474. __put_user_error(regs->regs[4], &sf->uc.uc_mcontext.arm_r4, err);
  475. __put_user_error(regs->regs[5], &sf->uc.uc_mcontext.arm_r5, err);
  476. __put_user_error(regs->regs[6], &sf->uc.uc_mcontext.arm_r6, err);
  477. __put_user_error(regs->regs[7], &sf->uc.uc_mcontext.arm_r7, err);
  478. __put_user_error(regs->regs[8], &sf->uc.uc_mcontext.arm_r8, err);
  479. __put_user_error(regs->regs[9], &sf->uc.uc_mcontext.arm_r9, err);
  480. __put_user_error(regs->regs[10], &sf->uc.uc_mcontext.arm_r10, err);
  481. __put_user_error(regs->regs[11], &sf->uc.uc_mcontext.arm_fp, err);
  482. __put_user_error(regs->regs[12], &sf->uc.uc_mcontext.arm_ip, err);
  483. __put_user_error(regs->compat_sp, &sf->uc.uc_mcontext.arm_sp, err);
  484. __put_user_error(regs->compat_lr, &sf->uc.uc_mcontext.arm_lr, err);
  485. __put_user_error(regs->pc, &sf->uc.uc_mcontext.arm_pc, err);
  486. __put_user_error(regs->pstate, &sf->uc.uc_mcontext.arm_cpsr, err);
  487. __put_user_error((compat_ulong_t)0, &sf->uc.uc_mcontext.trap_no, err);
  488. __put_user_error((compat_ulong_t)0, &sf->uc.uc_mcontext.error_code, err);
  489. __put_user_error(current->thread.fault_address, &sf->uc.uc_mcontext.fault_address, err);
  490. __put_user_error(set->sig[0], &sf->uc.uc_mcontext.oldmask, err);
  491. err |= put_sigset_t(&sf->uc.uc_sigmask, set);
  492. aux = (struct compat_aux_sigframe __user *) sf->uc.uc_regspace;
  493. if (err == 0)
  494. err |= compat_preserve_vfp_context(&aux->vfp);
  495. __put_user_error(0, &aux->end_magic, err);
  496. return err;
  497. }
  498. /*
  499. * 32-bit signal handling routines called from signal.c
  500. */
  501. int compat_setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
  502. sigset_t *set, struct pt_regs *regs)
  503. {
  504. struct compat_rt_sigframe __user *frame;
  505. compat_stack_t stack;
  506. int err = 0;
  507. frame = compat_get_sigframe(ka, regs, sizeof(*frame));
  508. if (!frame)
  509. return 1;
  510. err |= copy_siginfo_to_user32(&frame->info, info);
  511. __put_user_error(0, &frame->sig.uc.uc_flags, err);
  512. __put_user_error(NULL, &frame->sig.uc.uc_link, err);
  513. err |= __compat_save_altstack(&frame->sig.uc.uc_stack, regs->compat_sp);
  514. err |= compat_setup_sigframe(&frame->sig, regs, set);
  515. if (err == 0) {
  516. compat_setup_return(regs, ka, frame->sig.retcode, frame, usig);
  517. regs->regs[1] = (compat_ulong_t)(unsigned long)&frame->info;
  518. regs->regs[2] = (compat_ulong_t)(unsigned long)&frame->sig.uc;
  519. }
  520. return err;
  521. }
  522. int compat_setup_frame(int usig, struct k_sigaction *ka, sigset_t *set,
  523. struct pt_regs *regs)
  524. {
  525. struct compat_sigframe __user *frame;
  526. int err = 0;
  527. frame = compat_get_sigframe(ka, regs, sizeof(*frame));
  528. if (!frame)
  529. return 1;
  530. __put_user_error(0x5ac3c35a, &frame->uc.uc_flags, err);
  531. err |= compat_setup_sigframe(frame, regs, set);
  532. if (err == 0)
  533. compat_setup_return(regs, ka, frame->retcode, frame, usig);
  534. return err;
  535. }
  536. void compat_setup_restart_syscall(struct pt_regs *regs)
  537. {
  538. regs->regs[7] = __NR_compat_restart_syscall;
  539. }