VirtualBox

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

Last change on this file since 5764 was 5605, checked in by vboxsync, 17 years ago

BIT => RT_BIT, BIT64 => RT_BIT_64. BIT() is defined in Linux 2.6.24

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.6 KB
Line 
1/** @file
2 * MM - The Memory Manager.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef ___VBox_mm_h
18#define ___VBox_mm_h
19
20#include <VBox/cdefs.h>
21#include <VBox/types.h>
22#include <VBox/x86.h>
23#include <VBox/sup.h>
24
25
26__BEGIN_DECLS
27
28/** @defgroup grp_mm The Memory Manager API
29 * @{
30 */
31
32/** @name RAM Page Flags
33 * Since internal ranges have a byte granularity it's possible for a
34 * page be flagged for several uses. The access virtualization in PGM
35 * will choose the most restricted one and use EM to emulate access to
36 * the less restricted areas of the page.
37 *
38 * Bits 0-11 only since they are fitted into the offset part of a physical memory address.
39 * @{
40 */
41/** Reserved - Not RAM, ROM nor MMIO2.
42 * If this bit is cleared the memory is assumed to be some kind of RAM.
43 * Normal MMIO may set it but that depends on whether the RAM range was
44 * created specially for the MMIO or not.
45 *
46 * @remarks The current implementation will always reserve backing
47 * memory for reserved ranges to simplify things.
48 */
49#define MM_RAM_FLAGS_RESERVED RT_BIT(0)
50/** ROM - Read Only Memory.
51 * The page have a HC physical address which contains the BIOS code. All write
52 * access is trapped and ignored.
53 *
54 * HACK: Writable shadow ROM is indicated by both ROM and MMIO2 being
55 * set. (We're out of bits.)
56 */
57#define MM_RAM_FLAGS_ROM RT_BIT(1)
58/** MMIO - Memory Mapped I/O.
59 * All access is trapped and emulated. No physical backing is required, but
60 * might for various reasons be present.
61 */
62#define MM_RAM_FLAGS_MMIO RT_BIT(2)
63/** MMIO2 - Memory Mapped I/O, variation 2.
64 * The virtualization is performed using real memory and only catching
65 * a few accesses for like keeping track for dirty pages.
66 * @remark Involved in the shadow ROM hack.
67 */
68#define MM_RAM_FLAGS_MMIO2 RT_BIT(3)
69
70/** PGM has virtual page access handler(s) defined for pages with this flag. */
71#define MM_RAM_FLAGS_VIRTUAL_HANDLER RT_BIT(4)
72/** PGM has virtual page access handler(s) for write access. */
73#define MM_RAM_FLAGS_VIRTUAL_WRITE RT_BIT(5)
74/** PGM has virtual page access handler(s) for all access. */
75#define MM_RAM_FLAGS_VIRTUAL_ALL RT_BIT(6)
76/** PGM has physical page access handler(s) defined for pages with this flag. */
77#define MM_RAM_FLAGS_PHYSICAL_HANDLER RT_BIT(7)
78/** PGM has physical page access handler(s) for write access. */
79#define MM_RAM_FLAGS_PHYSICAL_WRITE RT_BIT(8)
80/** PGM has physical page access handler(s) for all access. */
81#define MM_RAM_FLAGS_PHYSICAL_ALL RT_BIT(9)
82/** PGM has physical page access handler(s) for this page and has temporarily disabled it. */
83#define MM_RAM_FLAGS_PHYSICAL_TEMP_OFF RT_BIT(10)
84#ifndef NEW_PHYS_CODE
85/** Physical backing memory is allocated dynamically. Not set implies a one time static allocation. */
86#define MM_RAM_FLAGS_DYNAMIC_ALLOC RT_BIT(11)
87#endif /* !NEW_PHYS_CODE */
88
89/** The shift used to get the reference count. */
90#define MM_RAM_FLAGS_CREFS_SHIFT 62
91/** The mask applied to the the page pool idx after using MM_RAM_FLAGS_CREFS_SHIFT to shift it down. */
92#define MM_RAM_FLAGS_CREFS_MASK 0x3
93/** The (shifted) cRef value used to indiciate that the idx is the head of a
94 * physical cross reference extent list. */
95#define MM_RAM_FLAGS_CREFS_PHYSEXT MM_RAM_FLAGS_CREFS_MASK
96/** The shift used to get the page pool idx. (Apply MM_RAM_FLAGS_IDX_MASK to the result when shifting down). */
97#define MM_RAM_FLAGS_IDX_SHIFT 48
98/** The mask applied to the the page pool idx after using MM_RAM_FLAGS_IDX_SHIFT to shift it down. */
99#define MM_RAM_FLAGS_IDX_MASK 0x3fff
100/** The idx value when we're out of of extents or there are simply too many mappings of this page. */
101#define MM_RAM_FLAGS_IDX_OVERFLOWED MM_RAM_FLAGS_IDX_MASK
102
103/** Mask for masking off any references to the page. */
104#define MM_RAM_FLAGS_NO_REFS_MASK UINT64_C(0x0000ffffffffffff)
105/** @} */
106
107/** @name MMR3PhysRegisterEx registration type
108 * @{
109 */
110typedef enum
111{
112 /** Normal physical region (flags specify exact page type) */
113 MM_PHYS_TYPE_NORMAL = 0,
114 /** Allocate part of a dynamically allocated physical region */
115 MM_PHYS_TYPE_DYNALLOC_CHUNK,
116
117 MM_PHYS_TYPE_32BIT_HACK = 0x7fffffff
118} MMPHYSREG;
119/** @} */
120
121/**
122 * Memory Allocation Tags.
123 * For use with MMHyperAlloc(), MMR3HeapAlloc(), MMR3HeapAllocEx(),
124 * MMR3HeapAllocZ() and MMR3HeapAllocZEx().
125 *
126 * @remark Don't forget to update the dump command in MMHeap.cpp!
127 */
128typedef enum MMTAG
129{
130 MM_TAG_INVALID = 0,
131
132 MM_TAG_CFGM,
133 MM_TAG_CFGM_BYTES,
134 MM_TAG_CFGM_STRING,
135 MM_TAG_CFGM_USER,
136
137 MM_TAG_CSAM,
138 MM_TAG_CSAM_PATCH,
139
140 MM_TAG_DBGF,
141 MM_TAG_DBGF_INFO,
142 MM_TAG_DBGF_LINE,
143 MM_TAG_DBGF_LINE_DUP,
144 MM_TAG_DBGF_STACK,
145 MM_TAG_DBGF_SYMBOL,
146 MM_TAG_DBGF_SYMBOL_DUP,
147 MM_TAG_DBGF_MODULE,
148
149 MM_TAG_EM,
150
151 MM_TAG_IOM,
152 MM_TAG_IOM_STATS,
153
154 MM_TAG_MM,
155 MM_TAG_MM_LOOKUP_GUEST,
156 MM_TAG_MM_LOOKUP_PHYS,
157 MM_TAG_MM_LOOKUP_VIRT,
158 MM_TAG_MM_PAGE,
159
160 MM_TAG_PATM,
161 MM_TAG_PATM_PATCH,
162
163 MM_TAG_PDM,
164 MM_TAG_PDM_DEVICE,
165 MM_TAG_PDM_DEVICE_USER,
166 MM_TAG_PDM_DRIVER,
167 MM_TAG_PDM_DRIVER_USER,
168 MM_TAG_PDM_USB,
169 MM_TAG_PDM_USB_USER,
170 MM_TAG_PDM_LUN,
171 MM_TAG_PDM_QUEUE,
172 MM_TAG_PDM_THREAD,
173
174 MM_TAG_PGM,
175 MM_TAG_PGM_CHUNK_MAPPING,
176 MM_TAG_PGM_HANDLERS,
177 MM_TAG_PGM_POOL,
178
179 MM_TAG_REM,
180
181 MM_TAG_SELM,
182
183 MM_TAG_SSM,
184
185 MM_TAG_STAM,
186
187 MM_TAG_TM,
188
189 MM_TAG_TRPM,
190
191 MM_TAG_VM,
192 MM_TAG_VM_REQ,
193
194 MM_TAG_VMM,
195
196 MM_TAG_HWACCM,
197
198 MM_TAG_32BIT_HACK = 0x7fffffff
199} MMTAG;
200
201
202
203
204/** @defgroup grp_mm_hyper Hypervisor Memory Management
205 * @ingroup grp_mm
206 * @{ */
207
208/**
209 * Converts a ring-0 host context address in the Hypervisor memory region to a ring-3 host context address.
210 *
211 * @returns ring-3 host context address.
212 * @param pVM The VM to operate on.
213 * @param R0Ptr The ring-0 host context address.
214 * You'll be damned if this is not in the HMA! :-)
215 * @thread The Emulation Thread.
216 */
217MMDECL(RTR3PTR) MMHyperR0ToR3(PVM pVM, RTR0PTR R0Ptr);
218
219/**
220 * Converts a ring-0 host context address in the Hypervisor memory region to a guest context address.
221 *
222 * @returns guest context address.
223 * @param pVM The VM to operate on.
224 * @param R0Ptr The ring-0 host context address.
225 * You'll be damned if this is not in the HMA! :-)
226 * @thread The Emulation Thread.
227 */
228MMDECL(RTGCPTR) MMHyperR0ToGC(PVM pVM, RTR0PTR R0Ptr);
229
230/**
231 * Converts a ring-0 host context address in the Hypervisor memory region to a current context address.
232 *
233 * @returns current context address.
234 * @param pVM The VM to operate on.
235 * @param R0Ptr The ring-0 host context address.
236 * You'll be damned if this is not in the HMA! :-)
237 * @thread The Emulation Thread.
238 */
239#ifndef IN_RING0
240MMDECL(void *) MMHyperR0ToCC(PVM pVM, RTR0PTR R0Ptr);
241#endif
242
243
244/**
245 * Converts a ring-3 host context address in the Hypervisor memory region to a ring-0 host context address.
246 *
247 * @returns ring-0 host context address.
248 * @param pVM The VM to operate on.
249 * @param R3Ptr The ring-3 host context address.
250 * You'll be damned if this is not in the HMA! :-)
251 * @thread The Emulation Thread.
252 */
253MMDECL(RTR0PTR) MMHyperR3ToR0(PVM pVM, RTR3PTR R3Ptr);
254
255/**
256 * Converts a ring-3 host context address in the Hypervisor memory region to a guest context address.
257 *
258 * @returns guest context address.
259 * @param pVM The VM to operate on.
260 * @param R3Ptr The ring-3 host context address.
261 * You'll be damned if this is not in the HMA! :-)
262 * @thread The Emulation Thread.
263 */
264MMDECL(RTGCPTR) MMHyperR3ToGC(PVM pVM, RTR3PTR R3Ptr);
265
266/**
267 * Converts a ring-3 host context address in the Hypervisor memory region to a current context address.
268 *
269 * @returns current context address.
270 * @param pVM The VM to operate on.
271 * @param R3Ptr The ring-3 host context address.
272 * You'll be damned if this is not in the HMA! :-)
273 * @thread The Emulation Thread.
274 */
275#ifndef IN_RING3
276MMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr);
277#else
278DECLINLINE(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
279{
280 NOREF(pVM);
281 return R3Ptr;
282}
283#endif
284
285
286/**
287 * Converts a guest context address in the Hypervisor memory region to a ring-3 context address.
288 *
289 * @returns ring-3 host context address.
290 * @param pVM The VM to operate on.
291 * @param GCPtr The guest context address.
292 * You'll be damned if this is not in the HMA! :-)
293 * @thread The Emulation Thread.
294 */
295MMDECL(RTR3PTR) MMHyperGCToR3(PVM pVM, RTGCPTR GCPtr);
296
297/**
298 * Converts a guest context address in the Hypervisor memory region to a ring-0 host context address.
299 *
300 * @returns ring-0 host context address.
301 * @param pVM The VM to operate on.
302 * @param GCPtr The guest context address.
303 * You'll be damned if this is not in the HMA! :-)
304 * @thread The Emulation Thread.
305 */
306MMDECL(RTR0PTR) MMHyperGCToR0(PVM pVM, RTGCPTR GCPtr);
307
308/**
309 * Converts a guest context address in the Hypervisor memory region to a current context address.
310 *
311 * @returns current context address.
312 * @param pVM The VM to operate on.
313 * @param GCPtr The guest host context address.
314 * You'll be damned if this is not in the HMA! :-)
315 * @thread The Emulation Thread.
316 */
317#ifndef IN_GC
318MMDECL(void *) MMHyperGCToCC(PVM pVM, RTGCPTR GCPtr);
319#else
320DECLINLINE(void *) MMHyperGCToCC(PVM pVM, RTGCPTR GCPtr)
321{
322 NOREF(pVM);
323 return GCPtr;
324}
325#endif
326
327
328
329/**
330 * Converts a current context address in the Hypervisor memory region to a ring-3 host context address.
331 *
332 * @returns ring-3 host context address.
333 * @param pVM The VM to operate on.
334 * @param pv The current context address.
335 * You'll be damned if this is not in the HMA! :-)
336 * @thread The Emulation Thread.
337 */
338#ifndef IN_RING3
339MMDECL(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv);
340#else
341DECLINLINE(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv)
342{
343 NOREF(pVM);
344 return pv;
345}
346#endif
347
348/**
349 * Converts a current context address in the Hypervisor memory region to a ring-0 host context address.
350 *
351 * @returns ring-0 host context address.
352 * @param pVM The VM to operate on.
353 * @param pv The current context address.
354 * You'll be damned if this is not in the HMA! :-)
355 * @thread The Emulation Thread.
356 */
357#ifndef IN_RING0
358MMDECL(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv);
359#else
360DECLINLINE(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv)
361{
362 NOREF(pVM);
363 return pv;
364}
365#endif
366
367/**
368 * Converts a current context address in the Hypervisor memory region to a guest context address.
369 *
370 * @returns guest context address.
371 * @param pVM The VM to operate on.
372 * @param pv The current context address.
373 * You'll be damned if this is not in the HMA! :-)
374 * @thread The Emulation Thread.
375 */
376#ifndef IN_GC
377MMDECL(RTGCPTR) MMHyperCCToGC(PVM pVM, void *pv);
378#else
379DECLINLINE(RTGCPTR) MMHyperCCToGC(PVM pVM, void *pv)
380{
381 NOREF(pVM);
382 return pv;
383}
384#endif
385
386
387
388/**
389 * Converts a current context address in the Hypervisor memory region to a HC address.
390 * The memory must have been allocated with MMHyperAlloc().
391 *
392 * @returns HC address.
393 * @param pVM The VM to operate on.
394 * @param Ptr The current context address.
395 * @thread The Emulation Thread.
396 * @deprecated
397 */
398#ifdef IN_GC
399MMDECL(RTHCPTR) MMHyper2HC(PVM pVM, uintptr_t Ptr);
400#else
401DECLINLINE(RTHCPTR) MMHyper2HC(PVM pVM, uintptr_t Ptr)
402{
403 NOREF(pVM);
404 return (RTHCPTR)Ptr;
405}
406#endif
407
408/**
409 * Converts a current context address in the Hypervisor memory region to a GC address.
410 * The memory must have been allocated with MMHyperAlloc().
411 *
412 * @returns HC address.
413 * @param pVM The VM to operate on.
414 * @param Ptr The current context address.
415 * @thread The Emulation Thread.
416 */
417#ifndef IN_GC
418MMDECL(RTGCPTR) MMHyper2GC(PVM pVM, uintptr_t Ptr);
419#else
420DECLINLINE(RTGCPTR) MMHyper2GC(PVM pVM, uintptr_t Ptr)
421{
422 NOREF(pVM);
423 return (RTGCPTR)Ptr;
424}
425#endif
426
427/**
428 * Converts a HC address in the Hypervisor memory region to a GC address.
429 * The memory must have been allocated with MMGCHyperAlloc() or MMR3HyperAlloc().
430 *
431 * @returns GC address.
432 * @param pVM The VM to operate on.
433 * @param HCPtr The host context address.
434 * You'll be damned if this is not in the HMA! :-)
435 * @thread The Emulation Thread.
436 * @deprecated
437 */
438MMDECL(RTGCPTR) MMHyperHC2GC(PVM pVM, RTHCPTR HCPtr);
439
440/**
441 * Converts a GC address in the Hypervisor memory region to a HC address.
442 * The memory must have been allocated with MMGCHyperAlloc() or MMR3HyperAlloc().
443 *
444 * @returns HC address.
445 * @param pVM The VM to operate on.
446 * @param GCPtr The guest context address.
447 * You'll be damned if this is not in the HMA! :-)
448 * @thread The Emulation Thread.
449 * @deprecated
450 */
451MMDECL(RTHCPTR) MMHyperGC2HC(PVM pVM, RTGCPTR GCPtr);
452
453
454/**
455 * Allocates memory in the Hypervisor (GC VMM) area.
456 * The returned memory is of course zeroed.
457 *
458 * @returns VBox status code.
459 * @param pVM The VM to operate on.
460 * @param cb Number of bytes to allocate.
461 * @param uAlignment Required memory alignment in bytes.
462 * Values are 0,8,16,32 and PAGE_SIZE.
463 * 0 -> default alignment, i.e. 8 bytes.
464 * @param enmTag The statistics tag.
465 * @param ppv Where to store the address to the allocated
466 * memory.
467 * @remark This is assumed not to be used at times when serialization is required.
468 */
469MMDECL(int) MMHyperAlloc(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, void **ppv);
470
471/**
472 * Free memory allocated using MMHyperAlloc().
473 *
474 * It's not possible to free memory which is page aligned!
475 *
476 * @returns VBox status code.
477 * @param pVM The VM to operate on.
478 * @param pv The memory to free.
479 * @remark Try avoid freeing hyper memory.
480 * @thread The Emulation Thread.
481 */
482MMDECL(int) MMHyperFree(PVM pVM, void *pv);
483
484#ifdef DEBUG
485/**
486 * Dumps the hypervisor heap to Log.
487 * @param pVM VM Handle.
488 * @thread The Emulation Thread.
489 */
490MMDECL(void) MMHyperHeapDump(PVM pVM);
491#endif
492
493/**
494 * Query the amount of free memory in the hypervisor heap.
495 *
496 * @returns Number of free bytes in the hypervisor heap.
497 * @thread Any.
498 */
499MMDECL(size_t) MMHyperHeapGetFreeSize(PVM pVM);
500
501/**
502 * Query the size the hypervisor heap.
503 *
504 * @returns The size of the hypervisor heap in bytes.
505 * @thread Any.
506 */
507MMDECL(size_t) MMHyperHeapGetSize(PVM pVM);
508
509
510/**
511 * Query the address and size the hypervisor memory area.
512 *
513 * @returns Base address of the hypervisor area.
514 * @param pVM VM Handle.
515 * @param pcb Where to store the size of the hypervisor area. (out)
516 * @thread Any.
517 */
518MMDECL(RTGCPTR) MMHyperGetArea(PVM pVM, size_t *pcb);
519
520/**
521 * Checks if an address is within the hypervisor memory area.
522 *
523 * @returns true if inside.
524 * @returns false if outside.
525 * @param pVM VM handle.
526 * @param GCPtr The pointer to check.
527 * @thread The Emulation Thread.
528 */
529MMDECL(bool) MMHyperIsInsideArea(PVM pVM, RTGCPTR GCPtr);
530
531/**
532 * Convert a page in the page pool to a HC physical address.
533 * This works for pages allocated by MMR3PageAlloc(), MMR3PageAllocPhys()
534 * and MMR3PageAllocLow().
535 *
536 * @returns Physical address for the specified page table.
537 * @param pVM VM handle.
538 * @param pvPage Page which physical address we query.
539 * @thread The Emulation Thread.
540 */
541MMDECL(RTHCPHYS) MMPage2Phys(PVM pVM, void *pvPage);
542
543/**
544 * Convert physical address of a page to a HC virtual address.
545 * This works for pages allocated by MMR3PageAlloc(), MMR3PageAllocPhys()
546 * and MMR3PageAllocLow().
547 *
548 * @returns Pointer to the page at that physical address.
549 * @param pVM VM handle.
550 * @param HCPhysPage The physical address of a page.
551 * @thread The Emulation Thread.
552 */
553MMDECL(void *) MMPagePhys2Page(PVM pVM, RTHCPHYS HCPhysPage);
554
555
556/**
557 * Convert physical address of a page to a HC virtual address.
558 * This works for pages allocated by MMR3PageAlloc(), MMR3PageAllocPhys()
559 * and MMR3PageAllocLow().
560 *
561 * @returns VBox status code.
562 * @param pVM VM handle.
563 * @param HCPhysPage The physical address of a page.
564 * @param ppvPage Where to store the address corresponding to HCPhysPage.
565 * @thread The Emulation Thread.
566 */
567MMDECL(int) MMPagePhys2PageEx(PVM pVM, RTHCPHYS HCPhysPage, void **ppvPage);
568
569
570/**
571 * Try convert physical address of a page to a HC virtual address.
572 * This works for pages allocated by MMR3PageAlloc(), MMR3PageAllocPhys()
573 * and MMR3PageAllocLow().
574 *
575 * @returns VBox status code.
576 * @param pVM VM handle.
577 * @param HCPhysPage The physical address of a page.
578 * @param ppvPage Where to store the address corresponding to HCPhysPage.
579 * @thread The Emulation Thread.
580 */
581MMDECL(int) MMPagePhys2PageTry(PVM pVM, RTHCPHYS HCPhysPage, void **ppvPage);
582
583/**
584 * Convert GC physical address to HC virtual address.
585 *
586 * @returns HC virtual address.
587 * @param pVM VM Handle
588 * @param GCPhys Guest context physical address.
589 * @param cbRange Physical range
590 * @thread The Emulation Thread.
591 * @deprecated
592 */
593MMDECL(void *) MMPhysGCPhys2HCVirt(PVM pVM, RTGCPHYS GCPhys, RTUINT cbRange);
594
595
596/** @def MMHYPER_GC_ASSERT_GCPTR
597 * Asserts that an address is either NULL or inside the hypervisor memory area.
598 * This assertion only works while IN_GC, it's a NOP everywhere else.
599 * @thread The Emulation Thread.
600 */
601#ifdef IN_GC
602# define MMHYPER_GC_ASSERT_GCPTR(pVM, GCPtr) Assert(MMHyperIsInsideArea((pVM), (GCPtr)) || !(GCPtr))
603#else
604# define MMHYPER_GC_ASSERT_GCPTR(pVM, GCPtr) do { } while (0)
605#endif
606
607/** @} */
608
609
610#ifdef IN_RING3
611/** @defgroup grp_mm_r3 The MM Host Context Ring-3 API
612 * @ingroup grp_mm
613 * @{
614 */
615
616/**
617 * Initialization of MM (save anything depending on PGM).
618 *
619 * @returns VBox status code.
620 * @param pVM The VM to operate on.
621 * @thread The Emulation Thread.
622 */
623MMR3DECL(int) MMR3Init(PVM pVM);
624
625/**
626 * Initializes the MM parts which depends on PGM being initialized.
627 *
628 * @returns VBox status code.
629 * @param pVM The VM to operate on.
630 * @thread The Emulation Thread.
631 */
632MMR3DECL(int) MMR3InitPaging(PVM pVM);
633
634/**
635 * Finalizes the HMA mapping.
636 *
637 * This is called later during init, most (all) HMA allocations should be done
638 * by the time this function is called.
639 *
640 * @returns VBox status.
641 */
642MMR3DECL(int) MMR3HyperInitFinalize(PVM pVM);
643
644/**
645 * Terminates the MM.
646 *
647 * Termination means cleaning up and freeing all resources,
648 * the VM it self is at this point powered off or suspended.
649 *
650 * @returns VBox status code.
651 * @param pVM The VM to operate on.
652 * @thread The Emulation Thread.
653 */
654MMR3DECL(int) MMR3Term(PVM pVM);
655
656/**
657 * Reset notification.
658 *
659 * MM will reload shadow ROMs into RAM at this point and make
660 * the ROM writable.
661 *
662 * @param pVM The VM handle.
663 */
664MMR3DECL(void) MMR3Reset(PVM pVM);
665
666/**
667 * Convert HC Physical address to HC Virtual address.
668 *
669 * @returns VBox status.
670 * @param pVM VM handle.
671 * @param HCPhys The host context virtual address.
672 * @param ppv Where to store the resulting address.
673 * @thread The Emulation Thread.
674 */
675MMR3DECL(int) MMR3HCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys, void **ppv);
676
677/**
678 * Read memory from GC virtual address using the current guest CR3.
679 *
680 * @returns VBox status.
681 * @param pVM VM handle.
682 * @param pvDst Destination address (HC of course).
683 * @param GCPtr GC virtual address.
684 * @param cb Number of bytes to read.
685 * @thread The Emulation Thread.
686 */
687MMR3DECL(int) MMR3ReadGCVirt(PVM pVM, void *pvDst, RTGCPTR GCPtr, size_t cb);
688
689/**
690 * Write to memory at GC virtual address translated using the current guest CR3.
691 *
692 * @returns VBox status.
693 * @param pVM VM handle.
694 * @param GCPtrDst GC virtual address.
695 * @param pvSrc The source address (HC of course).
696 * @param cb Number of bytes to read.
697 */
698MMR3DECL(int) MMR3WriteGCVirt(PVM pVM, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
699
700
701/** @defgroup grp_mm_r3_hyper Hypervisor Memory Manager (HC R3 Portion)
702 * @ingroup grp_mm_r3
703 * @{ */
704/**
705 * Allocates memory in the Hypervisor (GC VMM) area which never will
706 * be freed and don't have any offset based relation to other heap blocks.
707 *
708 * The latter means that two blocks allocated by this API will not have the
709 * same relative position to each other in GC and HC. In short, never use
710 * this API for allocating nodes for an offset based AVL tree!
711 *
712 * The returned memory is of course zeroed.
713 *
714 * @returns VBox status code.
715 * @param pVM The VM to operate on.
716 * @param cb Number of bytes to allocate.
717 * @param uAlignment Required memory alignment in bytes.
718 * Values are 0,8,16,32 and PAGE_SIZE.
719 * 0 -> default alignment, i.e. 8 bytes.
720 * @param enmTag The statistics tag.
721 * @param ppv Where to store the address to the allocated
722 * memory.
723 * @remark This is assumed not to be used at times when serialization is required.
724 */
725MMDECL(int) MMR3HyperAllocOnceNoRel(PVM pVM, size_t cb, uint32_t uAlignment, MMTAG enmTag, void **ppv);
726
727/**
728 * Maps contiguous HC physical memory into the hypervisor region in the GC.
729 *
730 * @return VBox status code.
731 *
732 * @param pVM VM handle.
733 * @param pvHC Host context address of the memory. Must be page aligned!
734 * @param HCPhys Host context physical address of the memory to be mapped. Must be page aligned!
735 * @param cb Size of the memory. Will be rounded up to nearest page.
736 * @param pszDesc Description.
737 * @param pGCPtr Where to store the GC address.
738 * @thread The Emulation Thread.
739 */
740MMR3DECL(int) MMR3HyperMapHCPhys(PVM pVM, void *pvHC, RTHCPHYS HCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr);
741
742/**
743 * Maps contiguous GC physical memory into the hypervisor region in the GC.
744 *
745 * @return VBox status code.
746 *
747 * @param pVM VM handle.
748 * @param GCPhys Guest context physical address of the memory to be mapped. Must be page aligned!
749 * @param cb Size of the memory. Will be rounded up to nearest page.
750 * @param pszDesc Mapping description.
751 * @param pGCPtr Where to store the GC address.
752 * @thread The Emulation Thread.
753 */
754MMR3DECL(int) MMR3HyperMapGCPhys(PVM pVM, RTGCPHYS GCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr);
755
756/**
757 * Locks and Maps HC virtual memory into the hypervisor region in the GC.
758 *
759 * @return VBox status code.
760 *
761 * @param pVM VM handle.
762 * @param pvHC Host context address of the memory (may be not page aligned).
763 * @param cb Size of the memory. Will be rounded up to nearest page.
764 * @param fFree Set this if MM is responsible for freeing the memory using SUPPageFree.
765 * @param pszDesc Mapping description.
766 * @param pGCPtr Where to store the GC address corresponding to pvHC.
767 * @thread The Emulation Thread.
768 */
769MMR3DECL(int) MMR3HyperMapHCRam(PVM pVM, void *pvHC, size_t cb, bool fFree, const char *pszDesc, PRTGCPTR pGCPtr);
770
771/**
772 * Maps locked R3 virtual memory into the hypervisor region in the GC.
773 *
774 * @return VBox status code.
775 *
776 * @param pVM VM handle.
777 * @param pvR3 The ring-3 address of the memory, must be page aligned.
778 * @param pvR0 The ring-0 address of the memory, must be page aligned. (optional)
779 * @param cPages The number of pages.
780 * @param paPages The page descriptors.
781 * @param pszDesc Mapping description.
782 * @param pGCPtr Where to store the GC address corresponding to pvHC.
783 */
784MMR3DECL(int) MMR3HyperMapPages(PVM pVM, void *pvR3, RTR0PTR pvR0, size_t cPages, PCSUPPAGE paPages, const char *pszDesc, PRTGCPTR pGCPtr);
785
786/**
787 * Reserves a hypervisor memory area.
788 * Most frequent usage is fence pages and dynamically mappings like the guest PD and PDPTR.
789 *
790 * @return VBox status code.
791 *
792 * @param pVM VM handle.
793 * @param cb Size of the memory. Will be rounded up to nearest page.
794 * @param pszDesc Mapping description.
795 * @param pGCPtr Where to store the assigned GC address. Optional.
796 * @thread The Emulation Thread.
797 */
798MMR3DECL(int) MMR3HyperReserve(PVM pVM, unsigned cb, const char *pszDesc, PRTGCPTR pGCPtr);
799
800
801/**
802 * Convert hypervisor HC virtual address to HC physical address.
803 *
804 * @returns HC physical address.
805 * @param pVM VM Handle
806 * @param pvHC Host context physical address.
807 * @thread The Emulation Thread.
808 */
809MMR3DECL(RTHCPHYS) MMR3HyperHCVirt2HCPhys(PVM pVM, void *pvHC);
810/**
811 * Convert hypervisor HC virtual address to HC physical address.
812 *
813 * @returns HC physical address.
814 * @param pVM VM Handle
815 * @param pvHC Host context physical address.
816 * @param pHCPhys Where to store the HC physical address.
817 * @thread The Emulation Thread.
818 */
819MMR3DECL(int) MMR3HyperHCVirt2HCPhysEx(PVM pVM, void *pvHC, PRTHCPHYS pHCPhys);
820/**
821 * Convert hypervisor HC physical address to HC virtual address.
822 *
823 * @returns HC virtual address.
824 * @param pVM VM Handle
825 * @param HCPhys Host context physical address.
826 * @thread The Emulation Thread.
827 */
828MMR3DECL(void *) MMR3HyperHCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys);
829/**
830 * Convert hypervisor HC physical address to HC virtual address.
831 *
832 * @returns VBox status.
833 * @param pVM VM Handle
834 * @param HCPhys Host context physical address.
835 * @param ppv Where to store the HC virtual address.
836 * @thread The Emulation Thread.
837 */
838MMR3DECL(int) MMR3HyperHCPhys2HCVirtEx(PVM pVM, RTHCPHYS HCPhys, void **ppv);
839
840/**
841 * Read hypervisor memory from GC virtual address.
842 *
843 * @returns VBox status.
844 * @param pVM VM handle.
845 * @param pvDst Destination address (HC of course).
846 * @param GCPtr GC virtual address.
847 * @param cb Number of bytes to read.
848 * @thread The Emulation Thread.
849 */
850MMR3DECL(int) MMR3HyperReadGCVirt(PVM pVM, void *pvDst, RTGCPTR GCPtr, size_t cb);
851
852/** @} */
853
854
855/** @defgroup grp_mm_phys Guest Physical Memory Manager
856 * @ingroup grp_mm_r3
857 * @{ */
858
859/**
860 * Register externally allocated RAM for the virtual machine.
861 *
862 * The memory registered with the VM thru this interface must not be freed
863 * before the virtual machine has been destroyed. Bad things may happen... :-)
864 *
865 * @return VBox status code.
866 * @param pVM VM handle.
867 * @param pvRam Virtual address of the guest's physical memory range Must be page aligned.
868 * @param GCPhys The physical address the ram shall be registered at.
869 * @param cb Size of the memory. Must be page aligend.
870 * @param fFlags Flags of the MM_RAM_FLAGS_* defines.
871 * @param pszDesc Description of the memory.
872 * @thread The Emulation Thread.
873 */
874MMR3DECL(int) MMR3PhysRegister(PVM pVM, void *pvRam, RTGCPHYS GCPhys, unsigned cb, unsigned fFlags, const char *pszDesc);
875
876/**
877 * Register externally allocated RAM for the virtual machine.
878 *
879 * The memory registered with the VM thru this interface must not be freed
880 * before the virtual machine has been destroyed. Bad things may happen... :-)
881 *
882 * @return VBox status code.
883 * @param pVM VM handle.
884 * @param pvRam Virtual address of the guest's physical memory range Must be page aligned.
885 * @param GCPhys The physical address the ram shall be registered at.
886 * @param cb Size of the memory. Must be page aligend.
887 * @param fFlags Flags of the MM_RAM_FLAGS_* defines.
888 * @param enmType Physical range type (MM_PHYS_TYPE_*)
889 * @param pszDesc Description of the memory.
890 * @thread The Emulation Thread.
891 * @todo update this description.
892 */
893MMR3DECL(int) MMR3PhysRegisterEx(PVM pVM, void *pvRam, RTGCPHYS GCPhys, unsigned cb, unsigned fFlags, MMPHYSREG enmType, const char *pszDesc);
894
895/**
896 * Register previously registered externally allocated RAM for the virtual machine.
897 *
898 * Use this only for MMIO ranges or the guest will become very confused.
899 * The memory registered with the VM thru this interface must not be freed
900 * before the virtual machine has been destroyed. Bad things may happen... :-)
901 *
902 * @return VBox status code.
903 * @param pVM VM handle.
904 * @param GCPhysOld The physical address the ram was registered at.
905 * @param GCPhysNew The physical address the ram shall be registered at.
906 * @param cb Size of the memory. Must be page aligend.
907 * @thread The Emulation Thread.
908 */
909MMR3DECL(int) MMR3PhysRelocate(PVM pVM, RTGCPHYS GCPhysOld, RTGCPHYS GCPhysNew, unsigned cb);
910
911/**
912 * Register a ROM (BIOS) region.
913 *
914 * It goes without saying that this is read-only memory. The memory region must be
915 * in unassigned memory. I.e. from the top of the address space or on the PC in
916 * the 0xa0000-0xfffff range.
917 *
918 * @returns VBox status.
919 * @param pVM VM Handle.
920 * @param pDevIns The device instance owning the ROM region.
921 * @param GCPhys First physical address in the range.
922 * Must be page aligned!
923 * @param cbRange The size of the range (in bytes).
924 * Must be page aligned!
925 * @param pvBinary Pointer to the binary data backing the ROM image.
926 * This must be cbRange bytes big.
927 * It will be copied and doesn't have to stick around.
928 * It will be copied and doesn't have to stick around if fShadow is clear.
929 * @param fShadow Whether to emulate ROM shadowing. This involves leaving
930 * the ROM writable for a while during the POST and refreshing
931 * it at reset. When this flag is set, the memory pointed to by
932 * pvBinary has to stick around for the lifespan of the VM.
933 * @param pszDesc Pointer to description string. This must not be freed.
934 * @remark There is no way to remove the rom, automatically on device cleanup or
935 * manually from the device yet. At present I doubt we need such features...
936 * @thread The Emulation Thread.
937 */
938MMR3DECL(int) MMR3PhysRomRegister(PVM pVM, PPDMDEVINS pDevIns, RTGCPHYS GCPhys, RTUINT cbRange, const void *pvBinary, bool fShadow, const char *pszDesc);
939
940/**
941 * Write-protects a shadow ROM range.
942 *
943 * This is called late in the POST for shadow ROM ranges.
944 *
945 * @returns VBox status code.
946 * @param pVM The VM handle.
947 * @param GCPhys Start of the registered shadow ROM range
948 * @param cbRange The length of the registered shadow ROM range.
949 * This can be NULL (not sure about the BIOS interface yet).
950 */
951MMR3DECL(int) MMR3PhysRomProtect(PVM pVM, RTGCPHYS GCPhys, RTUINT cbRange);
952
953/**
954 * Reserve physical address space for ROM and MMIO ranges.
955 *
956 * @returns VBox status code.
957 * @param pVM VM Handle.
958 * @param GCPhys Start physical address.
959 * @param cbRange The size of the range.
960 * @param pszDesc Description string.
961 * @thread The Emulation Thread.
962 */
963MMR3DECL(int) MMR3PhysReserve(PVM pVM, RTGCPHYS GCPhys, RTUINT cbRange, const char *pszDesc);
964
965/**
966 * Get the size of the base RAM.
967 * This usually means the size of the first contigous block of physical memory.
968 *
969 * @returns
970 * @param pVM
971 * @thread Any.
972 */
973MMR3DECL(uint64_t) MMR3PhysGetRamSize(PVM pVM);
974
975
976/** @} */
977
978
979/** @defgroup grp_mm_page Physical Page Pool
980 * @ingroup grp_mm_r3
981 * @{ */
982/**
983 * Allocates a page from the page pool.
984 *
985 * This function may returns pages which has physical addresses any
986 * where. If you require a page to be within the first 4GB of physical
987 * memory, use MMR3PageAllocLow().
988 *
989 * @returns Pointer to the allocated page page.
990 * @returns NULL on failure.
991 * @param pVM VM handle.
992 * @thread The Emulation Thread.
993 */
994MMR3DECL(void *) MMR3PageAlloc(PVM pVM);
995
996/**
997 * Allocates a page from the page pool and return its physical address.
998 *
999 * This function may returns pages which has physical addresses any
1000 * where. If you require a page to be within the first 4GB of physical
1001 * memory, use MMR3PageAllocLow().
1002 *
1003 * @returns Pointer to the allocated page page.
1004 * @returns NIL_RTHCPHYS on failure.
1005 * @param pVM VM handle.
1006 * @thread The Emulation Thread.
1007 */
1008MMR3DECL(RTHCPHYS) MMR3PageAllocPhys(PVM pVM);
1009
1010/**
1011 * Frees a page allocated from the page pool by MMR3PageAlloc() and MMR3PageAllocPhys().
1012 *
1013 * @param pVM VM handle.
1014 * @param pvPage Pointer to the page.
1015 * @thread The Emulation Thread.
1016 */
1017MMR3DECL(void) MMR3PageFree(PVM pVM, void *pvPage);
1018
1019/**
1020 * Allocates a page from the low page pool.
1021 *
1022 * @returns Pointer to the allocated page.
1023 * @returns NULL on failure.
1024 * @param pVM VM handle.
1025 * @thread The Emulation Thread.
1026 */
1027MMR3DECL(void *) MMR3PageAllocLow(PVM pVM);
1028
1029/**
1030 * Frees a page allocated from the page pool by MMR3PageAllocLow().
1031 *
1032 * @param pVM VM handle.
1033 * @param pvPage Pointer to the page.
1034 * @thread The Emulation Thread.
1035 */
1036MMR3DECL(void) MMR3PageFreeLow(PVM pVM, void *pvPage);
1037
1038/**
1039 * Free a page allocated from the page pool by physical address.
1040 * This works for pages allocated by MMR3PageAlloc(), MMR3PageAllocPhys()
1041 * and MMR3PageAllocLow().
1042 *
1043 * @param pVM VM handle.
1044 * @param HCPhysPage The physical address of the page to be freed.
1045 * @thread The Emulation Thread.
1046 */
1047MMR3DECL(void) MMR3PageFreeByPhys(PVM pVM, RTHCPHYS HCPhysPage);
1048
1049/**
1050 * Gets the HC pointer to the dummy page.
1051 *
1052 * The dummy page is used as a place holder to prevent potential bugs
1053 * from doing really bad things to the system.
1054 *
1055 * @returns Pointer to the dummy page.
1056 * @param pVM VM handle.
1057 * @thread The Emulation Thread.
1058 */
1059MMR3DECL(void *) MMR3PageDummyHCPtr(PVM pVM);
1060
1061/**
1062 * Gets the HC Phys to the dummy page.
1063 *
1064 * The dummy page is used as a place holder to prevent potential bugs
1065 * from doing really bad things to the system.
1066 *
1067 * @returns Pointer to the dummy page.
1068 * @param pVM VM handle.
1069 * @thread The Emulation Thread.
1070 */
1071MMR3DECL(RTHCPHYS) MMR3PageDummyHCPhys(PVM pVM);
1072
1073
1074#if 1 /* these are temporary wrappers and will be removed soon */
1075/**
1076 * Allocates a Page Table.
1077 *
1078 * @returns Pointer to page table.
1079 * @returns NULL on failure.
1080 * @param pVM VM handle.
1081 * @deprecated Use MMR3PageAlloc().
1082 */
1083DECLINLINE(PVBOXPT) MMR3PTAlloc(PVM pVM)
1084{
1085 return (PVBOXPT)MMR3PageAlloc(pVM);
1086}
1087
1088/**
1089 * Free a Page Table.
1090 *
1091 * @param pVM VM handle.
1092 * @param pPT Pointer to the page table as returned by MMR3PTAlloc().
1093 * @deprecated Use MMR3PageFree().
1094 */
1095DECLINLINE(void) MMR3PTFree(PVM pVM, PVBOXPT pPT)
1096{
1097 MMR3PageFree(pVM, pPT);
1098}
1099
1100/**
1101 * Free a Page Table by physical address.
1102 *
1103 * @param pVM VM handle.
1104 * @param HCPhysPT The physical address of the page table to be freed.
1105 * @deprecated Use MMR3PageFreeByPhys().
1106 */
1107DECLINLINE(void) MMR3PTFreeByPhys(PVM pVM, RTHCPHYS HCPhysPT)
1108{
1109 MMR3PageFreeByPhys(pVM, HCPhysPT);
1110}
1111
1112/**
1113 * Convert a Page Table address to a HC physical address.
1114 *
1115 * @returns Physical address for the specified page table.
1116 * @param pVM VM handle.
1117 * @param pPT Page table which physical address we query.
1118 * @deprecated Use MMR3Page2Phys().
1119 */
1120DECLINLINE(RTHCPHYS) MMR3PT2Phys(PVM pVM, PVBOXPT pPT)
1121{
1122 return MMPage2Phys(pVM, pPT);
1123}
1124
1125/**
1126 * Convert a physical address to a page table address
1127 *
1128 * @returns Pointer to the page table at that physical address.
1129 * @param pVM VM handle.
1130 * @param PhysPT Page table which physical address we query.
1131 * @deprecated Use MMR3PagePhys2Page().
1132 */
1133DECLINLINE(PVBOXPT) MMR3Phys2PT(PVM pVM, RTHCPHYS PhysPT)
1134{
1135 return (PVBOXPT)MMPagePhys2Page(pVM, PhysPT);
1136}
1137
1138/**
1139 * Allocate a Page Directory.
1140 *
1141 * @returns Pointer to the page directory.
1142 * @returns NULL on failure.
1143 * @param pVM VM handle.
1144 * @deprecated Use MMR3PageAlloc().
1145 */
1146DECLINLINE(PVBOXPD) MMR3PDAlloc(PVM pVM)
1147{
1148 return (PVBOXPD)MMR3PageAlloc(pVM);
1149}
1150
1151/**
1152 * Free a Page Directory.
1153 *
1154 * @param pVM VM handle.
1155 * @param pPD Pointer to the page directory allocated by MMR3PDAlloc().
1156 * @deprecated Use MMR3PageFree().
1157 */
1158DECLINLINE(void) MMR3PDFree(PVM pVM, PVBOXPD pPD)
1159{
1160 MMR3PageFree(pVM, pPD);
1161}
1162
1163/**
1164 * Convert a Page Directory address to a physical address.
1165 *
1166 * @returns Physical address for the specified page directory.
1167 * @param pVM VM handle.
1168 * @param pPD Page directory which physical address we query.
1169 * Allocated by MMR3PDAlloc().
1170 * @deprecated Use MMR3Page2Phys().
1171 */
1172DECLINLINE(RTHCPHYS) MMR3PD2Phys(PVM pVM, PVBOXPD pPD)
1173{
1174 return MMPage2Phys(pVM, pPD);
1175}
1176
1177/**
1178 * Convert a physical address to a page directory address
1179 *
1180 * @returns Pointer to the page directory at that physical address.
1181 * @param pVM VM handle.
1182 * @param PhysPD Physical address of page directory.
1183 * Allocated by MMR3PDAlloc().
1184 * @deprecated Use MMR3PageAlloc().
1185 */
1186DECLINLINE(PVBOXPD) MMR3Phys2PD(PVM pVM, RTHCPHYS PhysPD)
1187{
1188 return (PVBOXPD)MMPagePhys2Page(pVM, PhysPD);
1189}
1190
1191/** @deprecated */
1192DECLINLINE(void *) MMR3DummyPageHCPtr(PVM pVM) { return MMR3PageDummyHCPtr(pVM); }
1193/** @deprecated */
1194DECLINLINE(RTHCPHYS) MMR3DummyPageHCPhys(PVM pVM) { return MMR3PageDummyHCPhys(pVM); }
1195
1196#endif /* will be removed */
1197
1198/** @} */
1199
1200
1201/** @defgroup grp_mm_heap Heap Manager
1202 * @ingroup grp_mm_r3
1203 * @{ */
1204
1205/**
1206 * Allocate memory associating it with the VM for collective cleanup.
1207 *
1208 * The memory will be allocated from the default heap but a header
1209 * is added in which we keep track of which VM it belongs to and chain
1210 * all the allocations together so they can be freed in a one go.
1211 *
1212 * This interface is typically used for memory block which will not be
1213 * freed during the life of the VM.
1214 *
1215 * @returns Pointer to allocated memory.
1216 * @param pVM VM handle.
1217 * @param enmTag Statistics tag. Statistics are collected on a per tag
1218 * basis in addition to a global one. Thus we can easily
1219 * identify how memory is used by the VM.
1220 * @param cbSize Size of the block.
1221 * @thread Any thread.
1222 */
1223MMR3DECL(void *) MMR3HeapAlloc(PVM pVM, MMTAG enmTag, size_t cbSize);
1224
1225/**
1226 * Same as MMR3HeapAlloc().
1227 *
1228 *
1229 * @returns Pointer to allocated memory.
1230 * @param pVM VM handle.
1231 * @param enmTag Statistics tag. Statistics are collected on a per tag
1232 * basis in addition to a global one. Thus we can easily
1233 * identify how memory is used by the VM.
1234 * @param cbSize Size of the block.
1235 * @param ppv Where to store the pointer to the allocated memory on success.
1236 * @thread Any thread.
1237 */
1238MMR3DECL(int) MMR3HeapAllocEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
1239
1240/**
1241 * Same as MMR3HeapAlloc() only the memory is zeroed.
1242 *
1243 *
1244 * @returns Pointer to allocated memory.
1245 * @param pVM VM handle.
1246 * @param enmTag Statistics tag. Statistics are collected on a per tag
1247 * basis in addition to a global one. Thus we can easily
1248 * identify how memory is used by the VM.
1249 * @param cbSize Size of the block.
1250 * @thread Any thread.
1251 */
1252MMR3DECL(void *) MMR3HeapAllocZ(PVM pVM, MMTAG enmTag, size_t cbSize);
1253
1254/**
1255 * Same as MMR3HeapAllocZ().
1256 *
1257 *
1258 * @returns Pointer to allocated memory.
1259 * @param pVM VM handle.
1260 * @param enmTag Statistics tag. Statistics are collected on a per tag
1261 * basis in addition to a global one. Thus we can easily
1262 * identify how memory is used by the VM.
1263 * @param cbSize Size of the block.
1264 * @param ppv Where to store the pointer to the allocated memory on success.
1265 * @thread Any thread.
1266 */
1267MMR3DECL(int) MMR3HeapAllocZEx(PVM pVM, MMTAG enmTag, size_t cbSize, void **ppv);
1268
1269/**
1270 * Reallocate memory allocated with MMR3HeapAlloc() or MMR3HeapRealloc().
1271 *
1272 * @returns Pointer to reallocated memory.
1273 * @param pv Pointer to the memory block to reallocate.
1274 * Must not be NULL!
1275 * @param cbNewSize New block size.
1276 * @thread Any thread.
1277 */
1278MMR3DECL(void *) MMR3HeapRealloc(void *pv, size_t cbNewSize);
1279
1280/**
1281 * Duplicates the specified string.
1282 *
1283 * @returns Pointer to the duplicate.
1284 * @returns NULL on failure or when input NULL.
1285 * @param pVM The VM handle.
1286 * @param enmTag Statistics tag. Statistics are collected on a per tag
1287 * basis in addition to a global one. Thus we can easily
1288 * identify how memory is used by the VM.
1289 * @param psz The string to duplicate. NULL is allowed.
1290 */
1291MMR3DECL(char *) MMR3HeapStrDup(PVM pVM, MMTAG enmTag, const char *psz);
1292
1293/**
1294 * Releases memory allocated with MMR3HeapAlloc() or MMR3HeapRealloc().
1295 *
1296 * @param pv Pointer to the memory block to free.
1297 * @thread Any thread.
1298 */
1299MMR3DECL(void) MMR3HeapFree(void *pv);
1300
1301/** @} */
1302
1303/** @} */
1304#endif
1305
1306
1307
1308#ifdef IN_GC
1309/** @defgroup grp_mm_gc The MM Guest Context API
1310 * @ingroup grp_mm
1311 * @{
1312 */
1313
1314/**
1315 * Install MMGCRam Hypervisor page fault handler for normal working
1316 * of MMGCRamRead and MMGCRamWrite calls.
1317 * This handler will be automatically removed at page fault.
1318 * In other case it must be removed by MMGCRamDeregisterTrapHandler call.
1319 *
1320 * @param pVM VM handle.
1321 */
1322MMGCDECL(void) MMGCRamRegisterTrapHandler(PVM pVM);
1323
1324/**
1325 * Remove MMGCRam Hypervisor page fault handler.
1326 * See description of MMGCRamRegisterTrapHandler call.
1327 *
1328 * @param pVM VM handle.
1329 */
1330MMGCDECL(void) MMGCRamDeregisterTrapHandler(PVM pVM);
1331
1332/**
1333 * Read data in guest context with \#PF control.
1334 * MMRamGC page fault handler must be installed prior this call for safe operation.
1335 * Use MMGCRamRegisterTrapHandler() call for this task.
1336 *
1337 * @returns VBox status.
1338 * @param pDst Where to store the readed data.
1339 * @param pSrc Pointer to the data to read.
1340 * @param cb Size of data to read, only 1/2/4/8 is valid.
1341 */
1342MMGCDECL(int) MMGCRamReadNoTrapHandler(void *pDst, void *pSrc, size_t cb);
1343
1344/**
1345 * Write data in guest context with \#PF control.
1346 * MMRamGC page fault handler must be installed prior this call for safe operation.
1347 * Use MMGCRamRegisterTrapHandler() call for this task.
1348 *
1349 * @returns VBox status.
1350 * @param pDst Where to write the data.
1351 * @param pSrc Pointer to the data to write.
1352 * @param cb Size of data to write, only 1/2/4 is valid.
1353 */
1354MMGCDECL(int) MMGCRamWriteNoTrapHandler(void *pDst, void *pSrc, size_t cb);
1355
1356/**
1357 * Read data in guest context with \#PF control.
1358 *
1359 * @returns VBox status.
1360 * @param pVM The VM handle.
1361 * @param pDst Where to store the readed data.
1362 * @param pSrc Pointer to the data to read.
1363 * @param cb Size of data to read, only 1/2/4/8 is valid.
1364 */
1365MMGCDECL(int) MMGCRamRead(PVM pVM, void *pDst, void *pSrc, size_t cb);
1366
1367/**
1368 * Write data in guest context with \#PF control.
1369 *
1370 * @returns VBox status.
1371 * @param pVM The VM handle.
1372 * @param pDst Where to write the data.
1373 * @param pSrc Pointer to the data to write.
1374 * @param cb Size of data to write, only 1/2/4 is valid.
1375 */
1376MMGCDECL(int) MMGCRamWrite(PVM pVM, void *pDst, void *pSrc, size_t cb);
1377
1378/** @} */
1379#endif
1380
1381/** @} */
1382__END_DECLS
1383
1384
1385#endif
1386
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