signal_64.c 19 KB

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