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

[PATCH 3/6] xen/x86: Refactor xen/lib/x86 so it can be linked in hvmloader



A future patch will use these in hvmloader, which is freestanding, but
lacks the Xen code. The following changes fix the compilation errors.

* string.h => Remove memset() usages and bzero through assignments
* inttypes.h => Use stdint.h (it's what it should've been to begin with)
* errno.h => Use xen/errno.h instead

No functional change intended.

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@xxxxxxxxx>
---
 xen/lib/x86/cpuid.c   | 12 ++++++------
 xen/lib/x86/private.h |  8 +++++---
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c
index eb7698dc73..4a138c3a11 100644
--- a/xen/lib/x86/cpuid.c
+++ b/xen/lib/x86/cpuid.c
@@ -5,8 +5,8 @@
 static void zero_leaves(struct cpuid_leaf *l,
                         unsigned int first, unsigned int last)
 {
-    if ( first <= last )
-        memset(&l[first], 0, sizeof(*l) * (last - first + 1));
+    for (l = &l[first]; first <= last; first++, l++ )
+        *l = (struct cpuid_leaf){};
 }
 
 unsigned int x86_cpuid_lookup_vendor(uint32_t ebx, uint32_t ecx, uint32_t edx)
@@ -244,7 +244,7 @@ void x86_cpu_policy_clear_out_of_range_leaves(struct 
cpu_policy *p)
                 ARRAY_SIZE(p->basic.raw) - 1);
 
     if ( p->basic.max_leaf < 4 )
-        memset(p->cache.raw, 0, sizeof(p->cache.raw));
+        p->cache = (typeof(p->cache)){};
     else
     {
         for ( i = 0; (i < ARRAY_SIZE(p->cache.raw) &&
@@ -255,13 +255,13 @@ void x86_cpu_policy_clear_out_of_range_leaves(struct 
cpu_policy *p)
     }
 
     if ( p->basic.max_leaf < 7 )
-        memset(p->feat.raw, 0, sizeof(p->feat.raw));
+        p->feat = (typeof(p->feat)){};
     else
         zero_leaves(p->feat.raw, p->feat.max_subleaf + 1,
                     ARRAY_SIZE(p->feat.raw) - 1);
 
     if ( p->basic.max_leaf < 0xb )
-        memset(p->topo.raw, 0, sizeof(p->topo.raw));
+        p->topo = (typeof(p->topo)){};
     else
     {
         for ( i = 0; (i < ARRAY_SIZE(p->topo.raw) &&
@@ -272,7 +272,7 @@ void x86_cpu_policy_clear_out_of_range_leaves(struct 
cpu_policy *p)
     }
 
     if ( p->basic.max_leaf < 0xd || !cpu_policy_xstates(p) )
-        memset(p->xstate.raw, 0, sizeof(p->xstate.raw));
+        p->xstate = (typeof(p->xstate)){};
     else
     {
         /* This logic will probably need adjusting when XCR0[63] gets used. */
diff --git a/xen/lib/x86/private.h b/xen/lib/x86/private.h
index 60bb82a400..4b8cb97e64 100644
--- a/xen/lib/x86/private.h
+++ b/xen/lib/x86/private.h
@@ -17,12 +17,14 @@
 
 #else
 
-#include <errno.h>
-#include <inttypes.h>
+#include <stdint.h>
 #include <stdbool.h>
 #include <stddef.h>
-#include <string.h>
 
+enum {
+#define XEN_ERRNO(ident, rc) ident = (rc),
+#include <xen/errno.h>
+};
 #include <xen/asm/msr-index.h>
 #include <xen/asm/x86-vendors.h>
 
-- 
2.34.1




 


Rackspace

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