VirtualBox

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

Last change on this file since 4394 was 4388, checked in by vboxsync, 17 years ago

Shadow ROM emulation. Clear the RESERVED flag for ROM.

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