signal.c 18 KB

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