root/trunk/include/iprt/memobj.h
| Revision 8245, 11.6 kB (checked in by vboxsync, 7 months ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /** @file |
| 2 | * IPRT - Memory Objects (Ring-0). |
| 3 | */ |
| 4 | |
| 5 | /* |
| 6 | * Copyright (C) 2006-2007 Sun Microsystems, Inc. |
| 7 | * |
| 8 | * This file is part of VirtualBox Open Source Edition (OSE), as |
| 9 | * available from http://www.virtualbox.org. This file is free software; |
| 10 | * you can redistribute it and/or modify it under the terms of the GNU |
| 11 | * General Public License (GPL) as published by the Free Software |
| 12 | * Foundation, in version 2 as it comes in the "COPYING" file of the |
| 13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the |
| 14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. |
| 15 | * |
| 16 | * The contents of this file may alternatively be used under the terms |
| 17 | * of the Common Development and Distribution License Version 1.0 |
| 18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the |
| 19 | * VirtualBox OSE distribution, in which case the provisions of the |
| 20 | * CDDL are applicable instead of those of the GPL. |
| 21 | * |
| 22 | * You may elect to license modified versions of this file under the |
| 23 | * terms and conditions of either the GPL or the CDDL or both. |
| 24 | * |
| 25 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa |
| 26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need |
| 27 | * additional information or have any questions. |
| 28 | */ |
| 29 | |
| 30 | #ifndef ___iprt_memobj_h |
| 31 | #define ___iprt_memobj_h |
| 32 | |
| 33 | #include <iprt/cdefs.h> |
| 34 | #include <iprt/types.h> |
| 35 | |
| 36 | __BEGIN_DECLS |
| 37 | |
| 38 | /** @defgroup grp_rt_memobj RTMemObj - Memory Object Manipulation (Ring-0) |
| 39 | * @ingroup grp_rt |
| 40 | * @{ |
| 41 | */ |
| 42 | |
| 43 | #ifdef IN_RING0 |
| 44 | |
| 45 | /** |
| 46 | * Checks if this is mapping or not. |
| 47 | * |
| 48 | * @returns true if it's a mapping, otherwise false. |
| 49 | * @param MemObj The ring-0 memory object handle. |
| 50 | */ |
| 51 | RTR0DECL(bool) RTR0MemObjIsMapping(RTR0MEMOBJ MemObj); |
| 52 | |
| 53 | /** |
| 54 | * Gets the address of a ring-0 memory object. |
| 55 | * |
| 56 | * @returns The address of the memory object. |
| 57 | * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping. |
| 58 | * @param MemObj The ring-0 memory object handle. |
| 59 | */ |
| 60 | RTR0DECL(void *) RTR0MemObjAddress(RTR0MEMOBJ MemObj); |
| 61 | |
| 62 | /** |
| 63 | * Gets the ring-3 address of a ring-0 memory object. |
| 64 | * |
| 65 | * This only applies to ring-0 memory object with ring-3 mappings of some kind, i.e. |
| 66 | * locked user memory, reserved user address space and user mappings. This API should |
| 67 | * not be used on any other objects. |
| 68 | * |
| 69 | * @returns The address of the memory object. |
| 70 | * @returns NIL_RTR3PTR if the handle is invalid or if it's not an object with a ring-3 mapping. |
| 71 | * Strict builds will assert in both cases. |
| 72 | * @param MemObj The ring-0 memory object handle. |
| 73 | */ |
| 74 | RTR0DECL(RTR3PTR) RTR0MemObjAddressR3(RTR0MEMOBJ MemObj); |
| 75 | |
| 76 | /** |
| 77 | * Gets the size of a ring-0 memory object. |
| 78 | * |
| 79 | * @returns The address of the memory object. |
| 80 | * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping. |
| 81 | * @param MemObj The ring-0 memory object handle. |
| 82 | */ |
| 83 | RTR0DECL(size_t) RTR0MemObjSize(RTR0MEMOBJ MemObj); |
| 84 | |
| 85 | /** |
| 86 | * Get the physical address of an page in the memory object. |
| 87 | * |
| 88 | * @returns The physical address. |
| 89 | * @returns NIL_RTHCPHYS if the object doesn't contain fixed physical pages. |
| 90 | * @returns NIL_RTHCPHYS if the iPage is out of range. |
| 91 | * @returns NIL_RTHCPHYS if the object handle isn't valid. |
| 92 | * @param MemObj The ring-0 memory object handle. |
| 93 | * @param iPage The page number within the object. |
| 94 | */ |
| 95 | RTR0DECL(RTHCPHYS) RTR0MemObjGetPagePhysAddr(RTR0MEMOBJ MemObj, size_t iPage); |
| 96 | |
| 97 | /** |
| 98 | * Frees a ring-0 memory object. |
| 99 | * |
| 100 | * @returns IPRT status code. |
| 101 | * @retval VERR_INVALID_HANDLE if |
| 102 | * @param MemObj The ring-0 memory object to be freed. NULL is accepted. |
| 103 | * @param fFreeMappings Whether or not to free mappings of the object. |
| 104 | */ |
| 105 | RTR0DECL(int) RTR0MemObjFree(RTR0MEMOBJ MemObj, bool fFreeMappings); |
| 106 | |
| 107 | /** |
| 108 | * Allocates page aligned virtual kernel memory. |
| 109 | * |
| 110 | * The memory is taken from a non paged (= fixed physical memory backing) pool. |
| 111 | * |
| 112 | * @returns IPRT status code. |
| 113 | * @param pMemObj Where to store the ring-0 memory object handle. |
| 114 | * @param cb Number of bytes to allocate. This is rounded up to nearest page. |
| 115 | * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. |
| 116 | */ |
| 117 | RTR0DECL(int) RTR0MemObjAllocPage(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable); |
| 118 | |
| 119 | /** |
| 120 | * Allocates page aligned virtual kernel memory with physical backing below 4GB. |
| 121 | * |
| 122 | * The physical memory backing the allocation is fixed. |
| 123 | * |
| 124 | * @returns IPRT status code. |
| 125 | * @param pMemObj Where to store the ring-0 memory object handle. |
| 126 | * @param cb Number of bytes to allocate. This is rounded up to nearest page. |
| 127 | * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. |
| 128 | */ |
| 129 | RTR0DECL(int) RTR0MemObjAllocLow(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable); |
| 130 | |
| 131 | /** |
| 132 | * Allocates page aligned virtual kernel memory with contiguous physical backing below 4GB. |
| 133 | * |
| 134 | * The physical memory backing the allocation is fixed. |
| 135 | * |
| 136 | * @returns IPRT status code. |
| 137 | * @param pMemObj Where to store the ring-0 memory object handle. |
| 138 | * @param cb Number of bytes to allocate. This is rounded up to nearest page. |
| 139 | * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object. |
| 140 | */ |
| 141 | RTR0DECL(int) RTR0MemObjAllocCont(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable); |
| 142 | |
| 143 | /** |
| 144 | * Locks a range of user virtual memory. |
| 145 | * |
| 146 | * @returns IPRT status code. |
| 147 | * @param pMemObj Where to store the ring-0 memory object handle. |
| 148 | * @param R3Ptr User virtual address. This is rounded down to a page boundrary. |
| 149 | * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary. |
| 150 | * @param R0Process The process to lock pages in. NIL_R0PROCESS is an alias for the current one. |
| 151 | * |
| 152 | * @remark RTR0MemGetAddressR3() and RTR0MemGetAddress() will return the rounded down address. |
| 153 | */ |
| 154 | RTR0DECL(int) RTR0MemObjLockUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process); |
| 155 | |
| 156 | /** |
| 157 | * Locks a range of kernel virtual memory. |
| 158 | * |
| 159 | * @returns IPRT status code. |
| 160 | * @param pMemObj Where to store the ring-0 memory object handle. |
| 161 | * @param pv Kernel virtual address. This is rounded down to a page boundrary. |
| 162 | * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary. |
| 163 | * |
| 164 | * @remark RTR0MemGetAddress() will return the rounded down address. |
| 165 | */ |
| 166 | RTR0DECL(int) RTR0MemObjLockKernel(PRTR0MEMOBJ pMemObj, void *pv, size_t cb); |
| 167 | |
| 168 | /** |
| 169 | * Allocates contiguous page aligned physical memory without (necessarily) any kernel mapping. |
| 170 | * |
| 171 | * @returns IPRT status code. |
| 172 | * @param pMemObj Where to store the ring-0 memory object handle. |
| 173 | * @param cb Number of bytes to allocate. This is rounded up to nearest page. |
| 174 | * @param PhysHighest The highest permittable address (inclusive). |
| 175 | * Pass NIL_RTHCPHYS if any address is acceptable. |
| 176 | */ |
| 177 | RTR0DECL(int) RTR0MemObjAllocPhys(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest); |
| 178 | |
| 179 | /** |
| 180 | * Allocates non-contiguous page aligned physical memory without (necessarily) any kernel mapping. |
| 181 | * |
| 182 | * This API is for allocating huge amounts of pages and will return |
| 183 | * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory |
| 184 | * manner. |
| 185 | * |
| 186 | * @returns IPRT status code. |
| 187 | * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped |
| 188 | * physical memory on this platform. The caller should expect |
| 189 | * this error and have a fallback strategy for it. |
| 190 | * @param pMemObj Where to store the ring-0 memory object handle. |
| 191 | * @param cb Number of bytes to allocate. This is rounded up to nearest page. |
| 192 | * @param PhysHighest The highest permittable address (inclusive). |
| 193 | * Pass NIL_RTHCPHYS if any address is acceptable. |
| 194 | */ |
| 195 | RTR0DECL(int) RTR0MemObjAllocPhysNC(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest); |
| 196 | |
| 197 | /** |
| 198 | * Creates a page aligned, contiguous, physical memory object. |
| 199 | * |
| 200 | * No physical memory is allocated, we trust you do know what you're doing. |
| 201 | * |
| 202 | * @returns IPRT status code. |
| 203 | * @param pMemObj Where to store the ring-0 memory object handle. |
| 204 | * @param Phys The physical address to start at. This is rounded down to the |
| 205 | * nearest page boundrary. |
| 206 | * @param cb The size of the object in bytes. This is rounded up to nearest page boundrary. |
| 207 | */ |
| 208 | RTR0DECL(int) RTR0MemObjEnterPhys(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb); |
| 209 | |
| 210 | /** |
| 211 | * Reserves kernel virtual address space. |
| 212 | * |
| 213 | * If this function fails with VERR_NOT_SUPPORTED, the idea is that you |
| 214 | * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if |
| 215 | * you have a safe physical address range to make use of... |
| 216 | * |
| 217 | * @returns IPRT status code. |
| 218 | * @param pMemObj Where to store the ring-0 memory object handle. |
| 219 | * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. |
| 220 | * @param cb The number of bytes to reserve. This is rounded up to nearest page. |
| 221 | * @param uAlignment The alignment of the reserved memory. |
| 222 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. |
| 223 | */ |
| 224 | RTR0DECL(int) RTR0MemObjReserveKernel(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment); |
| 225 | |
| 226 | /** |
| 227 | * Reserves user virtual address space in the current process. |
| 228 | * |
| 229 | * @returns IPRT status code. |
| 230 | * @param pMemObj Where to store the ring-0 memory object handle. |
| 231 | * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment. |
| 232 | * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE. |
| 233 | * @param uAlignment The alignment of the reserved memory. |
| 234 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. |
| 235 | * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one. |
| 236 | */ |
| 237 | RTR0DECL(int) RTR0MemObjReserveUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process); |
| 238 | |
| 239 | /** |
| 240 | * Maps a memory object into kernel virtual address space. |
| 241 | * |
| 242 | * @returns IPRT status code. |
| 243 | * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. |
| 244 | * @param MemObjToMap The object to be map. |
| 245 | * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment. |
| 246 | * @param uAlignment The alignment of the reserved memory. |
| 247 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. |
| 248 | * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). |
| 249 | */ |
| 250 | RTR0DECL(int) RTR0MemObjMapKernel(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, unsigned fProt); |
| 251 | |
| 252 | /** |
| 253 | * Maps a memory object into user virtual address space in the current process. |
| 254 | * |
| 255 | * @returns IPRT status code. |
| 256 | * @param pMemObj Where to store the ring-0 memory object handle of the mapping object. |
| 257 | * @param MemObjToMap The object to be map. |
| 258 | * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment. |
| 259 | * @param uAlignment The alignment of the reserved memory. |
| 260 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M. |
| 261 | * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE). |
| 262 | * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one. |
| 263 | */ |
| 264 | RTR0DECL(int) RTR0MemObjMapUser(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process); |
| 265 | |
| 266 | #endif /* IN_RING0 */ |
| 267 | |
| 268 | /** @} */ |
| 269 | |
| 270 | __END_DECLS |
| 271 | |
| 272 | #endif |
| 273 |
Note: See TracBrowser for help on using the browser.

