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