signal.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * linux/arch/arm/kernel/signal.c
  3. *
  4. * Copyright (C) 1995-2009 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/errno.h>
  11. #include <linux/signal.h>
  12. #include <linux/personality.h>
  13. #include <linux/freezer.h>
  14. #include <linux/uaccess.h>
  15. #include <linux/tracehook.h>
  16. #include <asm/elf.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/ucontext.h>
  19. #include <asm/unistd.h>
  20. #include <asm/vfp.h>
  21. #include "signal.h"
  22. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  23. /*
  24. * For ARM syscalls, we encode the syscall number into the instruction.
  25. */
  26. #define SWI_SYS_SIGRETURN (0xef000000|(__NR_sigreturn)|(__NR_OABI_SYSCALL_BASE))
  27. #define SWI_SYS_RT_SIGRETURN (0xef000000|(__NR_rt_sigreturn)|(__NR_OABI_SYSCALL_BASE))
  28. #define SWI_SYS_RESTART (0xef000000|__NR_restart_syscall|__NR_OABI_SYSCALL_BASE)
  29. /*
  30. * With EABI, the syscall number has to be loaded into r7.
  31. */
  32. #define MOV_R7_NR_SIGRETURN (0xe3a07000 | (__NR_sigreturn - __NR_SYSCALL_BASE))
  33. #define MOV_R7_NR_RT_SIGRETURN (0xe3a07000 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
  34. /*
  35. * For Thumb syscalls, we pass the syscall number via r7. We therefore
  36. * need two 16-bit instructions.
  37. */
  38. #define SWI_THUMB_SIGRETURN (0xdf00 << 16 | 0x2700 | (__NR_sigreturn - __NR_SYSCALL_BASE))
  39. #define SWI_THUMB_RT_SIGRETURN (0xdf00 << 16 | 0x2700 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
  40. const unsigned long sigreturn_codes[7] = {
  41. MOV_R7_NR_SIGRETURN, SWI_SYS_SIGRETURN, SWI_THUMB_SIGRETURN,
  42. MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
  43. };
  44. /*
  45. * Either we support OABI only, or we have EABI with the OABI
  46. * compat layer enabled. In the later case we don't know if
  47. * user space is EABI or not, and if not we must not clobber r7.
  48. * Always using the OABI syscall solves that issue and works for
  49. * all those cases.
  50. */
  51. const unsigned long syscall_restart_code[2] = {
  52. SWI_SYS_RESTART, /* swi __NR_restart_syscall */
  53. 0xe49df004, /* ldr pc, [sp], #4 */
  54. };
  55. /*
  56. * atomically swap in the new signal mask, and wait for a signal.
  57. */
  58. asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask, old_sigset_t mask)
  59. {
  60. sigset_t blocked;
  61. siginitset(&blocked, mask);
  62. return sigsuspend(&blocked);
  63. }
  64. asmlinkage int
  65. sys_sigaction(int sig, const struct old_sigaction __user *act,
  66. struct old_sigaction __user *oact)
  67. {
  68. struct k_sigaction new_ka, old_ka;
  69. int ret;
  70. if (act) {
  71. old_sigset_t mask;
  72. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  73. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  74. __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
  75. return -EFAULT;
  76. __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  77. __get_user(mask, &act->sa_mask);
  78. siginitset(&new_ka.sa.sa_mask, mask);
  79. }
  80. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  81. if (!ret && oact) {
  82. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  83. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  84. __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
  85. return -EFAULT;
  86. __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  87. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  88. }
  89. return ret;
  90. }
  91. #ifdef CONFIG_CRUNCH
  92. static int preserve_crunch_context(struct crunch_sigframe __user *frame)
  93. {
  94. char kbuf[sizeof(*frame) + 8];
  95. struct crunch_sigframe *kframe;
  96. /* the crunch context must be 64 bit aligned */
  97. kframe = (struct crunch_sigframe *)((unsigned long)(kbuf + 8) & ~7);
  98. kframe->magic = CRUNCH_MAGIC;
  99. kframe->size = CRUNCH_STORAGE_SIZE;
  100. crunch_task_copy(current_thread_info(), &kframe->storage);
  101. return __copy_to_user(frame, kframe, sizeof(*frame));
  102. }
  103. static int restore_crunch_context(struct crunch_sigframe __user *frame)
  104. {
  105. char kbuf[sizeof(*frame) + 8];
  106. struct crunch_sigframe *kframe;
  107. /* the crunch context must be 64 bit aligned */
  108. kframe = (struct crunch_sigframe *)((unsigned long)(kbuf + 8) & ~7);
  109. if (__copy_from_user(kframe, frame, sizeof(*frame)))
  110. return -1;
  111. if (kframe->magic != CRUNCH_MAGIC ||
  112. kframe->size != CRUNCH_STORAGE_SIZE)
  113. return -1;
  114. crunch_task_restore(current_thread_info(), &kframe->storage);
  115. return 0;
  116. }
  117. #endif
  118. #ifdef CONFIG_IWMMXT
  119. static int preserve_iwmmxt_context(struct iwmmxt_sigframe *frame)
  120. {
  121. char kbuf[sizeof(*frame) + 8];
  122. struct iwmmxt_sigframe *kframe;
  123. /* the iWMMXt context must be 64 bit aligned */
  124. kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
  125. kframe->magic = IWMMXT_MAGIC;
  126. kframe->size = IWMMXT_STORAGE_SIZE;
  127. iwmmxt_task_copy(current_thread_info(), &kframe->storage);
  128. return __copy_to_user(frame, kframe, sizeof(*frame));
  129. }
  130. static int restore_iwmmxt_context(struct iwmmxt_sigframe *frame)
  131. {
  132. char kbuf[sizeof(*frame) + 8];
  133. struct iwmmxt_sigframe *kframe;
  134. /* the iWMMXt context must be 64 bit aligned */
  135. kframe = (struct iwmmxt_sigframe *)((unsigned long)(kbuf + 8) & ~7);
  136. if (__copy_from_user(kframe, frame, sizeof(*frame)))
  137. return -1;
  138. if (kframe->magic != IWMMXT_MAGIC ||
  139. kframe->size != IWMMXT_STORAGE_SIZE)
  140. return -1;
  141. iwmmxt_task_restore(current_thread_info(), &kframe->storage);
  142. return 0;
  143. }
  144. #endif
  145. #ifdef CONFIG_VFP
  146. static int preserve_vfp_context(struct vfp_sigframe __user *frame)
  147. {
  148. const unsigned long magic = VFP_MAGIC;
  149. const unsigned long size = VFP_STORAGE_SIZE;
  150. int err = 0;
  151. __put_user_error(magic, &frame->magic, err);
  152. __put_user_error(size, &frame->size, err);
  153. if (err)
  154. return -EFAULT;
  155. return vfp_preserve_user_clear_hwstate(&frame->ufp, &frame->ufp_exc);
  156. }
  157. static int restore_vfp_context(struct vfp_sigframe __user *frame)
  158. {
  159. unsigned long magic;
  160. unsigned long size;
  161. int err = 0;
  162. __get_user_error(magic, &frame->magic, err);
  163. __get_user_error(size, &frame->size, err);
  164. if (err)
  165. return -EFAULT;
  166. if (magic != VFP_MAGIC || size != VFP_STORAGE_SIZE)
  167. return -EINVAL;
  168. return vfp_restore_user_hwstate(&frame->ufp, &frame->ufp_exc);
  169. }
  170. #endif
  171. /*
  172. * Do a signal return; undo the signal stack. These are aligned to 64-bit.
  173. */
  174. struct sigframe {
  175. struct ucontext uc;
  176. unsigned long retcode[2];
  177. };
  178. struct rt_sigframe {
  179. struct siginfo info;
  180. struct sigframe sig;
  181. };
  182. static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
  183. {
  184. struct aux_sigframe __user *aux;
  185. sigset_t set;
  186. int err;
  187. err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
  188. if (err == 0) {
  189. sigdelsetmask(&set, ~_BLOCKABLE);
  190. set_current_blocked(&set);
  191. }
  192. __get_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
  193. __get_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
  194. __get_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err);
  195. __get_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err);
  196. __get_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err);
  197. __get_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err);
  198. __get_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err);
  199. __get_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err);
  200. __get_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err);
  201. __get_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err);
  202. __get_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err);
  203. __get_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err);
  204. __get_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err);
  205. __get_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err);
  206. __get_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err);
  207. __get_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err);
  208. __get_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err);
  209. err |= !valid_user_regs(regs);
  210. aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
  211. #ifdef CONFIG_CRUNCH
  212. if (err == 0)
  213. err |= restore_crunch_context(&aux->crunch);
  214. #endif
  215. #ifdef CONFIG_IWMMXT
  216. if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
  217. err |= restore_iwmmxt_context(&aux->iwmmxt);
  218. #endif
  219. #ifdef CONFIG_VFP
  220. if (err == 0)
  221. err |= restore_vfp_context(&aux->vfp);
  222. #endif
  223. return err;
  224. }
  225. asmlinkage int sys_sigreturn(struct pt_regs *regs)
  226. {
  227. struct sigframe __user *frame;
  228. /* Always make any pending restarted system calls return -EINTR */
  229. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  230. /*
  231. * Since we stacked the signal on a 64-bit boundary,
  232. * then 'sp' should be word aligned here. If it's
  233. * not, then the user is trying to mess with us.
  234. */
  235. if (regs->ARM_sp & 7)
  236. goto badframe;
  237. frame = (struct sigframe __user *)regs->ARM_sp;
  238. if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
  239. goto badframe;
  240. if (restore_sigframe(regs, frame))
  241. goto badframe;
  242. return regs->ARM_r0;
  243. badframe:
  244. force_sig(SIGSEGV, current);
  245. return 0;
  246. }
  247. asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
  248. {
  249. struct rt_sigframe __user *frame;
  250. /* Always make any pending restarted system calls return -EINTR */
  251. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  252. /*
  253. * Since we stacked the signal on a 64-bit boundary,
  254. * then 'sp' should be word aligned here. If it's
  255. * not, then the user is trying to mess with us.
  256. */
  257. if (regs->ARM_sp & 7)
  258. goto badframe;
  259. frame = (struct rt_sigframe __user *)regs->ARM_sp;
  260. if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
  261. goto badframe;
  262. if (restore_sigframe(regs, &frame->sig))
  263. goto badframe;
  264. if (do_sigaltstack(&frame->sig.uc.uc_stack, NULL, regs->ARM_sp) == -EFAULT)
  265. goto badframe;
  266. return regs->ARM_r0;
  267. badframe:
  268. force_sig(SIGSEGV, current);
  269. return 0;
  270. }
  271. static int
  272. setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set)
  273. {
  274. struct aux_sigframe __user *aux;
  275. int err = 0;
  276. __put_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
  277. __put_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
  278. __put_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err);
  279. __put_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err);
  280. __put_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err);
  281. __put_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err);
  282. __put_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err);
  283. __put_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err);
  284. __put_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err);
  285. __put_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err);
  286. __put_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err);
  287. __put_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err);
  288. __put_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err);
  289. __put_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err);
  290. __put_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err);
  291. __put_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err);
  292. __put_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err);
  293. __put_user_error(current->thread.trap_no, &sf->uc.uc_mcontext.trap_no, err);
  294. __put_user_error(current->thread.error_code, &sf->uc.uc_mcontext.error_code, err);
  295. __put_user_error(current->thread.address, &sf->uc.uc_mcontext.fault_address, err);
  296. __put_user_error(set->sig[0], &sf->uc.uc_mcontext.oldmask, err);
  297. err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set));
  298. aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
  299. #ifdef CONFIG_CRUNCH
  300. if (err == 0)
  301. err |= preserve_crunch_context(&aux->crunch);
  302. #endif
  303. #ifdef CONFIG_IWMMXT
  304. if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
  305. err |= preserve_iwmmxt_context(&aux->iwmmxt);
  306. #endif
  307. #ifdef CONFIG_VFP
  308. if (err == 0)
  309. err |= preserve_vfp_context(&aux->vfp);
  310. #endif
  311. __put_user_error(0, &aux->end_magic, err);
  312. return err;
  313. }
  314. static inline void __user *
  315. get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, int framesize)
  316. {
  317. unsigned long sp = regs->ARM_sp;
  318. void __user *frame;
  319. /*
  320. * This is the X/Open sanctioned signal stack switching.
  321. */
  322. if ((ka->sa.sa_flags & SA_ONSTACK) && !sas_ss_flags(sp))
  323. sp = current->sas_ss_sp + current->sas_ss_size;
  324. /*
  325. * ATPCS B01 mandates 8-byte alignment
  326. */
  327. frame = (void __user *)((sp - framesize) & ~7);
  328. /*
  329. * Check that we can actually write to the signal frame.
  330. */
  331. if (!access_ok(VERIFY_WRITE, frame, framesize))
  332. frame = NULL;
  333. return frame;
  334. }
  335. static int
  336. setup_return(struct pt_regs *regs, struct k_sigaction *ka,
  337. unsigned long __user *rc, void __user *frame, int usig)
  338. {
  339. unsigned long handler = (unsigned long)ka->sa.sa_handler;
  340. unsigned long retcode;
  341. int thumb = 0;
  342. unsigned long cpsr = regs->ARM_cpsr & ~(PSR_f | PSR_E_BIT);
  343. cpsr |= PSR_ENDSTATE;
  344. /*
  345. * Maybe we need to deliver a 32-bit signal to a 26-bit task.
  346. */
  347. if (ka->sa.sa_flags & SA_THIRTYTWO)
  348. cpsr = (cpsr & ~MODE_MASK) | USR_MODE;
  349. #ifdef CONFIG_ARM_THUMB
  350. if (elf_hwcap & HWCAP_THUMB) {
  351. /*
  352. * The LSB of the handler determines if we're going to
  353. * be using THUMB or ARM mode for this signal handler.
  354. */
  355. thumb = handler & 1;
  356. if (thumb) {
  357. cpsr |= PSR_T_BIT;
  358. #if __LINUX_ARM_ARCH__ >= 7
  359. /* clear the If-Then Thumb-2 execution state */
  360. cpsr &= ~PSR_IT_MASK;
  361. #endif
  362. } else
  363. cpsr &= ~PSR_T_BIT;
  364. }
  365. #endif
  366. if (ka->sa.sa_flags & SA_RESTORER) {
  367. retcode = (unsigned long)ka->sa.sa_restorer;
  368. } else {
  369. unsigned int idx = thumb << 1;
  370. if (ka->sa.sa_flags & SA_SIGINFO)
  371. idx += 3;
  372. if (__put_user(sigreturn_codes[idx], rc) ||
  373. __put_user(sigreturn_codes[idx+1], rc+1))
  374. return 1;
  375. if (cpsr & MODE32_BIT) {
  376. /*
  377. * 32-bit code can use the new high-page
  378. * signal return code support.
  379. */
  380. retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
  381. } else {
  382. /*
  383. * Ensure that the instruction cache sees
  384. * the return code written onto the stack.
  385. */
  386. flush_icache_range((unsigned long)rc,
  387. (unsigned long)(rc + 2));
  388. retcode = ((unsigned long)rc) + thumb;
  389. }
  390. }
  391. regs->ARM_r0 = usig;
  392. regs->ARM_sp = (unsigned long)frame;
  393. regs->ARM_lr = retcode;
  394. regs->ARM_pc = handler;
  395. regs->ARM_cpsr = cpsr;
  396. return 0;
  397. }
  398. static int
  399. setup_frame(int usig, struct k_sigaction *ka, sigset_t *set, struct pt_regs *regs)
  400. {
  401. struct sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
  402. int err = 0;
  403. if (!frame)
  404. return 1;
  405. /*
  406. * Set uc.uc_flags to a value which sc.trap_no would never have.
  407. */
  408. __put_user_error(0x5ac3c35a, &frame->uc.uc_flags, err);
  409. err |= setup_sigframe(frame, regs, set);
  410. if (err == 0)
  411. err = setup_return(regs, ka, frame->retcode, frame, usig);
  412. return err;
  413. }
  414. static int
  415. setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
  416. sigset_t *set, struct pt_regs *regs)
  417. {
  418. struct rt_sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
  419. stack_t stack;
  420. int err = 0;
  421. if (!frame)
  422. return 1;
  423. err |= copy_siginfo_to_user(&frame->info, info);
  424. __put_user_error(0, &frame->sig.uc.uc_flags, err);
  425. __put_user_error(NULL, &frame->sig.uc.uc_link, err);
  426. memset(&stack, 0, sizeof(stack));
  427. stack.ss_sp = (void __user *)current->sas_ss_sp;
  428. stack.ss_flags = sas_ss_flags(regs->ARM_sp);
  429. stack.ss_size = current->sas_ss_size;
  430. err |= __copy_to_user(&frame->sig.uc.uc_stack, &stack, sizeof(stack));
  431. err |= setup_sigframe(&frame->sig, regs, set);
  432. if (err == 0)
  433. err = setup_return(regs, ka, frame->sig.retcode, frame, usig);
  434. if (err == 0) {
  435. /*
  436. * For realtime signals we must also set the second and third
  437. * arguments for the signal handler.
  438. * -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
  439. */
  440. regs->ARM_r1 = (unsigned long)&frame->info;
  441. regs->ARM_r2 = (unsigned long)&frame->sig.uc;
  442. }
  443. return err;
  444. }
  445. /*
  446. * OK, we're invoking a handler
  447. */
  448. static int
  449. handle_signal(unsigned long sig, struct k_sigaction *ka,
  450. siginfo_t *info, sigset_t *oldset,
  451. struct pt_regs * regs)
  452. {
  453. struct thread_info *thread = current_thread_info();
  454. struct task_struct *tsk = current;
  455. int usig = sig;
  456. int ret;
  457. /*
  458. * translate the signal
  459. */
  460. if (usig < 32 && thread->exec_domain && thread->exec_domain->signal_invmap)
  461. usig = thread->exec_domain->signal_invmap[usig];
  462. /*
  463. * Set up the stack frame
  464. */
  465. if (ka->sa.sa_flags & SA_SIGINFO)
  466. ret = setup_rt_frame(usig, ka, info, oldset, regs);
  467. else
  468. ret = setup_frame(usig, ka, oldset, regs);
  469. /*
  470. * Check that the resulting registers are actually sane.
  471. */
  472. ret |= !valid_user_regs(regs);
  473. if (ret != 0) {
  474. force_sigsegv(sig, tsk);
  475. return ret;
  476. }
  477. /*
  478. * Block the signal if we were successful.
  479. */
  480. block_sigmask(ka, sig);
  481. tracehook_signal_handler(sig, info, ka, regs, 0);
  482. return 0;
  483. }
  484. /*
  485. * Note that 'init' is a special process: it doesn't get signals it doesn't
  486. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  487. * mistake.
  488. *
  489. * Note that we go through the signals twice: once to check the signals that
  490. * the kernel can handle, and then we build all the user-level signal handling
  491. * stack-frames in one go after that.
  492. */
  493. static void do_signal(struct pt_regs *regs, int syscall)
  494. {
  495. unsigned int retval = 0, continue_addr = 0, restart_addr = 0;
  496. struct k_sigaction ka;
  497. siginfo_t info;
  498. int signr;
  499. /*
  500. * We want the common case to go fast, which
  501. * is why we may in certain cases get here from
  502. * kernel mode. Just return without doing anything
  503. * if so.
  504. */
  505. if (!user_mode(regs))
  506. return;
  507. /*
  508. * If we were from a system call, check for system call restarting...
  509. */
  510. if (syscall) {
  511. continue_addr = regs->ARM_pc;
  512. restart_addr = continue_addr - (thumb_mode(regs) ? 2 : 4);
  513. retval = regs->ARM_r0;
  514. /*
  515. * Prepare for system call restart. We do this here so that a
  516. * debugger will see the already changed PSW.
  517. */
  518. switch (retval) {
  519. case -ERESTARTNOHAND:
  520. case -ERESTARTSYS:
  521. case -ERESTARTNOINTR:
  522. regs->ARM_r0 = regs->ARM_ORIG_r0;
  523. regs->ARM_pc = restart_addr;
  524. break;
  525. case -ERESTART_RESTARTBLOCK:
  526. regs->ARM_r0 = -EINTR;
  527. break;
  528. }
  529. }
  530. if (try_to_freeze())
  531. goto no_signal;
  532. /*
  533. * Get the signal to deliver. When running under ptrace, at this
  534. * point the debugger may change all our registers ...
  535. */
  536. signr = get_signal_to_deliver(&info, &ka, regs, NULL);
  537. if (signr > 0) {
  538. sigset_t *oldset;
  539. /*
  540. * Depending on the signal settings we may need to revert the
  541. * decision to restart the system call. But skip this if a
  542. * debugger has chosen to restart at a different PC.
  543. */
  544. if (regs->ARM_pc == restart_addr) {
  545. if (retval == -ERESTARTNOHAND
  546. || (retval == -ERESTARTSYS
  547. && !(ka.sa.sa_flags & SA_RESTART))) {
  548. regs->ARM_r0 = -EINTR;
  549. regs->ARM_pc = continue_addr;
  550. }
  551. }
  552. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  553. oldset = &current->saved_sigmask;
  554. else
  555. oldset = &current->blocked;
  556. if (handle_signal(signr, &ka, &info, oldset, regs) == 0) {
  557. /*
  558. * A signal was successfully delivered; the saved
  559. * sigmask will have been stored in the signal frame,
  560. * and will be restored by sigreturn, so we can simply
  561. * clear the TIF_RESTORE_SIGMASK flag.
  562. */
  563. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  564. clear_thread_flag(TIF_RESTORE_SIGMASK);
  565. }
  566. return;
  567. }
  568. no_signal:
  569. if (syscall) {
  570. /*
  571. * Handle restarting a different system call. As above,
  572. * if a debugger has chosen to restart at a different PC,
  573. * ignore the restart.
  574. */
  575. if (retval == -ERESTART_RESTARTBLOCK
  576. && regs->ARM_pc == continue_addr) {
  577. if (thumb_mode(regs)) {
  578. regs->ARM_r7 = __NR_restart_syscall - __NR_SYSCALL_BASE;
  579. regs->ARM_pc -= 2;
  580. } else {
  581. #if defined(CONFIG_AEABI) && !defined(CONFIG_OABI_COMPAT)
  582. regs->ARM_r7 = __NR_restart_syscall;
  583. regs->ARM_pc -= 4;
  584. #else
  585. u32 __user *usp;
  586. regs->ARM_sp -= 4;
  587. usp = (u32 __user *)regs->ARM_sp;
  588. if (put_user(regs->ARM_pc, usp) == 0) {
  589. regs->ARM_pc = KERN_RESTART_CODE;
  590. } else {
  591. regs->ARM_sp += 4;
  592. force_sigsegv(0, current);
  593. }
  594. #endif
  595. }
  596. }
  597. /* If there's no signal to deliver, we just put the saved sigmask
  598. * back.
  599. */
  600. if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
  601. clear_thread_flag(TIF_RESTORE_SIGMASK);
  602. sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
  603. }
  604. }
  605. }
  606. asmlinkage void
  607. do_notify_resume(struct pt_regs *regs, unsigned int thread_flags, int syscall)
  608. {
  609. if (thread_flags & _TIF_SIGPENDING)
  610. do_signal(regs, syscall);
  611. if (thread_flags & _TIF_NOTIFY_RESUME) {
  612. clear_thread_flag(TIF_NOTIFY_RESUME);
  613. tracehook_notify_resume(regs);
  614. if (current->replacement_session_keyring)
  615. key_replace_session_keyring();
  616. }
  617. }