From nobody Tue Feb 10 10:54:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.221.41 as permitted sender) client-ip=209.85.221.41; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wr1-f41.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1625423937; cv=none; d=zohomail.com; s=zohoarc; b=KCKcxKJs/IM/D6758XrBzUDlFfiFAf+Nna0NY8i/0ZlmmmIeKjesGT0HIyFXFd+PqvacP1+s7BYA6/ySGPYK3v+G29Sq3FqEiduuhlKy8fg9oA0Sgq+v9RAB5oIUf060n9r5yuZSGjuEeK3d+sd3lZdFmAHh6zvstXccSLGRTak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625423937; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Oz3/9LjOF/DujRVAV4aK72odTL+SNItH8ndIDVrL7Cc=; b=mEgcXWjN9yjPKvfQJqsf8g5AJLeQEOiRDnk4BoMzEnWDebhWlvLjYBKrGoU1aZpMUoLCqFF1hFWHePfZ49iItozql/OlCJNKvr7AdBN+4PDXnBg5n4NlNK92L1jpWBDovAG1qohR4LiP2c/e1AGIJMBprHFE9m4NGYtvB88HN6s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.221.41 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by mx.zohomail.com with SMTPS id 162542393738072.41670253737561; Sun, 4 Jul 2021 11:38:57 -0700 (PDT) Received: by mail-wr1-f41.google.com with SMTP id u8so19218879wrq.8 for ; Sun, 04 Jul 2021 11:38:56 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.. (93.red-83-35-24.dynamicip.rima-tde.net. [83.35.24.93]) by smtp.gmail.com with ESMTPSA id f14sm3451041wmq.10.2021.07.04.11.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jul 2021 11:38:55 -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=Oz3/9LjOF/DujRVAV4aK72odTL+SNItH8ndIDVrL7Cc=; b=vQPIFpT0avrRTFZcX1IapggI2sqF9HHkNWC88ySXNsUG0BGV6biJKrz+jmgIvXcZfI KIDsAsD1kFcOMPo2emJowwLFF58tcIzKNpDjF4r+rV/tpKtLd2dtBQdOihTEJhzZZXB3 /l49CauVvnpISpD7uOaHV/3Rc53yhm6dASnK70smHZX0mRam6xyYslljA4o8sHTOoof7 OxtOxv5tn2RM++zx4ohNanopfu3+15myCa1UNRmb1OrjOhwOKiKbxJakn8szXQECfS24 gXqrtui4RlBaYgzv4GgK91Kscr/fFKXqVcohGJGxZ36KqvuxLnzqOjbQ0bG5UQwFYRaf zwww== 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=Oz3/9LjOF/DujRVAV4aK72odTL+SNItH8ndIDVrL7Cc=; b=hcve551QkngOiTgWHN8pEnROdFF18m6LuL1WfflDFVrfLMHXmr7i50QgsAx9+Zvwof D+SuTKy4CXA+DSHsOzuXhcPVipD2AoVqNzF9aaSXugO3LNpn9jLkGfLZzYs0CmQlbPrx 3+V0BaVWVLcdLfoa6xr8cfOtDIZ/uY5rDbiN0wa0koZFHbwUneWj4A9DhO22y2Q1bEiI WAr9bVsfmQtcL5ShhvKhkFtJ7TJDcoXEpBIU5Elhe2HZ9zCPdYjDNw+NsBse1szntm3M Vu/PCqff8IBWgd3QRFvapYdxkom04CW5IJXZOP7UWVCop74cvhwTQOZaMrlajN3JvJmz fu9g== X-Gm-Message-State: AOAM531OeTQiVk3H0aEW+z73M0W/Pb2nEZ7tgbQjTkJp23l5/1tQAU8V eFAy6KKQZK47V2yNoJSQ8mVurE3fkNU= X-Google-Smtp-Source: ABdhPJwu0aMwGWM8VnVjhDt2sPa0r1PD7zNBSELGyOjoA4PtJ8asQNeIoBx2ntJhyCjCWhvsM6Zhfw== X-Received: by 2002:a05:6000:18ca:: with SMTP id w10mr11188229wrq.55.1625423935535; Sun, 04 Jul 2021 11:38:55 -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: Richard Henderson , Jiaxun Yang , Laurent Vivier , Aleksandar Rikalo , Taylor Simpson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Aurelien Jarno , Helge Deller Subject: [PATCH 12/12] linux-user: Extract target errno related functions to 'target_errno.h' Date: Sun, 4 Jul 2021 20:37:55 +0200 Message-Id: <20210704183755.655002-13-f4bug@amsat.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210704183755.655002-1-f4bug@amsat.org> References: <20210704183755.655002-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: 1625423940220100001 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=C3=A9 --- 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 diff --git a/linux-user/target_errno.h b/linux-user/target_errno.h new file mode 100644 index 00000000000..4e5e9d384c9 --- /dev/null +++ b/linux-user/target_errno.h @@ -0,0 +1,32 @@ +/* + * Linux syscalls + * + * 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 + */ +#ifndef LINUX_USER_TARGET_ERRNO_H +#define LINUX_USER_TARGET_ERRNO_H + +#define ERRNO_TABLE_SIZE 1200 + +int target_to_host_errno(int err); + +void target_to_host_errno_table_init(void); + +int host_to_target_errno(int err); + +#endif diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3761d3b2d64..06c4358b813 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -131,6 +131,7 @@ #include "qemu/selfmap.h" #include "user/syscall-trace.h" #include "qapi/error.h" +#include "target_errno.h" #include "fd-trans.h" #include "tcg/tcg.h" =20 @@ -507,167 +508,6 @@ static inline int next_free_host_timer(void) } #endif =20 -#define ERRNO_TABLE_SIZE 1200 - -/* - * 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] =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 ERKFILL - [ERFKILL] =3D TARGET_ERFKILL, -#endif -#ifdef EHWPOISON - [EHWPOISON] =3D TARGET_EHWPOISON, -#endif -}; - -static void target_to_host_errno_table_init(void) -{ - /* - * Build target_to_host_errno_table[] table - * from host_to_target_errno_table[]. - */ - for (int i =3D 0; i < ERRNO_TABLE_SIZE; i++) { - target_to_host_errno_table[host_to_target_errno_table[i]] =3D i; - } -} - -static inline int host_to_target_errno(int err) -{ - if (err >=3D 0 && err < ERRNO_TABLE_SIZE && - host_to_target_errno_table[err]) { - return host_to_target_errno_table[err]; - } - return err; -} - -static inline int target_to_host_errno(int err) -{ - if (err >=3D 0 && err < ERRNO_TABLE_SIZE && - target_to_host_errno_table[err]) { - return target_to_host_errno_table[err]; - } - return err; -} - static inline abi_long get_errno(abi_long ret) { if (ret =3D=3D -1) diff --git a/linux-user/target_errno.c b/linux-user/target_errno.c new file mode 100644 index 00000000000..2a7320d240f --- /dev/null +++ b/linux-user/target_errno.c @@ -0,0 +1,183 @@ +/* + * Linux syscalls + * + * 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 + */ + +#include "qemu/osdep.h" +#include "target_errno.h" +#include "errno_defs.h" + +/* + * 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] =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 ERKFILL + [ERFKILL] =3D TARGET_ERFKILL, +#endif +#ifdef EHWPOISON + [EHWPOISON] =3D TARGET_EHWPOISON, +#endif +}; + +void target_to_host_errno_table_init(void) +{ + /* + * Build target_to_host_errno_table[] table + * from host_to_target_errno_table[]. + */ + for (int i =3D 0; i < ERRNO_TABLE_SIZE; i++) { + target_to_host_errno_table[host_to_target_errno_table[i]] =3D i; + } +} + +int host_to_target_errno(int err) +{ + if (err >=3D 0 && err < ERRNO_TABLE_SIZE && + host_to_target_errno_table[err]) { + return host_to_target_errno_table[err]; + } + return err; +} + +int target_to_host_errno(int err) +{ + if (err >=3D 0 && err < ERRNO_TABLE_SIZE && + target_to_host_errno_table[err]) { + return target_to_host_errno_table[err]; + } + return err; +} diff --git a/linux-user/meson.build b/linux-user/meson.build index 9549f81682d..f757b63310b 100644 --- a/linux-user/meson.build +++ b/linux-user/meson.build @@ -9,6 +9,7 @@ 'signal.c', 'strace.c', 'syscall.c', + 'target_errno.c', 'uaccess.c', 'uname.c', )) --=20 2.31.1