VirtualBox

source: vbox/trunk/include/iprt/memobj.h@ 19952

Last change on this file since 19952 was 15721, checked in by vboxsync, 16 years ago

typo

  • Property eol-style set to native
File size: 13.5 KB
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 */
51RTR0DECL(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 */
60RTR0DECL(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 */
74RTR0DECL(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 */
83RTR0DECL(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 */
95RTR0DECL(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 */
105RTR0DECL(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 */
117RTR0DECL(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 */
129RTR0DECL(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 */
141RTR0DECL(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 * @remarks RTR0MemGetAddressR3() and RTR0MemGetAddress() will return the rounded
153 * down address.
154 * @remarks Linux: This API requires that the memory begin locked is in a memory
155 * mapping that is not required in any forked off child process. This
156 * is not intented as permanent restriction, feel free to help out
157 * lifting it.
158 */
159RTR0DECL(int) RTR0MemObjLockUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process);
160
161/**
162 * Locks a range of kernel virtual memory.
163 *
164 * @returns IPRT status code.
165 * @param pMemObj Where to store the ring-0 memory object handle.
166 * @param pv Kernel virtual address. This is rounded down to a page boundrary.
167 * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary.
168 *
169 * @remark RTR0MemGetAddress() will return the rounded down address.
170 */
171RTR0DECL(int) RTR0MemObjLockKernel(PRTR0MEMOBJ pMemObj, void *pv, size_t cb);
172
173/**
174 * Allocates contiguous page aligned physical memory without (necessarily) any kernel mapping.
175 *
176 * @returns IPRT status code.
177 * @param pMemObj Where to store the ring-0 memory object handle.
178 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
179 * @param PhysHighest The highest permittable address (inclusive).
180 * Pass NIL_RTHCPHYS if any address is acceptable.
181 */
182RTR0DECL(int) RTR0MemObjAllocPhys(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest);
183
184/**
185 * Allocates non-contiguous page aligned physical memory without (necessarily) any kernel mapping.
186 *
187 * This API is for allocating huge amounts of pages and will return
188 * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory
189 * manner.
190 *
191 * @returns IPRT status code.
192 * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped
193 * physical memory on this platform. The caller should expect
194 * this error and have a fallback strategy for it.
195 *
196 * @param pMemObj Where to store the ring-0 memory object handle.
197 * @param cb Number of bytes to allocate. This is rounded up to nearest page.
198 * @param PhysHighest The highest permittable address (inclusive).
199 * Pass NIL_RTHCPHYS if any address is acceptable.
200 */
201RTR0DECL(int) RTR0MemObjAllocPhysNC(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest);
202
203/**
204 * Creates a page aligned, contiguous, physical memory object.
205 *
206 * No physical memory is allocated, we trust you do know what you're doing.
207 *
208 * @returns IPRT status code.
209 * @param pMemObj Where to store the ring-0 memory object handle.
210 * @param Phys The physical address to start at. This is rounded down to the
211 * nearest page boundrary.
212 * @param cb The size of the object in bytes. This is rounded up to nearest page boundrary.
213 */
214RTR0DECL(int) RTR0MemObjEnterPhys(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb);
215
216/**
217 * Reserves kernel virtual address space.
218 *
219 * If this function fails with VERR_NOT_SUPPORTED, the idea is that you
220 * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if
221 * you have a safe physical address range to make use of...
222 *
223 * @returns IPRT status code.
224 * @param pMemObj Where to store the ring-0 memory object handle.
225 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
226 * @param cb The number of bytes to reserve. This is rounded up to nearest page.
227 * @param uAlignment The alignment of the reserved memory.
228 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
229 */
230RTR0DECL(int) RTR0MemObjReserveKernel(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment);
231
232/**
233 * Reserves user virtual address space in the current process.
234 *
235 * @returns IPRT status code.
236 * @param pMemObj Where to store the ring-0 memory object handle.
237 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
238 * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
239 * @param uAlignment The alignment of the reserved memory.
240 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
241 * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one.
242 */
243RTR0DECL(int) RTR0MemObjReserveUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process);
244
245/**
246 * Maps a memory object into kernel virtual address space.
247 *
248 * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set
249 * to zero.
250 *
251 * @returns IPRT status code.
252 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
253 * @param MemObjToMap The object to be map.
254 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
255 * @param uAlignment The alignment of the reserved memory.
256 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
257 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
258 */
259RTR0DECL(int) RTR0MemObjMapKernel(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, unsigned fProt);
260
261/**
262 * Maps a memory object into kernel virtual address space.
263 *
264 * The ability to map subsections of the object into kernel space is currently
265 * not implemented on all platforms. All/Most of platforms supports mapping the
266 * whole object into kernel space.
267 *
268 * @returns IPRT status code.
269 * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a
270 * memory object on this platform. When you hit this, try implement it.
271 *
272 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
273 * @param MemObjToMap The object to be map.
274 * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
275 * @param uAlignment The alignment of the reserved memory.
276 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
277 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
278 * @param offSub Where in the object to start mapping. If non-zero
279 * the value must be page aligned and cbSub must be
280 * non-zero as well.
281 * @param cbSub The size of the part of the object to be mapped. If
282 * zero the entire object is mapped. The value must be
283 * page aligned.
284 */
285RTR0DECL(int) RTR0MemObjMapKernelEx(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment,
286 unsigned fProt, size_t offSub, size_t cbSub);
287
288/**
289 * Maps a memory object into user virtual address space in the current process.
290 *
291 * @returns IPRT status code.
292 * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
293 * @param MemObjToMap The object to be map.
294 * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
295 * @param uAlignment The alignment of the reserved memory.
296 * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
297 * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
298 * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
299 */
300RTR0DECL(int) RTR0MemObjMapUser(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process);
301
302#endif /* IN_RING0 */
303
304/** @} */
305
306__END_DECLS
307
308#endif
309
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette