VirtualBox

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

Last change on this file since 4675 was 4668, checked in by vboxsync, 17 years ago

Removed MMPhysGCVirt2HCVirt.

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