sigutil_64.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include <linux/kernel.h>
  2. #include <linux/types.h>
  3. #include <linux/thread_info.h>
  4. #include <linux/uaccess.h>
  5. #include <asm/sigcontext.h>
  6. #include <asm/fpumacro.h>
  7. #include <asm/ptrace.h>
  8. #include "sigutil.h"
  9. int save_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
  10. {
  11. unsigned long *fpregs = current_thread_info()->fpregs;
  12. unsigned long fprs;
  13. int err = 0;
  14. fprs = current_thread_info()->fpsaved[0];
  15. if (fprs & FPRS_DL)
  16. err |= copy_to_user(&fpu->si_float_regs[0], fpregs,
  17. (sizeof(unsigned int) * 32));
  18. if (fprs & FPRS_DU)
  19. err |= copy_to_user(&fpu->si_float_regs[32], fpregs+16,
  20. (sizeof(unsigned int) * 32));
  21. err |= __put_user(current_thread_info()->xfsr[0], &fpu->si_fsr);
  22. err |= __put_user(current_thread_info()->gsr[0], &fpu->si_gsr);
  23. err |= __put_user(fprs, &fpu->si_fprs);
  24. return err;
  25. }
  26. int restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
  27. {
  28. unsigned long *fpregs = current_thread_info()->fpregs;
  29. unsigned long fprs;
  30. int err;
  31. err = __get_user(fprs, &fpu->si_fprs);
  32. fprs_write(0);
  33. regs->tstate &= ~TSTATE_PEF;
  34. if (fprs & FPRS_DL)
  35. err |= copy_from_user(fpregs, &fpu->si_float_regs[0],
  36. (sizeof(unsigned int) * 32));
  37. if (fprs & FPRS_DU)
  38. err |= copy_from_user(fpregs+16, &fpu->si_float_regs[32],
  39. (sizeof(unsigned int) * 32));
  40. err |= __get_user(current_thread_info()->xfsr[0], &fpu->si_fsr);
  41. err |= __get_user(current_thread_info()->gsr[0], &fpu->si_gsr);
  42. current_thread_info()->fpsaved[0] |= fprs;
  43. return err;
  44. }
  45. int save_rwin_state(int wsaved, __siginfo_rwin_t __user *rwin)
  46. {
  47. int i, err = __put_user(wsaved, &rwin->wsaved);
  48. for (i = 0; i < wsaved; i++) {
  49. struct reg_window *rp = &current_thread_info()->reg_window[i];
  50. unsigned long fp = current_thread_info()->rwbuf_stkptrs[i];
  51. err |= copy_to_user(&rwin->reg_window[i], rp,
  52. sizeof(struct reg_window));
  53. err |= __put_user(fp, &rwin->rwbuf_stkptrs[i]);
  54. }
  55. return err;
  56. }
  57. int restore_rwin_state(__siginfo_rwin_t __user *rp)
  58. {
  59. struct thread_info *t = current_thread_info();
  60. int i, wsaved, err;
  61. __get_user(wsaved, &rp->wsaved);
  62. if (wsaved > NSWINS)
  63. return -EFAULT;
  64. err = 0;
  65. for (i = 0; i < wsaved; i++) {
  66. err |= copy_from_user(&t->reg_window[i],
  67. &rp->reg_window[i],
  68. sizeof(struct reg_window));
  69. err |= __get_user(t->rwbuf_stkptrs[i],
  70. &rp->rwbuf_stkptrs[i]);
  71. }
  72. if (err)
  73. return err;
  74. set_thread_wsaved(wsaved);
  75. synchronize_user_stack();
  76. if (get_thread_wsaved())
  77. return -EFAULT;
  78. return 0;
  79. }