signal.c 19 KB

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