memobj-r0drv-freebsd.c revision 833f83ce101b6e9168f519decc0dc7a1079d35f7
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/* $Id$ */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/** @file
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * innotek Portable Runtime - 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/*******************************************************************************
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;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#if 0
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /** Lock for the ring-3 / ring-0 pinned objectes.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * This member might not be allocated for some object types. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync KernVMLock_t Lock;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /** Array of physical pages.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * This array can be 0 in length for some object types. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync KernPageList_t aPages[1];
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync} RTR0MEMOBJFREEBSD, *PRTR0MEMOBJFREEBSD;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/*******************************************************************************
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync* Internal Functions *
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync*******************************************************************************/
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeFree(RTR0MEMOBJ pMem)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)pMem;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync// int rc;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync switch (pMemFreeBSD->Core.enmType)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_PHYS:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD->Core.pv)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_MAPPING:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (pMemFreeBSD->Core.u.Mapping.R0Process == NIL_RTR0PROCESS)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* fall thru */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_PAGE:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_LOW:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_CONT:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync //rc = KernVMFree(pMemFreeBSD->Core.pv);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync //AssertMsg(!rc, ("rc=%d type=%d pv=%p cb=%#zx\n", rc, pMemFreeBSD->Core.enmType, pMemFreeBSD->Core.pv, pMemFreeBSD->Core.cb));
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_LOCK:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync //rc = KernVMUnlock(&pMemFreeBSD->Lock);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync //AssertMsg(!rc, ("rc=%d\n", rc));
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_RES_VIRT:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync default:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgFailed(("enmType=%d\n", pMemFreeBSD->Core.enmType));
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_INTERNAL_ERROR;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync NOREF(fExecutable);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#if 0
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync const ULONG cPages = cb >> PAGE_SHIFT;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_PAGE, NULL, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* do the allocation. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync int rc = KernVMAlloc(cb, VMDHA_FIXED, &pMemFreeBSD->Core.pv, (PPVOID)-1, NULL);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!rc)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync ULONG cPagesRet = cPages;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rc = KernLinToPageList(pMemFreeBSD->Core.pv, cb, &pMemFreeBSD->aPages[0], &cPagesRet);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!rc)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjFixPageList(&pMemFreeBSD->aPages[0], cPages, cPagesRet);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync KernVMFree(pMemFreeBSD->Core.pv);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return RTErrConvertFromOS2(rc);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_IMPLEMENTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync NOREF(fExecutable);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#if 0
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync const ULONG cPages = cb >> PAGE_SHIFT;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOW, NULL, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* do the allocation. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync int rc = KernVMAlloc(cb, VMDHA_FIXED, &pMemFreeBSD->Core.pv, (PPVOID)-1, NULL);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!rc)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync ULONG cPagesRet = cPages;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rc = KernLinToPageList(pMemFreeBSD->Core.pv, cb, &pMemFreeBSD->aPages[0], &cPagesRet);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!rc)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjFixPageList(&pMemFreeBSD->aPages[0], cPages, cPagesRet);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync KernVMFree(pMemFreeBSD->Core.pv);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return RTErrConvertFromOS2(rc);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_IMPLEMENTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync NOREF(fExecutable);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#if 0
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_CONT, NULL, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* do the allocation. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync ULONG ulPhys = ~0UL;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG, &pMemFreeBSD->Core.pv, (PPVOID)&ulPhys, NULL);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!rc)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync Assert(ulPhys != ~0UL);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Cont.Phys = ulPhys;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return RTErrConvertFromOS2(rc);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_IMPLEMENTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%VHp\n", PhysHighest), VERR_NOT_IMPLEMENTED);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#if 0
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* do the allocation. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync ULONG ulPhys = ~0UL;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G ? VMDHA_16M : 0), &pMemFreeBSD->Core.pv, (PPVOID)&ulPhys, NULL);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!rc)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync Assert(ulPhys != ~0UL);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Phys.fAllocated = true;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Phys.PhysBase = ulPhys;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return RTErrConvertFromOS2(rc);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_IMPLEMENTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#if 0
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* there is no allocation here, right? it needs to be mapped somewhere first. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Phys.fAllocated = false;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Phys.PhysBase = Phys;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_IMPLEMENTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, RTR0PROCESS R0Process)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#if 0
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync const ULONG cPages = cb >> PAGE_SHIFT;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, pv, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* lock it. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync ULONG cPagesRet = cPages;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync int rc = KernVMLock(VMDHL_LONG | VMDHL_WRITE, pv, cb, &pMemFreeBSD->Lock, &pMemFreeBSD->aPages[0], &cPagesRet);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!rc)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjFixPageList(&pMemFreeBSD->aPages[0], cPages, cPagesRet);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync Assert(cb == pMemFreeBSD->Core.cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync Assert(pv == pMemFreeBSD->Core.pv);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Lock.R0Process = R0Process;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return RTErrConvertFromOS2(rc);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_IMPLEMENTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#if 0
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* create the object. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync const ULONG cPages = cb >> PAGE_SHIFT;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, pv, cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /* lock it. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync ULONG cPagesRet = cPages;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync int rc = KernVMLock(VMDHL_LONG | VMDHL_WRITE, pv, cb, &pMemFreeBSD->Lock, &pMemFreeBSD->aPages[0], &cPagesRet);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!rc)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjFixPageList(&pMemFreeBSD->aPages[0], cPages, cPagesRet);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Lock.R0Process = NIL_RTR0PROCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rtR0MemObjDelete(&pMemFreeBSD->Core);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return RTErrConvertFromOS2(rc);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_IMPLEMENTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_IMPLEMENTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_IMPLEMENTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment, unsigned fProt)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#if 0
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync/** @todo finish the implementation. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync int rc;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync void *pvR0 = NULL;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemToMapOs2 = (PRTR0MEMOBJFREEBSD)pMemToMap;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync switch (pMemToMapOs2->Core.enmType)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /*
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * These has kernel mappings.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_PAGE:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_LOW:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_CONT:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pvR0 = pMemToMapOs2->Core.pv;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_PHYS:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pvR0 = pMemToMapOs2->Core.pv;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pvR0)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
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 Assert(!pMemToMapOs2->Core.u.Phys.fAllocated);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync ULONG ulPhys = pMemToMapOs2->Core.u.Phys.PhysBase;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rc = KernVMAlloc(pMemToMapOs2->Core.cb, VMDHA_PHYS, &pvR0, (PPVOID)&ulPhys, NULL);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (rc)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return RTErrConvertFromOS2(rc);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemToMapOs2->Core.pv = pvR0;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_LOCK:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (pMemToMapOs2->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_SUPPORTED; /** @todo implement this... */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pvR0 = pMemToMapOs2->Core.pv;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_RES_VIRT:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_MAPPING:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync default:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgFailed(("enmType=%d\n", pMemToMapOs2->Core.enmType));
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_INTERNAL_ERROR;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /*
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * Create a dummy mapping object for it.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * 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 */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR0, pMemToMapOs2->Core.cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_IMPLEMENTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncint rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#if 0
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync int rc;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync void *pvR0;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync void *pvR3 = NULL;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemToMapOs2 = (PRTR0MEMOBJFREEBSD)pMemToMap;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync switch (pMemToMapOs2->Core.enmType)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /*
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * These has kernel mappings.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_PAGE:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_LOW:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_CONT:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pvR0 = pMemToMapOs2->Core.pv;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_PHYS:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pvR0 = pMemToMapOs2->Core.pv;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#if 0/* this is wrong. */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pvR0)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
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 Assert(!pMemToMapOs2->Core.u.Phys.fAllocated);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync ULONG ulPhys = pMemToMapOs2->Core.u.Phys.PhysBase;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rc = KernVMAlloc(pMemToMapOs2->Core.cb, VMDHA_PHYS | VMDHA_PROCESS, &pvR3, (PPVOID)&ulPhys, NULL);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (rc)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return RTErrConvertFromOS2(rc);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_SUPPORTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_LOCK:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (pMemToMapOs2->Core.u.Lock.R0Process != NIL_RTR0PROCESS)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_SUPPORTED; /** @todo implement this... */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pvR0 = pMemToMapOs2->Core.pv;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync break;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_RES_VIRT:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_MAPPING:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync default:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync AssertMsgFailed(("enmType=%d\n", pMemToMapOs2->Core.enmType));
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_INTERNAL_ERROR;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /*
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * Map the ring-0 memory into the current process.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (!pvR3)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync Assert(pvR0);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync ULONG flFlags = 0;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (uAlignment == PAGE_SIZE)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync flFlags |= VMDHGP_4MB;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (fProt & RTMEM_PROT_WRITE)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync flFlags |= VMDHGP_WRITE;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync rc = RTR0Os2DHVMGlobalToProcess(flFlags, pvR0, pMemToMapOs2->Core.cb, &pvR3);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (rc)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return RTErrConvertFromOS2(rc);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync Assert(pvR3);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync /*
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync * Create a mapping object for it.
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync */
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR3, pMemToMapOs2->Core.cb);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync if (pMemFreeBSD)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync Assert(pMemFreeBSD->Core.pv == pvR3);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync pMemFreeBSD->Core.u.Mapping.R0Process = R0Process;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync *ppMem = &pMemFreeBSD->Core;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VINF_SUCCESS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync KernVMFree(pvR3);
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NO_MEMORY;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync#endif
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return VERR_NOT_IMPLEMENTED;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncRTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, unsigned iPage)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync{
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)pMem;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync switch (pMemFreeBSD->Core.enmType)
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync {
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_PAGE:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_LOW:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_LOCK:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync// return pMemFreeBSD->aPages[iPage].Addr;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsyncreturn NIL_RTHCPHYS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync
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
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_RES_VIRT:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync case RTR0MEMOBJTYPE_MAPPING:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync default:
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync return NIL_RTHCPHYS;
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync }
833f83ce101b6e9168f519decc0dc7a1079d35f7vboxsync}