Source-Changes-HG archive

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

[src/trunk]: src On Darwin, mach_init is the system bootstrap process. It is ...



details:   https://anonhg.NetBSD.org/src/rev/201601433e79
branches:  trunk
changeset: 540786:201601433e79
user:      manu <manu%NetBSD.org@localhost>
date:      Tue Dec 24 12:15:45 2002 +0000

description:
On Darwin, mach_init is the system bootstrap process. It is responsible
for forking the traditional UNIX init(8) and it does the Mach port naming
service. We need mach_init for the naming service, but unfortunately, it
will only act as such if its PID is 1. We introduce a sysctl
(emul.darwin.init_pid) to fool a given process into thinking its PID is 1.
That way we can get mach_init into behaving as the name server.

Typical use:
/sbin/sysctl -w emul.darwin.init_pid=$$ ; exec /emul/darwin/sbin/mach_init

diffstat:

 sbin/sysctl/sysctl.c                   |  33 ++++++++++++-
 sys/compat/darwin/darwin_exec.c        |   8 +-
 sys/compat/darwin/darwin_syscall.h     |   2 +-
 sys/compat/darwin/darwin_syscallargs.h |   8 +--
 sys/compat/darwin/darwin_syscalls.c    |   8 +--
 sys/compat/darwin/darwin_sysctl.c      |  87 ++++++++++++++++++++++++++-------
 sys/compat/darwin/darwin_sysctl.h      |  15 +++++-
 sys/compat/darwin/darwin_sysent.c      |  11 +---
 sys/compat/darwin/syscalls.master      |   8 +--
 sys/sys/sysctl.h                       |   6 +-
 10 files changed, 132 insertions(+), 54 deletions(-)

diffs (truncated from 465 to 300 lines):

diff -r 521427a9e059 -r 201601433e79 sbin/sysctl/sysctl.c
--- a/sbin/sysctl/sysctl.c      Tue Dec 24 12:13:15 2002 +0000
+++ b/sbin/sysctl/sysctl.c      Tue Dec 24 12:15:45 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysctl.c,v 1.61 2002/11/30 03:10:54 lukem Exp $        */
+/*     $NetBSD: sysctl.c,v 1.62 2002/12/24 12:15:46 manu Exp $ */
 
 /*
  * Copyright (c) 1993
@@ -44,7 +44,7 @@
 #if 0
 static char sccsid[] = "@(#)sysctl.c   8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: sysctl.c,v 1.61 2002/11/30 03:10:54 lukem Exp $");
+__RCSID("$NetBSD: sysctl.c,v 1.62 2002/12/24 12:15:46 manu Exp $");
 #endif
 #endif /* not lint */
 
@@ -96,6 +96,7 @@
 
 #include "../../sys/compat/linux/common/linux_exec.h"
 #include "../../sys/compat/irix/irix_sysctl.h"
+#include "../../sys/compat/darwin/darwin_sysctl.h"
 
 #ifdef IPSEC
 #include <net/route.h>
@@ -204,6 +205,7 @@
 
 static int sysctl_linux(char *, char **, int[], int, int *);
 static int sysctl_irix(char *, char **, int[], int, int *);
+static int sysctl_darwin(char *, char **, int[], int, int *);
 static int findname(char *, char *, char **, struct list *);
 static void usage(void);
 
@@ -537,9 +539,15 @@
                case EMUL_IRIX:
                    len = sysctl_irix(string, &bufp, mib, flags, &type);
                    break;
+
                case EMUL_LINUX:
                    len = sysctl_linux(string, &bufp, mib, flags, &type);
                    break;
+
+               case EMUL_DARWIN:
+                   len = sysctl_darwin(string, &bufp, mib, flags, &type);
+                   break;
+
                default:
                    warnx("Illegal emul level value: %d", mib[0]);
                    break;
@@ -1145,6 +1153,27 @@
        return (4);
 }
 
+struct ctlname darwinnames[] = EMUL_DARWIN_NAMES;
+struct list darwinvars = { darwinnames, EMUL_DARWIN_MAXID };
+
+static int
+sysctl_darwin(char *string, char **bufpp, int mib[], int flags, int *typep)
+{
+       struct list *lp = &darwinvars;
+       int indx;
+
+       if (*bufpp == NULL) {
+               listall(string, &darwinvars);
+               return (-1);
+       }
+       if ((indx = findname(string, "third", bufpp, lp)) == -1)
+               return (-1);
+       mib[2] = indx;
+       lp = &darwinvars;
+       *typep = lp->list[indx].ctl_type;
+       return (3);
+}
+
 /*
  * Scan a list of names searching for a particular name.
  */
diff -r 521427a9e059 -r 201601433e79 sys/compat/darwin/darwin_exec.c
--- a/sys/compat/darwin/darwin_exec.c   Tue Dec 24 12:13:15 2002 +0000
+++ b/sys/compat/darwin/darwin_exec.c   Tue Dec 24 12:15:45 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_exec.c,v 1.7 2002/12/07 15:33:03 manu Exp $ */
+/*     $NetBSD: darwin_exec.c,v 1.8 2002/12/24 12:15:45 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.7 2002/12/07 15:33:03 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.8 2002/12/24 12:15:45 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -45,6 +45,7 @@
 #include <sys/exec.h>
 #include <sys/malloc.h>
 #include <sys/syscall.h>
+#include <sys/sysctl.h>
 #include <sys/exec_macho.h>
 
 #include <uvm/uvm_extern.h>
@@ -56,6 +57,7 @@
 #include <compat/darwin/darwin_exec.h>
 #include <compat/darwin/darwin_signal.h>
 #include <compat/darwin/darwin_syscall.h>
+#include <compat/darwin/darwin_sysctl.h>
 
 static void darwin_e_proc_exec(struct proc *, struct exec_package *);
 static void darwin_e_proc_fork(struct proc *, struct proc *);
@@ -101,7 +103,7 @@
 #else
        syscall,
 #endif
-       NULL,
+       darwin_sysctl,
        NULL,
 };
 
diff -r 521427a9e059 -r 201601433e79 sys/compat/darwin/darwin_syscall.h
--- a/sys/compat/darwin/darwin_syscall.h        Tue Dec 24 12:13:15 2002 +0000
+++ b/sys/compat/darwin/darwin_syscall.h        Tue Dec 24 12:15:45 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: darwin_syscall.h,v 1.14 2002/12/08 21:53:57 manu Exp $ */
+/* $NetBSD: darwin_syscall.h,v 1.15 2002/12/24 12:15:45 manu Exp $ */
 
 /*
  * System call numbers.
diff -r 521427a9e059 -r 201601433e79 sys/compat/darwin/darwin_syscallargs.h
--- a/sys/compat/darwin/darwin_syscallargs.h    Tue Dec 24 12:13:15 2002 +0000
+++ b/sys/compat/darwin/darwin_syscallargs.h    Tue Dec 24 12:15:45 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: darwin_syscallargs.h,v 1.14 2002/12/08 21:53:58 manu Exp $ */
+/* $NetBSD: darwin_syscallargs.h,v 1.15 2002/12/24 12:15:45 manu Exp $ */
 
 /*
  * System call argument lists.
@@ -248,11 +248,7 @@
 int    sys_obreak(struct proc *, void *, register_t *);
 int    sys_getfsstat(struct proc *, void *, register_t *);
 int    sys_lseek(struct proc *, void *, register_t *);
-#ifdef COMPAT_43
-int    sys_getpid_with_ppid(struct proc *, void *, register_t *);
-#else
-int    sys_getpid(struct proc *, void *, register_t *);
-#endif
+int    darwin_sys_getpid(struct proc *, void *, register_t *);
 int    bsd_sys_mount(struct proc *, void *, register_t *);
 int    bsd_sys_unmount(struct proc *, void *, register_t *);
 int    sys_setuid(struct proc *, void *, register_t *);
diff -r 521427a9e059 -r 201601433e79 sys/compat/darwin/darwin_syscalls.c
--- a/sys/compat/darwin/darwin_syscalls.c       Tue Dec 24 12:13:15 2002 +0000
+++ b/sys/compat/darwin/darwin_syscalls.c       Tue Dec 24 12:15:45 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: darwin_syscalls.c,v 1.14 2002/12/08 21:53:58 manu Exp $ */
+/* $NetBSD: darwin_syscalls.c,v 1.15 2002/12/24 12:15:46 manu Exp $ */
 
 /*
  * System call names.
@@ -8,7 +8,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_syscalls.c,v 1.14 2002/12/08 21:53:58 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_syscalls.c,v 1.15 2002/12/24 12:15:46 manu Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_ktrace.h"
@@ -52,11 +52,7 @@
        "break",                        /* 17 = break */
        "getfsstat",                    /* 18 = getfsstat */
        "olseek",                       /* 19 = olseek */
-#ifdef COMPAT_43
        "getpid",                       /* 20 = getpid */
-#else
-       "getpid",                       /* 20 = getpid */
-#endif
        "mount",                        /* 21 = mount */
        "unmount",                      /* 22 = unmount */
        "setuid",                       /* 23 = setuid */
diff -r 521427a9e059 -r 201601433e79 sys/compat/darwin/darwin_sysctl.c
--- a/sys/compat/darwin/darwin_sysctl.c Tue Dec 24 12:13:15 2002 +0000
+++ b/sys/compat/darwin/darwin_sysctl.c Tue Dec 24 12:15:45 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_sysctl.c,v 1.4 2002/12/08 00:50:27 manu Exp $ */
+/*     $NetBSD: darwin_sysctl.c,v 1.5 2002/12/24 12:15:46 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_sysctl.c,v 1.4 2002/12/08 00:50:27 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_sysctl.c,v 1.5 2002/12/24 12:15:46 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -55,21 +55,23 @@
 #include <compat/darwin/darwin_sysctl.h>
 #include <compat/darwin/darwin_syscallargs.h>
 
-int darwin_kern_sysctl
-    (int *, u_int, void *, size_t *, void *, size_t, struct proc *);
-int darwin_vm_sysctl
+static pid_t darwin_init_pid;
+
+static int darwin_kern_sysctl
     (int *, u_int, void *, size_t *, void *, size_t, struct proc *);
-int darwin_vfs_sysctl
+static int darwin_vm_sysctl
     (int *, u_int, void *, size_t *, void *, size_t, struct proc *);
-int darwin_net_sysctl
+static int darwin_vfs_sysctl
     (int *, u_int, void *, size_t *, void *, size_t, struct proc *);
-int darwin_debug_sysctl
+static int darwin_net_sysctl
     (int *, u_int, void *, size_t *, void *, size_t, struct proc *);
-int darwin_hw_sysctl
+static int darwin_debug_sysctl
     (int *, u_int, void *, size_t *, void *, size_t, struct proc *);
-int darwin_machdep_sysctl
+static int darwin_hw_sysctl
     (int *, u_int, void *, size_t *, void *, size_t, struct proc *);
-int darwin_user_sysctl
+static int darwin_machdep_sysctl
+    (int *, u_int, void *, size_t *, void *, size_t, struct proc *);
+static int darwin_user_sysctl
     (int *, u_int, void *, size_t *, void *, size_t, struct proc *);
 
 int
@@ -175,7 +177,7 @@
 }
 
 
-int
+static int
 darwin_kern_sysctl(name, nlen, oldp, oldlenp, newp, newlen, p)
        int *name;
        u_int nlen;
@@ -220,7 +222,7 @@
        return 0;
 }
 
-int
+static int
 darwin_vm_sysctl(name, nlen, oldp, oldlenp, newp, newlen, p)
        int *name;
        u_int nlen;
@@ -239,7 +241,7 @@
        return 0;
 }
 
-int
+static int
 darwin_vfs_sysctl(name, nlen, oldp, oldlenp, newp, newlen, p)
        int *name;
        u_int nlen;
@@ -258,7 +260,7 @@
        return 0;
 }
 
-int
+static int
 darwin_net_sysctl(name, nlen, oldp, oldlenp, newp, newlen, p)
        int *name;
        u_int nlen;
@@ -277,7 +279,7 @@
        return 0;
 }
 
-int
+static int
 darwin_debug_sysctl(name, nlen, oldp, oldlenp, newp, newlen, p)
        int *name;
        u_int nlen;
@@ -296,7 +298,7 @@
        return 0;
 }
 
-int
+static int
 darwin_hw_sysctl(name, nlen, oldp, oldlenp, newp, newlen, p)
        int *name;
        u_int nlen;
@@ -322,7 +324,7 @@
        return 0;
 }
 
-int
+static int
 darwin_machdep_sysctl(name, nlen, oldp, oldlenp, newp, newlen, p)
        int *name;
        u_int nlen;
@@ -341,7 +343,7 @@
        return 0;
 }
 



Home | Main Index | Thread Index | Old Index