vfs: check userland buffers before reading them.
[haiku.git] / headers / libs / libunwind / remote.h
blob6fdf64c17f9429ca1fdda5983993deb9daa46d25
1 #ifndef REMOTE_H
2 #define REMOTE_H
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. */
8 #ifdef UNW_LOCAL_ONLY
10 static inline int
11 fetch8 (unw_addr_space_t as, unw_accessors_t *a,
12 unw_word_t *addr, int8_t *valp, void *arg)
14 *valp = *(int8_t *) (uintptr_t) *addr;
15 *addr += 1;
16 return 0;
19 static inline int
20 fetch16 (unw_addr_space_t as, unw_accessors_t *a,
21 unw_word_t *addr, int16_t *valp, void *arg)
23 *valp = *(int16_t *) (uintptr_t) *addr;
24 *addr += 2;
25 return 0;
28 static inline int
29 fetch32 (unw_addr_space_t as, unw_accessors_t *a,
30 unw_word_t *addr, int32_t *valp, void *arg)
32 *valp = *(int32_t *) (uintptr_t) *addr;
33 *addr += 4;
34 return 0;
37 static inline int
38 fetchw (unw_addr_space_t as, unw_accessors_t *a,
39 unw_word_t *addr, unw_word_t *valp, void *arg)
41 *valp = *(unw_word_t *) (uintptr_t) *addr;
42 *addr += sizeof (unw_word_t);
43 return 0;
46 #else /* !UNW_LOCAL_ONLY */
48 #define WSIZE (sizeof (unw_word_t))
50 static inline int
51 fetch8 (unw_addr_space_t as, unw_accessors_t *a,
52 unw_word_t *addr, int8_t *valp, void *arg)
54 unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
55 int ret;
57 *addr += 1;
59 ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
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;
70 static inline int
71 fetch16 (unw_addr_space_t as, unw_accessors_t *a,
72 unw_word_t *addr, int16_t *valp, void *arg)
74 unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
75 int ret;
77 assert ((off & 0x1) == 0);
79 *addr += 2;
81 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 - 2 - off);
87 #endif
88 *valp = val & 0xffff;
89 return ret;
92 static inline int
93 fetch32 (unw_addr_space_t as, unw_accessors_t *a,
94 unw_word_t *addr, int32_t *valp, void *arg)
96 unw_word_t val, aligned_addr = *addr & -WSIZE, off = *addr - aligned_addr;
97 int ret;
99 assert ((off & 0x3) == 0);
101 *addr += 4;
103 ret = (*a->access_mem) (as, aligned_addr, &val, 0, arg);
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;
114 static inline int
115 fetchw (unw_addr_space_t as, unw_accessors_t *a,
116 unw_word_t *addr, unw_word_t *valp, void *arg)
118 int ret;
120 ret = (*a->access_mem) (as, *addr, valp, 0, arg);
121 *addr += WSIZE;
122 return ret;
125 #endif /* !UNW_LOCAL_ONLY */
127 #endif /* REMOTE_H */