WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Enhance guest memory accessor macros so t

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Enhance guest memory accessor macros so that source operands can be
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 20 Jun 2007 11:23:58 -0700
Delivery-date: Wed, 20 Jun 2007 11:22:24 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1182349793 -3600
# Node ID 45a44a9cbe8d1028f1bc57b95734153e571602ab
# Parent  499bab040137bcd78c81b3f8255ffdf93108c146
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@xxxxxxxxxx>
---
 xen/arch/x86/mm.c                   |   10 ++---
 xen/arch/x86/traps.c                |    2 -
 xen/common/domctl.c                 |    4 +-
 xen/common/kernel.c                 |   10 ++---
 xen/common/perfc.c                  |    2 -
 xen/drivers/char/console.c          |    2 -
 xen/include/asm-ia64/guest_access.h |   25 +++++++------
 xen/include/asm-x86/guest_access.h  |   68 +++++++++++++++++++-----------------
 xen/include/xen/compat.h            |   62 +++++++++++++++++++-------------
 xen/include/xen/xencomm.h           |   43 ++++++++++++----------
 10 files changed, 124 insertions(+), 104 deletions(-)

diff -r 499bab040137 -r 45a44a9cbe8d xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c Wed Jun 20 15:08:32 2007 +0100
+++ b/xen/arch/x86/mm.c Wed Jun 20 15:29:53 2007 +0100
@@ -2942,7 +2942,7 @@ long do_set_gdt(XEN_GUEST_HANDLE(ulong) 
     if ( entries > FIRST_RESERVED_GDT_ENTRY )
         return -EINVAL;
     
-    if ( copy_from_guest((unsigned long *)frames, frame_list, nr_pages) )
+    if ( copy_from_guest(frames, frame_list, nr_pages) )
         return -EFAULT;
 
     LOCK_BIGLOCK(current->domain);
@@ -3123,7 +3123,7 @@ long arch_memory_op(int op, XEN_GUEST_HA
         else if ( (d = rcu_lock_domain_by_id(fmap.domid)) == NULL )
             return -ESRCH;
 
-        rc = copy_from_guest(&d->arch.e820[0], fmap.map.buffer,
+        rc = copy_from_guest(d->arch.e820, fmap.map.buffer,
                              fmap.map.nr_entries) ? -EFAULT : 0;
         d->arch.nr_e820 = fmap.map.nr_entries;
 
@@ -3144,7 +3144,7 @@ long arch_memory_op(int op, XEN_GUEST_HA
             return -EFAULT;
 
         map.nr_entries = min(map.nr_entries, d->arch.nr_e820);
-        if ( copy_to_guest(map.buffer, &d->arch.e820[0], map.nr_entries) ||
+        if ( copy_to_guest(map.buffer, d->arch.e820, map.nr_entries) ||
              copy_to_guest(arg, &map, 1) )
             return -EFAULT;
 
@@ -3168,7 +3168,7 @@ long arch_memory_op(int op, XEN_GUEST_HA
         buffer = guest_handle_cast(memmap.buffer, e820entry_t);
 
         count = min((unsigned int)e820.nr_map, memmap.nr_entries);
-        if ( copy_to_guest(buffer, &e820.map[0], count) < 0 )
+        if ( copy_to_guest(buffer, e820.map, count) < 0 )
             return -EFAULT;
 
         memmap.nr_entries = count;
@@ -3181,7 +3181,7 @@ long arch_memory_op(int op, XEN_GUEST_HA
 
     case XENMEM_machphys_mapping:
     {
-        struct xen_machphys_mapping mapping = {
+        static const struct xen_machphys_mapping mapping = {
             .v_start = MACH2PHYS_VIRT_START,
             .v_end   = MACH2PHYS_VIRT_END,
             .max_mfn = MACH2PHYS_NR_ENTRIES - 1
diff -r 499bab040137 -r 45a44a9cbe8d xen/arch/x86/traps.c
--- a/xen/arch/x86/traps.c      Wed Jun 20 15:08:32 2007 +0100
+++ b/xen/arch/x86/traps.c      Wed Jun 20 15:29:53 2007 +0100
@@ -1140,7 +1140,7 @@ static inline int guest_io_okay(
          * read as 0xff (no access allowed).
          */
         TOGGLE_MODE();
-        switch ( __copy_from_guest_offset(&x.bytes[0], v->arch.iobmp,
+        switch ( __copy_from_guest_offset(x.bytes, v->arch.iobmp,
                                           port>>3, 2) )
         {
         default: x.bytes[0] = ~0;
diff -r 499bab040137 -r 45a44a9cbe8d xen/common/domctl.c
--- a/xen/common/domctl.c       Wed Jun 20 15:08:32 2007 +0100
+++ b/xen/common/domctl.c       Wed Jun 20 15:29:53 2007 +0100
@@ -43,7 +43,7 @@ void cpumask_to_xenctl_cpumap(
 
     bitmap_long_to_byte(bytemap, cpus_addr(*cpumask), NR_CPUS);
 
-    copy_to_guest(xenctl_cpumap->bitmap, &bytemap[0], copy_bytes);
+    copy_to_guest(xenctl_cpumap->bitmap, bytemap, copy_bytes);
 
     for ( i = copy_bytes; i < guest_bytes; i++ )
         copy_to_guest_offset(xenctl_cpumap->bitmap, i, &zero, 1);
@@ -63,7 +63,7 @@ void xenctl_cpumap_to_cpumask(
     if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
         return;
 
-    copy_from_guest(&bytemap[0], xenctl_cpumap->bitmap, copy_bytes);
+    copy_from_guest(bytemap, xenctl_cpumap->bitmap, copy_bytes);
 
     bitmap_byte_to_long(cpus_addr(*cpumask), bytemap, NR_CPUS);
 }
diff -r 499bab040137 -r 45a44a9cbe8d xen/common/kernel.c
--- a/xen/common/kernel.c       Wed Jun 20 15:08:32 2007 +0100
+++ b/xen/common/kernel.c       Wed Jun 20 15:29:53 2007 +0100
@@ -142,7 +142,7 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDL
     {
         xen_extraversion_t extraversion;
         safe_strcpy(extraversion, xen_extra_version());
-        if ( copy_to_guest(arg, (char *)extraversion, sizeof(extraversion)) )
+        if ( copy_to_guest(arg, extraversion, ARRAY_SIZE(extraversion)) )
             return -EFAULT;
         return 0;
     }
@@ -167,7 +167,7 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDL
         memset(info, 0, sizeof(info));
         arch_get_xen_caps(&info);
 
-        if ( copy_to_guest(arg, (char *)info, sizeof(info)) )
+        if ( copy_to_guest(arg, info, ARRAY_SIZE(info)) )
             return -EFAULT;
         return 0;
     }
@@ -187,7 +187,7 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDL
     {
         xen_changeset_info_t chgset;
         safe_strcpy(chgset, xen_changeset());
-        if ( copy_to_guest(arg, (char *)chgset, sizeof(chgset)) )
+        if ( copy_to_guest(arg, chgset, ARRAY_SIZE(chgset)) )
             return -EFAULT;
         return 0;
     }
@@ -229,8 +229,8 @@ DO(xen_version)(int cmd, XEN_GUEST_HANDL
 
     case XENVER_guest_handle:
     {
-        if ( copy_to_guest(arg, (char *)current->domain->handle,
-                           sizeof(current->domain->handle)) )
+        if ( copy_to_guest(arg, current->domain->handle,
+                           ARRAY_SIZE(current->domain->handle)) )
             return -EFAULT;
         return 0;
     }    
diff -r 499bab040137 -r 45a44a9cbe8d xen/common/perfc.c
--- a/xen/common/perfc.c        Wed Jun 20 15:08:32 2007 +0100
+++ b/xen/common/perfc.c        Wed Jun 20 15:29:53 2007 +0100
@@ -227,7 +227,7 @@ static int perfc_copy_info(XEN_GUEST_HAN
     }
     BUG_ON(v != perfc_nbr_vals);
 
-    if ( copy_to_guest(desc, (xen_sysctl_perfc_desc_t *)perfc_d, NR_PERFCTRS) )
+    if ( copy_to_guest(desc, perfc_d, NR_PERFCTRS) )
         return -EFAULT;
     if ( copy_to_guest(val, perfc_vals, perfc_nbr_vals) )
         return -EFAULT;
diff -r 499bab040137 -r 45a44a9cbe8d xen/drivers/char/console.c
--- a/xen/drivers/char/console.c        Wed Jun 20 15:08:32 2007 +0100
+++ b/xen/drivers/char/console.c        Wed Jun 20 15:29:53 2007 +0100
@@ -326,7 +326,7 @@ static long guest_console_write(XEN_GUES
                 CONSOLEIO_write, count, buffer);
 
         kcount = min_t(int, count, sizeof(kbuf)-1);
-        if ( copy_from_guest((char *)kbuf, buffer, kcount) )
+        if ( copy_from_guest(kbuf, buffer, kcount) )
             return -EFAULT;
         kbuf[kcount] = '\0';
 
diff -r 499bab040137 -r 45a44a9cbe8d xen/include/asm-ia64/guest_access.h
--- a/xen/include/asm-ia64/guest_access.h       Wed Jun 20 15:08:32 2007 +0100
+++ b/xen/include/asm-ia64/guest_access.h       Wed Jun 20 15:29:53 2007 +0100
@@ -76,28 +76,31 @@ extern int xencomm_handle_is_null(void *
     __copy_field_from_guest(ptr, hnd, field)
 
 #define __copy_to_guest_offset(hnd, idx, ptr, nr) ({                    \
-    const typeof(ptr) _d = (hnd).p;                                     \
-    const typeof(ptr) _s = (ptr);                                       \
+    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) _d = (hnd).p;                                 \
+    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) _s = (hnd).p;                                        \
-    const typeof(ptr) _d = (ptr);                                          \
-    xencomm_copy_from_guest(_d, _s, sizeof(*_s)*(nr), sizeof(*_s)*(idx));  \
+#define __copy_from_guest_offset(ptr, hnd, idx, nr) ({                    \
+    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) _s = (hnd).p;                                 \
-    const typeof(&(ptr)->field) _d = &(ptr)->field;                 \
+    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);             \
 })
 
diff -r 499bab040137 -r 45a44a9cbe8d xen/include/asm-x86/guest_access.h
--- a/xen/include/asm-x86/guest_access.h        Wed Jun 20 15:08:32 2007 +0100
+++ b/xen/include/asm-x86/guest_access.h        Wed Jun 20 15:29:53 2007 +0100
@@ -32,11 +32,12 @@
  * specifying an offset into the guest array.
  */
 #define copy_to_guest_offset(hnd, off, ptr, nr) ({      \
-    typeof(ptr) _x = (hnd).p;                           \
-    const typeof(ptr) _y = (ptr);                       \
+    const typeof(*(ptr)) *_s = (ptr);                   \
+    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
+    ((void)((hnd).p == (ptr)));                         \
     is_hvm_vcpu(current) ?                              \
-    copy_to_user_hvm(_x+(off), _y, sizeof(*_x)*(nr)) :  \
-    copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));       \
+    copy_to_user_hvm(_d+(off), _s, sizeof(*_s)*(nr)) :  \
+    copy_to_user(_d+(off), _s, sizeof(*_s)*(nr));       \
 })
 
 /*
@@ -44,29 +45,30 @@
  * specifying an offset into the guest array.
  */
 #define copy_from_guest_offset(ptr, hnd, off, nr) ({    \
-    const typeof(ptr) _x = (hnd).p;                     \
-    typeof(ptr) _y = (ptr);                             \
+    const typeof(*(ptr)) *_s = (hnd).p;                 \
+    typeof(*(ptr)) *_d = (ptr);                         \
     is_hvm_vcpu(current) ?                              \
-    copy_from_user_hvm(_y, _x+(off), sizeof(*_x)*(nr)) :\
-    copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));     \
+    copy_from_user_hvm(_d, _s+(off), sizeof(*_d)*(nr)) :\
+    copy_from_user(_d, _s+(off), sizeof(*_d)*(nr));     \
 })
 
 /* Copy sub-field of a structure to guest context via a guest handle. */
 #define copy_field_to_guest(hnd, ptr, field) ({         \
-    typeof(&(ptr)->field) _x = &(hnd).p->field;         \
-    const typeof(&(ptr)->field) _y = &(ptr)->field;     \
+    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
+    void *_d = &(hnd).p->field;                         \
+    ((void)(&(hnd).p->field == &(ptr)->field));         \
     is_hvm_vcpu(current) ?                              \
-    copy_to_user_hvm(_x, _y, sizeof(*_x)) :             \
-    copy_to_user(_x, _y, sizeof(*_x));                  \
+    copy_to_user_hvm(_d, _s, sizeof(*_s)) :             \
+    copy_to_user(_d, _s, sizeof(*_s));                  \
 })
 
 /* Copy sub-field of a structure from guest context via a guest handle. */
 #define copy_field_from_guest(ptr, hnd, field) ({       \
-    const typeof(&(ptr)->field) _x = &(hnd).p->field;   \
-    typeof(&(ptr)->field) _y = &(ptr)->field;           \
+    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
+    typeof(&(ptr)->field) _d = &(ptr)->field;           \
     is_hvm_vcpu(current) ?                              \
-    copy_from_user_hvm(_y, _x, sizeof(*_x)) :           \
-    copy_from_user(_y, _x, sizeof(*_x));                \
+    copy_from_user_hvm(_d, _s, sizeof(*_d)) :           \
+    copy_from_user(_d, _s, sizeof(*_d));                \
 })
 
 /*
@@ -78,35 +80,37 @@
      array_access_ok((hnd).p, (nr), sizeof(*(hnd).p)))
 
 #define __copy_to_guest_offset(hnd, off, ptr, nr) ({    \
-    typeof(ptr) _x = (hnd).p;                           \
-    const typeof(ptr) _y = (ptr);                       \
+    const typeof(*(ptr)) *_s = (ptr);                   \
+    char (*_d)[sizeof(*_s)] = (void *)(hnd).p;          \
+    ((void)((hnd).p == (ptr)));                         \
     is_hvm_vcpu(current) ?                              \
-    copy_to_user_hvm(_x+(off), _y, sizeof(*_x)*(nr)) :  \
-    __copy_to_user(_x+(off), _y, sizeof(*_x)*(nr));     \
+    copy_to_user_hvm(_d+(off), _s, sizeof(*_s)*(nr)) :  \
+    __copy_to_user(_d+(off), _s, sizeof(*_s)*(nr));     \
 })
 
 #define __copy_from_guest_offset(ptr, hnd, off, nr) ({  \
-    const typeof(ptr) _x = (hnd).p;                     \
-    typeof(ptr) _y = (ptr);                             \
+    const typeof(*(ptr)) *_s = (hnd).p;                 \
+    typeof(*(ptr)) *_d = (ptr);                         \
     is_hvm_vcpu(current) ?                              \
-    copy_from_user_hvm(_y, _x+(off),sizeof(*_x)*(nr)) : \
-    __copy_from_user(_y, _x+(off), sizeof(*_x)*(nr));   \
+    copy_from_user_hvm(_d, _s+(off), sizeof(*_d)*(nr)) :\
+    __copy_from_user(_d, _s+(off), sizeof(*_d)*(nr));   \
 })
 
 #define __copy_field_to_guest(hnd, ptr, field) ({       \
-    typeof(&(ptr)->field) _x = &(hnd).p->field;         \
-    const typeof(&(ptr)->field) _y = &(ptr)->field;     \
+    const typeof(&(ptr)->field) _s = &(ptr)->field;     \
+    void *_d = &(hnd).p->field;                         \
+    ((void)(&(hnd).p->field == &(ptr)->field));         \
     is_hvm_vcpu(current) ?                              \
-    copy_to_user_hvm(_x, _y, sizeof(*_x)) :             \
-    __copy_to_user(_x, _y, sizeof(*_x));                \
+    copy_to_user_hvm(_d, _s, sizeof(*_s)) :             \
+    __copy_to_user(_d, _s, sizeof(*_s));                \
 })
 
 #define __copy_field_from_guest(ptr, hnd, field) ({     \
-    const typeof(&(ptr)->field) _x = &(hnd).p->field;   \
-    typeof(&(ptr)->field) _y = &(ptr)->field;           \
+    const typeof(&(ptr)->field) _s = &(hnd).p->field;   \
+    typeof(&(ptr)->field) _d = &(ptr)->field;           \
     is_hvm_vcpu(current) ?                              \
-    copy_from_user_hvm(_y, _x, sizeof(*_x)) :           \
-    __copy_from_user(_y, _x, sizeof(*_x));              \
+    copy_from_user_hvm(_d, _s, sizeof(*_d)) :           \
+    __copy_from_user(_d, _s, sizeof(*_d));              \
 })
 
 #endif /* __ASM_X86_GUEST_ACCESS_H__ */
diff -r 499bab040137 -r 45a44a9cbe8d xen/include/xen/compat.h
--- a/xen/include/xen/compat.h  Wed Jun 20 15:08:32 2007 +0100
+++ b/xen/include/xen/compat.h  Wed Jun 20 15:29:53 2007 +0100
@@ -44,9 +44,10 @@
  * specifying an offset into the guest array.
  */
 #define copy_to_compat_offset(hnd, off, ptr, nr) ({                  \
-    const typeof(ptr) _x = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
-    const typeof(*(ptr)) *const _y = (ptr);                          \
-    copy_to_user(_x + (off), _y, sizeof(*_x) * (nr));                \
+    const typeof(*(ptr)) *_s = (ptr);                                \
+    char (*_d)[sizeof(*_s)] = (void *)(full_ptr_t)(hnd).c;           \
+    ((void)((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c == (ptr)));     \
+    copy_to_user(_d + (off), _s, sizeof(*_s) * (nr));                \
 })
 
 /*
@@ -54,9 +55,9 @@
  * specifying an offset into the guest array.
  */
 #define copy_from_compat_offset(ptr, hnd, off, nr) ({                \
-    const typeof(ptr) _x = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
-    const typeof(ptr) _y = (ptr);                                    \
-    copy_from_user(_y, _x + (off), sizeof(*_x) * (nr));              \
+    const typeof(*(ptr)) *_s = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
+    typeof(*(ptr)) *_d = (ptr);                                      \
+    copy_from_user(_d, _s + (off), sizeof(*_d) * (nr));              \
 })
 
 #define copy_to_compat(hnd, ptr, nr)                                 \
@@ -67,16 +68,19 @@
 
 /* Copy sub-field of a structure to guest context via a compat handle. */
 #define copy_field_to_compat(hnd, ptr, field) ({                     \
-    typeof((ptr)->field) *const _x = &((typeof(**(hnd)._) 
*)(full_ptr_t)(hnd).c)->field; \
-    const typeof((ptr)->field) *const _y = &(ptr)->field;            \
-    copy_to_user(_x, _y, sizeof(*_x));                               \
+    const typeof(&(ptr)->field) _s = &(ptr)->field;                  \
+    void *_d = &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field;   \
+    ((void)(&((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field ==    \
+            &(ptr)->field));                                         \
+    copy_to_user(_d, _s, sizeof(*_s));                               \
 })
 
 /* Copy sub-field of a structure from guest context via a compat handle. */
 #define copy_field_from_compat(ptr, hnd, field) ({                   \
-    typeof((ptr)->field) *const _x = &((typeof(**(hnd)._) 
*)(full_ptr_t)(hnd).c)->field; \
-    typeof((ptr)->field) *const _y = &(ptr)->field;                  \
-    copy_from_user(_y, _x, sizeof(*_x));                             \
+    const typeof(&(ptr)->field) _s =                                 \
+        &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field;          \
+    typeof(&(ptr)->field) _d = &(ptr)->field;                        \
+    copy_from_user(_d, _s, sizeof(*_d));                             \
 })
 
 /*
@@ -84,18 +88,20 @@
  * Allows use of faster __copy_* functions.
  */
 #define compat_handle_okay(hnd, nr)                                  \
-    compat_array_access_ok((void *)(full_ptr_t)(hnd).c, (nr), 
sizeof(**(hnd)._))
+    compat_array_access_ok((void *)(full_ptr_t)(hnd).c, (nr),        \
+                           sizeof(**(hnd)._))
 
 #define __copy_to_compat_offset(hnd, off, ptr, nr) ({                \
-    const typeof(ptr) _x = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
-    const typeof(*(ptr)) *const _y = (ptr);                          \
-    __copy_to_user(_x + (off), _y, sizeof(*_x) * (nr));              \
+    const typeof(*(ptr)) *_s = (ptr);                                \
+    char (*_d)[sizeof(*_s)] = (void *)(full_ptr_t)(hnd).c;           \
+    ((void)((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c == (ptr)));     \
+    __copy_to_user(_d + (off), _s, sizeof(*_s) * (nr));              \
 })
 
 #define __copy_from_compat_offset(ptr, hnd, off, nr) ({              \
-    const typeof(ptr) _x = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
-    const typeof(ptr) _y = (ptr);                                    \
-    __copy_from_user(_y, _x + (off), sizeof(*_x) * (nr));            \
+    const typeof(*(ptr)) *_s = (typeof(**(hnd)._) *)(full_ptr_t)(hnd).c; \
+    typeof(*(ptr)) *_d = (ptr);                                      \
+    __copy_from_user(_d, _s + (off), sizeof(*_d) * (nr));            \
 })
 
 #define __copy_to_compat(hnd, ptr, nr)                               \
@@ -105,15 +111,18 @@
     __copy_from_compat_offset(ptr, hnd, 0, nr)
 
 #define __copy_field_to_compat(hnd, ptr, field) ({                   \
-    typeof((ptr)->field) *const _x = &((typeof(**(hnd)._) 
*)(full_ptr_t)(hnd).c)->field; \
-    const typeof((ptr)->field) *const _y = &(ptr)->field;            \
-    __copy_to_user(_x, _y, sizeof(*_x));                             \
+    const typeof(&(ptr)->field) _s = &(ptr)->field;                  \
+    void *_d = &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field;   \
+    ((void)(&((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field ==    \
+            &(ptr)->field));                                         \
+    __copy_to_user(_d, _s, sizeof(*_s));                             \
 })
 
 #define __copy_field_from_compat(ptr, hnd, field) ({                 \
-    typeof((ptr)->field) *const _x = &((typeof(**(hnd)._) 
*)(full_ptr_t)(hnd).c)->field; \
-    typeof((ptr)->field) *const _y = &(ptr)->field;                  \
-    __copy_from_user(_y, _x, sizeof(*_x));                           \
+    const typeof(&(ptr)->field) _s =                                 \
+        &((typeof(**(hnd)._) *)(full_ptr_t)(hnd).c)->field;          \
+    typeof(&(ptr)->field) _d = &(ptr)->field;                        \
+    __copy_from_user(_d, _s, sizeof(*_d));                           \
 })
 
 
@@ -169,7 +178,8 @@ int switch_compat(struct domain *);
 int switch_compat(struct domain *);
 int switch_native(struct domain *);
 
-#define BITS_PER_GUEST_LONG(d) (!IS_COMPAT(d) ? BITS_PER_LONG : 
COMPAT_BITS_PER_LONG)
+#define BITS_PER_GUEST_LONG(d) \
+    (!IS_COMPAT(d) ? BITS_PER_LONG : COMPAT_BITS_PER_LONG)
 
 #else
 
diff -r 499bab040137 -r 45a44a9cbe8d xen/include/xen/xencomm.h
--- a/xen/include/xen/xencomm.h Wed Jun 20 15:08:32 2007 +0100
+++ b/xen/include/xen/xencomm.h Wed Jun 20 15:29:53 2007 +0100
@@ -47,17 +47,17 @@ static inline unsigned long xencomm_inli
     ((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_inli
     __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__ */

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Enhance guest memory accessor macros so that source operands can be, Xen patchbot-unstable <=