To be used by userspace emulation to verify that the memory
range defined by [start, start+len) is valid for the guest,
taking into account TARGET_VIRT_ADDR_SPACE_BITS.

Signed-off-by: Richard Henderson <r...@twiddle.net>
---
 cpu-all.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/cpu-all.h b/cpu-all.h
index 927445c..7d31b16 100644
--- a/cpu-all.h
+++ b/cpu-all.h
@@ -637,11 +637,21 @@ extern int have_guest_base;
 
 #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS
 #define h2g_valid(x) 1
+#define guest_start_len_valid(s,l)  ({          \
+    unsigned long __s = (unsigned long)(s);     \
+    unsigned long __e = __s + (l) - 1;          \
+    __e >= __s;                                 \
+})
 #else
 #define h2g_valid(x) ({ \
     unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \
     __guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS); \
 })
+#define guest_start_len_valid(s,l) ({                           \
+    unsigned long __s = (unsigned long)(s);                     \
+    unsigned long __e = __s + (l) - 1;                          \
+    __e >= __s && __e < (1ul << TARGET_VIRT_ADDR_SPACE_BITS);   \
+})
 #endif
 
 #define h2g(x) ({ \
-- 
1.6.6.1



Reply via email to