sigutil_32.c 3.2 KB

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