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