Patchwork [2/7] Use TARGET_VIRT_ADDR_SPACE_BITS in h2g_valid.

login
register
mail settings
Submitter Richard Henderson
Date Feb. 11, 2010, 10:47 p.m.
Message ID <61c1b83df6256642fb1b23f1e0a7a070bf0dfcfb.1266267595.git.rth@twiddle.net>
Download mbox | patch
Permalink /patch/45432/
State New
Headers show

Comments

Richard Henderson - Feb. 11, 2010, 10:47 p.m.
Previously, only 32-bit guests had a proper check for the
validity of the virtual address.  Extend that check to 64-bit
guests with a restricted virtual address space.
---
 cpu-all.h |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)
Paul Brook - Feb. 28, 2010, 2:11 p.m.
>  /* All direct uses of g2h and h2g need to go away for usermode softmmu. 
>  */ #define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE))
> +
> +#if HOST_LONG_BITS == TARGET_VIRT_ADDR_SPACE_BITS

Shouldn't this be <= ? 
1ul << T_V_A_S_B is undefined for 64-bit guests on 32-bit hosts.

> +#define h2g_valid(x) 1
> +#else
> +#define h2g_valid(x) ({ \
> +    unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \
> +    __guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS); \


Paul

Patch

diff --git a/cpu-all.h b/cpu-all.h
index 1ccc9a8..b81641f 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -634,16 +634,22 @@  extern int have_guest_base;
 
 /* All direct uses of g2h and h2g need to go away for usermode softmmu.  */
 #define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE))
+
+#if HOST_LONG_BITS == TARGET_VIRT_ADDR_SPACE_BITS
+#define h2g_valid(x) 1
+#else
+#define h2g_valid(x) ({ \
+    unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \
+    __guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS); \
+})
+#endif
+
 #define h2g(x) ({ \
     unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \
     /* Check if given address fits target address space */ \
-    assert(__ret == (abi_ulong)__ret); \
+    assert(h2g_valid(x)); \
     (abi_ulong)__ret; \
 })
-#define h2g_valid(x) ({ \
-    unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \
-    (__guest == (abi_ulong)__guest); \
-})
 
 #define saddr(x) g2h(x)
 #define laddr(x) g2h(x)