signal.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * linux/arch/arm/kernel/signal.c
  3. *
  4. * Copyright (C) 1995-2002 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 <asm/elf.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/ucontext.h>
  18. #include <asm/unistd.h>
  19. #include "ptrace.h"
  20. #include "signal.h"
  21. #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
  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. /*
  28. * With EABI, the syscall number has to be loaded into r7.
  29. */
  30. #define MOV_R7_NR_SIGRETURN (0xe3a07000 | (__NR_sigreturn - __NR_SYSCALL_BASE))
  31. #define MOV_R7_NR_RT_SIGRETURN (0xe3a07000 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
  32. /*
  33. * For Thumb syscalls, we pass the syscall number via r7. We therefore
  34. * need two 16-bit instructions.
  35. */
  36. #define SWI_THUMB_SIGRETURN (0xdf00 << 16 | 0x2700 | (__NR_sigreturn - __NR_SYSCALL_BASE))
  37. #define SWI_THUMB_RT_SIGRETURN (0xdf00 << 16 | 0x2700 | (__NR_rt_sigreturn - __NR_SYSCALL_BASE))
  38. const unsigned long sigreturn_codes[7] = {
  39. MOV_R7_NR_SIGRETURN, SWI_SYS_SIGRETURN, SWI_THUMB_SIGRETURN,
  40. MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
  41. };
  42. /*
  43. * atomically swap in the new signal mask, and wait for a signal.
  44. */
  45. asmlinkage int sys_sigsuspend(int restart, unsigned long oldmask, old_sigset_t mask)
  46. {
  47. mask &= _BLOCKABLE;
  48. spin_lock_irq(&current->sighand->siglock);
  49. current->saved_sigmask = current->blocked;
  50. siginitset(&current->blocked, mask);
  51. recalc_sigpending();
  52. spin_unlock_irq(&current->sighand->siglock);
  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. return -EFAULT;
  70. __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  71. __get_user(mask, &act->sa_mask);
  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. return -EFAULT;
  80. __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  81. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
  82. }
  83. return ret;
  84. }
  85. #ifdef CONFIG_CRUNCH
  86. static int preserve_crunch_context(struct crunch_sigframe *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 *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. /*
  140. * Do a signal return; undo the signal stack. These are aligned to 64-bit.
  141. */
  142. struct sigframe {
  143. struct ucontext uc;
  144. unsigned long retcode[2];
  145. };
  146. struct rt_sigframe {
  147. struct siginfo info;
  148. struct sigframe sig;
  149. };
  150. static int restore_sigframe(struct pt_regs *regs, struct sigframe __user *sf)
  151. {
  152. struct aux_sigframe __user *aux;
  153. sigset_t set;
  154. int err;
  155. err = __copy_from_user(&set, &sf->uc.uc_sigmask, sizeof(set));
  156. if (err == 0) {
  157. sigdelsetmask(&set, ~_BLOCKABLE);
  158. spin_lock_irq(&current->sighand->siglock);
  159. current->blocked = set;
  160. recalc_sigpending();
  161. spin_unlock_irq(&current->sighand->siglock);
  162. }
  163. __get_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
  164. __get_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
  165. __get_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err);
  166. __get_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err);
  167. __get_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err);
  168. __get_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err);
  169. __get_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err);
  170. __get_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err);
  171. __get_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err);
  172. __get_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err);
  173. __get_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err);
  174. __get_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err);
  175. __get_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err);
  176. __get_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err);
  177. __get_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err);
  178. __get_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err);
  179. __get_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err);
  180. err |= !valid_user_regs(regs);
  181. aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
  182. #ifdef CONFIG_CRUNCH
  183. if (err == 0)
  184. err |= restore_crunch_context(&aux->crunch);
  185. #endif
  186. #ifdef CONFIG_IWMMXT
  187. if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
  188. err |= restore_iwmmxt_context(&aux->iwmmxt);
  189. #endif
  190. #ifdef CONFIG_VFP
  191. // if (err == 0)
  192. // err |= vfp_restore_state(&sf->aux.vfp);
  193. #endif
  194. return err;
  195. }
  196. asmlinkage int sys_sigreturn(struct pt_regs *regs)
  197. {
  198. struct sigframe __user *frame;
  199. /* Always make any pending restarted system calls return -EINTR */
  200. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  201. /*
  202. * Since we stacked the signal on a 64-bit boundary,
  203. * then 'sp' should be word aligned here. If it's
  204. * not, then the user is trying to mess with us.
  205. */
  206. if (regs->ARM_sp & 7)
  207. goto badframe;
  208. frame = (struct sigframe __user *)regs->ARM_sp;
  209. if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
  210. goto badframe;
  211. if (restore_sigframe(regs, frame))
  212. goto badframe;
  213. single_step_trap(current);
  214. return regs->ARM_r0;
  215. badframe:
  216. force_sig(SIGSEGV, current);
  217. return 0;
  218. }
  219. asmlinkage int sys_rt_sigreturn(struct pt_regs *regs)
  220. {
  221. struct rt_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 rt_sigframe __user *)regs->ARM_sp;
  232. if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
  233. goto badframe;
  234. if (restore_sigframe(regs, &frame->sig))
  235. goto badframe;
  236. if (do_sigaltstack(&frame->sig.uc.uc_stack, NULL, regs->ARM_sp) == -EFAULT)
  237. goto badframe;
  238. single_step_trap(current);
  239. return regs->ARM_r0;
  240. badframe:
  241. force_sig(SIGSEGV, current);
  242. return 0;
  243. }
  244. static int
  245. setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set)
  246. {
  247. struct aux_sigframe __user *aux;
  248. int err = 0;
  249. __put_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
  250. __put_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
  251. __put_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err);
  252. __put_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err);
  253. __put_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err);
  254. __put_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err);
  255. __put_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err);
  256. __put_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err);
  257. __put_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err);
  258. __put_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err);
  259. __put_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err);
  260. __put_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err);
  261. __put_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err);
  262. __put_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err);
  263. __put_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err);
  264. __put_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err);
  265. __put_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err);
  266. __put_user_error(current->thread.trap_no, &sf->uc.uc_mcontext.trap_no, err);
  267. __put_user_error(current->thread.error_code, &sf->uc.uc_mcontext.error_code, err);
  268. __put_user_error(current->thread.address, &sf->uc.uc_mcontext.fault_address, err);
  269. __put_user_error(set->sig[0], &sf->uc.uc_mcontext.oldmask, err);
  270. err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set));
  271. aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
  272. #ifdef CONFIG_CRUNCH
  273. if (err == 0)
  274. err |= preserve_crunch_context(&aux->crunch);
  275. #endif
  276. #ifdef CONFIG_IWMMXT
  277. if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
  278. err |= preserve_iwmmxt_context(&aux->iwmmxt);
  279. #endif
  280. #ifdef CONFIG_VFP
  281. // if (err == 0)
  282. // err |= vfp_save_state(&sf->aux.vfp);
  283. #endif
  284. __put_user_error(0, &aux->end_magic, err);
  285. return err;
  286. }
  287. static inline void __user *
  288. get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, int framesize)
  289. {
  290. unsigned long sp = regs->ARM_sp;
  291. void __user *frame;
  292. /*
  293. * This is the X/Open sanctioned signal stack switching.
  294. */
  295. if ((ka->sa.sa_flags & SA_ONSTACK) && !sas_ss_flags(sp))
  296. sp = current->sas_ss_sp + current->sas_ss_size;
  297. /*
  298. * ATPCS B01 mandates 8-byte alignment
  299. */
  300. frame = (void __user *)((sp - framesize) & ~7);
  301. /*
  302. * Check that we can actually write to the signal frame.
  303. */
  304. if (!access_ok(VERIFY_WRITE, frame, framesize))
  305. frame = NULL;
  306. return frame;
  307. }
  308. static int
  309. setup_return(struct pt_regs *regs, struct k_sigaction *ka,
  310. unsigned long __user *rc, void __user *frame, int usig)
  311. {
  312. unsigned long handler = (unsigned long)ka->sa.sa_handler;
  313. unsigned long retcode;
  314. int thumb = 0;
  315. unsigned long cpsr = regs->ARM_cpsr & ~PSR_f;
  316. /*
  317. * Maybe we need to deliver a 32-bit signal to a 26-bit task.
  318. */
  319. if (ka->sa.sa_flags & SA_THIRTYTWO)
  320. cpsr = (cpsr & ~MODE_MASK) | USR_MODE;
  321. #ifdef CONFIG_ARM_THUMB
  322. if (elf_hwcap & HWCAP_THUMB) {
  323. /*
  324. * The LSB of the handler determines if we're going to
  325. * be using THUMB or ARM mode for this signal handler.
  326. */
  327. thumb = handler & 1;
  328. if (thumb) {
  329. cpsr |= PSR_T_BIT;
  330. #if __LINUX_ARM_ARCH__ >= 7
  331. /* clear the If-Then Thumb-2 execution state */
  332. cpsr &= ~PSR_IT_MASK;
  333. #endif
  334. } else
  335. cpsr &= ~PSR_T_BIT;
  336. }
  337. #endif
  338. if (ka->sa.sa_flags & SA_RESTORER) {
  339. retcode = (unsigned long)ka->sa.sa_restorer;
  340. } else {
  341. unsigned int idx = thumb << 1;
  342. if (ka->sa.sa_flags & SA_SIGINFO)
  343. idx += 3;
  344. if (__put_user(sigreturn_codes[idx], rc) ||
  345. __put_user(sigreturn_codes[idx+1], rc+1))
  346. return 1;
  347. if (cpsr & MODE32_BIT) {
  348. /*
  349. * 32-bit code can use the new high-page
  350. * signal return code support.
  351. */
  352. retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
  353. } else {
  354. /*
  355. * Ensure that the instruction cache sees
  356. * the return code written onto the stack.
  357. */
  358. flush_icache_range((unsigned long)rc,
  359. (unsigned long)(rc + 2));
  360. retcode = ((unsigned long)rc) + thumb;
  361. }
  362. }
  363. regs->ARM_r0 = usig;
  364. regs->ARM_sp = (unsigned long)frame;
  365. regs->ARM_lr = retcode;
  366. regs->ARM_pc = handler;
  367. regs->ARM_cpsr = cpsr;
  368. return 0;
  369. }
  370. static int
  371. setup_frame(int usig, struct k_sigaction *ka, sigset_t *set, struct pt_regs *regs)
  372. {
  373. struct sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
  374. int err = 0;
  375. if (!frame)
  376. return 1;
  377. /*
  378. * Set uc.uc_flags to a value which sc.trap_no would never have.
  379. */
  380. __put_user_error(0x5ac3c35a, &frame->uc.uc_flags, err);
  381. err |= setup_sigframe(frame, regs, set);
  382. if (err == 0)
  383. err = setup_return(regs, ka, frame->retcode, frame, usig);
  384. return err;
  385. }
  386. static int
  387. setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
  388. sigset_t *set, struct pt_regs *regs)
  389. {
  390. struct rt_sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
  391. stack_t stack;
  392. int err = 0;
  393. if (!frame)
  394. return 1;
  395. err |= copy_siginfo_to_user(&frame->info, info);
  396. __put_user_error(0, &frame->sig.uc.uc_flags, err);
  397. __put_user_error(NULL, &frame->sig.uc.uc_link, err);
  398. memset(&stack, 0, sizeof(stack));
  399. stack.ss_sp = (void __user *)current->sas_ss_sp;
  400. stack.ss_flags = sas_ss_flags(regs->ARM_sp);
  401. stack.ss_size = current->sas_ss_size;
  402. err |= __copy_to_user(&frame->sig.uc.uc_stack, &stack, sizeof(stack));
  403. err |= setup_sigframe(&frame->sig, regs, set);
  404. if (err == 0)
  405. err = setup_return(regs, ka, frame->sig.retcode, frame, usig);
  406. if (err == 0) {
  407. /*
  408. * For realtime signals we must also set the second and third
  409. * arguments for the signal handler.
  410. * -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
  411. */
  412. regs->ARM_r1 = (unsigned long)&frame->info;
  413. regs->ARM_r2 = (unsigned long)&frame->sig.uc;
  414. }
  415. return err;
  416. }
  417. static inline void setup_syscall_restart(struct pt_regs *regs)
  418. {
  419. regs->ARM_r0 = regs->ARM_ORIG_r0;
  420. regs->ARM_pc -= thumb_mode(regs) ? 2 : 4;
  421. }
  422. /*
  423. * OK, we're invoking a handler
  424. */
  425. static int
  426. handle_signal(unsigned long sig, struct k_sigaction *ka,
  427. siginfo_t *info, sigset_t *oldset,
  428. struct pt_regs * regs, int syscall)
  429. {
  430. struct thread_info *thread = current_thread_info();
  431. struct task_struct *tsk = current;
  432. int usig = sig;
  433. int ret;
  434. /*
  435. * If we were from a system call, check for system call restarting...
  436. */
  437. if (syscall) {
  438. switch (regs->ARM_r0) {
  439. case -ERESTART_RESTARTBLOCK:
  440. case -ERESTARTNOHAND:
  441. regs->ARM_r0 = -EINTR;
  442. break;
  443. case -ERESTARTSYS:
  444. if (!(ka->sa.sa_flags & SA_RESTART)) {
  445. regs->ARM_r0 = -EINTR;
  446. break;
  447. }
  448. /* fallthrough */
  449. case -ERESTARTNOINTR:
  450. setup_syscall_restart(regs);
  451. }
  452. }
  453. /*
  454. * translate the signal
  455. */
  456. if (usig < 32 && thread->exec_domain && thread->exec_domain->signal_invmap)
  457. usig = thread->exec_domain->signal_invmap[usig];
  458. /*
  459. * Set up the stack frame
  460. */
  461. if (ka->sa.sa_flags & SA_SIGINFO)
  462. ret = setup_rt_frame(usig, ka, info, oldset, regs);
  463. else
  464. ret = setup_frame(usig, ka, oldset, regs);
  465. /*
  466. * Check that the resulting registers are actually sane.
  467. */
  468. ret |= !valid_user_regs(regs);
  469. if (ret != 0) {
  470. force_sigsegv(sig, tsk);
  471. return ret;
  472. }
  473. /*
  474. * Block the signal if we were successful.
  475. */
  476. spin_lock_irq(&tsk->sighand->siglock);
  477. sigorsets(&tsk->blocked, &tsk->blocked,
  478. &ka->sa.sa_mask);
  479. if (!(ka->sa.sa_flags & SA_NODEFER))
  480. sigaddset(&tsk->blocked, sig);
  481. recalc_sigpending();
  482. spin_unlock_irq(&tsk->sighand->siglock);
  483. return 0;
  484. }
  485. /*
  486. * Note that 'init' is a special process: it doesn't get signals it doesn't
  487. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  488. * mistake.
  489. *
  490. * Note that we go through the signals twice: once to check the signals that
  491. * the kernel can handle, and then we build all the user-level signal handling
  492. * stack-frames in one go after that.
  493. */
  494. static void do_signal(struct pt_regs *regs, int syscall)
  495. {
  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. if (try_to_freeze())
  508. goto no_signal;
  509. single_step_clear(current);
  510. signr = get_signal_to_deliver(&info, &ka, regs, NULL);
  511. if (signr > 0) {
  512. sigset_t *oldset;
  513. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  514. oldset = &current->saved_sigmask;
  515. else
  516. oldset = &current->blocked;
  517. if (handle_signal(signr, &ka, &info, oldset, regs, syscall) == 0) {
  518. /*
  519. * A signal was successfully delivered; the saved
  520. * sigmask will have been stored in the signal frame,
  521. * and will be restored by sigreturn, so we can simply
  522. * clear the TIF_RESTORE_SIGMASK flag.
  523. */
  524. if (test_thread_flag(TIF_RESTORE_SIGMASK))
  525. clear_thread_flag(TIF_RESTORE_SIGMASK);
  526. }
  527. single_step_set(current);
  528. return;
  529. }
  530. no_signal:
  531. /*
  532. * No signal to deliver to the process - restart the syscall.
  533. */
  534. if (syscall) {
  535. if (regs->ARM_r0 == -ERESTART_RESTARTBLOCK) {
  536. if (thumb_mode(regs)) {
  537. regs->ARM_r7 = __NR_restart_syscall - __NR_SYSCALL_BASE;
  538. regs->ARM_pc -= 2;
  539. } else {
  540. #if defined(CONFIG_AEABI) && !defined(CONFIG_OABI_COMPAT)
  541. regs->ARM_r7 = __NR_restart_syscall;
  542. regs->ARM_pc -= 4;
  543. #else
  544. u32 __user *usp;
  545. u32 swival = __NR_restart_syscall;
  546. regs->ARM_sp -= 12;
  547. usp = (u32 __user *)regs->ARM_sp;
  548. /*
  549. * Either we supports OABI only, or we have
  550. * EABI with the OABI compat layer enabled.
  551. * In the later case we don't know if user
  552. * space is EABI or not, and if not we must
  553. * not clobber r7. Always using the OABI
  554. * syscall solves that issue and works for
  555. * all those cases.
  556. */
  557. swival = swival - __NR_SYSCALL_BASE + __NR_OABI_SYSCALL_BASE;
  558. put_user(regs->ARM_pc, &usp[0]);
  559. /* swi __NR_restart_syscall */
  560. put_user(0xef000000 | swival, &usp[1]);
  561. /* ldr pc, [sp], #12 */
  562. put_user(0xe49df00c, &usp[2]);
  563. flush_icache_range((unsigned long)usp,
  564. (unsigned long)(usp + 3));
  565. regs->ARM_pc = regs->ARM_sp + 4;
  566. #endif
  567. }
  568. }
  569. if (regs->ARM_r0 == -ERESTARTNOHAND ||
  570. regs->ARM_r0 == -ERESTARTSYS ||
  571. regs->ARM_r0 == -ERESTARTNOINTR) {
  572. setup_syscall_restart(regs);
  573. }
  574. /* If there's no signal to deliver, we just put the saved sigmask
  575. * back.
  576. */
  577. if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
  578. clear_thread_flag(TIF_RESTORE_SIGMASK);
  579. sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
  580. }
  581. }
  582. single_step_set(current);
  583. }
  584. asmlinkage void
  585. do_notify_resume(struct pt_regs *regs, unsigned int thread_flags, int syscall)
  586. {
  587. if (thread_flags & _TIF_SIGPENDING)
  588. do_signal(regs, syscall);
  589. }