Added vm_copy

This commit is contained in:
manu 2003-06-03 20:09:37 +00:00
parent f1ed073d7b
commit 899161bdbc
3 changed files with 77 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_namemap.c,v 1.30 2003/06/03 06:48:48 manu Exp $ */
/* $NetBSD: mach_namemap.c,v 1.31 2003/06/03 20:09:37 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.30 2003/06/03 06:48:48 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: mach_namemap.c,v 1.31 2003/06/03 20:09:37 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -138,6 +138,7 @@ struct mach_subsystem_namemap mach_namemap[] = {
{ 3802, mach_vm_deallocate, "vm_deallocate" },
{ 3803, mach_vm_protect, "vm_protect" },
{ 3804, mach_vm_inherit, "vm_inherit" },
{ 3808, mach_vm_copy, "vm_copy" },
{ 3810, mach_vm_msync, "vm_msync" },
{ 3812, mach_vm_map, "vm_map" },
{ 3825, mach_vm_make_memory_entry, "vm_make_memory_entry" },

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_vm.c,v 1.27 2003/04/19 21:41:15 manu Exp $ */
/* $NetBSD: mach_vm.c,v 1.28 2003/06/03 20:09:37 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.27 2003/04/19 21:41:15 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.28 2003/06/03 20:09:37 manu Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -54,6 +54,7 @@ __KERNEL_RCSID(0, "$NetBSD: mach_vm.c,v 1.27 2003/04/19 21:41:15 manu Exp $");
#include <uvm/uvm_prot.h>
#include <uvm/uvm_map.h>
#include <uvm/uvm_extern.h>
/* Too much debug output from here, but we might need it later... */
#undef DEBUG_MACH
@ -594,3 +595,55 @@ mach_vm_msync(args)
*msglen = sizeof(*rep);
return 0;
}
int
mach_vm_copy(args)
struct mach_trap_args *args;
{
mach_vm_copy_request_t *req = args->smsg;
mach_vm_copy_reply_t *rep = args->rmsg;
size_t *msglen = args->rsize;
char tmpbuf[PAGE_SIZE];
int error;
caddr_t src, dst;
#ifdef DEBUG_MACH
printf("mach_vm_copy: src = 0x%08x, size = 0x%08x, addr = 0x%08x\n",
req->req_src, req->req_size, req->req_addr);
#endif
if ((req->req_src & (PAGE_SIZE - 1)) ||
(req->req_addr & (PAGE_SIZE - 1)) ||
(req->req_size & (PAGE_SIZE - 1)))
return mach_msg_error(args, EINVAL);
src = (caddr_t)req->req_src;
dst = (caddr_t)req->req_addr;
if ((uvm_useracc(src, req->req_size, B_READ) == 0) ||
(uvm_useracc(dst, req->req_size, B_WRITE) == 0))
return mach_msg_error(args, EPERM);
/* Is there an easy way of dealing with that efficiently? */
do {
if ((error = copyin(src, tmpbuf, PAGE_SIZE)) != 0)
return mach_msg_error(args, error);
if ((error = copyout(tmpbuf, dst, PAGE_SIZE)) != 0)
return mach_msg_error(args, error);
req->req_src += PAGE_SIZE;
req->req_addr += PAGE_SIZE;
req->req_size -= PAGE_SIZE;
} while (req->req_size != 0);
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 = 0;
rep->rep_trailer.msgh_trailer_size = 8;
*msglen = sizeof(*rep);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: mach_vm.h,v 1.13 2003/03/03 22:07:40 manu Exp $ */
/* $NetBSD: mach_vm.h,v 1.14 2003/06/03 20:09:37 manu Exp $ */
/*-
* Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@ -263,6 +263,23 @@ typedef struct {
mach_msg_trailer_t rep_trailer;
} mach_vm_msync_reply_t;
/* vm_copy */
typedef struct {
mach_msg_header_t req_msgh;
mach_ndr_record_t req_ndr;
mach_vm_address_t req_src;
mach_vm_size_t req_size;
mach_vm_address_t req_addr;
} mach_vm_copy_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_copy_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 *);
@ -272,5 +289,6 @@ 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 *);
int mach_vm_copy(struct mach_trap_args *);
#endif /* _MACH_VM_H_ */