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