Source-Changes-HG archive

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

[src/trunk]: src/sys/compat/mach Added vm_region and vm_msync traps



details:   https://anonhg.NetBSD.org/src/rev/495cfd2d4429
branches:  trunk
changeset: 543773:495cfd2d4429
user:      manu <manu%NetBSD.org@localhost>
date:      Mon Mar 03 22:07:39 2003 +0000

description:
Added vm_region and vm_msync traps

diffstat:

 sys/compat/mach/mach_message.h |  11 ++++-
 sys/compat/mach/mach_namemap.c |   6 +-
 sys/compat/mach/mach_types.h   |   5 +-
 sys/compat/mach/mach_vm.c      |  98 ++++++++++++++++++++++++++++++++++++++++-
 sys/compat/mach/mach_vm.h      |  67 ++++++++++++++++++++++++++++-
 5 files changed, 178 insertions(+), 9 deletions(-)

diffs (299 lines):

diff -r 4fea4d4727a3 -r 495cfd2d4429 sys/compat/mach/mach_message.h
--- a/sys/compat/mach/mach_message.h    Mon Mar 03 22:07:21 2003 +0000
+++ b/sys/compat/mach/mach_message.h    Mon Mar 03 22:07:39 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_message.h,v 1.14 2003/01/21 04:06:07 matt Exp $    */
+/*     $NetBSD: mach_message.h,v 1.15 2003/03/03 22:07:39 manu Exp $    */
 
 /*-
  * Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
@@ -194,6 +194,15 @@
 } mach_msg_ool_ports_descriptor_t;
 
 typedef struct {
+       void *                    address;
+       mach_msg_size_t           size;
+       mach_boolean_t            deallocate : 8;
+       mach_msg_copy_options_t   copy : 8;
+       unsigned int              pad1 : 8;
+       mach_msg_descriptor_type_t type : 8;
+} mach_msg_ool_descriptor_t;
+
+typedef struct {
        mach_msg_size_t msgh_descriptor_count;
 } mach_msg_body_t;
 
diff -r 4fea4d4727a3 -r 495cfd2d4429 sys/compat/mach/mach_namemap.c
--- a/sys/compat/mach/mach_namemap.c    Mon Mar 03 22:07:21 2003 +0000
+++ b/sys/compat/mach/mach_namemap.c    Mon Mar 03 22:07:39 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_namemap.c,v 1.18 2003/02/28 09:30:23 manu Exp $ */
+/*     $NetBSD: mach_namemap.c,v 1.19 2003/03/03 22:07:39 manu Exp $ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_namemap.c,v 1.18 2003/02/28 09:30:23 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_namemap.c,v 1.19 2003/03/03 22:07:39 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -103,10 +103,12 @@
        { 3418, mach_semaphore_create, "semaphore_create" },
        { 3419, mach_semaphore_destroy, "semaphore_destroy" },
        { 3616, mach_thread_policy, "thread_policy" },
+       { 3800, mach_vm_region, "vm_region" },
        { 3801, mach_vm_allocate, "vm_allocate" },
        { 3802, mach_vm_deallocate, "vm_deallocate" },
        { 3803, mach_vm_protect, "vm_protect" },
        { 3804, mach_vm_inherit, "vm_inherit" },
+       { 3810, mach_vm_msync, "vm_msync" },
        { 3812, mach_vm_map, "vm_map" },
        { 3825, mach_vm_make_memory_entry, "vm_make_memory_entry" },
        { 0, NULL, NULL },
diff -r 4fea4d4727a3 -r 495cfd2d4429 sys/compat/mach/mach_types.h
--- a/sys/compat/mach/mach_types.h      Mon Mar 03 22:07:21 2003 +0000
+++ b/sys/compat/mach/mach_types.h      Mon Mar 03 22:07:39 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_types.h,v 1.11 2003/01/21 04:06:08 matt Exp $      */
+/*     $NetBSD: mach_types.h,v 1.12 2003/03/03 22:07:40 manu Exp $      */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -59,6 +59,9 @@
 typedef unsigned int mach_natural_t;
 typedef unsigned long mach_vm_size_t;
 typedef unsigned long mach_vm_offset_t;
+typedef int mach_vm_region_flavor_t;
+typedef int mach_vm_behavior_t;
+typedef int mach_vm_sync_t;
 
 /* 
  * This is called cproc_t in Mach (cthread_t in Darwin). It is a pointer to 
diff -r 4fea4d4727a3 -r 495cfd2d4429 sys/compat/mach/mach_vm.c
--- a/sys/compat/mach/mach_vm.c Mon Mar 03 22:07:21 2003 +0000
+++ b/sys/compat/mach/mach_vm.c Mon Mar 03 22:07:39 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_vm.c,v 1.24 2003/01/21 04:06:08 matt Exp $ */
+/*     $NetBSD: mach_vm.c,v 1.25 2003/03/03 22:07:40 manu Exp $ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.24 2003/01/21 04:06:08 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.25 2003/03/03 22:07:40 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -90,7 +90,7 @@
 #if 1
        /* XXX Darwin fails on mapping a page at address 0 */
        if (req->req_address == 0)
-               return mach_msg_error(args, error);
+               return mach_msg_error(args, ENOMEM);
 #endif
 
        req->req_size = round_page(req->req_size);
@@ -474,7 +474,7 @@
        struct lwp *l = args->l;
        
        /* 
-        * XXX Find some documentation wbout what 
+        * XXX Find some documentation about what 
         * this is supposed to do, and implement it.
         */
        printf("pid %d.%d: Unimplemented mach_vm_make_memory_entry\n",
@@ -491,3 +491,93 @@
        *msglen = sizeof(*rep);
        return 0;
 }
+
+int
+mach_vm_region(args)
+       struct mach_trap_args *args;
+{
+       mach_vm_region_request_t *req = args->smsg;
+       mach_vm_region_reply_t *rep = args->rmsg;
+       size_t *msglen = args->rsize;
+       struct lwp *l = args->l;
+       struct mach_vm_region_basic_info *rbi;
+       struct vm_map_entry *vme;
+       
+       /* 
+        * MACH_VM_REGION_BASIC_INFO is the only 
+        * supported flavor in Darwin.
+        */
+       if (req->req_flavor != MACH_VM_REGION_BASIC_INFO) 
+               return mach_msg_error(args, EINVAL);
+       if (req->req_count * sizeof(int) < sizeof(*rbi))
+               return mach_msg_error(args, EINVAL);
+       *msglen += ((req->req_count - 9) * sizeof(int)); 
+
+       vme = uvm_map_findspace(&l->l_proc->p_vmspace->vm_map, 
+                           req->req_addr, 1, (vaddr_t *)&rep->rep_addr, 
+                           NULL, 0, 0, UVM_FLAG_FIXED);
+       if (vme == NULL)
+               return mach_msg_error(args, ENOMEM);
+
+       rep->rep_msgh.msgh_bits =
+           MACH_MSGH_REPLY_LOCAL_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE) |
+           MACH_MSGH_BITS_COMPLEX;
+       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_body.msgh_descriptor_count = 1;
+       rep->rep_obj.address = (void *)rep->rep_addr;
+       rep->rep_obj.size = rep->rep_size;
+       rep->rep_obj.deallocate = 0;
+       rep->rep_obj.copy = 0; /* XXX */
+       rep->rep_obj.type = MACH_MSG_OOL_DESCRIPTOR;
+       rep->rep_size = (vme->end - vme->start);
+       rep->rep_count = req->req_count;
+
+       rbi = (struct mach_vm_region_basic_info *)&rep->rep_info[0];
+       rbi->protection = vme->protection;
+       rbi->inheritance = vme->inheritance;
+       rbi->shared = 0; /* XXX how can we know? */
+       rbi->offset = vme->offset;
+       rbi->behavior = MACH_VM_BEHAVIOR_DEFAULT; /* XXX What is it? */
+       rbi->user_wired_count = vme->wired_count;
+
+       rep->rep_info[rep->rep_count + 1] = 8; /* This is the trailer */
+       return 0;
+}
+
+int
+mach_vm_msync(args)
+       struct mach_trap_args *args;
+{
+       mach_vm_msync_request_t *req = args->smsg;
+       mach_vm_msync_reply_t *rep = args->rmsg;
+       size_t *msglen = args->rsize;
+       struct lwp *l = args->l;
+       struct sys___msync13_args cup;
+       int error;
+       register_t dontcare;
+       
+       SCARG(&cup, addr) = (void *)req->req_addr;
+       SCARG(&cup, len) = req->req_size;
+       SCARG(&cup, flags) = 0;
+       if (req->req_flags & MACH_VM_SYNC_ASYNCHRONOUS)
+               SCARG(&cup, flags) |= MS_ASYNC;
+       if (req->req_flags & MACH_VM_SYNC_SYNCHRONOUS)
+               SCARG(&cup, flags) |= MS_SYNC;
+       if (req->req_flags & MACH_VM_SYNC_INVALIDATE)
+               SCARG(&cup, flags) |= MS_INVALIDATE;
+
+       error = sys___msync13(l, &cup, &dontcare);
+
+       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_retval = error;        
+       rep->rep_trailer.msgh_trailer_size = 8;
+
+       *msglen = sizeof(*rep);
+       return 0;
+}
diff -r 4fea4d4727a3 -r 495cfd2d4429 sys/compat/mach/mach_vm.h
--- a/sys/compat/mach/mach_vm.h Mon Mar 03 22:07:21 2003 +0000
+++ b/sys/compat/mach/mach_vm.h Mon Mar 03 22:07:39 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_vm.h,v 1.12 2003/01/04 15:15:01 manu Exp $ */
+/*     $NetBSD: mach_vm.h,v 1.13 2003/03/03 22:07:40 manu Exp $ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -63,6 +63,25 @@
        mach_vm_offset_t cksum;
 } mach_sf_mapping_t;
 
+struct mach_vm_region_basic_info {
+       mach_vm_prot_t protection;
+       mach_vm_prot_t max_protection;
+       mach_vm_inherit_t inheritance;
+       mach_boolean_t shared;
+       mach_boolean_t reserved;
+       mach_vm_offset_t offset;
+       mach_vm_behavior_t behavior;
+       unsigned short user_wired_count;
+};
+
+/* mach_vm_behavior_t values */
+#define MACH_VM_BEHAVIOR_DEFAULT 0
+#define MACH_VM_BEHAVIOR_RANDOM 1
+#define MACH_VM_BEHAVIOR_SEQUENTIAL 2
+#define MACH_VM_BEHAVIOR_RSEQNTL 3
+#define MACH_VM_BEHAVIOR_WILLNEED 4
+#define MACH_VM_BEHAVIOR_DONTNEED 5
+
 /* vm_map */
 #define MACH_VM_INHERIT_SHARE 0
 #define MACH_VM_INHERIT_COPY 1
@@ -200,6 +219,50 @@
        mach_msg_trailer_t rep_trailer;
 } mach_vm_make_memory_entry_reply_t;
 
+/* vm_region */
+
+#define MACH_VM_REGION_BASIC_INFO 10
+typedef struct {
+       mach_msg_header_t req_msgh;
+       mach_ndr_record_t req_ndr;
+       mach_vm_address_t req_addr;
+       mach_vm_region_flavor_t req_flavor;
+       mach_msg_type_number_t req_count;
+} mach_vm_region_request_t;
+
+typedef struct {
+       mach_msg_header_t rep_msgh;
+       mach_msg_body_t rep_body;
+       mach_msg_ool_descriptor_t rep_obj;
+       mach_ndr_record_t rep_ndr;
+       mach_msg_type_number_t rep_addr;
+       mach_vm_size_t rep_size;
+       mach_msg_type_number_t rep_count;
+       int rep_info[9];
+       mach_msg_trailer_t rep_trailer;
+} mach_vm_region_reply_t;
+
+/* vm_msync */
+#define MACH_VM_SYNC_ASYNCHRONOUS 0x01
+#define MACH_VM_SYNC_SYNCHRONOUS 0x02
+#define MACH_VM_SYNC_INVALIDATE 0x04
+#define MACH_VM_SYNC_KILLPAGES 0x08
+#define MACH_VM_SYNC_DEACTIVATE 0x10
+typedef struct {
+       mach_msg_header_t req_msgh;
+       mach_ndr_record_t req_ndr;
+       mach_vm_address_t req_addr;
+       mach_vm_size_t req_size;
+       mach_vm_sync_t req_flags;
+} mach_vm_msync_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_vm_msync_reply_t;
+
 int mach_vm_map(struct mach_trap_args *);
 int mach_vm_allocate(struct mach_trap_args *);
 int mach_vm_deallocate(struct mach_trap_args *);
@@ -207,5 +270,7 @@
 int mach_vm_protect(struct mach_trap_args *);
 int mach_vm_inherit(struct mach_trap_args *);
 int mach_vm_make_memory_entry(struct mach_trap_args *);
+int mach_vm_region(struct mach_trap_args *);
+int mach_vm_msync(struct mach_trap_args *);
 
 #endif /* _MACH_VM_H_ */



Home | Main Index | Thread Index | Old Index