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 #define WSIZE   (sizeof (unw_word_t))
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   unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
15   int ret;
16 
17   *addr += 1;
18 
19   ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
20 
21 #if __BYTE_ORDER == __LITTLE_ENDIAN
22   val >>= 8*off;
23 #else
24   val >>= 8*(WSIZE - 1 - off);
25 #endif
26   *valp = val & 0xff;
27   return ret;
28 }
29 
30 static inline int
fetch16(unw_addr_space_t as,unw_accessors_t * a,unw_word_t * addr,int16_t * valp,void * arg)31 fetch16 (unw_addr_space_t as, unw_accessors_t *a,
32          unw_word_t *addr, int16_t *valp, void *arg)
33 {
34   unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
35   int ret;
36 
37   assert ((off & 0x1) == 0);
38 
39   *addr += 2;
40 
41   ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
42 
43 #if __BYTE_ORDER == __LITTLE_ENDIAN
44   val >>= 8*off;
45 #else
46   val >>= 8*(WSIZE - 2 - off);
47 #endif
48   *valp = val & 0xffff;
49   return ret;
50 }
51 
52 static inline int
fetch32(unw_addr_space_t as,unw_accessors_t * a,unw_word_t * addr,int32_t * valp,void * arg)53 fetch32 (unw_addr_space_t as, unw_accessors_t *a,
54          unw_word_t *addr, int32_t *valp, void *arg)
55 {
56   unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
57   int ret;
58 
59   assert ((off & 0x3) == 0);
60 
61   *addr += 4;
62 
63   ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
64 
65 #if __BYTE_ORDER == __LITTLE_ENDIAN
66   val >>= 8*off;
67 #else
68   val >>= 8*(WSIZE - 4 - off);
69 #endif
70   *valp = val & 0xffffffff;
71   return ret;
72 }
73 
74 static inline int
fetchw(unw_addr_space_t as,unw_accessors_t * a,unw_word_t * addr,unw_word_t * valp,void * arg)75 fetchw (unw_addr_space_t as, unw_accessors_t *a,
76         unw_word_t *addr, unw_word_t *valp, void *arg)
77 {
78   int ret;
79 
80   ret = (*a->access_mem) (as, *addr, valp, 0, arg);
81   *addr += WSIZE;
82   return ret;
83 }
84 
85 #endif /* REMOTE_H */
86