VirtualBox

source: vbox/trunk/include/VBox/vmm/mm.h@ 78415

Last change on this file since 78415 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.4 KB
Line 
1/** @file
2 * MM - The Memory Manager.
3 */
4
5/*
6 * Copyright (C) 2006-2019 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
38RT_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 */
52typedef 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
82 MM_TAG_EM,
83
84 MM_TAG_IEM,
85
86 MM_TAG_IOM,
87 MM_TAG_IOM_STATS,
88
89 MM_TAG_MM,
90 MM_TAG_MM_LOOKUP_GUEST,
91 MM_TAG_MM_LOOKUP_PHYS,
92 MM_TAG_MM_LOOKUP_VIRT,
93 MM_TAG_MM_PAGE,
94
95 MM_TAG_PARAV,
96
97 MM_TAG_PATM,
98 MM_TAG_PATM_PATCH,
99
100 MM_TAG_PDM,
101 MM_TAG_PDM_ASYNC_COMPLETION,
102 MM_TAG_PDM_DEVICE,
103 MM_TAG_PDM_DEVICE_DESC,
104 MM_TAG_PDM_DEVICE_USER,
105 MM_TAG_PDM_DRIVER,
106 MM_TAG_PDM_DRIVER_DESC,
107 MM_TAG_PDM_DRIVER_USER,
108 MM_TAG_PDM_USB,
109 MM_TAG_PDM_USB_DESC,
110 MM_TAG_PDM_USB_USER,
111 MM_TAG_PDM_LUN,
112#ifdef VBOX_WITH_NETSHAPER
113 MM_TAG_PDM_NET_SHAPER,
114#endif /* VBOX_WITH_NETSHAPER */
115 MM_TAG_PDM_QUEUE,
116 MM_TAG_PDM_THREAD,
117
118 MM_TAG_PGM,
119 MM_TAG_PGM_CHUNK_MAPPING,
120 MM_TAG_PGM_HANDLERS,
121 MM_TAG_PGM_HANDLER_TYPES,
122 MM_TAG_PGM_MAPPINGS,
123 MM_TAG_PGM_PHYS,
124 MM_TAG_PGM_POOL,
125
126 MM_TAG_REM,
127
128 MM_TAG_SELM,
129
130 MM_TAG_SSM,
131
132 MM_TAG_STAM,
133
134 MM_TAG_TM,
135
136 MM_TAG_TRPM,
137
138 MM_TAG_VM,
139 MM_TAG_VM_REQ,
140
141 MM_TAG_VMM,
142
143 MM_TAG_HM,
144
145 MM_TAG_32BIT_HACK = 0x7fffffff
146} MMTAG;
147
148
149
150
151/** @defgroup grp_mm_hyper Hypervisor Memory Management
152 * @{ */
153
154VMMDECL(RTR3PTR) MMHyperR0ToR3(PVM pVM, RTR0PTR R0Ptr);
155VMMDECL(RTRCPTR) MMHyperR0ToRC(PVM pVM, RTR0PTR R0Ptr);
156#ifndef IN_RING0
157VMMDECL(void *) MMHyperR0ToCC(PVM pVM, RTR0PTR R0Ptr);
158#endif
159VMMDECL(RTR0PTR) MMHyperR3ToR0(PVM pVM, RTR3PTR R3Ptr);
160VMMDECL(RTRCPTR) MMHyperR3ToRC(PVM pVM, RTR3PTR R3Ptr);
161VMMDECL(RTR3PTR) MMHyperRCToR3(PVM pVM, RTRCPTR RCPtr);
162VMMDECL(RTR0PTR) MMHyperRCToR0(PVM pVM, RTRCPTR RCPtr);
163
164#ifndef IN_RING3
165VMMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr);
166#else
167DECLINLINE(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
168{
169 NOREF(pVM);
170 return R3Ptr;
171}
172#endif
173
174
175#ifndef IN_RC
176VMMDECL(void *) MMHyperRCToCC(PVM pVM, RTRCPTR RCPtr);
177#else
178DECLINLINE(void *) MMHyperRCToCC(PVM pVM, RTRCPTR RCPtr)
179{
180 NOREF(pVM);
181 return (void *)RCPtr;
182}
183#endif
184
185#ifndef IN_RING3
186VMMDECL(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv);
187#else
188DECLINLINE(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv)
189{
190 NOREF(pVM);
191 return pv;
192}
193#endif
194
195#ifndef IN_RING0
196VMMDECL(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv);
197#else
198DECLINLINE(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv)
199{
200 NOREF(pVM);
201 return pv;
202}
203#endif
204
205#ifndef IN_RC
206VMMDECL(RTRCPTR) MMHyperCCToRC(PVM pVM, void *pv);
207#else
208DECLINLINE(RTRCPTR) MMHyperCCToRC(PVM pVM, void *pv)
209{
210 NOREF(pVM);
211 return (RTRCPTR)pv;
212}
213#endif
214
215
216VMMDECL(int) MMHyperAlloc(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, void **ppv);
217VMMDECL(int) MMHyperDupMem(PVM pVM, const void *pvSrc, size_t cb, unsigned uAlignment, MMTAG enmTag, void **ppv);
218VMMDECL(int) MMHyperFree(PVM pVM, void *pv);
219VMMDECL(void) MMHyperHeapCheck(PVM pVM);
220VMMDECL(int) MMR3LockCall(PVM pVM);
221#ifdef DEBUG
222VMMDECL(void) MMHyperHeapDump(PVM pVM);
223#endif
224VMMDECL(size_t) MMHyperHeapGetFreeSize(PVM pVM);
225VMMDECL(size_t) MMHyperHeapGetSize(PVM pVM);
226VMMDECL(void *) MMHyperHeapOffsetToPtr(PVM pVM, uint32_t offHeap);
227VMMDECL(uint32_t) MMHyperHeapPtrToOffset(PVM pVM, void *pv);
228VMMDECL(RTGCPTR) MMHyperGetArea(PVM pVM, size_t *pcb);
229VMMDECL(bool) MMHyperIsInsideArea(PVM pVM, RTGCPTR GCPtr);
230
231
232VMMDECL(RTHCPHYS) MMPage2Phys(PVM pVM, void *pvPage);
233VMMDECL(void *) MMPagePhys2Page(PVM pVM, RTHCPHYS HCPhysPage);
234VMMDECL(int) MMPagePhys2PageEx(PVM pVM, RTHCPHYS HCPhysPage, void **ppvPage);
235VMMDECL(int) MMPagePhys2PageTry(PVM pVM, RTHCPHYS HCPhysPage, void **ppvPage);
236
237
238/** @def MMHYPER_RC_ASSERT_RCPTR
239 * Asserts that an address is either NULL or inside the hypervisor memory area.
240 * This assertion only works while IN_RC, it's a NOP everywhere else.
241 * @thread The Emulation Thread.
242 */
243#ifdef IN_RC
244# define MMHYPER_RC_ASSERT_RCPTR(pVM, RCPtr) Assert(MMHyperIsInsideArea((pVM), (RTRCUINTPTR)(RCPtr)) || !(RCPtr))
245#else
246# define MMHYPER_RC_ASSERT_RCPTR(pVM, RCPtr) do { } while (0)
247#endif
248
249/** @} */
250
251
252#if defined(IN_RING3) || defined(DOXYGEN_RUNNING)
253/** @defgroup grp_mm_r3 The MM Host Context Ring-3 API
254 * @{
255 */
256
257VMMR3DECL(int) MMR3InitUVM(PUVM pUVM);
258VMMR3DECL(int) MMR3Init(PVM pVM);
259VMMR3DECL(int) MMR3InitPaging(PVM pVM);
260VMMR3DECL(int) MMR3HyperInitFinalize(PVM pVM);
261VMMR3DECL(int) MMR3Term(PVM pVM);
262VMMR3DECL(void) MMR3TermUVM(PUVM pUVM);
263VMMR3_INT_DECL(bool) MMR3IsInitialized(PVM pVM);
264VMMR3DECL(int) MMR3ReserveHandyPages(PVM pVM, uint32_t cHandyPages);
265VMMR3DECL(int) MMR3IncreaseBaseReservation(PVM pVM, uint64_t cAddBasePages);
266VMMR3DECL(int) MMR3AdjustFixedReservation(PVM pVM, int32_t cDeltaFixedPages, const char *pszDesc);
267VMMR3DECL(int) MMR3UpdateShadowReservation(PVM pVM, uint32_t cShadowPages);
268
269VMMR3DECL(int) MMR3HCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys, void **ppv);
270
271/** @defgroup grp_mm_r3_hyper Hypervisor Memory Manager (HC R3 Portion)
272 * @{ */
273VMMR3DECL(int) MMR3HyperAllocOnceNoRel(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, void **ppv);
274VMMR3DECL(int) MMR3HyperAllocOnceNoRelEx(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, uint32_t fFlags, void **ppv);
275VMMR3DECL(int) MMR3HyperRealloc(PVM pVM, void *pv, size_t cb, unsigned uAlignmentNew, MMTAG enmTagNew, size_t cbNew, void **ppv);
276/** @name MMR3HyperAllocOnceNoRelEx flags
277 * @{ */
278/** Must have kernel mapping.
279 * If not specified, the R0 pointer may point to the user process mapping. */
280#define MMHYPER_AONR_FLAGS_KERNEL_MAPPING RT_BIT(0)
281/** @} */
282VMMR3DECL(int) MMR3HyperSetGuard(PVM pVM, void *pvStart, size_t cb, bool fSet);
283VMMR3DECL(int) MMR3HyperMapHCPhys(PVM pVM, void *pvR3, RTR0PTR pvR0, RTHCPHYS HCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr);
284VMMR3DECL(int) MMR3HyperMapGCPhys(PVM pVM, RTGCPHYS GCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr);
285VMMR3DECL(int) MMR3HyperMapMMIO2(PVM pVM, PPDMDEVINS pDevIns, uint32_t iSubDev, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb, const char *pszDesc, PRTRCPTR pRCPtr);
286VMMR3DECL(int) MMR3HyperMapPages(PVM pVM, void *pvR3, RTR0PTR pvR0, size_t cPages, PCSUPPAGE paPages, const char *pszDesc, PRTGCPTR pGCPtr);
287VMMR3DECL(int) MMR3HyperReserve(PVM pVM, unsigned cb, const char *pszDesc, PRTGCPTR pGCPtr);
288VMMR3DECL(RTHCPHYS) MMR3HyperHCVirt2HCPhys(PVM pVM, void *pvHC);
289VMMR3DECL(int) MMR3HyperHCVirt2HCPhysEx(PVM pVM, void *pvHC, PRTHCPHYS pHCPhys);
290VMMR3DECL(void *) MMR3HyperHCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys);
291VMMR3DECL(int) MMR3HyperHCPhys2HCVirtEx(PVM pVM, RTHCPHYS HCPhys, void **ppv);
292VMMR3_INT_DECL(int) MMR3HyperQueryInfoFromHCPhys(PVM pVM, RTHCPHYS HCPhys, char *pszWhat, size_t cbWhat, uint32_t *pcbAlloc);
293VMMR3DECL(int) MMR3HyperReadGCVirt(PVM pVM, void *pvDst, RTGCPTR GCPtr, size_t cb);
294/** @} */
295
296
297/** @defgroup grp_mm_phys Guest Physical Memory Manager
298 * @todo retire this group, elimintating or moving MMR3PhysGetRamSize to PGMPhys.
299 * @{ */
300VMMR3DECL(uint64_t) MMR3PhysGetRamSize(PVM pVM);
301VMMR3DECL(uint32_t) MMR3PhysGetRamSizeBelow4GB(PVM pVM);
302VMMR3DECL(uint64_t) MMR3PhysGetRamSizeAbove4GB(PVM pVM);
303VMMR3DECL(uint32_t) MMR3PhysGet4GBRamHoleSize(PVM pVM);
304/** @} */
305
306
307/** @defgroup grp_mm_page Physical Page Pool
308 * @{ */
309VMMR3DECL(void *) MMR3PageAlloc(PVM pVM);
310VMMR3DECL(RTHCPHYS) MMR3PageAllocPhys(PVM pVM);
311VMMR3DECL(void) MMR3PageFree(PVM pVM, void *pvPage);
312VMMR3DECL(void *) MMR3PageAllocLow(PVM pVM);
313VMMR3DECL(void) MMR3PageFreeLow(PVM pVM, void *pvPage);
314VMMR3DECL(void) MMR3PageFreeByPhys(PVM pVM, RTHCPHYS HCPhysPage);
315VMMR3DECL(void *) MMR3PageDummyHCPtr(PVM pVM);
316VMMR3DECL(RTHCPHYS) MMR3PageDummyHCPhys(PVM pVM);
317/** @} */
318
319
320/** @defgroup grp_mm_heap Heap Manager
321 * @{ */
322VMMR3DECL(void *) MMR3HeapAlloc(PVM pVM, MMTAG enmTag, size_t cbSize);
323VMMR3DECL(void *) MMR3HeapAllocU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
324VMMR3DECL(int) MMR3HeapAllocEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
325VMMR3DECL(int) MMR3HeapAllocExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
326VMMR3DECL(void *) MMR3HeapAllocZ(PVM pVM, MMTAG enmTag, size_t cbSize);
327VMMR3DECL(void *) MMR3HeapAllocZU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
328VMMR3DECL(int) MMR3HeapAllocZEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
329VMMR3DECL(int) MMR3HeapAllocZExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
330VMMR3DECL(void *) MMR3HeapRealloc(void *pv, size_t cbNewSize);
331VMMR3DECL(char *) MMR3HeapStrDup(PVM pVM, MMTAG enmTag, const char *psz);
332VMMR3DECL(char *) MMR3HeapStrDupU(PUVM pUVM, MMTAG enmTag, const char *psz);
333VMMR3DECL(char *) MMR3HeapAPrintf(PVM pVM, MMTAG enmTag, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
334VMMR3DECL(char *) MMR3HeapAPrintfU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
335VMMR3DECL(char *) MMR3HeapAPrintfV(PVM pVM, MMTAG enmTag, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
336VMMR3DECL(char *) MMR3HeapAPrintfVU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
337VMMR3DECL(void) MMR3HeapFree(void *pv);
338/** @} */
339
340/** @defgroup grp_mm_ukheap User-kernel Heap Manager.
341 *
342 * The memory is safely accessible from kernel context as well as user land.
343 *
344 * @{ */
345VMMR3DECL(void *) MMR3UkHeapAlloc(PVM pVM, MMTAG enmTag, size_t cbSize, PRTR0PTR pR0Ptr);
346VMMR3DECL(int) MMR3UkHeapAllocEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv, PRTR0PTR pR0Ptr);
347VMMR3DECL(void *) MMR3UkHeapAllocZ(PVM pVM, MMTAG enmTag, size_t cbSize, PRTR0PTR pR0Ptr);
348VMMR3DECL(int) MMR3UkHeapAllocZEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv, PRTR0PTR pR0Ptr);
349VMMR3DECL(void) MMR3UkHeapFree(PVM pVM, void *pv, MMTAG enmTag);
350/** @} */
351
352/** @} */
353#endif /* IN_RING3 || DOXYGEN_RUNNING */
354
355
356
357#if defined(IN_RC) || defined(DOXYGEN_RUNNING)
358/** @defgroup grp_mm_rc The MM Raw-mode Context API
359 * @{
360 */
361
362VMMRCDECL(void) MMGCRamRegisterTrapHandler(PVM pVM);
363VMMRCDECL(void) MMGCRamDeregisterTrapHandler(PVM pVM);
364VMMRCDECL(int) MMGCRamReadNoTrapHandler(void *pDst, void *pSrc, size_t cb);
365/**
366 * @deprecated Don't use this as it doesn't check the page state.
367 */
368VMMRCDECL(int) MMGCRamWriteNoTrapHandler(void *pDst, void *pSrc, size_t cb);
369VMMRCDECL(int) MMGCRamRead(PVM pVM, void *pDst, void *pSrc, size_t cb);
370VMMRCDECL(int) MMGCRamWrite(PVM pVM, void *pDst, void *pSrc, size_t cb);
371
372/** @} */
373#endif /* IN_RC || DOXYGEN_RUNNING */
374
375/** @} */
376RT_C_DECLS_END
377
378
379#endif /* !VBOX_INCLUDED_vmm_mm_h */
380
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette