debuggers.hg

view xen/include/asm-x86/guest_access.h @ 22855:1d1eec7e1fb4

xl: Perform minimal validation of virtual disk file while parsing config file

This patch performs some very basic validation on the virtual disk
file passed through the config file. This validation ensures that we
don't go too far with the initialization like spawn qemu and more
while there could be some potentially fundamental issues.

[ Patch fixed up to work with PHYSTYPE_EMPTY 22808:6ec61438713a -iwj ]

Signed-off-by: Kamala Narasimhan <kamala.narasimhan@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Kamala Narasimhan <kamala.narasimhan@gmail.com>
date Tue Jan 25 18:09:49 2011 +0000 (2011-01-25)
parents d835ad2f6980
children
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 })
48 #define const_guest_handle_from_ptr(ptr, type) \
49 ((XEN_GUEST_HANDLE(const_##type)) { (const type *)ptr })
51 /*
52 * Copy an array of objects to guest context via a guest handle,
53 * specifying an offset into the guest array.
54 */
55 #define copy_to_guest_offset(hnd, off, ptr, nr) ({ \
56 const typeof(*(ptr)) *_s = (ptr); \
57 char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \
58 ((void)((hnd).p == (ptr))); \
59 raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr)); \
60 })
62 /*
63 * Copy an array of objects from guest context via a guest handle,
64 * specifying an offset into the guest array.
65 */
66 #define copy_from_guest_offset(ptr, hnd, off, nr) ({ \
67 const typeof(*(ptr)) *_s = (hnd).p; \
68 typeof(*(ptr)) *_d = (ptr); \
69 raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
70 })
72 /* Copy sub-field of a structure to guest context via a guest handle. */
73 #define copy_field_to_guest(hnd, ptr, field) ({ \
74 const typeof(&(ptr)->field) _s = &(ptr)->field; \
75 void *_d = &(hnd).p->field; \
76 ((void)(&(hnd).p->field == &(ptr)->field)); \
77 raw_copy_to_guest(_d, _s, sizeof(*_s)); \
78 })
80 /* Copy sub-field of a structure from guest context via a guest handle. */
81 #define copy_field_from_guest(ptr, hnd, field) ({ \
82 const typeof(&(ptr)->field) _s = &(hnd).p->field; \
83 typeof(&(ptr)->field) _d = &(ptr)->field; \
84 raw_copy_from_guest(_d, _s, sizeof(*_d)); \
85 })
87 /*
88 * Pre-validate a guest handle.
89 * Allows use of faster __copy_* functions.
90 */
91 #define guest_handle_okay(hnd, nr) \
92 (paging_mode_external(current->domain) || \
93 array_access_ok((hnd).p, (nr), sizeof(*(hnd).p)))
94 #define guest_handle_subrange_okay(hnd, first, last) \
95 (paging_mode_external(current->domain) || \
96 array_access_ok((hnd).p + (first), \
97 (last)-(first)+1, \
98 sizeof(*(hnd).p)))
100 #define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \
101 const typeof(*(ptr)) *_s = (ptr); \
102 char (*_d)[sizeof(*_s)] = (void *)(hnd).p; \
103 ((void)((hnd).p == (ptr))); \
104 __raw_copy_to_guest(_d+(off), _s, sizeof(*_s)*(nr));\
105 })
107 #define __copy_from_guest_offset(ptr, hnd, off, nr) ({ \
108 const typeof(*(ptr)) *_s = (hnd).p; \
109 typeof(*(ptr)) *_d = (ptr); \
110 __raw_copy_from_guest(_d, _s+(off), sizeof(*_d)*(nr));\
111 })
113 #define __copy_field_to_guest(hnd, ptr, field) ({ \
114 const typeof(&(ptr)->field) _s = &(ptr)->field; \
115 void *_d = &(hnd).p->field; \
116 ((void)(&(hnd).p->field == &(ptr)->field)); \
117 __raw_copy_to_guest(_d, _s, sizeof(*_s)); \
118 })
120 #define __copy_field_from_guest(ptr, hnd, field) ({ \
121 const typeof(&(ptr)->field) _s = &(hnd).p->field; \
122 typeof(&(ptr)->field) _d = &(ptr)->field; \
123 __raw_copy_from_guest(_d, _s, sizeof(*_d)); \
124 })
126 #endif /* __ASM_X86_GUEST_ACCESS_H__ */