VirtualBox

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

Last change on this file since 19626 was 19608, checked in by vboxsync, 16 years ago

MMHyper.cpp: Extended release assertion with a message.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette