1 | /** @file
|
---|
2 | * MM - The Memory Manager.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
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 VBOX_INCLUDED_vmm_mm_h
|
---|
27 | #define VBOX_INCLUDED_vmm_mm_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <VBox/types.h>
|
---|
33 | #include <iprt/x86.h>
|
---|
34 | #include <VBox/sup.h>
|
---|
35 | #include <iprt/stdarg.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | RT_C_DECLS_BEGIN
|
---|
39 |
|
---|
40 | /** @defgroup grp_mm The Memory Manager API
|
---|
41 | * @ingroup grp_vmm
|
---|
42 | * @{
|
---|
43 | */
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Memory Allocation Tags.
|
---|
47 | * For use with MMHyperAlloc(), MMR3HeapAlloc(), MMR3HeapAllocEx(),
|
---|
48 | * MMR3HeapAllocZ() and MMR3HeapAllocZEx().
|
---|
49 | *
|
---|
50 | * @remark Don't forget to update the dump command in MMHeap.cpp!
|
---|
51 | */
|
---|
52 | typedef enum MMTAG
|
---|
53 | {
|
---|
54 | MM_TAG_INVALID = 0,
|
---|
55 |
|
---|
56 | MM_TAG_CFGM,
|
---|
57 | MM_TAG_CFGM_BYTES,
|
---|
58 | MM_TAG_CFGM_STRING,
|
---|
59 | MM_TAG_CFGM_USER,
|
---|
60 |
|
---|
61 | MM_TAG_CSAM,
|
---|
62 | MM_TAG_CSAM_PATCH,
|
---|
63 |
|
---|
64 | MM_TAG_CPUM_CTX,
|
---|
65 | MM_TAG_CPUM_CPUID,
|
---|
66 | MM_TAG_CPUM_MSRS,
|
---|
67 |
|
---|
68 | MM_TAG_DBGF,
|
---|
69 | MM_TAG_DBGF_AS,
|
---|
70 | MM_TAG_DBGF_CORE_WRITE,
|
---|
71 | MM_TAG_DBGF_INFO,
|
---|
72 | MM_TAG_DBGF_LINE,
|
---|
73 | MM_TAG_DBGF_LINE_DUP,
|
---|
74 | MM_TAG_DBGF_MODULE,
|
---|
75 | MM_TAG_DBGF_OS,
|
---|
76 | MM_TAG_DBGF_REG,
|
---|
77 | MM_TAG_DBGF_STACK,
|
---|
78 | MM_TAG_DBGF_SYMBOL,
|
---|
79 | MM_TAG_DBGF_SYMBOL_DUP,
|
---|
80 | MM_TAG_DBGF_TYPE,
|
---|
81 | MM_TAG_DBGF_TRACER,
|
---|
82 | MM_TAG_DBGF_FLOWTRACE,
|
---|
83 |
|
---|
84 | MM_TAG_EM,
|
---|
85 |
|
---|
86 | MM_TAG_IEM,
|
---|
87 |
|
---|
88 | MM_TAG_IOM,
|
---|
89 | MM_TAG_IOM_STATS,
|
---|
90 |
|
---|
91 | MM_TAG_MM,
|
---|
92 | MM_TAG_MM_LOOKUP_GUEST,
|
---|
93 | MM_TAG_MM_LOOKUP_PHYS,
|
---|
94 | MM_TAG_MM_LOOKUP_VIRT,
|
---|
95 | MM_TAG_MM_PAGE,
|
---|
96 |
|
---|
97 | MM_TAG_PARAV,
|
---|
98 |
|
---|
99 | MM_TAG_PATM,
|
---|
100 | MM_TAG_PATM_PATCH,
|
---|
101 |
|
---|
102 | MM_TAG_PDM,
|
---|
103 | MM_TAG_PDM_ASYNC_COMPLETION,
|
---|
104 | MM_TAG_PDM_DEVICE,
|
---|
105 | MM_TAG_PDM_DEVICE_DESC,
|
---|
106 | MM_TAG_PDM_DEVICE_USER,
|
---|
107 | MM_TAG_PDM_DRIVER,
|
---|
108 | MM_TAG_PDM_DRIVER_DESC,
|
---|
109 | MM_TAG_PDM_DRIVER_USER,
|
---|
110 | MM_TAG_PDM_USB,
|
---|
111 | MM_TAG_PDM_USB_DESC,
|
---|
112 | MM_TAG_PDM_USB_USER,
|
---|
113 | MM_TAG_PDM_LUN,
|
---|
114 | #ifdef VBOX_WITH_NETSHAPER
|
---|
115 | MM_TAG_PDM_NET_SHAPER,
|
---|
116 | #endif /* VBOX_WITH_NETSHAPER */
|
---|
117 | MM_TAG_PDM_QUEUE,
|
---|
118 | MM_TAG_PDM_THREAD,
|
---|
119 |
|
---|
120 | MM_TAG_PGM,
|
---|
121 | MM_TAG_PGM_CHUNK_MAPPING,
|
---|
122 | MM_TAG_PGM_HANDLERS,
|
---|
123 | MM_TAG_PGM_HANDLER_TYPES,
|
---|
124 | MM_TAG_PGM_MAPPINGS,
|
---|
125 | MM_TAG_PGM_PHYS,
|
---|
126 | MM_TAG_PGM_POOL,
|
---|
127 |
|
---|
128 | MM_TAG_REM,
|
---|
129 |
|
---|
130 | MM_TAG_SELM,
|
---|
131 |
|
---|
132 | MM_TAG_SSM,
|
---|
133 |
|
---|
134 | MM_TAG_STAM,
|
---|
135 |
|
---|
136 | MM_TAG_TM,
|
---|
137 |
|
---|
138 | MM_TAG_TRPM,
|
---|
139 |
|
---|
140 | MM_TAG_VM,
|
---|
141 | MM_TAG_VM_REQ,
|
---|
142 |
|
---|
143 | MM_TAG_VMM,
|
---|
144 |
|
---|
145 | MM_TAG_HM,
|
---|
146 |
|
---|
147 | MM_TAG_32BIT_HACK = 0x7fffffff
|
---|
148 | } MMTAG;
|
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 | /** @defgroup grp_mm_hyper Hypervisor Memory Management
|
---|
154 | * @{ */
|
---|
155 |
|
---|
156 | VMMDECL(RTR3PTR) MMHyperR0ToR3(PVM pVM, RTR0PTR R0Ptr);
|
---|
157 | #ifndef IN_RING0
|
---|
158 | VMMDECL(void *) MMHyperR0ToCC(PVM pVM, RTR0PTR R0Ptr);
|
---|
159 | #endif
|
---|
160 | VMMDECL(RTR0PTR) MMHyperR3ToR0(PVM pVM, RTR3PTR R3Ptr);
|
---|
161 | VMMDECL(RTR3PTR) MMHyperRCToR3(PVM pVM, RTRCPTR RCPtr);
|
---|
162 | VMMDECL(RTR0PTR) MMHyperRCToR0(PVM pVM, RTRCPTR RCPtr);
|
---|
163 |
|
---|
164 | #ifndef IN_RING3
|
---|
165 | VMMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr);
|
---|
166 | #else
|
---|
167 | DECLINLINE(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
|
---|
168 | {
|
---|
169 | NOREF(pVM);
|
---|
170 | return R3Ptr;
|
---|
171 | }
|
---|
172 | #endif
|
---|
173 |
|
---|
174 |
|
---|
175 | VMMDECL(void *) MMHyperRCToCC(PVM pVM, RTRCPTR RCPtr);
|
---|
176 |
|
---|
177 | #ifndef IN_RING3
|
---|
178 | VMMDECL(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv);
|
---|
179 | #else
|
---|
180 | DECLINLINE(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv)
|
---|
181 | {
|
---|
182 | NOREF(pVM);
|
---|
183 | return pv;
|
---|
184 | }
|
---|
185 | #endif
|
---|
186 |
|
---|
187 | #ifndef IN_RING0
|
---|
188 | VMMDECL(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv);
|
---|
189 | #else
|
---|
190 | DECLINLINE(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv)
|
---|
191 | {
|
---|
192 | NOREF(pVM);
|
---|
193 | return pv;
|
---|
194 | }
|
---|
195 | #endif
|
---|
196 |
|
---|
197 |
|
---|
198 | VMMDECL(int) MMHyperAlloc(PVMCC pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, void **ppv);
|
---|
199 | #if 0
|
---|
200 | VMMDECL(int) MMHyperDupMem(PVMCC pVM, const void *pvSrc, size_t cb, unsigned uAlignment, MMTAG enmTag, void **ppv);
|
---|
201 | #endif
|
---|
202 | VMMDECL(int) MMHyperFree(PVMCC pVM, void *pv);
|
---|
203 | VMMDECL(void) MMHyperHeapCheck(PVMCC pVM);
|
---|
204 | #ifdef DEBUG
|
---|
205 | VMMDECL(void) MMHyperHeapDump(PVM pVM);
|
---|
206 | #endif
|
---|
207 | VMMDECL(size_t) MMHyperHeapGetFreeSize(PVM pVM);
|
---|
208 | VMMDECL(size_t) MMHyperHeapGetSize(PVM pVM);
|
---|
209 | VMMDECL(void *) MMHyperHeapOffsetToPtr(PVM pVM, uint32_t offHeap);
|
---|
210 | VMMDECL(uint32_t) MMHyperHeapPtrToOffset(PVM pVM, void *pv);
|
---|
211 | VMMDECL(RTGCPTR) MMHyperGetArea(PVM pVM, size_t *pcb);
|
---|
212 | VMMDECL(bool) MMHyperIsInsideArea(PVM pVM, RTGCPTR GCPtr);
|
---|
213 |
|
---|
214 | #if 0
|
---|
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 | #endif
|
---|
220 |
|
---|
221 |
|
---|
222 | /** @def MMHYPER_RC_ASSERT_RCPTR
|
---|
223 | * Asserts that an address is either NULL or inside the hypervisor memory area.
|
---|
224 | * This assertion only works while IN_RC, it's a NOP everywhere else.
|
---|
225 | * @thread The Emulation Thread.
|
---|
226 | */
|
---|
227 | #define MMHYPER_RC_ASSERT_RCPTR(pVM, RCPtr) do { } while (0)
|
---|
228 |
|
---|
229 | /** @} */
|
---|
230 |
|
---|
231 |
|
---|
232 | #if defined(IN_RING3) || defined(DOXYGEN_RUNNING)
|
---|
233 | /** @defgroup grp_mm_r3 The MM Host Context Ring-3 API
|
---|
234 | * @{
|
---|
235 | */
|
---|
236 |
|
---|
237 | VMMR3DECL(int) MMR3InitUVM(PUVM pUVM);
|
---|
238 | VMMR3DECL(int) MMR3Init(PVM pVM);
|
---|
239 | VMMR3DECL(int) MMR3InitPaging(PVM pVM);
|
---|
240 | VMMR3DECL(int) MMR3HyperInitFinalize(PVM pVM);
|
---|
241 | VMMR3DECL(int) MMR3Term(PVM pVM);
|
---|
242 | VMMR3DECL(void) MMR3TermUVM(PUVM pUVM);
|
---|
243 | VMMR3_INT_DECL(bool) MMR3IsInitialized(PVM pVM);
|
---|
244 | VMMR3DECL(int) MMR3ReserveHandyPages(PVM pVM, uint32_t cHandyPages);
|
---|
245 | VMMR3DECL(int) MMR3IncreaseBaseReservation(PVM pVM, uint64_t cAddBasePages);
|
---|
246 | VMMR3DECL(int) MMR3AdjustFixedReservation(PVM pVM, int32_t cDeltaFixedPages, const char *pszDesc);
|
---|
247 | VMMR3DECL(int) MMR3UpdateShadowReservation(PVM pVM, uint32_t cShadowPages);
|
---|
248 |
|
---|
249 | VMMR3DECL(int) MMR3HCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys, void **ppv);
|
---|
250 |
|
---|
251 | /** @defgroup grp_mm_r3_hyper Hypervisor Memory Manager (HC R3 Portion)
|
---|
252 | * @{ */
|
---|
253 | VMMR3DECL(int) MMR3HyperAllocOnceNoRel(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, void **ppv);
|
---|
254 | VMMR3DECL(int) MMR3HyperAllocOnceNoRelEx(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, uint32_t fFlags, void **ppv);
|
---|
255 | #if 0
|
---|
256 | VMMR3DECL(int) MMR3HyperRealloc(PVM pVM, void *pv, size_t cb, unsigned uAlignmentNew, MMTAG enmTagNew, size_t cbNew, void **ppv);
|
---|
257 | #endif
|
---|
258 | /** @name MMR3HyperAllocOnceNoRelEx flags
|
---|
259 | * @{ */
|
---|
260 | /** Must have kernel mapping.
|
---|
261 | * If not specified, the R0 pointer may point to the user process mapping. */
|
---|
262 | #define MMHYPER_AONR_FLAGS_KERNEL_MAPPING RT_BIT(0)
|
---|
263 | /** @} */
|
---|
264 | VMMR3DECL(RTHCPHYS) MMR3HyperHCVirt2HCPhys(PVM pVM, void *pvHC);
|
---|
265 | VMMR3DECL(int) MMR3HyperHCVirt2HCPhysEx(PVM pVM, void *pvHC, PRTHCPHYS pHCPhys);
|
---|
266 | /** @} */
|
---|
267 |
|
---|
268 |
|
---|
269 | /** @defgroup grp_mm_phys Guest Physical Memory Manager
|
---|
270 | * @todo retire this group, elimintating or moving MMR3PhysGetRamSize to PGMPhys.
|
---|
271 | * @{ */
|
---|
272 | VMMR3DECL(uint64_t) MMR3PhysGetRamSize(PVM pVM);
|
---|
273 | VMMR3DECL(uint32_t) MMR3PhysGetRamSizeBelow4GB(PVM pVM);
|
---|
274 | VMMR3DECL(uint64_t) MMR3PhysGetRamSizeAbove4GB(PVM pVM);
|
---|
275 | VMMR3DECL(uint32_t) MMR3PhysGet4GBRamHoleSize(PVM pVM);
|
---|
276 | /** @} */
|
---|
277 |
|
---|
278 |
|
---|
279 | /** @defgroup grp_mm_page Physical Page Pool (what's left of it)
|
---|
280 | * @{ */
|
---|
281 | VMMR3DECL(void *) MMR3PageDummyHCPtr(PVM pVM);
|
---|
282 | VMMR3DECL(RTHCPHYS) MMR3PageDummyHCPhys(PVM pVM);
|
---|
283 | /** @} */
|
---|
284 |
|
---|
285 |
|
---|
286 | /** @defgroup grp_mm_heap Heap Manager
|
---|
287 | * @{ */
|
---|
288 | VMMR3DECL(void *) MMR3HeapAlloc(PVM pVM, MMTAG enmTag, size_t cbSize);
|
---|
289 | VMMR3DECL(void *) MMR3HeapAllocU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
|
---|
290 | VMMR3DECL(int) MMR3HeapAllocEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
291 | VMMR3DECL(int) MMR3HeapAllocExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
292 | VMMR3DECL(void *) MMR3HeapAllocZ(PVM pVM, MMTAG enmTag, size_t cbSize);
|
---|
293 | VMMR3DECL(void *) MMR3HeapAllocZU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
|
---|
294 | VMMR3DECL(int) MMR3HeapAllocZEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
295 | VMMR3DECL(int) MMR3HeapAllocZExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
296 | VMMR3DECL(void *) MMR3HeapRealloc(void *pv, size_t cbNewSize);
|
---|
297 | VMMR3DECL(char *) MMR3HeapStrDup(PVM pVM, MMTAG enmTag, const char *psz);
|
---|
298 | VMMR3DECL(char *) MMR3HeapStrDupU(PUVM pUVM, MMTAG enmTag, const char *psz);
|
---|
299 | VMMR3DECL(char *) MMR3HeapAPrintf(PVM pVM, MMTAG enmTag, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
300 | VMMR3DECL(char *) MMR3HeapAPrintfU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
301 | VMMR3DECL(char *) MMR3HeapAPrintfV(PVM pVM, MMTAG enmTag, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
|
---|
302 | VMMR3DECL(char *) MMR3HeapAPrintfVU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
|
---|
303 | VMMR3DECL(void) MMR3HeapFree(void *pv);
|
---|
304 | /** @} */
|
---|
305 |
|
---|
306 | /** @} */
|
---|
307 | #endif /* IN_RING3 || DOXYGEN_RUNNING */
|
---|
308 |
|
---|
309 |
|
---|
310 | /** @} */
|
---|
311 | RT_C_DECLS_END
|
---|
312 |
|
---|
313 |
|
---|
314 | #endif /* !VBOX_INCLUDED_vmm_mm_h */
|
---|
315 |
|
---|