sigutil_32.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include <linux/kernel.h>
  2. #include <linux/types.h>
  3. #include <linux/thread_info.h>
  4. #include <linux/uaccess.h>
  5. #include <linux/sched.h>
  6. #include <asm/sigcontext.h>
  7. #include <asm/fpumacro.h>
  8. #include <asm/ptrace.h>
  9. #include <asm/switch_to.h>
  10. #include "sigutil.h"
  11. int save_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
  12. {
  13. int err = 0;
  14. #ifdef CONFIG_SMP
  15. if (test_tsk_thread_flag(current, TIF_USEDFPU)) {
  16. put_psr(get_psr() | PSR_EF);
  17. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  18. &current->thread.fpqueue[0], &current->thread.fpqdepth);
  19. regs->psr &= ~(PSR_EF);
  20. clear_tsk_thread_flag(current, TIF_USEDFPU);
  21. }
  22. #else
  23. if (current == last_task_used_math) {
  24. put_psr(get_psr() | PSR_EF);
  25. fpsave(&current->thread.float_regs[0], &current->thread.fsr,
  26. &current->thread.fpqueue[0], &current->thread.fpqdepth);
  27. last_task_used_math = NULL;
  28. regs->psr &= ~(PSR_EF);
  29. }
  30. #endif
  31. err |= __copy_to_user(&fpu->si_float_regs[0],
  32. &current->thread.float_regs[0],
  33. (sizeof(unsigned long) * 32));
  34. err |= __put_user(current->thread.fsr, &fpu->si_fsr);
  35. err |= __put_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
  36. if (current->thread.fpqdepth != 0)
  37. err |= __copy_to_user(&fpu->si_fpqueue[0],
  38. &current->thread.fpqueue[0],
  39. ((sizeof(unsigned long) +
  40. (sizeof(unsigned long *)))*16));
  41. clear_used_math();
  42. return err;
  43. }
  44. int restore_fpu_state(struct pt_regs *regs, __siginfo_fpu_t __user *fpu)
  45. {
  46. int err;
  47. #ifdef CONFIG_SMP
  48. if (test_tsk_thread_flag(current, TIF_USEDFPU))
  49. regs->psr &= ~PSR_EF;
  50. #else
  51. if (current == last_task_used_math) {
  52. last_task_used_math = NULL;
  53. regs->psr &= ~PSR_EF;
  54. }
  55. #endif
  56. set_used_math();
  57. clear_tsk_thread_flag(current, TIF_USEDFPU);
  58. if (!access_ok(VERIFY_READ, fpu, sizeof(*fpu)))
  59. return -EFAULT;
  60. err = __copy_from_user(&current->thread.float_regs[0], &fpu->si_float_regs[0],
  61. (sizeof(unsigned long) * 32));
  62. err |= __get_user(current->thread.fsr, &fpu->si_fsr);
  63. err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
  64. if (current->thread.fpqdepth != 0)
  65. err |= __copy_from_user(&current->thread.fpqueue[0],
  66. &fpu->si_fpqueue[0],
  67. ((sizeof(unsigned long) +
  68. (sizeof(unsigned long *)))*16));
  69. return err;
  70. }
  71. int save_rwin_state(int wsaved, __siginfo_rwin_t __user *rwin)
  72. {
  73. int i, err = __put_user(wsaved, &rwin->wsaved);
  74. for (i = 0; i < wsaved; i++) {
  75. struct reg_window32 *rp;
  76. unsigned long fp;
  77. rp = &current_thread_info()->reg_window[i];
  78. fp = current_thread_info()->rwbuf_stkptrs[i];
  79. err |= copy_to_user(&rwin->reg_window[i], rp,
  80. sizeof(struct reg_window32));
  81. err |= __put_user(fp, &rwin->rwbuf_stkptrs[i]);
  82. }
  83. return err;
  84. }
  85. int restore_rwin_state(__siginfo_rwin_t __user *rp)
  86. {
  87. struct thread_info *t = current_thread_info();
  88. int i, wsaved, err;
  89. __get_user(wsaved, &rp->wsaved);
  90. if (wsaved > NSWINS)
  91. return -EFAULT;
  92. err = 0;
  93. for (i = 0; i < wsaved; i++) {
  94. err |= copy_from_user(&t->reg_window[i],
  95. &rp->reg_window[i],
  96. sizeof(struct reg_window32));
  97. err |= __get_user(t->rwbuf_stkptrs[i],
  98. &rp->rwbuf_stkptrs[i]);
  99. }
  100. if (err)
  101. return err;
  102. t->w_saved = wsaved;
  103. synchronize_user_stack();
  104. if (t->w_saved)
  105. return -EFAULT;
  106. return 0;
  107. }