VirtualBox

source: vbox/trunk/src/VBox/VMM/PGMMap.cpp@ 1349

Last change on this file since 1349 was 914, checked in by vboxsync, 18 years ago

PVMR0 changes for darwin.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 39.0 KB
Line 
1/* $Id: PGMMap.cpp 914 2007-02-14 23:23:08Z vboxsync $ */
2/** @file
3 * PGM - Page Manager, Guest Context Mappings.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_PGM
27#include <VBox/dbgf.h>
28#include <VBox/pgm.h>
29#include "PGMInternal.h"
30#include <VBox/vm.h>
31
32#include <VBox/log.h>
33#include <VBox/err.h>
34#include <iprt/asm.h>
35#include <iprt/assert.h>
36#include <iprt/string.h>
37
38
39/*******************************************************************************
40* Internal Functions *
41*******************************************************************************/
42static void pgmR3MapClearPDEs(PPGM pPGM, PPGMMAPPING pMap, int iOldPDE);
43static void pgmR3MapSetPDEs(PVM pVM, PPGMMAPPING pMap, int iNewPDE);
44static DECLCALLBACK(int) pgmR3DumpMappingsPhysicalCB(PAVLROGCPHYSNODECORE pNode, void *pvUser);
45static int pgmR3MapIntermediateCheckOne(PVM pVM, uintptr_t uAddress, unsigned cPages, PX86PT pPTDefault, PX86PTPAE pPTPaeDefault);
46static void pgmR3MapIntermediateDoOne(PVM pVM, uintptr_t uAddress, RTHCPHYS HCPhys, unsigned cPages, PX86PT pPTDefault, PX86PTPAE pPTPaeDefault);
47
48
49
50/**
51 * Creates a page table based mapping in GC.
52 *
53 * @returns VBox status code.
54 * @param pVM VM Handle.
55 * @param GCPtr Virtual Address. (Page table aligned!)
56 * @param cb Size of the range. Must be a 4MB aligned!
57 * @param pfnRelocate Relocation callback function.
58 * @param pvUser User argument to the callback.
59 * @param pszDesc Pointer to description string. This must not be freed.
60 */
61PGMR3DECL(int) PGMR3MapPT(PVM pVM, RTGCPTR GCPtr, size_t cb, PFNPGMRELOCATE pfnRelocate, void *pvUser, const char *pszDesc)
62{
63 LogFlow(("PGMR3MapPT: GCPtr=%#x cb=%d pfnRelocate=%p pvUser=%p pszDesc=%s\n", GCPtr, cb, pfnRelocate, pvUser, pszDesc));
64 AssertMsg(pVM->pgm.s.pInterPD && pVM->pgm.s.pHC32BitPD, ("Paging isn't initialized, init order problems!\n"));
65
66 /*
67 * Validate input.
68 */
69 if (cb < _2M || cb > 64 * _1M)
70 {
71 AssertMsgFailed(("Serious? cb=%d\n", cb));
72 return VERR_INVALID_PARAMETER;
73 }
74 cb = RT_ALIGN_Z(cb, _4M);
75 RTGCPTR GCPtrLast = GCPtr + cb - 1;
76 if (GCPtrLast < GCPtr)
77 {
78 AssertMsgFailed(("Range wraps! GCPtr=%x GCPtrLast=%x\n", GCPtr, GCPtrLast));
79 return VERR_INVALID_PARAMETER;
80 }
81 if (pVM->pgm.s.fMappingsFixed)
82 {
83 AssertMsgFailed(("Mappings are fixed! It's not possible to add new mappings at this time!\n"));
84 return VERR_PGM_MAPPINGS_FIXED;
85 }
86 if (!pfnRelocate)
87 {
88 AssertMsgFailed(("Callback is required\n"));
89 return VERR_INVALID_PARAMETER;
90 }
91
92 /*
93 * Find list location.
94 */
95 PPGMMAPPING pPrev = NULL;
96 PPGMMAPPING pCur = pVM->pgm.s.pMappingsHC;
97 while (pCur)
98 {
99 if (pCur->GCPtrLast >= GCPtr && pCur->GCPtr <= GCPtrLast)
100 {
101 AssertMsgFailed(("Address is already in use by %s. req %#x-%#x take %#x-%#x\n",
102 pCur->pszDesc, GCPtr, GCPtrLast, pCur->GCPtr, pCur->GCPtrLast));
103 return VERR_PGM_MAPPING_CONFLICT;
104 }
105 if (pCur->GCPtr > GCPtr)
106 break;
107 pPrev = pCur;
108 pCur = pCur->pNextHC;
109 }
110/** @todo this needs fixing, the function must relocate on conflict, not fail! */
111
112 /*
113 * Check for conflicts with intermediate mappings.
114 */
115 const unsigned iPageDir = GCPtr >> PGDIR_SHIFT;
116 const unsigned cPTs = cb >> PGDIR_SHIFT;
117 unsigned i;
118 for (i = 0; i < cPTs; i++)
119 {
120 if (pVM->pgm.s.pInterPD->a[iPageDir + i].n.u1Present)
121 {
122 AssertMsgFailed(("Address %#x is already in use by an intermediate mapping.\n", GCPtr + (i << PAGE_SHIFT)));
123 return VERR_PGM_MAPPING_CONFLICT;
124 }
125 }
126 /** @todo AMD64: add check in PAE structures too, so we can remove all the 32-Bit paging stuff there. */
127
128 /*
129 * Allocate and initialize the new list node.
130 */
131 PPGMMAPPING pNew;
132 int rc = MMHyperAlloc(pVM, RT_OFFSETOF(PGMMAPPING, aPTs[cPTs]), 0, MM_TAG_PGM, (void **)&pNew);
133 if (VBOX_FAILURE(rc))
134 return rc;
135 pNew->GCPtr = GCPtr;
136 pNew->GCPtrLast = GCPtrLast;
137 pNew->cb = cb;
138 pNew->pszDesc = pszDesc;
139 pNew->pfnRelocate = pfnRelocate;
140 pNew->pvUser = pvUser;
141 pNew->cPTs = cPTs;
142
143 /*
144 * Allocate page tables and insert them into the page directories.
145 * (One 32-bit PT and two PAE PTs.)
146 */
147 uint8_t *pbPTs;
148 rc = MMHyperAlloc(pVM, PAGE_SIZE * 3 * cPTs, PAGE_SIZE, MM_TAG_PGM, (void **)&pbPTs);
149 if (VBOX_FAILURE(rc))
150 {
151 MMHyperFree(pVM, pNew);
152 return VERR_NO_MEMORY;
153 }
154
155 /*
156 * Init the page tables and insert them into the page directories.
157 */
158 Log4(("PGMR3MapPT: GCPtr=%VGv cPTs=%u pbPTs=%p\n", GCPtr, cPTs, pbPTs));
159 for (i = 0; i < cPTs; i++)
160 {
161 /*
162 * 32-bit.
163 */
164 pNew->aPTs[i].pPTHC = (PVBOXPT)pbPTs;
165 pNew->aPTs[i].pPTGC = MMHyperHC2GC(pVM, pNew->aPTs[i].pPTHC);
166 pNew->aPTs[i].HCPhysPT = MMR3HyperHCVirt2HCPhys(pVM, pNew->aPTs[i].pPTHC);
167 pbPTs += PAGE_SIZE;
168 Log4(("PGMR3MapPT: i=%d: pPTHC=%p pPTGC=%p HCPhysPT=%RHp\n",
169 i, pNew->aPTs[i].pPTHC, pNew->aPTs[i].pPTGC, pNew->aPTs[i].HCPhysPT));
170
171 /*
172 * PAE.
173 */
174 pNew->aPTs[i].HCPhysPaePT0 = MMR3HyperHCVirt2HCPhys(pVM, pbPTs);
175 pNew->aPTs[i].HCPhysPaePT1 = MMR3HyperHCVirt2HCPhys(pVM, pbPTs + PAGE_SIZE);
176 pNew->aPTs[i].paPaePTsHC = (PX86PTPAE)pbPTs;
177 pNew->aPTs[i].paPaePTsGC = MMHyperHC2GC(pVM, pbPTs);
178 pbPTs += PAGE_SIZE * 2;
179 Log4(("PGMR3MapPT: i=%d: paPaePTsHC=%p paPaePTsGC=%p HCPhysPaePT0=%RHp HCPhysPaePT1=%RHp\n",
180 i, pNew->aPTs[i].paPaePTsHC, pNew->aPTs[i].paPaePTsGC, pNew->aPTs[i].HCPhysPaePT0, pNew->aPTs[i].HCPhysPaePT1));
181 }
182 pgmR3MapSetPDEs(pVM, pNew, iPageDir);
183
184 /*
185 * Insert the new mapping.
186 */
187 pNew->pNextHC = pCur;
188 pNew->pNextGC = pCur ? MMHyperHC2GC(pVM, pCur) : 0;
189 if (pPrev)
190 {
191 pPrev->pNextHC = pNew;
192 pPrev->pNextGC = MMHyperHC2GC(pVM, pNew);
193 }
194 else
195 {
196 pVM->pgm.s.pMappingsHC = pNew;
197 pVM->pgm.s.pMappingsGC = MMHyperHC2GC(pVM, pNew);
198 }
199
200 VM_FF_SET(pVM, VM_FF_PGM_SYNC_CR3);
201 return VINF_SUCCESS;
202}
203
204
205/**
206 * Removes a page table based mapping.
207 *
208 * @returns VBox status code.
209 * @param pVM VM Handle.
210 * @param GCPtr Virtual Address. (Page table aligned!)
211 */
212PGMR3DECL(int) PGMR3UnmapPT(PVM pVM, RTGCPTR GCPtr)
213{
214 LogFlow(("PGMR3UnmapPT: GCPtr=%#x\n", GCPtr));
215
216 /*
217 * Find it.
218 */
219 PPGMMAPPING pPrev = NULL;
220 PPGMMAPPING pCur = pVM->pgm.s.pMappingsHC;
221 while (pCur)
222 {
223 if (pCur->GCPtr == GCPtr)
224 {
225 /*
226 * Unlink it.
227 */
228 if (pPrev)
229 {
230 pPrev->pNextHC = pCur->pNextHC;
231 pPrev->pNextGC = pCur->pNextGC;
232 }
233 else
234 {
235 pVM->pgm.s.pMappingsHC = pCur->pNextHC;
236 pVM->pgm.s.pMappingsGC = pCur->pNextGC;
237 }
238
239 /*
240 * Free the page table memory, clear page directory entries
241 * and free the page tables and node memory.
242 */
243 MMHyperFree(pVM, pCur->aPTs[0].pPTHC);
244 pgmR3MapClearPDEs(&pVM->pgm.s, pCur, pCur->GCPtr >> PGDIR_SHIFT);
245 MMHyperFree(pVM, pCur);
246
247 VM_FF_SET(pVM, VM_FF_PGM_SYNC_CR3);
248 return VINF_SUCCESS;
249 }
250
251 /* done? */
252 if (pCur->GCPtr > GCPtr)
253 break;
254
255 /* next */
256 pPrev = pCur;
257 pCur = pCur->pNextHC;
258 }
259
260 AssertMsgFailed(("No mapping for %#x found!\n", GCPtr));
261 return VERR_INVALID_PARAMETER;
262}
263
264
265/**
266 * Gets the size of the current guest mappings if they were to be
267 * put next to oneanother.
268 *
269 * @returns VBox status code.
270 * @param pVM The VM.
271 * @param pcb Where to store the size.
272 */
273PGMR3DECL(int) PGMR3MappingsSize(PVM pVM, size_t *pcb)
274{
275 size_t cb = 0;
276 for (PPGMMAPPING pCur = pVM->pgm.s.pMappingsHC; pCur; pCur = pCur->pNextHC)
277 cb += pCur->cb;
278
279 *pcb = cb;
280 Log(("PGMR3MappingsSize: return %d (%#x) bytes\n", cb, cb));
281 return VINF_SUCCESS;
282}
283
284
285/**
286 * Fixes the guest context mappings in a range reserved from the Guest OS.
287 *
288 * @returns VBox status code.
289 * @param pVM The VM.
290 * @param GCPtrBase The address of the reserved range of guest memory.
291 * @param cb The size of the range starting at GCPtrBase.
292 */
293PGMR3DECL(int) PGMR3MappingsFix(PVM pVM, RTGCPTR GCPtrBase, size_t cb)
294{
295 Log(("PGMR3MappingsFix: GCPtrBase=%#x cb=%#x\n", GCPtrBase, cb));
296
297 /*
298 * This is all or nothing at all. So, a tiny bit of paranoia first.
299 */
300 if (GCPtrBase & PAGE_OFFSET_MASK_BIG)
301 {
302 AssertMsgFailed(("GCPtrBase (%#x) has to be aligned on a 4MB address!\n", GCPtrBase));
303 return VERR_INVALID_PARAMETER;
304 }
305 if (!cb || (cb & PAGE_OFFSET_MASK_BIG))
306 {
307 AssertMsgFailed(("cb (%#x) is 0 or not aligned on a 4MB address!\n", cb));
308 return VERR_INVALID_PARAMETER;
309 }
310
311 /*
312 * Before we do anything we'll do a forced PD sync to try make sure any
313 * pending relocations because of these mappings have been resolved.
314 */
315 PGMSyncCR3(pVM, CPUMGetGuestCR0(pVM), CPUMGetGuestCR3(pVM), CPUMGetGuestCR4(pVM), true);
316
317 /*
318 * Check that it's not conflicting with a core code mapping in the intermediate page table.
319 */
320 unsigned iPDNew = GCPtrBase >> PGDIR_SHIFT;
321 unsigned i = cb >> PGDIR_SHIFT;
322 while (i-- > 0)
323 {
324 if (pVM->pgm.s.pInterPD->a[iPDNew + i].n.u1Present)
325 {
326 /* Check that it's not one or our mappings. */
327 PPGMMAPPING pCur = pVM->pgm.s.pMappingsHC;
328 while (pCur)
329 {
330 if (iPDNew + i - (pCur->GCPtr >> PGDIR_SHIFT) < (pCur->cb >> PGDIR_SHIFT))
331 break;
332 pCur = pCur->pNextHC;
333 }
334 if (!pCur)
335 {
336 LogRel(("PGMR3MappingsFix: Conflicts with intermediate PDE %#x (GCPtrBase=%VGv cb=%#zx). The guest should retry.\n",
337 iPDNew + i, GCPtrBase, cb));
338 return VERR_PGM_MAPPINGS_FIX_CONFLICT;
339 }
340 }
341 }
342
343 /*
344 * Loop the mappings and check that they all agree on their new locations.
345 */
346 RTGCPTR GCPtrCur = GCPtrBase;
347 PPGMMAPPING pCur = pVM->pgm.s.pMappingsHC;
348 while (pCur)
349 {
350 if (!pCur->pfnRelocate(pVM, pCur->GCPtr, GCPtrCur, PGMRELOCATECALL_SUGGEST, pCur->pvUser))
351 {
352 AssertMsgFailed(("The suggested fixed address %#x was rejected by '%s'!\n", GCPtrCur, pCur->pszDesc));
353 return VERR_PGM_MAPPINGS_FIX_REJECTED;
354 }
355 /* next */
356 GCPtrCur += pCur->cb;
357 pCur = pCur->pNextHC;
358 }
359 if (GCPtrCur > GCPtrBase + cb)
360 {
361 AssertMsgFailed(("cb (%#x) is less than the required range %#x!\n", cb, GCPtrCur - GCPtrBase));
362 return VERR_PGM_MAPPINGS_FIX_TOO_SMALL;
363 }
364
365 /*
366 * Loop the table assigning the mappings to the passed in memory
367 * and call their relocator callback.
368 */
369 GCPtrCur = GCPtrBase;
370 pCur = pVM->pgm.s.pMappingsHC;
371 while (pCur)
372 {
373 unsigned iPDOld = pCur->GCPtr >> PGDIR_SHIFT;
374 iPDNew = GCPtrCur >> PGDIR_SHIFT;
375
376 /*
377 * Relocate the page table(s).
378 */
379 pgmR3MapClearPDEs(&pVM->pgm.s, pCur, iPDOld);
380 pgmR3MapSetPDEs(pVM, pCur, iPDNew);
381
382 /*
383 * Update the entry.
384 */
385 pCur->GCPtr = GCPtrCur;
386 pCur->GCPtrLast = GCPtrCur + pCur->cb - 1;
387
388 /*
389 * Callback to execute the relocation.
390 */
391 pCur->pfnRelocate(pVM, iPDOld << PGDIR_SHIFT, iPDNew << PGDIR_SHIFT, PGMRELOCATECALL_RELOCATE, pCur->pvUser);
392
393 /*
394 * Advance.
395 */
396 GCPtrCur += pCur->cb;
397 pCur = pCur->pNextHC;
398 }
399
400 /*
401 * Turn off CR3 updating monitoring.
402 */
403 int rc2 = PGM_GST_PFN(UnmonitorCR3, pVM)(pVM);
404 AssertRC(rc2);
405
406 /*
407 * Mark the mappings as fixed and return.
408 */
409 pVM->pgm.s.fMappingsFixed = true;
410 pVM->pgm.s.GCPtrMappingFixed = GCPtrBase;
411 pVM->pgm.s.cbMappingFixed = cb;
412 pVM->pgm.s.fSyncFlags &= ~PGM_SYNC_MONITOR_CR3;
413 VM_FF_SET(pVM, VM_FF_PGM_SYNC_CR3);
414 return VINF_SUCCESS;
415}
416
417
418/**
419 * Unfixes the mappings.
420 * After calling this function mapping conflict detection will be enabled.
421 *
422 * @returns VBox status code.
423 * @param pVM The VM.
424 */
425PGMR3DECL(int) PGMR3MappingsUnfix(PVM pVM)
426{
427 Log(("PGMR3MappingsUnfix: fMappingsFixed=%d\n", pVM->pgm.s.fMappingsFixed));
428 pVM->pgm.s.fMappingsFixed = false;
429 pVM->pgm.s.GCPtrMappingFixed = 0;
430 pVM->pgm.s.cbMappingFixed = 0;
431 VM_FF_SET(pVM, VM_FF_PGM_SYNC_CR3);
432
433 /*
434 * Re-enable the CR3 monitoring.
435 *
436 * Paranoia: We flush the page pool before doing that because Windows
437 * is using the CR3 page both as a PD and a PT, e.g. the pool may
438 * be monitoring it.
439 */
440#ifdef PGMPOOL_WITH_MONITORING
441 pgmPoolFlushAll(pVM);
442#endif
443 int rc = PGM_GST_PFN(MonitorCR3, pVM)(pVM, pVM->pgm.s.GCPhysCR3);
444 AssertRC(rc);
445
446 return VINF_SUCCESS;
447}
448
449
450/**
451 * Map pages into the intermediate context (switcher code).
452 * These pages are mapped at both the give virtual address and at
453 * the physical address (for identity mapping).
454 *
455 * @returns VBox status code.
456 * @param pVM The virtual machine.
457 * @param Addr Intermediate context address of the mapping.
458 * @param HCPhys Start of the range of physical pages. This must be entriely below 4GB!
459 * @param cbPages Number of bytes to map.
460 *
461 * @remark This API shall not be used to anything but mapping the switcher code.
462 */
463PGMR3DECL(int) PGMR3MapIntermediate(PVM pVM, RTUINTPTR Addr, RTHCPHYS HCPhys, unsigned cbPages)
464{
465 LogFlow(("PGMR3MapIntermediate: Addr=%RTptr HCPhys=%VHp cbPages=%#x\n", Addr, HCPhys, cbPages));
466
467 /*
468 * Adjust input.
469 */
470 cbPages += (uint32_t)HCPhys & PAGE_OFFSET_MASK;
471 cbPages = RT_ALIGN(cbPages, PAGE_SIZE);
472 HCPhys &= X86_PTE_PAE_PG_MASK;
473 Addr &= PAGE_BASE_MASK;
474 /* We only care about the first 4GB, because on AMD64 we'll be repeating them all over the address space. */
475 uint32_t uAddress = (uint32_t)Addr;
476
477 /*
478 * Assert input and state.
479 */
480 AssertMsg(pVM->pgm.s.offVM, ("Bad init order\n"));
481 AssertMsg(pVM->pgm.s.pInterPD, ("Bad init order, paging.\n"));
482 AssertMsg(cbPages <= (512 << PAGE_SHIFT), ("The mapping is too big %d bytes\n", cbPages));
483 AssertMsg(HCPhys < _4G && HCPhys + cbPages < _4G, ("Addr=%RTptr HCPhys=%VHp cbPages=%d\n", Addr, HCPhys, cbPages));
484
485 /*
486 * Check for internal conflicts between the virtual address and the physical address.
487 */
488 if ( uAddress != HCPhys
489 && ( uAddress < HCPhys
490 ? HCPhys - uAddress < cbPages
491 : uAddress - HCPhys < cbPages
492 )
493 )
494 {
495 AssertMsgFailed(("Addr=%RTptr HCPhys=%VHp cbPages=%d\n", Addr, HCPhys, cbPages));
496 LogRel(("Addr=%RTptr HCPhys=%VHp cbPages=%d\n", Addr, HCPhys, cbPages));
497 return VERR_PGM_MAPPINGS_FIX_CONFLICT; /** @todo new error code */
498 }
499
500 const unsigned cPages = cbPages >> PAGE_SHIFT;
501 int rc = pgmR3MapIntermediateCheckOne(pVM, uAddress, cPages, pVM->pgm.s.apInterPTs[0], pVM->pgm.s.apInterPaePTs[0]);
502 if (VBOX_FAILURE(rc))
503 return rc;
504 rc = pgmR3MapIntermediateCheckOne(pVM, (uintptr_t)HCPhys, cPages, pVM->pgm.s.apInterPTs[1], pVM->pgm.s.apInterPaePTs[1]);
505 if (VBOX_FAILURE(rc))
506 return rc;
507
508 /*
509 * Everythings fine, do the mapping.
510 */
511 pgmR3MapIntermediateDoOne(pVM, uAddress, HCPhys, cPages, pVM->pgm.s.apInterPTs[0], pVM->pgm.s.apInterPaePTs[0]);
512 pgmR3MapIntermediateDoOne(pVM, (uintptr_t)HCPhys, HCPhys, cPages, pVM->pgm.s.apInterPTs[1], pVM->pgm.s.apInterPaePTs[1]);
513
514 return VINF_SUCCESS;
515}
516
517
518/**
519 * Validates that there are no conflicts for this mapping into the intermediate context.
520 *
521 * @returns VBox status code.
522 * @param pVM VM handle.
523 * @param uAddress Address of the mapping.
524 * @param cPages Number of pages.
525 * @param pPTDefault Pointer to the default page table for this mapping.
526 * @param pPTPaeDefault Pointer to the default page table for this mapping.
527 */
528static int pgmR3MapIntermediateCheckOne(PVM pVM, uintptr_t uAddress, unsigned cPages, PX86PT pPTDefault, PX86PTPAE pPTPaeDefault)
529{
530 AssertMsg((uAddress >> X86_PD_SHIFT) + cPages <= 1024, ("64-bit fixme\n"));
531
532 /*
533 * Check that the ranges are available.
534 * (This codes doesn't have to be fast.)
535 */
536 while (cPages > 0)
537 {
538 /*
539 * 32-Bit.
540 */
541 unsigned iPDE = (uAddress >> X86_PD_SHIFT) & X86_PD_MASK;
542 unsigned iPTE = (uAddress >> X86_PT_SHIFT) & X86_PT_MASK;
543 PX86PT pPT = pPTDefault;
544 if (pVM->pgm.s.pInterPD->a[iPDE].u)
545 {
546 RTHCPHYS HCPhysPT = pVM->pgm.s.pInterPD->a[iPDE].u & X86_PDE_PG_MASK;
547 if (HCPhysPT == MMPage2Phys(pVM, pVM->pgm.s.apInterPTs[0]))
548 pPT = pVM->pgm.s.apInterPTs[0];
549 else if (HCPhysPT == MMPage2Phys(pVM, pVM->pgm.s.apInterPTs[1]))
550 pPT = pVM->pgm.s.apInterPTs[1];
551 else
552 {
553 /** @todo this must be handled with a relocation of the conflicting mapping!
554 * Which of course cannot be done because we're in the middle of the initialization. bad design! */
555 AssertMsgFailed(("Conflict between core code and PGMR3Mapping(). uAddress=%VHv\n", uAddress));
556 LogRel(("Conflict between core code and PGMR3Mapping(). uAddress=%VHv\n", uAddress));
557 return VERR_PGM_MAPPINGS_FIX_CONFLICT; /** @todo error codes! */
558 }
559 }
560 if (pPT->a[iPTE].u)
561 {
562 AssertMsgFailed(("Conflict iPTE=%#x iPDE=%#x uAddress=%VHv pPT->a[iPTE].u=%RX32\n", iPTE, iPDE, uAddress, pPT->a[iPTE].u));
563 LogRel(("Conflict iPTE=%#x iPDE=%#x uAddress=%VHv pPT->a[iPTE].u=%RX32\n",
564 iPTE, iPDE, uAddress, pPT->a[iPTE].u));
565 return VERR_PGM_MAPPINGS_FIX_CONFLICT; /** @todo error codes! */
566 }
567
568 /*
569 * PAE.
570 */
571 const unsigned iPDPE= (uAddress >> X86_PDPTR_SHIFT) & X86_PDPTR_MASK;
572 iPDE = (uAddress >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
573 iPTE = (uAddress >> X86_PT_PAE_SHIFT) & X86_PT_PAE_MASK;
574 Assert(iPDPE < 4);
575 Assert(pVM->pgm.s.apInterPaePDs[iPDPE]);
576 PX86PTPAE pPTPae = pPTPaeDefault;
577 if (pVM->pgm.s.apInterPaePDs[iPDPE]->a[iPDE].u)
578 {
579 RTHCPHYS HCPhysPT = pVM->pgm.s.apInterPaePDs[iPDPE]->a[iPDE].u & X86_PDE_PAE_PG_MASK;
580 if (HCPhysPT == MMPage2Phys(pVM, pVM->pgm.s.apInterPaePTs[0]))
581 pPTPae = pVM->pgm.s.apInterPaePTs[0];
582 else if (HCPhysPT == MMPage2Phys(pVM, pVM->pgm.s.apInterPaePTs[0]))
583 pPTPae = pVM->pgm.s.apInterPaePTs[1];
584 else
585 {
586 /** @todo this must be handled with a relocation of the conflicting mapping!
587 * Which of course cannot be done because we're in the middle of the initialization. bad design! */
588 AssertMsgFailed(("Conflict between core code and PGMR3Mapping(). uAddress=%VHv\n", uAddress));
589 LogRel(("Conflict between core code and PGMR3Mapping(). uAddress=%VHv\n", uAddress));
590 return VERR_PGM_MAPPINGS_FIX_CONFLICT; /** @todo error codes! */
591 }
592 }
593 if (pPTPae->a[iPTE].u)
594 {
595 AssertMsgFailed(("Conflict iPTE=%#x iPDE=%#x uAddress=%VHv pPTPae->a[iPTE].u=%#RX64\n", iPTE, iPDE, uAddress, pPTPae->a[iPTE].u));
596 LogRel(("Conflict iPTE=%#x iPDE=%#x uAddress=%VHv pPTPae->a[iPTE].u=%#RX64\n",
597 iPTE, iPDE, uAddress, pPTPae->a[iPTE].u));
598 return VERR_PGM_MAPPINGS_FIX_CONFLICT; /** @todo error codes! */
599 }
600
601 /* next */
602 uAddress += PAGE_SIZE;
603 cPages--;
604 }
605
606 return VINF_SUCCESS;
607}
608
609
610
611/**
612 * Sets up the intermediate page tables for a verified mapping.
613 *
614 * @param pVM VM handle.
615 * @param uAddress Address of the mapping.
616 * @param HCPhys The physical address of the page range.
617 * @param cPages Number of pages.
618 * @param pPTDefault Pointer to the default page table for this mapping.
619 * @param pPTPaeDefault Pointer to the default page table for this mapping.
620 */
621static void pgmR3MapIntermediateDoOne(PVM pVM, uintptr_t uAddress, RTHCPHYS HCPhys, unsigned cPages, PX86PT pPTDefault, PX86PTPAE pPTPaeDefault)
622{
623 while (cPages > 0)
624 {
625 /*
626 * 32-Bit.
627 */
628 unsigned iPDE = (uAddress >> X86_PD_SHIFT) & X86_PD_MASK;
629 unsigned iPTE = (uAddress >> X86_PT_SHIFT) & X86_PT_MASK;
630 PX86PT pPT;
631 if (pVM->pgm.s.pInterPD->a[iPDE].u)
632 pPT = (PX86PT)MMPagePhys2Page(pVM, pVM->pgm.s.pInterPD->a[iPDE].u & X86_PDE_PG_MASK);
633 else
634 {
635 pVM->pgm.s.pInterPD->a[iPDE].u = X86_PDE_P | X86_PDE_A | X86_PDE_RW
636 | (uint32_t)MMPage2Phys(pVM, pPTDefault);
637 pPT = pPTDefault;
638 }
639 pPT->a[iPTE].u = X86_PTE_P | X86_PTE_RW | X86_PTE_A | X86_PTE_D | (uint32_t)HCPhys;
640
641 /*
642 * PAE
643 */
644 const unsigned iPDPE= (uAddress >> X86_PDPTR_SHIFT) & X86_PDPTR_MASK;
645 iPDE = (uAddress >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
646 iPTE = (uAddress >> X86_PT_PAE_SHIFT) & X86_PT_PAE_MASK;
647 Assert(iPDPE < 4);
648 Assert(pVM->pgm.s.apInterPaePDs[iPDPE]);
649 PX86PTPAE pPTPae;
650 if (pVM->pgm.s.apInterPaePDs[iPDPE]->a[iPDE].u)
651 pPTPae = (PX86PTPAE)MMPagePhys2Page(pVM, pVM->pgm.s.apInterPaePDs[iPDPE]->a[iPDE].u & X86_PDE_PAE_PG_MASK);
652 else
653 {
654 pPTPae = pPTPaeDefault;
655 pVM->pgm.s.apInterPaePDs[iPDPE]->a[iPDE].u = X86_PDE_P | X86_PDE_A | X86_PDE_RW
656 | MMPage2Phys(pVM, pPTPaeDefault);
657 }
658 pPTPae->a[iPTE].u = X86_PTE_P | X86_PTE_RW | X86_PTE_A | X86_PTE_D | HCPhys;
659
660 /* next */
661 cPages--;
662 HCPhys += PAGE_SIZE;
663 uAddress += PAGE_SIZE;
664 }
665}
666
667
668/**
669 * Clears all PDEs involved with the mapping.
670 *
671 * @param pPGM Pointer to the PGM instance data.
672 * @param pMap Pointer to the mapping in question.
673 * @param iOldPDE The index of the 32-bit PDE corresponding to the base of the mapping.
674 */
675static void pgmR3MapClearPDEs(PPGM pPGM, PPGMMAPPING pMap, int iOldPDE)
676{
677 unsigned i = pMap->cPTs;
678 iOldPDE += i;
679 while (i-- > 0)
680 {
681 iOldPDE--;
682
683 /*
684 * 32-bit.
685 */
686 pPGM->pInterPD->a[iOldPDE].u = 0;
687 pPGM->pHC32BitPD->a[iOldPDE].u = 0;
688
689 /*
690 * PAE.
691 */
692 const int iPD = iOldPDE / 256;
693 int iPDE = iOldPDE * 2 % 512;
694 pPGM->apInterPaePDs[iPD]->a[iPDE].u = 0;
695 pPGM->apHCPaePDs[iPD]->a[iPDE].u = 0;
696 iPDE++;
697 pPGM->apInterPaePDs[iPD]->a[iPDE].u = 0;
698 pPGM->apHCPaePDs[iPD]->a[iPDE].u = 0;
699 }
700}
701
702
703/**
704 * Sets all PDEs involved with the mapping.
705 *
706 * @param pVM The VM handle.
707 * @param pMap Pointer to the mapping in question.
708 * @param iNewPDE The index of the 32-bit PDE corresponding to the base of the mapping.
709 */
710static void pgmR3MapSetPDEs(PVM pVM, PPGMMAPPING pMap, int iNewPDE)
711{
712 PPGM pPGM = &pVM->pgm.s;
713
714 /* If mappings are not supposed to be put in the shadow page table, then this function is a nop. */
715 if (!pgmMapAreMappingsEnabled(&pVM->pgm.s))
716 return;
717
718 /*
719 * Init the page tables and insert them into the page directories.
720 */
721 unsigned i = pMap->cPTs;
722 iNewPDE += i;
723 while (i-- > 0)
724 {
725 iNewPDE--;
726
727 /*
728 * 32-bit.
729 */
730 if (pPGM->pHC32BitPD->a[iNewPDE].n.u1Present)
731 pgmPoolFree(pVM, pPGM->pHC32BitPD->a[iNewPDE].n.u1Present & X86_PDE_PG_MASK, PGMPOOL_IDX_PD, iNewPDE);
732 X86PDE Pde;
733 /* Default mapping page directory flags are read/write and supervisor; individual page attributes determine the final flags */
734 Pde.u = PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | (uint32_t)pMap->aPTs[i].HCPhysPT;
735 pPGM->pInterPD->a[iNewPDE] = Pde;
736 pPGM->pHC32BitPD->a[iNewPDE] = Pde;
737
738 /*
739 * PAE.
740 */
741 const int iPD = iNewPDE / 256;
742 int iPDE = iNewPDE * 2 % 512;
743 if (pPGM->apHCPaePDs[iPD]->a[iPDE].n.u1Present)
744 pgmPoolFree(pVM, pPGM->apHCPaePDs[iPD]->a[iPDE].n.u1Present & X86_PDE_PAE_PG_MASK, PGMPOOL_IDX_PAE_PD, iNewPDE * 2);
745 X86PDEPAE PdePae0;
746 PdePae0.u = PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | pMap->aPTs[i].HCPhysPaePT0;
747 pPGM->apInterPaePDs[iPD]->a[iPDE] = PdePae0;
748 pPGM->apHCPaePDs[iPD]->a[iPDE] = PdePae0;
749
750 iPDE++;
751 if (pPGM->apHCPaePDs[iPD]->a[iPDE].n.u1Present)
752 pgmPoolFree(pVM, pPGM->apHCPaePDs[iPD]->a[iPDE].n.u1Present & X86_PDE_PAE_PG_MASK, PGMPOOL_IDX_PAE_PD, iNewPDE * 2 + 1);
753 X86PDEPAE PdePae1;
754 PdePae1.u = PGM_PDFLAGS_MAPPING | X86_PDE_P | X86_PDE_A | X86_PDE_RW | X86_PDE_US | pMap->aPTs[i].HCPhysPaePT1;
755 pPGM->apInterPaePDs[iPD]->a[iPDE] = PdePae1;
756 pPGM->apHCPaePDs[iPD]->a[iPDE] = PdePae1;
757 }
758}
759
760/**
761 * Relocates a mapping to a new address.
762 *
763 * @param pVM VM handle.
764 * @param pMapping The mapping to relocate.
765 * @param iPDOld Old page directory index.
766 * @param iPDNew New page directory index.
767 */
768void pgmR3MapRelocate(PVM pVM, PPGMMAPPING pMapping, int iPDOld, int iPDNew)
769{
770 Log(("PGM: Relocating %s from %#x to %#x\n", pMapping->pszDesc, iPDOld << PGDIR_SHIFT, iPDNew << PGDIR_SHIFT));
771 Assert(((unsigned)iPDOld << PGDIR_SHIFT) == pMapping->GCPtr);
772
773 /*
774 * Relocate the page table(s).
775 */
776 pgmR3MapClearPDEs(&pVM->pgm.s, pMapping, iPDOld);
777 pgmR3MapSetPDEs(pVM, pMapping, iPDNew);
778
779 /*
780 * Update and resort the mapping list.
781 */
782
783 /* Find previous mapping for pMapping, put result into pPrevMap. */
784 PPGMMAPPING pPrevMap = NULL;
785 PPGMMAPPING pCur = pVM->pgm.s.pMappingsHC;
786 while (pCur && pCur != pMapping)
787 {
788 /* next */
789 pPrevMap = pCur;
790 pCur = pCur->pNextHC;
791 }
792 Assert(pCur);
793
794 /* Find mapping which >= than pMapping. */
795 RTGCPTR GCPtrNew = iPDNew << PGDIR_SHIFT;
796 PPGMMAPPING pPrev = NULL;
797 pCur = pVM->pgm.s.pMappingsHC;
798 while (pCur && pCur->GCPtr < GCPtrNew)
799 {
800 /* next */
801 pPrev = pCur;
802 pCur = pCur->pNextHC;
803 }
804
805 if (pCur != pMapping && pPrev != pMapping)
806 {
807 /*
808 * Unlink.
809 */
810 if (pPrevMap)
811 {
812 pPrevMap->pNextHC = pMapping->pNextHC;
813 pPrevMap->pNextGC = pMapping->pNextGC;
814 }
815 else
816 {
817 pVM->pgm.s.pMappingsHC = pMapping->pNextHC;
818 pVM->pgm.s.pMappingsGC = pMapping->pNextGC;
819 }
820
821 /*
822 * Link
823 */
824 pMapping->pNextHC = pCur;
825 if (pPrev)
826 {
827 pMapping->pNextGC = pPrev->pNextGC;
828 pPrev->pNextHC = pMapping;
829 pPrev->pNextGC = MMHyperHC2GC(pVM, pMapping);
830 }
831 else
832 {
833 pMapping->pNextGC = pVM->pgm.s.pMappingsGC;
834 pVM->pgm.s.pMappingsHC = pMapping;
835 pVM->pgm.s.pMappingsGC = MMHyperHC2GC(pVM, pMapping);
836 }
837 }
838
839 /*
840 * Update the entry.
841 */
842 pMapping->GCPtr = GCPtrNew;
843 pMapping->GCPtrLast = GCPtrNew + pMapping->cb - 1;
844
845 /*
846 * Callback to execute the relocation.
847 */
848 pMapping->pfnRelocate(pVM, iPDOld << PGDIR_SHIFT, iPDNew << PGDIR_SHIFT, PGMRELOCATECALL_RELOCATE, pMapping->pvUser);
849}
850
851
852/**
853 * Resolves a conflict between a page table based GC mapping and
854 * the Guest OS page tables.
855 *
856 * @returns VBox status code.
857 * @param pVM VM Handle.
858 * @param pMapping The mapping which conflicts.
859 * @param pPDSrc The page directory of the guest OS.
860 * @param iPDOld The index to the start of the current mapping.
861 */
862int pgmR3SyncPTResolveConflict(PVM pVM, PPGMMAPPING pMapping, PVBOXPD pPDSrc, int iPDOld)
863{
864 STAM_PROFILE_START(&pVM->pgm.s.StatHCResolveConflict, a);
865
866 /*
867 * Scan for free page directory entries.
868 *
869 * Note that we do not support mappings at the very end of the
870 * address space since that will break our GCPtrEnd assumptions.
871 */
872 const unsigned cPTs = pMapping->cPTs;
873 unsigned iPDNew = ELEMENTS(pPDSrc->a) - cPTs; /* (+ 1 - 1) */
874 while (iPDNew-- > 0)
875 {
876 if (pPDSrc->a[iPDNew].n.u1Present)
877 continue;
878 if (cPTs > 1)
879 {
880 bool fOk = true;
881 for (unsigned i = 1; fOk && i < cPTs; i++)
882 if (pPDSrc->a[iPDNew + i].n.u1Present)
883 fOk = false;
884 if (!fOk)
885 continue;
886 }
887
888 /*
889 * Check that it's not conflicting with an intermediate page table mapping.
890 */
891 bool fOk = true;
892 unsigned i = cPTs;
893 while (fOk && i-- > 0)
894 fOk = !pVM->pgm.s.pInterPD->a[iPDNew + i].n.u1Present;
895 if (!fOk)
896 continue;
897 /** @todo AMD64 should check the PAE directories and skip the 32bit stuff. */
898
899 /*
900 * Ask the mapping.
901 */
902 if (pMapping->pfnRelocate(pVM, iPDOld << PGDIR_SHIFT, iPDNew << PGDIR_SHIFT, PGMRELOCATECALL_SUGGEST, pMapping->pvUser))
903 {
904 pgmR3MapRelocate(pVM, pMapping, iPDOld, iPDNew);
905 STAM_PROFILE_STOP(&pVM->pgm.s.StatHCResolveConflict, a);
906 return VINF_SUCCESS;
907 }
908 }
909
910 STAM_PROFILE_STOP(&pVM->pgm.s.StatHCResolveConflict, a);
911 AssertMsgFailed(("Failed to relocate page table mapping '%s' from %#x! (cPTs=%d)\n", pMapping->pszDesc, iPDOld << PGDIR_SHIFT, cPTs));
912 return VERR_PGM_NO_HYPERVISOR_ADDRESS;
913}
914
915
916
917/**
918 * Checks guest PD for conflicts with VMM GC mappings.
919 *
920 * @returns true if conflict detected.
921 * @returns false if not.
922 * @param pVM The virtual machine.
923 * @param cr3 Guest context CR3 register.
924 * @param fRawR0 Whether RawR0 is enabled or not.
925 */
926PGMR3DECL(bool) PGMR3MapHasConflicts(PVM pVM, uint32_t cr3, bool fRawR0) /** @todo how many HasConflict constructs do we really need? */
927{
928 /*
929 * Can skip this if mappings are safely fixed.
930 */
931 if (pVM->pgm.s.fMappingsFixed)
932 return false;
933
934 /*
935 * Resolve the page directory.
936 */
937 PVBOXPD pPD = pVM->pgm.s.pGuestPDHC; /** @todo Fix PAE! */
938 Assert(pPD);
939 Assert(pPD == (PVBOXPD)MMPhysGCPhys2HCVirt(pVM, cr3 & X86_CR3_PAGE_MASK, sizeof(*pPD)));
940
941 /*
942 * Iterate mappings.
943 */
944 for (PPGMMAPPING pCur = pVM->pgm.s.pMappingsHC; pCur; pCur = pCur->pNextHC)
945 {
946 unsigned iPDE = pCur->GCPtr >> PGDIR_SHIFT;
947 unsigned iPT = pCur->cPTs;
948 while (iPT-- > 0)
949 if ( pPD->a[iPDE + iPT].n.u1Present /** @todo PGMGstGetPDE. */
950 && (fRawR0 || pPD->a[iPDE + iPT].n.u1User))
951 {
952 STAM_COUNTER_INC(&pVM->pgm.s.StatHCDetectedConflicts);
953 #if 1
954 Log(("PGMR3HasMappingConflicts: Conflict was detected at %VGv for mapping %s\n"
955 " iPDE=%#x iPT=%#x PDE=%VGp.\n",
956 (iPT + iPDE) << PGDIR_SHIFT, pCur->pszDesc,
957 iPDE, iPT, pPD->a[iPDE + iPT].au32[0]));
958 #else
959 AssertMsgFailed(("PGMR3HasMappingConflicts: Conflict was detected at %VGv for mapping %s\n"
960 " iPDE=%#x iPT=%#x PDE=%VGp.\n",
961 (iPT + iPDE) << PGDIR_SHIFT, pCur->pszDesc,
962 iPDE, iPT, pPD->a[iPDE + iPT].au32[0]));
963 #endif
964 return true;
965 }
966 }
967
968 return false;
969}
970
971
972/**
973 * Read memory from the guest mappings.
974 *
975 * This will use the page tables associated with the mappings to
976 * read the memory. This means that not all kind of memory is readable
977 * since we don't necessarily know how to convert that physical address
978 * to a HC virtual one.
979 *
980 * @returns VBox status.
981 * @param pVM VM handle.
982 * @param pvDst The destination address (HC of course).
983 * @param GCPtrSrc The source address (GC virtual address).
984 * @param cb Number of bytes to read.
985 */
986PGMR3DECL(int) PGMR3MapRead(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb)
987{
988/** @todo remove this simplicity hack */
989 /*
990 * Simplicity over speed... Chop the request up into chunks
991 * which don't cross pages.
992 */
993 if (cb + (GCPtrSrc & PAGE_OFFSET_MASK) > PAGE_SIZE)
994 {
995 for (;;)
996 {
997 unsigned cbRead = RT_MIN(cb, PAGE_SIZE - (GCPtrSrc & PAGE_OFFSET_MASK));
998 int rc = PGMR3MapRead(pVM, pvDst, GCPtrSrc, cbRead);
999 if (VBOX_FAILURE(rc))
1000 return rc;
1001 cb -= cbRead;
1002 if (!cb)
1003 break;
1004 pvDst = (char *)pvDst + cbRead;
1005 GCPtrSrc += cbRead;
1006 }
1007 return VINF_SUCCESS;
1008 }
1009
1010 /*
1011 * Find the mapping.
1012 */
1013 PPGMMAPPING pCur = CTXSUFF(pVM->pgm.s.pMappings);
1014 while (pCur)
1015 {
1016 RTGCUINTPTR off = (RTGCUINTPTR)GCPtrSrc - (RTGCUINTPTR)pCur->GCPtr;
1017 if (off < pCur->cb)
1018 {
1019 if (off + cb > pCur->cb)
1020 {
1021 AssertMsgFailed(("Invalid page range %VGv LB%#x. mapping '%s' %VGv to %VGv\n",
1022 GCPtrSrc, cb, pCur->pszDesc, pCur->GCPtr, pCur->GCPtrLast));
1023 return VERR_INVALID_PARAMETER;
1024 }
1025
1026 unsigned iPT = off >> PGDIR_SHIFT;
1027 unsigned iPTE = (off >> PAGE_SHIFT) & PTE_MASK;
1028 while (cb > 0 && iPTE < ELEMENTS(CTXSUFF(pCur->aPTs[iPT].pPT)->a))
1029 {
1030 if (!CTXSUFF(pCur->aPTs[iPT].paPaePTs)[iPTE / 512].a[iPTE % 512].n.u1Present)
1031 return VERR_PAGE_NOT_PRESENT;
1032 RTHCPHYS HCPhys = CTXSUFF(pCur->aPTs[iPT].paPaePTs)[iPTE / 512].a[iPTE % 512].u & X86_PTE_PAE_PG_MASK;
1033
1034 /*
1035 * Get the virtual page from the physical one.
1036 */
1037 void *pvPage;
1038 int rc = MMR3HCPhys2HCVirt(pVM, HCPhys, &pvPage);
1039 if (VBOX_FAILURE(rc))
1040 return rc;
1041
1042 memcpy(pvDst, (char *)pvPage + (GCPtrSrc & PAGE_OFFSET_MASK), cb);
1043 return VINF_SUCCESS;
1044 }
1045 }
1046
1047 /* next */
1048 pCur = CTXSUFF(pCur->pNext);
1049 }
1050
1051 return VERR_INVALID_POINTER;
1052}
1053
1054
1055/**
1056 * Dumps one virtual handler range.
1057 *
1058 * @returns 0
1059 * @param pNode Pointer to a PGMVIRTHANDLER.
1060 * @param pvUser Pointer to command helper functions.
1061 */
1062static DECLCALLBACK(int) pgmVirtHandlerDump(PAVLROGCPTRNODECORE pNode, void *pvUser)
1063{
1064 PPGMVIRTHANDLER pCur = (PPGMVIRTHANDLER)pNode;
1065
1066 switch (pCur->enmType)
1067 {
1068 case PGMVIRTHANDLERTYPE_EIP:
1069 RTLogPrintf("EIP %RGv-%RGv size %RGv %s\n", pCur->GCPtr, pCur->GCPtrLast, pCur->cb, pCur->pszDesc);
1070 break;
1071 case PGMVIRTHANDLERTYPE_NORMAL:
1072 RTLogPrintf("NORMAL %RGv-%RGv size %RGv %s\n", pCur->GCPtr, pCur->GCPtrLast, pCur->cb, pCur->pszDesc);
1073 break;
1074 case PGMVIRTHANDLERTYPE_WRITE:
1075 RTLogPrintf("WRITE %RGv-%RGv size %RGv %s\n", pCur->GCPtr, pCur->GCPtrLast, pCur->cb, pCur->pszDesc);
1076 break;
1077 case PGMVIRTHANDLERTYPE_HYPERVISOR:
1078 RTLogPrintf("WRITEHYP %RGv-%RGv size %RGv %s\n", pCur->GCPtr, pCur->GCPtrLast, pCur->cb, pCur->pszDesc);
1079 break;
1080 case PGMVIRTHANDLERTYPE_ALL:
1081 RTLogPrintf("ALL %RGv-%RGv size %RGv %s\n", pCur->GCPtr, pCur->GCPtrLast, pCur->cb, pCur->pszDesc);
1082 break;
1083 }
1084 if (pCur->enmType != PGMVIRTHANDLERTYPE_HYPERVISOR)
1085 for (unsigned i = 0; i < pCur->cPages; i++)
1086 RTLogPrintf("Physical page %#05d %VGp\n", i, pCur->aPhysToVirt[i].Core.Key);
1087 return 0;
1088}
1089
1090/**
1091 * Dumps the current mappings to the log
1092 *
1093 * @returns VBox status.
1094 * @param pVM Pointer to the current VM (if any).
1095 *
1096 */
1097PGMR3DECL(void) PGMR3DumpMappings(PVM pVM)
1098{
1099 /*
1100 * Print message about the fixedness of the mappings and dump them.
1101 */
1102 RTLogPrintf(pVM->pgm.s.fMappingsFixed ? "\nThe mappings are FIXED.\n" : "\nThe mappings are FLOATING.\n");
1103
1104 PPGMMAPPING pCur;
1105 for (pCur = pVM->pgm.s.pMappingsHC; pCur; pCur = pCur->pNextHC)
1106 RTLogPrintf("%VGv - %VGv %s\n", pCur->GCPtr, pCur->GCPtrLast, pCur->pszDesc);
1107
1108/** @todo The handler stuff is totally alien here. This should be converted into a 'info' function. */
1109 RTLogPrintf("\nVirtual handlers:\n");
1110 RTAvlroGCPtrDoWithAll(&pVM->pgm.s.pTreesHC->VirtHandlers, true, pgmVirtHandlerDump, pVM);
1111
1112 RTLogPrintf("\n"
1113 "Physical handlers: (PhysHandlers=%d (%#x))\n"
1114 "From - To (incl) HandlerHC UserHC HandlerHC UserHC HandlerGC UserGC Type Description\n",
1115 pVM->pgm.s.pTreesHC->PhysHandlers, pVM->pgm.s.pTreesHC->PhysHandlers);
1116 RTAvlroGCPhysDoWithAll(&pVM->pgm.s.pTreesHC->PhysHandlers, true, pgmR3DumpMappingsPhysicalCB, NULL);
1117}
1118
1119
1120/**
1121 * Dumps one physical handler range.
1122 *
1123 * @returns 0
1124 * @param pNode Pointer to a PGMPHYSHANDLER.
1125 * @param pvUser Ignored.
1126 */
1127static DECLCALLBACK(int) pgmR3DumpMappingsPhysicalCB(PAVLROGCPHYSNODECORE pNode, void *pvUser)
1128{
1129 PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)pNode; NOREF(pvUser);
1130 const char *pszType;
1131 switch (pCur->enmType)
1132 {
1133 case PGMPHYSHANDLERTYPE_MMIO: pszType = "MMIO "; break;
1134 case PGMPHYSHANDLERTYPE_PHYSICAL: pszType = "Natural"; break;
1135 case PGMPHYSHANDLERTYPE_PHYSICAL_WRITE: pszType = "Write "; break;
1136 case PGMPHYSHANDLERTYPE_PHYSICAL_ALL: pszType = "All "; break;
1137 default: pszType = "????"; break;
1138 }
1139 RTLogPrintf("%VGp - %VGp %VHv %VHv %VHv %VHv %VGv %VGv %s %s\n",
1140 pCur->Core.Key, pCur->Core.KeyLast, pCur->pfnHandlerR3, pCur->pvUserR3, pCur->pfnHandlerR0, pCur->pvUserR0,
1141 pCur->pfnHandlerGC, pCur->pvUserGC, pszType, pCur->pszDesc);
1142 return 0;
1143}
1144
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