/kern_oII/arch/arm/kernel/signal.c

http://omnia2droid.googlecode.com/ · C · 720 lines · 477 code · 115 blank · 128 comment · 89 complexity · ce337775f3c9ba6a8cafa98efbe2b0eb MD5 · raw file

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