Added a few Mach traps: mach_boostrap_register, mach_port_set_attributes,

mach_port_move_member, mach_port_set_attributes, mach_task_set_special_port,
(none do anything)
Added mach_thread_create_running, which creates a new Mach thread. It
provides the register context of the new thread. We use it in a child
function provided to fork1(). The child function is machine dependent and
is not yet implemented for i386.

The new thread crashes quickly, but at least it starts.
This commit is contained in:
manu 2002-12-12 00:29:23 +00:00
parent 39387a63f4
commit 66a29c52af
9 changed files with 234 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_machdep.c,v 1.5 2002/11/17 01:24:03 manu Exp $ */
/* $NetBSD: mach_machdep.c,v 1.6 2002/12/12 00:29:23 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mach_machdep.c,v 1.5 2002/11/17 01:24:03 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: mach_machdep.c,v 1.6 2002/12/12 00:29:23 manu Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -58,11 +58,14 @@ __KERNEL_RCSID(0, "$NetBSD: mach_machdep.c,v 1.5 2002/11/17 01:24:03 manu Exp $"
#include <compat/mach/mach_types.h>
#include <compat/mach/mach_host.h>
#include <compat/mach/mach_thread.h>
#include <machine/cpu.h>
#include <machine/psl.h>
#include <machine/reg.h>
#include <machine/frame.h>
#include <machine/vmparam.h>
#include <machine/macho_machdep.h>
#include <uvm/uvm_extern.h>
@ -99,7 +102,7 @@ mach_trap(frame)
void
mach_host_basic_info(info)
struct mach_host_basic_info *info;
struct mach_host_basic_info *info;
{
/* XXX fill this accurately */
info->max_cpus = 1; /* XXX */
@ -108,3 +111,43 @@ mach_host_basic_info(info)
info->cpu_type = MACHO_CPU_TYPE_POWERPC;
info->cpu_subtype = (mfpvr() >> 16);
}
void
mach_create_thread_child(arg)
void *arg;
{
struct mach_create_thread_child_args *mctc;
struct trapframe *tf;
struct exec_macho_powerpc_thread_state *regs;
mctc = (struct mach_create_thread_child_args *)arg;
if (mctc->mctc_flavor != MACHO_POWERPC_THREAD_STATE)
uprintf("mach_create_thread_child: unknown flavor %d\n",
mctc->mctc_flavor);
tf = trapframe(*mctc->mctc_proc);
regs = (struct exec_macho_powerpc_thread_state *)mctc->mctc_state;
/* Security warning */
if ((regs->srr1 & PSL_USERSTATIC) != (tf->srr1 & PSL_USERSTATIC))
uprintf("mach_create_thread_child: PSL_USERSTATIC changed\n");
/* Set requested register context */
tf->srr0 = regs->srr0;
tf->srr1 = ((regs->srr1 & ~PSL_USERSTATIC) |
(tf->srr1 & PSL_USERSTATIC));
memcpy(&regs->r0, &tf->fixreg[0], 32 * sizeof(register_t));
tf->cr = regs->cr;
tf->xer = regs->xer;
tf->lr = regs->lr;
tf->ctr = regs->ctr;
/* XXX what should we do with regs->mq ? */
tf->vrsave = regs->vrsave;
/* Wakeup the parent */
mctc->mctc_child_done = 1;
wakeup(&mctc->mctc_child_done);
return;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_namemap.c,v 1.9 2002/12/11 21:23:37 manu Exp $ */
/* $NetBSD: mach_namemap.c,v 1.10 2002/12/12 00:29:24 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mach_namemap.c,v 1.9 2002/12/11 21:23:37 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: mach_namemap.c,v 1.10 2002/12/12 00:29:24 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -56,16 +56,20 @@ struct mach_subsystem_namemap mach_namemap[] = {
{ 200, mach_host_info, "host_info" },
{ 202, mach_host_page_size,"host_page_size" },
{ 206, mach_host_get_clock_service, "host_get_clock_service" },
/* { 403, mach_boostrap_register, "boostrap_register" }, */
{ 404, mach_bootstrap_look_up, "bootstrap_look_up" },
{ 1000, mach_clock_get_time, "clock_get_time" },
{ 3201, mach_port_type, "port_type" },
{ 3204, mach_port_allocate, "port_allocate" },
{ 3206, mach_port_deallocate, "port_deallocate" },
{ 3218, mach_port_set_attributes, "port_set_attributes" },
{ 3212, mach_port_move_member, "port_move_member" },
{ 3214, mach_port_insert_right, "port_insert_right" },
{ 3218, mach_port_set_attributes, "port_set_attributes" },
{ 3226, mach_port_insert_member, "port_insert_member" },
{ 3404, mach_ports_lookup, "ports_lookup" },
{ 3409, mach_task_get_special_port, "task_get_special_port" },
{ 3410, mach_task_set_special_port, "task_set_special_port" },
{ 3412, mach_thread_create_running, "thread_create_running" },
{ 3616, mach_thread_policy, "thread_policy" },
{ 3801, mach_vm_allocate, "vm_allocate" },
{ 3802, mach_vm_deallocate, "vm_deallocate" },

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_port.c,v 1.13 2002/12/10 21:36:45 manu Exp $ */
/* $NetBSD: mach_port.c,v 1.14 2002/12/12 00:29:24 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mach_port.c,v 1.13 2002/12/10 21:36:45 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: mach_port.c,v 1.14 2002/12/12 00:29:24 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -263,3 +263,30 @@ mach_port_insert_member(p, msgh, maxlen, dst)
return MACH_MSG_RETURN(p, &rep, msgh, sizeof(rep), maxlen, dst);
}
int
mach_port_move_member(p, msgh, maxlen, dst)
struct proc *p;
mach_msg_header_t *msgh;
size_t maxlen;
mach_msg_header_t *dst;
{
mach_port_insert_member_request_t req;
mach_port_insert_member_reply_t rep;
int error;
if ((error = copyin(msgh, &req, sizeof(req))) != 0)
return error;
bzero(&rep, sizeof(rep));
rep.rep_msgh.msgh_bits =
MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
rep.rep_msgh.msgh_size = sizeof(rep) - sizeof(rep.rep_trailer);
rep.rep_msgh.msgh_local_port = req.req_msgh.msgh_local_port;
rep.rep_msgh.msgh_id = req.req_msgh.msgh_id + 100;
rep.rep_trailer.msgh_trailer_size = 8;
return MACH_MSG_RETURN(p, &rep, msgh, sizeof(rep), maxlen, dst);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_port.h,v 1.5 2002/12/10 21:36:45 manu Exp $ */
/* $NetBSD: mach_port.h,v 1.6 2002/12/12 00:29:24 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -161,6 +161,22 @@ typedef struct {
mach_msg_trailer_t rep_trailer;
} mach_port_insert_member_reply_t;
/* port_move_member */
typedef struct {
mach_msg_header_t req_msgh;
mach_ndr_record_t req_ndr;
mach_port_name_t req_member;
mach_port_name_t req_after;
} mach_port_move_member_request_t;
typedef struct {
mach_msg_header_t rep_msgh;
mach_ndr_record_t rep_ndr;
mach_kern_return_t rep_retval;
mach_msg_trailer_t rep_trailer;
} mach_port_move_member_reply_t;
int mach_port_deallocate(struct proc *, mach_msg_header_t *,
size_t, mach_msg_header_t *);
int mach_port_allocate(struct proc *, mach_msg_header_t *,
@ -173,5 +189,7 @@ int mach_port_set_attributes(struct proc *, mach_msg_header_t *,
size_t, mach_msg_header_t *);
int mach_port_insert_member(struct proc *, mach_msg_header_t *,
size_t, mach_msg_header_t *);
int mach_port_move_member(struct proc *, mach_msg_header_t *,
size_t, mach_msg_header_t *);
#endif /* _MACH_PORT_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_task.c,v 1.9 2002/12/09 21:53:28 manu Exp $ */
/* $NetBSD: mach_task.c,v 1.10 2002/12/12 00:29:24 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mach_task.c,v 1.9 2002/12/09 21:53:28 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: mach_task.c,v 1.10 2002/12/12 00:29:24 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -129,4 +129,28 @@ mach_ports_lookup(p, msgh, maxlen, dst)
return MACH_MSG_RETURN(p, &rep, msgh, sizeof(rep), maxlen, dst);
}
int
mach_task_set_special_port(p, msgh, maxlen, dst)
struct proc *p;
mach_msg_header_t *msgh;
size_t maxlen;
mach_msg_header_t *dst;
{
mach_task_set_special_port_request_t req;
mach_task_set_special_port_reply_t rep;
int error;
if ((error = copyin(msgh, &req, sizeof(req))) != 0)
return error;
bzero(&rep, sizeof(rep));
rep.rep_msgh.msgh_bits =
MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
rep.rep_msgh.msgh_size = sizeof(rep) - sizeof(rep.rep_trailer);
rep.rep_msgh.msgh_local_port = req.req_msgh.msgh_local_port;
rep.rep_msgh.msgh_id = req.req_msgh.msgh_id + 100;
rep.rep_trailer.msgh_trailer_size = 8;
return MACH_MSG_RETURN(p, &rep, msgh, sizeof(rep), maxlen, dst);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_task.h,v 1.2 2002/11/28 21:21:33 manu Exp $ */
/* $NetBSD: mach_task.h,v 1.3 2002/12/12 00:29:24 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -69,9 +69,28 @@ typedef struct {
mach_msg_trailer_t rep_trailer;
} mach_ports_lookup_reply_t;
/* mach_set_special_port */
typedef struct {
mach_msg_header_t req_msgh;
mach_msg_body_t req_msgh_body;
mach_msg_port_descriptor_t req_special_port;
mach_ndr_record_t req_ndr;
int req_which_port;
} mach_task_set_special_port_request_t;
typedef struct {
mach_msg_header_t rep_msgh;
mach_ndr_record_t rep_ndr;
mach_kern_return_t rep_retval;
mach_msg_trailer_t rep_trailer;
} mach_task_set_special_port_reply_t;
int mach_task_get_special_port(struct proc *, mach_msg_header_t *,
size_t, mach_msg_header_t *);
int mach_ports_lookup(struct proc *, mach_msg_header_t *,
size_t, mach_msg_header_t *);
int mach_task_set_special_port(struct proc *, mach_msg_header_t *,
size_t, mach_msg_header_t *);
#endif /* _MACH_TASK_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_thread.c,v 1.3 2002/12/09 21:29:25 manu Exp $ */
/* $NetBSD: mach_thread.c,v 1.4 2002/12/12 00:29:24 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mach_thread.c,v 1.3 2002/12/09 21:29:25 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: mach_thread.c,v 1.4 2002/12/12 00:29:24 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -49,6 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: mach_thread.c,v 1.3 2002/12/09 21:29:25 manu Exp $")
#include <compat/mach/mach_message.h>
#include <compat/mach/mach_clock.h>
#include <compat/mach/mach_thread.h>
#include <compat/mach/mach_errno.h>
#include <compat/mach/mach_syscallargs.h>
int
@ -77,3 +78,57 @@ mach_thread_policy(p, msgh, maxlen, dst)
return MACH_MSG_RETURN(p, &rep, msgh, sizeof(rep), maxlen, dst);
}
int
mach_thread_create_running(p, msgh, maxlen, dst)
struct proc *p;
mach_msg_header_t *msgh;
size_t maxlen;
mach_msg_header_t *dst;
{
mach_thread_create_running_request_t req;
mach_thread_create_running_reply_t rep;
struct mach_create_thread_child_args mctc;
register_t retval;
struct proc *child;
int flags;
int error;
if ((error = copyin(msgh, &req, sizeof(req))) != 0)
return error;
/*
* Prepare the data we want to transmit to the child
*/
mctc.mctc_proc = &child;
mctc.mctc_flavor = req.req_flavor;
mctc.mctc_child_done = 0;
mctc.mctc_state = req.req_state;
flags = (FORK_SHAREVM | FORK_SHARECWD |
FORK_SHAREFILES | FORK_SHARESIGS);
error = fork1(p, flags, SIGCHLD, NULL, 0,
mach_create_thread_child, (void *)&mctc, &retval, &child);
if (error != 0)
return MACH_MSG_ERROR(p, msgh, &req, &rep, error, maxlen, dst);
/*
* The child relies on some values in mctc, so we should not
* exit until it is finished with it. We loop to avoid
* spurious wakeups due to signals.
*/
while(mctc.mctc_child_done == 0)
(void)tsleep(&mctc.mctc_child_done, PZERO, "mach_thread", 0);
bzero(&rep, sizeof(rep));
rep.rep_msgh.msgh_bits =
MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE);
rep.rep_msgh.msgh_size = sizeof(rep) - sizeof(rep.rep_trailer);
rep.rep_msgh.msgh_local_port = req.req_msgh.msgh_local_port;
rep.rep_msgh.msgh_id = req.req_msgh.msgh_id + 100;
/* XXX do something for rep.rep_child_act */
rep.rep_trailer.msgh_trailer_size = 8;
return MACH_MSG_RETURN(p, &rep, msgh, sizeof(rep), maxlen, dst);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_thread.h,v 1.2 2002/11/28 21:21:33 manu Exp $ */
/* $NetBSD: mach_thread.h,v 1.3 2002/12/12 00:29:24 manu Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -47,6 +47,13 @@
#include <compat/mach/mach_types.h>
#include <compat/mach/mach_message.h>
struct mach_create_thread_child_args {
struct proc **mctc_proc;
int mctc_flavor;
mach_natural_t *mctc_state;
int mctc_child_done;
};
/* thread_policy */
typedef int mach_policy_t;
@ -66,7 +73,27 @@ typedef struct {
mach_msg_trailer_t rep_trailer;
} mach_thread_policy_reply_t;
/* mach_thread_create_running */
typedef struct {
mach_msg_header_t req_msgh;
mach_ndr_record_t req_ndr;
mach_thread_state_flavor_t req_flavor;
mach_msg_type_number_t req_count;
mach_natural_t req_state[144];
} mach_thread_create_running_request_t;
typedef struct {
mach_msg_header_t rep_msgh;
mach_msg_body_t rep_body;
mach_msg_port_descriptor_t rep_child_act;
mach_msg_trailer_t rep_trailer;
} mach_thread_create_running_reply_t;
int mach_thread_policy(struct proc *, mach_msg_header_t *,
size_t, mach_msg_header_t *);
int mach_thread_create_running(struct proc *, mach_msg_header_t *,
size_t, mach_msg_header_t *);
void mach_create_thread_child(void *);
#endif /* _MACH_THREAD_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_types.h,v 1.9 2002/12/07 21:23:04 manu Exp $ */
/* $NetBSD: mach_types.h,v 1.10 2002/12/12 00:29:24 manu Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -55,6 +55,7 @@ typedef int mach_port_right_t;
typedef int mach_vm_address_t;
typedef int mach_vm_inherit_t;
typedef int mach_vm_prot_t;
typedef int mach_thread_state_flavor_t;
typedef unsigned int mach_natural_t;
typedef unsigned int mach_vm_size_t;
typedef unsigned long mach_vm_offset_t;