Source-Changes-HG archive

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

[src/trunk]: src/sys A working fork/vfork implementation. Darwin fork differs...



details:   https://anonhg.NetBSD.org/src/rev/1bd5a3a522b9
branches:  trunk
changeset: 540270:1bd5a3a522b9
user:      manu <manu%NetBSD.org@localhost>
date:      Sun Dec 08 21:53:10 2002 +0000

description:
A working fork/vfork implementation. Darwin fork differs from our fork by
two ways:
- the child gets its pid as retval[0] (userland stub will turn it into a 0),
retval[1] is 1 and it is 0 in the parent.
- in the child, the fork syscall is successful, hence we must skip the next
instruction.

diffstat:

 sys/arch/amigappc/include/darwin_machdep.h  |   3 +
 sys/arch/bebox/include/darwin_machdep.h     |   3 +
 sys/arch/macppc/include/darwin_machdep.h    |   3 +
 sys/arch/mvmeppc/include/darwin_machdep.h   |   3 +
 sys/arch/ofppc/include/darwin_machdep.h     |   3 +
 sys/arch/pmppc/include/darwin_machdep.h     |   3 +
 sys/arch/powerpc/include/darwin_machdep.h   |   4 +-
 sys/arch/powerpc/powerpc/darwin_machdep.c   |  38 ++++++++++-
 sys/arch/prep/include/darwin_machdep.h      |   3 +
 sys/arch/sandpoint/include/darwin_machdep.h |   3 +
 sys/arch/walnut/include/darwin_machdep.h    |   3 +
 sys/compat/darwin/darwin_syscall.h          |   2 +-
 sys/compat/darwin/darwin_syscallargs.h      |   6 +-
 sys/compat/darwin/darwin_syscalls.c         |   4 +-
 sys/compat/darwin/darwin_sysent.c           |   8 +-
 sys/compat/darwin/darwin_thread.c           |  92 +++++++++++++++++++++++++++++
 sys/compat/darwin/files.darwin              |   3 +-
 sys/compat/darwin/syscalls.master           |   6 +-
 18 files changed, 171 insertions(+), 19 deletions(-)

diffs (truncated from 371 to 300 lines):

diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/arch/amigappc/include/darwin_machdep.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/amigappc/include/darwin_machdep.h        Sun Dec 08 21:53:10 2002 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: darwin_machdep.h,v 1.1 2002/12/08 21:53:11 manu Exp $ */
+
+#include <powerpc/darwin_machdep.h>
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/arch/bebox/include/darwin_machdep.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/bebox/include/darwin_machdep.h   Sun Dec 08 21:53:10 2002 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: darwin_machdep.h,v 1.1 2002/12/08 21:53:12 manu Exp $ */
+
+#include <powerpc/darwin_machdep.h>
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/arch/macppc/include/darwin_machdep.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/macppc/include/darwin_machdep.h  Sun Dec 08 21:53:10 2002 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: darwin_machdep.h,v 1.1 2002/12/08 21:53:12 manu Exp $ */
+
+#include <powerpc/darwin_machdep.h>
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/arch/mvmeppc/include/darwin_machdep.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/mvmeppc/include/darwin_machdep.h Sun Dec 08 21:53:10 2002 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: darwin_machdep.h,v 1.1 2002/12/08 21:53:13 manu Exp $ */
+
+#include <powerpc/darwin_machdep.h>
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/arch/ofppc/include/darwin_machdep.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/ofppc/include/darwin_machdep.h   Sun Dec 08 21:53:10 2002 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: darwin_machdep.h,v 1.1 2002/12/08 21:53:13 manu Exp $ */
+
+#include <powerpc/darwin_machdep.h>
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/arch/pmppc/include/darwin_machdep.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/pmppc/include/darwin_machdep.h   Sun Dec 08 21:53:10 2002 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: darwin_machdep.h,v 1.1 2002/12/08 21:53:16 manu Exp $ */
+
+#include <powerpc/darwin_machdep.h>
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/arch/powerpc/include/darwin_machdep.h
--- a/sys/arch/powerpc/include/darwin_machdep.h Sun Dec 08 21:50:36 2002 +0000
+++ b/sys/arch/powerpc/include/darwin_machdep.h Sun Dec 08 21:53:10 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_machdep.h,v 1.1 2002/11/26 23:54:09 manu Exp $ */
+/*     $NetBSD: darwin_machdep.h,v 1.2 2002/12/08 21:53:10 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -39,6 +39,8 @@
 #ifndef        _DARWIN_MACHDEP_H_
 #define        _DARWIN_MACHDEP_H_
 
+void darwin_fork_child_return(void *);
+
 struct darwin_ppc_exception_state {
        unsigned long dar;
        unsigned long dsisr;
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/arch/powerpc/powerpc/darwin_machdep.c
--- a/sys/arch/powerpc/powerpc/darwin_machdep.c Sun Dec 08 21:50:36 2002 +0000
+++ b/sys/arch/powerpc/powerpc/darwin_machdep.c Sun Dec 08 21:53:10 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_machdep.c,v 1.4 2002/12/08 00:50:23 manu Exp $ */
+/*     $NetBSD: darwin_machdep.c,v 1.5 2002/12/08 21:53:11 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_machdep.c,v 1.4 2002/12/08 00:50:23 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_machdep.c,v 1.5 2002/12/08 21:53:11 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -51,8 +51,14 @@
 #include <compat/darwin/darwin_signal.h>
 #include <compat/darwin/darwin_syscallargs.h>
 
-#include <arch/powerpc/include/psl.h>
-#include <arch/powerpc/include/darwin_machdep.h>
+#include <machine/psl.h>
+#include <machine/darwin_machdep.h>
+
+/* 
+ * First argument is in reg 3, duplicated from 
+ * sys/arch/powerpc/powerpc/syscall.c 
+ */
+#define FIRSTARG 3
 
 /*
  * Send a signal to a Darwin process.
@@ -239,3 +245,27 @@
 
        return (EJUSTRETURN);
 }
+
+/*
+ * Set the return value for darwin binaries after a fork(). The userland
+ * libSystem stub expects the child pid to be in retval[0] for the parent
+ * and the child as well. It will perform the required operation to transform 
+ * it in the POSIXly correct value: zero for the child.
+ * We also need to skip the next instruction because the system call
+ * was successful (We also do this in the syscall handler, Darwin 
+ * works that way).
+ */
+void
+darwin_fork_child_return(arg)
+       void *arg;
+{
+       struct proc * const p = arg;
+       struct trapframe * const tf = trapframe(p);
+
+       child_return(arg);
+
+       tf->fixreg[FIRSTARG] = p->p_pid;
+       tf->srr0 +=4;
+
+       return;
+}
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/arch/prep/include/darwin_machdep.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/prep/include/darwin_machdep.h    Sun Dec 08 21:53:10 2002 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: darwin_machdep.h,v 1.1 2002/12/08 21:53:14 manu Exp $ */
+
+#include <powerpc/darwin_machdep.h>
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/arch/sandpoint/include/darwin_machdep.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/sandpoint/include/darwin_machdep.h       Sun Dec 08 21:53:10 2002 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: darwin_machdep.h,v 1.1 2002/12/08 21:53:15 manu Exp $ */
+
+#include <powerpc/darwin_machdep.h>
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/arch/walnut/include/darwin_machdep.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/walnut/include/darwin_machdep.h  Sun Dec 08 21:53:10 2002 +0000
@@ -0,0 +1,3 @@
+/*     $NetBSD: darwin_machdep.h,v 1.1 2002/12/08 21:53:16 manu Exp $ */
+
+#include <powerpc/darwin_machdep.h>
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/compat/darwin/darwin_syscall.h
--- a/sys/compat/darwin/darwin_syscall.h        Sun Dec 08 21:50:36 2002 +0000
+++ b/sys/compat/darwin/darwin_syscall.h        Sun Dec 08 21:53:10 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: darwin_syscall.h,v 1.12 2002/12/08 00:51:24 manu Exp $ */
+/* $NetBSD: darwin_syscall.h,v 1.13 2002/12/08 21:53:17 manu Exp $ */
 
 /*
  * System call numbers.
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/compat/darwin/darwin_syscallargs.h
--- a/sys/compat/darwin/darwin_syscallargs.h    Sun Dec 08 21:50:36 2002 +0000
+++ b/sys/compat/darwin/darwin_syscallargs.h    Sun Dec 08 21:53:10 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: darwin_syscallargs.h,v 1.12 2002/12/08 00:51:25 manu Exp $ */
+/* $NetBSD: darwin_syscallargs.h,v 1.13 2002/12/08 21:53:17 manu Exp $ */
 
 /*
  * System call argument lists.
@@ -231,7 +231,7 @@
  */
 
 int    sys_exit(struct proc *, void *, register_t *);
-int    sys_fork(struct proc *, void *, register_t *);
+int    darwin_sys_fork(struct proc *, void *, register_t *);
 int    sys_read(struct proc *, void *, register_t *);
 int    sys_write(struct proc *, void *, register_t *);
 int    bsd_sys_open(struct proc *, void *, register_t *);
@@ -308,7 +308,7 @@
 int    compat_43_sys_fstat(struct proc *, void *, register_t *);
 int    compat_43_sys_getpagesize(struct proc *, void *, register_t *);
 int    compat_12_sys_msync(struct proc *, void *, register_t *);
-int    sys_vfork(struct proc *, void *, register_t *);
+int    darwin_sys_vfork(struct proc *, void *, register_t *);
 int    sys_sbrk(struct proc *, void *, register_t *);
 int    sys_sstk(struct proc *, void *, register_t *);
 int    sys_mmap(struct proc *, void *, register_t *);
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/compat/darwin/darwin_syscalls.c
--- a/sys/compat/darwin/darwin_syscalls.c       Sun Dec 08 21:50:36 2002 +0000
+++ b/sys/compat/darwin/darwin_syscalls.c       Sun Dec 08 21:53:10 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: darwin_syscalls.c,v 1.12 2002/12/08 00:51:25 manu Exp $ */
+/* $NetBSD: darwin_syscalls.c,v 1.13 2002/12/08 21:53:17 manu Exp $ */
 
 /*
  * System call names.
@@ -8,7 +8,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_syscalls.c,v 1.12 2002/12/08 00:51:25 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_syscalls.c,v 1.13 2002/12/08 21:53:17 manu Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ktrace.h"
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/compat/darwin/darwin_sysent.c
--- a/sys/compat/darwin/darwin_sysent.c Sun Dec 08 21:50:36 2002 +0000
+++ b/sys/compat/darwin/darwin_sysent.c Sun Dec 08 21:53:10 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: darwin_sysent.c,v 1.12 2002/12/08 00:51:26 manu Exp $ */
+/* $NetBSD: darwin_sysent.c,v 1.13 2002/12/08 21:53:18 manu Exp $ */
 
 /*
  * System call switch table.
@@ -8,7 +8,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_sysent.c,v 1.12 2002/12/08 00:51:26 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_sysent.c,v 1.13 2002/12/08 21:53:18 manu Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_nfsserver.h"
@@ -37,7 +37,7 @@
        { 1, s(struct sys_exit_args), 0,
            sys_exit },                         /* 1 = exit */
        { 0, 0, 0,
-           sys_fork },                         /* 2 = fork */
+           darwin_sys_fork },                  /* 2 = fork */
        { 3, s(struct sys_read_args), 0,
            sys_read },                         /* 3 = read */
        { 3, s(struct sys_write_args), 0,
@@ -185,7 +185,7 @@
        { 2, s(struct compat_12_sys_msync_args), 0,
            compat_12_sys_msync },              /* 65 = msync */
        { 0, 0, 0,
-           sys_vfork },                        /* 66 = vfork */
+           darwin_sys_vfork },                 /* 66 = vfork */
        { 0, 0, 0,
            sys_nosys },                        /* 67 = obsolete vread */
        { 0, 0, 0,
diff -r 49dc97dba500 -r 1bd5a3a522b9 sys/compat/darwin/darwin_thread.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/compat/darwin/darwin_thread.c Sun Dec 08 21:53:10 2002 +0000
@@ -0,0 +1,92 @@
+/*     $NetBSD: darwin_thread.c,v 1.1 2002/12/08 21:53:18 manu Exp $ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Emmanuel Dreyfus.
+ *
+ * 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 the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * 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: darwin_thread.c,v 1.1 2002/12/08 21:53:18 manu Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/signal.h>
+#include <sys/mount.h>
+#include <sys/proc.h>
+
+#include <sys/syscallargs.h>
+
+#include <compat/mach/mach_types.h>
+#include <compat/mach/mach_vm.h>
+
+#include <compat/darwin/darwin_signal.h>
+#include <compat/darwin/darwin_syscallargs.h>
+
+#include <machine/darwin_machdep.h>
+
+/* 
+ * darwin_fork_child_return() sets the return values as expected by Darwin
+ * userland: libSystem stub expects the child pid to be in retval[0] for 
+ * the parent as well as the child. 



Home | Main Index | Thread Index | Old Index