memobj-r0drv-freebsd.c revision 5eda82e218d35ae0691febd531e1bfc0324cc4a6
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/* $Id$ */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/** @file
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Ring-0 Memory Objects, FreeBSD.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/*
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *
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 *
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * The above copyright notice and this permission notice shall be
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * included in all copies or substantial portions of the Software.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *
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
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/*******************************************************************************
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync* Header Files *
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync*******************************************************************************/
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#include "the-freebsd-kernel.h"
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#include <iprt/memobj.h>
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#include <iprt/mem.h>
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#include <iprt/err.h>
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#include <iprt/assert.h>
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#include <iprt/log.h>
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#include <iprt/param.h>
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#include <iprt/process.h>
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#include "internal/memobj.h"
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/*******************************************************************************
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync* Structures and Typedefs *
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync*******************************************************************************/
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/**
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * The FreeBSD version of the memory object structure.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsynctypedef struct RTR0MEMOBJFREEBSD
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /** The core structure. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync RTR0MEMOBJINTERNAL Core;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync /** Type dependent data */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync union
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync {
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync /** Non physical memory allocations */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync struct
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync {
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync /** The VM object associated with the allocation. */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync vm_object_t pObject;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync } NonPhys;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync /** Physical memory allocations */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync struct
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync {
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync /** Number of pages */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync uint32_t cPages;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync /** Array of pages - variable */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync vm_page_t apPages[1];
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync } Phys;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync } u;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync} RTR0MEMOBJFREEBSD, *PRTR0MEMOBJFREEBSD;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsyncMALLOC_DEFINE(M_IPRTMOBJ, "iprtmobj", "IPRT - R0MemObj");
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync/**
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync * Gets the virtual memory map the specified object is mapped into.
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync *
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync * @returns VM map handle on success, NULL if no map.
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync * @param pMem The memory object.
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsyncstatic vm_map_t rtR0MemObjFreeBSDGetMap(PRTR0MEMOBJINTERNAL pMem)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync{
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync switch (pMem->enmType)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync case RTR0MEMOBJTYPE_PAGE:
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync case RTR0MEMOBJTYPE_LOW:
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync case RTR0MEMOBJTYPE_CONT:
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync return kernel_map;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync case RTR0MEMOBJTYPE_PHYS:
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync case RTR0MEMOBJTYPE_PHYS_NC:
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync return NULL; /* pretend these have no mapping atm. */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync case RTR0MEMOBJTYPE_LOCK:
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync return pMem->u.Lock.R0Process == NIL_RTR0PROCESS
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync ? kernel_map
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync : &((struct proc *)pMem->u.Lock.R0Process)->p_vmspace->vm_map;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync case RTR0MEMOBJTYPE_RES_VIRT:
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync return pMem->u.ResVirt.R0Process == NIL_RTR0PROCESS
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync ? kernel_map
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync : &((struct proc *)pMem->u.ResVirt.R0Process)->p_vmspace->vm_map;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync case RTR0MEMOBJTYPE_MAPPING:
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync return pMem->u.Mapping.R0Process == NIL_RTR0PROCESS
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync ? kernel_map
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync : &((struct proc *)pMem->u.Mapping.R0Process)->p_vmspace->vm_map;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync default:
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync return NULL;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync }
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)pMem;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync int rc;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync switch (pMemFreeBSD->Core.enmType)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync case RTR0MEMOBJTYPE_CONT:
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync contigfree(pMemFreeBSD->Core.pv, pMemFreeBSD->Core.cb, M_IPRTMOBJ);
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync break;
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_PAGE:
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync rc = vm_map_remove(kernel_map,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync (vm_offset_t)pMemFreeBSD->Core.pv,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync AssertMsg(rc == KERN_SUCCESS, ("%#x", rc));
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_lock_queues();
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync for (uint32_t iPage = 0; iPage < pMemFreeBSD->u.Phys.cPages; iPage++)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_t pPage = pMemFreeBSD->u.Phys.apPages[iPage];
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_unwire(pPage, 0);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_free(pPage);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync }
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_unlock_queues();
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_LOCK:
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync {
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync vm_map_t pMap = kernel_map;
445661c86e95894713da707c6c9787b7507dfce6vboxsync
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (pMemFreeBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync pMap = &((struct proc *)pMemFreeBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map;
445661c86e95894713da707c6c9787b7507dfce6vboxsync
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync rc = vm_map_unwire(pMap,
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync (vm_offset_t)pMemFreeBSD->Core.pv,
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync AssertMsg(rc == KERN_SUCCESS, ("%#x", rc));
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_RES_VIRT:
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync {
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync vm_map_t pMap = kernel_map;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (pMemFreeBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync pMap = &((struct proc *)pMemFreeBSD->Core.u.Lock.R0Process)->p_vmspace->vm_map;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync rc = vm_map_remove(pMap,
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync (vm_offset_t)pMemFreeBSD->Core.pv,
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync AssertMsg(rc == KERN_SUCCESS, ("%#x", rc));
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync break;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync }
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync case RTR0MEMOBJTYPE_MAPPING:
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync {
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync vm_map_t pMap = kernel_map;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync if (pMemFreeBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS)
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync pMap = &((struct proc *)pMemFreeBSD->Core.u.Mapping.R0Process)->p_vmspace->vm_map;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync rc = vm_map_remove(pMap,
c889bbab784ba8552102ce776b6c67b982017861vboxsync (vm_offset_t)pMemFreeBSD->Core.pv,
c889bbab784ba8552102ce776b6c67b982017861vboxsync (vm_offset_t)pMemFreeBSD->Core.pv + pMemFreeBSD->Core.cb);
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync AssertMsg(rc == KERN_SUCCESS, ("%#x", rc));
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync break;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync }
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync case RTR0MEMOBJTYPE_PHYS:
c5d2523548cc57504b829f53f1362b848a84542cvboxsync case RTR0MEMOBJTYPE_PHYS_NC:
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_lock_queues();
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync for (uint32_t iPage = 0; iPage < pMemFreeBSD->u.Phys.cPages; iPage++)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_t pPage = pMemFreeBSD->u.Phys.apPages[iPage];
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_unwire(pPage, 0);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_free(pPage);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync }
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_unlock_queues();
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync break;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync }
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync
771c393ea3dea8143cabc5c8ff6b5cd38a1db91evboxsync#ifdef USE_KMEM_ALLOC_ATTR
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync case RTR0MEMOBJTYPE_LOW:
234af146205f61c4aa0be736abb06601a89facb8vboxsync {
234af146205f61c4aa0be736abb06601a89facb8vboxsync kmem_free(kernel_map, (vm_offset_t)pMemFreeBSD->Core.pv, pMemFreeBSD->Core.cb);
234af146205f61c4aa0be736abb06601a89facb8vboxsync break;
234af146205f61c4aa0be736abb06601a89facb8vboxsync }
234af146205f61c4aa0be736abb06601a89facb8vboxsync#else
234af146205f61c4aa0be736abb06601a89facb8vboxsync case RTR0MEMOBJTYPE_LOW: /* unused */
234af146205f61c4aa0be736abb06601a89facb8vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync default:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgFailed(("enmType=%d\n", pMemFreeBSD->Core.enmType));
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_INTERNAL_ERROR;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync int rc;
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync size_t cPages = cb >> PAGE_SHIFT;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJFREEBSD, u.Phys.apPages[cPages]),
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync RTR0MEMOBJTYPE_PAGE, NULL, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pMemFreeBSD->u.Phys.cPages = cPages;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_offset_t MapAddress = vm_map_min(kernel_map);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync rc = vm_map_find(kernel_map, /* map */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync NULL, /* object */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync 0, /* offset */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync &MapAddress, /* addr (IN/OUT) */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync cb, /* length */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync TRUE, /* find_space */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync fExecutable /* protection */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync ? VM_PROT_ALL
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync : VM_PROT_RW,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync VM_PROT_ALL, /* max(_prot) */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync 0); /* cow (copy-on-write) */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync if (rc == KERN_SUCCESS)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync rc = VINF_SUCCESS;
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync for (size_t iPage = 0; iPage < cPages; iPage++)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_t pPage;
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pPage = vm_page_alloc(NULL, iPage,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync VM_ALLOC_SYSTEM |
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync VM_ALLOC_WIRED | VM_ALLOC_NOOBJ);
1829a716128b3e2d42bcee064a15c553dbd44798vboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync if (!pPage)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync /*
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync * Out of pages
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync * Remove already allocated pages
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync while (iPage-- > 0)
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pPage = pMemFreeBSD->u.Phys.apPages[iPage];
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_lock_queues();
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_unwire(pPage, 0);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_free(pPage);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_unlock_queues();
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync }
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync rc = VERR_NO_MEMORY;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync break;
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync }
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pPage->valid = VM_PAGE_BITS_ALL;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pMemFreeBSD->u.Phys.apPages[iPage] = pPage;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync }
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync if (rc == VINF_SUCCESS)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_offset_t AddressDst = MapAddress;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync for (size_t iPage = 0; iPage < cPages; iPage++)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_t pPage = pMemFreeBSD->u.Phys.apPages[iPage];
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync MY_PMAP_ENTER(kernel_map->pmap, AddressDst, pPage,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync fExecutable
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync ? VM_PROT_ALL
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync : VM_PROT_RW,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync TRUE);
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync AddressDst += PAGE_SIZE;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync }
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync /* Store start address */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pMemFreeBSD->Core.pv = (void *)MapAddress;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync *ppMem = &pMemFreeBSD->Core;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync rc = VERR_NO_MEMORY; /** @todo fix translation (borrow from darwin) */
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return rc;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
771c393ea3dea8143cabc5c8ff6b5cd38a1db91evboxsync#ifdef USE_KMEM_ALLOC_ATTR
234af146205f61c4aa0be736abb06601a89facb8vboxsync /*
234af146205f61c4aa0be736abb06601a89facb8vboxsync * Use kmem_alloc_attr, fExectuable is not needed because the
234af146205f61c4aa0be736abb06601a89facb8vboxsync * memory will be executable by default
234af146205f61c4aa0be736abb06601a89facb8vboxsync */
234af146205f61c4aa0be736abb06601a89facb8vboxsync NOREF(fExecutable);
234af146205f61c4aa0be736abb06601a89facb8vboxsync
234af146205f61c4aa0be736abb06601a89facb8vboxsync /* create the object. */
234af146205f61c4aa0be736abb06601a89facb8vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_LOW, NULL, cb);
234af146205f61c4aa0be736abb06601a89facb8vboxsync if (!pMemFreeBSD)
234af146205f61c4aa0be736abb06601a89facb8vboxsync return VERR_NO_MEMORY;
234af146205f61c4aa0be736abb06601a89facb8vboxsync
234af146205f61c4aa0be736abb06601a89facb8vboxsync pMemFreeBSD->Core.pv = (void *)kmem_alloc_attr(kernel_map, /* Kernel */
234af146205f61c4aa0be736abb06601a89facb8vboxsync cb, /* Amount */
234af146205f61c4aa0be736abb06601a89facb8vboxsync M_ZERO, /* Zero memory */
234af146205f61c4aa0be736abb06601a89facb8vboxsync 0, /* Low physical address */
234af146205f61c4aa0be736abb06601a89facb8vboxsync _4G - PAGE_SIZE, /* Highest physical address */
234af146205f61c4aa0be736abb06601a89facb8vboxsync VM_MEMATTR_DEFAULT); /* Default memory attributes */
234af146205f61c4aa0be736abb06601a89facb8vboxsync if (!pMemFreeBSD->Core.pv)
234af146205f61c4aa0be736abb06601a89facb8vboxsync return VERR_NO_MEMORY;
234af146205f61c4aa0be736abb06601a89facb8vboxsync
ad836b4d6fb2ccaf969666246c2c389a8d10ca41vboxsync *ppMem = &pMemFreeBSD->Core;
ad836b4d6fb2ccaf969666246c2c389a8d10ca41vboxsync
234af146205f61c4aa0be736abb06601a89facb8vboxsync return VINF_SUCCESS;
234af146205f61c4aa0be736abb06601a89facb8vboxsync#else
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync /*
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 */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync int rc = rtR0MemObjNativeAllocPage(ppMem, cb, fExecutable);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (RT_SUCCESS(rc))
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync size_t iPage = cb >> PAGE_SHIFT;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync while (iPage-- > 0)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (rtR0MemObjNativeGetPagePhysAddr(*ppMem, iPage) > (_4G - PAGE_SIZE))
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync {
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync RTR0MemObjFree(*ppMem, false);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync *ppMem = NULL;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync rc = VERR_NO_MEMORY;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync break;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (RT_FAILURE(rc))
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync rc = rtR0MemObjNativeAllocCont(ppMem, cb, fExecutable);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return rc;
234af146205f61c4aa0be736abb06601a89facb8vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_CONT, NULL, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* do the allocation. */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync pMemFreeBSD->Core.pv = contigmalloc(cb, /* size */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync M_IPRTMOBJ, /* type */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync M_NOWAIT | M_ZERO, /* flags */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync 0, /* lowest physical address*/
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync _4G-1, /* highest physical address */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync PAGE_SIZE, /* alignment. */
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync 0); /* boundary */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync if (pMemFreeBSD->Core.pv)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync pMemFreeBSD->Core.u.Cont.Phys = vtophys(pMemFreeBSD->Core.pv);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync NOREF(fExecutable);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsyncstatic void rtR0MemObjFreeBSDPhysPageInit(vm_page_t pPage, vm_pindex_t iPage)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync{
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pPage->wire_count = 1;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pPage->pindex = iPage;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pPage->act_count = 0;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pPage->oflags = 0;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pPage->flags = PG_UNMANAGED;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync atomic_add_int(&cnt.v_wire_count, 1);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync}
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsyncstatic int rtR0MemObjFreeBSDAllocPhysPages(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJTYPE enmType,
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync size_t cb,
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync RTHCPHYS PhysHighest, size_t uAlignment,
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync bool fContiguous)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync int rc = VINF_SUCCESS;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync uint32_t cPages = cb >> PAGE_SHIFT;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync vm_paddr_t VmPhysAddrHigh;
041d531fb5794a8a4cf6c35886d89ec25cbbdde2vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJFREEBSD, u.Phys.apPages[cPages]),
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync enmType, NULL, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync pMemFreeBSD->u.Phys.cPages = cPages;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync if (PhysHighest != NIL_RTHCPHYS)
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync VmPhysAddrHigh = PhysHighest;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync else
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync VmPhysAddrHigh = ~(vm_paddr_t)0;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync if (fContiguous)
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync {
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync vm_page_t pPage = vm_phys_alloc_contig(cPages, 0, VmPhysAddrHigh, uAlignment, 0);
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync if (pPage)
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync for (uint32_t iPage = 0; iPage < cPages; iPage++)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync rtR0MemObjFreeBSDPhysPageInit(&pPage[iPage], iPage);
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync pMemFreeBSD->u.Phys.apPages[iPage] = &pPage[iPage];
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync }
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync else
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync rc = VERR_NO_MEMORY;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync }
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync else
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync {
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync /* Allocate page by page */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync for (uint32_t iPage = 0; iPage < cPages; iPage++)
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync {
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync vm_page_t pPage = vm_phys_alloc_contig(1, 0, VmPhysAddrHigh, uAlignment, 0);
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync if (!pPage)
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync {
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync /* Free all allocated pages */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync while (iPage-- > 0)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync {
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync pPage = pMemFreeBSD->u.Phys.apPages[iPage];
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_lock_queues();
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_unwire(pPage, 0);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_free(pPage);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_page_unlock_queues();
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync }
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync rc = VERR_NO_MEMORY;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync break;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync }
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync rtR0MemObjFreeBSDPhysPageInit(pPage, iPage);
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync pMemFreeBSD->u.Phys.apPages[iPage] = pPage;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync }
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync }
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync if (RT_FAILURE(rc))
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync else
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync {
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync if (enmType == RTR0MEMOBJTYPE_PHYS)
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync {
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync pMemFreeBSD->Core.u.Phys.PhysBase = VM_PAGE_TO_PHYS(pMemFreeBSD->u.Phys.apPages[0]);
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync pMemFreeBSD->Core.u.Phys.fAllocated = true;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync }
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync return rc;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync}
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment)
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync{
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync#if 1
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync return rtR0MemObjFreeBSDAllocPhysPages(ppMem, RTR0MEMOBJTYPE_PHYS, cb, PhysHighest, uAlignment, true);
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync#else
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync /* create the object. */
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_CONT, NULL, cb);
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync if (!pMemFreeBSD)
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync return VERR_NO_MEMORY;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync /* do the allocation. */
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync pMemFreeBSD->Core.pv = contigmalloc(cb, /* size */
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync M_IPRTMOBJ, /* type */
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync M_NOWAIT | M_ZERO, /* flags */
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync 0, /* lowest physical address*/
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync _4G-1, /* highest physical address */
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync uAlignment, /* alignment. */
ad27e1d5e48ca41245120c331cc88b50464813cevboxsync 0); /* boundary */
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync if (pMemFreeBSD->Core.pv)
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync {
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync pMemFreeBSD->Core.u.Cont.Phys = vtophys(pMemFreeBSD->Core.pv);
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync *ppMem = &pMemFreeBSD->Core;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync return VINF_SUCCESS;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync }
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync return VERR_NO_MEMORY;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
c5d2523548cc57504b829f53f1362b848a84542cvboxsync{
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync#if 1
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync return rtR0MemObjFreeBSDAllocPhysPages(ppMem, RTR0MEMOBJTYPE_PHYS_NC, cb, PhysHighest, PAGE_SIZE, false);
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync#else
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync return VERR_NOT_SUPPORTED;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync#endif
c5d2523548cc57504b829f53f1362b848a84542cvboxsync}
c5d2523548cc57504b829f53f1362b848a84542cvboxsync
c5d2523548cc57504b829f53f1362b848a84542cvboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb, uint32_t uCachePolicy)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
a9ed90fc7da3c371bc3b96c8535655b87836fcadvboxsync AssertReturn(uCachePolicy == RTMEM_CACHE_POLICY_DONT_CARE, VERR_NOT_SUPPORTED);
8929a16e87a515b7071399479548158b8c5fbdd2vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_PHYS, NULL, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
ee6e48c229ef52aee5e968d956ebd066073811abvboxsync /* there is no allocation here, it needs to be mapped somewhere first. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Phys.fAllocated = false;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Phys.PhysBase = Phys;
e4527e0a08e2d635a679ae2947d42195f30a2ce2vboxsync pMemFreeBSD->Core.u.Phys.uCachePolicy = uCachePolicy;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync/**
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync * Worker locking the memory in either kernel or user maps.
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsyncstatic int rtR0MemObjNativeLockInMap(PPRTR0MEMOBJINTERNAL ppMem, vm_map_t pVmMap,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_offset_t AddrStart, size_t cb, uint32_t fAccess,
7f18b4c79440e724c5e08f007674ea7883ce6c01vboxsync RTR0PROCESS R0Process, int fFlags)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync int rc;
db3d025f28c59aececbbda4174fa513496c89b2bvboxsync NOREF(fAccess);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_LOCK, (void *)AddrStart, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync /*
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.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync rc = vm_map_wire(pVmMap, /* the map */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync AddrStart, /* start */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync AddrStart + cb, /* end */
7f18b4c79440e724c5e08f007674ea7883ce6c01vboxsync fFlags); /* flags */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (rc == KERN_SUCCESS)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Lock.R0Process = R0Process;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return VERR_NO_MEMORY;/** @todo fix mach -> vbox error conversion for freebsd. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync return rtR0MemObjNativeLockInMap(ppMem,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync &((struct proc *)R0Process)->p_vmspace->vm_map,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync (vm_offset_t)R3Ptr,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync cb,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync fAccess,
7f18b4c79440e724c5e08f007674ea7883ce6c01vboxsync R0Process,
7f18b4c79440e724c5e08f007674ea7883ce6c01vboxsync VM_MAP_WIRE_USER | VM_MAP_WIRE_NOHOLES);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync}
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, uint32_t fAccess)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync{
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync return rtR0MemObjNativeLockInMap(ppMem,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync kernel_map,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync (vm_offset_t)pv,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync cb,
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync fAccess,
7f18b4c79440e724c5e08f007674ea7883ce6c01vboxsync NIL_RTR0PROCESS,
7f18b4c79440e724c5e08f007674ea7883ce6c01vboxsync VM_MAP_WIRE_SYSTEM | VM_MAP_WIRE_NOHOLES);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync/**
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * Worker for the two virtual address space reservers.
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync *
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * We're leaning on the examples provided by mmap and vm_mmap in vm_mmap.c here.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsyncstatic int rtR0MemObjNativeReserveInMap(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process, vm_map_t pMap)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync{
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync int rc;
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync /*
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * The pvFixed address range must be within the VM space when specified.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (pvFixed != (void *)-1
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync && ( (vm_offset_t)pvFixed < vm_map_min(pMap)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync || (vm_offset_t)pvFixed + cb > vm_map_max(pMap)))
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return VERR_INVALID_PARAMETER;
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync /*
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync * Check that the specified alignment is supported.
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync */
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync if (uAlignment > PAGE_SIZE)
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync return VERR_NOT_SUPPORTED;
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync /*
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync * Create the object.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(*pMemFreeBSD), RTR0MEMOBJTYPE_RES_VIRT, NULL, cb);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (!pMemFreeBSD)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return VERR_NO_MEMORY;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync /*
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync * Allocate an empty VM object and map it into the requested map.
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync pMemFreeBSD->u.NonPhys.pObject = vm_object_allocate(OBJT_DEFAULT, cb >> PAGE_SHIFT);
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync if (pMemFreeBSD->u.NonPhys.pObject)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync {
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync vm_offset_t MapAddress = pvFixed != (void *)-1
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync ? (vm_offset_t)pvFixed
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync : vm_map_min(pMap);
0ff2f0d33dea0e82857c2131d43f637c206a8163vboxsync if (pvFixed != (void *)-1)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync vm_map_remove(pMap,
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync MapAddress,
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync MapAddress + cb);
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync rc = vm_map_find(pMap, /* map */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync pMemFreeBSD->u.NonPhys.pObject, /* object */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync 0, /* offset */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync &MapAddress, /* addr (IN/OUT) */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync cb, /* length */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync pvFixed == (void *)-1, /* find_space */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync VM_PROT_NONE, /* protection */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync VM_PROT_ALL, /* max(_prot) ?? */
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync 0); /* cow (copy-on-write) */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (rc == KERN_SUCCESS)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync {
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if (R0Process != NIL_RTR0PROCESS)
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync {
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync rc = vm_map_inherit(pMap,
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync MapAddress,
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync MapAddress + cb,
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync VM_INHERIT_SHARE);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync AssertMsg(rc == KERN_SUCCESS, ("%#x\n", rc));
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync }
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync pMemFreeBSD->Core.pv = (void *)MapAddress;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync pMemFreeBSD->Core.u.ResVirt.R0Process = R0Process;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync *ppMem = &pMemFreeBSD->Core;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return VINF_SUCCESS;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync }
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync vm_object_deallocate(pMemFreeBSD->u.NonPhys.pObject);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync rc = VERR_NO_MEMORY; /** @todo fix translation (borrow from darwin) */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync }
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync else
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync rc = VERR_NO_MEMORY;
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return rc;
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync}
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return rtR0MemObjNativeReserveInMap(ppMem, pvFixed, cb, uAlignment, NIL_RTR0PROCESS, kernel_map);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
c5d2523548cc57504b829f53f1362b848a84542cvboxsync return rtR0MemObjNativeReserveInMap(ppMem, (void *)R3PtrFixed, cb, uAlignment, R0Process,
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync &((struct proc *)R0Process)->p_vmspace->vm_map);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync unsigned fProt, size_t offSub, size_t cbSub)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
fbb3513a43135c633f7f51544c4bdfce748929bfvboxsync AssertMsgReturn(!offSub && !cbSub, ("%#x %#x\n", offSub, cbSub), VERR_NOT_SUPPORTED);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync /*
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync * Check that the specified alignment is supported.
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync */
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync if (uAlignment > PAGE_SIZE)
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync return VERR_NOT_SUPPORTED;
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync
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
a9ed90fc7da3c371bc3b96c8535655b87836fcadvboxsync return VERR_NOT_SUPPORTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
c889bbab784ba8552102ce776b6c67b982017861vboxsync
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync/* see http://markmail.org/message/udhq33tefgtyfozs */
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync /*
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync * Check for unsupported stuff.
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
c5d2523548cc57504b829f53f1362b848a84542cvboxsync AssertMsgReturn(R3PtrFixed == (RTR3PTR)-1, ("%p\n", R3PtrFixed), VERR_NOT_SUPPORTED);
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync if (uAlignment > PAGE_SIZE)
ad1e35f9fb71d147c2126449a25adf0f8e155aaavboxsync return VERR_NOT_SUPPORTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync int rc;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync PRTR0MEMOBJFREEBSD pMemToMapFreeBSD = (PRTR0MEMOBJFREEBSD)pMemToMap;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync struct proc *pProc = (struct proc *)R0Process;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync struct vm_map *pProcMap = &pProc->p_vmspace->vm_map;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync
c889bbab784ba8552102ce776b6c67b982017861vboxsync /* calc protection */
c889bbab784ba8552102ce776b6c67b982017861vboxsync vm_prot_t ProtectionFlags = 0;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync if ((fProt & RTMEM_PROT_NONE) == RTMEM_PROT_NONE)
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync ProtectionFlags = VM_PROT_NONE;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync if ((fProt & RTMEM_PROT_READ) == RTMEM_PROT_READ)
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync ProtectionFlags |= VM_PROT_READ;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync if ((fProt & RTMEM_PROT_WRITE) == RTMEM_PROT_WRITE)
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync ProtectionFlags |= VM_PROT_WRITE;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync if ((fProt & RTMEM_PROT_EXEC) == RTMEM_PROT_EXEC)
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync ProtectionFlags |= VM_PROT_EXECUTE;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync
c889bbab784ba8552102ce776b6c67b982017861vboxsync /* calc mapping address */
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync PROC_LOCK(pProc);
c889bbab784ba8552102ce776b6c67b982017861vboxsync vm_offset_t AddrR3 = round_page((vm_offset_t)pProc->p_vmspace->vm_daddr + lim_max(pProc, RLIMIT_DATA));
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync PROC_UNLOCK(pProc);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync /* Insert the object in the map. */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync rc = vm_map_find(pProcMap, /* Map to insert the object in */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync NULL, /* Object to map */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync 0, /* Start offset in the object */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync &AddrR3, /* Start address IN/OUT */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync pMemToMap->cb, /* Size of the mapping */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync TRUE, /* Whether a suitable address should be searched for first */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync ProtectionFlags, /* protection flags */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync VM_PROT_ALL, /* Maximum protection flags */
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync 0); /* Copy on write */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync /* Map the memory page by page into the destination map. */
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync if (rc == KERN_SUCCESS)
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync {
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync size_t cPages = pMemToMap->cb >> PAGE_SHIFT;;
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync pmap_t pPhysicalMap = pProcMap->pmap;
81fcf0038d2d6c76ab2c8b02103dc18c24efe0a1vboxsync vm_offset_t AddrR3Dst = AddrR3;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync if ( pMemToMap->enmType == RTR0MEMOBJTYPE_PHYS
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync || pMemToMap->enmType == RTR0MEMOBJTYPE_PHYS_NC
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync || pMemToMap->enmType == RTR0MEMOBJTYPE_PAGE)
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync {
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync /* Mapping physical allocations */
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync Assert(cPages == pMemToMapFreeBSD->u.Phys.cPages);
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync /* Insert the memory page by page into the mapping. */
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync for (uint32_t iPage = 0; iPage < cPages; iPage++)
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync {
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync vm_page_t pPage = pMemToMapFreeBSD->u.Phys.apPages[iPage];
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync MY_PMAP_ENTER(pPhysicalMap, AddrR3Dst, pPage, ProtectionFlags, TRUE);
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync AddrR3Dst += PAGE_SIZE;
4d32c71a938b979c6aeee321ae325d5793a5ccdbvboxsync }
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync }
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync else
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync {
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync /* Mapping cont or low memory types */
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync vm_offset_t AddrToMap = (vm_offset_t)pMemToMap->pv;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync for (uint32_t iPage = 0; iPage < cPages; iPage++)
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync {
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync vm_page_t pPage = PHYS_TO_VM_PAGE(vtophys(AddrToMap));
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync MY_PMAP_ENTER(pPhysicalMap, AddrR3Dst, pPage, ProtectionFlags, TRUE);
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync AddrR3Dst += PAGE_SIZE;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync AddrToMap += PAGE_SIZE;
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync }
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync if (RT_SUCCESS(rc))
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync /*
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync * Create a mapping object for it.
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync */
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(sizeof(RTR0MEMOBJFREEBSD),
c889bbab784ba8552102ce776b6c67b982017861vboxsync RTR0MEMOBJTYPE_MAPPING,
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync (void *)AddrR3,
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync pMemToMap->cb);
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync if (pMemFreeBSD)
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync {
c889bbab784ba8552102ce776b6c67b982017861vboxsync Assert((vm_offset_t)pMemFreeBSD->Core.pv == AddrR3);
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync pMemFreeBSD->Core.u.Mapping.R0Process = R0Process;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync *ppMem = &pMemFreeBSD->Core;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync return VINF_SUCCESS;
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync }
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync
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"));
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
ab02aeaf2a0312fe9267a292e3911728e4531332vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(int) rtR0MemObjNativeProtect(PRTR0MEMOBJINTERNAL pMem, size_t offSub, size_t cbSub, uint32_t fProt)
31cda52093d58f5c604589fa74949c5fddcbde70vboxsync{
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_prot_t ProtectionFlags = 0;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_offset_t AddrStart = (uintptr_t)pMem->pv + offSub;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_offset_t AddrEnd = AddrStart + cbSub;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync vm_map_t pVmMap = rtR0MemObjFreeBSDGetMap(pMem);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync if (!pVmMap)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync return VERR_NOT_SUPPORTED;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync if ((fProt & RTMEM_PROT_NONE) == RTMEM_PROT_NONE)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync ProtectionFlags = VM_PROT_NONE;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync if ((fProt & RTMEM_PROT_READ) == RTMEM_PROT_READ)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync ProtectionFlags |= VM_PROT_READ;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync if ((fProt & RTMEM_PROT_WRITE) == RTMEM_PROT_WRITE)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync ProtectionFlags |= VM_PROT_WRITE;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync if ((fProt & RTMEM_PROT_EXEC) == RTMEM_PROT_EXEC)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync ProtectionFlags |= VM_PROT_EXECUTE;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync int krc = vm_map_protect(pVmMap, AddrStart, AddrEnd, ProtectionFlags, FALSE);
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync if (krc == KERN_SUCCESS)
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync return VINF_SUCCESS;
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync
31cda52093d58f5c604589fa74949c5fddcbde70vboxsync return VERR_NOT_SUPPORTED;
31cda52093d58f5c604589fa74949c5fddcbde70vboxsync}
31cda52093d58f5c604589fa74949c5fddcbde70vboxsync
31cda52093d58f5c604589fa74949c5fddcbde70vboxsync
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsyncDECLHIDDEN(RTHCPHYS) rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)pMem;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync switch (pMemFreeBSD->Core.enmType)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_LOCK:
6f058039e7b13efc3278b9bc84cf0fd135614b67vboxsync {
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync if ( pMemFreeBSD->Core.u.Lock.R0Process != NIL_RTR0PROCESS
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync && pMemFreeBSD->Core.u.Lock.R0Process != (RTR0PROCESS)curproc)
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync {
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync /* later */
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync return NIL_RTHCPHYS;
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync }
6f058039e7b13efc3278b9bc84cf0fd135614b67vboxsync
6f058039e7b13efc3278b9bc84cf0fd135614b67vboxsync vm_offset_t pb = (vm_offset_t)pMemFreeBSD->Core.pv + (iPage << PAGE_SHIFT);
6f058039e7b13efc3278b9bc84cf0fd135614b67vboxsync
6f058039e7b13efc3278b9bc84cf0fd135614b67vboxsync struct proc *pProc = (struct proc *)pMemFreeBSD->Core.u.Lock.R0Process;
6f058039e7b13efc3278b9bc84cf0fd135614b67vboxsync struct vm_map *pProcMap = &pProc->p_vmspace->vm_map;
6f058039e7b13efc3278b9bc84cf0fd135614b67vboxsync pmap_t pPhysicalMap = pProcMap->pmap;
6f058039e7b13efc3278b9bc84cf0fd135614b67vboxsync
6f058039e7b13efc3278b9bc84cf0fd135614b67vboxsync return pmap_extract(pPhysicalMap, pb);
6f058039e7b13efc3278b9bc84cf0fd135614b67vboxsync }
6f058039e7b13efc3278b9bc84cf0fd135614b67vboxsync
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync case RTR0MEMOBJTYPE_MAPPING:
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync {
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync vm_offset_t pb = (vm_offset_t)pMemFreeBSD->Core.pv + (iPage << PAGE_SHIFT);
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync if (pMemFreeBSD->Core.u.Mapping.R0Process != NIL_RTR0PROCESS)
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync {
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync struct proc *pProc = (struct proc *)pMemFreeBSD->Core.u.Mapping.R0Process;
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync struct vm_map *pProcMap = &pProc->p_vmspace->vm_map;
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync pmap_t pPhysicalMap = pProcMap->pmap;
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync return pmap_extract(pPhysicalMap, pb);
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync }
d9a86bd327291cd44d5f6da6e08bec728aae68bbvboxsync return vtophys(pb);
82c6fd518728c98e8bae58f3c5e55c5efa160878vboxsync }
e5bfc5c34142a7550be3564a8e01a037b1db5b31vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_CONT:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return pMemFreeBSD->Core.u.Cont.Phys + (iPage << PAGE_SHIFT);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_PHYS:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return pMemFreeBSD->Core.u.Phys.PhysBase + (iPage << PAGE_SHIFT);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
7f4b4ec1cadbf891d2756ce77dc4a4ec220a03bcvboxsync case RTR0MEMOBJTYPE_PAGE:
c5d2523548cc57504b829f53f1362b848a84542cvboxsync case RTR0MEMOBJTYPE_PHYS_NC:
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync return VM_PAGE_TO_PHYS(pMemFreeBSD->u.Phys.apPages[iPage]);
00cc5d93f7446d9394a0f6b7ad790b9fb9d6005cvboxsync
ad836b4d6fb2ccaf969666246c2c389a8d10ca41vboxsync#ifdef USE_KMEM_ALLOC_ATTR
ad836b4d6fb2ccaf969666246c2c389a8d10ca41vboxsync case RTR0MEMOBJTYPE_LOW:
ad836b4d6fb2ccaf969666246c2c389a8d10ca41vboxsync {
ad836b4d6fb2ccaf969666246c2c389a8d10ca41vboxsync vm_offset_t pb = (vm_offset_t)pMemFreeBSD->Core.pv + (iPage << PAGE_SHIFT);
ad836b4d6fb2ccaf969666246c2c389a8d10ca41vboxsync return vtophys(pb);
ad836b4d6fb2ccaf969666246c2c389a8d10ca41vboxsync }
ad836b4d6fb2ccaf969666246c2c389a8d10ca41vboxsync#else
d60d5da33bb93fc7a8717802f21b13aa37914799vboxsync case RTR0MEMOBJTYPE_LOW:
ad836b4d6fb2ccaf969666246c2c389a8d10ca41vboxsync#endif
ad836b4d6fb2ccaf969666246c2c389a8d10ca41vboxsync case RTR0MEMOBJTYPE_RES_VIRT:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync default:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return NIL_RTHCPHYS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
c889bbab784ba8552102ce776b6c67b982017861vboxsync