memobj-r0drv-freebsd.c revision d9a86bd327291cd44d5f6da6e08bec728aae68bb
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Ring-0 Memory Objects, FreeBSD.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * Permission is hereby granted, free of charge, to any person
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * obtaining a copy of this software and associated documentation
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * files (the "Software"), to deal in the Software without
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * restriction, including without limitation the rights to use,
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * copy, modify, merge, publish, distribute, sublicense, and/or sell
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * copies of the Software, and to permit persons to whom the
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * Software is furnished to do so, subject to the following
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * conditions:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * The above copyright notice and this permission notice shall be
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * included in all copies or substantial portions of the Software.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * OTHER DEALINGS IN THE SOFTWARE.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/*******************************************************************************
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync* Header Files *
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync*******************************************************************************/
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/*******************************************************************************
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync* Structures and Typedefs *
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync*******************************************************************************/
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * The FreeBSD version of the memory object structure.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /** The core structure. */
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync /** The VM object associated with the allocation. */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync /** the VM object associated with the mapping.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * In mapping mem object, this is the shadow object?
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * In a allocation/enter mem object, this is the shared object we constructed (contig, perhaps alloc). */
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsyncMALLOC_DEFINE(M_IPRTMOBJ, "iprtmobj", "IPRT - R0MemObj");
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/*******************************************************************************
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync* Internal Functions *
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync*******************************************************************************/
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)pMem;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync contigfree(pMemFreeBSD->Core.pv, pMemFreeBSD->Core.cb, M_IPRTMOBJ);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb);
b367610a6f6221996e1c27d38fcecd465140ad58vboxsync contigfree(pMemFreeBSD->Core.pv, pMemFreeBSD->Core.cb, M_IPRTMOBJ);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (pMemFreeBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync pMap = &((struct proc *)pMemFreeBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map;
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb,
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (pMemFreeBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync pMap = &((struct proc *)pMemFreeBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb);
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync /* vm_map_remove will unmap the pages we inserted with pmap_enter */
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync AssertMsg(pMemFreeBSD->pMappingObject != NULL, ("MappingObject is NULL\n"));
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync if (pMemFreeBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS)
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync pMap = &((struct proc *)pMemFreeBSD->Core.u.Mapping.R0Process)->p_vmspace->vm_map;
c889bbab784ba8552102ce776b6c67b982017861vboxsync (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb);
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync /* unused: */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgFailed(("enmType=%d\n", pMemFreeBSD->Core.enmType));
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_PAGE, NULL, cb);
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync pMemFreeBSD->pObject = vm_object_allocate(OBJT_DEFAULT, cPages);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync 0, /* offset */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync pPage = vm_page_alloc(pMemFreeBSD->pObject, PageIndex,
1829a716128b3e2d42bcee064a15c553dbd44798vboxsync#if __FreeBSD_version >= 800000 /** @todo Find exact version number */
1829a716128b3e2d42bcee064a15c553dbd44798vboxsync /* Fixes crashes during VM termination on FreeBSD8-CURRENT amd64
1829a716128b3e2d42bcee064a15c553dbd44798vboxsync * with kernel debugging enabled. */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync /* Put the page into the page table now. */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync pmap_enter(kernel_map->pmap, AddressDst, VM_PROT_NONE, pPage,
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync * Allocation failed. vm_map_remove will remove any
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync * page already alocated.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync rc = VERR_NO_MEMORY; /** @todo fix translation (borrow from darwin) */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * Try a Alloc first and see if we get luck, if not try contigmalloc.
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync * Might wish to try find our own pages or something later if this
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync * turns into a problemspot on AMD64 boxes.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync int rc = rtR0MemObjNativeAllocPage(ppMem, cb, fExecutable);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync while (iPage-- > 0)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (rtR0MemObjNativeGetPagePhysAddr(*ppMem, iPage) > (_4G - PAGE_SIZE))
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync rc = rtR0MemObjNativeAllocCont(ppMem, cb, fExecutable);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_CONT, NULL, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* do the allocation. */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync 0, /* lowest physical address*/
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync 0); /* boundrary */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync pMemFreeBSD->Core.u.Cont.Phys = vtophys(pMemFreeBSD->Core.pv);
041d531fb5794a8a4cf6c35886d89ec25cbbdde2vboxsyncint rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync /** @todo check if there is a more appropriate API somewhere.. */
041d531fb5794a8a4cf6c35886d89ec25cbbdde2vboxsync /** @todo */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_CONT, NULL, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* do the allocation. */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync 0, /* lowest physical address*/
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync 0); /* boundrary */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync pMemFreeBSD->Core.u.Cont.Phys = vtophys(pMemFreeBSD->Core.pv);
c5d2523548cc57504b829f53f1362b848a84542cvboxsyncint rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
c5d2523548cc57504b829f53f1362b848a84542cvboxsync /** @todo rtR0MemObjNativeAllocPhys / freebsd */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_PHYS, NULL, cb);
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync /* there is no allocation here, it needs to be mapped somewhere first. */
db3d025f28c59aececbbda4174fa513496c89b2bvboxsyncint rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
fa7c9928985ad8dc74ae6931809083c2af135250vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_LOCK, (void *)R3Ptr, cb);
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync * We could've used vslock here, but we don't wish to be subject to
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * resource usage restrictions, so we'll call vm_map_wire directly.
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync rc = vm_map_wire(&((struct proc *)R0Process)->p_vmspace->vm_map, /* the map */
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES); /* flags */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return VERR_NO_MEMORY;/** @todo fix mach -> vbox error conversion for freebsd. */
db3d025f28c59aececbbda4174fa513496c89b2bvboxsyncint rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, uint32_t fAccess)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_LOCK, pv, cb);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync /* lock the memory */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES); /* flags - SYSTEM? */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Lock.R0Process = NIL_RTR0PROCESS;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return VERR_NO_MEMORY;/** @todo fix mach -> vbox error conversion for freebsd. */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * Worker for the two virtual address space reservers.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * We're leaning on the examples provided by mmap and vm_mmap in vm_mmap.c here.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsyncstatic int rtR0MemObjNativeReserveInMap(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process, vm_map_t pMap)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * The pvFixed address range must be within the VM space when specified.
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync * Check that the specified alignment is supported.
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync * Create the object.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_RES_VIRT, NULL, cb);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * Allocate an empty VM object and map it into the requested map.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync pMemFreeBSD->pObject = vm_object_allocate(OBJT_DEFAULT, cb >> PAGE_SHIFT);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync 0, /* offset */
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync 0); /* cow (copy-on-write) */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync rc = VERR_NO_MEMORY; /** @todo fix translation (borrow from darwin) */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return rtR0MemObjNativeReserveInMap(ppMem, pvFixed, cb, uAlignment, NIL_RTR0PROCESS, kernel_map);
c5d2523548cc57504b829f53f1362b848a84542cvboxsyncint rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
c5d2523548cc57504b829f53f1362b848a84542cvboxsync return rtR0MemObjNativeReserveInMap(ppMem, (void *)R3PtrFixed, cb, uAlignment, R0Process,
fbb3513a43135c633f7f51544c4bdfce748929bfvboxsyncint rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
fbb3513a43135c633f7f51544c4bdfce748929bfvboxsync AssertMsgReturn(!offSub && !cbSub, ("%#x %#x\n", offSub, cbSub), VERR_NOT_SUPPORTED);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED);
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync * Check that the specified alignment is supported.
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync/* Phys: see pmap_mapdev in i386/i386/pmap.c (http://fxr.watson.org/fxr/source/i386/i386/pmap.c?v=RELENG62#L2860) */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/** @todo finish the implementation. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemToMapOs2 = (PRTR0MEMOBJFREEBSD)pMemToMap;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * These has kernel mappings.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* no ring-0 mapping, so allocate a mapping in the process. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgReturn(uAlignment == PAGE_SIZE, ("%#zx\n", uAlignment), VERR_NOT_SUPPORTED);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgReturn(fProt & RTMEM_PROT_WRITE, ("%#x\n", fProt), VERR_NOT_SUPPORTED);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rc = KernVMAlloc(pMemToMapOs2->Core.cb, VMDHA_PHYS, &pvR0, (PPVOID)&ulPhys, NULL);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (pMemToMapOs2->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_SUPPORTED; /** @todo implement this... */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgFailed(("enmType=%d\n", pMemToMapOs2->Core.enmType));
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * Create a dummy mapping object for it.
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync * All mappings are read/write/execute in OS/2 and there isn't
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * any cache options, so sharing is ok. And the main memory object
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * isn't actually freed until all the mappings have been freed up
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * (reference counting).
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR0, pMemToMapOs2->Core.cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync/* see http://markmail.org/message/udhq33tefgtyfozs */
c5d2523548cc57504b829f53f1362b848a84542cvboxsyncint rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync * Check for unsupported stuff.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
c5d2523548cc57504b829f53f1362b848a84542cvboxsync AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);
c889bbab784ba8552102ce776b6c67b982017861vboxsync vm_object_t pObjectToMap = ((PRTR0MEMOBJFREEBSD)pMemToMap)->pObject;
c889bbab784ba8552102ce776b6c67b982017861vboxsync struct vm_map *pProcMap = &pProc->p_vmspace->vm_map;
c889bbab784ba8552102ce776b6c67b982017861vboxsync /* calc protection */
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync if ((fProt & RTMEM_PROT_WRITE) == RTMEM_PROT_WRITE)
c889bbab784ba8552102ce776b6c67b982017861vboxsync /* calc mapping address */
c889bbab784ba8552102ce776b6c67b982017861vboxsync vm_offset_t AddrR3 = round_page((vm_offset_t)pProc->p_vmspace->vm_daddr + lim_max(pProc, RLIMIT_DATA));
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync vm_object_t pObjectNew = vm_object_allocate(OBJT_PHYS, pMemToMap->cb >> PAGE_SHIFT);
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync /* Insert the object in the map. */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync rc = vm_map_find(pProcMap, /* Map to insert the object in */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync 0, /* Start offset in the object */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync TRUE, /* Whether a suitable address should be searched for first */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync 0); /* Copy on write */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync /* Map the memory page by page into the destination map. */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync vm_offset_t AddrToMap = (vm_offset_t)pMemToMap->pv;
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync /* Insert the memory page by page into the mapping. */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync while (cLeft-- > 0)
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync vm_page_t Page = PHYS_TO_VM_PAGE(vtophys(AddrToMap));
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync pmap_enter(pPhysicalMap, AddrR3Dst, VM_PROT_NONE, Page, ProtectionFlags, TRUE);
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync pmap_enter(pPhysicalMap, AddrR3Dst, Page, ProtectionFlags, TRUE);
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync * Create a mapping object for it.
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(RTR0MEMOBJFREEBSD),
c889bbab784ba8552102ce776b6c67b982017861vboxsync Assert((vm_offset_t)pMemFreeBSD->Core.pv == AddrR3);
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync rc = vm_map_remove(pProcMap, ((vm_offset_t)AddrR3), ((vm_offset_t)AddrR3) + pMemToMap->cb);
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync AssertMsg(rc == KERN_SUCCESS, ("Deleting mapping failed\n"));
31cda52093d58f5c604589fa74949c5fddcbde70vboxsyncint rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsyncRTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)pMem;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if ( pMemFreeBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync && pMemFreeBSD->Core.u.Lock.R0Process != (RTR0PROCESS)curproc)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync /* later */
c889bbab784ba8552102ce776b6c67b982017861vboxsync /* fall thru*/
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync vm_offset_t pb = (vm_offset_t)pMemFreeBSD->Core.pv + (iPage << PAGE_SHIFT);
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync vm_offset_t pb = (vm_offset_t)pMemFreeBSD->Core.pv + (iPage << PAGE_SHIFT);
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync if (pMemFreeBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS)
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync struct proc *pProc = (struct proc *)pMemFreeBSD->Core.u.Mapping.R0Process;
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync struct vm_map *pProcMap = &pProc->p_vmspace->vm_map;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return pMemFreeBSD->Core.u.Cont.Phys + (iPage << PAGE_SHIFT);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return pMemFreeBSD->Core.u.Phys.PhysBase + (iPage << PAGE_SHIFT);