signal_64.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * arch/sh/kernel/signal_64.c
  3. *
  4. * Copyright (C) 2000, 2001 Paolo Alberelli
  5. * Copyright (C) 2003 - 2008 Paul Mundt
  6. * Copyright (C) 2004 Richard Curnow
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/rwsem.h>
  13. #include <linux/sched.h>
  14. #include <linux/mm.h>
  15. #include <linux/smp.h>
  16. #include <linux/kernel.h>
  17. #include <linux/signal.h>
  18. #include <linux/errno.h>
  19. #include <linux/wait.h>
  20. #include <linux/personality.h>
  21. #include <linux/ptrace.h>
  22. #include <linux/unistd.h>
  23. #include <linux/stddef.h>
  24. #include <linux/tracehook.h>
  25. #include <asm/ucontext.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/cacheflush.h>
  29. #include <asm/fpu.h>
  30. #define REG_RET 9
  31. #define REG_ARG1 2
  32. #define REG_ARG2 3
  33. #define REG_ARG3 4
  34. #define REG_SP 15
  35. #define REG_PR 18
  36. #define REF_REG_RET regs->regs[REG_RET]
  37. #define REF_REG_SP regs->regs[REG_SP]
  38. #define DEREF_REG_PR regs->regs[REG_PR]
  39. #define DEBUG_SIG 0
  40. static void
  41. handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
  42. struct pt_regs * regs);
  43. static inline void
  44. handle_syscall_restart(struct pt_regs *regs, struct sigaction *sa)
  45. {
  46. /* If we're not from a syscall, bail out */
  47. if (regs->syscall_nr < 0)
  48. return;
  49. /* check for system call restart.. */
  50. switch (regs->regs[REG_RET]) {
  51. case -ERESTART_RESTARTBLOCK:
  52. case -ERESTARTNOHAND:
  53. no_system_call_restart:
  54. regs->regs[REG_RET] = -EINTR;
  55. break;
  56. case -ERESTARTSYS:
  57. if (!(sa->sa_flags & SA_RESTART))
  58. goto no_system_call_restart;
  59. /* fallthrough */
  60. case -ERESTARTNOINTR:
  61. /* Decode syscall # */
  62. regs->regs[REG_RET] = regs->syscall_nr;
  63. regs->pc -= 4;
  64. break;
  65. }
  66. }
  67. /*
  68. * Note that 'init' is a special process: it doesn't get signals it doesn't
  69. * want to handle. Thus you cannot kill init even with a SIGKILL even by
  70. * mistake.
  71. *
  72. * Note that we go through the signals twice: once to check the signals that
  73. * the kernel can handle, and then we build all the user-level signal handling
  74. * stack-frames in one go after that.
  75. */
  76. static void do_signal(struct pt_regs *regs)
  77. {
  78. siginfo_t info;
  79. int signr;
  80. struct k_sigaction ka;
  81. /*
  82. * We want the common case to go fast, which
  83. * is why we may in certain cases get here from
  84. * kernel mode. Just return without doing anything
  85. * if so.
  86. */
  87. if (!user_mode(regs))
  88. return;
  89. signr = get_signal_to_deliver(&info, &ka, regs, 0);
  90. if (signr > 0) {
  91. handle_syscall_restart(regs, &ka.sa);
  92. /* Whee! Actually deliver the signal. */
  93. handle_signal(signr, &info, &ka, regs);
  94. return;
  95. }
  96. /* Did we come from a system call? */
  97. if (regs->syscall_nr >= 0) {
  98. /* Restart the system call - no handlers present */
  99. switch (regs->regs[REG_RET]) {
  100. case -ERESTARTNOHAND:
  101. case -ERESTARTSYS:
  102. case -ERESTARTNOINTR:
  103. /* Decode Syscall # */
  104. regs->regs[REG_RET] = regs->syscall_nr;
  105. regs->pc -= 4;
  106. break;
  107. case -ERESTART_RESTARTBLOCK:
  108. regs->regs[REG_RET] = __NR_restart_syscall;
  109. regs->pc -= 4;
  110. break;
  111. }
  112. }
  113. /* No signal to deliver -- put the saved sigmask back */
  114. restore_saved_sigmask();
  115. }
  116. /*
  117. * Atomically swap in the new signal mask, and wait for a signal.
  118. */
  119. asmlinkage int
  120. sys_sigsuspend(old_sigset_t mask)
  121. {
  122. sigset_t blocked;
  123. siginitset(&blocked, mask);
  124. return sigsuspend(&blocked);
  125. }
  126. asmlinkage int
  127. sys_sigaction(int sig, const struct old_sigaction __user *act,
  128. struct old_sigaction __user *oact)
  129. {
  130. struct k_sigaction new_ka, old_ka;
  131. int ret;
  132. if (act) {
  133. old_sigset_t mask;
  134. if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
  135. __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
  136. __get_user(new_ka.sa.sa_restorer, &act->sa_restorer) ||
  137. __get_user(new_ka.sa.sa_flags, &act->sa_flags) ||
  138. __get_user(mask, &act->sa_mask))
  139. return -EFAULT;
  140. siginitset(&new_ka.sa.sa_mask, mask);
  141. }
  142. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  143. if (!ret && oact) {
  144. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
  145. __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
  146. __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer) ||
  147. __put_user(old_ka.sa.sa_flags, &oact->sa_flags) ||
  148. __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask))
  149. return -EFAULT;
  150. }
  151. return ret;
  152. }
  153. asmlinkage int
  154. sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss,
  155. unsigned long r4, unsigned long r5, unsigned long r6,
  156. unsigned long r7,
  157. struct pt_regs * regs)
  158. {
  159. return do_sigaltstack(uss, uoss, REF_REG_SP);
  160. }
  161. /*
  162. * Do a signal return; undo the signal stack.
  163. */
  164. struct sigframe {
  165. struct sigcontext sc;
  166. unsigned long extramask[_NSIG_WORDS-1];
  167. long long retcode[2];
  168. };
  169. struct rt_sigframe {
  170. struct siginfo __user *pinfo;
  171. void *puc;
  172. struct siginfo info;
  173. struct ucontext uc;
  174. long long retcode[2];
  175. };
  176. #ifdef CONFIG_SH_FPU
  177. static inline int
  178. restore_sigcontext_fpu(struct pt_regs *regs, struct sigcontext __user *sc)
  179. {
  180. int err = 0;
  181. int fpvalid;
  182. err |= __get_user (fpvalid, &sc->sc_fpvalid);
  183. conditional_used_math(fpvalid);
  184. if (! fpvalid)
  185. return err;
  186. if (current == last_task_used_math) {
  187. last_task_used_math = NULL;
  188. regs->sr |= SR_FD;
  189. }
  190. err |= __copy_from_user(&current->thread.xstate->hardfpu, &sc->sc_fpregs[0],
  191. (sizeof(long long) * 32) + (sizeof(int) * 1));
  192. return err;
  193. }
  194. static inline int
  195. setup_sigcontext_fpu(struct pt_regs *regs, struct sigcontext __user *sc)
  196. {
  197. int err = 0;
  198. int fpvalid;
  199. fpvalid = !!used_math();
  200. err |= __put_user(fpvalid, &sc->sc_fpvalid);
  201. if (! fpvalid)
  202. return err;
  203. if (current == last_task_used_math) {
  204. enable_fpu();
  205. save_fpu(current);
  206. disable_fpu();
  207. last_task_used_math = NULL;
  208. regs->sr |= SR_FD;
  209. }
  210. err |= __copy_to_user(&sc->sc_fpregs[0], &current->thread.xstate->hardfpu,
  211. (sizeof(long long) * 32) + (sizeof(int) * 1));
  212. clear_used_math();
  213. return err;
  214. }
  215. #else
  216. static inline int
  217. restore_sigcontext_fpu(struct pt_regs *regs, struct sigcontext __user *sc)
  218. {
  219. return 0;
  220. }
  221. static inline int
  222. setup_sigcontext_fpu(struct pt_regs *regs, struct sigcontext __user *sc)
  223. {
  224. return 0;
  225. }
  226. #endif
  227. static int
  228. restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, long long *r2_p)
  229. {
  230. unsigned int err = 0;
  231. unsigned long long current_sr, new_sr;
  232. #define SR_MASK 0xffff8cfd
  233. #define COPY(x) err |= __get_user(regs->x, &sc->sc_##x)
  234. COPY(regs[0]); COPY(regs[1]); COPY(regs[2]); COPY(regs[3]);
  235. COPY(regs[4]); COPY(regs[5]); COPY(regs[6]); COPY(regs[7]);
  236. COPY(regs[8]); COPY(regs[9]); COPY(regs[10]); COPY(regs[11]);
  237. COPY(regs[12]); COPY(regs[13]); COPY(regs[14]); COPY(regs[15]);
  238. COPY(regs[16]); COPY(regs[17]); COPY(regs[18]); COPY(regs[19]);
  239. COPY(regs[20]); COPY(regs[21]); COPY(regs[22]); COPY(regs[23]);
  240. COPY(regs[24]); COPY(regs[25]); COPY(regs[26]); COPY(regs[27]);
  241. COPY(regs[28]); COPY(regs[29]); COPY(regs[30]); COPY(regs[31]);
  242. COPY(regs[32]); COPY(regs[33]); COPY(regs[34]); COPY(regs[35]);
  243. COPY(regs[36]); COPY(regs[37]); COPY(regs[38]); COPY(regs[39]);
  244. COPY(regs[40]); COPY(regs[41]); COPY(regs[42]); COPY(regs[43]);
  245. COPY(regs[44]); COPY(regs[45]); COPY(regs[46]); COPY(regs[47]);
  246. COPY(regs[48]); COPY(regs[49]); COPY(regs[50]); COPY(regs[51]);
  247. COPY(regs[52]); COPY(regs[53]); COPY(regs[54]); COPY(regs[55]);
  248. COPY(regs[56]); COPY(regs[57]); COPY(regs[58]); COPY(regs[59]);
  249. COPY(regs[60]); COPY(regs[61]); COPY(regs[62]);
  250. COPY(tregs[0]); COPY(tregs[1]); COPY(tregs[2]); COPY(tregs[3]);
  251. COPY(tregs[4]); COPY(tregs[5]); COPY(tregs[6]); COPY(tregs[7]);
  252. /* Prevent the signal handler manipulating SR in a way that can
  253. crash the kernel. i.e. only allow S, Q, M, PR, SZ, FR to be
  254. modified */
  255. current_sr = regs->sr;
  256. err |= __get_user(new_sr, &sc->sc_sr);
  257. regs->sr &= SR_MASK;
  258. regs->sr |= (new_sr & ~SR_MASK);
  259. COPY(pc);
  260. #undef COPY
  261. /* Must do this last in case it sets regs->sr.fd (i.e. after rest of sr
  262. * has been restored above.) */
  263. err |= restore_sigcontext_fpu(regs, sc);
  264. regs->syscall_nr = -1; /* disable syscall checks */
  265. err |= __get_user(*r2_p, &sc->sc_regs[REG_RET]);
  266. return err;
  267. }
  268. asmlinkage int sys_sigreturn(unsigned long r2, unsigned long r3,
  269. unsigned long r4, unsigned long r5,
  270. unsigned long r6, unsigned long r7,
  271. struct pt_regs * regs)
  272. {
  273. struct sigframe __user *frame = (struct sigframe __user *) (long) REF_REG_SP;
  274. sigset_t set;
  275. long long ret;
  276. /* Always make any pending restarted system calls return -EINTR */
  277. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  278. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  279. goto badframe;
  280. if (__get_user(set.sig[0], &frame->sc.oldmask)
  281. || (_NSIG_WORDS > 1
  282. && __copy_from_user(&set.sig[1], &frame->extramask,
  283. sizeof(frame->extramask))))
  284. goto badframe;
  285. set_current_blocked(&set);
  286. if (restore_sigcontext(regs, &frame->sc, &ret))
  287. goto badframe;
  288. regs->pc -= 4;
  289. return (int) ret;
  290. badframe:
  291. force_sig(SIGSEGV, current);
  292. return 0;
  293. }
  294. asmlinkage int sys_rt_sigreturn(unsigned long r2, unsigned long r3,
  295. unsigned long r4, unsigned long r5,
  296. unsigned long r6, unsigned long r7,
  297. struct pt_regs * regs)
  298. {
  299. struct rt_sigframe __user *frame = (struct rt_sigframe __user *) (long) REF_REG_SP;
  300. sigset_t set;
  301. long long ret;
  302. /* Always make any pending restarted system calls return -EINTR */
  303. current_thread_info()->restart_block.fn = do_no_restart_syscall;
  304. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  305. goto badframe;
  306. if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
  307. goto badframe;
  308. set_current_blocked(&set);
  309. if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &ret))
  310. goto badframe;
  311. regs->pc -= 4;
  312. /* It is more difficult to avoid calling this function than to
  313. call it and ignore errors. */
  314. if (do_sigaltstack(&frame->uc.uc_stack, NULL, REF_REG_SP) == -EFAULT)
  315. goto badframe;
  316. return (int) ret;
  317. badframe:
  318. force_sig(SIGSEGV, current);
  319. return 0;
  320. }
  321. /*
  322. * Set up a signal frame.
  323. */
  324. static int
  325. setup_sigcontext(struct sigcontext __user *sc, struct pt_regs *regs,
  326. unsigned long mask)
  327. {
  328. int err = 0;
  329. /* Do this first, otherwise is this sets sr->fd, that value isn't preserved. */
  330. err |= setup_sigcontext_fpu(regs, sc);
  331. #define COPY(x) err |= __put_user(regs->x, &sc->sc_##x)
  332. COPY(regs[0]); COPY(regs[1]); COPY(regs[2]); COPY(regs[3]);
  333. COPY(regs[4]); COPY(regs[5]); COPY(regs[6]); COPY(regs[7]);
  334. COPY(regs[8]); COPY(regs[9]); COPY(regs[10]); COPY(regs[11]);
  335. COPY(regs[12]); COPY(regs[13]); COPY(regs[14]); COPY(regs[15]);
  336. COPY(regs[16]); COPY(regs[17]); COPY(regs[18]); COPY(regs[19]);
  337. COPY(regs[20]); COPY(regs[21]); COPY(regs[22]); COPY(regs[23]);
  338. COPY(regs[24]); COPY(regs[25]); COPY(regs[26]); COPY(regs[27]);
  339. COPY(regs[28]); COPY(regs[29]); COPY(regs[30]); COPY(regs[31]);
  340. COPY(regs[32]); COPY(regs[33]); COPY(regs[34]); COPY(regs[35]);
  341. COPY(regs[36]); COPY(regs[37]); COPY(regs[38]); COPY(regs[39]);
  342. COPY(regs[40]); COPY(regs[41]); COPY(regs[42]); COPY(regs[43]);
  343. COPY(regs[44]); COPY(regs[45]); COPY(regs[46]); COPY(regs[47]);
  344. COPY(regs[48]); COPY(regs[49]); COPY(regs[50]); COPY(regs[51]);
  345. COPY(regs[52]); COPY(regs[53]); COPY(regs[54]); COPY(regs[55]);
  346. COPY(regs[56]); COPY(regs[57]); COPY(regs[58]); COPY(regs[59]);
  347. COPY(regs[60]); COPY(regs[61]); COPY(regs[62]);
  348. COPY(tregs[0]); COPY(tregs[1]); COPY(tregs[2]); COPY(tregs[3]);
  349. COPY(tregs[4]); COPY(tregs[5]); COPY(tregs[6]); COPY(tregs[7]);
  350. COPY(sr); COPY(pc);
  351. #undef COPY
  352. err |= __put_user(mask, &sc->oldmask);
  353. return err;
  354. }
  355. /*
  356. * Determine which stack to use..
  357. */
  358. static inline void __user *
  359. get_sigframe(struct k_sigaction *ka, unsigned long sp, size_t frame_size)
  360. {
  361. if ((ka->sa.sa_flags & SA_ONSTACK) != 0 && ! sas_ss_flags(sp))
  362. sp = current->sas_ss_sp + current->sas_ss_size;
  363. return (void __user *)((sp - frame_size) & -8ul);
  364. }
  365. void sa_default_restorer(void); /* See comments below */
  366. void sa_default_rt_restorer(void); /* See comments below */
  367. static int setup_frame(int sig, struct k_sigaction *ka,
  368. sigset_t *set, struct pt_regs *regs)
  369. {
  370. struct sigframe __user *frame;
  371. int err = 0;
  372. int signal;
  373. frame = get_sigframe(ka, regs->regs[REG_SP], sizeof(*frame));
  374. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  375. goto give_sigsegv;
  376. signal = current_thread_info()->exec_domain
  377. && current_thread_info()->exec_domain->signal_invmap
  378. && sig < 32
  379. ? current_thread_info()->exec_domain->signal_invmap[sig]
  380. : sig;
  381. err |= setup_sigcontext(&frame->sc, regs, set->sig[0]);
  382. /* Give up earlier as i386, in case */
  383. if (err)
  384. goto give_sigsegv;
  385. if (_NSIG_WORDS > 1) {
  386. err |= __copy_to_user(frame->extramask, &set->sig[1],
  387. sizeof(frame->extramask)); }
  388. /* Give up earlier as i386, in case */
  389. if (err)
  390. goto give_sigsegv;
  391. /* Set up to return from userspace. If provided, use a stub
  392. already in userspace. */
  393. if (ka->sa.sa_flags & SA_RESTORER) {
  394. /*
  395. * On SH5 all edited pointers are subject to NEFF
  396. */
  397. DEREF_REG_PR = neff_sign_extend((unsigned long)
  398. ka->sa.sa_restorer | 0x1);
  399. } else {
  400. /*
  401. * Different approach on SH5.
  402. * . Endianness independent asm code gets placed in entry.S .
  403. * This is limited to four ASM instructions corresponding
  404. * to two long longs in size.
  405. * . err checking is done on the else branch only
  406. * . flush_icache_range() is called upon __put_user() only
  407. * . all edited pointers are subject to NEFF
  408. * . being code, linker turns ShMedia bit on, always
  409. * dereference index -1.
  410. */
  411. DEREF_REG_PR = neff_sign_extend((unsigned long)
  412. frame->retcode | 0x01);
  413. if (__copy_to_user(frame->retcode,
  414. (void *)((unsigned long)sa_default_restorer & (~1)), 16) != 0)
  415. goto give_sigsegv;
  416. /* Cohere the trampoline with the I-cache. */
  417. flush_cache_sigtramp(DEREF_REG_PR-1);
  418. }
  419. /*
  420. * Set up registers for signal handler.
  421. * All edited pointers are subject to NEFF.
  422. */
  423. regs->regs[REG_SP] = neff_sign_extend((unsigned long)frame);
  424. regs->regs[REG_ARG1] = signal; /* Arg for signal handler */
  425. /* FIXME:
  426. The glibc profiling support for SH-5 needs to be passed a sigcontext
  427. so it can retrieve the PC. At some point during 2003 the glibc
  428. support was changed to receive the sigcontext through the 2nd
  429. argument, but there are still versions of libc.so in use that use
  430. the 3rd argument. Until libc.so is stabilised, pass the sigcontext
  431. through both 2nd and 3rd arguments.
  432. */
  433. regs->regs[REG_ARG2] = (unsigned long long)(unsigned long)(signed long)&frame->sc;
  434. regs->regs[REG_ARG3] = (unsigned long long)(unsigned long)(signed long)&frame->sc;
  435. regs->pc = neff_sign_extend((unsigned long)ka->sa.sa_handler);
  436. set_fs(USER_DS);
  437. /* Broken %016Lx */
  438. pr_debug("SIG deliver (#%d,%s:%d): sp=%p pc=%08Lx%08Lx link=%08Lx%08Lx\n",
  439. signal, current->comm, current->pid, frame,
  440. regs->pc >> 32, regs->pc & 0xffffffff,
  441. DEREF_REG_PR >> 32, DEREF_REG_PR & 0xffffffff);
  442. return 0;
  443. give_sigsegv:
  444. force_sigsegv(sig, current);
  445. return -EFAULT;
  446. }
  447. static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
  448. sigset_t *set, struct pt_regs *regs)
  449. {
  450. struct rt_sigframe __user *frame;
  451. int err = 0;
  452. int signal;
  453. frame = get_sigframe(ka, regs->regs[REG_SP], sizeof(*frame));
  454. if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  455. goto give_sigsegv;
  456. signal = current_thread_info()->exec_domain
  457. && current_thread_info()->exec_domain->signal_invmap
  458. && sig < 32
  459. ? current_thread_info()->exec_domain->signal_invmap[sig]
  460. : sig;
  461. err |= __put_user(&frame->info, &frame->pinfo);
  462. err |= __put_user(&frame->uc, &frame->puc);
  463. err |= copy_siginfo_to_user(&frame->info, info);
  464. /* Give up earlier as i386, in case */
  465. if (err)
  466. goto give_sigsegv;
  467. /* Create the ucontext. */
  468. err |= __put_user(0, &frame->uc.uc_flags);
  469. err |= __put_user(0, &frame->uc.uc_link);
  470. err |= __put_user((void *)current->sas_ss_sp,
  471. &frame->uc.uc_stack.ss_sp);
  472. err |= __put_user(sas_ss_flags(regs->regs[REG_SP]),
  473. &frame->uc.uc_stack.ss_flags);
  474. err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
  475. err |= setup_sigcontext(&frame->uc.uc_mcontext,
  476. regs, set->sig[0]);
  477. err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
  478. /* Give up earlier as i386, in case */
  479. if (err)
  480. goto give_sigsegv;
  481. /* Set up to return from userspace. If provided, use a stub
  482. already in userspace. */
  483. if (ka->sa.sa_flags & SA_RESTORER) {
  484. /*
  485. * On SH5 all edited pointers are subject to NEFF
  486. */
  487. DEREF_REG_PR = neff_sign_extend((unsigned long)
  488. ka->sa.sa_restorer | 0x1);
  489. } else {
  490. /*
  491. * Different approach on SH5.
  492. * . Endianness independent asm code gets placed in entry.S .
  493. * This is limited to four ASM instructions corresponding
  494. * to two long longs in size.
  495. * . err checking is done on the else branch only
  496. * . flush_icache_range() is called upon __put_user() only
  497. * . all edited pointers are subject to NEFF
  498. * . being code, linker turns ShMedia bit on, always
  499. * dereference index -1.
  500. */
  501. DEREF_REG_PR = neff_sign_extend((unsigned long)
  502. frame->retcode | 0x01);
  503. if (__copy_to_user(frame->retcode,
  504. (void *)((unsigned long)sa_default_rt_restorer & (~1)), 16) != 0)
  505. goto give_sigsegv;
  506. /* Cohere the trampoline with the I-cache. */
  507. flush_icache_range(DEREF_REG_PR-1, DEREF_REG_PR-1+15);
  508. }
  509. /*
  510. * Set up registers for signal handler.
  511. * All edited pointers are subject to NEFF.
  512. */
  513. regs->regs[REG_SP] = neff_sign_extend((unsigned long)frame);
  514. regs->regs[REG_ARG1] = signal; /* Arg for signal handler */
  515. regs->regs[REG_ARG2] = (unsigned long long)(unsigned long)(signed long)&frame->info;
  516. regs->regs[REG_ARG3] = (unsigned long long)(unsigned long)(signed long)&frame->uc.uc_mcontext;
  517. regs->pc = neff_sign_extend((unsigned long)ka->sa.sa_handler);
  518. set_fs(USER_DS);
  519. pr_debug("SIG deliver (#%d,%s:%d): sp=%p pc=%08Lx%08Lx link=%08Lx%08Lx\n",
  520. signal, current->comm, current->pid, frame,
  521. regs->pc >> 32, regs->pc & 0xffffffff,
  522. DEREF_REG_PR >> 32, DEREF_REG_PR & 0xffffffff);
  523. return 0;
  524. give_sigsegv:
  525. force_sigsegv(sig, current);
  526. return -EFAULT;
  527. }
  528. /*
  529. * OK, we're invoking a handler
  530. */
  531. static void
  532. handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
  533. struct pt_regs * regs)
  534. {
  535. sigset_t *oldset = sigmask_to_save();
  536. int ret;
  537. /* Set up the stack frame */
  538. if (ka->sa.sa_flags & SA_SIGINFO)
  539. ret = setup_rt_frame(sig, ka, info, oldset, regs);
  540. else
  541. ret = setup_frame(sig, ka, oldset, regs);
  542. if (ret)
  543. return;
  544. signal_delivered(sig, info, ka, regs,
  545. test_thread_flag(TIF_SINGLESTEP));
  546. }
  547. asmlinkage void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags)
  548. {
  549. if (thread_info_flags & _TIF_SIGPENDING)
  550. do_signal(regs);
  551. if (thread_info_flags & _TIF_NOTIFY_RESUME) {
  552. clear_thread_flag(TIF_NOTIFY_RESUME);
  553. tracehook_notify_resume(regs);
  554. }
  555. }