Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Implment map_fd mach trap



details:   https://anonhg.NetBSD.org/src/rev/176ddeef0f60
branches:  trunk
changeset: 539413:176ddeef0f60
user:      manu <manu%NetBSD.org@localhost>
date:      Sat Nov 16 20:00:29 2002 +0000

description:
Implment map_fd mach trap
Fix host_info(BASIC_INFO) which was broken wrt to the number of field
returned.

diffstat:

 sys/arch/powerpc/powerpc/mach_machdep.c |  12 ++--
 sys/compat/mach/mach_host.c             |  12 +++-
 sys/compat/mach/mach_misc.c             |  17 +-----
 sys/compat/mach/mach_vm.c               |  89 ++++++++++++++++++++++++++++++++-
 4 files changed, 105 insertions(+), 25 deletions(-)

diffs (220 lines):

diff -r a07fe60fd4f0 -r 176ddeef0f60 sys/arch/powerpc/powerpc/mach_machdep.c
--- a/sys/arch/powerpc/powerpc/mach_machdep.c   Sat Nov 16 19:59:19 2002 +0000
+++ b/sys/arch/powerpc/powerpc/mach_machdep.c   Sat Nov 16 20:00:29 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_machdep.c,v 1.3 2002/11/15 21:48:06 manu Exp $ */
+/*     $NetBSD: mach_machdep.c,v 1.4 2002/11/16 20:00:29 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.3 2002/11/15 21:48:06 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_machdep.c,v 1.4 2002/11/16 20:00:29 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -102,9 +102,9 @@
     struct mach_host_basic_info *info;
 {
        /* XXX fill this  accurately */
-       info->max_cpus = 1;
-       info->avail_cpus = 1;
-       info->memory_size = uvmexp.active + uvmexp.inactive;
+       info->max_cpus = 1; /* XXX */
+       info->avail_cpus = 1; /* XXX */
+       info->memory_size = (uvmexp.active + uvmexp.inactive) * PAGE_SIZE;
        info->cpu_type = MACHO_CPU_TYPE_POWERPC;
-       info->cpu_subtype = MACHO_CPU_SUBTYPE_POWERPC_ALL;
+       info->cpu_subtype = MACHO_CPU_SUBTYPE_POWERPC_604; /* XXX */
 }
diff -r a07fe60fd4f0 -r 176ddeef0f60 sys/compat/mach/mach_host.c
--- a/sys/compat/mach/mach_host.c       Sat Nov 16 19:59:19 2002 +0000
+++ b/sys/compat/mach/mach_host.c       Sat Nov 16 20:00:29 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_host.c,v 1.9 2002/11/14 21:17:30 christos Exp $ */
+/*     $NetBSD: mach_host.c,v 1.10 2002/11/16 20:00:30 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.9 2002/11/14 21:17:30 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_host.c,v 1.10 2002/11/16 20:00:30 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/malloc.h>
@@ -84,7 +84,15 @@
                    = (struct mach_host_basic_info *)&rep.rep_data[0];
 
                DPRINTF(("mach_host_info(BASIC_INFO);\n"));
+               rep.rep_msgh.msgh_size = sizeof(*reps) 
+                   - sizeof(rep.rep_trailer) + sizeof(*info);
+               rep.rep_count = sizeof(*info) / sizeof(int);
                mach_host_basic_info(info);
+               /* 
+                * XXX this is the trailer, the way it 
+                * is filled should be improved 
+                */
+               rep.rep_data[rep.rep_count + 1] = 8;
                break;
        }
 
diff -r a07fe60fd4f0 -r 176ddeef0f60 sys/compat/mach/mach_misc.c
--- a/sys/compat/mach/mach_misc.c       Sat Nov 16 19:59:19 2002 +0000
+++ b/sys/compat/mach/mach_misc.c       Sat Nov 16 20:00:29 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_misc.c,v 1.10 2002/11/14 21:17:30 christos Exp $   */
+/*     $NetBSD: mach_misc.c,v 1.11 2002/11/16 20:00:30 manu Exp $       */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_misc.c,v 1.10 2002/11/14 21:17:30 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_misc.c,v 1.11 2002/11/16 20:00:30 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -307,19 +307,6 @@
 
 
 int
-mach_sys_map_fd(struct proc *p, void *v, register_t *r) {
-#ifdef DEBUG_MACH
-       struct mach_sys_map_fd_args *ap = v;
-#endif
-       *r = 0;
-       DPRINTF(("mach_sys_map_fd(0x%lx, %p, %d, %d);\n",
-           SCARG(ap, offset), SCARG(ap, va), SCARG(ap, findspace),
-           SCARG(ap, size)));
-       return 0;
-}
-
-
-int
 mach_sys_task_for_pid(struct proc *p, void *v, register_t *r) {
 #ifdef DEBUG_MACH
        struct mach_sys_task_for_pid_args *ap = v;
diff -r a07fe60fd4f0 -r 176ddeef0f60 sys/compat/mach/mach_vm.c
--- a/sys/compat/mach/mach_vm.c Sat Nov 16 19:59:19 2002 +0000
+++ b/sys/compat/mach/mach_vm.c Sat Nov 16 20:00:29 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_vm.c,v 1.7 2002/11/14 21:17:31 christos Exp $ */
+/*     $NetBSD: mach_vm.c,v 1.8 2002/11/16 20:00:30 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.7 2002/11/14 21:17:31 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.8 2002/11/16 20:00:30 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -45,8 +45,14 @@
 #include <sys/mount.h>
 #include <sys/proc.h>
 #include <sys/mman.h>
+#include <sys/vnode.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/exec.h>
 #include <sys/syscallargs.h>
 
+#include <uvm/uvm_prot.h>
+#include <uvm/uvm_map.h>
  
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_message.h>
@@ -176,3 +182,82 @@
                return error;
        return 0;
 }
+
+
+/* XXX The findspace argument is not handled correctly */
+int
+mach_sys_map_fd(p, v, retval)
+       struct proc *p;
+       void *v;
+       register_t *retval;
+{
+       struct mach_sys_map_fd_args /* {
+               syscallarg(int) fd;
+               syscallarg(mach_vm_offset_t) offset;
+               syscallarg(mach_vm_offset_t *) va;
+               syscallarg(mach_boolean_t) findspace;
+               syscallarg(mach_vm_size_t) size;
+       } */ *uap = v;
+       struct file *fp; 
+       struct filedesc *fdp;
+       struct vnode *vp;
+       struct exec_vmcmd evc;
+       struct vm_map_entry *ret;
+       void *va;
+       int error;
+
+       if ((error = copyin(SCARG(uap, va), (void *)&va, sizeof(va))) != 0)
+               return error;
+
+       fdp = p->p_fd;
+       fp = fd_getfile(fdp, SCARG(uap, fd));
+       if (fp == NULL)
+               return EBADF;
+
+       FILE_USE(fp);
+       vp = (struct vnode *)fp->f_data;
+
+       bzero(&evc, sizeof(evc));
+       evc.ev_addr = (u_long)va;
+       evc.ev_len = SCARG(uap, size);
+       evc.ev_prot = VM_PROT_ALL;
+       evc.ev_flags = 0;
+       evc.ev_proc = vmcmd_map_readvn;
+       evc.ev_offset = SCARG(uap, offset);
+       evc.ev_vp = vp;
+
+       if ((error = (*evc.ev_proc)(p, &evc)) != 0) {
+               DPRINTF(("mach_sys_map_fd: mapping at %p failed\n", 
+                   (void *)evc.ev_addr));
+
+               if (SCARG(uap, findspace) == 0)
+                       goto bad;
+
+               if ((ret = uvm_map_findspace(&p->p_vmspace->vm_map,
+                   0x8000, evc.ev_len, (vaddr_t *)&evc.ev_addr,
+                   NULL, 0, PAGE_SIZE, 0)) == NULL)
+                       goto bad;
+
+               DPRINTF(("mach_sys_map_fd: trying at %p\n",
+                   (void *)evc.ev_addr));
+               if ((error = (*evc.ev_proc)(p, &evc)) != 0) 
+                       goto bad;
+       }
+
+       FILE_UNUSE(fp, p);
+       DPRINTF(("mach_sya_map_fd: mapping at %p\n", (void *)evc.ev_addr));
+
+       va = (mach_vm_offset_t *)evc.ev_addr;
+
+       if ((error = copyout((void *)&va, SCARG(uap, va), sizeof(va))) != 0)
+               return error;
+       
+       return 0;
+
+bad:
+       FILE_UNUSE(fp, p);
+       DPRINTF(("mach_sys_map_fd: mapping at %p failed\n", 
+           (void *)evc.ev_addr));
+       return error;
+}
+ 



Home | Main Index | Thread Index | Old Index