VirtualBox

source: vbox/trunk/include/VBox/mm.h@ 23002

Last change on this file since 23002 was 21217, checked in by vboxsync, 15 years ago

include/VBox/*.h: Mark which components the header files relate to.

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