1 | /** @file
|
---|
2 | * MM - The Memory Manager.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef VBOX_INCLUDED_vmm_mm_h
|
---|
37 | #define VBOX_INCLUDED_vmm_mm_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <VBox/types.h>
|
---|
43 | #include <iprt/x86.h>
|
---|
44 | #include <VBox/sup.h>
|
---|
45 | #include <iprt/stdarg.h>
|
---|
46 |
|
---|
47 |
|
---|
48 | RT_C_DECLS_BEGIN
|
---|
49 |
|
---|
50 | /** @defgroup grp_mm The Memory Manager API
|
---|
51 | * @ingroup grp_vmm
|
---|
52 | * @{
|
---|
53 | */
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Memory Allocation Tags.
|
---|
57 | * For use with MMHyperAlloc(), MMR3HeapAlloc(), MMR3HeapAllocEx(),
|
---|
58 | * MMR3HeapAllocZ() and MMR3HeapAllocZEx().
|
---|
59 | *
|
---|
60 | * @remark Don't forget to update the dump command in MMHeap.cpp!
|
---|
61 | */
|
---|
62 | typedef enum MMTAG
|
---|
63 | {
|
---|
64 | MM_TAG_INVALID = 0,
|
---|
65 |
|
---|
66 | MM_TAG_CFGM,
|
---|
67 | MM_TAG_CFGM_BYTES,
|
---|
68 | MM_TAG_CFGM_STRING,
|
---|
69 | MM_TAG_CFGM_USER,
|
---|
70 |
|
---|
71 | MM_TAG_CSAM,
|
---|
72 | MM_TAG_CSAM_PATCH,
|
---|
73 |
|
---|
74 | MM_TAG_CPUM_CTX,
|
---|
75 | MM_TAG_CPUM_CPUID,
|
---|
76 | MM_TAG_CPUM_MSRS,
|
---|
77 |
|
---|
78 | MM_TAG_DBGF,
|
---|
79 | MM_TAG_DBGF_AS,
|
---|
80 | MM_TAG_DBGF_CORE_WRITE,
|
---|
81 | MM_TAG_DBGF_INFO,
|
---|
82 | MM_TAG_DBGF_LINE,
|
---|
83 | MM_TAG_DBGF_LINE_DUP,
|
---|
84 | MM_TAG_DBGF_MODULE,
|
---|
85 | MM_TAG_DBGF_OS,
|
---|
86 | MM_TAG_DBGF_REG,
|
---|
87 | MM_TAG_DBGF_STACK,
|
---|
88 | MM_TAG_DBGF_SYMBOL,
|
---|
89 | MM_TAG_DBGF_SYMBOL_DUP,
|
---|
90 | MM_TAG_DBGF_TYPE,
|
---|
91 | MM_TAG_DBGF_TRACER,
|
---|
92 | MM_TAG_DBGF_FLOWTRACE,
|
---|
93 |
|
---|
94 | MM_TAG_EM,
|
---|
95 |
|
---|
96 | MM_TAG_IEM,
|
---|
97 |
|
---|
98 | MM_TAG_IOM,
|
---|
99 | MM_TAG_IOM_STATS,
|
---|
100 |
|
---|
101 | MM_TAG_MM,
|
---|
102 | MM_TAG_MM_LOOKUP_GUEST,
|
---|
103 | MM_TAG_MM_LOOKUP_PHYS,
|
---|
104 | MM_TAG_MM_LOOKUP_VIRT,
|
---|
105 | MM_TAG_MM_PAGE,
|
---|
106 |
|
---|
107 | MM_TAG_PARAV,
|
---|
108 |
|
---|
109 | MM_TAG_PATM,
|
---|
110 | MM_TAG_PATM_PATCH,
|
---|
111 |
|
---|
112 | MM_TAG_PDM,
|
---|
113 | MM_TAG_PDM_ASYNC_COMPLETION,
|
---|
114 | MM_TAG_PDM_DEVICE,
|
---|
115 | MM_TAG_PDM_DEVICE_DESC,
|
---|
116 | MM_TAG_PDM_DEVICE_USER,
|
---|
117 | MM_TAG_PDM_DRIVER,
|
---|
118 | MM_TAG_PDM_DRIVER_DESC,
|
---|
119 | MM_TAG_PDM_DRIVER_USER,
|
---|
120 | MM_TAG_PDM_USB,
|
---|
121 | MM_TAG_PDM_USB_DESC,
|
---|
122 | MM_TAG_PDM_USB_USER,
|
---|
123 | MM_TAG_PDM_LUN,
|
---|
124 | #ifdef VBOX_WITH_NETSHAPER
|
---|
125 | MM_TAG_PDM_NET_SHAPER,
|
---|
126 | #endif /* VBOX_WITH_NETSHAPER */
|
---|
127 | MM_TAG_PDM_QUEUE,
|
---|
128 | MM_TAG_PDM_THREAD,
|
---|
129 |
|
---|
130 | MM_TAG_PGM,
|
---|
131 | MM_TAG_PGM_CHUNK_MAPPING,
|
---|
132 | MM_TAG_PGM_HANDLERS,
|
---|
133 | MM_TAG_PGM_HANDLER_TYPES,
|
---|
134 | MM_TAG_PGM_MAPPINGS,
|
---|
135 | MM_TAG_PGM_PHYS,
|
---|
136 | MM_TAG_PGM_POOL,
|
---|
137 |
|
---|
138 | MM_TAG_REM,
|
---|
139 |
|
---|
140 | MM_TAG_SELM,
|
---|
141 |
|
---|
142 | MM_TAG_SSM,
|
---|
143 |
|
---|
144 | MM_TAG_STAM,
|
---|
145 |
|
---|
146 | MM_TAG_TM,
|
---|
147 |
|
---|
148 | MM_TAG_TRPM,
|
---|
149 |
|
---|
150 | MM_TAG_VM,
|
---|
151 | MM_TAG_VM_REQ,
|
---|
152 |
|
---|
153 | MM_TAG_VMM,
|
---|
154 |
|
---|
155 | MM_TAG_HM,
|
---|
156 |
|
---|
157 | MM_TAG_32BIT_HACK = 0x7fffffff
|
---|
158 | } MMTAG;
|
---|
159 |
|
---|
160 |
|
---|
161 |
|
---|
162 |
|
---|
163 | /** @defgroup grp_mm_hyper Hypervisor Memory Management
|
---|
164 | * @{ */
|
---|
165 |
|
---|
166 | VMMDECL(RTR0PTR) MMHyperR3ToR0(PVM pVM, RTR3PTR R3Ptr);
|
---|
167 |
|
---|
168 | #ifndef IN_RING3
|
---|
169 | VMMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr);
|
---|
170 | #else
|
---|
171 | DECLINLINE(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
|
---|
172 | {
|
---|
173 | NOREF(pVM);
|
---|
174 | return R3Ptr;
|
---|
175 | }
|
---|
176 | #endif
|
---|
177 |
|
---|
178 |
|
---|
179 | /** @def MMHYPER_RC_ASSERT_RCPTR
|
---|
180 | * Asserts that an address is either NULL or inside the hypervisor memory area.
|
---|
181 | * This assertion only works while IN_RC, it's a NOP everywhere else.
|
---|
182 | * @thread The Emulation Thread.
|
---|
183 | */
|
---|
184 | #define MMHYPER_RC_ASSERT_RCPTR(pVM, RCPtr) do { } while (0)
|
---|
185 |
|
---|
186 | /** @} */
|
---|
187 |
|
---|
188 |
|
---|
189 | #if defined(IN_RING3) || defined(DOXYGEN_RUNNING)
|
---|
190 | /** @defgroup grp_mm_r3 The MM Host Context Ring-3 API
|
---|
191 | * @{
|
---|
192 | */
|
---|
193 |
|
---|
194 | VMMR3DECL(int) MMR3InitUVM(PUVM pUVM);
|
---|
195 | VMMR3DECL(int) MMR3Init(PVM pVM);
|
---|
196 | VMMR3DECL(int) MMR3InitPaging(PVM pVM);
|
---|
197 | VMMR3DECL(int) MMR3Term(PVM pVM);
|
---|
198 | VMMR3DECL(void) MMR3TermUVM(PUVM pUVM);
|
---|
199 | VMMR3DECL(int) MMR3ReserveHandyPages(PVM pVM, uint32_t cHandyPages);
|
---|
200 | VMMR3DECL(int) MMR3IncreaseBaseReservation(PVM pVM, uint64_t cAddBasePages);
|
---|
201 | VMMR3DECL(int) MMR3AdjustFixedReservation(PVM pVM, int32_t cDeltaFixedPages, const char *pszDesc);
|
---|
202 | VMMR3DECL(int) MMR3UpdateShadowReservation(PVM pVM, uint32_t cShadowPages);
|
---|
203 | /** @} */
|
---|
204 |
|
---|
205 |
|
---|
206 | /** @defgroup grp_mm_phys Guest Physical Memory Manager
|
---|
207 | * @todo retire this group, elimintating or moving MMR3PhysGetRamSize to PGMPhys.
|
---|
208 | * @{ */
|
---|
209 | VMMR3DECL(uint64_t) MMR3PhysGetRamSize(PVM pVM);
|
---|
210 | VMMR3DECL(uint32_t) MMR3PhysGetRamSizeBelow4GB(PVM pVM);
|
---|
211 | VMMR3DECL(uint64_t) MMR3PhysGetRamSizeAbove4GB(PVM pVM);
|
---|
212 | VMMR3DECL(uint32_t) MMR3PhysGet4GBRamHoleSize(PVM pVM);
|
---|
213 | /** @} */
|
---|
214 |
|
---|
215 |
|
---|
216 | /** @defgroup grp_mm_heap Heap Manager
|
---|
217 | * @{ */
|
---|
218 | VMMR3DECL(void *) MMR3HeapAlloc(PVM pVM, MMTAG enmTag, size_t cbSize);
|
---|
219 | VMMR3DECL(void *) MMR3HeapAllocU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
|
---|
220 | VMMR3DECL(int) MMR3HeapAllocEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
221 | VMMR3DECL(int) MMR3HeapAllocExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
222 | VMMR3DECL(void *) MMR3HeapAllocZ(PVM pVM, MMTAG enmTag, size_t cbSize);
|
---|
223 | VMMR3DECL(void *) MMR3HeapAllocZU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
|
---|
224 | VMMR3DECL(int) MMR3HeapAllocZEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
225 | VMMR3DECL(int) MMR3HeapAllocZExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
|
---|
226 | VMMR3DECL(void *) MMR3HeapRealloc(void *pv, size_t cbNewSize);
|
---|
227 | VMMR3DECL(char *) MMR3HeapStrDup(PVM pVM, MMTAG enmTag, const char *psz);
|
---|
228 | VMMR3DECL(char *) MMR3HeapStrDupU(PUVM pUVM, MMTAG enmTag, const char *psz);
|
---|
229 | VMMR3DECL(char *) MMR3HeapAPrintf(PVM pVM, MMTAG enmTag, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
230 | VMMR3DECL(char *) MMR3HeapAPrintfU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
231 | VMMR3DECL(char *) MMR3HeapAPrintfV(PVM pVM, MMTAG enmTag, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
|
---|
232 | VMMR3DECL(char *) MMR3HeapAPrintfVU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
|
---|
233 | VMMR3DECL(void) MMR3HeapFree(void *pv);
|
---|
234 | /** @} */
|
---|
235 |
|
---|
236 | #endif /* IN_RING3 || DOXYGEN_RUNNING */
|
---|
237 |
|
---|
238 |
|
---|
239 | /** @} */
|
---|
240 | RT_C_DECLS_END
|
---|
241 |
|
---|
242 |
|
---|
243 | #endif /* !VBOX_INCLUDED_vmm_mm_h */
|
---|
244 |
|
---|