Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/compat/mach In Mach_task_suspend, stop the process witho...
details: https://anonhg.NetBSD.org/src/rev/0c91cf6c4274
branches: trunk
changeset: 555780:0c91cf6c4274
user: manu <manu%NetBSD.org@localhost>
date: Thu Nov 27 23:44:49 2003 +0000
description:
In Mach_task_suspend, stop the process without awaking its parent, this is
wrong on the semantic front; the spurious wakeup confuses Darwin's gdb.
Allow vm, task and thread operations on remote processes. The code to pick up
the remote process is in mach_sys_msg_trap(), so that any Mach service can
use it.
diffstat:
sys/compat/mach/mach_message.c | 29 +++++++-
sys/compat/mach/mach_message.h | 13 ++-
sys/compat/mach/mach_task.c | 137 ++++++----------------------------------
sys/compat/mach/mach_task.h | 5 +-
sys/compat/mach/mach_thread.c | 34 ++--------
sys/compat/mach/mach_vm.c | 65 ++++++++++--------
sys/compat/mach/mach_vm.h | 3 +-
7 files changed, 100 insertions(+), 186 deletions(-)
diffs (truncated from 772 to 300 lines):
diff -r b7d84d06453f -r 0c91cf6c4274 sys/compat/mach/mach_message.c
--- a/sys/compat/mach/mach_message.c Thu Nov 27 23:16:47 2003 +0000
+++ b/sys/compat/mach/mach_message.c Thu Nov 27 23:44:49 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_message.c,v 1.31 2003/11/25 21:59:31 christos Exp $ */
+/* $NetBSD: mach_message.c,v 1.32 2003/11/27 23:44:49 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.31 2003/11/25 21:59:31 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_message.c,v 1.32 2003/11/27 23:44:49 manu Exp $");
#include "opt_ktrace.h"
#include "opt_compat_mach.h" /* For COMPAT_MACH in <sys/ktrace.h> */
@@ -70,6 +70,8 @@
/* Mach message pool */
static struct pool mach_message_pool;
+static struct lwp *mach_get_target_task(struct lwp *, struct mach_port *);
+
int
mach_sys_msg_overwrite_trap(l, v, retval)
struct lwp *l;
@@ -265,7 +267,6 @@
*/
-
/*
* Invoke the server. We give it the opportunity
* to shorten rcv_size if there is less data in
@@ -279,6 +280,7 @@
rm = NULL;
args.l = l;
+ args.tl = mach_get_target_task(l, mp);
args.smsg = sm;
args.rmsg = rm;
args.rsize = &rcv_size;
@@ -769,6 +771,27 @@
return mach_sys_msg_overwrite_trap(l, &cup, retval);
}
+static struct lwp *
+mach_get_target_task(l, mp)
+ struct lwp *l;
+ struct mach_port *mp;
+{
+ struct proc *tp;
+ struct lwp *tl;
+
+ if (mp->mp_datatype != MACH_MP_PROC)
+ return l;
+
+ /*
+ * We need per thread kernel ports to avoid
+ * seeing always the same thread here
+ */
+ tp = (struct proc *)mp->mp_data;
+ tl = proc_representative_lwp(tp);
+
+ return tl;
+}
+
void
mach_message_init(void)
{
diff -r b7d84d06453f -r 0c91cf6c4274 sys/compat/mach/mach_message.h
--- a/sys/compat/mach/mach_message.h Thu Nov 27 23:16:47 2003 +0000
+++ b/sys/compat/mach/mach_message.h Thu Nov 27 23:44:49 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_message.h,v 1.18 2003/11/13 13:40:39 manu Exp $ */
+/* $NetBSD: mach_message.h,v 1.19 2003/11/27 23:44:49 manu Exp $ */
/*-
* Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
@@ -217,11 +217,12 @@
/* Kernel-private structures */
struct mach_trap_args {
- struct lwp *l;
- void *smsg;
- void *rmsg;
- size_t ssize;
- size_t *rsize;
+ struct lwp *l; /* Current task (doing the Mach system call) */
+ struct lwp *tl; /* Target task */
+ void *smsg; /* Sent message */
+ void *rmsg; /* Reply message */
+ size_t ssize; /* Sent message size */
+ size_t *rsize; /* Reply message maximum size, may be lowered */
};
struct mach_service {
diff -r b7d84d06453f -r 0c91cf6c4274 sys/compat/mach/mach_task.c
--- a/sys/compat/mach/mach_task.c Thu Nov 27 23:16:47 2003 +0000
+++ b/sys/compat/mach/mach_task.c Thu Nov 27 23:44:49 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mach_task.c,v 1.42 2003/11/24 20:30:19 manu Exp $ */
+/* $NetBSD: mach_task.c,v 1.43 2003/11/27 23:44:49 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.42 2003/11/24 20:30:19 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_task.c,v 1.43 2003/11/27 23:44:49 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -78,18 +78,11 @@
mach_task_get_special_port_reply_t *rep = args->rmsg;
size_t *msglen = args->rsize;
struct lwp *l = args->l;
+ struct lwp *tl = args->tl;
struct mach_emuldata *med;
struct mach_right *mr;
- struct proc *tp;
- mach_port_t mn;
- int error;
- /* Get the target process from the remote port. */
- mn = req->req_msgh.msgh_remote_port;
- if ((error = mach_get_target_task(l, mn, &tp, NULL)) != 0)
- return mach_msg_error(args, error);
-
- med = (struct mach_emuldata *)tp->p_emuldata;
+ med = (struct mach_emuldata *)tl->l_proc->p_emuldata;
switch (req->req_which_port) {
case MACH_TASK_KERNEL_PORT:
@@ -137,20 +130,13 @@
mach_ports_lookup_reply_t *rep = args->rmsg;
size_t *msglen = args->rsize;
struct lwp *l = args->l;
+ struct lwp *tl = args->tl;
struct mach_emuldata *med;
struct mach_right *mr;
- struct proc *tp;
- mach_port_t mn;
-
mach_port_name_t mnp[7];
vaddr_t va;
int error;
- /* Get the target process from the remote port. */
- mn = req->req_msgh.msgh_remote_port;
- if ((error = mach_get_target_task(l, mn, &tp, NULL)) != 0)
- return mach_msg_error(args, error);
-
/*
* This is some out of band data sent with the reply. In the
* encountered situation the out of band data has always been null
@@ -163,7 +149,7 @@
UVM_INH_COPY, UVM_ADV_NORMAL, UVM_FLAG_COPYONW))) != 0)
return mach_msg_error(args, error);
- med = (struct mach_emuldata *)tp->p_emuldata;
+ med = (struct mach_emuldata *)tl->l_proc->p_emuldata;
mnp[0] = (mach_port_name_t)MACH_PORT_DEAD;
mnp[3] = (mach_port_name_t)MACH_PORT_DEAD;
mnp[5] = (mach_port_name_t)MACH_PORT_DEAD;
@@ -213,17 +199,11 @@
mach_task_set_special_port_reply_t *rep = args->rmsg;
size_t *msglen = args->rsize;
struct lwp *l = args->l;
+ struct lwp *tl = args->tl;
mach_port_t mn;
struct mach_right *mr;
struct mach_port *mp;
struct mach_emuldata *med;
- struct proc *tp;
- int error;
-
- /* Get the target process from the remote port. */
- mn = req->req_msgh.msgh_remote_port;
- if ((error = mach_get_target_task(l, mn, &tp, NULL)) != 0)
- return mach_msg_error(args, error);
mn = req->req_special_port.name;
@@ -238,7 +218,7 @@
if (mr->mr_type == MACH_PORT_TYPE_DEAD_NAME)
return mach_msg_error(args, EINVAL);
- med = (struct mach_emuldata *)tp->p_emuldata;
+ med = (struct mach_emuldata *)tl->l_proc->p_emuldata;
switch (req->req_which_port) {
case MACH_TASK_KERNEL_PORT:
@@ -270,7 +250,7 @@
{
struct darwin_emuldata *ded;
- ded = tp->p_emuldata;
+ ded = tl->l_proc->p_emuldata;
if (ded->ded_fakepid == 1) {
mach_bootstrap_port = med->med_bootstrap;
#ifdef DEBUG_DARWIN
@@ -309,6 +289,8 @@
mach_task_threads_reply_t *rep = args->rmsg;
size_t *msglen = args->rsize;
struct lwp *l = args->l;
+ struct lwp *tl = args->tl;
+ struct proc *tp = tl->l_proc;
struct mach_emuldata *med;
int error;
vaddr_t va;
@@ -316,13 +298,6 @@
int i;
struct mach_right *mr;
mach_port_name_t *mnp;
- mach_port_t mn;
- struct proc *tp;
-
- /* Get the target lwp from the remote port. */
- mn = req->req_msgh.msgh_remote_port;
- if ((error = mach_get_target_task(l, mn, &tp, NULL)) != 0)
- return mach_msg_error(args, error);
med = tp->p_emuldata;
@@ -378,20 +353,13 @@
mach_task_get_exception_ports_request_t *req = args->smsg;
mach_task_get_exception_ports_reply_t *rep = args->rmsg;
struct lwp *l = args->l;
+ struct lwp *tl = args->tl;
size_t *msglen = args->rsize;
struct mach_emuldata *med;
struct mach_right *mr;
int i, j, count;
- mach_port_t mn;
- struct proc *tp;
- int error;
- /* Get the target lwp from the remote port. */
- mn = req->req_msgh.msgh_remote_port;
- if ((error = mach_get_target_task(l, mn, &tp, NULL)) != 0)
- return mach_msg_error(args, error);
-
- med = tp->p_emuldata;
+ med = tl->l_proc->p_emuldata;
/* It always return an array of 32 ports even if only 9 can be used */
count = sizeof(rep->rep_old_handler) / sizeof(rep->rep_old_handler[0]);
@@ -436,18 +404,12 @@
mach_task_set_exception_ports_request_t *req = args->smsg;
mach_task_set_exception_ports_reply_t *rep = args->rmsg;
struct lwp *l = args->l;
+ struct lwp *tl = args->tl;
size_t *msglen = args->rsize;
struct mach_emuldata *med;
mach_port_name_t mn;
struct mach_right *mr;
struct mach_port *mp;
- struct proc *tp;
- int error;
-
- /* Get the target lwp from the remote port. */
- mn = req->req_msgh.msgh_remote_port;
- if ((error = mach_get_target_task(l, mn, &tp, NULL)) != 0)
- return mach_msg_error(args, error);
mn = req->req_new_port.name;
if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_SEND)) == 0)
@@ -462,7 +424,7 @@
mp->mp_datatype = MACH_MP_EXC_FLAGS;
mp->mp_data = (void *)((req->req_behavior << 16) | req->req_flavor);
- med = tp->p_emuldata;
+ med = tl->l_proc->p_emuldata;
if (req->req_mask & MACH_EXC_MASK_BAD_ACCESS)
med->med_exc[MACH_EXC_BAD_ACCESS] = mp;
if (req->req_mask & MACH_EXC_MASK_BAD_INSTRUCTION)
@@ -508,17 +470,10 @@
{
mach_task_info_request_t *req = args->smsg;
mach_task_info_reply_t *rep = args->rmsg;
- struct lwp *l = args->l;
+ struct lwp *tl = args->tl;
size_t *msglen = args->rsize;
int count;
- mach_port_t mn;
- struct proc *tp;
- int error;
-
- /* Get the target lwp from the remote port. */
- mn = req->req_msgh.msgh_remote_port;
- if ((error = mach_get_target_task(l, mn, &tp, NULL)) != 0)
- return mach_msg_error(args, error);
+ struct proc *tp = tl->l_proc;
switch(req->req_flavor) {
case MACH_TASK_BASIC_INFO: {
Home |
Main Index |
Thread Index |
Old Index