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

[Xen-devel] [PATCH v10 2/6] xen: introduce DEFINE_SYMBOL



Introduce a MACRO to be used to declare array variables corresponding to
linker symbols, plus two static inline functions to be used for
comparing and subtracting pointers with the linker symbols.

Note that the start and end symbols are declared of different types to
help avoid errors and misusing those variables.

Suggested-by: Jan Beulich <JBeulich@xxxxxxxx>
Signed-off-by: Stefano Stabellini <stefanos@xxxxxxxxxx>
---
 xen/include/xen/compiler.h | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/xen/include/xen/compiler.h b/xen/include/xen/compiler.h
index ff6c0f5..99da107 100644
--- a/xen/include/xen/compiler.h
+++ b/xen/include/xen/compiler.h
@@ -99,6 +99,38 @@
     __asm__ ("" : "=r"(__ptr) : "0"(ptr));      \
     (typeof(ptr)) (__ptr + (off)); })
 
+
+/*
+ * Declare start and end array variables in C corresponding to existing
+ * linker symbols.
+ *
+ * Two static inline functions are declared to do comparisons and
+ * subtractions between these variables.
+ *
+ * The end variable is declared with a different type to make sure that
+ * the static inline functions cannot be misused.
+ */
+#define DEFINE_SYMBOL(type, name, start_name, end_name)                       \
+                                                                              \
+struct abstract_ ## name {                                                    \
+    type _;                                                                   \
+};                                                                            \
+                                                                              \
+extern const type start_name[];                                               \
+extern const struct abstract_ ## name end_name[];                             \
+                                                                              \
+static inline bool name ## _lt(const type s1[],                               \
+                               const struct abstract_ ## name s2[])           \
+{                                                                             \
+    return (uintptr_t)s1 < (uintptr_t)s2;                                     \
+}                                                                             \
+                                                                              \
+static inline ptrdiff_t name ## _diff(const type s1[],                        \
+                                      const struct abstract_ ## name s2[])    \
+{                                                                             \
+    return ((uintptr_t)s2 - (uintptr_t)s1) / sizeof(*s1);                     \
+}
+
 #ifdef __GCC_ASM_FLAG_OUTPUTS__
 # define ASM_FLAG_OUT(yes, no) yes
 #else
-- 
1.9.1


_______________________________________________
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®.