Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/modules/compat_linux32 add support COMPAT_LINUX32 for aa...
details: https://anonhg.NetBSD.org/src/rev/dcd3be41a063
branches: trunk
changeset: 1026440:dcd3be41a063
user: ryo <ryo%NetBSD.org@localhost>
date: Thu Nov 25 03:08:03 2021 +0000
description:
add support COMPAT_LINUX32 for aarch64
diffstat:
distrib/sets/lists/debug/module.ad.aarch64 | 4 +-
distrib/sets/lists/modules/ad.aarch64 | 4 +-
sys/arch/aarch64/aarch64/aarch32_syscall.c | 43 +-
sys/arch/aarch64/aarch64/linux32_syscall.c | 84 +
sys/arch/aarch64/conf/files.aarch64 | 9 +-
sys/compat/linux/arch/aarch64/linux_commons.c | 5 +-
sys/compat/linux/arch/aarch64/linux_machdep.h | 45 +-
sys/compat/linux/common/linux_file.c | 10 +-
sys/compat/linux/common/linux_misc.c | 6 +-
sys/compat/linux/common/linux_misc_notalpha.c | 6 +-
sys/compat/linux/common/linux_oldmmap.c | 8 +-
sys/compat/linux/common/linux_sig_notalpha.c | 9 +-
sys/compat/linux32/arch/Makefile | 4 +-
sys/compat/linux32/arch/aarch64/Makefile | 3 +
sys/compat/linux32/arch/aarch64/files.linux32_aarch64 | 11 +
sys/compat/linux32/arch/aarch64/linux32_errno.h | 39 +
sys/compat/linux32/arch/aarch64/linux32_exec.h | 57 +
sys/compat/linux32/arch/aarch64/linux32_exec_machdep.c | 142 +
sys/compat/linux32/arch/aarch64/linux32_fcntl.h | 42 +
sys/compat/linux32/arch/aarch64/linux32_ioctl.h | 47 +
sys/compat/linux32/arch/aarch64/linux32_machdep.c | 335 +
sys/compat/linux32/arch/aarch64/linux32_machdep.h | 118 +
sys/compat/linux32/arch/aarch64/linux32_missing.c | 60 +
sys/compat/linux32/arch/aarch64/linux32_missing.h | 59 +
sys/compat/linux32/arch/aarch64/linux32_sigcode.S | 129 +
sys/compat/linux32/arch/aarch64/linux32_siginfo.h | 98 +
sys/compat/linux32/arch/aarch64/linux32_signal.h | 94 +
sys/compat/linux32/arch/aarch64/linux32_syscall.h | 783 +
sys/compat/linux32/arch/aarch64/linux32_syscallargs.h | 1597 +++
sys/compat/linux32/arch/aarch64/linux32_syscalls.c | 1070 ++
sys/compat/linux32/arch/aarch64/linux32_sysent.c | 1831 ++++
sys/compat/linux32/arch/aarch64/linux32_systrace_args.c | 6729 +++++++++++++++
sys/compat/linux32/arch/aarch64/linux32_termios.h | 240 +
sys/compat/linux32/arch/aarch64/linux32_types.h | 99 +
sys/compat/linux32/arch/aarch64/syscalls.conf | 17 +
sys/compat/linux32/arch/aarch64/syscalls.master | 775 +
sys/compat/linux32/common/linux32_errno.h | 8 +-
sys/compat/linux32/common/linux32_exec.h | 8 +-
sys/compat/linux32/common/linux32_exec_elf32.c | 6 +-
sys/compat/linux32/common/linux32_ioctl.h | 8 +-
sys/compat/linux32/common/linux32_machdep.h | 6 +-
sys/compat/linux32/common/linux32_misc.c | 7 +-
sys/compat/linux32/common/linux32_siginfo.h | 8 +-
sys/compat/linux32/common/linux32_signal.h | 8 +-
sys/compat/linux32/common/linux32_sysinfo.c | 5 +-
sys/compat/linux32/common/linux32_termios.h | 8 +-
sys/compat/linux32/common/linux32_types.h | 8 +-
sys/compat/linux32/common/linux32_unistd.c | 7 +-
sys/compat/linux32/linux32_syscall.h | 6 +-
sys/compat/linux32/linux32_syscallargs.h | 6 +-
sys/compat/linux32/linux32_syscalls.c | 8 +-
sys/compat/linux32/linux32_systrace_args.c | 8 +-
sys/modules/Makefile | 3 +-
sys/modules/compat_linux32/Makefile | 14 +-
54 files changed, 14667 insertions(+), 77 deletions(-)
diffs (truncated from 15425 to 300 lines):
diff -r bc2c93e77465 -r dcd3be41a063 distrib/sets/lists/debug/module.ad.aarch64
--- a/distrib/sets/lists/debug/module.ad.aarch64 Thu Nov 25 02:48:00 2021 +0000
+++ b/distrib/sets/lists/debug/module.ad.aarch64 Thu Nov 25 03:08:03 2021 +0000
@@ -1,8 +1,10 @@
-# $NetBSD: module.ad.aarch64,v 1.3 2021/10/09 07:01:34 ryo Exp $
+# $NetBSD: module.ad.aarch64,v 1.4 2021/11/25 03:08:03 ryo Exp $
./usr/libdata/debug/@MODULEDIR@/bpfjit modules-base-kernel kmod,sljit,debug
./usr/libdata/debug/@MODULEDIR@/bpfjit/bpfjit.kmod.debug modules-base-kernel kmod,sljit,debug
./usr/libdata/debug/@MODULEDIR@/compat_linux modules-base-kernel kmod,debug
./usr/libdata/debug/@MODULEDIR@/compat_linux/compat_linux.kmod.debug modules-base-kernel kmod,debug
+./usr/libdata/debug/@MODULEDIR@/compat_linux32 modules-base-kernel kmod,debug
+./usr/libdata/debug/@MODULEDIR@/compat_linux32/compat_linux32.kmod.debug modules-base-kernel kmod,debug
./usr/libdata/debug/@MODULEDIR@/compat_netbsd32 modules-base-kernel kmod,debug
./usr/libdata/debug/@MODULEDIR@/compat_netbsd32/compat_netbsd32.kmod.debug modules-base-kernel kmod,debug
./usr/libdata/debug/@MODULEDIR@/compat_netbsd32_09 modules-base-kernel kmod,debug
diff -r bc2c93e77465 -r dcd3be41a063 distrib/sets/lists/modules/ad.aarch64
--- a/distrib/sets/lists/modules/ad.aarch64 Thu Nov 25 02:48:00 2021 +0000
+++ b/distrib/sets/lists/modules/ad.aarch64 Thu Nov 25 03:08:03 2021 +0000
@@ -1,8 +1,10 @@
-# $NetBSD: ad.aarch64,v 1.9 2021/10/09 07:01:34 ryo Exp $
+# $NetBSD: ad.aarch64,v 1.10 2021/11/25 03:08:04 ryo Exp $
./@MODULEDIR@/bpfjit modules-base-kernel kmod,sljit
./@MODULEDIR@/bpfjit/bpfjit.kmod modules-base-kernel kmod,sljit
./@MODULEDIR@/compat_linux modules-base-kernel kmod
./@MODULEDIR@/compat_linux/compat_linux.kmod modules-base-kernel kmod
+./@MODULEDIR@/compat_linux32 modules-base-kernel kmod
+./@MODULEDIR@/compat_linux32/compat_linux32.kmod modules-base-kernel kmod
./@MODULEDIR@/compat_netbsd32 modules-base-kernel kmod
./@MODULEDIR@/compat_netbsd32/compat_netbsd32.kmod modules-base-kernel kmod
./@MODULEDIR@/compat_netbsd32_09 modules-base-kernel kmod
diff -r bc2c93e77465 -r dcd3be41a063 sys/arch/aarch64/aarch64/aarch32_syscall.c
--- a/sys/arch/aarch64/aarch64/aarch32_syscall.c Thu Nov 25 02:48:00 2021 +0000
+++ b/sys/arch/aarch64/aarch64/aarch32_syscall.c Thu Nov 25 03:08:03 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: aarch32_syscall.c,v 1.5 2021/05/15 11:39:20 rin Exp $ */
+/* $NetBSD: aarch32_syscall.c,v 1.6 2021/11/25 03:08:04 ryo Exp $ */
/*
* Copyright (c) 2018 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: aarch32_syscall.c,v 1.5 2021/05/15 11:39:20 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aarch32_syscall.c,v 1.6 2021/11/25 03:08:04 ryo Exp $");
#include <sys/param.h>
#include <sys/ktrace.h>
@@ -71,8 +71,28 @@
curcpu()->ci_data.cpu_nsyscall++;
+ thumbmode = (tf->tf_spsr & SPSR_A32_T) ? true : false;
+#ifdef SYSCALL_CODE_REG
+ /*
+ * mov.w r<SYSCALL_CODE_REG>, #<syscall_no>
+ * svc #<SYSCALL_CODE_REG_SVC>
+ */
+#ifdef SYSCALL_CODE_REG_SVC
+ if ((tf->tf_esr & 0xffff) != SYSCALL_CODE_REG_SVC) {
+ error = EINVAL;
+ goto bad;
+ }
+#endif
+ uint32_t code = tf->tf_reg[SYSCALL_CODE_REG];
+#if (SYSCALL_CODE_REG == 0)
+ int regstart = 1; /* args start from r1 */
+ int nargs_reg = NARGREG - 1; /* number of argument in registers */
+#else
+ int regstart = 0; /* args start from r0 */
+ int nargs_reg = NARGREG; /* number of argument in registers */
+#endif
+#else /* SYSCALL_CODE_REG */
uint32_t code = tf->tf_esr & 0xffff; /* XXX: 16-23bits are omitted */
- thumbmode = (tf->tf_spsr & SPSR_A32_T) ? true : false;
if (thumbmode) {
if (code != 255) {
do_trapsignal(l, SIGILL, ILL_ILLTRP,
@@ -83,13 +103,17 @@
code = tf->tf_reg[0];
tf->tf_reg[0] = tf->tf_reg[12]; /* orig $r0 is saved to $ip */
}
-
+ int regstart = 0; /* args start from r0 */
int nargs_reg = NARGREG; /* number of argument in registers */
- int regstart = 0; /* args start from r0 */
+#endif /* SYSCALL_CODE_REG */
+#ifdef SYSCALL_CODE_REMAP
+ code = SYSCALL_CODE_REMAP(code);
+#endif
code %= EMULNAMEU(SYS_NSYSENT);
callp = p->p_emul->e_sysent + code;
+#ifndef SYSCALL_NO_INDIRECT
if (__predict_false(callp->sy_flags & SYCALL_INDIRECT)) {
int off = 1;
#ifdef NETBSD32_SYS_netbsd32____syscall /* XXX ugly: apply only for NETBSD32 */
@@ -117,6 +141,7 @@
goto bad;
}
}
+#endif /* SYSCALL_NO_INDIRECT */
/* number of argument to fetch from sp */
KASSERT(callp->sy_narg <= EMULNAMEU(SYS_MAXSYSARGS));
@@ -133,8 +158,8 @@
goto bad;
}
- rval[0] = rval[1] = 0;
-
+ rval[0] = 0;
+ rval[1] = tf->tf_reg[1];
#if 0
error = sy_invoke(callp, l, args32buf.a32, rval, code);
#else
@@ -171,7 +196,9 @@
if (__predict_true(error == 0)) {
tf->tf_reg[0] = rval[0];
+#ifndef SYSCALL_NO_RVAL1
tf->tf_reg[1] = rval[1];
+#endif
tf->tf_spsr &= ~NZCV_C;
} else {
switch (error) {
@@ -190,6 +217,8 @@
#ifndef __HAVE_MINIMAL_EMUL
if (p->p_emul->e_errno)
error = p->p_emul->e_errno[error];
+#elif defined(SYSCALL_EMUL_ERRNO)
+ error = SYSCALL_EMUL_ERRNO(error);
#endif
tf->tf_reg[0] = error;
tf->tf_spsr |= NZCV_C;
diff -r bc2c93e77465 -r dcd3be41a063 sys/arch/aarch64/aarch64/linux32_syscall.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/aarch64/aarch64/linux32_syscall.c Thu Nov 25 03:08:03 2021 +0000
@@ -0,0 +1,84 @@
+/* $NetBSD: linux32_syscall.c,v 1.1 2021/11/25 03:08:04 ryo Exp $ */
+
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Ryo Shimizu.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: linux32_syscall.c,v 1.1 2021/11/25 03:08:04 ryo Exp $");
+
+#if defined(_KERNEL_OPT)
+#include "opt_compat_linux32.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/types.h>
+
+#include <compat/linux32/linux32_syscall.h>
+#include <compat/linux32/common/linux32_errno.h>
+
+#define EMULNAME(x) __CONCAT(linux32_,x)
+#define EMULNAMEU(x) __CONCAT(LINUX32_,x)
+
+/*
+ * syscall.c behavior options
+ */
+
+/*
+ * EABI linux/arm always uses indirect syscall, and code of 'svc #<code>' must
+ * be zero. The system call number is specified by the r7 register.
+ */
+#define NARGREG 7 /* Seven(all) arguments are passed in r0-r6 */
+#define SYSCALL_CODE_REG 7 /* syscall number is passed in r7 */
+#define SYSCALL_CODE_REG_SVC 0 /* Non-zero is OABI, but not supported */
+#define SYSCALL_NO_INDIRECT
+
+/* used when __HAVE_MINIMAL_EMUL is not defined */
+#define SYSCALL_EMUL_ERRNO(x) native_to_linux32_errno[x]
+
+/* don't update x1 register with rval[1] */
+#define SYSCALL_NO_RVAL1
+
+#define SYSCALL_CODE_REMAP(code) linux32_syscall_code_remap(code)
+
+/*
+ * see also comments in the bottom of
+ * sys/compat/linux32/arch/aarch64/syscalls.master
+ */
+#define LINUX32_EARM_NR_BASE 0x0f0000
+#define LINUX32_SYS_ARMBASE 480
+
+static inline uint32_t
+linux32_syscall_code_remap(uint32_t code)
+{
+ if (code > LINUX32_EARM_NR_BASE)
+ code = code - LINUX32_EARM_NR_BASE + LINUX32_SYS_ARMBASE;
+ return code;
+}
+
+#include "aarch32_syscall.c"
diff -r bc2c93e77465 -r dcd3be41a063 sys/arch/aarch64/conf/files.aarch64
--- a/sys/arch/aarch64/conf/files.aarch64 Thu Nov 25 02:48:00 2021 +0000
+++ b/sys/arch/aarch64/conf/files.aarch64 Thu Nov 25 03:08:03 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.aarch64,v 1.35 2021/10/30 18:44:24 jmcneill Exp $
+# $NetBSD: files.aarch64,v 1.36 2021/11/25 03:08:04 ryo Exp $
defflag opt_cpuoptions.h AARCH64_ALIGNMENT_CHECK
defflag opt_cpuoptions.h AARCH64_EL0_STACK_ALIGNMENT_CHECK
@@ -134,7 +134,12 @@
include "compat/ossaudio/files.ossaudio"
include "compat/linux/files.linux"
include "compat/linux/arch/aarch64/files.linux_aarch64"
-file arch/aarch64/aarch64/linux_syscall.c compat_linux
+file arch/aarch64/aarch64/linux_syscall.c compat_linux
+
+# Linux 32 bit compatibility (COMPAT_LINUX32)
+include "compat/linux32/files.linux32"
+include "compat/linux32/arch/aarch64/files.linux32_aarch64"
+file arch/aarch64/aarch64/linux32_syscall.c compat_linux32
# profiling support
file dev/tprof/tprof_armv8.c tprof needs-flag
diff -r bc2c93e77465 -r dcd3be41a063 sys/compat/linux/arch/aarch64/linux_commons.c
--- a/sys/compat/linux/arch/aarch64/linux_commons.c Thu Nov 25 02:48:00 2021 +0000
+++ b/sys/compat/linux/arch/aarch64/linux_commons.c Thu Nov 25 03:08:03 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_commons.c,v 1.2 2021/10/12 08:36:28 andvar Exp $ */
+/* $NetBSD: linux_commons.c,v 1.3 2021/11/25 03:08:04 ryo Exp $ */
/*
* This file includes C files from the common
@@ -13,7 +13,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_commons.c,v 1.2 2021/10/12 08:36:28 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_commons.c,v 1.3 2021/11/25 03:08:04 ryo Exp $");
#if defined(_KERNEL_OPT)
#include "opt_sysv.h"
@@ -34,4 +34,5 @@
#include "../../common/linux_pipe.c"
#include "../../common/linux_file64.c"
#include "../../common/linux_misc_notalpha.c"
+#include "../../common/linux_sig_notalpha.c"
#include "../../common/linux_fadvise64.c"
diff -r bc2c93e77465 -r dcd3be41a063 sys/compat/linux/arch/aarch64/linux_machdep.h
--- a/sys/compat/linux/arch/aarch64/linux_machdep.h Thu Nov 25 02:48:00 2021 +0000
+++ b/sys/compat/linux/arch/aarch64/linux_machdep.h Thu Nov 25 03:08:03 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: linux_machdep.h,v 1.1 2021/09/23 06:56:27 ryo Exp $ */
+/* $NetBSD: linux_machdep.h,v 1.2 2021/11/25 03:08:04 ryo Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -74,6 +74,49 @@
struct linux_ucontext uc;
};
+/*
+ * Not required for COMPAT_LINUX,
+ * but required for COMPAT_LINUX32.
+ */
+struct linux_sys_open_args {
+ syscallarg(const char *) path;
+ syscallarg(int) flags;
+ syscallarg(linux_umode_t) mode;
+};
+int linux_sys_open(struct lwp *, const struct linux_sys_open_args *, register_t *);
+
+struct linux_sys_eventfd_args {
+ syscallarg(unsigned int) initval;
+};
+int linux_sys_eventfd(struct lwp *, const struct linux_sys_eventfd_args *, register_t *);
+
Home |
Main Index |
Thread Index |
Old Index