From: Richard Henderson <richard.henderson@linaro.org>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, qemu-devel@nongnu.org
Cc: Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>,
Helge Deller <deller@gmx.de>, Laurent Vivier <laurent@vivier.eu>,
Taylor Simpson <tsimpson@quicinc.com>,
Aurelien Jarno <aurelien@aurel32.net>
Subject: Re: [PATCH 12/12] linux-user: Extract target errno related functions to 'target_errno.h'
Date: Tue, 6 Jul 2021 19:08:59 -0700 [thread overview]
Message-ID: <d75bddf7-f54c-6b7a-803b-7a01e8e20fb6@linaro.org> (raw)
In-Reply-To: <20210704183755.655002-13-f4bug@amsat.org>
On 7/4/21 11:37 AM, Philippe Mathieu-Daudé wrote:
> Extract target errno related functions to a new 'target_errno.h'
> header, so we can do the host <-> target errno conversion out of
> the big syscall.c (which is already 13k LoC).
>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> linux-user/target_errno.h | 32 +++++++
> linux-user/syscall.c | 162 +--------------------------------
> linux-user/target_errno.c | 183 ++++++++++++++++++++++++++++++++++++++
> linux-user/meson.build | 1 +
> 4 files changed, 217 insertions(+), 161 deletions(-)
> create mode 100644 linux-user/target_errno.h
> create mode 100644 linux-user/target_errno.c
I guess this is just data movement, so it's ok.
But...
> +/*
> + * target_to_host_errno_table[] is initialized from
> + * host_to_target_errno_table[] in target_to_host_errno_table_init().
> + */
> +static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE] = {
> +};
> +
> +/*
> + * This list is the union of errno values overridden in asm-<arch>/errno.h
> + * minus the errnos that are not actually generic to all archs.
> + */
> +static uint16_t host_to_target_errno_table[ERRNO_TABLE_SIZE] = {
> + [EAGAIN] = TARGET_EAGAIN,
> + [EIDRM] = TARGET_EIDRM,
> + [ECHRNG] = TARGET_ECHRNG,
... there's enough pattern here to make it easy to initialize both of these at
compile-time. We just need to move the list out to a .c.inc file.
--%<
E(EAGAIN)
E(EIDRM)
...
#ifdef EFOO
E(EFOO)
#endif
--%<
static const uint16_t target_to_host_errno_table[] = {
#define E(X) [TARGET_##X] = X,
#include "errnos.c.inc"
#undef E
};
static const uint16_t host_to_target_errno_table[] = {
#define E(X) [X] = TARGET_##X,
#include "errnos.c.inc"
#undef E
};
> +int host_to_target_errno(int err)
> +{
> + if (err >= 0 && err < ERRNO_TABLE_SIZE &&
> + host_to_target_errno_table[err]) {
> + return host_to_target_errno_table[err];
> + }
> + return err;
> +}
Here and
> +int target_to_host_errno(int err)
> +{
> + if (err >= 0 && err < ERRNO_TABLE_SIZE &&
> + target_to_host_errno_table[err]) {
> + return target_to_host_errno_table[err];
> + }
> + return err;
> +}
here, we might as well use ARRAY_SIZE(foo) instead of ERRNO_TABLE_SIZE.
Or even convert directly to switches, with no array, and let the compiler decide what it
thinks is best. Which might turn out to compile away to the identity function when host
and guest are both asm-generic.
r~
prev parent reply other threads:[~2021-07-07 2:10 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-04 18:37 [PATCH 00/12] linux-user: Extract target errno related functions to 'target_errno.h' Philippe Mathieu-Daudé
2021-07-04 18:37 ` [PATCH 01/12] linux-user/alpha: Handle TARGET_EWOULDBLOCK as TARGET_EAGAIN Philippe Mathieu-Daudé
2021-07-07 1:44 ` Richard Henderson
2021-07-07 19:25 ` Laurent Vivier
2021-07-04 18:37 ` [PATCH 02/12] linux-user/hppa: " Philippe Mathieu-Daudé
2021-07-07 1:44 ` Richard Henderson
2021-07-07 19:26 ` Laurent Vivier
2021-07-04 18:37 ` [PATCH 03/12] linux-user/mips: " Philippe Mathieu-Daudé
2021-07-07 1:45 ` Richard Henderson
2021-07-07 19:27 ` Laurent Vivier
2021-07-04 18:37 ` [PATCH 04/12] linux-user/sparc: Rename target_errno.h -> target_errno_defs.h Philippe Mathieu-Daudé
2021-07-07 19:29 ` Laurent Vivier
2021-07-04 18:37 ` [PATCH 05/12] linux-user: Extract target errno to 'target_errno_defs.h' Philippe Mathieu-Daudé
2021-07-05 22:32 ` Taylor Simpson
2021-07-07 1:53 ` Richard Henderson
2021-07-08 8:32 ` Philippe Mathieu-Daudé
2021-07-04 18:37 ` [PATCH 06/12] linux-user/alpha: Remove hardcoded tabs (code style) Philippe Mathieu-Daudé
2021-07-07 1:46 ` Richard Henderson
2021-07-07 19:32 ` Laurent Vivier
2021-07-04 18:37 ` [PATCH 07/12] linux-user/alpha: Move errno definitions to 'target_errno_defs.h' Philippe Mathieu-Daudé
2021-07-04 18:37 ` [PATCH 08/12] linux-user/hppa: " Philippe Mathieu-Daudé
2021-07-04 18:37 ` [PATCH 09/12] linux-user/mips: " Philippe Mathieu-Daudé
2021-07-04 18:37 ` [PATCH 10/12] linux-user/syscall: Refactor target_to_host_errno_table_init() Philippe Mathieu-Daudé
2021-07-04 18:37 ` [PATCH 11/12] linux-user/syscall: Remove hardcoded tabs (code style) Philippe Mathieu-Daudé
2021-07-07 19:34 ` Laurent Vivier
2021-07-04 18:37 ` [PATCH 12/12] linux-user: Extract target errno related functions to 'target_errno.h' Philippe Mathieu-Daudé
2021-07-05 22:29 ` Taylor Simpson
2021-07-07 2:08 ` Richard Henderson [this message]
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=d75bddf7-f54c-6b7a-803b-7a01e8e20fb6@linaro.org \
--to=richard.henderson@linaro.org \
--cc=aleksandar.rikalo@syrmia.com \
--cc=aurelien@aurel32.net \
--cc=deller@gmx.de \
--cc=f4bug@amsat.org \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=tsimpson@quicinc.com \
/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).