signal.c 17 KB

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