Skip to contentSkip to conversation

compat: Allow CHECK_FIELD_COMMON_ macro deal with fields that are handles

PATCH In review Boris Ostrovsky 2 participants 2 messages Jan 10, 2014 – Jan 13, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compat: Allow CHECK_FIELD_COMMON_ macro deal with fields that are handles

CHECK_FIELD_COMMON_ and CHECK_FIELD_COMMON macros verify whether the field in 64- and 32-bit versions of a structure is at the same offset by comparing address of the field in both structures.

However, if the field itself is a handle, it is either

typedef struct {
    <type> *p;
} __guest_handle_<type>

or

typedef struct {
    compat_ptr_t c;
    <type> *_[0] __attribute__((__packed__));
} __compat_handle_<type>

and compiler will warn that we are trying to compare addresses of different structures.

By casting the addresses to (void *) we will avoid this warning.

---
 xen/include/xen/compat.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/include/xen/compat.h +2 -2
index ca60699..6de2d14 100644
@@ -158,14 +158,14 @@ static inline int name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \
 { \
     BUILD_BUG_ON(offsetof(xen_ ## t ## _t, f) != \
                  offsetof(compat_ ## t ## _t, f)); \
-    return &x->f == &c->f; \
+    return (void *)&x->f == (void *)&c->f; \
 }
 #define CHECK_FIELD_COMMON_(k, name, n, f) \
 static inline int name(k xen_ ## n *x, k compat_ ## n *c) \
 { \
     BUILD_BUG_ON(offsetof(k xen_ ## n, f) != \
                  offsetof(k compat_ ## n, f)); \
-    return &x->f == &c->f; \
+    return (void *)&x->f == (void *)&c->f; \
 }
 
 #define CHECK_FIELD(t, f) \
Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Boris Ostrovsky

CHECK_FIELD_COMMON_ and CHECK_FIELD_COMMON macros verify whether the field in 64- and 32-bit versions of a structure is at the same offset by comparing address of the field in both structures.

However, if the field itself is a handle, it is either

typedef struct {
    <type> *p;
} __guest_handle_<type>

or

typedef struct {
    compat_ptr_t c;
    <type> *_[0] __attribute__((__packed__));
} __compat_handle_<type>
Quoted 4 lines

and compiler will warn that we are trying to compare addresses of different structures.

By casting the addresses to (void *) we will avoid this warning.

Which means you didn't understand the purpose: If a structure contains a handle, it shouldn't be subject to checking at all, but would need translation instead.

Jan

Quoted 35 lines
---
 xen/include/xen/compat.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/include/xen/compat.h +2 -2
index ca60699..6de2d14 100644
@@ -158,14 +158,14 @@ static inline int name(xen_ ## t ## _t *x, compat_ ## t 
 ## _t *c) \
 { \
     BUILD_BUG_ON(offsetof(xen_ ## t ## _t, f) != \
                  offsetof(compat_ ## t ## _t, f)); \
-    return &x->f == &c->f; \
+    return (void *)&x->f == (void *)&c->f; \
 }
 #define CHECK_FIELD_COMMON_(k, name, n, f) \
 static inline int name(k xen_ ## n *x, k compat_ ## n *c) \
 { \
     BUILD_BUG_ON(offsetof(k xen_ ## n, f) != \
                  offsetof(k compat_ ## n, f)); \
-    return &x->f == &c->f; \
+    return (void *)&x->f == (void *)&c->f; \
 }
 

#define CHECK_FIELD(t, f) \

Signature · 7 lines
1.8.1.4


_______________________________________________
Xen-devel mailing list
[email protected] 
http://lists.xen.org/xen-devel