[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 06/18] xen: add XEN_GUEST_HANDLE_NULL macros for null XEN_GUEST_HANDLE



This is to assist code clarity and abstraction conformance, enabling:

    var = XEN_GUEST_HANDLE_NULL(type);

instead of an abstraction violation, where structure is assumed:

    var = ((XEN_GUEST_HANDLE(type)){(void *)0});
or:
    var.p = NULL;

and for convenience for supplying a suitably typed NULL value to a function
that takes an argument with a XEN_GUEST_HANDLE type. eg:

    my_function(foo, bar, XEN_GUEST_HANDLE_NULL(type));

C89-compliance for the public header prohibits use of compound literals
so a declaration is required prior to the point of using the macro:

    DECLARE_XEN_GUEST_HANDLE_NULL(type);

This will define a const variable at the given static or auto scope which is
then utilized to supply the NULL-with-correct-type value when
XEN_GUEST_HANDLE_NULL is used.

Signed-off-by: Christopher Clark <christopher.clark6@xxxxxxxxxxxxxx>
---
v1 #8 feedback Jan:
    parenthesize XEN_GUEST_HANDLE_NULL
    header requires C89 compliance

 xen/include/public/xen.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h
index 0a27546..5f4f760 100644
--- a/xen/include/public/xen.h
+++ b/xen/include/public/xen.h
@@ -982,6 +982,10 @@ typedef struct {
 #define XEN_GUEST_HANDLE_64(name) XEN_GUEST_HANDLE(name)
 #endif
 
+#define DECLARE_XEN_GUEST_HANDLE_NULL(type) \
+    XEN_GUEST_HANDLE(type) const __guest_handle_ ## type ## _NULL = {(type *)0}
+#define XEN_GUEST_HANDLE_NULL(type) (__guest_handle_ ## type ## _NULL)
+
 #ifndef __ASSEMBLY__
 struct xenctl_bitmap {
     XEN_GUEST_HANDLE_64(uint8) bitmap;
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.