From nobody Tue Feb 10 06:58:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.52 as permitted sender) client-ip=209.85.221.52; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f52.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1625763989; cv=none; d=zohomail.com; s=zohoarc; b=aG2sQ75JHf0NPWMwFOoy7PyDy58hZa917pJpJ+N9CiSabr36FOs+NyeU7rP06P/D8OhI5wlizxz6iGfDDsCSToyDfkX2lIYAnYDFM+Hwlytc8wAis/9+E6Jm1jjE53yBlpOzzDTPF7FgkYEKuohWXayy5y73jklPdphm1476EDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625763989; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=j7HZJOllN6OfKBQTdNJ3H8eHsI2Pf9DjuFO+rQOtCt8=; b=RQb9OPrbMMW9X0TT8Z/ENJxtlV2iJ2Kinbov2j/PJQikc6eBZSbzQc9tfSDMxSmkMsoPiB1Kwkrmm+qEDeGueswT3buFe5G+C+anrGA7Uic0VVcu2T4sa7OkR6uwCohkcxQ6qdYtWCBcCdHxe41ESeNKvh6Uu2RZkhGEgM8hyQQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.52 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) by mx.zohomail.com with SMTPS id 1625763989003630.840267086028; Thu, 8 Jul 2021 10:06:29 -0700 (PDT) Received: by mail-wr1-f52.google.com with SMTP id f17so8407947wrt.6 for ; Thu, 08 Jul 2021 10:06:27 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (93.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.93]) by smtp.gmail.com with ESMTPSA id d8sm2836199wra.41.2021.07.08.10.06.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jul 2021 10:06:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j7HZJOllN6OfKBQTdNJ3H8eHsI2Pf9DjuFO+rQOtCt8=; b=XkC06vRhcXH7YomgPcaoR/aackxYVmVN2cmnimYW16D9qsY4+IHtIaWuKOj7mC/pVa fvq9VYVK33U5zF7QC95BD4Y3eesCV0stSQJPMSbruf3f6xx3N701QTQr0EhbtJDzeg8y X0sulNiWAsBEi6sz7D25e+RqYQI5QI1rtIoC9BfJSpfOvZy/BKBPhfRQggsgYWufrAbz hOATYqMguIUxwu75Yj9fiVbfdZ8JPGarF1DlABua5jnGWRfxdb7/KPupjWvk5SUnzwHq C8pL+P1x1xHO8gu+7NolRJWmP4HNOu0CdUMk5sCdYqsW2aZirEdjAOnoTGRu38ZRDKjS bUHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=j7HZJOllN6OfKBQTdNJ3H8eHsI2Pf9DjuFO+rQOtCt8=; b=iLhDdBqkMMNWMOGTSy8Kav/TbOWKY7bWfAUTvGQ2ziTOysFKTLoC0F8VCqQQ5AU10G B+oFThMYnpY0obpsgEBUKBZTYAqo0joYV2Ui8Uv99Dd2UM8kXYFlOF+L1Bi+JBCia29A VpN/zHuNl3FTOscpfIzF2gcG+WXo2OKfM62RyRN5iv7I2B0v6J1/Ur+3EBpsNu8Q/S5+ /mexwZmLx9PS5OKmLnFBeLpIppB1/lP6SyGoVvU6MRRTrXCRW4FCvd9BFDgnGnMoQzBV Wh9IjfXGcg01DkTQyaYUO2c0KYj/AJZS3Eae6HXziggLp5TiY1fFzg2jeL7gjDSrUqc9 Plww== X-Gm-Message-State: AOAM5301l5IOWIAcNAo3deR8My9YIkwJpIhcTBtKQTtnddKRT3G7Krwe r6JIScg3/rEo1x3L0nHsDbs= X-Google-Smtp-Source: ABdhPJyni5ZhdPqPA90zSujsWzOsGiqjo5Slo/+O7XFmjP9V8f2+0Px8OYzYivuyWPCGtom3Zx2Shw== X-Received: by 2002:a05:6000:52:: with SMTP id k18mr2523652wrx.270.1625763986148; Thu, 08 Jul 2021 10:06:26 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Laurent Vivier , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 7/8] linux-user: Simplify host <-> target errno conversion using macros Date: Thu, 8 Jul 2021 19:05:49 +0200 Message-Id: <20210708170550.1846343-8-f4bug@amsat.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210708170550.1846343-1-f4bug@amsat.org> References: <20210708170550.1846343-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1625763989695100001 Convert the host_to_target_errno_table[] array to a switch case to allow compiler optimizations (such noticing the identity function when host and guest errnos match). Extract the errnos list as to a new includible unit, using a generic macro. Remove the code related to target_to_host_errno_table[] initialization. Suggested-by: Richard Henderson Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Laurent Vivier Reviewed-by: Richard Henderson --- linux-user/syscall.c | 159 ++++------------------------------------ linux-user/errnos.c.inc | 140 +++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+), 145 deletions(-) create mode 100644 linux-user/errnos.c.inc diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 4842a1987b7..94ec6f730b3 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -509,150 +509,26 @@ static inline int next_free_host_timer(void) =20 #define ERRNO_TABLE_SIZE 1200 =20 -/* target_to_host_errno_table[] is initialized from - * host_to_target_errno_table[] in syscall_init(). */ -static uint16_t target_to_host_errno_table[ERRNO_TABLE_SIZE] =3D { -}; - -/* - * This list is the union of errno values overridden in asm-/errno.h - * minus the errnos that are not actually generic to all archs. - */ -static uint16_t host_to_target_errno_table[ERRNO_TABLE_SIZE] =3D { - [EAGAIN] =3D TARGET_EAGAIN, - [EIDRM] =3D TARGET_EIDRM, - [ECHRNG] =3D TARGET_ECHRNG, - [EL2NSYNC] =3D TARGET_EL2NSYNC, - [EL3HLT] =3D TARGET_EL3HLT, - [EL3RST] =3D TARGET_EL3RST, - [ELNRNG] =3D TARGET_ELNRNG, - [EUNATCH] =3D TARGET_EUNATCH, - [ENOCSI] =3D TARGET_ENOCSI, - [EL2HLT] =3D TARGET_EL2HLT, - [EDEADLK] =3D TARGET_EDEADLK, - [ENOLCK] =3D TARGET_ENOLCK, - [EBADE] =3D TARGET_EBADE, - [EBADR] =3D TARGET_EBADR, - [EXFULL] =3D TARGET_EXFULL, - [ENOANO] =3D TARGET_ENOANO, - [EBADRQC] =3D TARGET_EBADRQC, - [EBADSLT] =3D TARGET_EBADSLT, - [EBFONT] =3D TARGET_EBFONT, - [ENOSTR] =3D TARGET_ENOSTR, - [ENODATA] =3D TARGET_ENODATA, - [ETIME] =3D TARGET_ETIME, - [ENOSR] =3D TARGET_ENOSR, - [ENONET] =3D TARGET_ENONET, - [ENOPKG] =3D TARGET_ENOPKG, - [EREMOTE] =3D TARGET_EREMOTE, - [ENOLINK] =3D TARGET_ENOLINK, - [EADV] =3D TARGET_EADV, - [ESRMNT] =3D TARGET_ESRMNT, - [ECOMM] =3D TARGET_ECOMM, - [EPROTO] =3D TARGET_EPROTO, - [EDOTDOT] =3D TARGET_EDOTDOT, - [EMULTIHOP] =3D TARGET_EMULTIHOP, - [EBADMSG] =3D TARGET_EBADMSG, - [ENAMETOOLONG] =3D TARGET_ENAMETOOLONG, - [EOVERFLOW] =3D TARGET_EOVERFLOW, - [ENOTUNIQ] =3D TARGET_ENOTUNIQ, - [EBADFD] =3D TARGET_EBADFD, - [EREMCHG] =3D TARGET_EREMCHG, - [ELIBACC] =3D TARGET_ELIBACC, - [ELIBBAD] =3D TARGET_ELIBBAD, - [ELIBSCN] =3D TARGET_ELIBSCN, - [ELIBMAX] =3D TARGET_ELIBMAX, - [ELIBEXEC] =3D TARGET_ELIBEXEC, - [EILSEQ] =3D TARGET_EILSEQ, - [ENOSYS] =3D TARGET_ENOSYS, - [ELOOP] =3D TARGET_ELOOP, - [ERESTART] =3D TARGET_ERESTART, - [ESTRPIPE] =3D TARGET_ESTRPIPE, - [ENOTEMPTY] =3D TARGET_ENOTEMPTY, - [EUSERS] =3D TARGET_EUSERS, - [ENOTSOCK] =3D TARGET_ENOTSOCK, - [EDESTADDRREQ] =3D TARGET_EDESTADDRREQ, - [EMSGSIZE] =3D TARGET_EMSGSIZE, - [EPROTOTYPE] =3D TARGET_EPROTOTYPE, - [ENOPROTOOPT] =3D TARGET_ENOPROTOOPT, - [EPROTONOSUPPORT] =3D TARGET_EPROTONOSUPPORT, - [ESOCKTNOSUPPORT] =3D TARGET_ESOCKTNOSUPPORT, - [EOPNOTSUPP] =3D TARGET_EOPNOTSUPP, - [EPFNOSUPPORT] =3D TARGET_EPFNOSUPPORT, - [EAFNOSUPPORT] =3D TARGET_EAFNOSUPPORT, - [EADDRINUSE] =3D TARGET_EADDRINUSE, - [EADDRNOTAVAIL] =3D TARGET_EADDRNOTAVAIL, - [ENETDOWN] =3D TARGET_ENETDOWN, - [ENETUNREACH] =3D TARGET_ENETUNREACH, - [ENETRESET] =3D TARGET_ENETRESET, - [ECONNABORTED] =3D TARGET_ECONNABORTED, - [ECONNRESET] =3D TARGET_ECONNRESET, - [ENOBUFS] =3D TARGET_ENOBUFS, - [EISCONN] =3D TARGET_EISCONN, - [ENOTCONN] =3D TARGET_ENOTCONN, - [EUCLEAN] =3D TARGET_EUCLEAN, - [ENOTNAM] =3D TARGET_ENOTNAM, - [ENAVAIL] =3D TARGET_ENAVAIL, - [EISNAM] =3D TARGET_EISNAM, - [EREMOTEIO] =3D TARGET_EREMOTEIO, - [EDQUOT] =3D TARGET_EDQUOT, - [ESHUTDOWN] =3D TARGET_ESHUTDOWN, - [ETOOMANYREFS] =3D TARGET_ETOOMANYREFS, - [ETIMEDOUT] =3D TARGET_ETIMEDOUT, - [ECONNREFUSED] =3D TARGET_ECONNREFUSED, - [EHOSTDOWN] =3D TARGET_EHOSTDOWN, - [EHOSTUNREACH] =3D TARGET_EHOSTUNREACH, - [EALREADY] =3D TARGET_EALREADY, - [EINPROGRESS] =3D TARGET_EINPROGRESS, - [ESTALE] =3D TARGET_ESTALE, - [ECANCELED] =3D TARGET_ECANCELED, - [ENOMEDIUM] =3D TARGET_ENOMEDIUM, - [EMEDIUMTYPE] =3D TARGET_EMEDIUMTYPE, -#ifdef ENOKEY - [ENOKEY] =3D TARGET_ENOKEY, -#endif -#ifdef EKEYEXPIRED - [EKEYEXPIRED] =3D TARGET_EKEYEXPIRED, -#endif -#ifdef EKEYREVOKED - [EKEYREVOKED] =3D TARGET_EKEYREVOKED, -#endif -#ifdef EKEYREJECTED - [EKEYREJECTED] =3D TARGET_EKEYREJECTED, -#endif -#ifdef EOWNERDEAD - [EOWNERDEAD] =3D TARGET_EOWNERDEAD, -#endif -#ifdef ENOTRECOVERABLE - [ENOTRECOVERABLE] =3D TARGET_ENOTRECOVERABLE, -#endif -#ifdef ENOMSG - [ENOMSG] =3D TARGET_ENOMSG, -#endif -#ifdef ERFKILL - [ERFKILL] =3D TARGET_ERFKILL, -#endif -#ifdef EHWPOISON - [EHWPOISON] =3D TARGET_EHWPOISON, -#endif -}; - -static inline int host_to_target_errno(int err) +static inline int host_to_target_errno(int host_errno) { - if (err >=3D 0 && err < ERRNO_TABLE_SIZE && - host_to_target_errno_table[err]) { - return host_to_target_errno_table[err]; + switch (host_errno) { +#define E(X) case X: return TARGET_##X; +#include "errnos.c.inc" +#undef E + default: + return host_errno; } - return err; } =20 -static inline int target_to_host_errno(int err) +static inline int target_to_host_errno(int target_errno) { - if (err >=3D 0 && err < ERRNO_TABLE_SIZE && - target_to_host_errno_table[err]) { - return target_to_host_errno_table[err]; + switch (target_errno) { +#define E(X) case TARGET_##X: return X; +#include "errnos.c.inc" +#undef E + default: + return target_errno; } - return err; } =20 static inline abi_long get_errno(abi_long ret) @@ -7102,7 +6978,6 @@ void syscall_init(void) IOCTLEntry *ie; const argtype *arg_type; int size; - int i; =20 thunk_init(STRUCT_MAX); =20 @@ -7112,12 +6987,6 @@ void syscall_init(void) #undef STRUCT #undef STRUCT_SPECIAL =20 - /* Build target_to_host_errno_table[] table from - * host_to_target_errno_table[]. */ - for (i =3D 0; i < ERRNO_TABLE_SIZE; i++) { - target_to_host_errno_table[host_to_target_errno_table[i]] =3D i; - } - /* we patch the ioctl size if necessary. We rely on the fact that no ioctl has all the bits at '1' in the size field */ ie =3D ioctl_entries; diff --git a/linux-user/errnos.c.inc b/linux-user/errnos.c.inc new file mode 100644 index 00000000000..963ba1ce9d1 --- /dev/null +++ b/linux-user/errnos.c.inc @@ -0,0 +1,140 @@ +/* + * This list is the union of errno values overridden in asm-/errno.h + * minus the errnos that are not actually generic to all archs. + * + * Please keep this list sorted alphabetically. + * + * Copyright (c) 2003 Fabrice Bellard + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +E(EADDRINUSE) +E(EADDRNOTAVAIL) +E(EADV) +E(EAFNOSUPPORT) +E(EAGAIN) +E(EALREADY) +E(EBADE) +E(EBADFD) +E(EBADMSG) +E(EBADR) +E(EBADRQC) +E(EBADSLT) +E(EBFONT) +E(ECANCELED) +E(ECHRNG) +E(ECOMM) +E(ECONNABORTED) +E(ECONNREFUSED) +E(ECONNRESET) +E(EDEADLK) +E(EDESTADDRREQ) +E(EDOTDOT) +E(EDQUOT) +E(EHOSTDOWN) +E(EHOSTUNREACH) +#ifdef EHWPOISON +E(EHWPOISON) +#endif +E(EIDRM) +E(EILSEQ) +E(EINPROGRESS) +E(EISCONN) +E(EISNAM) +#ifdef EKEYEXPIRED +E(EKEYEXPIRED) +#endif +#ifdef EKEYREJECTED +E(EKEYREJECTED) +#endif +#ifdef EKEYREVOKED +E(EKEYREVOKED) +#endif +E(EL2HLT) +E(EL2NSYNC) +E(EL3HLT) +E(EL3RST) +E(ELIBACC) +E(ELIBBAD) +E(ELIBEXEC) +E(ELIBMAX) +E(ELIBSCN) +E(ELNRNG) +E(ELOOP) +E(EMEDIUMTYPE) +E(EMSGSIZE) +E(EMULTIHOP) +E(ENAMETOOLONG) +E(ENAVAIL) +E(ENETDOWN) +E(ENETRESET) +E(ENETUNREACH) +E(ENOANO) +E(ENOBUFS) +E(ENOCSI) +E(ENODATA) +#ifdef ENOKEY +E(ENOKEY) +#endif +E(ENOLCK) +E(ENOLINK) +E(ENOMEDIUM) +#ifdef ENOMSG +E(ENOMSG) +#endif +E(ENONET) +E(ENOPKG) +E(ENOPROTOOPT) +E(ENOSR) +E(ENOSTR) +E(ENOSYS) +E(ENOTCONN) +E(ENOTEMPTY) +E(ENOTNAM) +#ifdef ENOTRECOVERABLE +E(ENOTRECOVERABLE) +#endif +E(ENOTSOCK) +E(ENOTUNIQ) +E(EOPNOTSUPP) +E(EOVERFLOW) +#ifdef EOWNERDEAD +E(EOWNERDEAD) +#endif +E(EPFNOSUPPORT) +E(EPROTO) +E(EPROTONOSUPPORT) +E(EPROTOTYPE) +E(EREMCHG) +E(EREMOTE) +E(EREMOTEIO) +E(ERESTART) +#ifdef ERFKILL +E(ERFKILL) +#endif +E(ESHUTDOWN) +E(ESOCKTNOSUPPORT) +E(ESRMNT) +E(ESTALE) +E(ESTRPIPE) +E(ETIME) +E(ETIMEDOUT) +E(ETOOMANYREFS) +E(EUCLEAN) +E(EUNATCH) +E(EUSERS) +E(EXFULL) --=20 2.31.1