mach_ports_lookup allocate one page of memory and returns its address.

On error, most traps return a short packet with just an error code, emulate
this correctly.
This commit is contained in:
manu 2002-11-12 05:18:31 +00:00
parent f2cc0d2ae5
commit 3eb20e3576
4 changed files with 75 additions and 16 deletions

View File

@ -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 <sys/cdefs.h>
__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 <sys/types.h>
#include <sys/systm.h>
#include <compat/mach/mach_types.h>
#include <compat/mach/mach_message.h>
#include <compat/mach/mach_errno.h>
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));
}

View File

@ -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_ */

View File

@ -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 <sys/cdefs.h>
__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 <sys/types.h>
#include <sys/param.h>
#include <sys/exec.h>
#include <sys/systm.h>
#include <uvm/uvm_extern.h>
#include <uvm/uvm_param.h>
#include <compat/mach/mach_types.h>
#include <compat/mach/mach_message.h>
#include <compat/mach/mach_errno.h>
#include <compat/mach/mach_task.h>
#include <compat/mach/mach_syscallargs.h>
@ -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)

View File

@ -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 <sys/cdefs.h>
__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 <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mount.h>
#include <sys/proc.h>
#include <sys/mman.h>
#include <sys/syscallargs.h>
#include <compat/mach/mach_types.h>
#include <compat/mach/mach_message.h>
@ -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);