Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/compat Provide a kernel port for each thread. This makes...
details: https://anonhg.NetBSD.org/src/rev/1e335e4b952c
branches: trunk
changeset: 556565:1e335e4b952c
user: manu <manu%NetBSD.org@localhost>
date: Sat Dec 20 19:43:17 2003 +0000
description:
Provide a kernel port for each thread. This makes the emulation of
Mach threads much more accurate: we do not confuse threads and tasks
anymore.
diffstat:
sys/compat/darwin/darwin_exec.c | 8 ++--
sys/compat/mach/mach_exec.c | 65 +++++++++++++++++++++++++++++++++++++---
sys/compat/mach/mach_exec.h | 9 +++++-
sys/compat/mach/mach_message.c | 25 +++++++++------
sys/compat/mach/mach_port.c | 14 +++-----
sys/compat/mach/mach_port.h | 3 +-
sys/compat/mach/mach_task.c | 16 +++++----
sys/compat/mach/mach_thread.c | 16 ++++++---
8 files changed, 114 insertions(+), 42 deletions(-)
diffs (truncated from 370 to 300 lines):
diff -r 3f4b7a0dd186 -r 1e335e4b952c sys/compat/darwin/darwin_exec.c
--- a/sys/compat/darwin/darwin_exec.c Sat Dec 20 19:01:29 2003 +0000
+++ b/sys/compat/darwin/darwin_exec.c Sat Dec 20 19:43:17 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: darwin_exec.c,v 1.31 2003/12/20 19:01:30 fvdl Exp $ */
+/* $NetBSD: darwin_exec.c,v 1.32 2003/12/20 19:43:17 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
#include "opt_compat_darwin.h" /* For COMPAT_DARWIN in mach_port.h */
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.31 2003/12/20 19:01:30 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.32 2003/12/20 19:43:17 manu Exp $");
#include "opt_syscall_debug.h"
@@ -125,8 +125,8 @@
darwin_e_proc_exec,
darwin_e_proc_fork,
darwin_e_proc_exit,
- NULL,
- NULL,
+ mach_e_lwp_fork,
+ mach_e_lwp_exit,
#ifdef __HAVE_SYSCALL_INTERN
mach_syscall_intern,
#else
diff -r 3f4b7a0dd186 -r 1e335e4b952c sys/compat/mach/mach_exec.c
--- a/sys/compat/mach/mach_exec.c Sat Dec 20 19:01:29 2003 +0000
+++ b/sys/compat/mach/mach_exec.c Sat Dec 20 19:43:17 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_exec.c,v 1.47 2003/12/20 19:01:30 fvdl Exp $ */
+/* $NetBSD: mach_exec.c,v 1.48 2003/12/20 19:43:17 manu Exp $ */
/*-
* Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_exec.c,v 1.47 2003/12/20 19:01:30 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_exec.c,v 1.48 2003/12/20 19:43:17 manu Exp $");
#include "opt_syscall_debug.h"
@@ -106,13 +106,12 @@
NULL,
NULL,
#endif
- NULL,
setregs,
mach_e_proc_exec,
mach_e_proc_fork,
mach_e_proc_exit,
- NULL,
- NULL,
+ mach_e_lwp_fork,
+ mach_e_lwp_exit,
#ifdef __HAVE_SYSCALL_INTERN
mach_syscall_intern,
#else
@@ -200,6 +199,9 @@
{
mach_e_proc_init(p, p->p_vmspace);
+ if (p->p_emul != epp->ep_es->es_emul)
+ mach_e_lwp_fork(NULL, proc_representative_lwp(p));
+
return;
}
@@ -360,6 +362,8 @@
struct mach_right *mr;
int i;
+ mach_e_lwp_exit(proc_representative_lwp(p));
+
mach_semaphore_cleanup(p);
med = (struct mach_emuldata *)p->p_emuldata;
@@ -402,6 +406,57 @@
return;
}
+void
+mach_e_lwp_fork(l1, l2)
+ struct lwp *l1;
+ struct lwp *l2;
+{
+ struct mach_lwp_emuldata *mle;
+
+ mle = malloc(sizeof(*mle), M_EMULDATA, M_WAITOK);
+ l2->l_emuldata = mle;
+
+ mle->mle_kernel = mach_port_get();
+ mle->mle_kernel->mp_refcount++;
+
+ mle->mle_kernel->mp_flags |= MACH_MP_INKERNEL;
+ mle->mle_kernel->mp_datatype = MACH_MP_LWP;
+ mle->mle_kernel->mp_data = (void *)l2;
+
+#if 0
+ /* Nothing to copy from parent thread for now */
+ if (l1 != NULL);
+#endif
+
+ return;
+}
+
+void
+mach_e_lwp_exit(l)
+ struct lwp *l;
+{
+ struct mach_lwp_emuldata *mle;
+
+#ifdef DIAGNOSTIC
+ if (l->l_emuldata == NULL) {
+ printf("lwp_emuldata already freed\n");
+ return;
+ }
+#endif
+ mle = l->l_emuldata;
+
+ mle->mle_kernel->mp_data = NULL;
+ mle->mle_kernel->mp_datatype = MACH_MP_NONE;
+
+ if (--mle->mle_kernel->mp_refcount <= 0)
+ mach_port_put(mle->mle_kernel);
+
+ free(mle, M_EMULDATA);
+ l->l_emuldata = NULL;
+
+ return;
+}
+
static void
mach_init(void)
{
diff -r 3f4b7a0dd186 -r 1e335e4b952c sys/compat/mach/mach_exec.h
--- a/sys/compat/mach/mach_exec.h Sat Dec 20 19:01:29 2003 +0000
+++ b/sys/compat/mach/mach_exec.h Sat Dec 20 19:43:17 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_exec.h,v 1.24 2003/12/09 12:13:44 manu Exp $ */
+/* $NetBSD: mach_exec.h,v 1.25 2003/12/20 19:43:17 manu Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -64,6 +64,11 @@
};
+struct mach_lwp_emuldata {
+ struct mach_port *mle_kernel; /* Thread's kernel port */
+ struct mach_port *mle_exc; /* Exception we stop on */
+};
+
int exec_mach_copyargs(struct proc *, struct exec_package *,
struct ps_strings *, char **, void *);
int exec_mach_probe(char **);
@@ -72,6 +77,8 @@
void mach_e_proc_exec(struct proc *, struct exec_package *);
void mach_e_proc_fork(struct proc *, struct proc *);
void mach_e_proc_fork1(struct proc *, struct proc *, int);
+void mach_e_lwp_fork(struct lwp *, struct lwp *);
+void mach_e_lwp_exit(struct lwp *);
extern const struct emul emul_mach;
diff -r 3f4b7a0dd186 -r 1e335e4b952c sys/compat/mach/mach_message.c
--- a/sys/compat/mach/mach_message.c Sat Dec 20 19:01:29 2003 +0000
+++ b/sys/compat/mach/mach_message.c Sat Dec 20 19:43:17 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_message.c,v 1.38 2003/12/18 01:10:20 grant Exp $ */
+/* $NetBSD: mach_message.c,v 1.39 2003/12/20 19:43:17 manu Exp $ */
/*-
* Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_message.c,v 1.38 2003/12/18 01:10:20 grant Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_message.c,v 1.39 2003/12/20 19:43:17 manu Exp $");
#include "opt_ktrace.h"
#include "opt_compat_mach.h" /* For COMPAT_MACH in <sys/ktrace.h> */
@@ -702,15 +702,20 @@
struct proc *tp;
struct lwp *tl;
- if (mp->mp_datatype != MACH_MP_PROC)
- return l;
+ switch (mp->mp_datatype) {
+ case MACH_MP_PROC:
+ tp = (struct proc *)mp->mp_data;
+ tl = proc_representative_lwp(tp);
+ break;
- /*
- * We need per thread kernel ports to avoid
- * always seeing the same thread here.
- */
- tp = (struct proc *)mp->mp_data;
- tl = proc_representative_lwp(tp);
+ case MACH_MP_LWP:
+ tl = (struct lwp *)mp->mp_data;
+ break;
+
+ default:
+ tl = l;
+ break;
+ }
return tl;
}
diff -r 3f4b7a0dd186 -r 1e335e4b952c sys/compat/mach/mach_port.c
--- a/sys/compat/mach/mach_port.c Sat Dec 20 19:01:29 2003 +0000
+++ b/sys/compat/mach/mach_port.c Sat Dec 20 19:43:17 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_port.c,v 1.47 2003/12/18 01:10:20 grant Exp $ */
+/* $NetBSD: mach_port.c,v 1.48 2003/12/20 19:43:17 manu Exp $ */
/*-
* Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
#include "opt_compat_darwin.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_port.c,v 1.47 2003/12/18 01:10:20 grant Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_port.c,v 1.48 2003/12/20 19:43:17 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -93,15 +93,11 @@
void *v;
register_t *retval;
{
- struct mach_emuldata *med;
+ struct mach_lwp_emuldata *mle;
struct mach_right *mr;
- /*
- * XXX for now thread kernel port and task kernel port are the same
- * awaiting for struct lwp ...
- */
- med = (struct mach_emuldata *)l->l_proc->p_emuldata;
- mr = mach_right_get(med->med_kernel, l, MACH_PORT_TYPE_SEND, 0);
+ mle = l->l_emuldata;
+ mr = mach_right_get(mle->mle_kernel, l, MACH_PORT_TYPE_SEND, 0);
*retval = (register_t)mr->mr_name;
return 0;
diff -r 3f4b7a0dd186 -r 1e335e4b952c sys/compat/mach/mach_port.h
--- a/sys/compat/mach/mach_port.h Sat Dec 20 19:01:29 2003 +0000
+++ b/sys/compat/mach/mach_port.h Sat Dec 20 19:43:17 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_port.h,v 1.31 2003/12/09 11:29:01 manu Exp $ */
+/* $NetBSD: mach_port.h,v 1.32 2003/12/20 19:43:17 manu Exp $ */
/*-
* Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -310,6 +310,7 @@
/* mp_datatype for struct mach_port */
#define MACH_MP_NONE 0x0 /* No data */
+#define MACH_MP_LWP 0x1 /* (struct lwp *) */
#define MACH_MP_DEVICE_ITERATOR 0x2 /* (struct mach_device_iterator *) */
#define MACH_MP_IOKIT_DEVCLASS 0x3 /* (struct mach_iokit_devclass *) */
#define MACH_MP_PROC 0x4 /* (struct proc *) */
diff -r 3f4b7a0dd186 -r 1e335e4b952c sys/compat/mach/mach_task.c
--- a/sys/compat/mach/mach_task.c Sat Dec 20 19:01:29 2003 +0000
+++ b/sys/compat/mach/mach_task.c Sat Dec 20 19:43:17 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_task.c,v 1.50 2003/12/18 01:10:20 grant Exp $ */
+/* $NetBSD: mach_task.c,v 1.51 2003/12/20 19:43:17 manu Exp $ */
/*-
* Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -40,7 +40,7 @@
#include "opt_compat_darwin.h"
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_task.c,v 1.50 2003/12/18 01:10:20 grant Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_task.c,v 1.51 2003/12/20 19:43:17 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -278,11 +278,13 @@
struct lwp *l = args->l;
struct lwp *tl = args->tl;
struct proc *tp = tl->l_proc;
+ struct lwp *cl;
struct mach_emuldata *med;
+ struct mach_lwp_emuldata *mle;
int error;
void *uaddr;
size_t size;
- int i;
Home |
Main Index |
Thread Index |
Old Index