diff --git a/sys/compat/mach/mach_errno.c b/sys/compat/mach/mach_errno.c index 70b8ce9955e5..bf45e88cfb8d 100644 --- a/sys/compat/mach/mach_errno.c +++ b/sys/compat/mach/mach_errno.c @@ -1,4 +1,4 @@ -/* $NetBSD: mach_errno.c,v 1.1 2002/11/11 01:18:44 manu Exp $ */ +/* $NetBSD: mach_errno.c,v 1.2 2002/11/12 05:18:31 manu Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -37,8 +37,13 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mach_errno.c,v 1.1 2002/11/11 01:18:44 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mach_errno.c,v 1.2 2002/11/12 05:18:31 manu Exp $"); +#include +#include + +#include +#include #include int native_to_mach_errno[] = { @@ -129,3 +134,23 @@ int native_to_mach_errno[] = { MACH_KERN_FAILURE, /* EOVERFLOW */ MACH_KERN_FAILURE, /* EILSEQ */ /* 85 */ }; + +int +mach_msg_error(msgh, req, rep, error) + mach_msg_header_t *msgh; + mach_msg_header_t *req; + mach_error_reply_t *rep; + int 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->msgh_local_port; + rep->rep_msgh.msgh_id = req->msgh_id + 100; + rep->rep_retval = native_to_mach_errno[error]; + rep->rep_trailer.msgh_trailer_size = 8; + + return copyout(rep, msgh, sizeof(*rep)); +} diff --git a/sys/compat/mach/mach_errno.h b/sys/compat/mach/mach_errno.h index 79e5291d407c..14cfdfd4c4a2 100644 --- a/sys/compat/mach/mach_errno.h +++ b/sys/compat/mach/mach_errno.h @@ -1,4 +1,4 @@ -/* $NetBSD: mach_errno.h,v 1.1 2002/11/11 01:18:44 manu Exp $ */ + /* $NetBSD: mach_errno.h,v 1.2 2002/11/12 05:18:31 manu Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -92,4 +92,18 @@ extern int native_to_mach_errno[]; #define MACH_KERN_NOT_WAITING 48 #define MACH_KERN_OPERATION_TIMED_OUT 49 +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_error_reply_t; + +#define MACH_MSG_ERROR(msgh,req,rep,error) \ + mach_msg_error((msgh), (mach_msg_header_t *)(req), \ + (mach_error_reply_t *)(rep), (error)) + +int mach_msg_error __P((mach_msg_header_t *, + mach_msg_header_t *, mach_error_reply_t *, int)); + #endif /* _MACH_ERRNO_H_ */ diff --git a/sys/compat/mach/mach_task.c b/sys/compat/mach/mach_task.c index 4b897c0f6606..1b1adbd6fb5f 100644 --- a/sys/compat/mach/mach_task.c +++ b/sys/compat/mach/mach_task.c @@ -1,4 +1,4 @@ -/* $NetBSD: mach_task.c,v 1.3 2002/11/11 09:28:00 manu Exp $ */ +/* $NetBSD: mach_task.c,v 1.4 2002/11/12 05:18:31 manu Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -37,14 +37,19 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mach_task.c,v 1.3 2002/11/11 09:28:00 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mach_task.c,v 1.4 2002/11/12 05:18:31 manu Exp $"); #include #include +#include #include +#include +#include + #include #include +#include #include #include @@ -86,10 +91,20 @@ mach_ports_lookup(p, msgh) { mach_ports_lookup_request_t req; mach_ports_lookup_reply_t rep; + struct exec_vmcmd evc; int error; if ((error = copyin(msgh, &req, sizeof(req))) != 0) return error; + + bzero(&evc, sizeof(evc)); + evc.ev_addr = 0x00008000; + evc.ev_len = PAGE_SIZE; + evc.ev_prot = UVM_PROT_RW; + evc.ev_proc = *vmcmd_map_zero; + + if ((error = (*evc.ev_proc)(p, &evc)) != 0) + return MACH_MSG_ERROR(msgh, &req, &rep, error); bzero(&rep, sizeof(rep)); @@ -100,11 +115,12 @@ mach_ports_lookup(p, msgh) 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_msgh_body.msgh_descriptor_count = 1; /* XXX why ? */ - rep.rep_init_port_set.address = (void *)0x8000; /* XXX why? */ + rep.rep_init_port_set.address = (void *)evc.ev_addr; rep.rep_init_port_set.count = 3; /* XXX why ? */ rep.rep_init_port_set.copy = 2; /* XXX why ? */ rep.rep_init_port_set.disposition = 0x11; /* XXX why? */ rep.rep_init_port_set.type = 2; /* XXX why? */ + rep.rep_init_port_set_count = 3; /* XXX why? */ rep.rep_trailer.msgh_trailer_size = 8; if ((error = copyout(&rep, msgh, sizeof(rep))) != 0) diff --git a/sys/compat/mach/mach_vm.c b/sys/compat/mach/mach_vm.c index 849237053181..67eaa288fdff 100644 --- a/sys/compat/mach/mach_vm.c +++ b/sys/compat/mach/mach_vm.c @@ -1,4 +1,4 @@ -/* $NetBSD: mach_vm.c,v 1.4 2002/11/11 09:28:00 manu Exp $ */ +/* $NetBSD: mach_vm.c,v 1.5 2002/11/12 05:18:32 manu Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -37,14 +37,16 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.4 2002/11/11 09:28:00 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.5 2002/11/12 05:18:32 manu Exp $"); #include #include #include #include #include +#include #include + #include #include @@ -67,16 +69,18 @@ mach_vm_map(p, msgh) bzero(&rep, sizeof(rep)); + DPRINTF(("vm_map(addr = %p, size = 0x%08x)\n", + (void *)req.req_address, req.req_size)); SCARG(&cup, addr) = (void *)req.req_address; SCARG(&cup, len) = req.req_size; - SCARG(&cup, prot) = req.req_cur_protection; /* XXX */ - SCARG(&cup, flags) = req.req_flags; /* XXX */ - SCARG(&cup, fd) = 0; /* XXX */ - SCARG(&cup, pos) = (off_t)req.req_offset; + SCARG(&cup, prot) = PROT_READ | PROT_WRITE; + SCARG(&cup, flags) = MAP_ANON | MAP_FIXED; + SCARG(&cup, fd) = -1; + SCARG(&cup, pos) = 0; if ((error = sys_mmap(p, &cup, &rep.rep_retval)) != 0) - rep.rep_retval = native_to_mach_errno[error]; - + return MACH_MSG_ERROR(msgh, &req, &rep, error); + 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); @@ -108,8 +112,8 @@ mach_vm_deallocate(p, msgh) SCARG(&cup, len) = req.req_size; if ((error = sys_munmap(p, &cup, &rep.rep_retval)) != 0) - rep.rep_retval = native_to_mach_errno[error]; - + return MACH_MSG_ERROR(msgh, &req, &rep, error); + 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);