memobj.h revision 9d80662bfa36cc718a22f982d48148415ca95fb8
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/* $Revision$ */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/** @file
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * innotek Portable Runtime - Ring-0 Memory Objects.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/*
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Copyright (C) 2006-2007 innotek GmbH
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * available from http://www.virtualbox.org. This file is free software;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * General Public License (GPL) as published by the Free Software
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * The contents of this file may alternatively be used under the terms
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * of the Common Development and Distribution License Version 1.0
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * VirtualBox OSE distribution, in which case the provisions of the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * CDDL are applicable instead of those of the GPL.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync *
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * You may elect to license modified versions of this file under the
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync * terms and conditions of either the GPL or the CDDL or both.
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync */
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync
930b5f872e89407f445d4000d4e4aaecaa6a0998vboxsync#ifndef ___internal_memobj_h
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#define ___internal_memobj_h
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#include <iprt/memobj.h>
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#include <iprt/assert.h>
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync#include "internal/magics.h"
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync__BEGIN_DECLS
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/** @defgroup grp_rt_memobj_int Internals.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @ingroup grp_rt_memobj
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @internal
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @{
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Ring-0 memory object type.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsynctypedef enum RTR0MEMOBJTYPE
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync{
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The traditional invalid value. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0MEMOBJTYPE_INVALID = 0,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** @name Primary types (parents)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @{ */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MemObjAllocPage.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This memory is page aligned and fixed. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0MEMOBJTYPE_PAGE,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MemObjAllocLow.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This memory is page aligned, fixed and is backed by physical memory below 4GB. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0MEMOBJTYPE_LOW,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MemObjAllocCont.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This memory is page aligned, fixed and is backed by contiguous physical memory below 4GB. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0MEMOBJTYPE_CONT,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MemObjLockKernel, RTR0MemObjLockUser.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This memory is page aligned and fixed. It was locked/pinned/wired down by the API call. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0MEMOBJTYPE_LOCK,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MemObjAllocPhys, RTR0MemObjEnterPhys.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This memory is physical memory, page aligned, contiguous and doesn't need to have a mapping. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0MEMOBJTYPE_PHYS,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MemObjAllocPhysNC.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This memory is physical memory, page aligned and doesn't need to have a mapping. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0MEMOBJTYPE_PHYS_NC,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MemObjReserveKernel, RTR0MemObjReserveUser.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This memory is page aligned and has no backing. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0MEMOBJTYPE_RES_VIRT,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** @} */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** @name Secondary types (children)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @{
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MemObjMapUser, RTR0MemObjMapKernel.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This is a user or kernel context mapping of another ring-0 memory object. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0MEMOBJTYPE_MAPPING,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** @} */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The end of the valid types. Used for sanity checking. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0MEMOBJTYPE_END
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync} RTR0MEMOBJTYPE;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsynctypedef struct RTR0MEMOBJINTERNAL *PRTR0MEMOBJINTERNAL;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsynctypedef struct RTR0MEMOBJINTERNAL **PPRTR0MEMOBJINTERNAL;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Ring-0 memory object.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * When using the PRTR0MEMOBJINTERNAL and PPRTR0MEMOBJINTERNAL types
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * we get pMem and ppMem variable names.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * When using the RTR0MEMOBJ and PRTR0MEMOBJ types we get MemObj and
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * pMemObj variable names. We never dereference variables of the RTR0MEMOBJ
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * type, we always convert it to a PRTR0MEMOBJECTINTERNAL variable first.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsynctypedef struct RTR0MEMOBJINTERNAL
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync{
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Magic number (RTR0MEM_MAGIC). */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync uint32_t u32Magic;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The size of this structure. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync uint32_t cbSelf;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The type of allocation. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0MEMOBJTYPE enmType;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The size of the memory allocated, pinned down, or mapped. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync size_t cb;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The memory address.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * What this really is varies with the type.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * For PAGE, CONT, LOW, RES_VIRT/R0, LOCK/R0 and MAP/R0 it's the ring-0 mapping.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * For LOCK/R3, RES_VIRT/R3 and MAP/R3 it is the ring-3 mapping.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * For PHYS this might actually be NULL if there isn't any mapping.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync void *pv;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Object relations. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync union
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** This is for tracking child memory handles mapping the
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * memory described by the primary handle. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync struct
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Number of mappings. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync uint32_t cMappingsAllocated;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Number of mappings in the array. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync uint32_t cMappings;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Pointers to child handles mapping this memory. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync PPRTR0MEMOBJINTERNAL papMappings;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } Parent;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Pointer to the primary handle. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync struct
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Pointer to the parent. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync PRTR0MEMOBJINTERNAL pParent;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } Child;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } uRel;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** Type specific data for the memory types that requires that. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync union
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MEMTYPE_PAGE. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync struct
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync unsigned iDummy;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } Page;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MEMTYPE_LOW. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync struct
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync unsigned iDummy;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } Low;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MEMTYPE_CONT. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync struct
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The physical address of the first page. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTHCPHYS Phys;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } Cont;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MEMTYPE_LOCK_USER. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync struct
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The process that owns the locked memory.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This is NIL_RTR0PROCESS if it's kernel memory. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0PROCESS R0Process;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } Lock;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MEMTYPE_PHYS. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync struct
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The base address of the physical memory. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTHCPHYS PhysBase;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** If set this object was created by RTR0MemPhysAlloc, otherwise it was
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * created by RTR0MemPhysEnter. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync bool fAllocated;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } Phys;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MEMTYPE_PHYS_NC. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync struct
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync unsigned iDummy;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } PhysNC;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MEMOBJTYPE_RES_VIRT */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync struct
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The process that owns the reserved memory.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This is NIL_RTR0PROCESS if it's kernel memory. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0PROCESS R0Process;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } ResVirt;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** RTR0MEMOBJTYPE_MAPPING */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync struct
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /** The process that owns the reserved memory.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This is NIL_RTR0PROCESS if it's kernel memory. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTR0PROCESS R0Process;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } Mapping;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync } u;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync} RTR0MEMOBJINTERNAL;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Checks if this is mapping or not.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns true if it's a mapping, otherwise false.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param pMem The ring-0 memory object handle.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @see RTR0MemObjIsMapping
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncDECLINLINE(bool) rtR0MemObjIsMapping(PRTR0MEMOBJINTERNAL pMem)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync{
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync switch (pMem->enmType)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync case RTR0MEMOBJTYPE_MAPPING:
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync return true;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync default:
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync return false;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync }
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync}
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Checks if RTR0MEMOBJ::pv is a ring-3 pointer or not.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns true if it's a object with a ring-3 address, otherwise false.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param pMem The ring-0 memory object handle.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncDECLINLINE(bool) rtR0MemObjIsRing3(PRTR0MEMOBJINTERNAL pMem)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync{
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync switch (pMem->enmType)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync {
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync case RTR0MEMOBJTYPE_RES_VIRT:
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync return pMem->u.ResVirt.R0Process != NIL_RTR0PROCESS;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync case RTR0MEMOBJTYPE_LOCK:
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync return pMem->u.Lock.R0Process != NIL_RTR0PROCESS;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync case RTR0MEMOBJTYPE_MAPPING:
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync return pMem->u.Mapping.R0Process != NIL_RTR0PROCESS;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync default:
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync return false;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync }
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync}
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Frees the memory object (but not the handle).
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Any OS specific handle resources will be freed by this call.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns IPRT status code. On failure it is assumed that the object remains valid.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param pMem The ring-0 memory object handle to the memory which should be freed.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncint rtR0MemObjNativeFree(PRTR0MEMOBJINTERNAL pMem);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Allocates page aligned virtual kernel memory.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * The memory is taken from a non paged (= fixed physical memory backing) pool.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns IPRT status code.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param ppMem Where to store the ring-0 memory object handle.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param cb Number of bytes to allocate, page aligned.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncint rtR0MemObjNativeAllocPage(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Allocates page aligned virtual kernel memory with physical backing below 4GB.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * The physical memory backing the allocation is fixed.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns IPRT status code.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param ppMem Where to store the ring-0 memory object handle.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param cb Number of bytes to allocate, page aligned.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncint rtR0MemObjNativeAllocLow(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Allocates page aligned virtual kernel memory with contiguous physical backing below 4GB.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * The physical memory backing the allocation is fixed.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns IPRT status code.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param ppMem Where to store the ring-0 memory object handle.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param cb Number of bytes to allocate, page aligned.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncint rtR0MemObjNativeAllocCont(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, bool fExecutable);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Locks a range of user virtual memory.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns IPRT status code.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param ppMem Where to store the ring-0 memory object handle.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param R3Ptr User virtual address, page aligned.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param cb Number of bytes to lock, page aligned.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param R0Process The process to lock pages in.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncint rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Locks a range of kernel virtual memory.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns IPRT status code.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param ppMem Where to store the ring-0 memory object handle.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param pv Kernel virtual address, page aligned.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param cb Number of bytes to lock, page aligned.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncint rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Allocates contiguous page aligned physical memory without (necessarily) any kernel mapping.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns IPRT status code.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param ppMem Where to store the ring-0 memory object handle.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param cb Number of bytes to allocate, page aligned.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param PhysHighest The highest permittable address (inclusive).
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * NIL_RTHCPHYS if any address is acceptable.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncint rtR0MemObjNativeAllocPhys(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/**
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Allocates non-contiguous page aligned physical memory without (necessarily) any kernel mapping.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync *
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @returns IPRT status code.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * physical memory on this platform.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param ppMem Where to store the ring-0 memory object handle.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param cb Number of bytes to allocate, page aligned.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param PhysHighest The highest permittable address (inclusive).
* NIL_RTHCPHYS if any address is acceptable.
*/
int rtR0MemObjNativeAllocPhysNC(PPRTR0MEMOBJINTERNAL ppMem, size_t cb, RTHCPHYS PhysHighest);
/**
* Creates a page aligned, contiguous, physical memory object.
*
* @returns IPRT status code.
* @param ppMem Where to store the ring-0 memory object handle.
* @param Phys The physical address to start at, page aligned.
* @param cb The size of the object in bytes, page aligned.
*/
int rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb);
/**
* Reserves kernel virtual address space.
*
* @returns IPRT status code.
* Return VERR_NOT_SUPPORTED to indicate that the user should employ fallback strategies.
* @param ppMem Where to store the ring-0 memory object handle.
* @param pvFixed Requested address. (void *)-1 means any address. This matches uAlignment if specified.
* @param cb The number of bytes to reserve, page aligned.
* @param uAlignment The alignment of the reserved memory; PAGE_SIZE, _2M or _4M.
*/
int rtR0MemObjNativeReserveKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pvFixed, size_t cb, size_t uAlignment);
/**
* Reserves user virtual address space in the current process.
*
* @returns IPRT status code.
* @param ppMem Where to store the ring-0 memory object handle.
* @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This matches uAlignment if specified.
* @param cb The number of bytes to reserve, page aligned.
* @param uAlignment The alignment of the reserved memory; PAGE_SIZE, _2M or _4M.
* @param R0Process The process to reserve the memory in.
*/
int rtR0MemObjNativeReserveUser(PPRTR0MEMOBJINTERNAL ppMem, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process);
/**
* Maps a memory object into user virtual address space in the current process.
*
* @returns IPRT status code.
* @param ppMem Where to store the ring-0 memory object handle of the mapping object.
* @param pMemToMap The object to be map.
* @param pvFixed Requested address. (void *)-1 means any address. This matches uAlignment if specified.
* @param uAlignment The alignment of the reserved memory; PAGE_SIZE, _2M or _4M.
* @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
*/
int rtR0MemObjNativeMapKernel(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, void *pvFixed, size_t uAlignment, unsigned fProt);
/**
* Maps a memory object into user virtual address space in the current process.
*
* @returns IPRT status code.
* @param ppMem Where to store the ring-0 memory object handle of the mapping object.
* @param pMemToMap The object to be map.
* @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This matches uAlignment if specified.
* @param uAlignment The alignment of the reserved memory; PAGE_SIZE, _2M or _4M.
* @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
* @param R0Process The process to map the memory into.
*/
int rtR0MemObjNativeMapUser(PPRTR0MEMOBJINTERNAL ppMem, PRTR0MEMOBJINTERNAL pMemToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process);
/**
* Get the physical address of an page in the memory object.
*
* @returns The physical address.
* @returns NIL_RTHCPHYS if the object doesn't contain fixed physical pages.
* @returns NIL_RTHCPHYS if the iPage is out of range.
* @returns NIL_RTHCPHYS if the object handle isn't valid.
* @param pMem The ring-0 memory object handle.
* @param iPage The page number within the object (valid).
*/
RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, size_t iPage);
PRTR0MEMOBJINTERNAL rtR0MemObjNew(size_t cbSelf, RTR0MEMOBJTYPE enmType, void *pv, size_t cb);
void rtR0MemObjDelete(PRTR0MEMOBJINTERNAL pMem);
/** @} */
__END_DECLS
#endif