signal.c 19 KB

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