sigutil_32.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. if (((unsigned long) fpu) & 3)
  48. return -EFAULT;
  49. #ifdef CONFIG_SMP
  50. if (test_tsk_thread_flag(current, TIF_USEDFPU))
  51. regs->psr &= ~PSR_EF;
  52. #else
  53. if (current == last_task_used_math) {
  54. last_task_used_math = NULL;
  55. regs->psr &= ~PSR_EF;
  56. }
  57. #endif
  58. set_used_math();
  59. clear_tsk_thread_flag(current, TIF_USEDFPU);
  60. if (!access_ok(VERIFY_READ, fpu, sizeof(*fpu)))
  61. return -EFAULT;
  62. err = __copy_from_user(&current->thread.float_regs[0], &fpu->si_float_regs[0],
  63. (sizeof(unsigned long) * 32));
  64. err |= __get_user(current->thread.fsr, &fpu->si_fsr);
  65. err |= __get_user(current->thread.fpqdepth, &fpu->si_fpqdepth);
  66. if (current->thread.fpqdepth != 0)
  67. err |= __copy_from_user(&current->thread.fpqueue[0],
  68. &fpu->si_fpqueue[0],
  69. ((sizeof(unsigned long) +
  70. (sizeof(unsigned long *)))*16));
  71. return err;
  72. }
  73. int save_rwin_state(int wsaved, __siginfo_rwin_t __user *rwin)
  74. {
  75. int i, err = __put_user(wsaved, &rwin->wsaved);
  76. for (i = 0; i < wsaved; i++) {
  77. struct reg_window32 *rp;
  78. unsigned long fp;
  79. rp = &current_thread_info()->reg_window[i];
  80. fp = current_thread_info()->rwbuf_stkptrs[i];
  81. err |= copy_to_user(&rwin->reg_window[i], rp,
  82. sizeof(struct reg_window32));
  83. err |= __put_user(fp, &rwin->rwbuf_stkptrs[i]);
  84. }
  85. return err;
  86. }
  87. int restore_rwin_state(__siginfo_rwin_t __user *rp)
  88. {
  89. struct thread_info *t = current_thread_info();
  90. int i, wsaved, err;
  91. if (((unsigned long) rp) & 3)
  92. return -EFAULT;
  93. get_user(wsaved, &rp->wsaved);
  94. if (wsaved > NSWINS)
  95. return -EFAULT;
  96. err = 0;
  97. for (i = 0; i < wsaved; i++) {
  98. err |= copy_from_user(&t->reg_window[i],
  99. &rp->reg_window[i],
  100. sizeof(struct reg_window32));
  101. err |= __get_user(t->rwbuf_stkptrs[i],
  102. &rp->rwbuf_stkptrs[i]);
  103. }
  104. if (err)
  105. return err;
  106. t->w_saved = wsaved;
  107. synchronize_user_stack();
  108. if (t->w_saved)
  109. return -EFAULT;
  110. return 0;
  111. }