memobj.h revision 2601f76f6fc7465f38061e4b406235a8398c3ef8
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync * IPRT - Memory Objects (Ring-0).
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * available from http://www.virtualbox.org. This file is free software;
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * you can redistribute it and/or modify it under the terms of the GNU
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * General Public License (GPL) as published by the Free Software
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * The contents of this file may alternatively be used under the terms
8f22303f06a6aeb6f4e186f9db1492ec13d9fcecvboxsync * of the Common Development and Distribution License Version 1.0
8f22303f06a6aeb6f4e186f9db1492ec13d9fcecvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
8f22303f06a6aeb6f4e186f9db1492ec13d9fcecvboxsync * VirtualBox OSE distribution, in which case the provisions of the
8f22303f06a6aeb6f4e186f9db1492ec13d9fcecvboxsync * CDDL are applicable instead of those of the GPL.
8f22303f06a6aeb6f4e186f9db1492ec13d9fcecvboxsync * You may elect to license modified versions of this file under the
8f22303f06a6aeb6f4e186f9db1492ec13d9fcecvboxsync * terms and conditions of either the GPL or the CDDL or both.
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * additional information or have any questions.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync/** @defgroup grp_rt_memobj RTMemObj - Memory Object Manipulation (Ring-0)
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @ingroup grp_rt
1003ebeb480229ce94b8f381fbd03412f844b193vboxsync * Checks if this is mapping or not.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns true if it's a mapping, otherwise false.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param MemObj The ring-0 memory object handle.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsyncRTR0DECL(bool) RTR0MemObjIsMapping(RTR0MEMOBJ MemObj);
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Gets the address of a ring-0 memory object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns The address of the memory object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param MemObj The ring-0 memory object handle.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsyncRTR0DECL(void *) RTR0MemObjAddress(RTR0MEMOBJ MemObj);
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Gets the ring-3 address of a ring-0 memory object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * This only applies to ring-0 memory object with ring-3 mappings of some kind, i.e.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * locked user memory, reserved user address space and user mappings. This API should
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * not be used on any other objects.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns The address of the memory object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns NIL_RTR3PTR if the handle is invalid or if it's not an object with a ring-3 mapping.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Strict builds will assert in both cases.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param MemObj The ring-0 memory object handle.
1003ebeb480229ce94b8f381fbd03412f844b193vboxsyncRTR0DECL(RTR3PTR) RTR0MemObjAddressR3(RTR0MEMOBJ MemObj);
1003ebeb480229ce94b8f381fbd03412f844b193vboxsync * Gets the size of a ring-0 memory object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns The address of the memory object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param MemObj The ring-0 memory object handle.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Get the physical address of an page in the memory object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns The physical address.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns NIL_RTHCPHYS if the object doesn't contain fixed physical pages.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns NIL_RTHCPHYS if the iPage is out of range.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns NIL_RTHCPHYS if the object handle isn't valid.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param MemObj The ring-0 memory object handle.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param iPage The page number within the object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsyncRTR0DECL(RTHCPHYS) RTR0MemObjGetPagePhysAddr(RTR0MEMOBJ MemObj, size_t iPage);
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Frees a ring-0 memory object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns IPRT status code.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @retval VERR_INVALID_HANDLE if
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param MemObj The ring-0 memory object to be freed. NULL is accepted.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param fFreeMappings Whether or not to free mappings of the object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsyncRTR0DECL(int) RTR0MemObjFree(RTR0MEMOBJ MemObj, bool fFreeMappings);
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Allocates page aligned virtual kernel memory.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * The memory is taken from a non paged (= fixed physical memory backing) pool.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns IPRT status code.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param cb Number of bytes to allocate. This is rounded up to nearest page.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsyncRTR0DECL(int) RTR0MemObjAllocPage(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Allocates page aligned virtual kernel memory with physical backing below 4GB.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * The physical memory backing the allocation is fixed.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns IPRT status code.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param cb Number of bytes to allocate. This is rounded up to nearest page.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsyncRTR0DECL(int) RTR0MemObjAllocLow(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Allocates page aligned virtual kernel memory with contiguous physical backing below 4GB.
1003ebeb480229ce94b8f381fbd03412f844b193vboxsync * The physical memory backing the allocation is fixed.
1003ebeb480229ce94b8f381fbd03412f844b193vboxsync * @returns IPRT status code.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param cb Number of bytes to allocate. This is rounded up to nearest page.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsyncRTR0DECL(int) RTR0MemObjAllocCont(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync * Locks a range of user virtual memory.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns IPRT status code.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param pMemObj Where to store the ring-0 memory object handle.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param R3Ptr User virtual address. This is rounded down to a page boundrary.
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param R0Process The process to lock pages in. NIL_R0PROCESS is an alias for the current one.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return the rounded
5856c5b39318bc766ccd6f823f1349c80a3dcfaavboxsync * down address.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @remarks Linux: This API requires that the memory begin locked is in a memory
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * mapping that is not required in any forked off child process. This
5eda82e218d35ae0691febd531e1bfc0324cc4a6vboxsync * is not intented as permanent restriction, feel free to help out
RTR0DECL(int) RTR0MemObjLockUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process);
RTR0DECL(int) RTR0MemObjReserveKernel(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment);
* @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
* @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one.
RTR0DECL(int) RTR0MemObjReserveUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process);
RTR0DECL(int) RTR0MemObjMapKernel(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, unsigned fProt);
RTR0DECL(int) RTR0MemObjMapKernelEx(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment,
* @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
* @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
RTR0DECL(int) RTR0MemObjMapUser(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process);