_UPT_access_fpreg.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* libunwind - a platform-independent unwind library
  2. Copyright (C) 2003 Hewlett-Packard Co
  3. Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
  4. Copyright (C) 2010 Konstantin Belousov <kib@freebsd.org>
  5. This file is part of libunwind.
  6. Permission is hereby granted, free of charge, to any person obtaining
  7. a copy of this software and associated documentation files (the
  8. "Software"), to deal in the Software without restriction, including
  9. without limitation the rights to use, copy, modify, merge, publish,
  10. distribute, sublicense, and/or sell copies of the Software, and to
  11. permit persons to whom the Software is furnished to do so, subject to
  12. the following conditions:
  13. The above copyright notice and this permission notice shall be
  14. included in all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  22. #include "_UPT_internal.h"
  23. #if HAVE_DECL_PTRACE_POKEUSER || HAVE_TTRACE
  24. int
  25. _UPT_access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
  26. int write, void *arg)
  27. {
  28. unw_word_t *wp = (unw_word_t *) val;
  29. struct UPT_info *ui = arg;
  30. pid_t pid = ui->pid;
  31. int i;
  32. if ((unsigned) reg >= sizeof (_UPT_reg_offset) / sizeof (_UPT_reg_offset[0]))
  33. return -UNW_EBADREG;
  34. errno = 0;
  35. if (write)
  36. for (i = 0; i < (int) (sizeof (*val) / sizeof (wp[i])); ++i)
  37. {
  38. #ifdef HAVE_TTRACE
  39. # warning No support for ttrace() yet.
  40. #else
  41. ptrace (PTRACE_POKEUSER, pid, _UPT_reg_offset[reg] + i * sizeof(wp[i]),
  42. wp[i]);
  43. #endif
  44. if (errno)
  45. return -UNW_EBADREG;
  46. }
  47. else
  48. for (i = 0; i < (int) (sizeof (*val) / sizeof (wp[i])); ++i)
  49. {
  50. #ifdef HAVE_TTRACE
  51. # warning No support for ttrace() yet.
  52. #else
  53. wp[i] = ptrace (PTRACE_PEEKUSER, pid,
  54. _UPT_reg_offset[reg] + i * sizeof(wp[i]), 0);
  55. #endif
  56. if (errno)
  57. return -UNW_EBADREG;
  58. }
  59. return 0;
  60. }
  61. #elif HAVE_DECL_PT_GETFPREGS
  62. int
  63. _UPT_access_fpreg (unw_addr_space_t as, unw_regnum_t reg, unw_fpreg_t *val,
  64. int write, void *arg)
  65. {
  66. struct UPT_info *ui = arg;
  67. pid_t pid = ui->pid;
  68. fpregset_t fpreg;
  69. if ((unsigned) reg >= sizeof (_UPT_reg_offset) / sizeof (_UPT_reg_offset[0]))
  70. return -UNW_EBADREG;
  71. if (ptrace(PT_GETFPREGS, pid, (caddr_t)&fpreg, 0) == -1)
  72. return -UNW_EBADREG;
  73. if (write) {
  74. #if defined(__amd64__)
  75. memcpy(&fpreg.fpr_xacc[reg], val, sizeof(unw_fpreg_t));
  76. #elif defined(__i386__)
  77. memcpy(&fpreg.fpr_acc[reg], val, sizeof(unw_fpreg_t));
  78. #else
  79. #error Fix me
  80. #endif
  81. if (ptrace(PT_SETFPREGS, pid, (caddr_t)&fpreg, 0) == -1)
  82. return -UNW_EBADREG;
  83. } else
  84. #if defined(__amd64__)
  85. memcpy(val, &fpreg.fpr_xacc[reg], sizeof(unw_fpreg_t));
  86. #elif defined(__i386__)
  87. memcpy(val, &fpreg.fpr_acc[reg], sizeof(unw_fpreg_t));
  88. #else
  89. #error Fix me
  90. #endif
  91. return 0;
  92. }
  93. #else
  94. #error Fix me
  95. #endif