Index: head/lib/libsysdecode/errno.c =================================================================== --- head/lib/libsysdecode/errno.c (revision 367300) +++ head/lib/libsysdecode/errno.c (revision 367301) @@ -1,191 +1,190 @@ /*- * Copyright (c) 2015 John H. Baldwin * * 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #if defined(__aarch64__) || defined(__amd64__) || defined(__i386__) #include -static #include #endif #include static const int cloudabi_errno_table[] = { [CLOUDABI_E2BIG] = E2BIG, [CLOUDABI_EACCES] = EACCES, [CLOUDABI_EADDRINUSE] = EADDRINUSE, [CLOUDABI_EADDRNOTAVAIL] = EADDRNOTAVAIL, [CLOUDABI_EAFNOSUPPORT] = EAFNOSUPPORT, [CLOUDABI_EAGAIN] = EAGAIN, [CLOUDABI_EALREADY] = EALREADY, [CLOUDABI_EBADF] = EBADF, [CLOUDABI_EBADMSG] = EBADMSG, [CLOUDABI_EBUSY] = EBUSY, [CLOUDABI_ECANCELED] = ECANCELED, [CLOUDABI_ECHILD] = ECHILD, [CLOUDABI_ECONNABORTED] = ECONNABORTED, [CLOUDABI_ECONNREFUSED] = ECONNREFUSED, [CLOUDABI_ECONNRESET] = ECONNRESET, [CLOUDABI_EDEADLK] = EDEADLK, [CLOUDABI_EDESTADDRREQ] = EDESTADDRREQ, [CLOUDABI_EDOM] = EDOM, [CLOUDABI_EDQUOT] = EDQUOT, [CLOUDABI_EEXIST] = EEXIST, [CLOUDABI_EFAULT] = EFAULT, [CLOUDABI_EFBIG] = EFBIG, [CLOUDABI_EHOSTUNREACH] = EHOSTUNREACH, [CLOUDABI_EIDRM] = EIDRM, [CLOUDABI_EILSEQ] = EILSEQ, [CLOUDABI_EINPROGRESS] = EINPROGRESS, [CLOUDABI_EINTR] = EINTR, [CLOUDABI_EINVAL] = EINVAL, [CLOUDABI_EIO] = EIO, [CLOUDABI_EISCONN] = EISCONN, [CLOUDABI_EISDIR] = EISDIR, [CLOUDABI_ELOOP] = ELOOP, [CLOUDABI_EMFILE] = EMFILE, [CLOUDABI_EMLINK] = EMLINK, [CLOUDABI_EMSGSIZE] = EMSGSIZE, [CLOUDABI_EMULTIHOP] = EMULTIHOP, [CLOUDABI_ENAMETOOLONG] = ENAMETOOLONG, [CLOUDABI_ENETDOWN] = ENETDOWN, [CLOUDABI_ENETRESET] = ENETRESET, [CLOUDABI_ENETUNREACH] = ENETUNREACH, [CLOUDABI_ENFILE] = ENFILE, [CLOUDABI_ENOBUFS] = ENOBUFS, [CLOUDABI_ENODEV] = ENODEV, [CLOUDABI_ENOENT] = ENOENT, [CLOUDABI_ENOEXEC] = ENOEXEC, [CLOUDABI_ENOLCK] = ENOLCK, [CLOUDABI_ENOLINK] = ENOLINK, [CLOUDABI_ENOMEM] = ENOMEM, [CLOUDABI_ENOMSG] = ENOMSG, [CLOUDABI_ENOPROTOOPT] = ENOPROTOOPT, [CLOUDABI_ENOSPC] = ENOSPC, [CLOUDABI_ENOSYS] = ENOSYS, [CLOUDABI_ENOTCONN] = ENOTCONN, [CLOUDABI_ENOTDIR] = ENOTDIR, [CLOUDABI_ENOTEMPTY] = ENOTEMPTY, [CLOUDABI_ENOTRECOVERABLE] = ENOTRECOVERABLE, [CLOUDABI_ENOTSOCK] = ENOTSOCK, [CLOUDABI_ENOTSUP] = ENOTSUP, [CLOUDABI_ENOTTY] = ENOTTY, [CLOUDABI_ENXIO] = ENXIO, [CLOUDABI_EOVERFLOW] = EOVERFLOW, [CLOUDABI_EOWNERDEAD] = EOWNERDEAD, [CLOUDABI_EPERM] = EPERM, [CLOUDABI_EPIPE] = EPIPE, [CLOUDABI_EPROTO] = EPROTO, [CLOUDABI_EPROTONOSUPPORT] = EPROTONOSUPPORT, [CLOUDABI_EPROTOTYPE] = EPROTOTYPE, [CLOUDABI_ERANGE] = ERANGE, [CLOUDABI_EROFS] = EROFS, [CLOUDABI_ESPIPE] = ESPIPE, [CLOUDABI_ESRCH] = ESRCH, [CLOUDABI_ESTALE] = ESTALE, [CLOUDABI_ETIMEDOUT] = ETIMEDOUT, [CLOUDABI_ETXTBSY] = ETXTBSY, [CLOUDABI_EXDEV] = EXDEV, [CLOUDABI_ENOTCAPABLE] = ENOTCAPABLE, }; int sysdecode_abi_to_freebsd_errno(enum sysdecode_abi abi, int error) { switch (abi) { case SYSDECODE_ABI_FREEBSD: case SYSDECODE_ABI_FREEBSD32: return (error); #if defined(__aarch64__) || defined(__amd64__) || defined(__i386__) case SYSDECODE_ABI_LINUX: case SYSDECODE_ABI_LINUX32: { unsigned int i; /* * This is imprecise since it returns the first * matching errno. */ for (i = 0; i < nitems(linux_errtbl); i++) { if (error == linux_errtbl[i]) return (i); } break; } #endif case SYSDECODE_ABI_CLOUDABI32: case SYSDECODE_ABI_CLOUDABI64: if (error >= 0 && (unsigned int)error < nitems(cloudabi_errno_table)) return (cloudabi_errno_table[error]); break; default: break; } return (INT_MAX); } int sysdecode_freebsd_to_abi_errno(enum sysdecode_abi abi, int error) { switch (abi) { case SYSDECODE_ABI_FREEBSD: case SYSDECODE_ABI_FREEBSD32: return (error); #if defined(__aarch64__) || defined(__amd64__) || defined(__i386__) case SYSDECODE_ABI_LINUX: case SYSDECODE_ABI_LINUX32: if (error >= 0 && error <= ELAST) return (linux_errtbl[error]); break; #endif case SYSDECODE_ABI_CLOUDABI32: case SYSDECODE_ABI_CLOUDABI64: { unsigned int i; for (i = 0; i < nitems(cloudabi_errno_table); i++) { if (error == cloudabi_errno_table[i]) return (i); } break; } default: break; } return (INT_MAX); } Index: head/sys/compat/linux/linux_emul.h =================================================================== --- head/sys/compat/linux/linux_emul.h (revision 367300) +++ head/sys/compat/linux/linux_emul.h (revision 367301) @@ -1,85 +1,83 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 2006 Roman Divacky * Copyright (c) 2013 Dmitry Chagin * All rights reserved. * * 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_EMUL_H_ #define _LINUX_EMUL_H_ struct image_params; /* * modeled after similar structure in NetBSD * this will be extended as we need more functionality */ struct linux_emuldata { int *child_set_tid; /* in clone(): Child's TID to set on clone */ int *child_clear_tid;/* in clone(): Child's TID to clear on exit */ int flags; /* thread emuldata flags */ int em_tid; /* thread id */ struct linux_robust_list_head *robust_futexes; }; struct linux_emuldata *em_find(struct thread *); int linux_exec_imgact_try(struct image_params *); void linux_proc_init(struct thread *, struct thread *, int); void linux_proc_exit(void *, struct proc *); void linux_schedtail(struct thread *); void linux_proc_exec(void *, struct proc *, struct image_params *); void linux_thread_dtor(void *arg __unused, struct thread *); void linux_thread_detach(struct thread *); int linux_common_execve(struct thread *, struct image_args *); /* process emuldata flags */ #define LINUX_XDEPR_REQUEUEOP 0x00000001 /* uses deprecated futex REQUEUE op*/ #define LINUX_XUNSUP_EPOLL 0x00000002 /* unsupported epoll events */ #define LINUX_XUNSUP_FUTEXPIOP 0x00000004 /* uses unsupported pi futex */ struct linux_pemuldata { uint32_t flags; /* process emuldata flags */ struct sx pem_sx; /* lock for this struct */ void *epoll; /* epoll data */ uint32_t persona; /* process execution domain */ uint32_t ptrace_flags; /* used by ptrace(2) */ }; #define LINUX_PEM_XLOCK(p) sx_xlock(&(p)->pem_sx) #define LINUX_PEM_XUNLOCK(p) sx_xunlock(&(p)->pem_sx) #define LINUX_PEM_SLOCK(p) sx_slock(&(p)->pem_sx) #define LINUX_PEM_SUNLOCK(p) sx_sunlock(&(p)->pem_sx) struct linux_pemuldata *pem_find(struct proc *); -extern const int linux_errtbl[]; - #endif /* !_LINUX_EMUL_H_ */ Index: head/sys/compat/linux/linux_errno.inc =================================================================== --- head/sys/compat/linux/linux_errno.inc (revision 367300) +++ head/sys/compat/linux/linux_errno.inc (revision 367301) @@ -1,162 +1,162 @@ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD * * Copyright (c) 1994-1996 Søren Schmidt * All rights reserved. * * 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$ */ /* * Linux syscalls return negative errno's, we do positive and map them * Reference: * FreeBSD: src/sys/sys/errno.h * Linux: include/uapi/asm-generic/errno-base.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] = { +static const int linux_errtbl[ELAST + 1] = { /* [0, 9] */ [0] = -0, [EPERM] = -LINUX_EPERM, [ENOENT] = -LINUX_ENOENT, [ESRCH] = -LINUX_ESRCH, [EINTR] = -LINUX_EINTR, [EIO] = -LINUX_EIO, [ENXIO] = -LINUX_ENXIO, [E2BIG] = -LINUX_E2BIG, [ENOEXEC] = -LINUX_ENOEXEC, [EBADF] = -LINUX_EBADF, /* [10, 19] */ [ECHILD] = -LINUX_ECHILD, [EDEADLK] = -LINUX_EDEADLK, [ENOMEM] = -LINUX_ENOMEM, [EACCES] = -LINUX_EACCES, [EFAULT] = -LINUX_EFAULT, [ENOTBLK] = -LINUX_ENOTBLK, [EBUSY] = -LINUX_EBUSY, [EEXIST] = -LINUX_EEXIST, [EXDEV] = -LINUX_EXDEV, [ENODEV] = -LINUX_ENODEV, /* [20, 29] */ [ENOTDIR] = -LINUX_ENOTDIR, [EISDIR] = -LINUX_EISDIR, [EINVAL] = -LINUX_EINVAL, [ENFILE] = -LINUX_ENFILE, [EMFILE] = -LINUX_EMFILE, [ENOTTY] = -LINUX_ENOTTY, [ETXTBSY] = -LINUX_ETXTBSY, [EFBIG] = -LINUX_EFBIG, [ENOSPC] = -LINUX_ENOSPC, [ESPIPE] = -LINUX_ESPIPE, /* [30, 39] */ [EROFS] = -LINUX_EROFS, [EMLINK] = -LINUX_EMLINK, [EPIPE] = -LINUX_EPIPE, [EDOM] = -LINUX_EDOM, [ERANGE] = -LINUX_ERANGE, [EAGAIN] = -LINUX_EAGAIN, [EINPROGRESS] = -LINUX_EINPROGRESS, [EALREADY] = -LINUX_EALREADY, [ENOTSOCK] = -LINUX_ENOTSOCK, [EDESTADDRREQ] = -LINUX_EDESTADDRREQ, /* [40, 49] */ [EMSGSIZE] = -LINUX_EMSGSIZE, [EPROTOTYPE] = -LINUX_EPROTOTYPE, [ENOPROTOOPT] = -LINUX_ENOPROTOOPT, [EPROTONOSUPPORT] = -LINUX_EPROTONOTSUPPORT, [ESOCKTNOSUPPORT] = -LINUX_ESOCKNOTSUPPORT, [EOPNOTSUPP] = -LINUX_EOPNOTSUPPORT, [EPFNOSUPPORT] = -LINUX_EPFNOTSUPPORT, [EAFNOSUPPORT] = -LINUX_EAFNOTSUPPORT, [EADDRINUSE] = -LINUX_EADDRINUSE, [EADDRNOTAVAIL] = -LINUX_EADDRNOTAVAIL, /* [50, 59] */ [ENETDOWN] = -LINUX_ENETDOWN, [ENETUNREACH] = -LINUX_ENETUNREACH, [ENETRESET] = -LINUX_ENETRESET, [ECONNABORTED] = -LINUX_ECONNABORTED, [ECONNRESET] = -LINUX_ECONNRESET, [ENOBUFS] = -LINUX_ENOBUFS, [EISCONN] = -LINUX_EISCONN, [ENOTCONN] = -LINUX_ENOTCONN, [ESHUTDOWN] = -LINUX_ESHUTDOWN, [ETOOMANYREFS] = -LINUX_ETOOMANYREFS, /* [60, 69] */ [ETIMEDOUT] = -LINUX_ETIMEDOUT, [ECONNREFUSED] = -LINUX_ECONNREFUSED, [ELOOP] = -LINUX_ELOOP, [ENAMETOOLONG] = -LINUX_ENAMETOOLONG, [EHOSTDOWN] = -LINUX_EHOSTDOWN, [EHOSTUNREACH] = -LINUX_EHOSTUNREACH, [ENOTEMPTY] = -LINUX_ENOTEMPTY, [EPROCLIM] = -LINUX_EAGAIN, /* XXX */ [EUSERS] = -LINUX_EUSERS, [EDQUOT] = -LINUX_EDQUOT, /* [70, 79] */ [ESTALE] = -LINUX_ESTALE, [EREMOTE] = -LINUX_EREMOTE, [EBADRPC] = -LINUX_ENXIO, /* XXX */ [ERPCMISMATCH] = -LINUX_ENXIO, /* XXX */ [EPROGUNAVAIL] = -LINUX_ENXIO, /* XXX */ [EPROGMISMATCH] = -LINUX_ENXIO, /* XXX */ [EPROCUNAVAIL] = -LINUX_ENXIO, /* XXX */ [ENOLCK] = -LINUX_ENOLCK, [ENOSYS] = -LINUX_ENOSYS, [EFTYPE] = -LINUX_EBADF, /* XXX */ /* [80, 89] */ [EAUTH] = -LINUX_ENXIO, /* XXX */ [ENEEDAUTH] = -LINUX_ENXIO, /* XXX */ [EIDRM] = -LINUX_EIDRM, [ENOMSG] = -LINUX_ENOMSG, [EOVERFLOW] = -LINUX_EOVERFLOW, [ECANCELED] = -LINUX_ECANCELED, [EILSEQ] = -LINUX_EILSEQ, [ENOATTR] = -LINUX_ENODATA, /* XXX */ [EDOOFUS] = -LINUX_EINVAL, /* XXX */ [EBADMSG] = -LINUX_EBADMSG, /* [90, 99] */ [EMULTIHOP] = -LINUX_EMULTIHOP, [ENOLINK] = -LINUX_ENOLINK, [EPROTO] = -LINUX_EPROTO, [ENOTCAPABLE] = -LINUX_EPERM, /* XXX */ [ECAPMODE] = -LINUX_EPERM, /* XXX */ [ENOTRECOVERABLE] = -LINUX_ENOTRECOVERABLE, [EOWNERDEAD] = -LINUX_EOWNERDEAD, [EINTEGRITY] = -LINUX_EINVAL, /* XXX */ }; _Static_assert(ELAST == 97, "missing errno entries in linux_errtbl"); Index: head/sys/modules/linux_common/Makefile =================================================================== --- head/sys/modules/linux_common/Makefile (revision 367300) +++ head/sys/modules/linux_common/Makefile (revision 367301) @@ -1,22 +1,21 @@ # $FreeBSD$ .PATH: ${SRCTOP}/sys/compat/linux KMOD= linux_common SRCS= linux_common.c linux_mib.c linux_mmap.c linux_util.c linux_emul.c \ linux_errno.c \ linux.c device_if.h vnode_if.h bus_if.h opt_inet6.h EXPORT_SYMS= EXPORT_SYMS+= linux_emul_path -EXPORT_SYMS+= linux_errtbl EXPORT_SYMS+= linux_ioctl_register_handler EXPORT_SYMS+= linux_ioctl_unregister_handler EXPORT_SYMS+= linux_get_osname EXPORT_SYMS+= linux_get_osrelease .if !defined(KERNBUILDDIR) .warning Building Linuxulator outside of a kernel does not make sense .endif .include