VirtualBox

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

Last change on this file since 67989 was 64545, checked in by vboxsync, 8 years ago

IEM: Added per-instruction statistics (not release).

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