memobj.h revision 9d577a7b721cf6430727d2bc2577642310642366
2N/A * IPRT - Memory Objects (Ring-0). 2N/A * Copyright (C) 2006-2010 Oracle Corporation 2N/A * This file is part of VirtualBox Open Source Edition (OSE), as 2N/A * you can redistribute it and/or modify it under the terms of the GNU 2N/A * General Public License (GPL) as published by the Free Software 2N/A * Foundation, in version 2 as it comes in the "COPYING" file of the 2N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the 2N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 2N/A * The contents of this file may alternatively be used under the terms 2N/A * of the Common Development and Distribution License Version 1.0 2N/A * (CDDL) only, as it comes in the "COPYING.CDDL" file of the 2N/A * VirtualBox OSE distribution, in which case the provisions of the 2N/A * CDDL are applicable instead of those of the GPL. 2N/A * You may elect to license modified versions of this file under the 2N/A * terms and conditions of either the GPL or the CDDL or both. 2N/A/** @defgroup grp_rt_memobj RTMemObj - Memory Object Manipulation (Ring-0) 2N/A * The default allocation tag used by the RTMem allocation APIs. 2N/A * will default to the pointer to the current file name. The memory API will 2N/A * make of use of this as pointer to a volatile but read-only string. 2N/A * Checks if this is mapping or not. 2N/A * @returns true if it's a mapping, otherwise false. 2N/A * @param MemObj The ring-0 memory object handle. 2N/A * Gets the address of a ring-0 memory object. 2N/A * @returns The address of the memory object. 2N/A * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping. 2N/A * @param MemObj The ring-0 memory object handle. 2N/A * Gets the ring-3 address of a ring-0 memory object. 2N/A * This only applies to ring-0 memory object with ring-3 mappings of some kind, i.e. 2N/A * locked user memory, reserved user address space and user mappings. This API should 2N/A * not be used on any other objects. 2N/A * @returns The address of the memory object. 2N/A * @returns NIL_RTR3PTR if the handle is invalid or if it's not an object with a ring-3 mapping. 2N/A * Strict builds will assert in both cases. 2N/A * @param MemObj The ring-0 memory object handle. 2N/A * Gets the size of a ring-0 memory object. 2N/A * @returns The address of the memory object. 2N/A * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping. 2N/A * @param MemObj The ring-0 memory object handle. 2N/A * Get the physical address of an page in the memory object. 2N/A * @returns The physical address. 2N/A * @returns NIL_RTHCPHYS if the object doesn't contain fixed physical pages. 2N/A * @returns NIL_RTHCPHYS if the iPage is out of range. 2N/A * @returns NIL_RTHCPHYS if the object handle isn't valid. 2N/A * @param MemObj The ring-0 memory object handle. 2N/A * @param iPage The page number within the object. 2N/A * Frees a ring-0 memory object. 2N/A * @returns IPRT status code. 2N/A * @retval VERR_INVALID_HANDLE if 2N/A * @param MemObj The ring-0 memory object to be freed. NULL is accepted. 2N/A * @param fFreeMappings Whether or not to free mappings of the object. * Allocates page aligned virtual kernel memory (default tag). * The memory is taken from a non paged (= fixed physical memory backing) pool. * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. * Allocates page aligned virtual kernel memory (custom tag). * The memory is taken from a non paged (= fixed physical memory backing) pool. * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. * @param pszTag Allocation tag used for statistics and such. * Allocates page aligned virtual kernel memory with physical backing below 4GB * The physical memory backing the allocation is fixed. * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. * Allocates page aligned virtual kernel memory with physical backing below 4GB * The physical memory backing the allocation is fixed. * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. * @param pszTag Allocation tag used for statistics and such. * Allocates page aligned virtual kernel memory with contiguous physical backing * below 4GB (default tag). * The physical memory backing the allocation is fixed. * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. * Allocates page aligned virtual kernel memory with contiguous physical backing * below 4GB (custom tag). * The physical memory backing the allocation is fixed. * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. * @param pszTag Allocation tag used for statistics and such. * Locks a range of user virtual memory (default tag). * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param R3Ptr User virtual address. This is rounded down to a page * @param cb Number of bytes to lock. This is rounded up to * nearest page boundrary. * @param fAccess The desired access, a combination of RTMEM_PROT_READ * @param R0Process The process to lock pages in. NIL_R0PROCESS is an * alias for the current one. * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded * @remarks Linux: This API requires that the memory begin locked is in a memory * mapping that is not required in any forked off child process. This * is not intented as permanent restriction, feel free to help out * Locks a range of user virtual memory (custom tag). * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param R3Ptr User virtual address. This is rounded down to a page * @param cb Number of bytes to lock. This is rounded up to * nearest page boundrary. * @param fAccess The desired access, a combination of RTMEM_PROT_READ * @param R0Process The process to lock pages in. NIL_R0PROCESS is an * alias for the current one. * @param pszTag Allocation tag used for statistics and such. * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return therounded * @remarks Linux: This API requires that the memory begin locked is in a memory * mapping that is not required in any forked off child process. This * is not intented as permanent restriction, feel free to help out * Locks a range of kernel virtual memory (default tag). * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param pv Kernel virtual address. This is rounded down to a page boundrary. * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary. * @param fAccess The desired access, a combination of RTMEM_PROT_READ * @remark RTR0MemGetAddress() will return the rounded down address. * Locks a range of kernel virtual memory (custom tag). * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param pv Kernel virtual address. This is rounded down to a page boundrary. * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary. * @param fAccess The desired access, a combination of RTMEM_PROT_READ * @param pszTag Allocation tag used for statistics and such. * @remark RTR0MemGetAddress() will return the rounded down address. * Allocates contiguous page aligned physical memory without (necessarily) any * kernel mapping (default tag). * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param PhysHighest The highest permittable address (inclusive). * Pass NIL_RTHCPHYS if any address is acceptable. * Allocates contiguous page aligned physical memory without (necessarily) any * kernel mapping (custom tag). * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param PhysHighest The highest permittable address (inclusive). * Pass NIL_RTHCPHYS if any address is acceptable. * @param pszTag Allocation tag used for statistics and such. * Allocates contiguous physical memory without (necessarily) any kernel mapping * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param PhysHighest The highest permittable address (inclusive). * Pass NIL_RTHCPHYS if any address is acceptable. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G. * Allocates contiguous physical memory without (necessarily) any kernel mapping * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param PhysHighest The highest permittable address (inclusive). * Pass NIL_RTHCPHYS if any address is acceptable. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M, _4M and _1G. * @param pszTag Allocation tag used for statistics and such. * Allocates non-contiguous page aligned physical memory without (necessarily) * any kernel mapping (default tag). * This API is for allocating huge amounts of pages and will return * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory * @returns IPRT status code. * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped * physical memory on this platform. The caller should expect * this error and have a fallback strategy for it. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param PhysHighest The highest permittable address (inclusive). * Pass NIL_RTHCPHYS if any address is acceptable. * Allocates non-contiguous page aligned physical memory without (necessarily) * any kernel mapping (custom tag). * This API is for allocating huge amounts of pages and will return * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory * @returns IPRT status code. * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped * physical memory on this platform. The caller should expect * this error and have a fallback strategy for it. * @param pMemObj Where to store the ring-0 memory object handle. * @param cb Number of bytes to allocate. This is rounded up to nearest page. * @param PhysHighest The highest permittable address (inclusive). * Pass NIL_RTHCPHYS if any address is acceptable. * @param pszTag Allocation tag used for statistics and such. /** Memory cache policy for RTR0MemObjEnterPhys. /** Default caching policy -- don't care. */ /** MMIO caching policy -- uncachable. */ * Creates a page aligned, contiguous, physical memory object (default tag). * No physical memory is allocated, we trust you do know what you're doing. * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param Phys The physical address to start at. This is rounded down to the * nearest page boundrary. * @param cb The size of the object in bytes. This is rounded up to nearest page boundrary. * @param uCachePolicy One of the RTMEM_CACHE_XXX modes. * Creates a page aligned, contiguous, physical memory object (custom tag). * No physical memory is allocated, we trust you do know what you're doing. * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param Phys The physical address to start at. This is rounded down to the * nearest page boundrary. * @param cb The size of the object in bytes. This is rounded up to nearest page boundrary. * @param uCachePolicy One of the RTMEM_CACHE_XXX modes. * @param pszTag Allocation tag used for statistics and such. * Reserves kernel virtual address space (default tag). * If this function fails with VERR_NOT_SUPPORTED, the idea is that you * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if * you have a safe physical address range to make use of... * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. * @param cb The number of bytes to reserve. This is rounded up to nearest page. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. * Reserves kernel virtual address space (custom tag). * If this function fails with VERR_NOT_SUPPORTED, the idea is that you * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if * you have a safe physical address range to make use of... * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. * @param cb The number of bytes to reserve. This is rounded up to nearest page. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. * @param pszTag Allocation tag used for statistics and such. * Reserves user virtual address space in the current process (default tag). * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment. * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one. * Reserves user virtual address space in the current process (custom tag). * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle. * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment. * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one. * @param pszTag Allocation tag used for statistics and such. * Maps a memory object into kernel virtual address space (default tag). * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. * @param MemObjToMap The object to be map. * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). * Maps a memory object into kernel virtual address space (custom tag). * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. * @param MemObjToMap The object to be map. * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). * @param pszTag Allocation tag used for statistics and such. * Maps a memory object into kernel virtual address space (default tag). * The ability to map subsections of the object into kernel space is currently * not implemented on all platforms. All/Most of platforms supports mapping the * whole object into kernel space. * @returns IPRT status code. * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a * memory object on this platform. When you hit this, try implement it. * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. * @param MemObjToMap The object to be map. * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). * @param offSub Where in the object to start mapping. If non-zero * the value must be page aligned and cbSub must be * @param cbSub The size of the part of the object to be mapped. If * zero the entire object is mapped. The value must be * Maps a memory object into kernel virtual address space (custom tag). * The ability to map subsections of the object into kernel space is currently * not implemented on all platforms. All/Most of platforms supports mapping the * whole object into kernel space. * @returns IPRT status code. * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a * memory object on this platform. When you hit this, try implement it. * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. * @param MemObjToMap The object to be map. * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). * @param offSub Where in the object to start mapping. If non-zero * the value must be page aligned and cbSub must be * @param cbSub The size of the part of the object to be mapped. If * zero the entire object is mapped. The value must be * @param pszTag Allocation tag used for statistics and such. * Maps a memory object into user virtual address space in the current process * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. * @param MemObjToMap The object to be map. * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one. * Maps a memory object into user virtual address space in the current process * @returns IPRT status code. * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. * @param MemObjToMap The object to be map. * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment. * @param uAlignment The alignment of the reserved memory. * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one. * @param pszTag Allocation tag used for statistics and such. * Change the page level protection of one or more pages in a memory object. * @returns IPRT status code. * @retval VERR_NOT_SUPPORTED if the OS doesn't provide any way to manipulate * page level protection. The caller must handle this status code * gracefully. (Note that it may also occur if the implementation is * missing, in which case just go ahead and implement it.) * @param hMemObj Memory object handle. * @param offSub Offset into the memory object. Must be page aligned. * @param cbSub Number of bytes to change the protection of. Must be * @param fProt Combination of RTMEM_PROT_* flags.