VirtualBox

source: vbox/trunk/src/VBox/VMM/MMHyper.cpp@ 13813

Last change on this file since 13813 was 13796, checked in by vboxsync, 16 years ago

VMM: some adjustments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 40.4 KB
Line 
1/* $Id: MMHyper.cpp 13796 2008-11-04 18:37:33Z vboxsync $ */
2/** @file
3 * MM - Memory Manager - Hypervisor Memory Area.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_MM_HYPER
27#include <VBox/pgm.h>
28#include <VBox/mm.h>
29#include <VBox/dbgf.h>
30#include "MMInternal.h"
31#include <VBox/vm.h>
32#include <VBox/err.h>
33#include <VBox/param.h>
34#include <VBox/log.h>
35#include <iprt/alloc.h>
36#include <iprt/assert.h>
37#include <iprt/string.h>
38
39
40/*******************************************************************************
41* Internal Functions *
42*******************************************************************************/
43static DECLCALLBACK(bool) mmR3HyperRelocateCallback(PVM pVM, RTGCPTR GCPtrOld, RTGCPTR GCPtrNew, PGMRELOCATECALL enmMode, void *pvUser);
44static int mmR3HyperMap(PVM pVM, const size_t cb, const char *pszDesc, PRTGCPTR pGCPtr, PMMLOOKUPHYPER *ppLookup);
45static int mmR3HyperHeapCreate(PVM pVM, const size_t cb, PMMHYPERHEAP *ppHeap);
46static int mmR3HyperHeapMap(PVM pVM, PMMHYPERHEAP pHeap, PRTGCPTR ppHeapGC);
47static DECLCALLBACK(void) mmR3HyperInfoHma(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs);
48
49
50
51
52/**
53 * Initializes the hypvervisor related MM stuff without
54 * calling down to PGM.
55 *
56 * PGM is not initialized at this point, PGM relies on
57 * the heap to initialize.
58 *
59 * @returns VBox status.
60 */
61int mmR3HyperInit(PVM pVM)
62{
63 LogFlow(("mmR3HyperInit:\n"));
64
65 /*
66 * Decide Hypervisor mapping in the guest context
67 * And setup various hypervisor area and heap parameters.
68 */
69 pVM->mm.s.pvHyperAreaGC = (RTGCPTR)MM_HYPER_AREA_ADDRESS;
70 pVM->mm.s.cbHyperArea = MM_HYPER_AREA_MAX_SIZE;
71 AssertRelease(RT_ALIGN_T(pVM->mm.s.pvHyperAreaGC, 1 << X86_PD_SHIFT, RTGCPTR) == pVM->mm.s.pvHyperAreaGC);
72 Assert(pVM->mm.s.pvHyperAreaGC < 0xff000000);
73
74 /** @todo @bugref{1865}, @bugref{3202}: Change the cbHyperHeap default
75 * depending on whether VT-x/AMD-V is enabled or not! Don't waste
76 * precious kernel space on heap for the PATM. */
77 uint32_t cbHyperHeap;
78 int rc = CFGMR3QueryU32(CFGMR3GetChild(CFGMR3GetRoot(pVM), "MM"), "cbHyperHeap", &cbHyperHeap);
79 if (rc == VERR_CFGM_NO_PARENT || rc == VERR_CFGM_VALUE_NOT_FOUND)
80 cbHyperHeap = 1280*_1K;
81 else if (VBOX_FAILURE(rc))
82 {
83 LogRel(("MM/cbHyperHeap query -> %Vrc\n", rc));
84 AssertRCReturn(rc, rc);
85 }
86 cbHyperHeap = RT_ALIGN_32(cbHyperHeap, PAGE_SIZE);
87
88 /*
89 * Allocate the hypervisor heap.
90 *
91 * (This must be done before we start adding memory to the
92 * hypervisor static area because lookup records are allocated from it.)
93 */
94 rc = mmR3HyperHeapCreate(pVM, cbHyperHeap, &pVM->mm.s.pHyperHeapR3);
95 if (VBOX_SUCCESS(rc))
96 {
97 pVM->mm.s.pHyperHeapR0 = (uintptr_t)pVM->mm.s.pHyperHeapR3; /** @todo #1865: map into ring-0 / whatever. */
98
99 /*
100 * Make a small head fence to fend of accidental sequential access.
101 */
102 MMR3HyperReserve(pVM, PAGE_SIZE, "fence", NULL);
103
104 /*
105 * Map the VM structure into the hypervisor space.
106 */
107 AssertRelease(pVM->cbSelf == RT_UOFFSETOF(VM, aCpus[pVM->cCPUs]));
108 RTGCPTR GCPtr;
109 rc = MMR3HyperMapPages(pVM, pVM, pVM->pVMR0, RT_ALIGN_Z(pVM->cbSelf, PAGE_SIZE) >> PAGE_SHIFT, pVM->paVMPagesR3, "VM", &GCPtr);
110 if (VBOX_SUCCESS(rc))
111 {
112 pVM->pVMRC = (RTGCPTR32)GCPtr;
113 pVM->pVMGC = pVM->pVMRC;
114 for (uint32_t i = 0; i < pVM->cCPUs; i++)
115 pVM->aCpus[i].pVMRC = pVM->pVMRC;
116
117 /* Reserve a page for fencing. */
118 MMR3HyperReserve(pVM, PAGE_SIZE, "fence", NULL);
119
120 /*
121 * Map the heap into the hypervisor space.
122 */
123 rc = mmR3HyperHeapMap(pVM, pVM->mm.s.pHyperHeapR3, &GCPtr);
124 if (VBOX_SUCCESS(rc))
125 {
126 pVM->mm.s.pHyperHeapRC = (RTRCPTR)GCPtr;
127 Assert(pVM->mm.s.pHyperHeapRC == GCPtr);
128
129 /*
130 * Register info handlers.
131 */
132 DBGFR3InfoRegisterInternal(pVM, "hma", "Show the layout of the Hypervisor Memory Area.", mmR3HyperInfoHma);
133
134 LogFlow(("mmR3HyperInit: returns VINF_SUCCESS\n"));
135 return VINF_SUCCESS;
136 }
137 /* Caller will do proper cleanup. */
138 }
139 }
140
141 LogFlow(("mmR3HyperInit: returns %Vrc\n", rc));
142 return rc;
143}
144
145
146/**
147 * Finalizes the HMA mapping.
148 *
149 * This is called later during init, most (all) HMA allocations should be done
150 * by the time this function is called.
151 *
152 * @returns VBox status.
153 */
154VMMR3DECL(int) MMR3HyperInitFinalize(PVM pVM)
155{
156 LogFlow(("MMR3HyperInitFinalize:\n"));
157
158 /*
159 * Adjust and create the HMA mapping.
160 */
161 while ((RTINT)pVM->mm.s.offHyperNextStatic + 64*_1K < (RTINT)pVM->mm.s.cbHyperArea - _4M)
162 pVM->mm.s.cbHyperArea -= _4M;
163 int rc = PGMR3MapPT(pVM, pVM->mm.s.pvHyperAreaGC, pVM->mm.s.cbHyperArea,
164 mmR3HyperRelocateCallback, NULL, "Hypervisor Memory Area");
165 if (VBOX_FAILURE(rc))
166 return rc;
167 pVM->mm.s.fPGMInitialized = true;
168
169 /*
170 * Do all the delayed mappings.
171 */
172 PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((uintptr_t)pVM->mm.s.pHyperHeapR3 + pVM->mm.s.offLookupHyper);
173 for (;;)
174 {
175 RTGCPTR GCPtr = pVM->mm.s.pvHyperAreaGC + pLookup->off;
176 unsigned cPages = pLookup->cb >> PAGE_SHIFT;
177 switch (pLookup->enmType)
178 {
179 case MMLOOKUPHYPERTYPE_LOCKED:
180 rc = mmR3MapLocked(pVM, pLookup->u.Locked.pLockedMem, GCPtr, 0, cPages, 0);
181 break;
182
183 case MMLOOKUPHYPERTYPE_HCPHYS:
184 rc = PGMMap(pVM, GCPtr, pLookup->u.HCPhys.HCPhys, pLookup->cb, 0);
185 break;
186
187 case MMLOOKUPHYPERTYPE_GCPHYS:
188 {
189 const RTGCPHYS GCPhys = pLookup->u.GCPhys.GCPhys;
190 const size_t cb = pLookup->cb;
191 for (unsigned off = 0; off < cb; off += PAGE_SIZE)
192 {
193 RTHCPHYS HCPhys;
194 rc = PGMPhysGCPhys2HCPhys(pVM, GCPhys + off, &HCPhys);
195 if (VBOX_FAILURE(rc))
196 break;
197 rc = PGMMap(pVM, GCPtr + off, HCPhys, PAGE_SIZE, 0);
198 if (VBOX_FAILURE(rc))
199 break;
200 }
201 break;
202 }
203
204 case MMLOOKUPHYPERTYPE_MMIO2:
205 {
206 const RTGCPHYS offEnd = pLookup->u.MMIO2.off + pLookup->cb;
207 for (RTGCPHYS offCur = pLookup->u.MMIO2.off; offCur < offEnd; offCur += PAGE_SIZE)
208 {
209 RTHCPHYS HCPhys;
210 rc = PGMR3PhysMMIO2GetHCPhys(pVM, pLookup->u.MMIO2.pDevIns, pLookup->u.MMIO2.iRegion, offCur, &HCPhys);
211 if (RT_FAILURE(rc))
212 break;
213 rc = PGMMap(pVM, GCPtr + (offCur - pLookup->u.MMIO2.off), HCPhys, PAGE_SIZE, 0);
214 if (RT_FAILURE(rc))
215 break;
216 }
217 break;
218 }
219
220 case MMLOOKUPHYPERTYPE_DYNAMIC:
221 /* do nothing here since these are either fences or managed by someone else using PGM. */
222 break;
223
224 default:
225 AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
226 break;
227 }
228
229 if (VBOX_FAILURE(rc))
230 {
231 AssertMsgFailed(("rc=%Vrc cb=%d GCPtr=%VGv enmType=%d pszDesc=%s\n",
232 rc, pLookup->cb, pLookup->enmType, pLookup->pszDesc));
233 return rc;
234 }
235
236 /* next */
237 if (pLookup->offNext == (int32_t)NIL_OFFSET)
238 break;
239 pLookup = (PMMLOOKUPHYPER)((uintptr_t)pLookup + pLookup->offNext);
240 }
241
242 LogFlow(("MMR3HyperInitFinalize: returns VINF_SUCCESS\n"));
243 return VINF_SUCCESS;
244}
245
246
247/**
248 * Callback function which will be called when PGM is trying to find
249 * a new location for the mapping.
250 *
251 * The callback is called in two modes, 1) the check mode and 2) the relocate mode.
252 * In 1) the callback should say if it objects to a suggested new location. If it
253 * accepts the new location, it is called again for doing it's relocation.
254 *
255 *
256 * @returns true if the location is ok.
257 * @returns false if another location should be found.
258 * @param pVM The VM handle.
259 * @param GCPtrOld The old virtual address.
260 * @param GCPtrNew The new virtual address.
261 * @param enmMode Used to indicate the callback mode.
262 * @param pvUser User argument. Ignored.
263 * @remark The return value is no a failure indicator, it's an acceptance
264 * indicator. Relocation can not fail!
265 */
266static DECLCALLBACK(bool) mmR3HyperRelocateCallback(PVM pVM, RTGCPTR GCPtrOld, RTGCPTR GCPtrNew, PGMRELOCATECALL enmMode, void *pvUser)
267{
268 switch (enmMode)
269 {
270 /*
271 * Verify location - all locations are good for us.
272 */
273 case PGMRELOCATECALL_SUGGEST:
274 return true;
275
276 /*
277 * Execute the relocation.
278 */
279 case PGMRELOCATECALL_RELOCATE:
280 {
281 /*
282 * Accepted!
283 */
284 AssertMsg(GCPtrOld == pVM->mm.s.pvHyperAreaGC, ("GCPtrOld=%VGv pVM->mm.s.pvHyperAreaGC=%VGv\n", GCPtrOld, pVM->mm.s.pvHyperAreaGC));
285 Log(("Relocating the hypervisor from %VGv to %VGv\n", GCPtrOld, GCPtrNew));
286
287 /*
288 * Relocate the VM structure and ourselves.
289 */
290 RTGCINTPTR offDelta = GCPtrNew - GCPtrOld;
291 pVM->pVMRC += offDelta;
292 pVM->pVMGC = pVM->pVMRC;
293 for (uint32_t i = 0; i < pVM->cCPUs; i++)
294 pVM->aCpus[i].pVMRC = pVM->pVMRC;
295
296 pVM->mm.s.pvHyperAreaGC += offDelta;
297 Assert(pVM->mm.s.pvHyperAreaGC < _4G);
298 pVM->mm.s.pHyperHeapRC += offDelta;
299 pVM->mm.s.pHyperHeapR3->pbHeapRC += offDelta;
300 pVM->mm.s.pHyperHeapR3->pVMRC = pVM->pVMRC;
301
302 /*
303 * Relocate the rest.
304 */
305 VMR3Relocate(pVM, offDelta);
306 return true;
307 }
308
309 default:
310 AssertMsgFailed(("Invalid relocation mode %d\n", enmMode));
311 }
312
313 return false;
314}
315
316
317/**
318 * Maps contiguous HC physical memory into the hypervisor region in the GC.
319 *
320 * @return VBox status code.
321 *
322 * @param pVM VM handle.
323 * @param pvR3 Host context address of the memory. Must be page
324 * aligned!
325 * @param HCPhys Host context physical address of the memory to be
326 * mapped. Must be page aligned!
327 * @param cb Size of the memory. Will be rounded up to nearest page.
328 * @param pszDesc Description.
329 * @param pGCPtr Where to store the GC address.
330 */
331VMMR3DECL(int) MMR3HyperMapHCPhys(PVM pVM, void *pvR3, RTHCPHYS HCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr)
332{
333 LogFlow(("MMR3HyperMapHCPhys: pvR3=%p HCPhys=%RHp cb=%d pszDesc=%p:{%s} pGCPtr=%p\n", pvR3, HCPhys, (int)cb, pszDesc, pszDesc, pGCPtr));
334
335 /*
336 * Validate input.
337 */
338 AssertReturn(RT_ALIGN_P(pvR3, PAGE_SIZE) == pvR3, VERR_INVALID_PARAMETER);
339 AssertReturn(RT_ALIGN_T(HCPhys, PAGE_SIZE, RTHCPHYS) == HCPhys, VERR_INVALID_PARAMETER);
340 AssertReturn(pszDesc && *pszDesc, VERR_INVALID_PARAMETER);
341
342 /*
343 * Add the memory to the hypervisor area.
344 */
345 uint32_t cbAligned = RT_ALIGN_32(cb, PAGE_SIZE);
346 AssertReturn(cbAligned >= cb, VERR_INVALID_PARAMETER);
347 RTGCPTR GCPtr;
348 PMMLOOKUPHYPER pLookup;
349 int rc = mmR3HyperMap(pVM, cbAligned, pszDesc, &GCPtr, &pLookup);
350 if (VBOX_SUCCESS(rc))
351 {
352 pLookup->enmType = MMLOOKUPHYPERTYPE_HCPHYS;
353 pLookup->u.HCPhys.pvR3 = pvR3;
354 pLookup->u.HCPhys.HCPhys = HCPhys;
355
356 /*
357 * Update the page table.
358 */
359 if (pVM->mm.s.fPGMInitialized)
360 rc = PGMMap(pVM, GCPtr, HCPhys, cbAligned, 0);
361 if (VBOX_SUCCESS(rc))
362 *pGCPtr = GCPtr;
363 }
364 return rc;
365}
366
367
368/**
369 * Maps contiguous GC physical memory into the hypervisor region in the GC.
370 *
371 * @return VBox status code.
372 *
373 * @param pVM VM handle.
374 * @param GCPhys Guest context physical address of the memory to be mapped. Must be page aligned!
375 * @param cb Size of the memory. Will be rounded up to nearest page.
376 * @param pszDesc Mapping description.
377 * @param pGCPtr Where to store the GC address.
378 */
379VMMR3DECL(int) MMR3HyperMapGCPhys(PVM pVM, RTGCPHYS GCPhys, size_t cb, const char *pszDesc, PRTGCPTR pGCPtr)
380{
381 LogFlow(("MMR3HyperMapGCPhys: GCPhys=%VGp cb=%d pszDesc=%p:{%s} pGCPtr=%p\n", GCPhys, (int)cb, pszDesc, pszDesc, pGCPtr));
382
383 /*
384 * Validate input.
385 */
386 AssertReturn(RT_ALIGN_T(GCPhys, PAGE_SIZE, RTGCPHYS) == GCPhys, VERR_INVALID_PARAMETER);
387 AssertReturn(pszDesc && *pszDesc, VERR_INVALID_PARAMETER);
388
389 /*
390 * Add the memory to the hypervisor area.
391 */
392 cb = RT_ALIGN_Z(cb, PAGE_SIZE);
393 RTGCPTR GCPtr;
394 PMMLOOKUPHYPER pLookup;
395 int rc = mmR3HyperMap(pVM, cb, pszDesc, &GCPtr, &pLookup);
396 if (VBOX_SUCCESS(rc))
397 {
398 pLookup->enmType = MMLOOKUPHYPERTYPE_GCPHYS;
399 pLookup->u.GCPhys.GCPhys = GCPhys;
400
401 /*
402 * Update the page table.
403 */
404 for (unsigned off = 0; off < cb; off += PAGE_SIZE)
405 {
406 RTHCPHYS HCPhys;
407 rc = PGMPhysGCPhys2HCPhys(pVM, GCPhys + off, &HCPhys);
408 AssertRC(rc);
409 if (VBOX_FAILURE(rc))
410 {
411 AssertMsgFailed(("rc=%Vrc GCPhys=%VGv off=%#x %s\n", rc, GCPhys, off, pszDesc));
412 break;
413 }
414 if (pVM->mm.s.fPGMInitialized)
415 {
416 rc = PGMMap(pVM, GCPtr + off, HCPhys, PAGE_SIZE, 0);
417 AssertRC(rc);
418 if (VBOX_FAILURE(rc))
419 {
420 AssertMsgFailed(("rc=%Vrc GCPhys=%VGv off=%#x %s\n", rc, GCPhys, off, pszDesc));
421 break;
422 }
423 }
424 }
425
426 if (VBOX_SUCCESS(rc) && pGCPtr)
427 *pGCPtr = GCPtr;
428 }
429 return rc;
430}
431
432
433/**
434 * Maps a portion of an MMIO2 region into the hypervisor region.
435 *
436 * Callers of this API must never deregister the MMIO2 region before the
437 * VM is powered off. If this becomes a requirement MMR3HyperUnmapMMIO2
438 * API will be needed to perform cleanups.
439 *
440 * @return VBox status code.
441 *
442 * @param pVM Pointer to the shared VM structure.
443 * @param pDevIns The device owning the MMIO2 memory.
444 * @param iRegion The region.
445 * @param off The offset into the region. Will be rounded down to closest page boundrary.
446 * @param cb The number of bytes to map. Will be rounded up to the closest page boundrary.
447 * @param pszDesc Mapping description.
448 * @param pRCPtr Where to store the RC address.
449 */
450VMMR3DECL(int) MMR3HyperMapMMIO2(PVM pVM, PPDMDEVINS pDevIns, uint32_t iRegion, RTGCPHYS off, RTGCPHYS cb,
451 const char *pszDesc, PRTRCPTR pRCPtr)
452{
453 LogFlow(("MMR3HyperMapMMIO2: pDevIns=%p iRegion=%#x off=%VGp cb=%VGp pszDesc=%p:{%s} pRCPtr=%p\n",
454 pDevIns, iRegion, off, cb, pszDesc, pszDesc, pRCPtr));
455 int rc;
456
457 /*
458 * Validate input.
459 */
460 AssertReturn(pszDesc && *pszDesc, VERR_INVALID_PARAMETER);
461 AssertReturn(off + cb > off, VERR_INVALID_PARAMETER);
462 uint32_t const offPage = off & PAGE_OFFSET_MASK;
463 off &= ~(RTGCPHYS)PAGE_OFFSET_MASK;
464 cb += offPage;
465 cb = RT_ALIGN_Z(cb, PAGE_SIZE);
466 const RTGCPHYS offEnd = off + cb;
467 AssertReturn(offEnd > off, VERR_INVALID_PARAMETER);
468 for (RTGCPHYS offCur = off; offCur < offEnd; offCur += PAGE_SIZE)
469 {
470 RTHCPHYS HCPhys;
471 rc = PGMR3PhysMMIO2GetHCPhys(pVM, pDevIns, iRegion, offCur, &HCPhys);
472 AssertMsgRCReturn(rc, ("rc=%Rrc - iRegion=%d off=%RGp\n", rc, iRegion, off), rc);
473 }
474
475 /*
476 * Add the memory to the hypervisor area.
477 */
478 RTGCPTR GCPtr;
479 PMMLOOKUPHYPER pLookup;
480 rc = mmR3HyperMap(pVM, cb, pszDesc, &GCPtr, &pLookup);
481 if (VBOX_SUCCESS(rc))
482 {
483 pLookup->enmType = MMLOOKUPHYPERTYPE_MMIO2;
484 pLookup->u.MMIO2.pDevIns = pDevIns;
485 pLookup->u.MMIO2.iRegion = iRegion;
486 pLookup->u.MMIO2.off = off;
487
488 /*
489 * Update the page table.
490 */
491 if (pVM->mm.s.fPGMInitialized)
492 {
493 for (RTGCPHYS offCur = off; offCur < offEnd; offCur += PAGE_SIZE)
494 {
495 RTHCPHYS HCPhys;
496 rc = PGMR3PhysMMIO2GetHCPhys(pVM, pDevIns, iRegion, offCur, &HCPhys);
497 AssertRCReturn(rc, VERR_INTERNAL_ERROR);
498 rc = PGMMap(pVM, GCPtr + (offCur - off), HCPhys, PAGE_SIZE, 0);
499 if (VBOX_FAILURE(rc))
500 {
501 AssertMsgFailed(("rc=%Vrc offCur=%RGp %s\n", rc, offCur, pszDesc));
502 break;
503 }
504 }
505 }
506
507 if (VBOX_SUCCESS(rc))
508 {
509 GCPtr |= offPage;
510 *pRCPtr = GCPtr;
511 AssertLogRelReturn(*pRCPtr == GCPtr, VERR_INTERNAL_ERROR);
512 }
513 }
514 return rc;
515}
516
517
518/**
519 * Locks and Maps HC virtual memory into the hypervisor region in the GC.
520 *
521 * @return VBox status code.
522 *
523 * @param pVM VM handle.
524 * @param pvR3 Host context address of the memory (may be not page
525 * aligned).
526 * @param cb Size of the memory. Will be rounded up to nearest page.
527 * @param fFree Set this if MM is responsible for freeing the memory
528 * using SUPPageFree.
529 * @param pszDesc Mapping description.
530 * @param pGCPtr Where to store the GC address corresponding to pvR3.
531 */
532VMMR3DECL(int) MMR3HyperMapHCRam(PVM pVM, void *pvR3, size_t cb, bool fFree, const char *pszDesc, PRTGCPTR pGCPtr)
533{
534 LogFlow(("MMR3HyperMapHCRam: pvR3=%p cb=%d fFree=%d pszDesc=%p:{%s} pGCPtr=%p\n", pvR3, (int)cb, fFree, pszDesc, pszDesc, pGCPtr));
535
536 /*
537 * Validate input.
538 */
539 if ( !pvR3
540 || cb <= 0
541 || !pszDesc
542 || !*pszDesc)
543 {
544 AssertMsgFailed(("Invalid parameter\n"));
545 return VERR_INVALID_PARAMETER;
546 }
547
548 /*
549 * Page align address and size.
550 */
551 void *pvR3Page = (void *)((uintptr_t)pvR3 & PAGE_BASE_HC_MASK);
552 cb += (uintptr_t)pvR3 & PAGE_OFFSET_MASK;
553 cb = RT_ALIGN_Z(cb, PAGE_SIZE);
554
555 /*
556 * Add the memory to the hypervisor area.
557 */
558 RTGCPTR GCPtr;
559 PMMLOOKUPHYPER pLookup;
560 int rc = mmR3HyperMap(pVM, cb, pszDesc, &GCPtr, &pLookup);
561 if (VBOX_SUCCESS(rc))
562 {
563 /*
564 * Lock the heap memory and tell PGM about the locked pages.
565 */
566 PMMLOCKEDMEM pLockedMem;
567 rc = mmR3LockMem(pVM, pvR3Page, cb, fFree ? MM_LOCKED_TYPE_HYPER : MM_LOCKED_TYPE_HYPER_NOFREE, &pLockedMem, false /* fSilentFailure */);
568 if (VBOX_SUCCESS(rc))
569 {
570 /* map the stuff into guest address space. */
571 if (pVM->mm.s.fPGMInitialized)
572 rc = mmR3MapLocked(pVM, pLockedMem, GCPtr, 0, ~(size_t)0, 0);
573 if (VBOX_SUCCESS(rc))
574 {
575 pLookup->enmType = MMLOOKUPHYPERTYPE_LOCKED;
576 pLookup->u.Locked.pvR3 = pvR3;
577 pLookup->u.Locked.pvR0 = NIL_RTR0PTR;
578 pLookup->u.Locked.pLockedMem = pLockedMem;
579
580 /* done. */
581 GCPtr |= (uintptr_t)pvR3 & PAGE_OFFSET_MASK;
582 *pGCPtr = GCPtr;
583 return rc;
584 }
585 /* Don't care about failure clean, we're screwed if this fails anyway. */
586 }
587 }
588
589 return rc;
590}
591
592
593/**
594 * Maps locked R3 virtual memory into the hypervisor region in the GC.
595 *
596 * @return VBox status code.
597 *
598 * @param pVM VM handle.
599 * @param pvR3 The ring-3 address of the memory, must be page aligned.
600 * @param pvR0 The ring-0 address of the memory, must be page aligned. (optional)
601 * @param cPages The number of pages.
602 * @param paPages The page descriptors.
603 * @param pszDesc Mapping description.
604 * @param pGCPtr Where to store the GC address corresponding to pvR3.
605 */
606VMMR3DECL(int) MMR3HyperMapPages(PVM pVM, void *pvR3, RTR0PTR pvR0, size_t cPages, PCSUPPAGE paPages, const char *pszDesc, PRTGCPTR pGCPtr)
607{
608 LogFlow(("MMR3HyperMapPages: pvR3=%p pvR0=%p cPages=%zu paPages=%p pszDesc=%p:{%s} pGCPtr=%p\n",
609 pvR3, pvR0, cPages, paPages, pszDesc, pszDesc, pGCPtr));
610
611 /*
612 * Validate input.
613 */
614 AssertPtrReturn(pvR3, VERR_INVALID_POINTER);
615 AssertPtrReturn(paPages, VERR_INVALID_POINTER);
616 AssertReturn(cPages > 0, VERR_INVALID_PARAMETER);
617 AssertReturn(cPages < 1024, VERR_INVALID_PARAMETER);
618 AssertPtrReturn(pszDesc, VERR_INVALID_POINTER);
619 AssertReturn(*pszDesc, VERR_INVALID_PARAMETER);
620 AssertPtrReturn(pGCPtr, VERR_INVALID_PARAMETER);
621
622 /*
623 * Add the memory to the hypervisor area.
624 */
625 RTGCPTR GCPtr;
626 PMMLOOKUPHYPER pLookup;
627 int rc = mmR3HyperMap(pVM, cPages << PAGE_SHIFT, pszDesc, &GCPtr, &pLookup);
628 if (VBOX_SUCCESS(rc))
629 {
630 /*
631 * Create a locked memory record and tell PGM about this.
632 */
633 PMMLOCKEDMEM pLockedMem = (PMMLOCKEDMEM)MMR3HeapAlloc(pVM, MM_TAG_MM, RT_OFFSETOF(MMLOCKEDMEM, aPhysPages[cPages]));
634 if (pLockedMem)
635 {
636 pLockedMem->pv = pvR3;
637 pLockedMem->cb = cPages << PAGE_SHIFT;
638 pLockedMem->eType = MM_LOCKED_TYPE_HYPER_PAGES;
639 memset(&pLockedMem->u, 0, sizeof(pLockedMem->u));
640 for (size_t i = 0; i < cPages; i++)
641 {
642 AssertReleaseReturn(paPages[i].Phys != 0 && paPages[i].Phys != NIL_RTHCPHYS && !(paPages[i].Phys & PAGE_OFFSET_MASK), VERR_INTERNAL_ERROR);
643 pLockedMem->aPhysPages[i].Phys = paPages[i].Phys;
644 pLockedMem->aPhysPages[i].uReserved = (RTHCUINTPTR)pLockedMem;
645 }
646
647 /* map the stuff into guest address space. */
648 if (pVM->mm.s.fPGMInitialized)
649 rc = mmR3MapLocked(pVM, pLockedMem, GCPtr, 0, ~(size_t)0, 0);
650 if (VBOX_SUCCESS(rc))
651 {
652 pLookup->enmType = MMLOOKUPHYPERTYPE_LOCKED;
653 pLookup->u.Locked.pvR3 = pvR3;
654 pLookup->u.Locked.pvR0 = pvR0;
655 pLookup->u.Locked.pLockedMem = pLockedMem;
656
657 /* done. */
658 *pGCPtr = GCPtr;
659 return rc;
660 }
661 /* Don't care about failure clean, we're screwed if this fails anyway. */
662 }
663 }
664
665 return rc;
666}
667
668
669/**
670 * Reserves a hypervisor memory area.
671 * Most frequent usage is fence pages and dynamically mappings like the guest PD and PDPT.
672 *
673 * @return VBox status code.
674 *
675 * @param pVM VM handle.
676 * @param cb Size of the memory. Will be rounded up to nearest page.
677 * @param pszDesc Mapping description.
678 * @param pGCPtr Where to store the assigned GC address. Optional.
679 */
680VMMR3DECL(int) MMR3HyperReserve(PVM pVM, unsigned cb, const char *pszDesc, PRTGCPTR pGCPtr)
681{
682 LogFlow(("MMR3HyperMapHCRam: cb=%d pszDesc=%p:{%s} pGCPtr=%p\n", (int)cb, pszDesc, pszDesc, pGCPtr));
683
684 /*
685 * Validate input.
686 */
687 if ( cb <= 0
688 || !pszDesc
689 || !*pszDesc)
690 {
691 AssertMsgFailed(("Invalid parameter\n"));
692 return VERR_INVALID_PARAMETER;
693 }
694
695 /*
696 * Add the memory to the hypervisor area.
697 */
698 RTGCPTR GCPtr;
699 PMMLOOKUPHYPER pLookup;
700 int rc = mmR3HyperMap(pVM, cb, pszDesc, &GCPtr, &pLookup);
701 if (VBOX_SUCCESS(rc))
702 {
703 pLookup->enmType = MMLOOKUPHYPERTYPE_DYNAMIC;
704 if (pGCPtr)
705 *pGCPtr = GCPtr;
706 return VINF_SUCCESS;
707 }
708 return rc;
709}
710
711
712/**
713 * Adds memory to the hypervisor memory arena.
714 *
715 * @return VBox status code.
716 * @param pVM The VM handle.
717 * @param cb Size of the memory. Will be rounded up to neares page.
718 * @param pszDesc The description of the memory.
719 * @param pGCPtr Where to store the GC address.
720 * @param ppLookup Where to store the pointer to the lookup record.
721 * @remark We assume the threading structure of VBox imposes natural
722 * serialization of most functions, this one included.
723 */
724static int mmR3HyperMap(PVM pVM, const size_t cb, const char *pszDesc, PRTGCPTR pGCPtr, PMMLOOKUPHYPER *ppLookup)
725{
726 /*
727 * Validate input.
728 */
729 const uint32_t cbAligned = RT_ALIGN(cb, PAGE_SIZE);
730 AssertReturn(cbAligned >= cb, VERR_INVALID_PARAMETER);
731 if (pVM->mm.s.offHyperNextStatic + cbAligned >= pVM->mm.s.cbHyperArea) /* don't use the last page, it's a fence. */
732 {
733 AssertMsgFailed(("Out of static mapping space in the HMA! offHyperAreaGC=%x cbAligned=%x\n",
734 pVM->mm.s.offHyperNextStatic, cbAligned));
735 return VERR_NO_MEMORY;
736 }
737
738 /*
739 * Allocate lookup record.
740 */
741 PMMLOOKUPHYPER pLookup;
742 int rc = MMHyperAlloc(pVM, sizeof(*pLookup), 1, MM_TAG_MM, (void **)&pLookup);
743 if (VBOX_SUCCESS(rc))
744 {
745 /*
746 * Initialize it and insert it.
747 */
748 pLookup->offNext = pVM->mm.s.offLookupHyper;
749 pLookup->cb = cbAligned;
750 pLookup->off = pVM->mm.s.offHyperNextStatic;
751 pVM->mm.s.offLookupHyper = (uint8_t *)pLookup - (uint8_t *)pVM->mm.s.pHyperHeapR3;
752 if (pLookup->offNext != (int32_t)NIL_OFFSET)
753 pLookup->offNext -= pVM->mm.s.offLookupHyper;
754 pLookup->enmType = MMLOOKUPHYPERTYPE_INVALID;
755 memset(&pLookup->u, 0xff, sizeof(pLookup->u));
756 pLookup->pszDesc = pszDesc;
757
758 /* Mapping. */
759 *pGCPtr = pVM->mm.s.pvHyperAreaGC + pVM->mm.s.offHyperNextStatic;
760 pVM->mm.s.offHyperNextStatic += cbAligned;
761
762 /* Return pointer. */
763 *ppLookup = pLookup;
764 }
765
766 AssertRC(rc);
767 LogFlow(("mmR3HyperMap: returns %Vrc *pGCPtr=%VGv\n", rc, *pGCPtr));
768 return rc;
769}
770
771
772/**
773 * Allocates a new heap.
774 *
775 * @returns VBox status code.
776 * @param pVM The VM handle.
777 * @param cb The size of the new heap.
778 * @param ppHeap Where to store the heap pointer on successful return.
779 */
780static int mmR3HyperHeapCreate(PVM pVM, const size_t cb, PMMHYPERHEAP *ppHeap)
781{
782 /*
783 * Allocate the hypervisor heap.
784 */
785 const uint32_t cbAligned = RT_ALIGN_Z(cb, PAGE_SIZE);
786 AssertReturn(cbAligned >= cb, VERR_INVALID_PARAMETER);
787 void *pv;
788 int rc = SUPPageAlloc(cbAligned >> PAGE_SHIFT, &pv); /** @todo #1865: heap allocation must be changed for osx (only). */
789 if (VBOX_SUCCESS(rc))
790 {
791 /*
792 * Initialize the heap and first free chunk.
793 */
794 PMMHYPERHEAP pHeap = (PMMHYPERHEAP)pv;
795 pHeap->u32Magic = MMHYPERHEAP_MAGIC;
796 pHeap->pbHeapR3 = (uint8_t *)pHeap + MMYPERHEAP_HDR_SIZE;
797 pHeap->pbHeapR0 = (uintptr_t)pHeap->pbHeapR3; /** @todo #1865: Map heap into ring-0 on darwin. */
798 //pHeap->pbHeapGC = 0; // set by mmR3HyperHeapMap()
799 pHeap->pVMR3 = pVM;
800 pHeap->pVMR0 = pVM->pVMR0;
801 pHeap->pVMRC = pVM->pVMRC;
802 pHeap->cbHeap = cbAligned - MMYPERHEAP_HDR_SIZE;
803 pHeap->cbFree = pHeap->cbHeap - sizeof(MMHYPERCHUNK);
804 //pHeap->offFreeHead = 0;
805 //pHeap->offFreeTail = 0;
806 pHeap->offPageAligned = pHeap->cbHeap;
807 //pHeap->HyperHeapStatTree = 0;
808
809 PMMHYPERCHUNKFREE pFree = (PMMHYPERCHUNKFREE)pHeap->pbHeapR3;
810 pFree->cb = pHeap->cbFree;
811 //pFree->core.offNext = 0;
812 MMHYPERCHUNK_SET_TYPE(&pFree->core, MMHYPERCHUNK_FLAGS_FREE);
813 pFree->core.offHeap = -(int32_t)MMYPERHEAP_HDR_SIZE;
814 //pFree->offNext = 0;
815 //pFree->offPrev = 0;
816
817 STAMR3Register(pVM, &pHeap->cbHeap, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, "/MM/HyperHeap/cbHeap", STAMUNIT_BYTES, "The heap size.");
818 STAMR3Register(pVM, &pHeap->cbFree, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, "/MM/HyperHeap/cbFree", STAMUNIT_BYTES, "The free space.");
819
820 *ppHeap = pHeap;
821 return VINF_SUCCESS;
822 }
823 AssertMsgFailed(("SUPPageAlloc(%d,) -> %Vrc\n", cbAligned >> PAGE_SHIFT, rc));
824
825 *ppHeap = NULL;
826 return rc;
827}
828
829
830/**
831 * Allocates a new heap.
832 */
833static int mmR3HyperHeapMap(PVM pVM, PMMHYPERHEAP pHeap, PRTGCPTR ppHeapGC)
834{
835 int rc = MMR3HyperMapHCRam(pVM, pHeap, pHeap->cbHeap + MMYPERHEAP_HDR_SIZE, true, "Heap", ppHeapGC);
836 if (VBOX_SUCCESS(rc))
837 {
838 pHeap->pVMRC = pVM->pVMRC;
839 pHeap->pbHeapRC = *ppHeapGC + MMYPERHEAP_HDR_SIZE;
840 /* Reserve a page for fencing. */
841 MMR3HyperReserve(pVM, PAGE_SIZE, "fence", NULL);
842 }
843 return rc;
844}
845
846
847#if 0
848/**
849 * Destroys a heap.
850 */
851static int mmR3HyperHeapDestroy(PVM pVM, PMMHYPERHEAP pHeap)
852{
853 /* all this is dealt with when unlocking and freeing locked memory. */
854}
855#endif
856
857
858/**
859 * Allocates memory in the Hypervisor (GC VMM) area which never will
860 * be freed and doesn't have any offset based relation to other heap blocks.
861 *
862 * The latter means that two blocks allocated by this API will not have the
863 * same relative position to each other in GC and HC. In short, never use
864 * this API for allocating nodes for an offset based AVL tree!
865 *
866 * The returned memory is of course zeroed.
867 *
868 * @returns VBox status code.
869 * @param pVM The VM to operate on.
870 * @param cb Number of bytes to allocate.
871 * @param uAlignment Required memory alignment in bytes.
872 * Values are 0,8,16,32 and PAGE_SIZE.
873 * 0 -> default alignment, i.e. 8 bytes.
874 * @param enmTag The statistics tag.
875 * @param ppv Where to store the address to the allocated
876 * memory.
877 * @remark This is assumed not to be used at times when serialization is required.
878 */
879VMMDECL(int) MMR3HyperAllocOnceNoRel(PVM pVM, size_t cb, unsigned uAlignment, MMTAG enmTag, void **ppv)
880{
881 AssertMsg(cb >= 8, ("Hey! Do you really mean to allocate less than 8 bytes?! cb=%d\n", cb));
882
883 /*
884 * Choose between allocating a new chunk of HMA memory
885 * and the heap. We will only do BIG allocations from HMA.
886 */
887 if ( cb < _64K
888 && ( uAlignment != PAGE_SIZE
889 || cb < 48*_1K))
890 {
891 int rc = MMHyperAlloc(pVM, cb, uAlignment, enmTag, ppv);
892 if ( rc != VERR_MM_HYPER_NO_MEMORY
893 || cb <= 8*_1K)
894 {
895 Log2(("MMR3HyperAllocOnceNoRel: cb=%#zx uAlignment=%#x returns %Rrc and *ppv=%p\n",
896 cb, uAlignment, rc, *ppv));
897 return rc;
898 }
899 }
900
901 /*
902 * Validate alignment.
903 */
904 switch (uAlignment)
905 {
906 case 0:
907 case 8:
908 case 16:
909 case 32:
910 case PAGE_SIZE:
911 break;
912 default:
913 AssertMsgFailed(("Invalid alignment %u\n", uAlignment));
914 return VERR_INVALID_PARAMETER;
915 }
916
917 /*
918 * Allocate the pages and the HMA space.
919 */
920 cb = RT_ALIGN(cb, PAGE_SIZE);
921 void *pvPages;
922 int rc = SUPPageAlloc(cb >> PAGE_SHIFT, &pvPages);
923 if (VBOX_SUCCESS(rc))
924 {
925 RTGCPTR GCPtr;
926 rc = MMR3HyperMapHCRam(pVM, pvPages, cb, true,
927 MMR3HeapAPrintf(pVM, MM_TAG_MM, "alloc once (%s)", mmR3GetTagName(enmTag)),
928 &GCPtr);
929 if (VBOX_SUCCESS(rc))
930 {
931 *ppv = pvPages;
932 Log2(("MMR3HyperAllocOnceNoRel: cb=%#x uAlignment=%#x returns VINF_SUCCESS and *ppv=%p\n",
933 cb, uAlignment, *ppv));
934 return rc;
935 }
936 AssertMsgFailed(("Failed to allocate %zd bytes! %Rrc\n", cb, rc));
937 SUPPageFree(pvPages, cb >> PAGE_SHIFT);
938
939 /*
940 * HACK ALERT! Try allocate it off the heap so that we don't freak
941 * out during vga/vmmdev mmio2 allocation with certain ram sizes.
942 */
943 /** @todo make a proper fix for this so we will never end up in this kind of situation! */
944 Log(("MMR3HyperAllocOnceNoRel: MMR3HyperMapHCRam failed with rc=%Rrc, try MMHyperAlloc(,%#d,,) instead\n", rc, cb));
945 int rc2 = MMHyperAlloc(pVM, cb, uAlignment, enmTag, ppv);
946 if (RT_SUCCESS(rc2))
947 {
948 Log2(("MMR3HyperAllocOnceNoRel: cb=%#x uAlignment=%#x returns %Rrc and *ppv=%p\n",
949 cb, uAlignment, rc, *ppv));
950 return rc;
951 }
952 }
953 else
954 AssertMsgFailed(("Failed to allocate %zd bytes! %Rrc\n", cb, rc));
955
956 if (rc == VERR_NO_MEMORY)
957 rc = VERR_MM_HYPER_NO_MEMORY;
958 LogRel(("MMR3HyperAllocOnceNoRel: cb=%#zx uAlignment=%#x returns %Rrc\n", cb, uAlignment, rc));
959 return rc;
960}
961
962
963/**
964 * Convert hypervisor HC virtual address to HC physical address.
965 *
966 * @returns HC physical address.
967 * @param pVM VM Handle
968 * @param pvR3 Host context virtual address.
969 */
970VMMR3DECL(RTHCPHYS) MMR3HyperHCVirt2HCPhys(PVM pVM, void *pvR3)
971{
972 PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((uint8_t *)pVM->mm.s.pHyperHeapR3 + pVM->mm.s.offLookupHyper);
973 for (;;)
974 {
975 switch (pLookup->enmType)
976 {
977 case MMLOOKUPHYPERTYPE_LOCKED:
978 {
979 unsigned off = (uint8_t *)pvR3 - (uint8_t *)pLookup->u.Locked.pvR3;
980 if (off < pLookup->cb)
981 return (pLookup->u.Locked.pLockedMem->aPhysPages[off >> PAGE_SHIFT].Phys & X86_PTE_PAE_PG_MASK) | (off & PAGE_OFFSET_MASK);
982 break;
983 }
984
985 case MMLOOKUPHYPERTYPE_HCPHYS:
986 {
987 unsigned off = (uint8_t *)pvR3 - (uint8_t *)pLookup->u.HCPhys.pvR3;
988 if (off < pLookup->cb)
989 return pLookup->u.HCPhys.HCPhys + off;
990 break;
991 }
992
993 case MMLOOKUPHYPERTYPE_GCPHYS:
994 case MMLOOKUPHYPERTYPE_MMIO2:
995 case MMLOOKUPHYPERTYPE_DYNAMIC:
996 /* can (or don't want to) convert these kind of records. */
997 break;
998
999 default:
1000 AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
1001 break;
1002 }
1003
1004 /* next */
1005 if ((unsigned)pLookup->offNext == NIL_OFFSET)
1006 break;
1007 pLookup = (PMMLOOKUPHYPER)((uint8_t *)pLookup + pLookup->offNext);
1008 }
1009
1010 AssertMsgFailed(("pvR3=%p is not inside the hypervisor memory area!\n", pvR3));
1011 return NIL_RTHCPHYS;
1012}
1013
1014
1015#if 0 /* unused, not implemented */
1016/**
1017 * Convert hypervisor HC physical address to HC virtual address.
1018 *
1019 * @returns HC virtual address.
1020 * @param pVM VM Handle
1021 * @param HCPhys Host context physical address.
1022 */
1023VMMR3DECL(void *) MMR3HyperHCPhys2HCVirt(PVM pVM, RTHCPHYS HCPhys)
1024{
1025 void *pv;
1026 int rc = MMR3HyperHCPhys2HCVirtEx(pVM, HCPhys, &pv);
1027 if (VBOX_SUCCESS(rc))
1028 return pv;
1029 AssertMsgFailed(("Invalid address HCPhys=%x rc=%d\n", HCPhys, rc));
1030 return NULL;
1031}
1032
1033
1034/**
1035 * Convert hypervisor HC physical address to HC virtual address.
1036 *
1037 * @returns VBox status.
1038 * @param pVM VM Handle
1039 * @param HCPhys Host context physical address.
1040 * @param ppv Where to store the HC virtual address.
1041 */
1042VMMR3DECL(int) MMR3HyperHCPhys2HCVirtEx(PVM pVM, RTHCPHYS HCPhys, void **ppv)
1043{
1044 /*
1045 * Linear search.
1046 */
1047 /** @todo implement when actually used. */
1048 return VERR_INVALID_POINTER;
1049}
1050#endif /* unused, not implemented */
1051
1052
1053/**
1054 * Read hypervisor memory from GC virtual address.
1055 *
1056 * @returns VBox status.
1057 * @param pVM VM handle.
1058 * @param pvDst Destination address (HC of course).
1059 * @param GCPtr GC virtual address.
1060 * @param cb Number of bytes to read.
1061 *
1062 * @remarks For DBGF only.
1063 */
1064VMMR3DECL(int) MMR3HyperReadGCVirt(PVM pVM, void *pvDst, RTGCPTR GCPtr, size_t cb)
1065{
1066 if (GCPtr - pVM->mm.s.pvHyperAreaGC >= pVM->mm.s.cbHyperArea)
1067 return VERR_INVALID_PARAMETER;
1068 return PGMR3MapRead(pVM, pvDst, GCPtr, cb);
1069}
1070
1071
1072/**
1073 * Info handler for 'hma', it dumps the list of lookup records for the hypervisor memory area.
1074 *
1075 * @param pVM The VM handle.
1076 * @param pHlp Callback functions for doing output.
1077 * @param pszArgs Argument string. Optional and specific to the handler.
1078 */
1079static DECLCALLBACK(void) mmR3HyperInfoHma(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
1080{
1081 pHlp->pfnPrintf(pHlp, "Hypervisor Memory Area (HMA) Layout: Base %VGv, 0x%08x bytes\n",
1082 pVM->mm.s.pvHyperAreaGC, pVM->mm.s.cbHyperArea);
1083
1084 PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((uint8_t *)pVM->mm.s.pHyperHeapR3 + pVM->mm.s.offLookupHyper);
1085 for (;;)
1086 {
1087 switch (pLookup->enmType)
1088 {
1089 case MMLOOKUPHYPERTYPE_LOCKED:
1090 pHlp->pfnPrintf(pHlp, "%VGv-%VGv %RHv LOCKED %-*s %s\n",
1091 pLookup->off + pVM->mm.s.pvHyperAreaGC,
1092 pLookup->off + pVM->mm.s.pvHyperAreaGC + pLookup->cb,
1093 pLookup->u.Locked.pvR3,
1094 sizeof(RTHCPTR) * 2,
1095 pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_HYPER_NOFREE ? "nofree"
1096 : pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_HYPER ? "autofree"
1097 : pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_HYPER_PAGES ? "pages"
1098 : pLookup->u.Locked.pLockedMem->eType == MM_LOCKED_TYPE_PHYS ? "gstphys"
1099 : "??",
1100 pLookup->pszDesc);
1101 break;
1102
1103 case MMLOOKUPHYPERTYPE_HCPHYS:
1104 pHlp->pfnPrintf(pHlp, "%VGv-%VGv %RHv HCPHYS %VHp %s\n",
1105 pLookup->off + pVM->mm.s.pvHyperAreaGC,
1106 pLookup->off + pVM->mm.s.pvHyperAreaGC + pLookup->cb,
1107 pLookup->u.HCPhys.pvR3, pLookup->u.HCPhys.HCPhys,
1108 pLookup->pszDesc);
1109 break;
1110
1111 case MMLOOKUPHYPERTYPE_GCPHYS:
1112 pHlp->pfnPrintf(pHlp, "%VGv-%VGv %*s GCPHYS %VGp%*s %s\n",
1113 pLookup->off + pVM->mm.s.pvHyperAreaGC,
1114 pLookup->off + pVM->mm.s.pvHyperAreaGC + pLookup->cb,
1115 sizeof(RTHCPTR) * 2, "",
1116 pLookup->u.GCPhys.GCPhys, RT_ABS((int)(sizeof(RTHCPHYS) - sizeof(RTGCPHYS))) * 2, "",
1117 pLookup->pszDesc);
1118 break;
1119
1120 case MMLOOKUPHYPERTYPE_MMIO2:
1121 pHlp->pfnPrintf(pHlp, "%VGv-%VGv %*s MMIO2 %VGp%*s %s\n",
1122 pLookup->off + pVM->mm.s.pvHyperAreaGC,
1123 pLookup->off + pVM->mm.s.pvHyperAreaGC + pLookup->cb,
1124 sizeof(RTHCPTR) * 2, "",
1125 pLookup->u.MMIO2.off, RT_ABS((int)(sizeof(RTHCPHYS) - sizeof(RTGCPHYS))) * 2, "",
1126 pLookup->pszDesc);
1127 break;
1128
1129 case MMLOOKUPHYPERTYPE_DYNAMIC:
1130 pHlp->pfnPrintf(pHlp, "%VGv-%VGv %*s DYNAMIC %*s %s\n",
1131 pLookup->off + pVM->mm.s.pvHyperAreaGC,
1132 pLookup->off + pVM->mm.s.pvHyperAreaGC + pLookup->cb,
1133 sizeof(RTHCPTR) * 2, "",
1134 sizeof(RTHCPTR) * 2, "",
1135 pLookup->pszDesc);
1136 break;
1137
1138 default:
1139 AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
1140 break;
1141 }
1142
1143 /* next */
1144 if ((unsigned)pLookup->offNext == NIL_OFFSET)
1145 break;
1146 pLookup = (PMMLOOKUPHYPER)((uint8_t *)pLookup + pLookup->offNext);
1147 }
1148}
1149
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