VirtualBox

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

Last change on this file since 5958 was 5811, checked in by vboxsync, 17 years ago

Add error codes and logging group for pdm async completion

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