1 | /** @file
|
---|
2 | * MM - The Memory Manager.
|
---|
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 ___VBox_mm_h
|
---|
31 | #define ___VBox_mm_h
|
---|
32 |
|
---|
33 | #include <VBox/cdefs.h>
|
---|
34 | #include <VBox/types.h>
|
---|
35 | #include <VBox/x86.h>
|
---|
36 | #include <iprt/stdarg.h>
|
---|
37 | #include <VBox/sup.h>
|
---|
38 |
|
---|
39 |
|
---|
40 | __BEGIN_DECLS
|
---|
41 |
|
---|
42 | /** @defgroup grp_mm The Memory Manager API
|
---|
43 | * @{
|
---|
44 | */
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Memory Allocation Tags.
|
---|
48 | * For use with MMHyperAlloc(), MMR3HeapAlloc(), MMR3HeapAllocEx(),
|
---|
49 | * MMR3HeapAllocZ() and MMR3HeapAllocZEx().
|
---|
50 | *
|
---|
51 | * @remark Don't forget to update the dump command in MMHeap.cpp!
|
---|
52 | */
|
---|
53 | typedef enum MMTAG
|
---|
54 | {
|
---|
55 | MM_TAG_INVALID = 0,
|
---|
56 |
|
---|
57 | MM_TAG_CFGM,
|
---|
58 | MM_TAG_CFGM_BYTES,
|
---|
59 | MM_TAG_CFGM_STRING,
|
---|
60 | MM_TAG_CFGM_USER,
|
---|
61 |
|
---|
62 | MM_TAG_CSAM,
|
---|
63 | MM_TAG_CSAM_PATCH,
|
---|
64 |
|
---|
65 | MM_TAG_CPUM_CTX,
|
---|
66 |
|
---|
67 | MM_TAG_DBGF,
|
---|
68 | MM_TAG_DBGF_INFO,
|
---|
69 | MM_TAG_DBGF_LINE,
|
---|
70 | MM_TAG_DBGF_LINE_DUP,
|
---|
71 | MM_TAG_DBGF_MODULE,
|
---|
72 | MM_TAG_DBGF_OS,
|
---|
73 | MM_TAG_DBGF_STACK,
|
---|
74 | MM_TAG_DBGF_SYMBOL,
|
---|
75 | MM_TAG_DBGF_SYMBOL_DUP,
|
---|
76 |
|
---|
77 | MM_TAG_EM,
|
---|
78 |
|
---|
79 | MM_TAG_IOM,
|
---|
80 | MM_TAG_IOM_STATS,
|
---|
81 |
|
---|
82 | MM_TAG_MM,
|
---|
83 | MM_TAG_MM_LOOKUP_GUEST,
|
---|
84 | MM_TAG_MM_LOOKUP_PHYS,
|
---|
85 | MM_TAG_MM_LOOKUP_VIRT,
|
---|
86 | MM_TAG_MM_PAGE,
|
---|
87 |
|
---|
88 | MM_TAG_PARAV,
|
---|
89 |
|
---|
90 | MM_TAG_PATM,
|
---|
91 | MM_TAG_PATM_PATCH,
|
---|
92 |
|
---|
93 | MM_TAG_PDM,
|
---|
94 | MM_TAG_PDM_ASYNC_COMPLETION,
|
---|
95 | MM_TAG_PDM_DEVICE,
|
---|
96 | MM_TAG_PDM_DEVICE_USER,
|
---|
97 | MM_TAG_PDM_DRIVER,
|
---|
98 | MM_TAG_PDM_DRIVER_USER,
|
---|
99 | MM_TAG_PDM_USB,
|
---|
100 | MM_TAG_PDM_USB_USER,
|
---|
101 | MM_TAG_PDM_LUN,
|
---|
102 | MM_TAG_PDM_QUEUE,
|
---|
103 | MM_TAG_PDM_THREAD,
|
---|
104 |
|
---|
105 | MM_TAG_PGM,
|
---|
106 | MM_TAG_PGM_CHUNK_MAPPING,
|
---|
107 | MM_TAG_PGM_HANDLERS,
|
---|
108 | MM_TAG_PGM_MAPPINGS,
|
---|
109 | MM_TAG_PGM_PHYS,
|
---|
110 | MM_TAG_PGM_POOL,
|
---|
111 |
|
---|
112 | MM_TAG_REM,
|
---|
113 |
|
---|
114 | MM_TAG_SELM,
|
---|
115 |
|
---|
116 | MM_TAG_SSM,
|
---|
117 |
|
---|
118 | MM_TAG_STAM,
|
---|
119 |
|
---|
120 | MM_TAG_TM,
|
---|
121 |
|
---|
122 | MM_TAG_TRPM,
|
---|
123 |
|
---|
124 | MM_TAG_VM,
|
---|
125 | MM_TAG_VM_REQ,
|
---|
126 |
|
---|
127 | MM_TAG_VMM,
|
---|
128 |
|
---|
129 | MM_TAG_HWACCM,
|
---|
130 |
|
---|
131 | MM_TAG_32BIT_HACK = 0x7fffffff
|
---|
132 | } MMTAG;
|
---|
133 |
|
---|
134 |
|
---|
135 |
|
---|
136 |
|
---|
137 | /** @defgroup grp_mm_hyper Hypervisor Memory Management
|
---|
138 | * @ingroup grp_mm
|
---|
139 | * @{ */
|
---|
140 |
|
---|
141 | VMMDECL(RTR3PTR) MMHyperR0ToR3(PVM pVM, RTR0PTR R0Ptr);
|
---|
142 | VMMDECL(RTRCPTR) MMHyperR0ToRC(PVM pVM, RTR0PTR R0Ptr);
|
---|
143 | #ifndef IN_RING0
|
---|
144 | VMMDECL(void *) MMHyperR0ToCC(PVM pVM, RTR0PTR R0Ptr);
|
---|
145 | #endif
|
---|
146 | VMMDECL(RTR0PTR) MMHyperR3ToR0(PVM pVM, RTR3PTR R3Ptr);
|
---|
147 | VMMDECL(RTRCPTR) MMHyperR3ToRC(PVM pVM, RTR3PTR R3Ptr);
|
---|
148 | VMMDECL(RTR3PTR) MMHyperRCToR3(PVM pVM, RTRCPTR RCPtr);
|
---|
149 | VMMDECL(RTR0PTR) MMHyperRCToR0(PVM pVM, RTRCPTR RCPtr);
|
---|
150 |
|
---|
151 | #ifndef IN_RING3
|
---|
152 | VMMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr);
|
---|
153 | #else
|
---|
154 | DECLINLINE(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
|
---|
155 | {
|
---|
156 | NOREF(pVM);
|
---|
157 | return R3Ptr;
|
---|
158 | }
|
---|
159 | #endif
|
---|
160 |
|
---|
161 |
|
---|
162 | #ifndef IN_RC
|
---|
163 | VMMDECL(void *) MMHyperRCToCC(PVM pVM, RTRCPTR RCPtr);
|
---|
164 | #else
|
---|
165 | DECLINLINE(void *) MMHyperRCToCC(PVM pVM, RTRCPTR RCPtr)
|
---|
166 | {
|
---|
167 | NOREF(pVM);
|
---|
168 | return (void *)RCPtr;
|
---|
169 | }
|
---|
170 | #endif
|
---|
171 |
|
---|
172 | #ifndef IN_RING3
|
---|
173 | VMMDECL(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv);
|
---|
174 | #else
|
---|
175 | DECLINLINE(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv)
|
---|
176 | {
|
---|
177 | NOREF(pVM);
|
---|
178 | return pv;
|
---|
179 | }
|
---|
180 | #endif
|
---|
181 |
|
---|
182 | #ifndef IN_RING0
|
---|
183 | VMMDECL(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv);
|
---|
184 | #else
|
---|
185 | DECLINLINE(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv)
|
---|
186 | {
|
---|
187 | NOREF(pVM);
|
---|
188 | return pv;
|
---|
189 | }
|
---|
190 | #endif
|
---|
191 |
|
---|
192 | #ifndef IN_RC
|
---|
193 | VMMDECL(RTRCPTR) MMHyperCCToRC(PVM pVM, void *pv);
|
---|
194 | #else
|
---|
195 | DECLINLINE(RTRCPTR) MMHyperCCToRC(PVM pVM, void *pv)
|
---|
196 | {
|
---|
197 | NOREF(pVM);
|
---|
198 | return (RTRCPTR)pv;
|
---|
199 | }
|
---|
200 | #endif
|
---|
201 |
|
---|
202 |
|
---|
203 | VMMDECL(int) MMHyperAlloc(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, void **ppv);
|
---|
204 | VMMDECL(int) MMHyperFree(PVM pVM, void *pv);
|
---|
205 | VMMDECL(void) MMHyperHeapCheck(PVM pVM);
|
---|
206 | #ifdef DEBUG
|
---|
207 | VMMDECL(void) MMHyperHeapDump(PVM pVM);
|
---|
208 | #endif
|
---|
209 | VMMDECL(size_t) MMHyperHeapGetFreeSize(PVM pVM);
|
---|
210 | VMMDECL(size_t) MMHyperHeapGetSize(PVM pVM);
|
---|
211 | VMMDECL(RTGCPTR) MMHyperGetArea(PVM pVM, size_t *pcb);
|
---|
212 | VMMDECL(bool) MMHyperIsInsideArea(PVM pVM, RTGCPTR GCPtr);
|
---|
213 |
|
---|
214 |
|
---|
215 | VMMDECL(RTHCPHYS) MMPage2Phys(PVM pVM, void *pvPage);
|
---|
216 | VMMDECL(void *) MMPagePhys2Page(PVM pVM, RTHCPHYS HCPhysPage);
|
---|
217 | VMMDECL(int) MMPagePhys2PageEx(PVM pVM, RTHCPHYS HCPhysPage, void **ppvPage);
|
---|
218 | VMMDECL(int) MMPagePhys2PageTry(PVM pVM, RTHCPHYS HCPhysPage, void **ppvPage);
|
---|
219 |
|
---|
220 |
|
---|
221 | /** @def MMHYPER_RC_ASSERT_RCPTR
|
---|
222 | * Asserts that an address is either NULL or inside the hypervisor memory area.
|
---|
223 | * This assertion only works while IN_RC, it's a NOP everywhere else.
|
---|
224 | * @thread The Emulation Thread.
|
---|
225 | */
|
---|
226 | #ifdef IN_RC
|
---|
227 | # define MMHYPER_RC_ASSERT_RCPTR(pVM, RCPtr) Assert(MMHyperIsInsideArea((pVM), (RTRCUINTPTR)(RCPtr)) || !(RCPtr))
|
---|
228 | #else
|
---|
229 | # define MMHYPER_RC_ASSERT_RCPTR(pVM, RCPtr) do { } while (0)
|
---|
230 | #endif
|
---|
231 |
|
---|
232 | /** @} */
|
---|
233 |
|
---|
234 |
|
---|
235 | #ifdef IN_RING3
|
---|
236 | /** @defgroup grp_mm_r3 The MM Host Context Ring-3 API
|
---|
237 | * @ingroup grp_mm
|
---|
238 | * @{
|
---|
239 | */
|
---|
240 |
|
---|
241 | VMMR3DECL(int) MMR3InitUVM(PUVM pUVM);
|
---|
242 | VMMR3DECL(int) MMR3Init(PVM pVM);
|
---|
243 | VMMR3DECL(int) MMR3InitPaging(PVM pVM);
|
---|
244 | VMMR3DECL(int) MMR3HyperInitFinalize(PVM pVM);
|
---|
245 | VMMR3DECL(int) MMR3Term(PVM pVM);
|
---|
246 | VMMR3DECL(void) MMR3TermUVM(PUVM pUVM);
|
---|
247 | VMMR3DECL(void) MMR3Reset(PVM pVM);
|
---|
248 | VMMR3DECL(int) MMR3ReserveHandyPages(PVM pVM, uint32_t cHandyPages);
|
---|
249 | VMMR3DECL(int) MMR3IncreaseBaseReservation(PVM pVM, uint64_t cAddBasePages);
|
---|
250 | VMMR3DECL(int) MMR3AdjustFixedReservation(PVM pVM, int32_t cDeltaFixedPages, const char *pszDesc);
|
---|
251 | VMMR3DECL(int) MMR3UpdateShadowReservation(PVM pVM, uint32_t cShadowPages);
|
---|
252 |
|
---|
253 | VMMR3DECL(int) MMR3HCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys, void **ppv);
|
---|
254 | VMMR3DECL(int) MMR3ReadGCVirt(PVM pVM, void *pvDst, RTGCPTR GCPtr, size_t cb);
|
---|
255 | VMMR3DECL(int) MMR3WriteGCVirt(PVM pVM, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
|
---|
256 |
|
---|
257 |
|
---|
258 | /** @defgroup grp_mm_r3_hyper Hypervisor Memory Manager (HC R3 Portion)
|
---|
259 | * @ingroup grp_mm_r3
|
---|
260 | * @{ */
|
---|
261 | VMMDECL(int) MMR3HyperAllocOnceNoRel(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, void **ppv);
|
---|
262 | VMMR3DECL(int) MMR3HyperMapHCPhys(PVM pVM, void *pvR3, RTR0PTR pvR0, RTHCPHYS HCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr);
|
---|
263 | VMMR3DECL(int) MMR3HyperMapGCPhys(PVM pVM, RTGCPHYS GCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr);
|
---|
264 | VMMR3DECL(int) MMR3HyperMapMMIO2(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb, const char *pszDesc, PRTRCPTR pRCPtr);
|
---|
265 | VMMR3DECL(int) MMR3HyperMapPages(PVM pVM, void *pvR3, RTR0PTR pvR0, size_t cPages, PCSUPPAGE paPages, const char *pszDesc, PRTGCPTR pGCPtr);
|
---|
266 | VMMR3DECL(int) MMR3HyperReserve(PVM pVM, unsigned cb, const char *pszDesc, PRTGCPTR pGCPtr);
|
---|
267 | VMMR3DECL(RTHCPHYS) MMR3HyperHCVirt2HCPhys(PVM pVM, void *pvHC);
|
---|
268 | VMMR3DECL(int) MMR3HyperHCVirt2HCPhysEx(PVM pVM, void *pvHC, PRTHCPHYS pHCPhys);
|
---|
269 | VMMR3DECL(void *) MMR3HyperHCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys);
|
---|
270 | VMMR3DECL(int) MMR3HyperHCPhys2HCVirtEx(PVM pVM, RTHCPHYS HCPhys, void **ppv);
|
---|
271 | VMMR3DECL(int) MMR3HyperReadGCVirt(PVM pVM, void *pvDst, RTGCPTR GCPtr, size_t cb);
|
---|
272 | /** @} */
|
---|
273 |
|
---|
274 |
|
---|
275 | /** @defgroup grp_mm_phys Guest Physical Memory Manager
|
---|
276 | * @todo retire this group, elimintating or moving MMR3PhysGetRamSize to PGMPhys.
|
---|
277 | * @ingroup grp_mm_r3
|
---|
278 | * @{ */
|
---|
279 | VMMR3DECL(uint64_t) MMR3PhysGetRamSize(PVM pVM);
|
---|
280 | /** @} */
|
---|
281 |
|
---|
282 |
|
---|
283 | /** @defgroup grp_mm_page Physical Page Pool
|
---|
284 | * @ingroup grp_mm_r3
|
---|
285 | * @{ */
|
---|
286 | VMMR3DECL(void *) MMR3PageAlloc(PVM pVM);
|
---|
287 | VMMR3DECL(RTHCPHYS) MMR3PageAllocPhys(PVM pVM);
|
---|
288 | VMMR3DECL(void) MMR3PageFree(PVM pVM, void *pvPage);
|
---|
289 | VMMR3DECL(void *) MMR3PageAllocLow(PVM pVM);
|
---|
290 | VMMR3DECL(void) MMR3PageFreeLow(PVM pVM, void *pvPage);
|
---|
291 | VMMR3DECL(void) MMR3PageFreeByPhys(PVM pVM, RTHCPHYS HCPhysPage);
|
---|
292 | VMMR3DECL(void *) MMR3PageDummyHCPtr(PVM pVM);
|
---|
293 | VMMR3DECL(RTHCPHYS) MMR3PageDummyHCPhys(PVM pVM);
|
---|
294 | /** @} */
|
---|
295 |
|
---|
296 |
|
---|
297 | /** @defgroup grp_mm_heap Heap Manager
|
---|
298 | * @ingroup grp_mm_r3
|
---|
299 | * @{ */
|
---|
300 | VMMR3DECL(void *) MMR3HeapAlloc(PVM pVM, MMTAG enmTag, size_t cbSize);
|
---|
301 | VMMR3DECL(void *) MMR3HeapAllocU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
|
---|
302 | VMMR3DECL(int) MMR3HeapAllocEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
303 | VMMR3DECL(int) MMR3HeapAllocExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
304 | VMMR3DECL(void *) MMR3HeapAllocZ(PVM pVM, MMTAG enmTag, size_t cbSize);
|
---|
305 | VMMR3DECL(void *) MMR3HeapAllocZU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
|
---|
306 | VMMR3DECL(int) MMR3HeapAllocZEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
307 | VMMR3DECL(int) MMR3HeapAllocZExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
308 | VMMR3DECL(void *) MMR3HeapRealloc(void *pv, size_t cbNewSize);
|
---|
309 | VMMR3DECL(char *) MMR3HeapStrDup(PVM pVM, MMTAG enmTag, const char *psz);
|
---|
310 | VMMR3DECL(char *) MMR3HeapStrDupU(PUVM pUVM, MMTAG enmTag, const char *psz);
|
---|
311 | VMMR3DECL(char *) MMR3HeapAPrintf(PVM pVM, MMTAG enmTag, const char *pszFormat, ...);
|
---|
312 | VMMR3DECL(char *) MMR3HeapAPrintfU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, ...);
|
---|
313 | VMMR3DECL(char *) MMR3HeapAPrintfV(PVM pVM, MMTAG enmTag, const char *pszFormat, va_list va);
|
---|
314 | VMMR3DECL(char *) MMR3HeapAPrintfVU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, va_list va);
|
---|
315 | VMMR3DECL(void) MMR3HeapFree(void *pv);
|
---|
316 | /** @} */
|
---|
317 |
|
---|
318 | /** @} */
|
---|
319 | #endif /* IN_RING3 */
|
---|
320 |
|
---|
321 |
|
---|
322 |
|
---|
323 | #ifdef IN_RC
|
---|
324 | /** @defgroup grp_mm_gc The MM Guest Context API
|
---|
325 | * @ingroup grp_mm
|
---|
326 | * @{
|
---|
327 | */
|
---|
328 |
|
---|
329 | VMMRCDECL(void) MMGCRamRegisterTrapHandler(PVM pVM);
|
---|
330 | VMMRCDECL(void) MMGCRamDeregisterTrapHandler(PVM pVM);
|
---|
331 | VMMRCDECL(int) MMGCRamReadNoTrapHandler(void *pDst, void *pSrc, size_t cb);
|
---|
332 | VMMRCDECL(int) MMGCRamWriteNoTrapHandler(void *pDst, void *pSrc, size_t cb);
|
---|
333 | VMMRCDECL(int) MMGCRamRead(PVM pVM, void *pDst, void *pSrc, size_t cb);
|
---|
334 | VMMRCDECL(int) MMGCRamWrite(PVM pVM, void *pDst, void *pSrc, size_t cb);
|
---|
335 |
|
---|
336 | /** @} */
|
---|
337 | #endif /* IN_RC */
|
---|
338 |
|
---|
339 | /** @} */
|
---|
340 | __END_DECLS
|
---|
341 |
|
---|
342 |
|
---|
343 | #endif
|
---|
344 |
|
---|