signal.c 18 KB

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