ia64/xen-unstable

view xen/include/asm-x86/guest_access.h @ 18432:1e98ea5c8604

x86: Fix guest_handle_okay/guest_handle_subrange_okay

The guest handle checks should use paging_* predicates, not shadow_*.
Also tidy up a few places where p2m definitions were being imported
via asm/guest_access.h -> asm/shadow.h -> asm/p2m.h

Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Sep 03 14:16:35 2008 +0100 (2008-09-03)
parents ac745ad5f018
children d835ad2f6980
line source
1 /******************************************************************************
2 * guest_access.h
3 *
4 * Copyright (c) 2006, K A Fraser
5 */
7 #ifndef __ASM_X86_GUEST_ACCESS_H__
8 #define __ASM_X86_GUEST_ACCESS_H__
10 #include <asm/uaccess.h>
11 #include <asm/paging.h>
12 #include <asm/hvm/support.h>
13 #include <asm/hvm/guest_access.h>
15 /* Raw access functions: no type checking. */
16 #define raw_copy_to_guest(dst, src, len) \
17 (is_hvm_vcpu(current) ? \
18 copy_to_user_hvm((dst), (src), (len)) : \
19 copy_to_user((dst), (src), (len)))
20 #define raw_copy_from_guest(dst, src, len) \
21 (is_hvm_vcpu(current) ? \
22 copy_from_user_hvm((dst), (src), (len)) : \
23 copy_from_user((dst), (src), (len)))
24 #define __raw_copy_to_guest(dst, src, len) \
25 (is_hvm_vcpu(current) ? \
26 copy_to_user_hvm((dst), (src), (len)) : \
27 __copy_to_user((dst), (src), (len)))
28 #define __raw_copy_from_guest(dst, src, len) \
29 (is_hvm_vcpu(current) ? \
30 copy_from_user_hvm((dst), (src), (len)) : \
31 __copy_from_user((dst), (src), (len)))
33 /* Is the guest handle a NULL reference? */
34 #define guest_handle_is_null(hnd) ((hnd).p == NULL)
36 /* Offset the given guest handle into the array it refers to. */
37 #define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
38 #define guest_handle_subtract_offset(hnd, nr) ((hnd).p -= (nr))
40 /* Cast a guest handle to the specified type of handle. */
41 #define guest_handle_cast(hnd, type) ({ \
42 type *_x = (hnd).p; \
43 (XEN_GUEST_HANDLE(type)) { _x }; \
44 })
46 #define guest_handle_from_ptr(ptr, type) \
47 ((XEN_GUEST_HANDLE(type)) { (type *)ptr })
49 /*
50 * Copy an array of objects to guest context via a guest handle,
51 * specifying an offset into the guest array.
52 */
53 #define copy_to_guest_offset(hnd, off, ptr, nr) ({ \
54 const typeof(*(ptr)) *_s = (ptr); \
55 char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \
56 ((void)((hnd).p == (ptr))); \
57 raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr)); \
58 })
60 /*
61 * Copy an array of objects from guest context via a guest handle,
62 * specifying an offset into the guest array.
63 */
64 #define copy_from_guest_offset(ptr, hnd, off, nr) ({ \
65 const typeof(*(ptr)) *_s = (hnd).p; \
66 typeof(*(ptr)) *_d = (ptr); \
67 raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
68 })
70 /* Copy sub-field of a structure to guest context via a guest handle. */
71 #define copy_field_to_guest(hnd, ptr, field) ({ \
72 const typeof(&(ptr)->field) _s = &(ptr)->field; \
73 void *_d = &(hnd).p->field; \
74 ((void)(&(hnd).p->field == &(ptr)->field)); \
75 raw_copy_to_guest(_d, _s, sizeof(*_s)); \
76 })
78 /* Copy sub-field of a structure from guest context via a guest handle. */
79 #define copy_field_from_guest(ptr, hnd, field) ({ \
80 const typeof(&(ptr)->field) _s = &(hnd).p->field; \
81 typeof(&(ptr)->field) _d = &(ptr)->field; \
82 raw_copy_from_guest(_d, _s, sizeof(*_d)); \
83 })
85 /*
86 * Pre-validate a guest handle.
87 * Allows use of faster __copy_* functions.
88 */
89 #define guest_handle_okay(hnd, nr) \
90 (paging_mode_external(current->domain) || \
91 array_access_ok((hnd).p, (nr), sizeof(*(hnd).p)))
92 #define guest_handle_subrange_okay(hnd, first, last) \
93 (paging_mode_external(current->domain) || \
94 array_access_ok((hnd).p + (first), \
95 (last)-(first)+1, \
96 sizeof(*(hnd).p)))
98 #define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \
99 const typeof(*(ptr)) *_s = (ptr); \
100 char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \
101 ((void)((hnd).p == (ptr))); \
102 __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\
103 })
105 #define __copy_from_guest_offset(ptr, hnd, off, nr) ({ \
106 const typeof(*(ptr)) *_s = (hnd).p; \
107 typeof(*(ptr)) *_d = (ptr); \
108 __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
109 })
111 #define __copy_field_to_guest(hnd, ptr, field) ({ \
112 const typeof(&(ptr)->field) _s = &(ptr)->field; \
113 void *_d = &(hnd).p->field; \
114 ((void)(&(hnd).p->field == &(ptr)->field)); \
115 __raw_copy_to_guest(_d, _s, sizeof(*_s)); \
116 })
118 #define __copy_field_from_guest(ptr, hnd, field) ({ \
119 const typeof(&(ptr)->field) _s = &(hnd).p->field; \
120 typeof(&(ptr)->field) _d = &(ptr)->field; \
121 __raw_copy_from_guest(_d, _s, sizeof(*_d)); \
122 })
124 #endif /* __ASM_X86_GUEST_ACCESS_H__ */