debuggers.hg

view xen/include/asm-x86/guest_access.h @ 10958:bfe12b4d45d3

[HVM] Make copy_{to,from}_guest work for HVM domains.
Signed-off-by: Steven Smith <ssmith@xensource.com>
author kfraser@localhost.localdomain
date Thu Aug 03 15:22:25 2006 +0100 (2006-08-03)
parents 4e1b8be54311
children 49dcd838b7df
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/hvm/support.h>
12 #include <asm/hvm/guest_access.h>
14 /* Is the guest handle a NULL reference? */
15 #define guest_handle_is_null(hnd) ((hnd).p == NULL)
17 /* Offset the given guest handle into the array it refers to. */
18 #define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
20 /* Cast a guest handle to the specified type of handle. */
21 #define guest_handle_cast(hnd, type) ({ \
22 type *_x = (hnd).p; \
23 (XEN_GUEST_HANDLE(type)) { _x }; \
24 })
26 /*
27 * Copy an array of objects to guest context via a guest handle,
28 * specifying an offset into the guest array.
29 */
30 #define copy_to_guest_offset(hnd, off, ptr, nr) ({ \
31 const typeof(ptr) _x = (hnd).p; \
32 const typeof(ptr) _y = (ptr); \
33 hvm_guest(current) ? \
34 copy_to_user_hvm(_x+(off), _y, sizeof(*_x)*(nr)) : \
35 copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)); \
36 })
38 /*
39 * Copy an array of objects from guest context via a guest handle,
40 * specifying an offset into the guest array.
41 */
42 #define copy_from_guest_offset(ptr, hnd, off, nr) ({ \
43 const typeof(ptr) _x = (hnd).p; \
44 const typeof(ptr) _y = (ptr); \
45 hvm_guest(current) ? \
46 copy_from_user_hvm(_y, _x+(off), sizeof(*_x)*(nr)) :\
47 copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)); \
48 })
50 /* Copy sub-field of a structure to guest context via a guest handle. */
51 #define copy_field_to_guest(hnd, ptr, field) ({ \
52 const typeof(&(ptr)->field) _x = &(hnd).p->field; \
53 const typeof(&(ptr)->field) _y = &(ptr)->field; \
54 hvm_guest(current) ? \
55 copy_to_user_hvm(_x, _y, sizeof(*_x)) : \
56 copy_to_user(_x, _y, sizeof(*_x)); \
57 })
59 /* Copy sub-field of a structure from guest context via a guest handle. */
60 #define copy_field_from_guest(ptr, hnd, field) ({ \
61 const typeof(&(ptr)->field) _x = &(hnd).p->field; \
62 const typeof(&(ptr)->field) _y = &(ptr)->field; \
63 hvm_guest(current) ? \
64 copy_from_user_hvm(_y, _x, sizeof(*_x)) : \
65 copy_from_user(_y, _x, sizeof(*_x)); \
66 })
68 /*
69 * Pre-validate a guest handle.
70 * Allows use of faster __copy_* functions.
71 */
72 #define guest_handle_okay(hnd, nr) \
73 (hvm_guest(current) || array_access_ok((hnd).p, (nr), sizeof(*(hnd).p)))
75 #define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \
76 const typeof(ptr) _x = (hnd).p; \
77 const typeof(ptr) _y = (ptr); \
78 hvm_guest(current) ? \
79 copy_to_user_hvm(_x+(off), _y, sizeof(*_x)*(nr)) : \
80 __copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)); \
81 })
83 #define __copy_from_guest_offset(ptr, hnd, off, nr) ({ \
84 const typeof(ptr) _x = (hnd).p; \
85 const typeof(ptr) _y = (ptr); \
86 hvm_guest(current) ? \
87 copy_from_user_hvm(_y, _x+(off),sizeof(*_x)*(nr)) : \
88 __copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)); \
89 })
91 #define __copy_field_to_guest(hnd, ptr, field) ({ \
92 const typeof(&(ptr)->field) _x = &(hnd).p->field; \
93 const typeof(&(ptr)->field) _y = &(ptr)->field; \
94 hvm_guest(current) ? \
95 copy_to_user_hvm(_x, _y, sizeof(*_x)) : \
96 __copy_to_user(_x, _y, sizeof(*_x)); \
97 })
99 #define __copy_field_from_guest(ptr, hnd, field) ({ \
100 const typeof(&(ptr)->field) _x = &(hnd).p->field; \
101 const typeof(&(ptr)->field) _y = &(ptr)->field; \
102 hvm_guest(current) ? \
103 copy_from_user_hvm(_x, _y, sizeof(*_x)) : \
104 __copy_from_user(_y, _x, sizeof(*_x)); \
105 })
107 #endif /* __ASM_X86_GUEST_ACCESS_H__ */