Add defines for Linux errno values and use them to make linux_errtbl[]

more readable.  While here, add linux_check_errtbl() function to make
sure we don't leave holes.

No objections:	emaste (earlier version)
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D26972
This commit is contained in:
Edward Tomasz Napierala 2020-10-29 14:23:52 +00:00
parent 80d8e42662
commit 1a8577fa68
6 changed files with 302 additions and 97 deletions

View File

@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <sysdecode.h> #include <sysdecode.h>
#if defined(__aarch64__) || defined(__amd64__) || defined(__i386__) #if defined(__aarch64__) || defined(__amd64__) || defined(__i386__)
#include <compat/linux/linux_errno.h>
static static
#include <compat/linux/linux_errno.inc> #include <compat/linux/linux_errno.inc>
#endif #endif

View File

@ -197,5 +197,6 @@ int linux_to_bsd_bits_(int value, struct bsd_to_linux_bitmap *bitmap,
#define BITMAP_1t1_LINUX(_name) BITMAP_EASY_LINUX(_name, LINUX_##_name) #define BITMAP_1t1_LINUX(_name) BITMAP_EASY_LINUX(_name, LINUX_##_name)
int bsd_to_linux_errno(int error); int bsd_to_linux_errno(int error);
void linux_check_errtbl(void);
#endif /* _LINUX_MI_H_ */ #endif /* _LINUX_MI_H_ */

View File

@ -67,6 +67,9 @@ linux_common_modevent(module_t mod, int type, void *data)
switch(type) { switch(type) {
case MOD_LOAD: case MOD_LOAD:
#ifdef INVARIANTS
linux_check_errtbl();
#endif
linux_dev_shm_create(); linux_dev_shm_create();
linux_osd_jail_register(); linux_osd_jail_register();
linux_exit_tag = EVENTHANDLER_REGISTER(process_exit, linux_exit_tag = EVENTHANDLER_REGISTER(process_exit,

View File

@ -8,6 +8,7 @@ __FBSDID("$FreeBSD$");
#include <sys/systm.h> #include <sys/systm.h>
#include <compat/linux/linux.h> #include <compat/linux/linux.h>
#include <compat/linux/linux_errno.h>
#include <compat/linux/linux_errno.inc> #include <compat/linux/linux_errno.inc>
int int
@ -19,3 +20,16 @@ bsd_to_linux_errno(int error)
return (linux_errtbl[error]); return (linux_errtbl[error]);
} }
#ifdef INVARIANTS
void
linux_check_errtbl(void)
{
int i;
for (i = 1; i < sizeof(linux_errtbl); i++) {
KASSERT(linux_errtbl[i] != 0,
("%s: linux_errtbl[%d] == 0", __func__, i));
}
}
#endif

View File

@ -0,0 +1,183 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2020 The FreeBSD Foundation
*
* This software was developed by Edward Tomasz Napierala under sponsorship
* from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#ifndef _LINUX_ERRNO_H_
#define _LINUX_ERRNO_H_
#define LINUX_EPERM 1
#define LINUX_ENOENT 2
#define LINUX_ESRCH 3
#define LINUX_EINTR 4
#define LINUX_EIO 5
#define LINUX_ENXIO 6
#define LINUX_E2BIG 7
#define LINUX_ENOEXEC 8
#define LINUX_EBADF 9
#define LINUX_ECHILD 10
#define LINUX_EAGAIN 11
#define LINUX_ENOMEM 12
#define LINUX_EACCES 13
#define LINUX_EFAULT 14
#define LINUX_ENOTBLK 15
#define LINUX_EBUSY 16
#define LINUX_EEXIST 17
#define LINUX_EXDEV 18
#define LINUX_ENODEV 19
#define LINUX_ENOTDIR 20
#define LINUX_EISDIR 21
#define LINUX_EINVAL 22
#define LINUX_ENFILE 23
#define LINUX_EMFILE 24
#define LINUX_ENOTTY 25
#define LINUX_ETXTBSY 26
#define LINUX_EFBIG 27
#define LINUX_ENOSPC 28
#define LINUX_ESPIPE 29
#define LINUX_EROFS 30
#define LINUX_EMLINK 31
#define LINUX_EPIPE 32
#define LINUX_EDOM 33
#define LINUX_ERANGE 34
#define LINUX_EDEADLK 35
#define LINUX_ENAMETOOLONG 36
#define LINUX_ENOLCK 37
#define LINUX_ENOSYS 38
#define LINUX_ENOTEMPTY 39
#define LINUX_ELOOP 40
/* XXX: errno 41 is not defined in Linux. */
#define LINUX_ENOMSG 42
#define LINUX_EIDRM 43
#define LINUX_ECHRNG 44
#define LINUX_EL2NSYNC 45
#define LINUX_EL3HLT 46
#define LINUX_EL3RST 47
#define LINUX_ELNRNG 48
#define LINUX_EUNATCH 49
#define LINUX_ENOCSI 50
#define LINUX_L2HLT 51
#define LINUX_EBADE 52
#define LINUX_EBADR 53
#define LINUX_EXFULL 54
#define LINUX_ENOANO 55
#define LINUX_EBADRQC 56
#define LINUX_EBADSLT 57
/* XXX: errno 58 is not defined in Linux. */
#define LINUX_EBFONT 59
#define LINUX_ENOSTR 60
#define LINUX_ENODATA 61
#define LINUX_ENOTIME 62
#define LINUX_ENOSR 63
#define LINUX_ENONET 64
#define LINUX_ENOPKG 65
#define LINUX_EREMOTE 66
#define LINUX_ENOLINK 67
#define LINUX_EADV 68
#define LINUX_ESRMNT 69
#define LINUX_ECOMM 70
#define LINUX_EPROTO 71
#define LINUX_EMULTIHOP 72
#define LINUX_EDOTDOT 73
#define LINUX_EBADMSG 74
#define LINUX_EOVERFLOW 75
#define LINUX_ENOTUNIQ 76
#define LINUX_EBADFD 77
#define LINUX_EREMCHG 78
#define LINUX_ELIBACC 79
#define LINUX_ELIBBAD 80
#define LINUX_ELIBSCN 81
#define LINUX_ELIBMAX 82
#define LINUX_ELIBEXEC 83
#define LINUX_EILSEQ 84
#define LINUX_ERESTART 85
#define LINUX_ESTRPIPE 86
#define LINUX_EUSERS 87
#define LINUX_ENOTSOCK 88
#define LINUX_EDESTADDRREQ 89
#define LINUX_EMSGSIZE 90
#define LINUX_EPROTOTYPE 91
#define LINUX_ENOPROTOOPT 92
#define LINUX_EPROTONOTSUPPORT 93
#define LINUX_ESOCKNOTSUPPORT 94
#define LINUX_EOPNOTSUPPORT 95
#define LINUX_EPFNOTSUPPORT 96
#define LINUX_EAFNOTSUPPORT 97
#define LINUX_EADDRINUSE 98
#define LINUX_EADDRNOTAVAIL 99
#define LINUX_ENETDOWN 100
#define LINUX_ENETUNREACH 101
#define LINUX_ENETRESET 102
#define LINUX_ECONNABORTED 103
#define LINUX_ECONNRESET 104
#define LINUX_ENOBUFS 105
#define LINUX_EISCONN 106
#define LINUX_ENOTCONN 107
#define LINUX_ESHUTDOWN 108
#define LINUX_ETOOMANYREFS 109
#define LINUX_ETIMEDOUT 110
#define LINUX_ECONNREFUSED 111
#define LINUX_EHOSTDOWN 112
#define LINUX_EHOSTUNREACH 113
#define LINUX_EALREADY 114
#define LINUX_EINPROGRESS 115
#define LINUX_ESTALE 116
#define LINUX_EUCLEAN 117
#define LINUX_ENOTNAM 118
#define LINUX_ENAVAIL 119
#define LINUX_EISNAM 120
#define LINUX_EREMOTEIO 121
#define LINUX_EDQUOT 122
#define LINUX_ENOMEDIUM 123
#define LINUX_EMEDIUMTYPE 124
#define LINUX_ECANCELED 125
#define LINUX_ENOKEY 126
#define LINUX_EKEYEXPIRED 127
#define LINUX_EKEYREVOKED 128
#define LINUX_EKEYREJECTED 129
#define LINUX_EOWNERDEAD 130
#define LINUX_ENOTRECOVERABLE 131
#define LINUX_ERFKILL 132
#define LINUX_EHWPOISON 133
#endif /* _LINUX_ERRNO_H_ */

View File

@ -34,125 +34,128 @@
* FreeBSD: src/sys/sys/errno.h * FreeBSD: src/sys/sys/errno.h
* Linux: include/uapi/asm-generic/errno-base.h * Linux: include/uapi/asm-generic/errno-base.h
* include/uapi/asm-generic/errno.h * include/uapi/asm-generic/errno.h
*
* XXX: The "XXX" comments below should be replaced with rationale
* for the errno value chosen.
*/ */
const int linux_errtbl[ELAST + 1] = { const int linux_errtbl[ELAST + 1] = {
/* [0, 9] */ /* [0, 9] */
[0] = -0, [0] = -0,
[EPERM] = -1, [EPERM] = -LINUX_EPERM,
[ENOENT] = -2, [ENOENT] = -LINUX_ENOENT,
[ESRCH] = -3, [ESRCH] = -LINUX_ESRCH,
[EINTR] = -4, [EINTR] = -LINUX_EINTR,
[EIO] = -5, [EIO] = -LINUX_EIO,
[ENXIO] = -6, [ENXIO] = -LINUX_ENXIO,
[E2BIG] = -7, [E2BIG] = -LINUX_E2BIG,
[ENOEXEC] = -8, [ENOEXEC] = -LINUX_ENOEXEC,
[EBADF] = -9, [EBADF] = -LINUX_EBADF,
/* [10, 19] */ /* [10, 19] */
[ECHILD] = -10, [ECHILD] = -LINUX_ECHILD,
[EDEADLK] = -35, [EDEADLK] = -LINUX_EDEADLK,
[ENOMEM] = -12, [ENOMEM] = -LINUX_ENOMEM,
[EACCES] = -13, [EACCES] = -LINUX_EACCES,
[EFAULT] = -14, [EFAULT] = -LINUX_EFAULT,
[ENOTBLK] = -15, [ENOTBLK] = -LINUX_ENOTBLK,
[EBUSY] = -16, [EBUSY] = -LINUX_EBUSY,
[EEXIST] = -17, [EEXIST] = -LINUX_EEXIST,
[EXDEV] = -18, [EXDEV] = -LINUX_EXDEV,
[ENODEV] = -19, [ENODEV] = -LINUX_ENODEV,
/* [20, 29] */ /* [20, 29] */
[ENOTDIR] = -20, [ENOTDIR] = -LINUX_ENOTDIR,
[EISDIR] = -21, [EISDIR] = -LINUX_EISDIR,
[EINVAL] = -22, [EINVAL] = -LINUX_EINVAL,
[ENFILE] = -23, [ENFILE] = -LINUX_ENFILE,
[EMFILE] = -24, [EMFILE] = -LINUX_EMFILE,
[ENOTTY] = -25, [ENOTTY] = -LINUX_ENOTTY,
[ETXTBSY] = -26, [ETXTBSY] = -LINUX_ETXTBSY,
[EFBIG] = -27, [EFBIG] = -LINUX_EFBIG,
[ENOSPC] = -28, [ENOSPC] = -LINUX_ENOSPC,
[ESPIPE] = -29, [ESPIPE] = -LINUX_ESPIPE,
/* [30, 39] */ /* [30, 39] */
[EROFS] = -30, [EROFS] = -LINUX_EROFS,
[EMLINK] = -31, [EMLINK] = -LINUX_EMLINK,
[EPIPE] = -32, [EPIPE] = -LINUX_EPIPE,
[EDOM] = -33, [EDOM] = -LINUX_EDOM,
[ERANGE] = -34, [ERANGE] = -LINUX_ERANGE,
[EAGAIN] = -11, [EAGAIN] = -LINUX_EAGAIN,
[EINPROGRESS] = -115, [EINPROGRESS] = -LINUX_EINPROGRESS,
[EALREADY] = -114, [EALREADY] = -LINUX_EALREADY,
[ENOTSOCK] = -88, [ENOTSOCK] = -LINUX_ENOTSOCK,
[EDESTADDRREQ] = -89, [EDESTADDRREQ] = -LINUX_EDESTADDRREQ,
/* [40, 49] */ /* [40, 49] */
[EMSGSIZE] = -90, [EMSGSIZE] = -LINUX_EMSGSIZE,
[EPROTOTYPE] = -91, [EPROTOTYPE] = -LINUX_EPROTOTYPE,
[ENOPROTOOPT] = -92, [ENOPROTOOPT] = -LINUX_ENOPROTOOPT,
[EPROTONOSUPPORT] = -93, [EPROTONOSUPPORT] = -LINUX_EPROTONOTSUPPORT,
[ESOCKTNOSUPPORT] = -94, [ESOCKTNOSUPPORT] = -LINUX_ESOCKNOTSUPPORT,
[EOPNOTSUPP] = -95, [EOPNOTSUPP] = -LINUX_EOPNOTSUPPORT,
[EPFNOSUPPORT] = -96, [EPFNOSUPPORT] = -LINUX_EPFNOTSUPPORT,
[EAFNOSUPPORT] = -97, [EAFNOSUPPORT] = -LINUX_EAFNOTSUPPORT,
[EADDRINUSE] = -98, [EADDRINUSE] = -LINUX_EADDRINUSE,
[EADDRNOTAVAIL] = -99, [EADDRNOTAVAIL] = -LINUX_EADDRNOTAVAIL,
/* [50, 59] */ /* [50, 59] */
[ENETDOWN] = -100, [ENETDOWN] = -LINUX_ENETDOWN,
[ENETUNREACH] = -101, [ENETUNREACH] = -LINUX_ENETUNREACH,
[ENETRESET] = -102, [ENETRESET] = -LINUX_ENETRESET,
[ECONNABORTED] = -103, [ECONNABORTED] = -LINUX_ECONNABORTED,
[ECONNRESET] = -104, [ECONNRESET] = -LINUX_ECONNRESET,
[ENOBUFS] = -105, [ENOBUFS] = -LINUX_ENOBUFS,
[EISCONN] = -106, [EISCONN] = -LINUX_EISCONN,
[ENOTCONN] = -107, [ENOTCONN] = -LINUX_ENOTCONN,
[ESHUTDOWN] = -108, [ESHUTDOWN] = -LINUX_ESHUTDOWN,
[ETOOMANYREFS] = -109, [ETOOMANYREFS] = -LINUX_ETOOMANYREFS,
/* [60, 69] */ /* [60, 69] */
[ETIMEDOUT] = -110, [ETIMEDOUT] = -LINUX_ETIMEDOUT,
[ECONNREFUSED] = -111, [ECONNREFUSED] = -LINUX_ECONNREFUSED,
[ELOOP] = -40, [ELOOP] = -LINUX_ELOOP,
[ENAMETOOLONG] = -36, [ENAMETOOLONG] = -LINUX_ENAMETOOLONG,
[EHOSTDOWN] = -112, [EHOSTDOWN] = -LINUX_EHOSTDOWN,
[EHOSTUNREACH] = -113, [EHOSTUNREACH] = -LINUX_EHOSTUNREACH,
[ENOTEMPTY] = -39, [ENOTEMPTY] = -LINUX_ENOTEMPTY,
[EPROCLIM] = -11, [EPROCLIM] = -LINUX_EAGAIN, /* XXX */
[EUSERS] = -87, [EUSERS] = -LINUX_EUSERS,
[EDQUOT] = -122, [EDQUOT] = -LINUX_EDQUOT,
/* [70, 79] */ /* [70, 79] */
[ESTALE] = -116, [ESTALE] = -LINUX_ESTALE,
[EREMOTE] = -66, [EREMOTE] = -LINUX_EREMOTE,
[EBADRPC] = -6, /* EBADRPC -> ENXIO */ [EBADRPC] = -LINUX_ENXIO, /* XXX */
[ERPCMISMATCH] = -6, /* ERPCMISMATCH -> ENXIO */ [ERPCMISMATCH] = -LINUX_ENXIO, /* XXX */
[EPROGUNAVAIL] = -6, /* EPROGUNAVAIL -> ENXIO */ [EPROGUNAVAIL] = -LINUX_ENXIO, /* XXX */
[EPROGMISMATCH] = -6, /* EPROGMISMATCH -> ENXIO */ [EPROGMISMATCH] = -LINUX_ENXIO, /* XXX */
[EPROCUNAVAIL] = -6, /* EPROCUNAVAIL -> ENXIO */ [EPROCUNAVAIL] = -LINUX_ENXIO, /* XXX */
[ENOLCK] = -37, [ENOLCK] = -LINUX_ENOLCK,
[ENOSYS] = -38, [ENOSYS] = -LINUX_ENOSYS,
[EFTYPE] = -9, [EFTYPE] = -LINUX_EBADF, /* XXX */
/* [80, 89] */ /* [80, 89] */
[EAUTH] = -6, /* EAUTH -> ENXIO */ [EAUTH] = -LINUX_ENXIO, /* XXX */
[ENEEDAUTH] = -6, /* ENEEDAUTH -> ENXIO */ [ENEEDAUTH] = -LINUX_ENXIO, /* XXX */
[EIDRM] = -43, [EIDRM] = -LINUX_EIDRM,
[ENOMSG] = -42, [ENOMSG] = -LINUX_ENOMSG,
[EOVERFLOW] = -75, [EOVERFLOW] = -LINUX_EOVERFLOW,
[ECANCELED] = -125, [ECANCELED] = -LINUX_ECANCELED,
[EILSEQ] = -84, [EILSEQ] = -LINUX_EILSEQ,
[ENOATTR] = -61, [ENOATTR] = -LINUX_ENODATA, /* XXX */
[EDOOFUS] = -22, /* EDOOFUS -> EINVAL */ [EDOOFUS] = -LINUX_EINVAL, /* XXX */
[EBADMSG] = -74, [EBADMSG] = -LINUX_EBADMSG,
/* [90, 99] */ /* [90, 99] */
[EMULTIHOP] = -72, [EMULTIHOP] = -LINUX_EMULTIHOP,
[ENOLINK] = -67, [ENOLINK] = -LINUX_ENOLINK,
[EPROTO] = -71, [EPROTO] = -LINUX_EPROTO,
[ENOTCAPABLE] = -1, /* ENOTCAPABLE -> EPERM */ [ENOTCAPABLE] = -LINUX_EPERM, /* XXX */
[ECAPMODE] = -1, /* ECAPMODE -> EPERM */ [ECAPMODE] = -LINUX_EPERM, /* XXX */
[ENOTRECOVERABLE] = -131, /* ENOTRECOVERABLE */ [ENOTRECOVERABLE] = -LINUX_ENOTRECOVERABLE,
[EOWNERDEAD] = -130, /* EOWNERDEAD */ [EOWNERDEAD] = -LINUX_EOWNERDEAD,
[EINTEGRITY] = -22, /* EINTEGRITY -> EINVAL */ [EINTEGRITY] = -LINUX_EINVAL, /* XXX */
}; };
_Static_assert(ELAST == 97, _Static_assert(ELAST == 97,