Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys First work on COMPAT_LINUX/amd64



details:   https://anonhg.NetBSD.org/src/rev/eda211ea993d
branches:  trunk
changeset: 580680:eda211ea993d
user:      manu <manu%NetBSD.org@localhost>
date:      Tue May 03 16:26:27 2005 +0000

description:
First work on COMPAT_LINUX/amd64
Process startup and dynamiclinking work, but processes hang due to
Linux arch_prctl(2) not being really supported yet.

diffstat:

 sys/arch/amd64/amd64/linux_sigcode.S             |    48 +
 sys/arch/amd64/amd64/linux_syscall.c             |    55 +
 sys/arch/amd64/amd64/linux_trap.c                |    47 +
 sys/arch/amd64/amd64/syscall.c                   |   107 +-
 sys/compat/linux/arch/amd64/Makefile             |     4 +
 sys/compat/linux/arch/amd64/files.linux_amd64    |     9 +
 sys/compat/linux/arch/amd64/linux_commons.c      |    37 +
 sys/compat/linux/arch/amd64/linux_errno.h        |   135 ++
 sys/compat/linux/arch/amd64/linux_exec.h         |    68 +
 sys/compat/linux/arch/amd64/linux_exec_machdep.c |   257 +++++
 sys/compat/linux/arch/amd64/linux_fcntl.h        |    64 +
 sys/compat/linux/arch/amd64/linux_ioctl.h        |    48 +
 sys/compat/linux/arch/amd64/linux_machdep.c      |   505 ++++++++++
 sys/compat/linux/arch/amd64/linux_machdep.h      |   110 ++
 sys/compat/linux/arch/amd64/linux_mmap.h         |    45 +
 sys/compat/linux/arch/amd64/linux_prctl.h        |    42 +
 sys/compat/linux/arch/amd64/linux_siginfo.h      |    86 +
 sys/compat/linux/arch/amd64/linux_signal.h       |   130 ++
 sys/compat/linux/arch/amd64/linux_socket.h       |    60 +
 sys/compat/linux/arch/amd64/linux_syscall.h      |   470 +++++++++
 sys/compat/linux/arch/amd64/linux_syscallargs.h  |   851 +++++++++++++++++
 sys/compat/linux/arch/amd64/linux_syscalls.c     |   271 +++++
 sys/compat/linux/arch/amd64/linux_sysent.c       |  1058 ++++++++++++++++++++++
 sys/compat/linux/arch/amd64/linux_termios.h      |   208 ++++
 sys/compat/linux/arch/amd64/linux_types.h        |    92 +
 sys/compat/linux/arch/amd64/syscalls.conf        |    15 +
 sys/compat/linux/arch/amd64/syscalls.master      |   380 +++++++
 sys/compat/linux/common/linux_errno.h            |     4 +-
 sys/compat/linux/common/linux_exec.h             |     5 +-
 sys/compat/linux/common/linux_exec_elf32.c       |     7 +-
 sys/compat/linux/common/linux_fcntl.h            |     4 +-
 sys/compat/linux/common/linux_file.c             |    21 +-
 sys/compat/linux/common/linux_file64.c           |     8 +-
 sys/compat/linux/common/linux_ioctl.h            |     4 +-
 sys/compat/linux/common/linux_ipccall.h          |     6 +-
 sys/compat/linux/common/linux_machdep.h          |     4 +-
 sys/compat/linux/common/linux_misc.c             |    17 +-
 sys/compat/linux/common/linux_misc.h             |     6 +-
 sys/compat/linux/common/linux_misc_notalpha.c    |    16 +-
 sys/compat/linux/common/linux_mmap.h             |     4 +-
 sys/compat/linux/common/linux_prctl.h            |    44 +
 sys/compat/linux/common/linux_sig_notalpha.c     |     8 +-
 sys/compat/linux/common/linux_sigaction.c        |     8 +-
 sys/compat/linux/common/linux_siginfo.h          |     4 +-
 sys/compat/linux/common/linux_signal.c           |    13 +-
 sys/compat/linux/common/linux_signal.h           |     9 +-
 sys/compat/linux/common/linux_socket.c           |     6 +-
 sys/compat/linux/common/linux_socket.h           |     4 +-
 sys/compat/linux/common/linux_socketcall.c       |     6 +-
 sys/compat/linux/common/linux_socketcall.h       |     4 +-
 sys/compat/linux/common/linux_termios.h          |     4 +-
 sys/compat/linux/common/linux_time.c             |     7 +-
 sys/compat/linux/common/linux_types.h            |     4 +-
 sys/kern/exec_conf.c                             |     6 +-
 54 files changed, 5329 insertions(+), 106 deletions(-)

diffs (truncated from 6327 to 300 lines):

diff -r 51bda9c1d2f2 -r eda211ea993d sys/arch/amd64/amd64/linux_sigcode.S
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amd64/amd64/linux_sigcode.S      Tue May 03 16:26:27 2005 +0000
@@ -0,0 +1,48 @@
+/*     $NetBSD: linux_sigcode.S,v 1.1 2005/05/03 16:26:28 manu Exp $ */
+
+/*-
+ * Copyright (c) 2005 Emmanuel Dreyfus, 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by Emmanuel Dreyfus
+ * 4. The name of the author may not be used to endorse or promote 
+ *    products derived from this software without specific prior written 
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE 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 <machine/asm.h>
+
+/* 
+ * The signal trampoline are not used on Linux/amd64: a
+ * libc provided trampoline is always used.
+ * We just provide the symbol so that the kernel builds.
+ */
+
+/* LINTSTUB: Var: char linux_sigcode[1], linux_esigcode[1]; */
+NENTRY(linux_sigcode)
+
+/* LINTSTUB: Var: char linux_rt_sigcode[1]; */
+NENTRY(linux_rt_sigcode)
+       .globl  _C_LABEL(linux_esigcode)
+_C_LABEL(linux_esigcode):
diff -r 51bda9c1d2f2 -r eda211ea993d sys/arch/amd64/amd64/linux_syscall.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amd64/amd64/linux_syscall.c      Tue May 03 16:26:27 2005 +0000
@@ -0,0 +1,55 @@
+/*     $NetBSD: linux_syscall.c,v 1.1 2005/05/03 16:26:28 manu Exp $ */
+
+/*-
+ * Copyright (c) 2005 Emmanuel Dreyfus, 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by Emmanuel Dreyfus
+ * 4. The name of the author may not be used to endorse or promote 
+ *    products derived from this software without specific prior written 
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE 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 "opt_compat_linux.h"
+#include <sys/cdefs.h>
+
+__KERNEL_RCSID(0, "$NetBSD: linux_syscall.c,v 1.1 2005/05/03 16:26:28 manu Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/signal.h>
+#include <sys/proc.h> 
+ 
+#include <compat/linux/linux_syscall.h>
+#include <compat/linux/common/linux_types.h>
+#include <compat/linux/common/linux_errno.h>
+#include <compat/linux/common/linux_signal.h>
+#include <compat/linux/common/linux_siginfo.h>
+#include <compat/linux/arch/amd64/linux_siginfo.h>
+#include <compat/linux/arch/amd64/linux_machdep.h>
+
+#define EMULNAME(x)     __CONCAT(linux_,x)
+#define EMULNAMEU(x)    __CONCAT(LINUX_,x)
+
+#include "syscall.c"
diff -r 51bda9c1d2f2 -r eda211ea993d sys/arch/amd64/amd64/linux_trap.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amd64/amd64/linux_trap.c Tue May 03 16:26:27 2005 +0000
@@ -0,0 +1,47 @@
+/*     $NetBSD: linux_trap.c,v 1.1 2005/05/03 16:26:28 manu Exp $ */
+
+/*-
+ * Copyright (c) 2005 Emmanuel Dreyfus, 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by Emmanuel Dreyfus
+ * 4. The name of the author may not be used to endorse or promote 
+ *    products derived from this software without specific prior written 
+ *    permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE 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 <sys/types.h>
+#include <sys/systm.h>
+#include <sys/param.h>
+#include <sys/lwp.h>
+#include <sys/proc.h>
+#include <sys/siginfo.h> 
+
+#include <compat/linux/common/linux_exec.h>
+
+void
+linux_trapsignal(struct lwp *l, const ksiginfo_t *ksi)
+{
+       printf("linux_trapsignal()\n");
+}
diff -r 51bda9c1d2f2 -r eda211ea993d sys/arch/amd64/amd64/syscall.c
--- a/sys/arch/amd64/amd64/syscall.c    Tue May 03 14:51:42 2005 +0000
+++ b/sys/arch/amd64/amd64/syscall.c    Tue May 03 16:26:27 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: syscall.c,v 1.5 2003/10/31 03:28:12 simonb Exp $       */
+/*     $NetBSD: syscall.c,v 1.6 2005/05/03 16:26:28 manu Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.5 2003/10/31 03:28:12 simonb Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.6 2005/05/03 16:26:28 manu Exp $");
 
 #include "opt_syscall_debug.h"
 #include "opt_ktrace.h"
@@ -56,7 +56,6 @@
 #ifdef SYSTRACE
 #include <sys/systrace.h>
 #endif
-#include <sys/syscall.h>
 
 #include <uvm/uvm_extern.h>
 
@@ -64,27 +63,61 @@
 #include <machine/psl.h>
 #include <machine/userret.h>
 
-void syscall_intern __P((struct proc *));
-void syscall_plain __P((struct trapframe *));
-void syscall_fancy __P((struct trapframe *));
+#ifndef EMULNAME
+#include <sys/syscall.h>
+ 
+#define EMULNAME(x)     (x)
+#define EMULNAMEU(x)    (x)
+#include <sys/syscall.h>
 
 void
-syscall_intern(p)
+child_return(arg)
+       void *arg;
+{
+       struct lwp *l = arg;
+       struct trapframe *tf = l->l_md.md_regs;
+#ifdef KTRACE
+       struct proc *p = l->l_proc;
+#endif
+
+       tf->tf_rax = 0;
+       tf->tf_rflags &= ~PSL_C;
+
+       KERNEL_PROC_UNLOCK(l);
+
+       userret(l);
+#ifdef KTRACE
+       if (KTRPOINT(p, KTR_SYSRET)) {
+               KERNEL_PROC_LOCK(l);
+               ktrsysret(p, EMULNAMEU(SYS_fork), 0, 0);
+               KERNEL_PROC_UNLOCK(l);
+       }
+#endif
+}
+#endif /* EMULNAME */
+
+void EMULNAME(syscall_intern) __P((struct proc *));
+void EMULNAME(syscall_plain) __P((struct trapframe *));
+void EMULNAME(syscall_fancy) __P((struct trapframe *));
+
+void
+EMULNAME(syscall_intern)(p) /*
+syscall_intern(p) */
        struct proc *p;
 {
 #ifdef KTRACE
        if (p->p_traceflag & (KTRFAC_SYSCALL | KTRFAC_SYSRET)) {
-               p->p_md.md_syscall = syscall_fancy;
+               p->p_md.md_syscall = EMULNAME(syscall_fancy);
                return;
        }
 #endif
 #ifdef SYSTRACE
        if (ISSET(p->p_flag, P_SYSTRACE)) {
-               p->p_md.md_syscall = syscall_fancy;
+               p->p_md.md_syscall = EMULNAME(syscall_fancy);
                return;
        } 
 #endif
-       p->p_md.md_syscall = syscall_plain;
+       p->p_md.md_syscall = EMULNAME(syscall_plain);
 }
 
 /*
@@ -93,7 +126,8 @@
  * Like trap(), argument is call by reference.
  */
 void
-syscall_plain(frame)
+EMULNAME(syscall_plain)(frame) /*
+syscall_plain(frame) */
        struct trapframe *frame;
 {
        caddr_t params;
@@ -113,9 +147,10 @@
        argoff = 0;
        argp = &args[0];
 
+#ifndef COMPAT_LINUX
        switch (code) {
-       case SYS_syscall:
-       case SYS___syscall:
+       case EMULNAMEU(SYS_syscall):
+       case EMULNAMEU(SYS___syscall):
                /*
                 * Code is first argument, followed by actual args.
                 */
@@ -126,8 +161,9 @@
        default:
                break;
        }
+#endif /* !COMPAT_LINUX */
 
-       code &= (SYS_NSYSENT - 1);
+       code &= (EMULNAMEU(SYS_NSYSENT) - 1);
        callp += code;
 
        argsize = (callp->sy_argsize >> 3) + argoff;
@@ -188,7 +224,11 @@
                break;
        default:
        bad:
+#ifdef COMPAT_LINUX
+               frame->tf_rax = LINUX_SCERR_SIGN error;
+#else
                frame->tf_rax = error;
+#endif



Home | Main Index | Thread Index | Old Index