remote.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef REMOTE_H
  2. #define REMOTE_H
  3. /* Helper functions for accessing (remote) memory. These functions
  4. assume that all addresses are naturally aligned (e.g., 32-bit
  5. quantity is stored at a 32-bit-aligned address. */
  6. #ifdef UNW_LOCAL_ONLY
  7. static inline int
  8. fetch8 (unw_addr_space_t as, unw_accessors_t *a,
  9. unw_word_t *addr, int8_t *valp, void *arg)
  10. {
  11. *valp = *(int8_t *) (uintptr_t) *addr;
  12. *addr += 1;
  13. return 0;
  14. }
  15. static inline int
  16. fetch16 (unw_addr_space_t as, unw_accessors_t *a,
  17. unw_word_t *addr, int16_t *valp, void *arg)
  18. {
  19. *valp = *(int16_t *) (uintptr_t) *addr;
  20. *addr += 2;
  21. return 0;
  22. }
  23. static inline int
  24. fetch32 (unw_addr_space_t as, unw_accessors_t *a,
  25. unw_word_t *addr, int32_t *valp, void *arg)
  26. {
  27. *valp = *(int32_t *) (uintptr_t) *addr;
  28. *addr += 4;
  29. return 0;
  30. }
  31. static inline int
  32. fetchw (unw_addr_space_t as, unw_accessors_t *a,
  33. unw_word_t *addr, unw_word_t *valp, void *arg)
  34. {
  35. *valp = *(unw_word_t *) (uintptr_t) *addr;
  36. *addr += sizeof (unw_word_t);
  37. return 0;
  38. }
  39. #else /* !UNW_LOCAL_ONLY */
  40. #define WSIZE (sizeof (unw_word_t))
  41. static inline int
  42. fetch8 (unw_addr_space_t as, unw_accessors_t *a,
  43. unw_word_t *addr, int8_t *valp, void *arg)
  44. {
  45. unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
  46. int ret;
  47. *addr += 1;
  48. ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
  49. #if __BYTE_ORDER == __LITTLE_ENDIAN
  50. val >>= 8*off;
  51. #else
  52. val >>= 8*(WSIZE - 1 - off);
  53. #endif
  54. *valp = val & 0xff;
  55. return ret;
  56. }
  57. static inline int
  58. fetch16 (unw_addr_space_t as, unw_accessors_t *a,
  59. unw_word_t *addr, int16_t *valp, void *arg)
  60. {
  61. unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
  62. int ret;
  63. assert ((off & 0x1) == 0);
  64. *addr += 2;
  65. ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
  66. #if __BYTE_ORDER == __LITTLE_ENDIAN
  67. val >>= 8*off;
  68. #else
  69. val >>= 8*(WSIZE - 2 - off);
  70. #endif
  71. *valp = val & 0xffff;
  72. return ret;
  73. }
  74. static inline int
  75. fetch32 (unw_addr_space_t as, unw_accessors_t *a,
  76. unw_word_t *addr, int32_t *valp, void *arg)
  77. {
  78. unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
  79. int ret;
  80. assert ((off & 0x3) == 0);
  81. *addr += 4;
  82. ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
  83. #if __BYTE_ORDER == __LITTLE_ENDIAN
  84. val >>= 8*off;
  85. #else
  86. val >>= 8*(WSIZE - 4 - off);
  87. #endif
  88. *valp = val & 0xffffffff;
  89. return ret;
  90. }
  91. static inline int
  92. fetchw (unw_addr_space_t as, unw_accessors_t *a,
  93. unw_word_t *addr, unw_word_t *valp, void *arg)
  94. {
  95. int ret;
  96. ret = (*a->access_mem) (as, *addr, valp, 0, arg);
  97. *addr += WSIZE;
  98. return ret;
  99. }
  100. #endif /* !UNW_LOCAL_ONLY */
  101. #endif /* REMOTE_H */