Source-Changes-HG archive

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

[src/trunk]: src/sys/compat/mach FIrst attempt at mach ports and rights, whic...



details:   https://anonhg.NetBSD.org/src/rev/2fb91e4b7154
branches:  trunk
changeset: 540460:2fb91e4b7154
user:      manu <manu%NetBSD.org@localhost>
date:      Sun Dec 15 00:40:24 2002 +0000

description:
FIrst attempt at mach ports and rights, which are needed if we ever want
to implement messages between kernel and userland.
While we are there, cleanup some debug messages.

diffstat:

 sys/compat/mach/mach_errno.c     |    5 +-
 sys/compat/mach/mach_exec.c      |   45 +++-
 sys/compat/mach/mach_exec.h      |   18 +-
 sys/compat/mach/mach_host.c      |   17 +-
 sys/compat/mach/mach_message.c   |   37 +++-
 sys/compat/mach/mach_message.h   |   16 +-
 sys/compat/mach/mach_port.c      |  397 ++++++++++++++++++++++++++++++++++++++-
 sys/compat/mach/mach_port.h      |   50 ++++-
 sys/compat/mach/mach_semaphore.c |    8 +-
 sys/compat/mach/mach_task.c      |   43 +++-
 sys/compat/mach/mach_task.h      |    8 +-
 sys/compat/mach/mach_vm.c        |    7 +-
 12 files changed, 604 insertions(+), 47 deletions(-)

diffs (truncated from 1094 to 300 lines):

diff -r ab72e82fbe5d -r 2fb91e4b7154 sys/compat/mach/mach_errno.c
--- a/sys/compat/mach/mach_errno.c      Sat Dec 14 17:52:47 2002 +0000
+++ b/sys/compat/mach/mach_errno.c      Sun Dec 15 00:40:24 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_errno.c,v 1.7 2002/12/09 21:53:28 manu Exp $ */
+/*     $NetBSD: mach_errno.c,v 1.8 2002/12/15 00:40:24 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,11 +37,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_errno.c,v 1.7 2002/12/09 21:53:28 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_errno.c,v 1.8 2002/12/15 00:40:24 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/systm.h>
 #include <sys/null.h>
+#include <sys/queue.h>
 #include <sys/errno.h>
 
 #include <compat/mach/mach_types.h>
diff -r ab72e82fbe5d -r 2fb91e4b7154 sys/compat/mach/mach_exec.c
--- a/sys/compat/mach/mach_exec.c       Sat Dec 14 17:52:47 2002 +0000
+++ b/sys/compat/mach/mach_exec.c       Sun Dec 15 00:40:24 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_exec.c,v 1.14 2002/12/12 23:18:20 manu Exp $       */
+/*     $NetBSD: mach_exec.c,v 1.15 2002/12/15 00:40:25 manu Exp $       */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_exec.c,v 1.14 2002/12/12 23:18:20 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_exec.c,v 1.15 2002/12/15 00:40:25 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -54,12 +54,16 @@
 
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
+#include <compat/mach/mach_port.h>
 #include <compat/mach/mach_semaphore.h>
 #include <compat/mach/mach_exec.h>
 
+static int mach_cold = 1; /* Have we initialized COMPAT_MACH structures? */
+
 static void mach_e_proc_exec(struct proc *, struct exec_package *);
 static void mach_e_proc_fork(struct proc *, struct proc *);
 static void mach_e_proc_exit(struct proc *);
+static void mach_init(void);
 
 extern char sigcode[], esigcode[];
 extern struct sysent sysent[];
@@ -220,6 +224,13 @@
 {
        struct mach_emuldata *med;
 
+       /* 
+        * Initialize various things if needed. 
+        * XXX Not the best place for that. 
+        */
+       if (mach_cold == 1)
+               mach_init();
+
        if (!p->p_emuldata)
                p->p_emuldata = malloc(sizeof(struct mach_emuldata),
                    M_EMULDATA, M_WAITOK | M_ZERO);
@@ -227,9 +238,21 @@
        med = (struct mach_emuldata *)p->p_emuldata;
        med->med_p = 0;
 
-       /* Initialize semaphores if needed. Not the best place for that... */
-       if (mach_semaphore_cold == 1)
-               mach_semaphore_init();
+       LIST_INIT(&med->med_recv);
+       LIST_INIT(&med->med_send);
+       LIST_INIT(&med->med_sendonce);
+       lockinit(&med->med_rlock, PZERO|PCATCH, "mach_port", 0, 0);
+       lockinit(&med->med_slock, PZERO|PCATCH, "mach_port", 0, 0);
+       lockinit(&med->med_solock, PZERO|PCATCH, "mach_port", 0, 0);
+
+       med->med_bootstrap = mach_port_get(NULL);
+       med->med_kernel = mach_port_get(NULL);
+       med->med_host = mach_port_get(NULL);
+
+       /* Make sure they will not be deallocated */
+       med->med_bootstrap->mp_refcount++;
+       med->med_kernel->mp_refcount++;
+       med->med_host->mp_refcount++;
 
        return;
 }
@@ -245,3 +268,15 @@
 
        return;
 }
+
+static void
+mach_init(void)
+{
+       mach_semaphore_init();
+       mach_message_init();
+       mach_port_init();
+
+       mach_cold = 0;
+
+       return;
+}
diff -r ab72e82fbe5d -r 2fb91e4b7154 sys/compat/mach/mach_exec.h
--- a/sys/compat/mach/mach_exec.h       Sat Dec 14 17:52:47 2002 +0000
+++ b/sys/compat/mach/mach_exec.h       Sun Dec 15 00:40:24 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_exec.h,v 1.7 2002/12/12 23:18:20 manu Exp $        */
+/*     $NetBSD: mach_exec.h,v 1.8 2002/12/15 00:40:25 manu Exp $        */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -44,8 +44,20 @@
 #include <compat/mach/mach_types.h>
 
 struct mach_emuldata {
-       mach_cproc_t med_p;
-       int med_thpri;
+       mach_cproc_t med_p;             /* Thread id */
+       int med_thpri;                  /* Saved priority */
+       LIST_HEAD(med_recv,             /* List of receive rights */
+           mach_right) med_recv;
+       LIST_HEAD(med_send,             /* List of send rights */
+           mach_right) med_send;
+       LIST_HEAD(med_sendonce,         /* List of send once rights */
+           mach_right) med_sendonce;
+       struct lock med_rlock;          /* Lock on recv rights list */
+       struct lock med_slock;          /* Lock on send rights list */
+       struct lock med_solock;         /* Lock on send once rights list */
+       struct mach_port *med_bootstrap;/* task bootstrap port */
+       struct mach_port *med_kernel;   /* task kernel port */
+       struct mach_port *med_host;     /* task host port */
 };
 
 int exec_mach_copyargs(struct proc *, struct exec_package *, 
diff -r ab72e82fbe5d -r 2fb91e4b7154 sys/compat/mach/mach_host.c
--- a/sys/compat/mach/mach_host.c       Sat Dec 14 17:52:47 2002 +0000
+++ b/sys/compat/mach/mach_host.c       Sun Dec 15 00:40:24 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_host.c,v 1.14 2002/12/09 21:29:24 manu Exp $ */
+/*     $NetBSD: mach_host.c,v 1.15 2002/12/15 00:40:25 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.14 2002/12/09 21:29:24 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.15 2002/12/15 00:40:25 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/malloc.h>
@@ -85,7 +85,6 @@
                struct mach_host_basic_info *info
                    = (struct mach_host_basic_info *)&rep.rep_data[0];
 
-               DPRINTF(("mach_host_info(BASIC_INFO);\n"));
                rep.rep_msgh.msgh_size = sizeof(*reps) 
                    - sizeof(rep.rep_trailer) + sizeof(*info);
                rep.rep_count = sizeof(*info) / sizeof(mach_integer_t);
@@ -102,7 +101,6 @@
                struct mach_host_priority_info *info
                    = (struct mach_host_priority_info *)&rep.rep_data[0];
 
-               DPRINTF(("mach_host_info(PRIORITY_INFO);\n"));
                rep.rep_msgh.msgh_size = sizeof(*reps) 
                    - sizeof(rep.rep_trailer) + sizeof(*info);
                rep.rep_count = sizeof(*info) / sizeof(mach_integer_t);
@@ -117,9 +115,6 @@
 
        case MACH_HOST_SEMAPHORE_TRAPS:
        case MACH_HOST_MACH_MSG_TRAP:
-               DPRINTF(("mach_host_info(%s);\n",
-                   req.req_flavor == MACH_HOST_SEMAPHORE_TRAPS ?
-                   "SEMAPHORE_TRAPS" : "MACH_MSG_TRAP"));
                reps = (mach_host_info_reply_simple_t *)&rep;
                reps->rep_msgh.msgh_size = 
                    sizeof(*reps) - sizeof(reps->rep_trailer);
@@ -129,8 +124,8 @@
 
        case MACH_HOST_SCHED_INFO:
        case MACH_HOST_RESOURCE_SIZES:
-               DPRINTF(("Unimplemented host_info flavor %d\n", 
-                   req.req_flavor));
+               uprintf("mach_host_info() Unimplemented host_info flavor %d\n", 
+                   req.req_flavor);
        default:
                uprintf("Unknown host_info flavor %d\n", req.req_flavor);
                rep.rep_retval = native_to_mach_errno[EINVAL];
@@ -155,8 +150,6 @@
        if ((error = copyin(msgh, &req, sizeof(req))) != 0)
                return error;
 
-       DPRINTF(("mach_host_page_size();\n"));
-
        bzero(&rep, sizeof(rep));
 
        rep.rep_msgh.msgh_bits =
@@ -184,8 +177,6 @@
        if ((error = copyin(msgh, &req, sizeof(req))) != 0)
                return error;
 
-       DPRINTF(("mach_host_get_clock_service();\n"));
-
        bzero(&rep, sizeof(rep));
 
        rep.rep_msgh.msgh_bits = 
diff -r ab72e82fbe5d -r 2fb91e4b7154 sys/compat/mach/mach_message.c
--- a/sys/compat/mach/mach_message.c    Sat Dec 14 17:52:47 2002 +0000
+++ b/sys/compat/mach/mach_message.c    Sun Dec 15 00:40:24 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_message.c,v 1.2 2002/12/09 21:29:24 manu Exp $ */
+/*     $NetBSD: mach_message.c,v 1.3 2002/12/15 00:40:25 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_message.c,v 1.2 2002/12/09 21:29:24 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_message.c,v 1.3 2002/12/15 00:40:25 manu Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_compat_mach.h" /* For COMPAT_MACH in <sys/ktrace.h> */
@@ -47,6 +47,9 @@
 #include <sys/systm.h>
 #include <sys/signal.h>
 #include <sys/proc.h>
+#include <sys/queue.h>
+#include <sys/malloc.h>
+#include <sys/pool.h>
 #ifdef KTRACE
 #include <sys/ktrace.h>
 #endif 
@@ -57,6 +60,9 @@
 #include <compat/mach/mach_clock.h>
 #include <compat/mach/mach_syscallargs.h>
 
+/* Mach message pool */
+static struct pool mach_message_pool;
+
 #ifdef DEBUG_MACH
 static void mach_print_msg_header_t(mach_msg_header_t *);
 static char *mach_print_msg_bits_t(mach_msg_bits_t, char *, size_t);
@@ -244,3 +250,30 @@
 
        return 0;
 }
+
+void
+mach_message_init(void)
+{
+       pool_init(&mach_message_pool, sizeof (struct mach_message),
+           0, 0, 128, "mach_message_pool", NULL);
+       return;
+}
+
+struct mach_message *
+mach_message_get(void)
+{
+       struct mach_message *mm;
+
+       mm = (struct mach_message *)pool_get(&mach_message_pool, M_WAITOK);
+
+       return mm;
+}
+
+void
+mach_message_put(mm)
+       struct mach_message *mm;
+{
+       pool_put(&mach_message_pool, mm);
+
+       return;
+}
diff -r ab72e82fbe5d -r 2fb91e4b7154 sys/compat/mach/mach_message.h
--- a/sys/compat/mach/mach_message.h    Sat Dec 14 17:52:47 2002 +0000
+++ b/sys/compat/mach/mach_message.h    Sun Dec 15 00:40:24 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_message.h,v 1.7 2002/12/09 21:29:24 manu Exp $     */
+/*     $NetBSD: mach_message.h,v 1.8 2002/12/15 00:40:25 manu Exp $     */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -166,4 +166,18 @@
 int mach_msg_return(struct proc *, mach_msg_header_t *, mach_msg_header_t *, 
     size_t, size_t, mach_msg_header_t *);
 



Home | Main Index | Thread Index | Old Index