signal.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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. 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_IWMMXT
  184. if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
  185. err |= restore_iwmmxt_context(&aux->iwmmxt);
  186. #endif
  187. #ifdef CONFIG_VFP
  188. // if (err == 0)
  189. // err |= vfp_restore_state(&sf->aux.vfp);
  190. #endif
  191. return err;
  192. }
  193. asmlinkage int sys_sigreturn(struct pt_regs *regs)
  194. {
  195. struct sigframe __user *frame;
  196. /* Always make any pending restarted system calls return -EINTR */
  197. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  198. /*
  199. * Since we stacked the signal on a 64-bit boundary,
  200. * then 'sp' should be word aligned here. If it's
  201. * not, then the user is trying to mess with us.
  202. */
  203. if (regs->ARM_sp & 7)
  204. goto badframe;
  205. frame = (struct sigframe __user *)regs->ARM_sp;
  206. if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
  207. goto badframe;
  208. if (restore_sigframe(regs, frame))
  209. goto badframe;
  210. /* Send SIGTRAP if we're single-stepping */
  211. if (current->ptrace & PT_SINGLESTEP) {
  212. ptrace_cancel_bpt(current);
  213. send_sig(SIGTRAP, current, 1);
  214. }
  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. /* 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. static int
  250. setup_sigframe(struct sigframe __user *sf, struct pt_regs *regs, sigset_t *set)
  251. {
  252. struct aux_sigframe __user *aux;
  253. int err = 0;
  254. __put_user_error(regs->ARM_r0, &sf->uc.uc_mcontext.arm_r0, err);
  255. __put_user_error(regs->ARM_r1, &sf->uc.uc_mcontext.arm_r1, err);
  256. __put_user_error(regs->ARM_r2, &sf->uc.uc_mcontext.arm_r2, err);
  257. __put_user_error(regs->ARM_r3, &sf->uc.uc_mcontext.arm_r3, err);
  258. __put_user_error(regs->ARM_r4, &sf->uc.uc_mcontext.arm_r4, err);
  259. __put_user_error(regs->ARM_r5, &sf->uc.uc_mcontext.arm_r5, err);
  260. __put_user_error(regs->ARM_r6, &sf->uc.uc_mcontext.arm_r6, err);
  261. __put_user_error(regs->ARM_r7, &sf->uc.uc_mcontext.arm_r7, err);
  262. __put_user_error(regs->ARM_r8, &sf->uc.uc_mcontext.arm_r8, err);
  263. __put_user_error(regs->ARM_r9, &sf->uc.uc_mcontext.arm_r9, err);
  264. __put_user_error(regs->ARM_r10, &sf->uc.uc_mcontext.arm_r10, err);
  265. __put_user_error(regs->ARM_fp, &sf->uc.uc_mcontext.arm_fp, err);
  266. __put_user_error(regs->ARM_ip, &sf->uc.uc_mcontext.arm_ip, err);
  267. __put_user_error(regs->ARM_sp, &sf->uc.uc_mcontext.arm_sp, err);
  268. __put_user_error(regs->ARM_lr, &sf->uc.uc_mcontext.arm_lr, err);
  269. __put_user_error(regs->ARM_pc, &sf->uc.uc_mcontext.arm_pc, err);
  270. __put_user_error(regs->ARM_cpsr, &sf->uc.uc_mcontext.arm_cpsr, err);
  271. __put_user_error(current->thread.trap_no, &sf->uc.uc_mcontext.trap_no, err);
  272. __put_user_error(current->thread.error_code, &sf->uc.uc_mcontext.error_code, err);
  273. __put_user_error(current->thread.address, &sf->uc.uc_mcontext.fault_address, err);
  274. __put_user_error(set->sig[0], &sf->uc.uc_mcontext.oldmask, err);
  275. err |= __copy_to_user(&sf->uc.uc_sigmask, set, sizeof(*set));
  276. aux = (struct aux_sigframe __user *) sf->uc.uc_regspace;
  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. else
  332. cpsr &= ~PSR_T_BIT;
  333. }
  334. #endif
  335. if (ka->sa.sa_flags & SA_RESTORER) {
  336. retcode = (unsigned long)ka->sa.sa_restorer;
  337. } else {
  338. unsigned int idx = thumb << 1;
  339. if (ka->sa.sa_flags & SA_SIGINFO)
  340. idx += 3;
  341. if (__put_user(sigreturn_codes[idx], rc) ||
  342. __put_user(sigreturn_codes[idx+1], rc+1))
  343. return 1;
  344. if (cpsr & MODE32_BIT) {
  345. /*
  346. * 32-bit code can use the new high-page
  347. * signal return code support.
  348. */
  349. retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
  350. } else {
  351. /*
  352. * Ensure that the instruction cache sees
  353. * the return code written onto the stack.
  354. */
  355. flush_icache_range((unsigned long)rc,
  356. (unsigned long)(rc + 2));
  357. retcode = ((unsigned long)rc) + thumb;
  358. }
  359. }
  360. regs->ARM_r0 = usig;
  361. regs->ARM_sp = (unsigned long)frame;
  362. regs->ARM_lr = retcode;
  363. regs->ARM_pc = handler;
  364. regs->ARM_cpsr = cpsr;
  365. return 0;
  366. }
  367. static int
  368. setup_frame(int usig, struct k_sigaction *ka, sigset_t *set, struct pt_regs *regs)
  369. {
  370. struct sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
  371. int err = 0;
  372. if (!frame)
  373. return 1;
  374. /*
  375. * Set uc.uc_flags to a value which sc.trap_no would never have.
  376. */
  377. __put_user_error(0x5ac3c35a, &frame->uc.uc_flags, err);
  378. err |= setup_sigframe(frame, regs, set);
  379. if (err == 0)
  380. err = setup_return(regs, ka, frame->retcode, frame, usig);
  381. return err;
  382. }
  383. static int
  384. setup_rt_frame(int usig, struct k_sigaction *ka, siginfo_t *info,
  385. sigset_t *set, struct pt_regs *regs)
  386. {
  387. struct rt_sigframe __user *frame = get_sigframe(ka, regs, sizeof(*frame));
  388. stack_t stack;
  389. int err = 0;
  390. if (!frame)
  391. return 1;
  392. err |= copy_siginfo_to_user(&frame->info, info);
  393. __put_user_error(0, &frame->sig.uc.uc_flags, err);
  394. __put_user_error(NULL, &frame->sig.uc.uc_link, err);
  395. memset(&stack, 0, sizeof(stack));
  396. stack.ss_sp = (void __user *)current->sas_ss_sp;
  397. stack.ss_flags = sas_ss_flags(regs->ARM_sp);
  398. stack.ss_size = current->sas_ss_size;
  399. err |= __copy_to_user(&frame->sig.uc.uc_stack, &stack, sizeof(stack));
  400. err |= setup_sigframe(&frame->sig, regs, set);
  401. if (err == 0)
  402. err = setup_return(regs, ka, frame->sig.retcode, frame, usig);
  403. if (err == 0) {
  404. /*
  405. * For realtime signals we must also set the second and third
  406. * arguments for the signal handler.
  407. * -- Peter Maydell <pmaydell@chiark.greenend.org.uk> 2000-12-06
  408. */
  409. regs->ARM_r1 = (unsigned long)&frame->info;
  410. regs->ARM_r2 = (unsigned long)&frame->sig.uc;
  411. }
  412. return err;
  413. }
  414. static inline void restart_syscall(struct pt_regs *regs)
  415. {
  416. regs->ARM_r0 = regs->ARM_ORIG_r0;
  417. regs->ARM_pc -= thumb_mode(regs) ? 2 : 4;
  418. }
  419. /*
  420. * OK, we're invoking a handler
  421. */
  422. static void
  423. handle_signal(unsigned long sig, struct k_sigaction *ka,
  424. siginfo_t *info, sigset_t *oldset,
  425. struct pt_regs * regs, int syscall)
  426. {
  427. struct thread_info *thread = current_thread_info();
  428. struct task_struct *tsk = current;
  429. int usig = sig;
  430. int ret;
  431. /*
  432. * If we were from a system call, check for system call restarting...
  433. */
  434. if (syscall) {
  435. switch (regs->ARM_r0) {
  436. case -ERESTART_RESTARTBLOCK:
  437. case -ERESTARTNOHAND:
  438. regs->ARM_r0 = -EINTR;
  439. break;
  440. case -ERESTARTSYS:
  441. if (!(ka->sa.sa_flags & SA_RESTART)) {
  442. regs->ARM_r0 = -EINTR;
  443. break;
  444. }
  445. /* fallthrough */
  446. case -ERESTARTNOINTR:
  447. restart_syscall(regs);
  448. }
  449. }
  450. /*
  451. * translate the signal
  452. */
  453. if (usig < 32 && thread->exec_domain && thread->exec_domain->signal_invmap)
  454. usig = thread->exec_domain->signal_invmap[usig];
  455. /*
  456. * Set up the stack frame
  457. */
  458. if (ka->sa.sa_flags & SA_SIGINFO)
  459. ret = setup_rt_frame(usig, ka, info, oldset, regs);
  460. else
  461. ret = setup_frame(usig, ka, oldset, regs);
  462. /*
  463. * Check that the resulting registers are actually sane.
  464. */
  465. ret |= !valid_user_regs(regs);
  466. if (ret != 0) {
  467. force_sigsegv(sig, tsk);
  468. return;
  469. }
  470. /*
  471. * Block the signal if we were successful.
  472. */
  473. spin_lock_irq(&tsk->sighand->siglock);
  474. sigorsets(&tsk->blocked, &tsk->blocked,
  475. &ka->sa.sa_mask);
  476. if (!(ka->sa.sa_flags & SA_NODEFER))
  477. sigaddset(&tsk->blocked, sig);
  478. recalc_sigpending();
  479. spin_unlock_irq(&tsk->sighand->siglock);
  480. }
  481. /*
  482. * Note that 'init' is a special process: it doesn't get signals it doesn't
  483. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  484. * mistake.
  485. *
  486. * Note that we go through the signals twice: once to check the signals that
  487. * the kernel can handle, and then we build all the user-level signal handling
  488. * stack-frames in one go after that.
  489. */
  490. static int do_signal(sigset_t *oldset, struct pt_regs *regs, int syscall)
  491. {
  492. struct k_sigaction ka;
  493. siginfo_t info;
  494. int signr;
  495. /*
  496. * We want the common case to go fast, which
  497. * is why we may in certain cases get here from
  498. * kernel mode. Just return without doing anything
  499. * if so.
  500. */
  501. if (!user_mode(regs))
  502. return 0;
  503. if (try_to_freeze())
  504. goto no_signal;
  505. if (current->ptrace & PT_SINGLESTEP)
  506. ptrace_cancel_bpt(current);
  507. signr = get_signal_to_deliver(&info, &ka, regs, NULL);
  508. if (signr > 0) {
  509. handle_signal(signr, &ka, &info, oldset, regs, syscall);
  510. if (current->ptrace & PT_SINGLESTEP)
  511. ptrace_set_bpt(current);
  512. return 1;
  513. }
  514. no_signal:
  515. /*
  516. * No signal to deliver to the process - restart the syscall.
  517. */
  518. if (syscall) {
  519. if (regs->ARM_r0 == -ERESTART_RESTARTBLOCK) {
  520. if (thumb_mode(regs)) {
  521. regs->ARM_r7 = __NR_restart_syscall - __NR_SYSCALL_BASE;
  522. regs->ARM_pc -= 2;
  523. } else {
  524. #if defined(CONFIG_AEABI) && !defined(CONFIG_OABI_COMPAT)
  525. regs->ARM_r7 = __NR_restart_syscall;
  526. regs->ARM_pc -= 4;
  527. #else
  528. u32 __user *usp;
  529. u32 swival = __NR_restart_syscall;
  530. regs->ARM_sp -= 12;
  531. usp = (u32 __user *)regs->ARM_sp;
  532. /*
  533. * Either we supports OABI only, or we have
  534. * EABI with the OABI compat layer enabled.
  535. * In the later case we don't know if user
  536. * space is EABI or not, and if not we must
  537. * not clobber r7. Always using the OABI
  538. * syscall solves that issue and works for
  539. * all those cases.
  540. */
  541. swival = swival - __NR_SYSCALL_BASE + __NR_OABI_SYSCALL_BASE;
  542. put_user(regs->ARM_pc, &usp[0]);
  543. /* swi __NR_restart_syscall */
  544. put_user(0xef000000 | swival, &usp[1]);
  545. /* ldr pc, [sp], #12 */
  546. put_user(0xe49df00c, &usp[2]);
  547. flush_icache_range((unsigned long)usp,
  548. (unsigned long)(usp + 3));
  549. regs->ARM_pc = regs->ARM_sp + 4;
  550. #endif
  551. }
  552. }
  553. if (regs->ARM_r0 == -ERESTARTNOHAND ||
  554. regs->ARM_r0 == -ERESTARTSYS ||
  555. regs->ARM_r0 == -ERESTARTNOINTR) {
  556. restart_syscall(regs);
  557. }
  558. }
  559. if (current->ptrace & PT_SINGLESTEP)
  560. ptrace_set_bpt(current);
  561. return 0;
  562. }
  563. asmlinkage void
  564. do_notify_resume(struct pt_regs *regs, unsigned int thread_flags, int syscall)
  565. {
  566. if (thread_flags & _TIF_SIGPENDING)
  567. do_signal(&current->blocked, regs, syscall);
  568. }