VirtualBox

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

Last change on this file since 4337 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

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