From: Richard Henderson <richard.henderson@linaro.org>
To: Vivian Wang <uwu@dram.page>, qemu-devel@nongnu.org
Cc: Richard Henderson <rth@twiddle.net>, Laurent Vivier <laurent@vivier.eu>
Subject: Re: [PATCH 1/2] util/getauxval: Ensure setting errno if not found
Date: Tue, 23 Jul 2024 09:24:29 +1000 [thread overview]
Message-ID: <0b27836e-88d2-475a-9cd4-bf781861298c@linaro.org> (raw)
In-Reply-To: <20240721090817.120888-2-uwu@dram.page>
On 7/21/24 19:08, Vivian Wang wrote:
> Sometimes zero is a valid value for getauxval (e.g. AT_EXECFD). Make
> sure that we can distinguish between a valid zero value and a not found
> entry by setting errno.
>
> Ignore getauxval from sys/auxv.h on glibc < 2.19 because it does not set
> errno.
>
> Signed-off-by: Vivian Wang <uwu@dram.page>
> ---
> util/getauxval.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/util/getauxval.c b/util/getauxval.c
> index b124107d61..f1008bdc59 100644
> --- a/util/getauxval.c
> +++ b/util/getauxval.c
> @@ -24,7 +24,13 @@
>
> #include "qemu/osdep.h"
>
> -#ifdef CONFIG_GETAUXVAL
> +/* If glibc < 2.19, getauxval can't be used because it does not set errno if
> + entry is not found. */
> +#if defined(CONFIG_GETAUXVAL) && \
> + (!defined(__GLIBC__) \
> + || __GLIBC__ > 2 \
> + || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 19))
Version 2.19 is so long ago that all supported OS releases have something newer. For
Alpine Linux using musl, the first commit of getauxval had the errno setting.
Therefore we don't need this check.
> @@ -95,6 +101,7 @@ unsigned long qemu_getauxval(unsigned long type)
> }
> }
>
> + errno = ENOENT;
> return 0;
> }
Ok.
> @@ -104,7 +111,9 @@ unsigned long qemu_getauxval(unsigned long type)
> unsigned long qemu_getauxval(unsigned long type)
> {
> unsigned long aux = 0;
> - elf_aux_info(type, &aux, sizeof(aux));
> + int ret = elf_aux_info(type, &aux, sizeof(aux));
> + if (ret != 0)
> + errno = ret;
Braces required.
> return aux;
> }
>
> @@ -112,6 +121,7 @@ unsigned long qemu_getauxval(unsigned long type)
>
> unsigned long qemu_getauxval(unsigned long type)
> {
> + errno = ENOSYS;
> return 0;
> }
Ok.
r~
next prev parent reply other threads:[~2024-07-22 23:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-21 9:08 [PATCH 0/2] linux-user: Fix handling when AT_EXECFD is 0 Vivian Wang
2024-07-21 9:08 ` [PATCH 1/2] util/getauxval: Ensure setting errno if not found Vivian Wang
2024-07-22 0:18 ` Xingtao Yao (Fujitsu) via
2024-07-22 8:24 ` Vivian Wang
2024-07-22 9:26 ` Xingtao Yao (Fujitsu) via
2024-07-22 23:24 ` Richard Henderson [this message]
2024-07-21 9:08 ` [PATCH 2/2] linux-user/main: Check errno when getting AT_EXECFD Vivian Wang
2024-07-22 23:24 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0b27836e-88d2-475a-9cd4-bf781861298c@linaro.org \
--to=richard.henderson@linaro.org \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=uwu@dram.page \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).