From f130f7a839530d097af9be5e97f6bf1ef6d29755 Mon Sep 17 00:00:00 2001 From: manu Date: Tue, 12 Nov 2002 06:14:39 +0000 Subject: [PATCH] In mach_reply_port, don't increment the returned port for now, this confuses the binary on the second launch. In mach_vm_map, hack in a failure so that we fail exactly like Darwin when mapping a page at address 0 Add vm_allocate trap --- sys/compat/mach/mach_errno.c | 6 ++--- sys/compat/mach/mach_host.c | 8 +++--- sys/compat/mach/mach_namemap.c | 5 ++-- sys/compat/mach/mach_port.c | 6 ++--- sys/compat/mach/mach_vm.c | 48 ++++++++++++++++++++++++++++++++-- sys/compat/mach/mach_vm.h | 21 ++++++++++++++- 6 files changed, 79 insertions(+), 15 deletions(-) diff --git a/sys/compat/mach/mach_errno.c b/sys/compat/mach/mach_errno.c index bf45e88cfb8d..c25171b22932 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.2 2002/11/12 05:18:31 manu Exp $ */ +/* $NetBSD: mach_errno.c,v 1.3 2002/11/12 06:14:39 manu Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mach_errno.c,v 1.2 2002/11/12 05:18:31 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mach_errno.c,v 1.3 2002/11/12 06:14:39 manu Exp $"); #include #include @@ -59,7 +59,7 @@ int native_to_mach_errno[] = { MACH_KERN_FAILURE, /* EBADF */ MACH_KERN_FAILURE, /* ECHILD */ /* 10 */ MACH_KERN_FAILURE, /* EDEADLK */ - MACH_KERN_FAILURE, /* ENOMEM */ + MACH_KERN_NO_SPACE, /* ENOMEM */ MACH_KERN_FAILURE, /* EACCES */ MACH_KERN_INVALID_ADDRESS, /* EFAULT */ MACH_KERN_FAILURE, /* ENOTBLK */ /* 15 */ diff --git a/sys/compat/mach/mach_host.c b/sys/compat/mach/mach_host.c index e17937f9dfdc..5689bb795bda 100644 --- a/sys/compat/mach/mach_host.c +++ b/sys/compat/mach/mach_host.c @@ -1,4 +1,4 @@ -/* $NetBSD: mach_host.c,v 1.6 2002/11/11 09:28:00 manu Exp $ */ +/* $NetBSD: mach_host.c,v 1.7 2002/11/12 06:14:39 manu Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.6 2002/11/11 09:28:00 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.7 2002/11/12 06:14:39 manu Exp $"); #include #include @@ -86,8 +86,8 @@ mach_host_info(p, msgh) info->max_cpus = 1; /* XXX fill this accurately */ info->avail_cpus = 1; info->memory_size = uvmexp.active + uvmexp.inactive; - info->cpu_type = 0; - info->cpu_subtype = 0; + info->cpu_type = 12; + info->cpu_subtype = 9; break; } diff --git a/sys/compat/mach/mach_namemap.c b/sys/compat/mach/mach_namemap.c index 584e7aca72cd..35cc6263b362 100644 --- a/sys/compat/mach/mach_namemap.c +++ b/sys/compat/mach/mach_namemap.c @@ -1,4 +1,4 @@ -/* $NetBSD: mach_namemap.c,v 1.3 2002/11/10 21:53:40 manu Exp $ */ +/* $NetBSD: mach_namemap.c,v 1.4 2002/11/12 06:14:39 manu Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mach_namemap.c,v 1.3 2002/11/10 21:53:40 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mach_namemap.c,v 1.4 2002/11/12 06:14:39 manu Exp $"); #include #include @@ -57,6 +57,7 @@ struct mach_subsystem_namemap mach_namemap[] = { { 3206, mach_port_deallocate, "port_deallocate" }, { 3404, mach_ports_lookup, "ports_lookup" }, { 3409, mach_task_get_special_port, "task_get_special_port" }, + { 3801, mach_vm_allocate, "vm_allocate" }, { 3802, mach_vm_deallocate, "vm_deallocate" }, { 3812, mach_vm_map, "vm_map" }, { 0, NULL, NULL }, diff --git a/sys/compat/mach/mach_port.c b/sys/compat/mach/mach_port.c index 7805618e24a7..b33cd114557a 100644 --- a/sys/compat/mach/mach_port.c +++ b/sys/compat/mach/mach_port.c @@ -1,4 +1,4 @@ -/* $NetBSD: mach_port.c,v 1.3 2002/11/11 09:28:00 manu Exp $ */ +/* $NetBSD: mach_port.c,v 1.4 2002/11/12 06:14:39 manu Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mach_port.c,v 1.3 2002/11/11 09:28:00 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mach_port.c,v 1.4 2002/11/12 06:14:39 manu Exp $"); #include #include @@ -58,7 +58,7 @@ mach_sys_reply_port(p, v, retval) { static int current_port = 0x80b; - *retval = current_port++; /* XXX */ + *retval = current_port; /* XXX */ return 0; } diff --git a/sys/compat/mach/mach_vm.c b/sys/compat/mach/mach_vm.c index 67eaa288fdff..486d7290d518 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.5 2002/11/12 05:18:32 manu Exp $ */ +/* $NetBSD: mach_vm.c,v 1.6 2002/11/12 06:14:39 manu Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.5 2002/11/12 05:18:32 manu Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.6 2002/11/12 06:14:39 manu Exp $"); #include #include @@ -67,6 +67,12 @@ mach_vm_map(p, msgh) if ((error = copyin(msgh, &req, sizeof(req))) != 0) return error; +#if 1 + /* XXX Darwin fails on mapping a page at address 0 */ + if (req.req_address == 0) + return MACH_MSG_ERROR(msgh, &req, &rep, ENOMEM); +#endif + bzero(&rep, sizeof(rep)); DPRINTF(("vm_map(addr = %p, size = 0x%08x)\n", @@ -93,6 +99,44 @@ mach_vm_map(p, msgh) return 0; } +int +mach_vm_allocate(p, msgh) + struct proc *p; + mach_msg_header_t *msgh; +{ + mach_vm_allocate_request_t req; + mach_vm_allocate_reply_t rep; + struct sys_mmap_args cup; + int error; + + if ((error = copyin(msgh, &req, sizeof(req))) != 0) + return error; + + bzero(&rep, sizeof(rep)); + + SCARG(&cup, addr) = (caddr_t)req.req_address; + SCARG(&cup, len) = req.req_size; + SCARG(&cup, prot) = PROT_READ | PROT_WRITE; + SCARG(&cup, flags) = MAP_ANON; + if (req.req_flags) + SCARG(&cup, flags) |= MAP_FIXED; + SCARG(&cup, fd) = -1; + SCARG(&cup, pos) = 0; + + if ((error = sys_mmap(p, &cup, &rep.rep_address)) != 0) + 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); + 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; + + if ((error = copyout(&rep, msgh, sizeof(rep))) != 0) + return error; + return 0; +} int mach_vm_deallocate(p, msgh) struct proc *p; diff --git a/sys/compat/mach/mach_vm.h b/sys/compat/mach/mach_vm.h index 0c92813d7a2d..634b0d6305a3 100644 --- a/sys/compat/mach/mach_vm.h +++ b/sys/compat/mach/mach_vm.h @@ -1,4 +1,4 @@ -/* $NetBSD: mach_vm.h,v 1.1 2002/11/10 21:53:41 manu Exp $ */ +/* $NetBSD: mach_vm.h,v 1.2 2002/11/12 06:14:39 manu Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -72,6 +72,24 @@ typedef struct { mach_msg_trailer_t rep_trailer; } mach_vm_map_reply_t; +/* vm_allocate */ +typedef struct { + mach_msg_header_t req_msgh; + mach_ndr_record_t req_ndr; + mach_vm_address_t req_address; + mach_vm_size_t req_size; + int req_flags; +} mach_vm_allocate_request_t; + + +typedef struct { + mach_msg_header_t rep_msgh; + mach_ndr_record_t rep_ndr; + mach_kern_return_t rep_retval; + mach_vm_address_t rep_address; + mach_msg_trailer_t rep_trailer; +} mach_vm_allocate_reply_t; + /* vm_deallocate */ typedef struct { @@ -89,6 +107,7 @@ typedef struct { } mach_vm_deallocate_reply_t; int mach_vm_map __P((struct proc *, mach_msg_header_t *)); +int mach_vm_allocate __P((struct proc *, mach_msg_header_t *)); int mach_vm_deallocate __P((struct proc *, mach_msg_header_t *)); #endif /* _MACH_VM_H_ */