/src/libunwind/include/remote.h
Line | Count | Source |
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 | | #include <string.h> |
11 | | |
12 | | static inline int |
13 | | fetch8 (unw_addr_space_t as UNUSED, unw_accessors_t *a UNUSED, |
14 | | unw_word_t *addr, int8_t *valp, void *arg UNUSED) |
15 | 0 | { |
16 | 0 | memcpy (valp, (void *) (uintptr_t) *addr, sizeof (*valp)); |
17 | 0 | *addr += 1; |
18 | 0 | return 0; |
19 | 0 | } |
20 | | |
21 | | static inline int |
22 | | fetch16 (unw_addr_space_t as UNUSED, unw_accessors_t *a UNUSED, |
23 | | unw_word_t *addr, int16_t *valp, void *arg UNUSED) |
24 | 0 | { |
25 | 0 | memcpy (valp, (void *) (uintptr_t) *addr, sizeof (*valp)); |
26 | 0 | *addr += 2; |
27 | 0 | return 0; |
28 | 0 | } |
29 | | |
30 | | static inline int |
31 | | fetch32 (unw_addr_space_t as UNUSED, unw_accessors_t *a UNUSED, |
32 | | unw_word_t *addr, int32_t *valp, void *arg UNUSED) |
33 | 0 | { |
34 | 0 | memcpy (valp, (void *) (uintptr_t) *addr, sizeof (*valp)); |
35 | 0 | *addr += 4; |
36 | 0 | return 0; |
37 | 0 | } |
38 | | |
39 | | static inline int |
40 | | fetchw (unw_addr_space_t as UNUSED, unw_accessors_t *a UNUSED, |
41 | | unw_word_t *addr, unw_word_t *valp, void *arg UNUSED) |
42 | 0 | { |
43 | 0 | memcpy (valp, (void *) (uintptr_t) *addr, sizeof (*valp)); |
44 | 0 | *addr += sizeof (unw_word_t); |
45 | 0 | return 0; |
46 | 0 | } |
47 | | |
48 | | #else /* !UNW_LOCAL_ONLY */ |
49 | | |
50 | | #define WSIZE (sizeof (unw_word_t)) |
51 | | |
52 | | static inline int |
53 | | fetch8 (unw_addr_space_t as, unw_accessors_t *a, |
54 | | unw_word_t *addr, int8_t *valp, void *arg) |
55 | | { |
56 | | unw_word_t val, aligned_addr = *addr & (~WSIZE + 1), off = *addr - aligned_addr; |
57 | | int ret; |
58 | | |
59 | | *addr += 1; |
60 | | |
61 | | ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg); |
62 | | |
63 | | #if UNW_BYTE_ORDER == UNW_LITTLE_ENDIAN |
64 | | val >>= 8*off; |
65 | | #else |
66 | | val >>= 8*(WSIZE - 1 - off); |
67 | | #endif |
68 | | *valp = val & 0xff; |
69 | | return ret; |
70 | | } |
71 | | |
72 | | static inline int |
73 | | fetch16 (unw_addr_space_t as, unw_accessors_t *a, |
74 | | unw_word_t *addr, int16_t *valp, void *arg) |
75 | | { |
76 | | unw_word_t val, aligned_addr = *addr & (~WSIZE + 1), off = *addr - aligned_addr; |
77 | | int ret; |
78 | | |
79 | | if ((off & 0x1) != 0) |
80 | | return -UNW_EINVAL; |
81 | | |
82 | | *addr += 2; |
83 | | |
84 | | ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg); |
85 | | |
86 | | #if UNW_BYTE_ORDER == UNW_LITTLE_ENDIAN |
87 | | val >>= 8*off; |
88 | | #else |
89 | | val >>= 8*(WSIZE - 2 - off); |
90 | | #endif |
91 | | *valp = val & 0xffff; |
92 | | return ret; |
93 | | } |
94 | | |
95 | | static inline int |
96 | | fetch32 (unw_addr_space_t as, unw_accessors_t *a, |
97 | | unw_word_t *addr, int32_t *valp, void *arg) |
98 | | { |
99 | | unw_word_t val, aligned_addr = *addr & (~WSIZE + 1), off = *addr - aligned_addr; |
100 | | int ret; |
101 | | |
102 | | if ((off & 0x3) != 0) |
103 | | return -UNW_EINVAL; |
104 | | |
105 | | *addr += 4; |
106 | | |
107 | | ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg); |
108 | | |
109 | | #if UNW_BYTE_ORDER == UNW_LITTLE_ENDIAN |
110 | | val >>= 8*off; |
111 | | #else |
112 | | val >>= 8*(WSIZE - 4 - off); |
113 | | #endif |
114 | | *valp = val & 0xffffffff; |
115 | | return ret; |
116 | | } |
117 | | |
118 | | static inline int |
119 | | fetchw (unw_addr_space_t as, unw_accessors_t *a, |
120 | | unw_word_t *addr, unw_word_t *valp, void *arg) |
121 | | { |
122 | | int ret; |
123 | | |
124 | | ret = (*a->access_mem) (as, *addr, valp, 0, arg); |
125 | | *addr += WSIZE; |
126 | | return ret; |
127 | | } |
128 | | |
129 | | #endif /* !UNW_LOCAL_ONLY */ |
130 | | |
131 | | #endif /* REMOTE_H */ |