VirtualBox

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

Last change on this file since 4693 was 4688, checked in by vboxsync, 17 years ago

MM_TAG_PGM_CHUNK_MAPPING.

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