2
* MM - The Memory Manager. (VMM)
6
* Copyright (C) 2006-2007 Oracle Corporation
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.
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.
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.
29
#include <VBox/cdefs.h>
30
#include <VBox/types.h>
32
#include <iprt/stdarg.h>
38
/** @defgroup grp_mm The Memory Manager API
43
* Memory Allocation Tags.
44
* For use with MMHyperAlloc(), MMR3HeapAlloc(), MMR3HeapAllocEx(),
45
* MMR3HeapAllocZ() and MMR3HeapAllocZEx().
47
* @remark Don't forget to update the dump command in MMHeap.cpp!
72
MM_TAG_DBGF_SYMBOL_DUP,
80
MM_TAG_MM_LOOKUP_GUEST,
81
MM_TAG_MM_LOOKUP_PHYS,
82
MM_TAG_MM_LOOKUP_VIRT,
91
MM_TAG_PDM_ASYNC_COMPLETION,
93
MM_TAG_PDM_DEVICE_DESC,
94
MM_TAG_PDM_DEVICE_USER,
96
MM_TAG_PDM_DRIVER_DESC,
97
MM_TAG_PDM_DRIVER_USER,
106
MM_TAG_PGM_CHUNK_MAPPING,
131
MM_TAG_32BIT_HACK = 0x7fffffff
137
/** @defgroup grp_mm_hyper Hypervisor Memory Management
141
VMMDECL(RTR3PTR) MMHyperR0ToR3(PVM pVM, RTR0PTR R0Ptr);
142
VMMDECL(RTRCPTR) MMHyperR0ToRC(PVM pVM, RTR0PTR R0Ptr);
144
VMMDECL(void *) MMHyperR0ToCC(PVM pVM, RTR0PTR R0Ptr);
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);
152
VMMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr);
154
DECLINLINE(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
163
VMMDECL(void *) MMHyperRCToCC(PVM pVM, RTRCPTR RCPtr);
165
DECLINLINE(void *) MMHyperRCToCC(PVM pVM, RTRCPTR RCPtr)
168
return (void *)RCPtr;
173
VMMDECL(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv);
175
DECLINLINE(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv)
183
VMMDECL(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv);
185
DECLINLINE(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv)
193
VMMDECL(RTRCPTR) MMHyperCCToRC(PVM pVM, void *pv);
195
DECLINLINE(RTRCPTR) MMHyperCCToRC(PVM pVM, void *pv)
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
VMMDECL(int) MMR3LockCall(PVM pVM);
208
VMMDECL(void) MMHyperHeapDump(PVM pVM);
210
VMMDECL(size_t) MMHyperHeapGetFreeSize(PVM pVM);
211
VMMDECL(size_t) MMHyperHeapGetSize(PVM pVM);
212
VMMDECL(RTGCPTR) MMHyperGetArea(PVM pVM, size_t *pcb);
213
VMMDECL(bool) MMHyperIsInsideArea(PVM pVM, RTGCPTR GCPtr);
216
VMMDECL(RTHCPHYS) MMPage2Phys(PVM pVM, void *pvPage);
217
VMMDECL(void *) MMPagePhys2Page(PVM pVM, RTHCPHYS HCPhysPage);
218
VMMDECL(int) MMPagePhys2PageEx(PVM pVM, RTHCPHYS HCPhysPage, void **ppvPage);
219
VMMDECL(int) MMPagePhys2PageTry(PVM pVM, RTHCPHYS HCPhysPage, void **ppvPage);
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.
228
# define MMHYPER_RC_ASSERT_RCPTR(pVM, RCPtr) Assert(MMHyperIsInsideArea((pVM), (RTRCUINTPTR)(RCPtr)) || !(RCPtr))
230
# define MMHYPER_RC_ASSERT_RCPTR(pVM, RCPtr) do { } while (0)
237
/** @defgroup grp_mm_r3 The MM Host Context Ring-3 API
242
VMMR3DECL(int) MMR3InitUVM(PUVM pUVM);
243
VMMR3DECL(int) MMR3Init(PVM pVM);
244
VMMR3DECL(int) MMR3InitPaging(PVM pVM);
245
VMMR3DECL(int) MMR3HyperInitFinalize(PVM pVM);
246
VMMR3DECL(int) MMR3Term(PVM pVM);
247
VMMR3DECL(void) MMR3TermUVM(PUVM pUVM);
248
VMMR3DECL(void) MMR3Reset(PVM pVM);
249
VMMR3DECL(int) MMR3ReserveHandyPages(PVM pVM, uint32_t cHandyPages);
250
VMMR3DECL(int) MMR3IncreaseBaseReservation(PVM pVM, uint64_t cAddBasePages);
251
VMMR3DECL(int) MMR3AdjustFixedReservation(PVM pVM, int32_t cDeltaFixedPages, const char *pszDesc);
252
VMMR3DECL(int) MMR3UpdateShadowReservation(PVM pVM, uint32_t cShadowPages);
254
VMMR3DECL(int) MMR3HCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys, void **ppv);
256
/** @defgroup grp_mm_r3_hyper Hypervisor Memory Manager (HC R3 Portion)
259
VMMR3DECL(int) MMR3HyperAllocOnceNoRel(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, void **ppv);
260
VMMR3DECL(int) MMR3HyperAllocOnceNoRelEx(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, uint32_t fFlags, void **ppv);
261
/** @name MMR3HyperAllocOnceNoRelEx flags
263
/** Must have kernel mapping.
264
* If not specified, the R0 pointer may point to the user process mapping. */
265
#define MMHYPER_AONR_FLAGS_KERNEL_MAPPING RT_BIT(0)
267
VMMR3DECL(int) MMR3HyperSetGuard(PVM pVM, void *pvStart, size_t cb, bool fSet);
268
VMMR3DECL(int) MMR3HyperMapHCPhys(PVM pVM, void *pvR3, RTR0PTR pvR0, RTHCPHYS HCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr);
269
VMMR3DECL(int) MMR3HyperMapGCPhys(PVM pVM, RTGCPHYS GCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr);
270
VMMR3DECL(int) MMR3HyperMapMMIO2(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb, const char *pszDesc, PRTRCPTR pRCPtr);
271
VMMR3DECL(int) MMR3HyperMapPages(PVM pVM, void *pvR3, RTR0PTR pvR0, size_t cPages, PCSUPPAGE paPages, const char *pszDesc, PRTGCPTR pGCPtr);
272
VMMR3DECL(int) MMR3HyperReserve(PVM pVM, unsigned cb, const char *pszDesc, PRTGCPTR pGCPtr);
273
VMMR3DECL(RTHCPHYS) MMR3HyperHCVirt2HCPhys(PVM pVM, void *pvHC);
274
VMMR3DECL(int) MMR3HyperHCVirt2HCPhysEx(PVM pVM, void *pvHC, PRTHCPHYS pHCPhys);
275
VMMR3DECL(void *) MMR3HyperHCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys);
276
VMMR3DECL(int) MMR3HyperHCPhys2HCVirtEx(PVM pVM, RTHCPHYS HCPhys, void **ppv);
277
VMMR3DECL(int) MMR3HyperReadGCVirt(PVM pVM, void *pvDst, RTGCPTR GCPtr, size_t cb);
281
/** @defgroup grp_mm_phys Guest Physical Memory Manager
282
* @todo retire this group, elimintating or moving MMR3PhysGetRamSize to PGMPhys.
285
VMMR3DECL(uint64_t) MMR3PhysGetRamSize(PVM pVM);
289
/** @defgroup grp_mm_page Physical Page Pool
292
VMMR3DECL(void *) MMR3PageAlloc(PVM pVM);
293
VMMR3DECL(RTHCPHYS) MMR3PageAllocPhys(PVM pVM);
294
VMMR3DECL(void) MMR3PageFree(PVM pVM, void *pvPage);
295
VMMR3DECL(void *) MMR3PageAllocLow(PVM pVM);
296
VMMR3DECL(void) MMR3PageFreeLow(PVM pVM, void *pvPage);
297
VMMR3DECL(void) MMR3PageFreeByPhys(PVM pVM, RTHCPHYS HCPhysPage);
298
VMMR3DECL(void *) MMR3PageDummyHCPtr(PVM pVM);
299
VMMR3DECL(RTHCPHYS) MMR3PageDummyHCPhys(PVM pVM);
303
/** @defgroup grp_mm_heap Heap Manager
306
VMMR3DECL(void *) MMR3HeapAlloc(PVM pVM, MMTAG enmTag, size_t cbSize);
307
VMMR3DECL(void *) MMR3HeapAllocU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
308
VMMR3DECL(int) MMR3HeapAllocEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
309
VMMR3DECL(int) MMR3HeapAllocExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
310
VMMR3DECL(void *) MMR3HeapAllocZ(PVM pVM, MMTAG enmTag, size_t cbSize);
311
VMMR3DECL(void *) MMR3HeapAllocZU(PUVM pUVM, MMTAG enmTag, size_t cbSize);
312
VMMR3DECL(int) MMR3HeapAllocZEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
313
VMMR3DECL(int) MMR3HeapAllocZExU(PUVM pUVM, MMTAG enmTag, size_t cbSize, void **ppv);
314
VMMR3DECL(void *) MMR3HeapRealloc(void *pv, size_t cbNewSize);
315
VMMR3DECL(char *) MMR3HeapStrDup(PVM pVM, MMTAG enmTag, const char *psz);
316
VMMR3DECL(char *) MMR3HeapStrDupU(PUVM pUVM, MMTAG enmTag, const char *psz);
317
VMMR3DECL(char *) MMR3HeapAPrintf(PVM pVM, MMTAG enmTag, const char *pszFormat, ...);
318
VMMR3DECL(char *) MMR3HeapAPrintfU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, ...);
319
VMMR3DECL(char *) MMR3HeapAPrintfV(PVM pVM, MMTAG enmTag, const char *pszFormat, va_list va);
320
VMMR3DECL(char *) MMR3HeapAPrintfVU(PUVM pUVM, MMTAG enmTag, const char *pszFormat, va_list va);
321
VMMR3DECL(void) MMR3HeapFree(void *pv);
324
/** @defgroup grp_mm_heap User-kernel Heap Manager.
327
* The memory is safely accessible from kernel context as well as user land.
330
VMMR3DECL(void *) MMR3UkHeapAlloc(PVM pVM, MMTAG enmTag, size_t cbSize, PRTR0PTR pR0Ptr);
331
VMMR3DECL(int) MMR3UkHeapAllocEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv, PRTR0PTR pR0Ptr);
332
VMMR3DECL(void *) MMR3UkHeapAllocZ(PVM pVM, MMTAG enmTag, size_t cbSize, PRTR0PTR pR0Ptr);
333
VMMR3DECL(int) MMR3UkHeapAllocZEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv, PRTR0PTR pR0Ptr);
334
VMMR3DECL(void) MMR3UkHeapFree(PVM pVM, void *pv, MMTAG enmTag);
338
#endif /* IN_RING3 */
343
/** @defgroup grp_mm_gc The MM Guest Context API
348
VMMRCDECL(void) MMGCRamRegisterTrapHandler(PVM pVM);
349
VMMRCDECL(void) MMGCRamDeregisterTrapHandler(PVM pVM);
350
VMMRCDECL(int) MMGCRamReadNoTrapHandler(void *pDst, void *pSrc, size_t cb);
352
* @deprecated Don't use this as it doesn't check the page state.
354
VMMRCDECL(int) MMGCRamWriteNoTrapHandler(void *pDst, void *pSrc, size_t cb);
355
VMMRCDECL(int) MMGCRamRead(PVM pVM, void *pDst, void *pSrc, size_t cb);
356
VMMRCDECL(int) MMGCRamWrite(PVM pVM, void *pDst, void *pSrc, size_t cb);