On 12/15/20 11:43 PM, Richard Henderson wrote: > On 12/14/20 4:09 PM, Philippe Mathieu-Daudé wrote: >> On 12/14/20 3:02 PM, Richard Henderson wrote: >>> Create a function to determine if a pointer is within the buffer. >>> >>> Signed-off-by: Richard Henderson <richard.hender...@linaro.org> >>> --- >>> include/tcg/tcg.h | 6 ++++++ >>> accel/tcg/translate-all.c | 26 ++++++++------------------ >>> 2 files changed, 14 insertions(+), 18 deletions(-) >>> >>> diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h >>> index bb1e97b13b..e4d0ace44b 100644 >>> --- a/include/tcg/tcg.h >>> +++ b/include/tcg/tcg.h >>> @@ -680,6 +680,12 @@ extern __thread TCGContext *tcg_ctx; >>> extern void *tcg_code_gen_epilogue; >>> extern TCGv_env cpu_env; >>> >>> +static inline bool in_code_gen_buffer(const void *p) >>> +{ >>> + const TCGContext *s = &tcg_init_ctx; >>> + return (size_t)(p - s->code_gen_buffer) <= s->code_gen_buffer_size; >> >> If 'p == s->code_gen_buffer + s->code_gen_buffer_size', >> is it really "in" the buffer? > > Well, sort of. > > Compare the fact that in C, a pointer to the end of an array is valid as a > pointer even though it can't be dereferenced. This is a pointer to the end of > the buffer. > > Extra commentary required?
Preferably, since you change from '<' to '<=', this would make it clearer, then no question asked :) With it: Reviewed-by: Philippe Mathieu-Daudé <f4...@amsat.org> Thanks, Phil.