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