signal.c 19 KB

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