diff options
author | kfraser@localhost.localdomain <kfraser@localhost.localdomain> | 2007-06-20 15:29:53 +0100 |
---|---|---|
committer | kfraser@localhost.localdomain <kfraser@localhost.localdomain> | 2007-06-20 15:29:53 +0100 |
commit | b7954cc5983140272e6a96e34e6de6e8674018e1 (patch) | |
tree | 5dbeb278065b2b9ebe7b70945a240657f8ccb592 /xen/include/xen/xencomm.h | |
parent | 6f23c61e5df5a18d58e0c92d8eab24f3cb62e8d1 (diff) | |
download | xen-b7954cc5983140272e6a96e34e6de6e8674018e1.tar.gz xen-b7954cc5983140272e6a96e34e6de6e8674018e1.tar.bz2 xen-b7954cc5983140272e6a96e34e6de6e8674018e1.zip |
Enhance guest memory accessor macros so that source operands can be
pointers to const or arrays.
Only build-tested on ia64, and untested for powerpc (which, however,
is almost identical to ia64, except for an apparent bug in the original
version of __copy_field_{from,to}_guest in that the field offset was
multiplied by the field size).
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Diffstat (limited to 'xen/include/xen/xencomm.h')
-rw-r--r-- | xen/include/xen/xencomm.h | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/xen/include/xen/xencomm.h b/xen/include/xen/xencomm.h index e961cc6681..95126ba67f 100644 --- a/xen/include/xen/xencomm.h +++ b/xen/include/xen/xencomm.h @@ -47,17 +47,17 @@ static inline unsigned long xencomm_inline_addr(const void *handle) ((hnd).p == NULL || xencomm_handle_is_null((hnd).p)) /* Offset the given guest handle into the array it refers to. */ -#define guest_handle_add_offset(hnd, nr) ({ \ - const typeof((hnd).p) _ptr; \ - xencomm_add_offset((void **)&((hnd).p), nr * sizeof(*_ptr)); \ +#define guest_handle_add_offset(hnd, nr) ({ \ + const typeof((hnd).p) _ptr; \ + xencomm_add_offset((void **)&((hnd).p), nr * sizeof(*_ptr)); \ }) /* Cast a guest handle to the specified type of handle. */ #define guest_handle_cast(hnd, type) ({ \ type *_x = (hnd).p; \ - XEN_GUEST_HANDLE(type) _y; \ - set_xen_guest_handle(_y, _x); \ - _y; \ + XEN_GUEST_HANDLE(type) _y; \ + set_xen_guest_handle(_y, _x); \ + _y; \ }) /* Since we run in real mode, we can safely access all addresses. That also @@ -87,29 +87,32 @@ static inline unsigned long xencomm_inline_addr(const void *handle) __copy_field_from_guest(ptr, hnd, field) #define __copy_to_guest_offset(hnd, idx, ptr, nr) ({ \ - const typeof(ptr) _x = (hnd).p; \ - const typeof(ptr) _y = (ptr); \ - xencomm_copy_to_guest(_x, _y, sizeof(*_x)*(nr), sizeof(*_x)*(idx)); \ + const typeof(*(ptr)) *_s = (ptr); \ + void *_d = (hnd).p; \ + ((void)((hnd).p == (ptr))); \ + xencomm_copy_to_guest(_d, _s, sizeof(*_s)*(nr), sizeof(*_s)*(idx)); \ }) #define __copy_field_to_guest(hnd, ptr, field) ({ \ - const int _off = offsetof(typeof(*ptr), field); \ - const typeof(&(ptr)->field) _x = &(hnd).p->field; \ - const typeof(&(ptr)->field) _y = &(ptr)->field; \ - xencomm_copy_to_guest(_x, _y, sizeof(*_x), sizeof(*_x)*(_off)); \ + unsigned int _off = offsetof(typeof(*(hnd).p), field); \ + const typeof(&(ptr)->field) _s = &(ptr)->field; \ + void *_d = (hnd).p; \ + ((void)(&(hnd).p->field == &(ptr)->field)); \ + xencomm_copy_to_guest(_d, _s, sizeof(*_s), _off); \ }) #define __copy_from_guest_offset(ptr, hnd, idx, nr) ({ \ - const typeof(ptr) _x = (hnd).p; \ - const typeof(ptr) _y = (ptr); \ - xencomm_copy_from_guest(_y, _x, sizeof(*_x)*(nr), sizeof(*_x)*(idx)); \ + const typeof(*(ptr)) *_s = (hnd).p; \ + typeof(*(ptr)) *_d = (ptr); \ + xencomm_copy_from_guest(_d, _s, sizeof(*_d)*(nr), sizeof(*_d)*(idx)); \ }) #define __copy_field_from_guest(ptr, hnd, field) ({ \ - const int _off = offsetof(typeof(*ptr), field); \ - const typeof(&(ptr)->field) _x = &(hnd).p->field; \ - const typeof(&(ptr)->field) _y = &(ptr)->field; \ - xencomm_copy_to_guest(_y, _x, sizeof(*_x), sizeof(*_x)*(_off)); \ + unsigned int _off = offsetof(typeof(*(hnd).p), field); \ + const void *_s = (hnd).p; \ + typeof(&(ptr)->field) _d = &(ptr)->field; \ + ((void)(&(hnd).p->field == &(ptr)->field)); \ + xencomm_copy_from_guest(_d, _s, sizeof(*_d), _off); \ }) #endif /* __XENCOMM_H__ */ |