signal.c 17 KB

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