signal.c 19 KB

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