1 | /** @file
|
---|
2 | * innotek Portable Runtime - Memory Objects (Ring-0).
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 |
|
---|
26 | #ifndef ___iprt_memobj_h
|
---|
27 | #define ___iprt_memobj_h
|
---|
28 |
|
---|
29 | #include <iprt/cdefs.h>
|
---|
30 | #include <iprt/types.h>
|
---|
31 |
|
---|
32 | __BEGIN_DECLS
|
---|
33 |
|
---|
34 | /** @defgroup grp_rt_memobj RTMemObj - Memory Object Manipulation (Ring-0)
|
---|
35 | * @ingroup grp_rt
|
---|
36 | * @{
|
---|
37 | */
|
---|
38 |
|
---|
39 | #ifdef IN_RING0
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Checks if this is mapping or not.
|
---|
43 | *
|
---|
44 | * @returns true if it's a mapping, otherwise false.
|
---|
45 | * @param MemObj The ring-0 memory object handle.
|
---|
46 | */
|
---|
47 | RTR0DECL(bool) RTR0MemObjIsMapping(RTR0MEMOBJ MemObj);
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Gets the address of a ring-0 memory object.
|
---|
51 | *
|
---|
52 | * @returns The address of the memory object.
|
---|
53 | * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping.
|
---|
54 | * @param MemObj The ring-0 memory object handle.
|
---|
55 | */
|
---|
56 | RTR0DECL(void *) RTR0MemObjAddress(RTR0MEMOBJ MemObj);
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Gets the ring-3 address of a ring-0 memory object.
|
---|
60 | *
|
---|
61 | * This only applies to ring-0 memory object with ring-3 mappings of some kind, i.e.
|
---|
62 | * locked user memory, reserved user address space and user mappings. This API should
|
---|
63 | * not be used on any other objects.
|
---|
64 | *
|
---|
65 | * @returns The address of the memory object.
|
---|
66 | * @returns NIL_RTR3PTR if the handle is invalid or if it's not an object with a ring-3 mapping.
|
---|
67 | * Strict builds will assert in both cases.
|
---|
68 | * @param MemObj The ring-0 memory object handle.
|
---|
69 | */
|
---|
70 | RTR0DECL(RTR3PTR) RTR0MemObjAddressR3(RTR0MEMOBJ MemObj);
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Gets the size of a ring-0 memory object.
|
---|
74 | *
|
---|
75 | * @returns The address of the memory object.
|
---|
76 | * @returns NULL if the handle is invalid (asserts in strict builds) or if there isn't any mapping.
|
---|
77 | * @param MemObj The ring-0 memory object handle.
|
---|
78 | */
|
---|
79 | RTR0DECL(size_t) RTR0MemObjSize(RTR0MEMOBJ MemObj);
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * Get the physical address of an page in the memory object.
|
---|
83 | *
|
---|
84 | * @returns The physical address.
|
---|
85 | * @returns NIL_RTHCPHYS if the object doesn't contain fixed physical pages.
|
---|
86 | * @returns NIL_RTHCPHYS if the iPage is out of range.
|
---|
87 | * @returns NIL_RTHCPHYS if the object handle isn't valid.
|
---|
88 | * @param MemObj The ring-0 memory object handle.
|
---|
89 | * @param iPage The page number within the object.
|
---|
90 | */
|
---|
91 | RTR0DECL(RTHCPHYS) RTR0MemObjGetPagePhysAddr(RTR0MEMOBJ MemObj, size_t iPage);
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Frees a ring-0 memory object.
|
---|
95 | *
|
---|
96 | * @returns IPRT status code.
|
---|
97 | * @retval VERR_INVALID_HANDLE if
|
---|
98 | * @param MemObj The ring-0 memory object to be freed. NULL is accepted.
|
---|
99 | * @param fFreeMappings Whether or not to free mappings of the object.
|
---|
100 | */
|
---|
101 | RTR0DECL(int) RTR0MemObjFree(RTR0MEMOBJ MemObj, bool fFreeMappings);
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Allocates page aligned virtual kernel memory.
|
---|
105 | *
|
---|
106 | * The memory is taken from a non paged (= fixed physical memory backing) pool.
|
---|
107 | *
|
---|
108 | * @returns IPRT status code.
|
---|
109 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
110 | * @param cb Number of bytes to allocate. This is rounded up to nearest page.
|
---|
111 | * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
|
---|
112 | */
|
---|
113 | RTR0DECL(int) RTR0MemObjAllocPage(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Allocates page aligned virtual kernel memory with physical backing below 4GB.
|
---|
117 | *
|
---|
118 | * The physical memory backing the allocation is fixed.
|
---|
119 | *
|
---|
120 | * @returns IPRT status code.
|
---|
121 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
122 | * @param cb Number of bytes to allocate. This is rounded up to nearest page.
|
---|
123 | * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
|
---|
124 | */
|
---|
125 | RTR0DECL(int) RTR0MemObjAllocLow(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Allocates page aligned virtual kernel memory with contiguous physical backing below 4GB.
|
---|
129 | *
|
---|
130 | * The physical memory backing the allocation is fixed.
|
---|
131 | *
|
---|
132 | * @returns IPRT status code.
|
---|
133 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
134 | * @param cb Number of bytes to allocate. This is rounded up to nearest page.
|
---|
135 | * @param fExecutable Flag indicating whether it should be permitted to executed code in the memory object.
|
---|
136 | */
|
---|
137 | RTR0DECL(int) RTR0MemObjAllocCont(PRTR0MEMOBJ pMemObj, size_t cb, bool fExecutable);
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Locks a range of user virtual memory.
|
---|
141 | *
|
---|
142 | * @returns IPRT status code.
|
---|
143 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
144 | * @param R3Ptr User virtual address. This is rounded down to a page boundrary.
|
---|
145 | * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary.
|
---|
146 | * @param R0Process The process to lock pages in. NIL_R0PROCESS is an alias for the current one.
|
---|
147 | *
|
---|
148 | * @remark RTR0MemGetAddressR3() and RTR0MemGetAddress() will return the rounded down address.
|
---|
149 | */
|
---|
150 | RTR0DECL(int) RTR0MemObjLockUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3Ptr, size_t cb, RTR0PROCESS R0Process);
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Locks a range of kernel virtual memory.
|
---|
154 | *
|
---|
155 | * @returns IPRT status code.
|
---|
156 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
157 | * @param pv Kernel virtual address. This is rounded down to a page boundrary.
|
---|
158 | * @param cb Number of bytes to lock. This is rounded up to nearest page boundrary.
|
---|
159 | *
|
---|
160 | * @remark RTR0MemGetAddress() will return the rounded down address.
|
---|
161 | */
|
---|
162 | RTR0DECL(int) RTR0MemObjLockKernel(PRTR0MEMOBJ pMemObj, void *pv, size_t cb);
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Allocates contiguous page aligned physical memory without (necessarily) any kernel mapping.
|
---|
166 | *
|
---|
167 | * @returns IPRT status code.
|
---|
168 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
169 | * @param cb Number of bytes to allocate. This is rounded up to nearest page.
|
---|
170 | * @param PhysHighest The highest permittable address (inclusive).
|
---|
171 | * Pass NIL_RTHCPHYS if any address is acceptable.
|
---|
172 | */
|
---|
173 | RTR0DECL(int) RTR0MemObjAllocPhys(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest);
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * Allocates non-contiguous page aligned physical memory without (necessarily) any kernel mapping.
|
---|
177 | *
|
---|
178 | * This API is for allocating huge amounts of pages and will return
|
---|
179 | * VERR_NOT_SUPPORTED if this cannot be implemented in a satisfactory
|
---|
180 | * manner.
|
---|
181 | *
|
---|
182 | * @returns IPRT status code.
|
---|
183 | * @retval VERR_NOT_SUPPORTED if it's not possible to allocated unmapped
|
---|
184 | * physical memory on this platform. The caller should expect
|
---|
185 | * this error and have a fallback strategy for it.
|
---|
186 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
187 | * @param cb Number of bytes to allocate. This is rounded up to nearest page.
|
---|
188 | * @param PhysHighest The highest permittable address (inclusive).
|
---|
189 | * Pass NIL_RTHCPHYS if any address is acceptable.
|
---|
190 | */
|
---|
191 | RTR0DECL(int) RTR0MemObjAllocPhysNC(PRTR0MEMOBJ pMemObj, size_t cb, RTHCPHYS PhysHighest);
|
---|
192 |
|
---|
193 | /**
|
---|
194 | * Creates a page aligned, contiguous, physical memory object.
|
---|
195 | *
|
---|
196 | * No physical memory is allocated, we trust you do know what you're doing.
|
---|
197 | *
|
---|
198 | * @returns IPRT status code.
|
---|
199 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
200 | * @param Phys The physical address to start at. This is rounded down to the
|
---|
201 | * nearest page boundrary.
|
---|
202 | * @param cb The size of the object in bytes. This is rounded up to nearest page boundrary.
|
---|
203 | */
|
---|
204 | RTR0DECL(int) RTR0MemObjEnterPhys(PRTR0MEMOBJ pMemObj, RTHCPHYS Phys, size_t cb);
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Reserves kernel virtual address space.
|
---|
208 | *
|
---|
209 | * If this function fails with VERR_NOT_SUPPORTED, the idea is that you
|
---|
210 | * can use RTR0MemObjEnterPhys() + RTR0MemObjMapKernel() as a fallback if
|
---|
211 | * you have a safe physical address range to make use of...
|
---|
212 | *
|
---|
213 | * @returns IPRT status code.
|
---|
214 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
215 | * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
|
---|
216 | * @param cb The number of bytes to reserve. This is rounded up to nearest page.
|
---|
217 | * @param uAlignment The alignment of the reserved memory.
|
---|
218 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
|
---|
219 | */
|
---|
220 | RTR0DECL(int) RTR0MemObjReserveKernel(PRTR0MEMOBJ pMemObj, void *pvFixed, size_t cb, size_t uAlignment);
|
---|
221 |
|
---|
222 | /**
|
---|
223 | * Reserves user virtual address space in the current process.
|
---|
224 | *
|
---|
225 | * @returns IPRT status code.
|
---|
226 | * @param pMemObj Where to store the ring-0 memory object handle.
|
---|
227 | * @param R3PtrFixed Requested address. (RTR3PTR)-1 means any address. This must match the alignment.
|
---|
228 | * @param cb The number of bytes to reserve. This is rounded up to nearest PAGE_SIZE.
|
---|
229 | * @param uAlignment The alignment of the reserved memory.
|
---|
230 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
|
---|
231 | * @param R0Process The process to reserve the memory in. NIL_R0PROCESS is an alias for the current one.
|
---|
232 | */
|
---|
233 | RTR0DECL(int) RTR0MemObjReserveUser(PRTR0MEMOBJ pMemObj, RTR3PTR R3PtrFixed, size_t cb, size_t uAlignment, RTR0PROCESS R0Process);
|
---|
234 |
|
---|
235 | /**
|
---|
236 | * Maps a memory object into kernel virtual address space.
|
---|
237 | *
|
---|
238 | * @returns IPRT status code.
|
---|
239 | * @param pMemObj Where to store the ring-0 memory object handle of the mapping object.
|
---|
240 | * @param MemObjToMap The object to be map.
|
---|
241 | * @param pvFixed Requested address. (void *)-1 means any address. This must match the alignment.
|
---|
242 | * @param uAlignment The alignment of the reserved memory.
|
---|
243 | * Supported values are 0 (alias for PAGE_SIZE), PAGE_SIZE, _2M and _4M.
|
---|
244 | * @param fProt Combination of RTMEM_PROT_* flags (except RTMEM_PROT_NONE).
|
---|
245 | */
|
---|
246 | RTR0DECL(int) RTR0MemObjMapKernel(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, void *pvFixed, size_t uAlignment, unsigned fProt);
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Maps a memory object into user virtual address space in the current process.
|
---|
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 R3PtrFixed Requested address. (RTR3PTR)-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 | * @param R0Process The process to map the memory into. NIL_R0PROCESS is an alias for the current one.
|
---|
259 | */
|
---|
260 | RTR0DECL(int) RTR0MemObjMapUser(PRTR0MEMOBJ pMemObj, RTR0MEMOBJ MemObjToMap, RTR3PTR R3PtrFixed, size_t uAlignment, unsigned fProt, RTR0PROCESS R0Process);
|
---|
261 |
|
---|
262 | #endif /* IN_RING0 */
|
---|
263 |
|
---|
264 | /** @} */
|
---|
265 |
|
---|
266 | __END_DECLS
|
---|
267 |
|
---|
268 | #endif
|
---|
269 |
|
---|