memobj-r0drv-nt.cpp revision fbb3513a43135c633f7f51544c4bdfce748929bf
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * IPRT - Ring-0 Memory Objects, NT.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * available from http://www.virtualbox.org. This file is free software;
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * you can redistribute it and/or modify it under the terms of the GNU
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * General Public License (GPL) as published by the Free Software
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * The contents of this file may alternatively be used under the terms
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * of the Common Development and Distribution License Version 1.0
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * VirtualBox OSE distribution, in which case the provisions of the
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * CDDL are applicable instead of those of the GPL.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * You may elect to license modified versions of this file under the
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * terms and conditions of either the GPL or the CDDL or both.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * additional information or have any questions.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/*******************************************************************************
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync* Header Files *
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync*******************************************************************************/
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/*******************************************************************************
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync* Defined Constants And Macros *
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync*******************************************************************************/
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/** Maximum number of bytes we try to lock down in one go.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * This is supposed to have a limit right below 256MB, but this appears
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * to actually be much lower. The values here have been determined experimentally.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync# define MAX_LOCK_MEM_SIZE (32*1024*1024) /* 32MB */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync# define MAX_LOCK_MEM_SIZE (24*1024*1024) /* 24MB */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/*******************************************************************************
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync* Structures and Typedefs *
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync*******************************************************************************/
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * The NT version of the memory object structure.
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsynctypedef struct RTR0MEMOBJNT
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync /** The core structure. */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync /** Used MmAllocatePagesForMdl(). */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync /** Pointer returned by MmSecureVirtualMemory */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync /** The number of PMDLs (memory descriptor lists) in the array. */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync /** Array of MDL pointers. (variable size) */
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync * Deal with it on a per type basis (just as a variation).
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync Assert(pMemNt->Core.pv && pMemNt->cMdls == 1 && pMemNt->apMdls[0]);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync MmUnmapLockedPages(pMemNt->Core.pv, pMemNt->apMdls[0]);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync/* if (pMemNt->Core.u.ResVirt.R0Process == NIL_RTR0PROCESS)
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync PRTR0MEMOBJNT pMemNtParent = (PRTR0MEMOBJNT)pMemNt->Core.uRel.Child.pParent;
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync Assert(pMemNtParent->cMdls == 1 && pMemNtParent->apMdls[0]);
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync Assert( pMemNt->Core.u.Mapping.R0Process == NIL_RTR0PROCESS
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync || pMemNt->Core.u.Mapping.R0Process == RTR0ProcHandleSelf());
0b74a2f80aba476dc8be8bc1c63891fc53945986vboxsync MmUnmapLockedPages(pMemNt->Core.pv, pMemNtParent->apMdls[0]);
return VERR_INTERNAL_ERROR;
return VINF_SUCCESS;
if (pv)
if (pMdl)
#ifdef RT_ARCH_AMD64
if (pMemNt)
return VINF_SUCCESS;
return rc;
while (iPage-- > 0)
return rc;
#ifndef IPRT_TARGET_NT4
if (pMdl)
if (pv)
if (pMemNt)
return VINF_SUCCESS;
static int rtR0MemObjNativeAllocContEx(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable, RTHCPHYS PhysHighest)
if (!pv)
return VERR_NO_MEMORY;
if (pMdl)
#ifdef RT_ARCH_AMD64
if (pMemNt)
return VINF_SUCCESS;
return VERR_NO_MEMORY;
#ifndef IPRT_TARGET_NT4
if (pMdl)
PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_PHYS, NULL, cb);
if (pMemNt)
return VINF_SUCCESS;
#ifndef IPRT_TARGET_NT4
if (pMdl)
PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_PHYS_NC, NULL, cb);
if (pMemNt)
return VINF_SUCCESS;
return VERR_NO_MEMORY;
return VERR_NOT_SUPPORTED;
return VERR_ADDRESS_TOO_BIG;
PRTR0MEMOBJNT pMemNt = (PRTR0MEMOBJNT)rtR0MemObjNew(sizeof(*pMemNt), RTR0MEMOBJTYPE_PHYS, NULL, cb);
if (pMemNt)
return VINF_SUCCESS;
return VERR_NO_MEMORY;
cMdls++;
return VERR_OUT_OF_RANGE;
if (!pMemNt)
return VERR_NO_MEMORY;
if (!pMdl)
return rc;
while (iMdl-- > 0)
return rc;
int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process)
AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED);
int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment)
return VERR_NOT_IMPLEMENTED;
int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process)
return VERR_NOT_IMPLEMENTED;
static int rtR0MemObjNtMap(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
return VERR_NOT_SUPPORTED;
if (pvFixed == 0)
return VERR_NOT_SUPPORTED;
return VERR_NOT_SUPPORTED;
if (pv)
if (pMemNt)
return VINF_SUCCESS;
return VERR_NOT_SUPPORTED;
void *pv = MmMapIoSpace(Phys, pMemNtToMap->Core.cb, MmCached); /** @todo add cache type to fProt. */
if (pv)
if (pMemNt)
return VINF_SUCCESS;
return rc;
int rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, void *pvFixed, size_t uAlignment,
int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, RTR0MEMOBJ pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process)
case RTR0MEMOBJTYPE_MAPPING:
case RTR0MEMOBJTYPE_PHYS:
case RTR0MEMOBJTYPE_PAGE:
case RTR0MEMOBJTYPE_PHYS_NC:
case RTR0MEMOBJTYPE_LOW:
case RTR0MEMOBJTYPE_CONT:
case RTR0MEMOBJTYPE_LOCK:
case RTR0MEMOBJTYPE_RES_VIRT:
return NIL_RTHCPHYS;