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 | *
|
---|
191 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
192 | * @param cb Number of bytes to allocate. This is rounded up to nearest page.
|
---|
193 | * @param PhysHighest The highest permittable address (inclusive).
|
---|
194 | * Pass NIL_RTHCPHYS if any address is acceptable.
|
---|
195 | */
|
---|
196 | RTR0DECL(int) RTR0MemObjAllocPhysNC(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest);
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Creates a page aligned, contiguous, physical memory object.
|
---|
200 | *
|
---|
201 | * No physical memory is allocated, we trust you do know what you're doing.
|
---|
202 | *
|
---|
203 | * @returns IPRT status code.
|
---|
204 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
205 | * @param Phys The physical address to start at. This is rounded down to the
|
---|
206 | * nearest page boundrary.
|
---|
207 | * @param cb The size of the object in bytes. This is rounded up to nearest page boundrary.
|
---|
208 | */
|
---|
209 | RTR0DECL(int) RTR0MemObjEnterPhys(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb);
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Reserves kernel virtual address space.
|
---|
213 | *
|
---|
214 | * If this function fails with VERR_NOT_SUPPORTED, the idea is that you
|
---|
215 | * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if
|
---|
216 | * you have a safe physical address range to make use of...
|
---|
217 | *
|
---|
218 | * @returns IPRT status code.
|
---|
219 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
220 | * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
|
---|
221 | * @param cb The number of bytes to reserve. This is rounded up to nearest page.
|
---|
222 | * @param uAlignment The alignment of the reserved memory.
|
---|
223 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
|
---|
224 | */
|
---|
225 | RTR0DECL(int) RTR0MemObjReserveKernel(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment);
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Reserves user virtual address space in the current process.
|
---|
229 | *
|
---|
230 | * @returns IPRT status code.
|
---|
231 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
232 | * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
|
---|
233 | * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
|
---|
234 | * @param uAlignment The alignment of the reserved memory.
|
---|
235 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
|
---|
236 | * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one.
|
---|
237 | */
|
---|
238 | RTR0DECL(int) RTR0MemObjReserveUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process);
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * Maps a memory object into kernel virtual address space.
|
---|
242 | *
|
---|
243 | * This is the same as calling RTR0MemObjMapKernelEx with cbSub and offSub set
|
---|
244 | * to zero.
|
---|
245 | *
|
---|
246 | * @returns IPRT status code.
|
---|
247 | * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
|
---|
248 | * @param MemObjToMap The object to be map.
|
---|
249 | * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
|
---|
250 | * @param uAlignment The alignment of the reserved memory.
|
---|
251 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
|
---|
252 | * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
|
---|
253 | */
|
---|
254 | RTR0DECL(int) RTR0MemObjMapKernel(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, unsigned fProt);
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * Maps a memory object into kernel virtual address space.
|
---|
258 | *
|
---|
259 | * The ability to map subsections of the object into kernel space is currently
|
---|
260 | * not implemented on all platforms. All/Most of platforms supports mapping the
|
---|
261 | * whole object into kernel space.
|
---|
262 | *
|
---|
263 | * @returns IPRT status code.
|
---|
264 | * @retval VERR_NOT_SUPPORTED if it's not possible to map a subsection of a
|
---|
265 | * memory object on this platform. When you hit this, try implement it.
|
---|
266 | *
|
---|
267 | * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
|
---|
268 | * @param MemObjToMap The object to be map.
|
---|
269 | * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
|
---|
270 | * @param uAlignment The alignment of the reserved memory.
|
---|
271 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
|
---|
272 | * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
|
---|
273 | * @param offSub Where in the object to start mapping. If non-zero
|
---|
274 | * the value must be page aligned and cbSub must be
|
---|
275 | * non-zero as well.
|
---|
276 | * @param cbSub The size of the part of the object to be mapped. If
|
---|
277 | * zero the entire object is mapped. The value must be
|
---|
278 | * page aligned.
|
---|
279 | */
|
---|
280 | RTR0DECL(int) RTR0MemObjMapKernelEx(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment,
|
---|
281 | unsigned fProt, size_t offSub, size_t cbSub);
|
---|
282 |
|
---|
283 | /**
|
---|
284 | * Maps a memory object into user virtual address space in the current process.
|
---|
285 | *
|
---|
286 | * @returns IPRT status code.
|
---|
287 | * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
|
---|
288 | * @param MemObjToMap The object to be map.
|
---|
289 | * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
|
---|
290 | * @param uAlignment The alignment of the reserved memory.
|
---|
291 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
|
---|
292 | * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
|
---|
293 | * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
|
---|
294 | */
|
---|
295 | RTR0DECL(int) RTR0MemObjMapUser(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process);
|
---|
296 |
|
---|
297 | #endif /* IN_RING0 */
|
---|
298 |
|
---|
299 | /** @} */
|
---|
300 |
|
---|
301 | __END_DECLS
|
---|
302 |
|
---|
303 | #endif
|
---|
304 |
|
---|