memobj.h revision e296ac49dd5e8fa78ae41750b32e86d491a31f21
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/** @file
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * IPRT - Memory Objects (Ring-0).
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/*
b3eb676cebf5407921b8f535095ca7655edb9db3vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * available from http://www.virtualbox.org. This file is free software;
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * you can redistribute it and/or modify it under the terms of the GNU
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * General Public License (GPL) as published by the Free Software
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * The contents of this file may alternatively be used under the terms
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * of the Common Development and Distribution License Version 1.0
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * VirtualBox OSE distribution, in which case the provisions of the
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * CDDL are applicable instead of those of the GPL.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * You may elect to license modified versions of this file under the
2d97f8baccdd684bc0a8a15eb86bbe9ff2b85374vboxsync * terms and conditions of either the GPL or the CDDL or both.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * additional information or have any questions.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
032703cba22135d6032705fc2d67dd1294a6491avboxsync#ifndef ___iprt_memobj_h
032703cba22135d6032705fc2d67dd1294a6491avboxsync#define ___iprt_memobj_h
032703cba22135d6032705fc2d67dd1294a6491avboxsync
032703cba22135d6032705fc2d67dd1294a6491avboxsync#include <iprt/cdefs.h>
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync#include <iprt/types.h>
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync
032703cba22135d6032705fc2d67dd1294a6491avboxsyncRT_C_DECLS_BEGIN
032703cba22135d6032705fc2d67dd1294a6491avboxsync
032703cba22135d6032705fc2d67dd1294a6491avboxsync/** @defgroup grp_rt_memobj RTMemObj - Memory Object Manipulation (Ring-0)
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * @ingroup grp_rt
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @{
032703cba22135d6032705fc2d67dd1294a6491avboxsync */
032703cba22135d6032705fc2d67dd1294a6491avboxsync
032703cba22135d6032705fc2d67dd1294a6491avboxsync#ifdef IN_RING0
032703cba22135d6032705fc2d67dd1294a6491avboxsync
032703cba22135d6032705fc2d67dd1294a6491avboxsync/**
032703cba22135d6032705fc2d67dd1294a6491avboxsync * Checks if this is mapping or not.
032703cba22135d6032705fc2d67dd1294a6491avboxsync *
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * @returns true if it's a mapping, otherwise false.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @param MemObj The ring-0 memory object handle.
032703cba22135d6032705fc2d67dd1294a6491avboxsync */
032703cba22135d6032705fc2d67dd1294a6491avboxsyncRTR0DECL(bool) RTR0MemObjIsMapping(RTR0MEMOBJ MemObj);
032703cba22135d6032705fc2d67dd1294a6491avboxsync
032703cba22135d6032705fc2d67dd1294a6491avboxsync/**
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * Gets the address of a ring-0 memory object.
032703cba22135d6032705fc2d67dd1294a6491avboxsync *
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @returns The address of the memory object.
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @param MemObj The ring-0 memory object handle.
032703cba22135d6032705fc2d67dd1294a6491avboxsync */
032703cba22135d6032705fc2d67dd1294a6491avboxsyncRTR0DECL(void *) RTR0MemObjAddress(RTR0MEMOBJ MemObj);
032703cba22135d6032705fc2d67dd1294a6491avboxsync
032703cba22135d6032705fc2d67dd1294a6491avboxsync/**
032703cba22135d6032705fc2d67dd1294a6491avboxsync * Gets the ring-3 address of a ring-0 memory object.
032703cba22135d6032705fc2d67dd1294a6491avboxsync *
032703cba22135d6032705fc2d67dd1294a6491avboxsync * This only applies to ring-0 memory object with ring-3 mappings of some kind, i.e.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * locked user memory, reserved user address space and user mappings. This API should
032703cba22135d6032705fc2d67dd1294a6491avboxsync * not be used on any other objects.
032703cba22135d6032705fc2d67dd1294a6491avboxsync *
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @returns The address of the memory object.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @returns NIL_RTR3PTR if the handle is invalid or if it's not an object with a ring-3 mapping.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * Strict builds will assert in both cases.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @param MemObj The ring-0 memory object handle.
032703cba22135d6032705fc2d67dd1294a6491avboxsync */
032703cba22135d6032705fc2d67dd1294a6491avboxsyncRTR0DECL(RTR3PTR) RTR0MemObjAddressR3(RTR0MEMOBJ MemObj);
032703cba22135d6032705fc2d67dd1294a6491avboxsync
032703cba22135d6032705fc2d67dd1294a6491avboxsync/**
032703cba22135d6032705fc2d67dd1294a6491avboxsync * Gets the size of a ring-0 memory object.
032703cba22135d6032705fc2d67dd1294a6491avboxsync *
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @returns The address of the memory object.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @param MemObj The ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(size_t) RTR0MemObjSize(RTR0MEMOBJ MemObj);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Get the physical address of an page in the memory object.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * @returns The physical address.
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * @returns NIL_RTHCPHYS if the object doesn't contain fixed physical pages.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns NIL_RTHCPHYS if the iPage is out of range.
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * @returns NIL_RTHCPHYS if the object handle isn't valid.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param MemObj The ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param iPage The page number within the object.
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync */
315f68b04971772d94ba6c4408eaa19559a77cedvboxsyncRTR0DECL(RTHCPHYS) RTR0MemObjGetPagePhysAddr(RTR0MEMOBJ MemObj, size_t iPage);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Frees a ring-0 memory object.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * @returns IPRT status code.
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * @retval VERR_INVALID_HANDLE if
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param MemObj The ring-0 memory object to be freed. NULL is accepted.
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * @param fFreeMappings Whether or not to free mappings of the object.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjFree(RTR0MEMOBJ MemObj, bool fFreeMappings);
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Allocates page aligned virtual kernel memory.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * The memory is taken from a non paged (= fixed physical memory backing) pool.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cb Number of bytes to allocate. This is rounded up to nearest page.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjAllocPage(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Allocates page aligned virtual kernel memory with physical backing below 4GB.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * The physical memory backing the allocation is fixed.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cb Number of bytes to allocate. This is rounded up to nearest page.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjAllocLow(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Allocates page aligned virtual kernel memory with contiguous physical backing below 4GB.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * The physical memory backing the allocation is fixed.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cb Number of bytes to allocate. This is rounded up to nearest page.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjAllocCont(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Locks a range of user virtual memory.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param R3Ptr User virtual address. This is rounded down to a page
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * boundrary.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cb Number of bytes to lock. This is rounded up to
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * nearest page boundrary.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param fAccess The desired access, a combination of RTMEM_PROT_READ
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * and RTMEM_PROT_WRITE.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param R0Process The process to lock pages in. NIL_R0PROCESS is an
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * alias for the current one.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * down address.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @remarks Linux: This API requires that the memory begin locked is in a memory
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * mapping that is not required in any forked off child process. This
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * is not intented as permanent restriction, feel free to help out
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * lifting it.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjLockUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, uint32_t fAccess, RTR0PROCESS R0Process);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
032703cba22135d6032705fc2d67dd1294a6491avboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Locks a range of kernel virtual memory.
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pv Kernel virtual address. This is rounded down to a page boundrary.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param fAccess The desired access, a combination of RTMEM_PROT_READ
032703cba22135d6032705fc2d67dd1294a6491avboxsync * and RTMEM_PROT_WRITE.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * @remark RTR0MemGetAddress() will return the rounded down address.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjLockKernel(PRTR0MEMOBJ pMemObj, void *pv, size_t cb, uint32_t fAccess);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Allocates contiguous page aligned physical memory without (necessarily) any kernel mapping.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @param pMemObj Where to store the ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cb Number of bytes to allocate. This is rounded up to nearest page.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param PhysHighest The highest permittable address (inclusive).
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync * Pass NIL_RTHCPHYS if any address is acceptable.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjAllocPhys(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Allocates contiguous physical memory without (necessarily) any kernel mapping.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cb Number of bytes to allocate. This is rounded up to nearest page.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @param PhysHighest The highest permittable address (inclusive).
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Pass NIL_RTHCPHYS if any address is acceptable.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param uAlignment The alignment of the reserved memory.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G.
315f68b04971772d94ba6c4408eaa19559a77cedvboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjAllocPhysEx(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest, size_t uAlignment);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Allocates non-contiguous page aligned physical memory without (necessarily) any kernel mapping.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * This API is for allocating huge amounts of pages and will return
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * manner.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * physical memory on this platform. The caller should expect
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * this error and have a fallback strategy for it.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cb Number of bytes to allocate. This is rounded up to nearest page.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param PhysHighest The highest permittable address (inclusive).
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Pass NIL_RTHCPHYS if any address is acceptable.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjAllocPhysNC(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/** Memory cache policy for RTR0MemObjEnterPhys.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @{
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/** Default caching policy -- don't care. */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync#define RTMEM_CACHE_POLICY_DONT_CARE UINT32_C(0)
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/** MMIO caching policy -- uncachable. */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync#define RTMEM_CACHE_POLICY_MMIO UINT32_C(1)
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/** @} */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Creates a page aligned, contiguous, physical memory object.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * No physical memory is allocated, we trust you do know what you're doing.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param Phys The physical address to start at. This is rounded down to the
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * nearest page boundrary.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cb The size of the object in bytes. This is rounded up to nearest page boundrary.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param CachePolicy One of the RTMEM_CACHE_XXX modes.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjEnterPhys(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb, unsigned CachePolicy);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Reserves kernel virtual address space.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * If this function fails with VERR_NOT_SUPPORTED, the idea is that you
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * you have a safe physical address range to make use of...
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cb The number of bytes to reserve. This is rounded up to nearest page.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param uAlignment The alignment of the reserved memory.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjReserveKernel(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Reserves user virtual address space in the current process.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param uAlignment The alignment of the reserved memory.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjReserveUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Maps a memory object into kernel virtual address space.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * to zero.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param MemObjToMap The object to be map.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param uAlignment The alignment of the reserved memory.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
b64efece437bfca8872b81be9d0568ba90389d91vboxsync * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
b64efece437bfca8872b81be9d0568ba90389d91vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjMapKernel(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, unsigned fProt);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
ab37cc785e1bcbaaad50b8fb791bfecba6f4b4d5vboxsync/**
3755e2bacafa2dd718108ad1a18661dcd9566bd8vboxsync * Maps a memory object into kernel virtual address space.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * The ability to map subsections of the object into kernel space is currently
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * not implemented on all platforms. All/Most of platforms supports mapping the
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * whole object into kernel space.
032703cba22135d6032705fc2d67dd1294a6491avboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a
3755e2bacafa2dd718108ad1a18661dcd9566bd8vboxsync * memory object on this platform. When you hit this, try implement it.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param MemObjToMap The object to be map.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @param uAlignment The alignment of the reserved memory.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
3755e2bacafa2dd718108ad1a18661dcd9566bd8vboxsync * @param offSub Where in the object to start mapping. If non-zero
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * the value must be page aligned and cbSub must be
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * non-zero as well.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cbSub The size of the part of the object to be mapped. If
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * zero the entire object is mapped. The value must be
032703cba22135d6032705fc2d67dd1294a6491avboxsync * page aligned.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjMapKernelEx(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment,
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync unsigned fProt, size_t offSub, size_t cbSub);
3755e2bacafa2dd718108ad1a18661dcd9566bd8vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Maps a memory object into user virtual address space in the current process.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
032703cba22135d6032705fc2d67dd1294a6491avboxsync * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param MemObjToMap The object to be map.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
3755e2bacafa2dd718108ad1a18661dcd9566bd8vboxsync * @param uAlignment The alignment of the reserved memory.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjMapUser(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/**
3755e2bacafa2dd718108ad1a18661dcd9566bd8vboxsync * Change the page level protection of one or more pages in a memory object.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @returns IPRT status code.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @retval VERR_NOT_SUPPORTED if the OS doesn't provide any way to manipulate
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * page level protection. The caller must handle this status code
032703cba22135d6032705fc2d67dd1294a6491avboxsync * gracefully. (Note that it may also occur if the implementation is
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * missing, in which case just go ahead and implement it.)
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync *
3755e2bacafa2dd718108ad1a18661dcd9566bd8vboxsync * @param hMemObj Memory object handle.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param offSub Offset into the memory object. Must be page aligned.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param cbSub Number of bytes to change the protection of. Must be
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * page aligned.
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync * @param fProt Combination of RTMEM_PROT_* flags.
032703cba22135d6032705fc2d67dd1294a6491avboxsync */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRTR0DECL(int) RTR0MemObjProtect(RTR0MEMOBJ hMemObj, size_t offSub, size_t cbSub, uint32_t fProt);
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
3755e2bacafa2dd718108ad1a18661dcd9566bd8vboxsync#endif /* IN_RING0 */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync/** @} */
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsyncRT_C_DECLS_END
032703cba22135d6032705fc2d67dd1294a6491avboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync#endif
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync
65c72795ab90d3daefa759b716fbb5c6352c7a56vboxsync