Patchwork [2/7] Add guest_start_len_valid function.

login
register
mail settings
Submitter Richard Henderson
Date April 5, 2010, 5:24 p.m.
Message ID <8fab352a4e45a8412daed0adb442dc4457279ca0.1270488612.git.rth@twiddle.net>
Download mbox | patch
Permalink /patch/49414/
State New
Headers show

Comments

Richard Henderson - April 5, 2010, 5:24 p.m.
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 <rth@twiddle.net>
---
 cpu-all.h |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
malc - April 5, 2010, 6:15 p.m.
On Mon, 5 Apr 2010, Richard Henderson wrote:

> 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 <rth@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

Please do not use double leading underscore.

>  
>  #define h2g(x) ({ \
>
Richard Henderson - April 5, 2010, 6:31 p.m.
On 04/05/2010 11:15 AM, malc wrote:
> Please do not use double leading underscore.

In contrast to the existing use in:

>>  #define h2g_valid(x) ({ \
>>      unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \

What do you suggest instead?  Trailing underscores?


r~
malc - April 5, 2010, 6:41 p.m.
On Mon, 5 Apr 2010, Richard Henderson wrote:

> On 04/05/2010 11:15 AM, malc wrote:
> > Please do not use double leading underscore.
> 
> In contrast to the existing use in:
> 
> >>  #define h2g_valid(x) ({ \
> >>      unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \
> 
> What do you suggest instead?  Trailing underscores?

Yes, the code is not C++ so trailing underscores will do.

Patch

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) ({ \