signal.c 18 KB

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