Message ID | 8fab352a4e45a8412daed0adb442dc4457279ca0.1270488612.git.rth@twiddle.net |
---|---|
State | New |
Headers | show |
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) ({ \ >
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~
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.
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) ({ \
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(-)