[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v4 07/43] tcg: Add in_code_gen_buffer
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH v4 07/43] tcg: Add in_code_gen_buffer |
Date: |
Wed, 16 Dec 2020 00:15:49 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 |
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.henderson@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é <f4bug@amsat.org>
Thanks,
Phil.
- [PATCH v4 01/43] tcg: Do not flush icache for interpreter, (continued)
- [PATCH v4 08/43] tcg: Introduce tcg_splitwx_to_{rx,rw}, Richard Henderson, 2020/12/14
- [PATCH v4 11/43] tcg: Adjust tcg_out_label for const, Richard Henderson, 2020/12/14
- [PATCH v4 12/43] tcg: Adjust tcg_register_jit for const, Richard Henderson, 2020/12/14
- [PATCH v4 09/43] tcg: Adjust TCGLabel for const, Richard Henderson, 2020/12/14
- [PATCH v4 14/43] tcg: Make DisasContextBase.tb const, Richard Henderson, 2020/12/14
- [PATCH v4 10/43] tcg: Adjust tcg_out_call for const, Richard Henderson, 2020/12/14
- [PATCH v4 18/43] accel/tcg: Support split-wx for linux with memfd, Richard Henderson, 2020/12/14