debuggers.hg

view xen/include/xen/compat.h @ 21055:a02b1c791c9b

Fix compat mode type checking macros for gcc 4.5

Just like with the __RING_SIZE() macro, the compat mode type checking
macros also need changing in order to work with gcc 4.5.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Mar 08 19:11:00 2010 +0000 (2010-03-08)
parents 71af89e70fee
children 3ffdb094c2c0
line source
1 /******************************************************************************
2 * compat.h
3 */
5 #ifndef __XEN_COMPAT_H__
6 #define __XEN_COMPAT_H__
8 #include <xen/config.h>
10 #ifdef CONFIG_COMPAT
12 #include <xen/types.h>
13 #include <asm/compat.h>
14 #include <compat/xlat.h>
16 #define __DEFINE_COMPAT_HANDLE(name, type) \
17 typedef struct { \
18 compat_ptr_t c; \
19 type *_[0] __attribute__((__packed__)); \
20 } __compat_handle_ ## name
22 #define DEFINE_COMPAT_HANDLE(name) \
23 __DEFINE_COMPAT_HANDLE(name, name); \
24 __DEFINE_COMPAT_HANDLE(const_ ## name, const name)
25 #define COMPAT_HANDLE(name) __compat_handle_ ## name
27 /* Is the compat handle a NULL reference? */
28 #define compat_handle_is_null(hnd) ((hnd).c == 0)
30 /* Offset the given compat handle into the array it refers to. */
31 #define compat_handle_add_offset(hnd, nr) \
32 ((hnd).c += (nr) * sizeof(**(hnd)._))
34 /* Cast a compat handle to the specified type of handle. */
35 #define compat_handle_cast(chnd, type) ({ \
36 type *_x = (__typeof__(**(chnd)._) *)(full_ptr_t)(chnd).c; \
37 (XEN_GUEST_HANDLE(type)) { _x }; \
38 })
40 #define guest_from_compat_handle(ghnd, chnd) \
41 set_xen_guest_handle(ghnd, \
42 (__typeof__(**(chnd)._) *)(full_ptr_t)(chnd).c)
44 /*
45 * Copy an array of objects to guest context via a compat handle,
46 * specifying an offset into the guest array.
47 */
48 #define copy_to_compat_offset(hnd, off, ptr, nr) ({ \
49 const typeof(*(ptr)) *_s = (ptr); \
50 char (*_d)[sizeof(*_s)] = (void *)(full_ptr_t)(hnd).c; \
51 ((void)((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c == (ptr))); \
52 raw_copy_to_guest(_d + (off), _s, sizeof(*_s) * (nr)); \
53 })
55 /*
56 * Copy an array of objects from guest context via a compat handle,
57 * specifying an offset into the guest array.
58 */
59 #define copy_from_compat_offset(ptr, hnd, off, nr) ({ \
60 const typeof(*(ptr)) *_s = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
61 typeof(*(ptr)) *_d = (ptr); \
62 raw_copy_from_guest(_d, _s + (off), sizeof(*_d) * (nr)); \
63 })
65 #define copy_to_compat(hnd, ptr, nr) \
66 copy_to_compat_offset(hnd, 0, ptr, nr)
68 #define copy_from_compat(ptr, hnd, nr) \
69 copy_from_compat_offset(ptr, hnd, 0, nr)
71 /* Copy sub-field of a structure to guest context via a compat handle. */
72 #define copy_field_to_compat(hnd, ptr, field) ({ \
73 const typeof(&(ptr)->field) _s = &(ptr)->field; \
74 void *_d = &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
75 ((void)(&((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field == \
76 &(ptr)->field)); \
77 raw_copy_to_guest(_d, _s, sizeof(*_s)); \
78 })
80 /* Copy sub-field of a structure from guest context via a compat handle. */
81 #define copy_field_from_compat(ptr, hnd, field) ({ \
82 const typeof(&(ptr)->field) _s = \
83 &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
84 typeof(&(ptr)->field) _d = &(ptr)->field; \
85 raw_copy_from_guest(_d, _s, sizeof(*_d)); \
86 })
88 /*
89 * Pre-validate a guest handle.
90 * Allows use of faster __copy_* functions.
91 */
92 #define compat_handle_okay(hnd, nr) \
93 compat_array_access_ok((void *)(full_ptr_t)(hnd).c, (nr), \
94 sizeof(**(hnd)._))
96 #define __copy_to_compat_offset(hnd, off, ptr, nr) ({ \
97 const typeof(*(ptr)) *_s = (ptr); \
98 char (*_d)[sizeof(*_s)] = (void *)(full_ptr_t)(hnd).c; \
99 ((void)((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c == (ptr))); \
100 __raw_copy_to_guest(_d + (off), _s, sizeof(*_s) * (nr)); \
101 })
103 #define __copy_from_compat_offset(ptr, hnd, off, nr) ({ \
104 const typeof(*(ptr)) *_s = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
105 typeof(*(ptr)) *_d = (ptr); \
106 __raw_copy_from_guest(_d, _s + (off), sizeof(*_d) * (nr)); \
107 })
109 #define __copy_to_compat(hnd, ptr, nr) \
110 __copy_to_compat_offset(hnd, 0, ptr, nr)
112 #define __copy_from_compat(ptr, hnd, nr) \
113 __copy_from_compat_offset(ptr, hnd, 0, nr)
115 #define __copy_field_to_compat(hnd, ptr, field) ({ \
116 const typeof(&(ptr)->field) _s = &(ptr)->field; \
117 void *_d = &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
118 ((void)(&((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field == \
119 &(ptr)->field)); \
120 __raw_copy_to_guest(_d, _s, sizeof(*_s)); \
121 })
123 #define __copy_field_from_compat(ptr, hnd, field) ({ \
124 const typeof(&(ptr)->field) _s = \
125 &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field; \
126 typeof(&(ptr)->field) _d = &(ptr)->field; \
127 __raw_copy_from_guest(_d, _s, sizeof(*_d)); \
128 })
131 #define CHECK_NAME(name, tag) __check ## tag ## name
132 #define CHECK_NAME_(k, n, tag) __check ## tag ## k ## _ ## n
134 #define CHECK_TYPE(name) \
135 static inline int CHECK_NAME(name, T)(xen_ ## name ## _t *x, \
136 compat_ ## name ## _t *c) \
137 { \
138 return x == c; \
139 }
140 #define CHECK_TYPE_(k, n) \
141 static inline int CHECK_NAME_(k, n, T)(k xen_ ## n *x, \
142 k compat_ ## n *c) \
143 { \
144 return x == c; \
145 }
147 #define CHECK_SIZE(name) \
148 typedef int CHECK_NAME(name, S)[1 - (sizeof(xen_ ## name ## _t) != \
149 sizeof(compat_ ## name ## _t)) * 2]
150 #define CHECK_SIZE_(k, n) \
151 typedef int CHECK_NAME_(k, n, S)[1 - (sizeof(k xen_ ## n) != \
152 sizeof(k compat_ ## n)) * 2]
154 #define CHECK_FIELD_COMMON(name, t, f) \
155 static inline int name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \
156 { \
157 BUILD_BUG_ON(offsetof(xen_ ## t ## _t, f) != \
158 offsetof(compat_ ## t ## _t, f)); \
159 return &x->f == &c->f; \
160 }
161 #define CHECK_FIELD_COMMON_(k, name, n, f) \
162 static inline int name(k xen_ ## n *x, k compat_ ## n *c) \
163 { \
164 BUILD_BUG_ON(offsetof(k xen_ ## n, f) != \
165 offsetof(k compat_ ## n, f)); \
166 return &x->f == &c->f; \
167 }
169 #define CHECK_FIELD(t, f) \
170 CHECK_FIELD_COMMON(CHECK_NAME(t ## __ ## f, F), t, f)
171 #define CHECK_FIELD_(k, n, f) \
172 CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f, F), n, f)
174 #define CHECK_SUBFIELD_1(t, f1, f2) \
175 CHECK_FIELD_COMMON(CHECK_NAME(t ## __ ## f1 ## __ ## f2, F1), t, f1.f2)
176 #define CHECK_SUBFIELD_1_(k, n, f1, f2) \
177 CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f1 ## __ ## f2, F1), \
178 n, f1.f2)
180 #define CHECK_SUBFIELD_2(t, f1, f2, f3) \
181 CHECK_FIELD_COMMON(CHECK_NAME(t ## __ ## f1 ## __ ## f2 ## __ ## f3, F2), \
182 t, f1.f2.f3)
183 #define CHECK_SUBFIELD_2_(k, n, f1, f2, f3) \
184 CHECK_FIELD_COMMON_(k, CHECK_NAME_(k, n ## __ ## f1 ## __ ## f2 ## __ ## \
185 f3, F2), n, f1.f2.f3)
187 int hypercall_xlat_continuation(unsigned int *id, unsigned int mask, ...);
189 /* In-place translation functons: */
190 struct start_info;
191 void xlat_start_info(struct start_info *, enum XLAT_start_info_console);
192 struct vcpu_runstate_info;
193 void xlat_vcpu_runstate_info(struct vcpu_runstate_info *);
195 int switch_compat(struct domain *);
196 int switch_native(struct domain *);
198 #else
200 #define compat_handle_is_null(hnd) 0
202 #endif
204 #endif /* __XEN_COMPAT_H__ */