signal.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1991, 1992 Linus Torvalds
  7. * Copyright (C) 1994 - 2000 Ralf Baechle
  8. * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
  9. * Copyright (C) 2014, Imagination Technologies Ltd.
  10. */
  11. #include <linux/cache.h>
  12. #include <linux/context_tracking.h>
  13. #include <linux/irqflags.h>
  14. #include <linux/sched.h>
  15. #include <linux/mm.h>
  16. #include <linux/personality.h>
  17. #include <linux/smp.h>
  18. #include <linux/kernel.h>
  19. #include <linux/signal.h>
  20. #include <linux/errno.h>
  21. #include <linux/wait.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/unistd.h>
  24. #include <linux/compiler.h>
  25. #include <linux/syscalls.h>
  26. #include <linux/uaccess.h>
  27. #include <linux/tracehook.h>
  28. #include <asm/abi.h>
  29. #include <asm/asm.h>
  30. #include <linux/bitops.h>
  31. #include <asm/cacheflush.h>
  32. #include <asm/fpu.h>
  33. #include <asm/sim.h>
  34. #include <asm/ucontext.h>
  35. #include <asm/cpu-features.h>
  36. #include <asm/war.h>
  37. #include <asm/vdso.h>
  38. #include <asm/dsp.h>
  39. #include <asm/inst.h>
  40. #include "signal-common.h"
  41. static int (*save_fp_context)(struct sigcontext __user *sc);
  42. static int (*restore_fp_context)(struct sigcontext __user *sc);
  43. extern asmlinkage int _save_fp_context(struct sigcontext __user *sc);
  44. extern asmlinkage int _restore_fp_context(struct sigcontext __user *sc);
  45. struct sigframe {
  46. u32 sf_ass[4]; /* argument save space for o32 */
  47. u32 sf_pad[2]; /* Was: signal trampoline */
  48. struct sigcontext sf_sc;
  49. sigset_t sf_mask;
  50. };
  51. struct rt_sigframe {
  52. u32 rs_ass[4]; /* argument save space for o32 */
  53. u32 rs_pad[2]; /* Was: signal trampoline */
  54. struct siginfo rs_info;
  55. struct ucontext rs_uc;
  56. };
  57. /*
  58. * Thread saved context copy to/from a signal context presumed to be on the
  59. * user stack, and therefore accessed with appropriate macros from uaccess.h.
  60. */
  61. static int copy_fp_to_sigcontext(struct sigcontext __user *sc)
  62. {
  63. int i;
  64. int err = 0;
  65. for (i = 0; i < NUM_FPU_REGS; i++) {
  66. err |=
  67. __put_user(get_fpr64(&current->thread.fpu.fpr[i], 0),
  68. &sc->sc_fpregs[i]);
  69. }
  70. err |= __put_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
  71. return err;
  72. }
  73. static int copy_fp_from_sigcontext(struct sigcontext __user *sc)
  74. {
  75. int i;
  76. int err = 0;
  77. u64 fpr_val;
  78. for (i = 0; i < NUM_FPU_REGS; i++) {
  79. err |= __get_user(fpr_val, &sc->sc_fpregs[i]);
  80. set_fpr64(&current->thread.fpu.fpr[i], 0, fpr_val);
  81. }
  82. err |= __get_user(current->thread.fpu.fcr31, &sc->sc_fpc_csr);
  83. return err;
  84. }
  85. /*
  86. * Helper routines
  87. */
  88. static int protected_save_fp_context(struct sigcontext __user *sc)
  89. {
  90. int err;
  91. #ifndef CONFIG_EVA
  92. while (1) {
  93. lock_fpu_owner();
  94. if (is_fpu_owner()) {
  95. err = save_fp_context(sc);
  96. unlock_fpu_owner();
  97. } else {
  98. unlock_fpu_owner();
  99. err = copy_fp_to_sigcontext(sc);
  100. }
  101. if (likely(!err))
  102. break;
  103. /* touch the sigcontext and try again */
  104. err = __put_user(0, &sc->sc_fpregs[0]) |
  105. __put_user(0, &sc->sc_fpregs[31]) |
  106. __put_user(0, &sc->sc_fpc_csr);
  107. if (err)
  108. break; /* really bad sigcontext */
  109. }
  110. #else
  111. /*
  112. * EVA does not have FPU EVA instructions so saving fpu context directly
  113. * does not work.
  114. */
  115. lose_fpu(1);
  116. err = save_fp_context(sc); /* this might fail */
  117. #endif
  118. return err;
  119. }
  120. static int protected_restore_fp_context(struct sigcontext __user *sc)
  121. {
  122. int err, tmp __maybe_unused;
  123. #ifndef CONFIG_EVA
  124. while (1) {
  125. lock_fpu_owner();
  126. if (is_fpu_owner()) {
  127. err = restore_fp_context(sc);
  128. unlock_fpu_owner();
  129. } else {
  130. unlock_fpu_owner();
  131. err = copy_fp_from_sigcontext(sc);
  132. }
  133. if (likely(!err))
  134. break;
  135. /* touch the sigcontext and try again */
  136. err = __get_user(tmp, &sc->sc_fpregs[0]) |
  137. __get_user(tmp, &sc->sc_fpregs[31]) |
  138. __get_user(tmp, &sc->sc_fpc_csr);
  139. if (err)
  140. break; /* really bad sigcontext */
  141. }
  142. #else
  143. /*
  144. * EVA does not have FPU EVA instructions so restoring fpu context
  145. * directly does not work.
  146. */
  147. lose_fpu(0);
  148. err = restore_fp_context(sc); /* this might fail */
  149. #endif
  150. return err;
  151. }
  152. int setup_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
  153. {
  154. int err = 0;
  155. int i;
  156. unsigned int used_math;
  157. err |= __put_user(regs->cp0_epc, &sc->sc_pc);
  158. err |= __put_user(0, &sc->sc_regs[0]);
  159. for (i = 1; i < 32; i++)
  160. err |= __put_user(regs->regs[i], &sc->sc_regs[i]);
  161. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  162. err |= __put_user(regs->acx, &sc->sc_acx);
  163. #endif
  164. err |= __put_user(regs->hi, &sc->sc_mdhi);
  165. err |= __put_user(regs->lo, &sc->sc_mdlo);
  166. if (cpu_has_dsp) {
  167. err |= __put_user(mfhi1(), &sc->sc_hi1);
  168. err |= __put_user(mflo1(), &sc->sc_lo1);
  169. err |= __put_user(mfhi2(), &sc->sc_hi2);
  170. err |= __put_user(mflo2(), &sc->sc_lo2);
  171. err |= __put_user(mfhi3(), &sc->sc_hi3);
  172. err |= __put_user(mflo3(), &sc->sc_lo3);
  173. err |= __put_user(rddsp(DSP_MASK), &sc->sc_dsp);
  174. }
  175. used_math = !!used_math();
  176. err |= __put_user(used_math, &sc->sc_used_math);
  177. if (used_math) {
  178. /*
  179. * Save FPU state to signal context. Signal handler
  180. * will "inherit" current FPU state.
  181. */
  182. err |= protected_save_fp_context(sc);
  183. }
  184. return err;
  185. }
  186. int fpcsr_pending(unsigned int __user *fpcsr)
  187. {
  188. int err, sig = 0;
  189. unsigned int csr, enabled;
  190. err = __get_user(csr, fpcsr);
  191. enabled = FPU_CSR_UNI_X | ((csr & FPU_CSR_ALL_E) << 5);
  192. /*
  193. * If the signal handler set some FPU exceptions, clear it and
  194. * send SIGFPE.
  195. */
  196. if (csr & enabled) {
  197. csr &= ~enabled;
  198. err |= __put_user(csr, fpcsr);
  199. sig = SIGFPE;
  200. }
  201. return err ?: sig;
  202. }
  203. static int
  204. check_and_restore_fp_context(struct sigcontext __user *sc)
  205. {
  206. int err, sig;
  207. err = sig = fpcsr_pending(&sc->sc_fpc_csr);
  208. if (err > 0)
  209. err = 0;
  210. err |= protected_restore_fp_context(sc);
  211. return err ?: sig;
  212. }
  213. int restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc)
  214. {
  215. unsigned int used_math;
  216. unsigned long treg;
  217. int err = 0;
  218. int i;
  219. /* Always make any pending restarted system calls return -EINTR */
  220. current->restart_block.fn = do_no_restart_syscall;
  221. err |= __get_user(regs->cp0_epc, &sc->sc_pc);
  222. #ifdef CONFIG_CPU_HAS_SMARTMIPS
  223. err |= __get_user(regs->acx, &sc->sc_acx);
  224. #endif
  225. err |= __get_user(regs->hi, &sc->sc_mdhi);
  226. err |= __get_user(regs->lo, &sc->sc_mdlo);
  227. if (cpu_has_dsp) {
  228. err |= __get_user(treg, &sc->sc_hi1); mthi1(treg);
  229. err |= __get_user(treg, &sc->sc_lo1); mtlo1(treg);
  230. err |= __get_user(treg, &sc->sc_hi2); mthi2(treg);
  231. err |= __get_user(treg, &sc->sc_lo2); mtlo2(treg);
  232. err |= __get_user(treg, &sc->sc_hi3); mthi3(treg);
  233. err |= __get_user(treg, &sc->sc_lo3); mtlo3(treg);
  234. err |= __get_user(treg, &sc->sc_dsp); wrdsp(treg, DSP_MASK);
  235. }
  236. for (i = 1; i < 32; i++)
  237. err |= __get_user(regs->regs[i], &sc->sc_regs[i]);
  238. err |= __get_user(used_math, &sc->sc_used_math);
  239. conditional_used_math(used_math);
  240. if (used_math) {
  241. /* restore fpu context if we have used it before */
  242. if (!err)
  243. err = check_and_restore_fp_context(sc);
  244. } else {
  245. /* signal handler may have used FPU. Give it up. */
  246. lose_fpu(0);
  247. }
  248. return err;
  249. }
  250. void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
  251. size_t frame_size)
  252. {
  253. unsigned long sp;
  254. /* Default to using normal stack */
  255. sp = regs->regs[29];
  256. /*
  257. * FPU emulator may have it's own trampoline active just
  258. * above the user stack, 16-bytes before the next lowest
  259. * 16 byte boundary. Try to avoid trashing it.
  260. */
  261. sp -= 32;
  262. sp = sigsp(sp, ksig);
  263. return (void __user *)((sp - frame_size) & (ICACHE_REFILLS_WORKAROUND_WAR ? ~(cpu_icache_line_size()-1) : ALMASK));
  264. }
  265. /*
  266. * Atomically swap in the new signal mask, and wait for a signal.
  267. */
  268. #ifdef CONFIG_TRAD_SIGNALS
  269. SYSCALL_DEFINE1(sigsuspend, sigset_t __user *, uset)
  270. {
  271. return sys_rt_sigsuspend(uset, sizeof(sigset_t));
  272. }
  273. #endif
  274. #ifdef CONFIG_TRAD_SIGNALS
  275. SYSCALL_DEFINE3(sigaction, int, sig, const struct sigaction __user *, act,
  276. struct sigaction __user *, oact)
  277. {
  278. struct k_sigaction new_ka, old_ka;
  279. int ret;
  280. int err = 0;
  281. if (act) {
  282. old_sigset_t mask;
  283. if (!access_ok(VERIFY_READ, act, sizeof(*act)))
  284. return -EFAULT;
  285. err |= __get_user(new_ka.sa.sa_handler, &act->sa_handler);
  286. err |= __get_user(new_ka.sa.sa_flags, &act->sa_flags);
  287. err |= __get_user(mask, &act->sa_mask.sig[0]);
  288. if (err)
  289. return -EFAULT;
  290. siginitset(&new_ka.sa.sa_mask, mask);
  291. }
  292. ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
  293. if (!ret && oact) {
  294. if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)))
  295. return -EFAULT;
  296. err |= __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
  297. err |= __put_user(old_ka.sa.sa_handler, &oact->sa_handler);
  298. err |= __put_user(old_ka.sa.sa_mask.sig[0], oact->sa_mask.sig);
  299. err |= __put_user(0, &oact->sa_mask.sig[1]);
  300. err |= __put_user(0, &oact->sa_mask.sig[2]);
  301. err |= __put_user(0, &oact->sa_mask.sig[3]);
  302. if (err)
  303. return -EFAULT;
  304. }
  305. return ret;
  306. }
  307. #endif
  308. #ifdef CONFIG_TRAD_SIGNALS
  309. asmlinkage void sys_sigreturn(nabi_no_regargs struct pt_regs regs)
  310. {
  311. struct sigframe __user *frame;
  312. sigset_t blocked;
  313. int sig;
  314. frame = (struct sigframe __user *) regs.regs[29];
  315. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  316. goto badframe;
  317. if (__copy_from_user(&blocked, &frame->sf_mask, sizeof(blocked)))
  318. goto badframe;
  319. set_current_blocked(&blocked);
  320. sig = restore_sigcontext(&regs, &frame->sf_sc);
  321. if (sig < 0)
  322. goto badframe;
  323. else if (sig)
  324. force_sig(sig, current);
  325. /*
  326. * Don't let your children do this ...
  327. */
  328. __asm__ __volatile__(
  329. "move\t$29, %0\n\t"
  330. "j\tsyscall_exit"
  331. :/* no outputs */
  332. :"r" (&regs));
  333. /* Unreached */
  334. badframe:
  335. force_sig(SIGSEGV, current);
  336. }
  337. #endif /* CONFIG_TRAD_SIGNALS */
  338. asmlinkage void sys_rt_sigreturn(nabi_no_regargs struct pt_regs regs)
  339. {
  340. struct rt_sigframe __user *frame;
  341. sigset_t set;
  342. int sig;
  343. frame = (struct rt_sigframe __user *) regs.regs[29];
  344. if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  345. goto badframe;
  346. if (__copy_from_user(&set, &frame->rs_uc.uc_sigmask, sizeof(set)))
  347. goto badframe;
  348. set_current_blocked(&set);
  349. sig = restore_sigcontext(&regs, &frame->rs_uc.uc_mcontext);
  350. if (sig < 0)
  351. goto badframe;
  352. else if (sig)
  353. force_sig(sig, current);
  354. if (restore_altstack(&frame->rs_uc.uc_stack))
  355. goto badframe;
  356. /*
  357. * Don't let your children do this ...
  358. */
  359. __asm__ __volatile__(
  360. "move\t$29, %0\n\t"
  361. "j\tsyscall_exit"
  362. :/* no outputs */
  363. :"r" (&regs));
  364. /* Unreached */
  365. badframe:
  366. force_sig(SIGSEGV, current);
  367. }
  368. #ifdef CONFIG_TRAD_SIGNALS
  369. static int setup_frame(void *sig_return, struct ksignal *ksig,
  370. struct pt_regs *regs, sigset_t *set)
  371. {
  372. struct sigframe __user *frame;
  373. int err = 0;
  374. frame = get_sigframe(ksig, regs, sizeof(*frame));
  375. if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
  376. return -EFAULT;
  377. err |= setup_sigcontext(regs, &frame->sf_sc);
  378. err |= __copy_to_user(&frame->sf_mask, set, sizeof(*set));
  379. if (err)
  380. return -EFAULT;
  381. /*
  382. * Arguments to signal handler:
  383. *
  384. * a0 = signal number
  385. * a1 = 0 (should be cause)
  386. * a2 = pointer to struct sigcontext
  387. *
  388. * $25 and c0_epc point to the signal handler, $29 points to the
  389. * struct sigframe.
  390. */
  391. regs->regs[ 4] = ksig->sig;
  392. regs->regs[ 5] = 0;
  393. regs->regs[ 6] = (unsigned long) &frame->sf_sc;
  394. regs->regs[29] = (unsigned long) frame;
  395. regs->regs[31] = (unsigned long) sig_return;
  396. regs->cp0_epc = regs->regs[25] = (unsigned long) ksig->ka.sa.sa_handler;
  397. DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
  398. current->comm, current->pid,
  399. frame, regs->cp0_epc, regs->regs[31]);
  400. return 0;
  401. }
  402. #endif
  403. static int setup_rt_frame(void *sig_return, struct ksignal *ksig,
  404. struct pt_regs *regs, sigset_t *set)
  405. {
  406. struct rt_sigframe __user *frame;
  407. int err = 0;
  408. frame = get_sigframe(ksig, regs, sizeof(*frame));
  409. if (!access_ok(VERIFY_WRITE, frame, sizeof (*frame)))
  410. return -EFAULT;
  411. /* Create siginfo. */
  412. err |= copy_siginfo_to_user(&frame->rs_info, &ksig->info);
  413. /* Create the ucontext. */
  414. err |= __put_user(0, &frame->rs_uc.uc_flags);
  415. err |= __put_user(NULL, &frame->rs_uc.uc_link);
  416. err |= __save_altstack(&frame->rs_uc.uc_stack, regs->regs[29]);
  417. err |= setup_sigcontext(regs, &frame->rs_uc.uc_mcontext);
  418. err |= __copy_to_user(&frame->rs_uc.uc_sigmask, set, sizeof(*set));
  419. if (err)
  420. return -EFAULT;
  421. /*
  422. * Arguments to signal handler:
  423. *
  424. * a0 = signal number
  425. * a1 = 0 (should be cause)
  426. * a2 = pointer to ucontext
  427. *
  428. * $25 and c0_epc point to the signal handler, $29 points to
  429. * the struct rt_sigframe.
  430. */
  431. regs->regs[ 4] = ksig->sig;
  432. regs->regs[ 5] = (unsigned long) &frame->rs_info;
  433. regs->regs[ 6] = (unsigned long) &frame->rs_uc;
  434. regs->regs[29] = (unsigned long) frame;
  435. regs->regs[31] = (unsigned long) sig_return;
  436. regs->cp0_epc = regs->regs[25] = (unsigned long) ksig->ka.sa.sa_handler;
  437. DEBUGP("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%lx\n",
  438. current->comm, current->pid,
  439. frame, regs->cp0_epc, regs->regs[31]);
  440. return 0;
  441. }
  442. struct mips_abi mips_abi = {
  443. #ifdef CONFIG_TRAD_SIGNALS
  444. .setup_frame = setup_frame,
  445. .signal_return_offset = offsetof(struct mips_vdso, signal_trampoline),
  446. #endif
  447. .setup_rt_frame = setup_rt_frame,
  448. .rt_signal_return_offset =
  449. offsetof(struct mips_vdso, rt_signal_trampoline),
  450. .restart = __NR_restart_syscall
  451. };
  452. static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
  453. {
  454. sigset_t *oldset = sigmask_to_save();
  455. int ret;
  456. struct mips_abi *abi = current->thread.abi;
  457. #ifdef CONFIG_CPU_MICROMIPS
  458. void *vdso;
  459. unsigned long tmp = (unsigned long)current->mm->context.vdso;
  460. set_isa16_mode(tmp);
  461. vdso = (void *)tmp;
  462. #else
  463. void *vdso = current->mm->context.vdso;
  464. #endif
  465. if (regs->regs[0]) {
  466. switch(regs->regs[2]) {
  467. case ERESTART_RESTARTBLOCK:
  468. case ERESTARTNOHAND:
  469. regs->regs[2] = EINTR;
  470. break;
  471. case ERESTARTSYS:
  472. if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
  473. regs->regs[2] = EINTR;
  474. break;
  475. }
  476. /* fallthrough */
  477. case ERESTARTNOINTR:
  478. regs->regs[7] = regs->regs[26];
  479. regs->regs[2] = regs->regs[0];
  480. regs->cp0_epc -= 4;
  481. }
  482. regs->regs[0] = 0; /* Don't deal with this again. */
  483. }
  484. if (sig_uses_siginfo(&ksig->ka))
  485. ret = abi->setup_rt_frame(vdso + abi->rt_signal_return_offset,
  486. ksig, regs, oldset);
  487. else
  488. ret = abi->setup_frame(vdso + abi->signal_return_offset, ksig,
  489. regs, oldset);
  490. signal_setup_done(ret, ksig, 0);
  491. }
  492. static void do_signal(struct pt_regs *regs)
  493. {
  494. struct ksignal ksig;
  495. if (get_signal(&ksig)) {
  496. /* Whee! Actually deliver the signal. */
  497. handle_signal(&ksig, regs);
  498. return;
  499. }
  500. if (regs->regs[0]) {
  501. switch (regs->regs[2]) {
  502. case ERESTARTNOHAND:
  503. case ERESTARTSYS:
  504. case ERESTARTNOINTR:
  505. regs->regs[2] = regs->regs[0];
  506. regs->regs[7] = regs->regs[26];
  507. regs->cp0_epc -= 4;
  508. break;
  509. case ERESTART_RESTARTBLOCK:
  510. regs->regs[2] = current->thread.abi->restart;
  511. regs->regs[7] = regs->regs[26];
  512. regs->cp0_epc -= 4;
  513. break;
  514. }
  515. regs->regs[0] = 0; /* Don't deal with this again. */
  516. }
  517. /*
  518. * If there's no signal to deliver, we just put the saved sigmask
  519. * back
  520. */
  521. restore_saved_sigmask();
  522. }
  523. /*
  524. * notification of userspace execution resumption
  525. * - triggered by the TIF_WORK_MASK flags
  526. */
  527. asmlinkage void do_notify_resume(struct pt_regs *regs, void *unused,
  528. __u32 thread_info_flags)
  529. {
  530. local_irq_enable();
  531. user_exit();
  532. /* deal with pending signal delivery */
  533. if (thread_info_flags & _TIF_SIGPENDING)
  534. do_signal(regs);
  535. if (thread_info_flags & _TIF_NOTIFY_RESUME) {
  536. clear_thread_flag(TIF_NOTIFY_RESUME);
  537. tracehook_notify_resume(regs);
  538. }
  539. user_enter();
  540. }
  541. #ifdef CONFIG_SMP
  542. #ifndef CONFIG_EVA
  543. static int smp_save_fp_context(struct sigcontext __user *sc)
  544. {
  545. return raw_cpu_has_fpu
  546. ? _save_fp_context(sc)
  547. : copy_fp_to_sigcontext(sc);
  548. }
  549. static int smp_restore_fp_context(struct sigcontext __user *sc)
  550. {
  551. return raw_cpu_has_fpu
  552. ? _restore_fp_context(sc)
  553. : copy_fp_from_sigcontext(sc);
  554. }
  555. #endif /* CONFIG_EVA */
  556. #endif
  557. static int signal_setup(void)
  558. {
  559. #ifndef CONFIG_EVA
  560. #ifdef CONFIG_SMP
  561. /* For now just do the cpu_has_fpu check when the functions are invoked */
  562. save_fp_context = smp_save_fp_context;
  563. restore_fp_context = smp_restore_fp_context;
  564. #else
  565. if (cpu_has_fpu) {
  566. save_fp_context = _save_fp_context;
  567. restore_fp_context = _restore_fp_context;
  568. } else {
  569. save_fp_context = copy_fp_to_sigcontext;
  570. restore_fp_context = copy_fp_from_sigcontext;
  571. }
  572. #endif /* CONFIG_SMP */
  573. #else
  574. save_fp_context = copy_fp_to_sigcontext;
  575. restore_fp_context = copy_fp_from_sigcontext;
  576. #endif
  577. return 0;
  578. }
  579. arch_initcall(signal_setup);