1 #ifndef XEN_LIB_X86_PRIVATE_H
2 #define XEN_LIB_X86_PRIVATE_H
3
4 #ifdef __XEN__
5
6 #include <xen/bitops.h>
7 #include <xen/guest_access.h>
8 #include <xen/kernel.h>
9 #include <xen/lib.h>
10 #include <xen/nospec.h>
11 #include <xen/types.h>
12
13 #include <asm/msr.h>
14
15 #define copy_to_buffer_offset copy_to_guest_offset
16 #define copy_from_buffer_offset copy_from_guest_offset
17
18 #else
19
20 #include <errno.h>
21 #include <inttypes.h>
22 #include <stdbool.h>
23 #include <stddef.h>
24 #include <string.h>
25
26 #include <xen/asm/msr-index.h>
27 #include <xen/asm/x86-vendors.h>
28
29 #include <xen-tools/common-macros.h>
30
test_bit(unsigned int bit,const void * vaddr)31 static inline bool test_bit(unsigned int bit, const void *vaddr)
32 {
33 const char *addr = vaddr;
34
35 return addr[bit / 8] & (1u << (bit % 8));
36 }
37
38 #define array_access_nospec(a, i) (a)[(i)]
39
40 /* memcpy(), but with copy_to_guest_offset()'s API. */
41 #define copy_to_buffer_offset(dst, index, src, nr) \
42 ({ \
43 const typeof(*(src)) *src_ = (src); \
44 typeof(*(dst)) *dst_ = (dst); \
45 typeof(index) index_ = (index); \
46 typeof(nr) nr_ = (nr), i_; \
47 \
48 for ( i_ = 0; i_ < nr_; i_++ ) \
49 dst_[index_ + i_] = src_[i_]; \
50 0; \
51 })
52
53 /* memcpy(), but with copy_from_guest_offset()'s API. */
54 #define copy_from_buffer_offset(dst, src, index, nr) \
55 ({ \
56 const typeof(*(src)) *src_ = (src); \
57 typeof(*(dst)) *dst_ = (dst); \
58 typeof(index) index_ = (index); \
59 typeof(nr) nr_ = (nr), i_; \
60 \
61 for ( i_ = 0; i_ < nr_; i_++ ) \
62 dst_[i_] = src_[index_ + i_]; \
63 0; \
64 })
65
66 #endif /* __XEN__ */
67
68 #endif /* XEN_LIB_X86_PRIVATE_H */
69
70 /*
71 * Local variables:
72 * mode: C
73 * c-file-style: "BSD"
74 * c-basic-offset: 4
75 * tab-width: 4
76 * indent-tabs-mode: nil
77 * End:
78 */
79