13 messages in com.xensource.lists.xen-develRe: [Xen-devel] uint64_aligned_t not ...| From | Sent On | Attachments |
|---|---|---|
| Jan Beulich | 28 Aug 2006 07:46 | |
| Keir Fraser | 28 Aug 2006 08:01 | |
| Jan Beulich | 28 Aug 2006 08:32 | |
| Keir Fraser | 28 Aug 2006 08:35 | |
| Jan Beulich | 29 Aug 2006 01:49 | |
| Jan Beulich | 29 Aug 2006 03:12 | |
| John Levon | 29 Aug 2006 05:37 | |
| Jan Beulich | 29 Aug 2006 05:46 | |
| Keir Fraser | 30 Aug 2006 09:18 | |
| Keir Fraser | 30 Aug 2006 09:46 | |
| Jan Beulich | 30 Aug 2006 23:41 | |
| Jan Beulich | 30 Aug 2006 23:53 | |
| Keir Fraser | 31 Aug 2006 11:03 |
| Subject: | Re: [Xen-devel] uint64_aligned_t not compatible across gcc versions![]() |
|---|---|
| From: | Jan Beulich (jbeu...@novell.com) |
| Date: | 08/29/2006 03:12:50 AM |
| List: | com.xensource.lists.xen-devel |
OTOH, extra checking rarely hurts and would be easy to add.
Here my take at it. This actually also replaces the patch sent under the same subject yesterday, as I meanwhile realized there's a simpler way to achieve the desired effect. It also converts the 64-bit store to a 32-bit one, as only the upper 32 bits need clearing.
Signed-off-by: Jan Beulich <jbeu...@novell.com>
Index: 2006-08-28/xen/include/public/arch-x86_32.h
===================================================================
--- 2006-08-28.orig/xen/include/public/arch-x86_32.h 2006-08-28
08:32:38.000000000 +0200
+++ 2006-08-28/xen/include/public/arch-x86_32.h 2006-08-29 11:15:44.000000000
+0200
@@ -29,11 +29,11 @@
/* Structural guest handles introduced in 0x00030201. */
#if (defined(__XEN__) || defined(__XEN_TOOLS__)) && !defined(__ASSEMBLY__)
-typedef uint64_t __attribute__((aligned(8))) uint64_aligned_t;
+#define uint64_aligned_t uint64_t __attribute__((__aligned__(8)))
#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
typedef struct { type *p; } \
__guest_handle_ ## name; \
- typedef struct { union { type *p; uint64_aligned_t q; }; } \
+ typedef struct { type *p __attribute__((__aligned__(8))); } \
__guest_handle_64_ ## name
#elif __XEN_INTERFACE_VERSION__ >= 0x00030201
#define __DEFINE_XEN_GUEST_HANDLE(name, type) \
@@ -49,7 +49,7 @@ typedef uint64_t __attribute__((aligned(
#ifdef __XEN_TOOLS__
#define get_xen_guest_handle(val, hnd) do { val = (hnd).p; } while (0)
#define set_xen_guest_handle(hnd, val) \
- do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0; \
+ do { if ( sizeof(hnd) == 8 ) (&(hnd).p)[1] = NULL; \
(hnd).p = val; \
} while ( 0 )
#else
Index: 2006-08-28/xen/include/asm-x86/guest_access.h
===================================================================
--- 2006-08-28.orig/xen/include/asm-x86/guest_access.h 2006-08-07
09:07:03.000000000 +0200
+++ 2006-08-28/xen/include/asm-x86/guest_access.h 2006-08-29 11:52:57.000000000
+0200
@@ -17,6 +17,14 @@
/* Offset the given guest handle into the array it refers to. */
#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr))
+#if defined(__i386__) +#define __guest_handle_okay(hnd) \ + (sizeof(hnd) == sizeof((hnd).p) || \ + (&(hnd).p)[1] == NULL) +#elif defined(__x86_64__) +#define __guest_handle_okay(hnd) ((void)(hnd), 1) +#endif + /* Cast a guest handle to the specified type of handle. */ #define guest_handle_cast(hnd, type) ({ \ type *_x = (hnd).p; \ @@ -33,9 +41,11 @@ #define copy_to_guest_offset(hnd, off, ptr, nr) ({ \ const typeof(ptr) _x = (hnd).p; \ const typeof(ptr) _y = (ptr); \ + __guest_handle_okay(hnd) ? \ hvm_guest(current) ? \ copy_to_user_hvm(_x+(off), _y, sizeof(*_x)*(nr)) : \ - copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)); \ + copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)) : \ + sizeof(*_x) * (nr); \ })
/* @@ -45,27 +55,33 @@ #define copy_from_guest_offset(ptr, hnd, off, nr) ({ \ const typeof(ptr) _x = (hnd).p; \ const typeof(ptr) _y = (ptr); \ + __guest_handle_okay(hnd) ? \ hvm_guest(current) ? \ copy_from_user_hvm(_y, _x+(off), sizeof(*_x)*(nr)) :\ - copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)); \ + copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)) : \ + sizeof(*_x) * (nr); \ })
/* Copy sub-field of a structure to guest context via a guest handle. */ #define copy_field_to_guest(hnd, ptr, field) ({ \ const typeof(&(ptr)->field) _x = &(hnd).p->field; \ const typeof(&(ptr)->field) _y = &(ptr)->field; \ + __guest_handle_okay(hnd) ? \ hvm_guest(current) ? \ copy_to_user_hvm(_x, _y, sizeof(*_x)) : \ - copy_to_user(_x, _y, sizeof(*_x)); \ + copy_to_user(_x, _y, sizeof(*_x)) : \ + sizeof(*_x); \ })
/* 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; \ const typeof(&(ptr)->field) _y = &(ptr)->field; \ + __guest_handle_okay(hnd) ? \ hvm_guest(current) ? \ copy_from_user_hvm(_y, _x, sizeof(*_x)) : \ - copy_from_user(_y, _x, sizeof(*_x)); \ + copy_from_user(_y, _x, sizeof(*_x)) : \ + sizeof(*_x); \ })
/* @@ -73,7 +89,9 @@ * Allows use of faster __copy_* functions. */ #define guest_handle_okay(hnd, nr) \ - (hvm_guest(current) || array_access_ok((hnd).p, (nr), sizeof(*(hnd).p))) + (__guest_handle_okay(hnd) && \ + (hvm_guest(current) || \ + array_access_ok((hnd).p, (nr), sizeof(*(hnd).p))))
#define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \ const typeof(ptr) _x = (hnd).p; \
_______________________________________________ Xen-devel mailing list Xen-...@lists.xensource.com http://lists.xensource.com/xen-devel




