2003-12-25 02:22:22 +03:00
|
|
|
/* $NetBSD: mach_task.c,v 1.52 2003/12/24 23:22:22 manu Exp $ */
|
2002-11-11 00:53:40 +03:00
|
|
|
|
|
|
|
/*-
|
2003-04-06 01:18:02 +04:00
|
|
|
* Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
|
2002-11-11 00:53:40 +03:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-11-24 19:51:33 +03:00
|
|
|
#include "opt_ktrace.h"
|
2002-12-30 21:44:33 +03:00
|
|
|
#include "opt_compat_darwin.h"
|
|
|
|
|
2002-11-11 00:53:40 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-12-25 02:22:22 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: mach_task.c,v 1.52 2003/12/24 23:22:22 manu Exp $");
|
2002-11-11 00:53:40 +03:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
2002-11-12 08:18:31 +03:00
|
|
|
#include <sys/exec.h>
|
2002-11-11 00:53:40 +03:00
|
|
|
#include <sys/systm.h>
|
2003-04-06 01:18:02 +04:00
|
|
|
#include <sys/proc.h>
|
2003-11-24 19:51:33 +03:00
|
|
|
#include <sys/ktrace.h>
|
2003-04-06 01:18:02 +04:00
|
|
|
#include <sys/resourcevar.h>
|
2003-03-29 14:04:08 +03:00
|
|
|
#include <sys/malloc.h>
|
2003-11-30 23:42:03 +03:00
|
|
|
#include <sys/sa.h>
|
|
|
|
#include <sys/mount.h>
|
2003-12-08 15:03:16 +03:00
|
|
|
#include <sys/ktrace.h>
|
2003-11-30 23:42:03 +03:00
|
|
|
#include <sys/syscallargs.h>
|
2002-11-11 00:53:40 +03:00
|
|
|
|
2002-11-12 08:18:31 +03:00
|
|
|
#include <uvm/uvm_extern.h>
|
|
|
|
#include <uvm/uvm_param.h>
|
|
|
|
|
2002-11-11 00:53:40 +03:00
|
|
|
#include <compat/mach/mach_types.h>
|
|
|
|
#include <compat/mach/mach_message.h>
|
2002-11-26 11:10:14 +03:00
|
|
|
#include <compat/mach/mach_clock.h>
|
2002-11-12 08:18:31 +03:00
|
|
|
#include <compat/mach/mach_errno.h>
|
2002-12-15 03:40:24 +03:00
|
|
|
#include <compat/mach/mach_exec.h>
|
|
|
|
#include <compat/mach/mach_port.h>
|
2002-11-11 00:53:40 +03:00
|
|
|
#include <compat/mach/mach_task.h>
|
2003-11-13 16:40:39 +03:00
|
|
|
#include <compat/mach/mach_services.h>
|
2002-11-11 00:53:40 +03:00
|
|
|
#include <compat/mach/mach_syscallargs.h>
|
|
|
|
|
2002-12-30 21:44:33 +03:00
|
|
|
#ifdef COMPAT_DARWIN
|
|
|
|
#include <compat/darwin/darwin_exec.h>
|
|
|
|
#endif
|
2002-11-11 00:53:40 +03:00
|
|
|
|
2003-11-22 20:17:55 +03:00
|
|
|
#define ISSET(t, f) ((t) & (f))
|
|
|
|
|
2003-12-06 18:15:19 +03:00
|
|
|
static void
|
|
|
|
update_exception_port(struct mach_emuldata *, int exc, struct mach_port *);
|
|
|
|
|
2002-11-11 00:53:40 +03:00
|
|
|
int
|
2002-12-17 21:42:54 +03:00
|
|
|
mach_task_get_special_port(args)
|
|
|
|
struct mach_trap_args *args;
|
2002-11-11 00:53:40 +03:00
|
|
|
{
|
2002-12-17 21:42:54 +03:00
|
|
|
mach_task_get_special_port_request_t *req = args->smsg;
|
|
|
|
mach_task_get_special_port_reply_t *rep = args->rmsg;
|
|
|
|
size_t *msglen = args->rsize;
|
2003-01-21 07:06:06 +03:00
|
|
|
struct lwp *l = args->l;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct lwp *tl = args->tl;
|
2002-12-15 03:40:24 +03:00
|
|
|
struct mach_emuldata *med;
|
|
|
|
struct mach_right *mr;
|
2003-11-24 17:31:40 +03:00
|
|
|
|
2003-11-28 02:44:49 +03:00
|
|
|
med = (struct mach_emuldata *)tl->l_proc->p_emuldata;
|
2002-12-15 03:40:24 +03:00
|
|
|
|
2002-12-17 21:42:54 +03:00
|
|
|
switch (req->req_which_port) {
|
2002-12-15 03:40:24 +03:00
|
|
|
case MACH_TASK_KERNEL_PORT:
|
2003-01-21 07:06:06 +03:00
|
|
|
mr = mach_right_get(med->med_kernel, l, MACH_PORT_TYPE_SEND, 0);
|
2002-12-15 03:40:24 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MACH_TASK_HOST_PORT:
|
2003-01-21 07:06:06 +03:00
|
|
|
mr = mach_right_get(med->med_host, l, MACH_PORT_TYPE_SEND, 0);
|
2002-12-15 03:40:24 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MACH_TASK_BOOTSTRAP_PORT:
|
|
|
|
mr = mach_right_get(med->med_bootstrap,
|
2003-01-21 07:06:06 +03:00
|
|
|
l, MACH_PORT_TYPE_SEND, 0);
|
2002-12-15 03:40:24 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MACH_TASK_WIRED_LEDGER_PORT:
|
|
|
|
case MACH_TASK_PAGED_LEDGER_PORT:
|
|
|
|
default:
|
|
|
|
uprintf("mach_task_get_special_port(): unimpl. port %d\n",
|
2002-12-17 21:42:54 +03:00
|
|
|
req->req_which_port);
|
2003-10-26 00:15:13 +04:00
|
|
|
return mach_msg_error(args, EINVAL);
|
2002-12-15 03:40:24 +03:00
|
|
|
break;
|
|
|
|
}
|
2002-11-11 00:53:40 +03:00
|
|
|
|
2002-12-17 21:42:54 +03:00
|
|
|
*msglen = sizeof(*rep);
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_set_header(rep, req, *msglen);
|
|
|
|
mach_add_port_desc(rep, mr->mr_name);
|
|
|
|
mach_set_trailer(rep, *msglen);
|
|
|
|
|
2002-12-17 21:42:54 +03:00
|
|
|
return 0;
|
2002-11-11 00:53:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-12-17 21:42:54 +03:00
|
|
|
mach_ports_lookup(args)
|
|
|
|
struct mach_trap_args *args;
|
2002-11-11 00:53:40 +03:00
|
|
|
{
|
2002-12-17 21:42:54 +03:00
|
|
|
mach_ports_lookup_request_t *req = args->smsg;
|
|
|
|
mach_ports_lookup_reply_t *rep = args->rmsg;
|
|
|
|
size_t *msglen = args->rsize;
|
2003-01-21 07:06:06 +03:00
|
|
|
struct lwp *l = args->l;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct lwp *tl = args->tl;
|
2003-12-08 22:27:38 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2002-12-20 01:23:06 +03:00
|
|
|
struct mach_emuldata *med;
|
2003-11-12 03:00:28 +03:00
|
|
|
struct mach_right *mr;
|
|
|
|
mach_port_name_t mnp[7];
|
2003-12-08 22:27:38 +03:00
|
|
|
void *uaddr;
|
2002-11-11 00:53:40 +03:00
|
|
|
int error;
|
2003-12-09 14:29:01 +03:00
|
|
|
int count;
|
2002-11-11 00:53:40 +03:00
|
|
|
|
2002-12-15 03:40:24 +03:00
|
|
|
/*
|
2003-12-18 04:10:20 +03:00
|
|
|
* This is some out of band data sent with the reply. In the
|
|
|
|
* encountered situation, the out of band data has always been null
|
2002-12-20 01:23:06 +03:00
|
|
|
* filled. We have to see more of this in order to fully understand
|
2002-12-18 01:47:07 +03:00
|
|
|
* how this trap works.
|
2002-12-15 03:40:24 +03:00
|
|
|
*/
|
2003-11-28 02:44:49 +03:00
|
|
|
med = (struct mach_emuldata *)tl->l_proc->p_emuldata;
|
2003-11-12 03:00:28 +03:00
|
|
|
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;
|
|
|
|
mnp[6] = (mach_port_name_t)MACH_PORT_DEAD;
|
|
|
|
|
|
|
|
mr = mach_right_get(med->med_kernel, l, MACH_PORT_TYPE_SEND, 0);
|
|
|
|
mnp[MACH_TASK_KERNEL_PORT] = mr->mr_name;
|
|
|
|
mr = mach_right_get(med->med_host, l, MACH_PORT_TYPE_SEND, 0);
|
|
|
|
mnp[MACH_TASK_HOST_PORT] = mr->mr_name;
|
|
|
|
mr = mach_right_get(med->med_bootstrap, l, MACH_PORT_TYPE_SEND, 0);
|
|
|
|
mnp[MACH_TASK_BOOTSTRAP_PORT] = mr->mr_name;
|
2002-12-20 01:23:06 +03:00
|
|
|
|
|
|
|
/*
|
2002-12-27 22:57:47 +03:00
|
|
|
* On Darwin, the data seems always null...
|
2002-12-20 01:23:06 +03:00
|
|
|
*/
|
2003-12-08 22:27:38 +03:00
|
|
|
uaddr = NULL;
|
|
|
|
if ((error = mach_ool_copyout(p, &mnp[0],
|
|
|
|
&uaddr, sizeof(mnp), MACH_OOL_TRACE)) != 0)
|
2002-12-20 01:23:06 +03:00
|
|
|
return mach_msg_error(args, error);
|
2002-12-27 22:57:47 +03:00
|
|
|
|
2003-12-09 14:29:01 +03:00
|
|
|
count = 3; /* XXX Shouldn't this be 7? */
|
2002-12-17 21:42:54 +03:00
|
|
|
|
|
|
|
*msglen = sizeof(*rep);
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_set_header(rep, req, *msglen);
|
|
|
|
mach_add_ool_ports_desc(rep, uaddr, count);
|
|
|
|
|
|
|
|
rep->rep_init_port_set_count = count;
|
|
|
|
|
|
|
|
mach_set_trailer(rep, *msglen);
|
|
|
|
|
2002-12-17 21:42:54 +03:00
|
|
|
return 0;
|
2002-11-11 00:53:40 +03:00
|
|
|
}
|
|
|
|
|
2002-12-12 03:29:23 +03:00
|
|
|
int
|
2002-12-17 21:42:54 +03:00
|
|
|
mach_task_set_special_port(args)
|
|
|
|
struct mach_trap_args *args;
|
2002-12-12 03:29:23 +03:00
|
|
|
{
|
2002-12-17 21:42:54 +03:00
|
|
|
mach_task_set_special_port_request_t *req = args->smsg;
|
|
|
|
mach_task_set_special_port_reply_t *rep = args->rmsg;
|
|
|
|
size_t *msglen = args->rsize;
|
2003-01-21 07:06:06 +03:00
|
|
|
struct lwp *l = args->l;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct lwp *tl = args->tl;
|
2002-12-31 18:47:37 +03:00
|
|
|
mach_port_t mn;
|
2002-12-20 01:23:06 +03:00
|
|
|
struct mach_right *mr;
|
|
|
|
struct mach_port *mp;
|
|
|
|
struct mach_emuldata *med;
|
2003-11-24 17:31:40 +03:00
|
|
|
|
2002-12-31 18:47:37 +03:00
|
|
|
mn = req->req_special_port.name;
|
2002-12-20 01:23:06 +03:00
|
|
|
|
|
|
|
/* Null port ? */
|
2003-10-25 22:37:49 +04:00
|
|
|
if (mn == 0)
|
2002-12-20 01:23:06 +03:00
|
|
|
return mach_msg_error(args, 0);
|
|
|
|
|
|
|
|
/* Does the inserted port exists? */
|
2003-01-21 07:06:06 +03:00
|
|
|
if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_ALL_RIGHTS)) == 0)
|
2002-12-20 01:23:06 +03:00
|
|
|
return mach_msg_error(args, EPERM);
|
|
|
|
|
2002-12-27 12:59:24 +03:00
|
|
|
if (mr->mr_type == MACH_PORT_TYPE_DEAD_NAME)
|
2002-12-20 01:23:06 +03:00
|
|
|
return mach_msg_error(args, EINVAL);
|
|
|
|
|
2003-11-28 02:44:49 +03:00
|
|
|
med = (struct mach_emuldata *)tl->l_proc->p_emuldata;
|
2002-12-20 01:23:06 +03:00
|
|
|
|
|
|
|
switch (req->req_which_port) {
|
|
|
|
case MACH_TASK_KERNEL_PORT:
|
|
|
|
mp = med->med_kernel;
|
|
|
|
med->med_kernel = mr->mr_port;
|
|
|
|
mp->mp_refcount--;
|
|
|
|
if (mp->mp_refcount == 0)
|
|
|
|
mach_port_put(mp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MACH_TASK_HOST_PORT:
|
|
|
|
mp = med->med_host;
|
|
|
|
med->med_host = mr->mr_port;
|
|
|
|
mp->mp_refcount--;
|
|
|
|
if (mp->mp_refcount == 0)
|
|
|
|
mach_port_put(mp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MACH_TASK_BOOTSTRAP_PORT:
|
|
|
|
mp = med->med_bootstrap;
|
|
|
|
med->med_bootstrap = mr->mr_port;
|
|
|
|
mp->mp_refcount--;
|
|
|
|
if (mp->mp_refcount == 0)
|
|
|
|
mach_port_put(mp);
|
2002-12-30 21:44:33 +03:00
|
|
|
#ifdef COMPAT_DARWIN
|
|
|
|
/*
|
2003-12-18 04:10:20 +03:00
|
|
|
* mach_init sets the bootstrap port for any new process.
|
2002-12-30 21:44:33 +03:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct darwin_emuldata *ded;
|
|
|
|
|
2003-11-28 02:44:49 +03:00
|
|
|
ded = tl->l_proc->p_emuldata;
|
2002-12-30 21:44:33 +03:00
|
|
|
if (ded->ded_fakepid == 1) {
|
|
|
|
mach_bootstrap_port = med->med_bootstrap;
|
|
|
|
#ifdef DEBUG_DARWIN
|
|
|
|
printf("*** New bootstrap port %p, "
|
|
|
|
"recv %p [%p]\n",
|
|
|
|
mach_bootstrap_port,
|
|
|
|
mach_bootstrap_port->mp_recv,
|
|
|
|
mach_bootstrap_port->mp_recv->mr_sethead);
|
|
|
|
#endif /* DEBUG_DARWIN */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* COMPAT_DARWIN */
|
2002-12-20 01:23:06 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
uprintf("mach_task_set_special_port: unimplemented port %d\n",
|
|
|
|
req->req_which_port);
|
|
|
|
}
|
2002-12-12 03:29:23 +03:00
|
|
|
|
2002-12-17 21:42:54 +03:00
|
|
|
*msglen = sizeof(*rep);
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_set_header(rep, req, *msglen);
|
|
|
|
|
|
|
|
rep->rep_retval = 0;
|
|
|
|
|
|
|
|
mach_set_trailer(rep, *msglen);
|
|
|
|
|
2002-12-17 21:42:54 +03:00
|
|
|
return 0;
|
2002-12-12 03:29:23 +03:00
|
|
|
}
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
mach_task_threads(args)
|
|
|
|
struct mach_trap_args *args;
|
|
|
|
{
|
|
|
|
mach_task_threads_request_t *req = args->smsg;
|
|
|
|
mach_task_threads_reply_t *rep = args->rmsg;
|
|
|
|
size_t *msglen = args->rsize;
|
|
|
|
struct lwp *l = args->l;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct lwp *tl = args->tl;
|
|
|
|
struct proc *tp = tl->l_proc;
|
2003-12-20 22:43:17 +03:00
|
|
|
struct lwp *cl;
|
2003-03-29 14:04:08 +03:00
|
|
|
struct mach_emuldata *med;
|
2003-12-20 22:43:17 +03:00
|
|
|
struct mach_lwp_emuldata *mle;
|
2003-03-29 14:04:08 +03:00
|
|
|
int error;
|
2003-12-08 22:27:38 +03:00
|
|
|
void *uaddr;
|
2003-03-29 14:04:08 +03:00
|
|
|
size_t size;
|
2003-12-20 22:43:17 +03:00
|
|
|
int i = 0;
|
2003-03-29 14:04:08 +03:00
|
|
|
struct mach_right *mr;
|
2003-11-12 03:00:28 +03:00
|
|
|
mach_port_name_t *mnp;
|
2003-11-24 17:31:40 +03:00
|
|
|
|
|
|
|
med = tp->p_emuldata;
|
|
|
|
size = tp->p_nlwps * sizeof(*mnp);
|
2003-11-12 03:00:28 +03:00
|
|
|
mnp = malloc(size, M_TEMP, M_WAITOK);
|
2003-12-08 22:27:38 +03:00
|
|
|
uaddr = NULL;
|
|
|
|
|
2003-12-20 22:43:17 +03:00
|
|
|
LIST_FOREACH(cl, &tp->p_lwps, l_sibling) {
|
|
|
|
mle = cl->l_emuldata;
|
|
|
|
mr = mach_right_get(mle->mle_kernel, l, MACH_PORT_TYPE_SEND, 0);
|
|
|
|
mnp[i++] = mr->mr_name;
|
2003-03-29 14:04:08 +03:00
|
|
|
}
|
|
|
|
|
2003-12-08 22:27:38 +03:00
|
|
|
/* This will free mnp */
|
|
|
|
if ((error = mach_ool_copyout(l->l_proc, mnp, &uaddr,
|
|
|
|
size, MACH_OOL_TRACE|MACH_OOL_FREE)) != 0)
|
|
|
|
return mach_msg_error(args, error);
|
2003-11-24 20:20:58 +03:00
|
|
|
|
2003-12-09 14:29:01 +03:00
|
|
|
*msglen = sizeof(*rep);
|
|
|
|
mach_set_header(rep, req, *msglen);
|
|
|
|
mach_add_ool_ports_desc(rep, uaddr, tp->p_nlwps);
|
|
|
|
|
2003-11-24 17:31:40 +03:00
|
|
|
rep->rep_count = tp->p_nlwps;
|
2003-03-29 14:04:08 +03:00
|
|
|
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_set_trailer(rep, *msglen);
|
|
|
|
|
2003-03-29 14:04:08 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mach_task_get_exception_ports(args)
|
|
|
|
struct mach_trap_args *args;
|
|
|
|
{
|
|
|
|
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;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct lwp *tl = args->tl;
|
2003-03-29 14:04:08 +03:00
|
|
|
size_t *msglen = args->rsize;
|
|
|
|
struct mach_emuldata *med;
|
2003-11-17 16:20:06 +03:00
|
|
|
struct mach_right *mr;
|
2003-12-25 02:22:22 +03:00
|
|
|
struct mach_exc_info *mei;
|
2003-11-17 16:20:06 +03:00
|
|
|
int i, j, count;
|
2003-03-29 14:04:08 +03:00
|
|
|
|
2003-11-28 02:44:49 +03:00
|
|
|
med = tl->l_proc->p_emuldata;
|
2003-03-29 14:04:08 +03:00
|
|
|
|
2003-12-18 04:10:20 +03:00
|
|
|
/* It always returns an array of 32 ports even if only 9 can be used */
|
2003-11-17 16:20:06 +03:00
|
|
|
count = sizeof(rep->rep_old_handler) / sizeof(rep->rep_old_handler[0]);
|
2003-11-09 14:10:11 +03:00
|
|
|
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_set_header(rep, req, *msglen);
|
|
|
|
|
2003-11-17 16:20:06 +03:00
|
|
|
rep->rep_masks_count = count;
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
for (i = 0; i <= MACH_EXC_MAX; i++) {
|
|
|
|
if (med->med_exc[i] == NULL)
|
|
|
|
continue;
|
|
|
|
|
2003-12-25 02:22:22 +03:00
|
|
|
if (med->med_exc[i]->mp_datatype != MACH_MP_EXC_INFO) {
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
printf("Exception port without mach_exc_info\n");
|
|
|
|
#endif
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
mei = med->med_exc[i]->mp_data;
|
|
|
|
|
2003-11-17 16:20:06 +03:00
|
|
|
mr = mach_right_get(med->med_exc[i], l, MACH_PORT_TYPE_SEND, 0);
|
|
|
|
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_add_port_desc(rep, mr->mr_name);
|
|
|
|
|
2003-11-17 16:20:06 +03:00
|
|
|
rep->rep_masks[j] = 1 << i;
|
2003-12-25 02:22:22 +03:00
|
|
|
rep->rep_old_behaviors[j] = mei->mei_behavior;
|
|
|
|
rep->rep_old_flavors[j] = mei->mei_flavor;
|
2003-11-17 16:20:06 +03:00
|
|
|
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
2003-03-29 14:04:08 +03:00
|
|
|
*msglen = sizeof(*rep);
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_set_trailer(rep, *msglen);
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-12-06 18:15:19 +03:00
|
|
|
static void
|
|
|
|
update_exception_port(med, exc, mp)
|
|
|
|
struct mach_emuldata *med;
|
|
|
|
int exc;
|
|
|
|
struct mach_port *mp;
|
|
|
|
{
|
|
|
|
if (med->med_exc[exc] != NULL) {
|
|
|
|
med->med_exc[exc]->mp_refcount--;
|
|
|
|
if (med->med_exc[exc]->mp_refcount <= 0)
|
|
|
|
mach_port_put(med->med_exc[exc]);
|
|
|
|
}
|
|
|
|
med->med_exc[exc] = mp;
|
|
|
|
mp->mp_refcount++;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-03-29 14:04:08 +03:00
|
|
|
int
|
|
|
|
mach_task_set_exception_ports(args)
|
|
|
|
struct mach_trap_args *args;
|
|
|
|
{
|
|
|
|
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;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct lwp *tl = args->tl;
|
2003-03-29 14:04:08 +03:00
|
|
|
size_t *msglen = args->rsize;
|
|
|
|
struct mach_emuldata *med;
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
mach_port_name_t mn;
|
|
|
|
struct mach_right *mr;
|
|
|
|
struct mach_port *mp;
|
2003-12-25 02:22:22 +03:00
|
|
|
struct mach_exc_info *mei;
|
2003-11-24 17:31:40 +03:00
|
|
|
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
mn = req->req_new_port.name;
|
|
|
|
if ((mr = mach_right_check(mn, l, MACH_PORT_TYPE_SEND)) == 0)
|
|
|
|
return mach_msg_error(args, EPERM);
|
2003-03-29 14:04:08 +03:00
|
|
|
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
mp = mr->mr_port;
|
|
|
|
#ifdef DIAGNOSTIC
|
2003-12-25 02:22:22 +03:00
|
|
|
if ((mp->mp_datatype != MACH_MP_EXC_INFO) &&
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
(mp->mp_datatype != MACH_MP_NONE))
|
|
|
|
printf("mach_task_set_exception_ports: data exists\n");
|
|
|
|
#endif
|
2003-12-25 02:22:22 +03:00
|
|
|
mei = malloc(sizeof(*mei), M_EMULDATA, M_WAITOK);
|
|
|
|
mei->mei_flavor = req->req_flavor;
|
|
|
|
mei->mei_behavior = req->req_behavior;
|
|
|
|
|
|
|
|
mp->mp_data = mei;
|
|
|
|
mp->mp_flags |= MACH_MP_DATA_ALLOCATED;
|
|
|
|
mp->mp_datatype = MACH_MP_EXC_INFO;
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
|
2003-11-28 02:44:49 +03:00
|
|
|
med = tl->l_proc->p_emuldata;
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
if (req->req_mask & MACH_EXC_MASK_BAD_ACCESS)
|
2003-12-06 18:15:19 +03:00
|
|
|
update_exception_port(med, MACH_EXC_BAD_ACCESS, mp);
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
if (req->req_mask & MACH_EXC_MASK_BAD_INSTRUCTION)
|
2003-12-06 18:15:19 +03:00
|
|
|
update_exception_port(med, MACH_EXC_BAD_INSTRUCTION, mp);
|
2003-11-17 16:20:06 +03:00
|
|
|
if (req->req_mask & MACH_EXC_MASK_ARITHMETIC)
|
2003-12-06 18:15:19 +03:00
|
|
|
update_exception_port(med, MACH_EXC_ARITHMETIC, mp);
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
if (req->req_mask & MACH_EXC_MASK_EMULATION)
|
2003-12-06 18:15:19 +03:00
|
|
|
update_exception_port(med, MACH_EXC_EMULATION, mp);
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
if (req->req_mask & MACH_EXC_MASK_SOFTWARE)
|
2003-12-06 18:15:19 +03:00
|
|
|
update_exception_port(med, MACH_EXC_SOFTWARE, mp);
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
if (req->req_mask & MACH_EXC_MASK_BREAKPOINT)
|
2003-12-06 18:15:19 +03:00
|
|
|
update_exception_port(med, MACH_EXC_BREAKPOINT, mp);
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
if (req->req_mask & MACH_EXC_MASK_SYSCALL)
|
2003-12-06 18:15:19 +03:00
|
|
|
update_exception_port(med, MACH_EXC_SYSCALL, mp);
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
if (req->req_mask & MACH_EXC_MASK_MACH_SYSCALL)
|
2003-12-06 18:15:19 +03:00
|
|
|
update_exception_port(med, MACH_EXC_MACH_SYSCALL, mp);
|
First work on Mach exceptions. Things that can turn into signals on UNIX
may turn into exceptions on Mach: a small message sent by the kernel to
the task that requested the exception.
On Darwin, when an exception is sent, no signal can be delivered.
TODO: more exceptions: arithmetic, bad instructions, emulation, s
software, and syscalls (plain and Mach). There is also RPC alert, but
I have no idea about what it is.
While we are there, remove some user ktrace in notification code, and add
a NODEF qualifier in mach_services.master: it will be used for notifications
and exceptions, where the kernel is always client and never server: we
don't want the message to be displayed as "unimplemented xxx" in kdump (thus
UNIMPL is not good), but we don't want to generate the server prototype
(therefore, STD is not good either). NODEF will declare it normally in the
name tables without creating the prototype.
2003-11-17 04:52:14 +03:00
|
|
|
if (req->req_mask & MACH_EXC_MASK_RPC_ALERT)
|
2003-12-06 18:15:19 +03:00
|
|
|
update_exception_port(med, MACH_EXC_RPC_ALERT, mp);
|
2003-04-06 01:18:02 +04:00
|
|
|
|
2003-11-17 16:20:06 +03:00
|
|
|
#ifdef DEBUG_MACH
|
2003-11-20 10:12:34 +03:00
|
|
|
if (req->req_mask & (MACH_EXC_ARITHMETIC |
|
|
|
|
MACH_EXC_EMULATION | MACH_EXC_MASK_SYSCALL |
|
2003-11-17 16:20:06 +03:00
|
|
|
MACH_EXC_MASK_MACH_SYSCALL | MACH_EXC_RPC_ALERT))
|
|
|
|
printf("mach_set_exception_ports: some exceptions are "
|
|
|
|
"not supported (mask %x)\n", req->req_mask);
|
|
|
|
#endif
|
|
|
|
|
2003-03-29 14:04:08 +03:00
|
|
|
*msglen = sizeof(*rep);
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_set_header(rep, req, *msglen);
|
|
|
|
|
|
|
|
rep->rep_retval = 0;
|
|
|
|
|
|
|
|
mach_set_trailer(rep, *msglen);
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-06 01:18:02 +04:00
|
|
|
int
|
|
|
|
mach_task_info(args)
|
|
|
|
struct mach_trap_args *args;
|
|
|
|
{
|
|
|
|
mach_task_info_request_t *req = args->smsg;
|
|
|
|
mach_task_info_reply_t *rep = args->rmsg;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct lwp *tl = args->tl;
|
2003-04-06 01:18:02 +04:00
|
|
|
size_t *msglen = args->rsize;
|
|
|
|
int count;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct proc *tp = tl->l_proc;
|
2003-04-06 01:18:02 +04:00
|
|
|
|
|
|
|
switch(req->req_flavor) {
|
|
|
|
case MACH_TASK_BASIC_INFO: {
|
|
|
|
struct mach_task_basic_info *mtbi;
|
|
|
|
struct rusage *ru;
|
|
|
|
|
2003-11-13 16:40:39 +03:00
|
|
|
count = sizeof(*mtbi) / sizeof(rep->rep_info[0]);
|
2003-04-06 01:18:02 +04:00
|
|
|
if (req->req_count < count)
|
|
|
|
return mach_msg_error(args, ENOBUFS);
|
|
|
|
|
2003-11-24 17:31:40 +03:00
|
|
|
ru = &tp->p_stats->p_ru;
|
2003-04-06 01:18:02 +04:00
|
|
|
mtbi = (struct mach_task_basic_info *)&rep->rep_info[0];
|
|
|
|
|
|
|
|
mtbi->mtbi_suspend_count = ru->ru_nvcsw + ru->ru_nivcsw;
|
|
|
|
mtbi->mtbi_virtual_size = ru->ru_ixrss;
|
|
|
|
mtbi->mtbi_resident_size = ru->ru_maxrss;
|
|
|
|
mtbi->mtbi_user_time.seconds = ru->ru_utime.tv_sec;
|
|
|
|
mtbi->mtbi_user_time.microseconds = ru->ru_utime.tv_usec;
|
|
|
|
mtbi->mtbi_system_time.seconds = ru->ru_stime.tv_sec;
|
|
|
|
mtbi->mtbi_system_time.microseconds = ru->ru_stime.tv_usec;
|
|
|
|
mtbi->mtbi_policy = 0;
|
|
|
|
|
2003-11-13 16:40:39 +03:00
|
|
|
*msglen = sizeof(*rep) - sizeof(rep->rep_info) + sizeof(*mtbi);
|
2003-04-06 01:18:02 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX this is supposed to be about threads, not processes... */
|
|
|
|
case MACH_TASK_THREAD_TIMES_INFO: {
|
|
|
|
struct mach_task_thread_times_info *mttti;
|
|
|
|
struct rusage *ru;
|
|
|
|
|
2003-11-13 16:40:39 +03:00
|
|
|
count = sizeof(*mttti) / sizeof(rep->rep_info[0]);
|
2003-04-06 01:18:02 +04:00
|
|
|
if (req->req_count < count)
|
|
|
|
return mach_msg_error(args, ENOBUFS);
|
|
|
|
|
2003-11-24 17:31:40 +03:00
|
|
|
ru = &tp->p_stats->p_ru;
|
2003-04-06 01:18:02 +04:00
|
|
|
mttti = (struct mach_task_thread_times_info *)&rep->rep_info[0];
|
|
|
|
|
|
|
|
mttti->mttti_user_time.seconds = ru->ru_utime.tv_sec;
|
|
|
|
mttti->mttti_user_time.microseconds = ru->ru_utime.tv_usec;
|
|
|
|
mttti->mttti_system_time.seconds = ru->ru_stime.tv_sec;
|
|
|
|
mttti->mttti_system_time.microseconds = ru->ru_stime.tv_usec;
|
|
|
|
|
2003-11-13 16:40:39 +03:00
|
|
|
*msglen = sizeof(*rep) - sizeof(rep->rep_info) + sizeof(*mttti);
|
2003-04-06 01:18:02 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX a few statistics missing here */
|
|
|
|
case MACH_TASK_EVENTS_INFO: {
|
|
|
|
struct mach_task_events_info *mtei;
|
|
|
|
struct rusage *ru;
|
|
|
|
|
2003-11-13 16:40:39 +03:00
|
|
|
count = sizeof(*mtei) / sizeof(rep->rep_info[0]);
|
2003-04-06 01:18:02 +04:00
|
|
|
if (req->req_count < count)
|
|
|
|
return mach_msg_error(args, ENOBUFS);
|
|
|
|
|
|
|
|
mtei = (struct mach_task_events_info *)&rep->rep_info[0];
|
2003-11-24 17:31:40 +03:00
|
|
|
ru = &tp->p_stats->p_ru;
|
2003-04-06 01:18:02 +04:00
|
|
|
|
|
|
|
mtei->mtei_faults = ru->ru_majflt;
|
|
|
|
mtei->mtei_pageins = ru->ru_minflt;
|
|
|
|
mtei->mtei_cow_faults = 0; /* XXX */
|
|
|
|
mtei->mtei_message_sent = ru->ru_msgsnd;
|
|
|
|
mtei->mtei_message_received = ru->ru_msgrcv;
|
|
|
|
mtei->mtei_syscalls_mach = 0; /* XXX */
|
|
|
|
mtei->mtei_syscalls_unix = 0; /* XXX */
|
|
|
|
mtei->mtei_csw = 0; /* XXX */
|
|
|
|
|
2003-11-13 16:40:39 +03:00
|
|
|
*msglen = sizeof(*rep) - sizeof(rep->rep_info) + sizeof(*mtei);
|
2003-04-06 01:18:02 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
uprintf("mach_task_info: unsupported flavor %d\n",
|
|
|
|
req->req_flavor);
|
|
|
|
return mach_msg_error(args, EINVAL);
|
|
|
|
};
|
|
|
|
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_set_header(rep, req, *msglen);
|
|
|
|
|
2003-04-06 01:18:02 +04:00
|
|
|
rep->rep_count = count;
|
2003-12-09 14:29:01 +03:00
|
|
|
|
|
|
|
mach_set_trailer(rep, *msglen);
|
2003-04-06 01:18:02 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-06 21:58:49 +04:00
|
|
|
int
|
|
|
|
mach_task_suspend(args)
|
|
|
|
struct mach_trap_args *args;
|
|
|
|
{
|
|
|
|
mach_task_suspend_request_t *req = args->smsg;
|
|
|
|
mach_task_suspend_reply_t *rep = args->rmsg;
|
|
|
|
size_t *msglen = args->rsize;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct lwp *tl = args->tl;
|
2003-11-15 20:44:38 +03:00
|
|
|
struct lwp *lp;
|
2003-04-06 21:58:49 +04:00
|
|
|
struct mach_emuldata *med;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct proc *tp = tl->l_proc;
|
2003-11-24 17:31:40 +03:00
|
|
|
|
|
|
|
med = tp->p_emuldata;
|
2003-04-06 21:58:49 +04:00
|
|
|
med->med_suspend++; /* XXX Mach also has a per thread semaphore */
|
|
|
|
|
2003-11-24 17:31:40 +03:00
|
|
|
LIST_FOREACH(lp, &tp->p_lwps, l_sibling) {
|
2003-11-15 20:44:38 +03:00
|
|
|
switch(lp->l_stat) {
|
|
|
|
case LSONPROC:
|
|
|
|
case LSRUN:
|
|
|
|
case LSSLEEP:
|
|
|
|
case LSSUSPENDED:
|
|
|
|
case LSZOMB:
|
|
|
|
case LSDEAD:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return mach_msg_error(args, 0);
|
|
|
|
break;
|
|
|
|
}
|
2003-04-06 21:58:49 +04:00
|
|
|
}
|
2003-11-28 02:44:49 +03:00
|
|
|
proc_stop(tp, 0);
|
2003-04-06 21:58:49 +04:00
|
|
|
|
|
|
|
*msglen = sizeof(*rep);
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_set_header(rep, req, *msglen);
|
|
|
|
|
|
|
|
rep->rep_retval = 0;
|
|
|
|
|
|
|
|
mach_set_trailer(rep, *msglen);
|
2003-04-06 21:58:49 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mach_task_resume(args)
|
|
|
|
struct mach_trap_args *args;
|
|
|
|
{
|
|
|
|
mach_task_resume_request_t *req = args->smsg;
|
|
|
|
mach_task_resume_reply_t *rep = args->rmsg;
|
|
|
|
size_t *msglen = args->rsize;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct lwp *tl = args->tl;
|
2003-04-06 21:58:49 +04:00
|
|
|
struct mach_emuldata *med;
|
2003-11-28 02:44:49 +03:00
|
|
|
struct proc *tp = tl->l_proc;
|
2003-04-06 21:58:49 +04:00
|
|
|
|
2003-11-24 17:31:40 +03:00
|
|
|
med = tp->p_emuldata;
|
2003-04-06 21:58:49 +04:00
|
|
|
med->med_suspend--; /* XXX Mach also has a per thread semaphore */
|
2003-11-15 20:44:38 +03:00
|
|
|
#if 0
|
2003-04-06 21:58:49 +04:00
|
|
|
if (med->med_suspend > 0)
|
|
|
|
return mach_msg_error(args, 0); /* XXX error code */
|
2003-11-15 20:44:38 +03:00
|
|
|
#endif
|
2003-04-06 21:58:49 +04:00
|
|
|
|
|
|
|
/* XXX We should also wake up the stopped thread... */
|
2003-11-24 17:31:40 +03:00
|
|
|
#ifdef DEBUG_MACH
|
|
|
|
printf("resuming pid %d\n", tp->p_pid);
|
|
|
|
#endif
|
|
|
|
(void)proc_unstop(tp);
|
2003-04-06 21:58:49 +04:00
|
|
|
|
2003-12-09 14:29:01 +03:00
|
|
|
*msglen = sizeof(*rep);
|
|
|
|
mach_set_header(rep, req, *msglen);
|
|
|
|
|
2003-11-11 20:26:32 +03:00
|
|
|
rep->rep_retval = 0;
|
2003-04-06 21:58:49 +04:00
|
|
|
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_set_trailer(rep, *msglen);
|
2003-04-06 21:58:49 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-11-30 23:42:03 +03:00
|
|
|
int
|
|
|
|
mach_task_terminate(args)
|
|
|
|
struct mach_trap_args *args;
|
|
|
|
{
|
|
|
|
mach_task_resume_request_t *req = args->smsg;
|
|
|
|
mach_task_resume_reply_t *rep = args->rmsg;
|
|
|
|
size_t *msglen = args->rsize;
|
|
|
|
struct lwp *tl = args->tl;
|
|
|
|
struct sys_exit_args cup;
|
|
|
|
register_t retval;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
|
|
SCARG(&cup, rval) = 0;
|
|
|
|
error = sys_exit(tl, &cup, &retval);
|
|
|
|
|
2003-12-09 14:29:01 +03:00
|
|
|
*msglen = sizeof(*rep);
|
|
|
|
mach_set_header(rep, req, *msglen);
|
|
|
|
|
2003-11-30 23:42:03 +03:00
|
|
|
rep->rep_retval = native_to_mach_errno[error];
|
|
|
|
|
2003-12-09 14:29:01 +03:00
|
|
|
mach_set_trailer(rep, *msglen);
|
2003-11-30 23:42:03 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-29 14:04:08 +03:00
|
|
|
int
|
|
|
|
mach_sys_task_for_pid(l, v, retval)
|
|
|
|
struct lwp *l;
|
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct mach_sys_task_for_pid_args /* {
|
|
|
|
syscallarg(mach_port_t) target_tport;
|
|
|
|
syscallarg(int) pid;
|
|
|
|
syscallarg(mach_port_t) *t;
|
|
|
|
} */ *uap = v;
|
|
|
|
struct mach_right *mr;
|
|
|
|
struct mach_emuldata *med;
|
2003-11-22 20:17:55 +03:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
struct proc *t;
|
2003-03-29 14:04:08 +03:00
|
|
|
int error;
|
|
|
|
|
2003-11-22 20:17:55 +03:00
|
|
|
/*
|
|
|
|
* target_tport is used because the task may be on
|
|
|
|
* a different host. (target_tport, pid) is unique.
|
2003-12-18 04:10:20 +03:00
|
|
|
* We don't support multiple-host configuration
|
|
|
|
* yet, so this parameter should be useless.
|
2003-11-22 20:17:55 +03:00
|
|
|
* However, we still validate it.
|
|
|
|
*/
|
2003-03-29 14:04:08 +03:00
|
|
|
if ((mr = mach_right_check(SCARG(uap, target_tport),
|
|
|
|
l, MACH_PORT_TYPE_ALL_RIGHTS)) == NULL)
|
|
|
|
return EPERM;
|
|
|
|
|
2003-11-22 20:17:55 +03:00
|
|
|
if ((t = pfind(SCARG(uap, pid))) == NULL)
|
2003-03-29 14:04:08 +03:00
|
|
|
return ESRCH;
|
2003-11-22 20:17:55 +03:00
|
|
|
|
|
|
|
/* Allowed only if the UID match, if setuid, or if superuser */
|
|
|
|
if ((t->p_cred->p_ruid != p->p_cred->p_ruid ||
|
|
|
|
ISSET(t->p_flag, P_SUGID)) &&
|
|
|
|
(error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
|
|
|
return (error);
|
2003-03-29 14:04:08 +03:00
|
|
|
|
|
|
|
/* This will only work on a Mach process */
|
2003-11-22 20:17:55 +03:00
|
|
|
if ((t->p_emul != &emul_mach) &&
|
2003-03-29 14:04:08 +03:00
|
|
|
#ifdef COMPAT_DARWIN
|
2003-11-22 20:17:55 +03:00
|
|
|
(t->p_emul != &emul_darwin) &&
|
2003-03-29 14:04:08 +03:00
|
|
|
#endif
|
|
|
|
1)
|
|
|
|
return EINVAL;
|
|
|
|
|
2003-11-22 20:17:55 +03:00
|
|
|
med = t->p_emuldata;
|
2003-03-29 14:04:08 +03:00
|
|
|
|
2003-11-22 20:17:55 +03:00
|
|
|
if ((mr = mach_right_get(med->med_kernel, l,
|
2003-03-29 14:04:08 +03:00
|
|
|
MACH_PORT_TYPE_SEND, 0)) == NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
if ((error = copyout(&mr->mr_name, SCARG(uap, t),
|
|
|
|
sizeof(mr->mr_name))) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2003-11-24 17:31:40 +03:00
|
|
|
|