VirtualBox

source: vbox/trunk/src/VBox/VMM/PGMHandler.cpp@ 34244

Last change on this file since 34244 was 34241, checked in by vboxsync, 14 years ago

PDM: Added search paths to the device and driver DLL CFGM nodes so that VBoxEhciR0.r0/RC.rc can be found.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 23.4 KB
Line 
1/* $Id: PGMHandler.cpp 34241 2010-11-22 14:26:53Z vboxsync $ */
2/** @file
3 * PGM - Page Manager / Monitor, Access Handlers.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
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
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_PGM
23#include <VBox/dbgf.h>
24#include <VBox/pgm.h>
25#include <VBox/cpum.h>
26#include <VBox/iom.h>
27#include <VBox/sup.h>
28#include <VBox/mm.h>
29#include <VBox/em.h>
30#include <VBox/stam.h>
31#include <VBox/csam.h>
32#include <VBox/rem.h>
33#include <VBox/dbgf.h>
34#include <VBox/rem.h>
35#include <VBox/selm.h>
36#include <VBox/ssm.h>
37#include "PGMInternal.h"
38#include <VBox/vm.h>
39#include "PGMInline.h"
40#include <VBox/dbg.h>
41
42#include <VBox/log.h>
43#include <iprt/assert.h>
44#include <iprt/alloc.h>
45#include <iprt/asm.h>
46#include <iprt/thread.h>
47#include <iprt/string.h>
48#include <VBox/param.h>
49#include <VBox/err.h>
50#include <VBox/hwaccm.h>
51
52
53/*******************************************************************************
54* Internal Functions *
55*******************************************************************************/
56static DECLCALLBACK(int) pgmR3HandlerPhysicalOneClear(PAVLROGCPHYSNODECORE pNode, void *pvUser);
57static DECLCALLBACK(int) pgmR3HandlerPhysicalOneSet(PAVLROGCPHYSNODECORE pNode, void *pvUser);
58static DECLCALLBACK(int) pgmR3InfoHandlersPhysicalOne(PAVLROGCPHYSNODECORE pNode, void *pvUser);
59static DECLCALLBACK(int) pgmR3InfoHandlersVirtualOne(PAVLROGCPTRNODECORE pNode, void *pvUser);
60
61
62
63/**
64 * Register a access handler for a physical range.
65 *
66 * @returns VBox status code.
67 * @param pVM VM handle.
68 * @param enmType Handler type. Any of the PGMPHYSHANDLERTYPE_PHYSICAL* enums.
69 * @param GCPhys Start physical address.
70 * @param GCPhysLast Last physical address. (inclusive)
71 * @param pfnHandlerR3 The R3 handler.
72 * @param pvUserR3 User argument to the R3 handler.
73 * @param pszModR0 The R0 handler module. NULL means the default R0 module.
74 * @param pszHandlerR0 The R0 handler symbol name.
75 * @param pvUserR0 User argument to the R0 handler.
76 * @param pszModRC The RC handler module. NULL means the default RC
77 * module.
78 * @param pszHandlerRC The RC handler symbol name.
79 * @param pvUserRC User argument to the RC handler. Values less than
80 * 0x10000 will not be relocated.
81 * @param pszDesc Pointer to description string. This must not be freed.
82 */
83VMMR3DECL(int) PGMR3HandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
84 PFNPGMR3PHYSHANDLER pfnHandlerR3, void *pvUserR3,
85 const char *pszModR0, const char *pszHandlerR0, RTR0PTR pvUserR0,
86 const char *pszModRC, const char *pszHandlerRC, RTRCPTR pvUserRC, const char *pszDesc)
87{
88 LogFlow(("PGMR3HandlerPhysicalRegister: enmType=%d GCPhys=%RGp GCPhysLast=%RGp pfnHandlerR3=%RHv pvUserHC=%RHv pszModR0=%s pszHandlerR0=%s pvUserR0=%RHv pszModRC=%s pszHandlerRC=%s pvUser=%RRv pszDesc=%s\n",
89 enmType, GCPhys, GCPhysLast, pfnHandlerR3, pvUserR3, pszModR0, pszHandlerR0, pvUserR0, pszHandlerRC, pszModRC, pvUserRC, pszDesc));
90
91 /*
92 * Validate input.
93 */
94 if (!pszModRC)
95 pszModRC = VMMGC_MAIN_MODULE_NAME;
96 if (!pszModR0)
97 pszModR0 = VMMR0_MAIN_MODULE_NAME;
98 if (!pszHandlerR0)
99 pszHandlerR0 = "pgmPhysHandlerRedirectToHC";
100 if (!pszHandlerRC)
101 pszHandlerRC = "pgmPhysHandlerRedirectToHC";
102 AssertPtrReturn(pfnHandlerR3, VERR_INVALID_POINTER);
103 AssertPtrReturn(pszHandlerR0, VERR_INVALID_POINTER);
104 AssertPtrReturn(pszHandlerRC, VERR_INVALID_POINTER);
105
106 /*
107 * Resolve the R0 handler.
108 */
109 R0PTRTYPE(PFNPGMR0PHYSHANDLER) pfnHandlerR0 = NIL_RTR0PTR;
110 int rc = VINF_SUCCESS;
111 rc = PDMR3LdrGetSymbolR0Lazy(pVM, pszModR0, NULL /*pszSearchPath*/, pszHandlerR0, &pfnHandlerR0);
112 if (RT_SUCCESS(rc))
113 {
114 /*
115 * Resolve the GC handler.
116 */
117 RTRCPTR pfnHandlerRC = NIL_RTRCPTR;
118 rc = PDMR3LdrGetSymbolRCLazy(pVM, pszModRC, NULL /*pszSearchPath*/, pszHandlerRC, &pfnHandlerRC);
119 if (RT_SUCCESS(rc))
120 return PGMHandlerPhysicalRegisterEx(pVM, enmType, GCPhys, GCPhysLast, pfnHandlerR3, pvUserR3,
121 pfnHandlerR0, pvUserR0, pfnHandlerRC, pvUserRC, pszDesc);
122
123 AssertMsgFailed(("Failed to resolve %s.%s, rc=%Rrc.\n", pszModRC, pszHandlerRC, rc));
124 }
125 else
126 AssertMsgFailed(("Failed to resolve %s.%s, rc=%Rrc.\n", pszModR0, pszHandlerR0, rc));
127
128 return rc;
129}
130
131
132/**
133 * Updates the physical page access handlers.
134 *
135 * @param pVM VM handle.
136 * @remark Only used when restoring a saved state.
137 */
138void pgmR3HandlerPhysicalUpdateAll(PVM pVM)
139{
140 LogFlow(("pgmHandlerPhysicalUpdateAll:\n"));
141
142 /*
143 * Clear and set.
144 * (the right -> left on the setting pass is just bird speculating on cache hits)
145 */
146 pgmLock(pVM);
147 RTAvlroGCPhysDoWithAll(&pVM->pgm.s.CTX_SUFF(pTrees)->PhysHandlers, true, pgmR3HandlerPhysicalOneClear, pVM);
148 RTAvlroGCPhysDoWithAll(&pVM->pgm.s.CTX_SUFF(pTrees)->PhysHandlers, false, pgmR3HandlerPhysicalOneSet, pVM);
149 pgmUnlock(pVM);
150}
151
152
153/**
154 * Clears all the page level flags for one physical handler range.
155 *
156 * @returns 0
157 * @param pNode Pointer to a PGMPHYSHANDLER.
158 * @param pvUser VM handle.
159 */
160static DECLCALLBACK(int) pgmR3HandlerPhysicalOneClear(PAVLROGCPHYSNODECORE pNode, void *pvUser)
161{
162 PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)pNode;
163 PPGMRAMRANGE pRamHint = NULL;
164 RTGCPHYS GCPhys = pCur->Core.Key;
165 RTUINT cPages = pCur->cPages;
166 PPGM pPGM = &((PVM)pvUser)->pgm.s;
167 for (;;)
168 {
169 PPGMPAGE pPage;
170 int rc = pgmPhysGetPageWithHintEx(pPGM, GCPhys, &pPage, &pRamHint);
171 if (RT_SUCCESS(rc))
172 PGM_PAGE_SET_HNDL_PHYS_STATE(pPage, PGM_PAGE_HNDL_PHYS_STATE_NONE);
173 else
174 AssertRC(rc);
175
176 if (--cPages == 0)
177 return 0;
178 GCPhys += PAGE_SIZE;
179 }
180}
181
182
183/**
184 * Sets all the page level flags for one physical handler range.
185 *
186 * @returns 0
187 * @param pNode Pointer to a PGMPHYSHANDLER.
188 * @param pvUser VM handle.
189 */
190static DECLCALLBACK(int) pgmR3HandlerPhysicalOneSet(PAVLROGCPHYSNODECORE pNode, void *pvUser)
191{
192 PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)pNode;
193 unsigned uState = pgmHandlerPhysicalCalcState(pCur);
194 PPGMRAMRANGE pRamHint = NULL;
195 RTGCPHYS GCPhys = pCur->Core.Key;
196 RTUINT cPages = pCur->cPages;
197 PPGM pPGM = &((PVM)pvUser)->pgm.s;
198 for (;;)
199 {
200 PPGMPAGE pPage;
201 int rc = pgmPhysGetPageWithHintEx(pPGM, GCPhys, &pPage, &pRamHint);
202 if (RT_SUCCESS(rc))
203 PGM_PAGE_SET_HNDL_PHYS_STATE(pPage, uState);
204 else
205 AssertRC(rc);
206
207 if (--cPages == 0)
208 return 0;
209 GCPhys += PAGE_SIZE;
210 }
211}
212
213
214/**
215 * Register a access handler for a virtual range.
216 *
217 * @returns VBox status code.
218 * @param pVM VM handle.
219 * @param enmType Handler type. Any of the PGMVIRTHANDLERTYPE_* enums.
220 * @param GCPtr Start address.
221 * @param GCPtrLast Last address (inclusive).
222 * @param pfnInvalidateR3 The R3 invalidate callback (can be 0)
223 * @param pfnHandlerR3 The R3 handler.
224 * @param pszHandlerRC The RC handler symbol name.
225 * @param pszModRC The RC handler module.
226 * @param pszDesc Pointer to description string. This must not be freed.
227 */
228VMMR3DECL(int) PGMR3HandlerVirtualRegister(PVM pVM, PGMVIRTHANDLERTYPE enmType, RTGCPTR GCPtr, RTGCPTR GCPtrLast,
229 PFNPGMR3VIRTINVALIDATE pfnInvalidateR3,
230 PFNPGMR3VIRTHANDLER pfnHandlerR3,
231 const char *pszHandlerRC, const char *pszModRC,
232 const char *pszDesc)
233{
234 LogFlow(("PGMR3HandlerVirtualRegisterEx: enmType=%d GCPtr=%RGv GCPtrLast=%RGv pszHandlerRC=%p:{%s} pszModRC=%p:{%s} pszDesc=%s\n",
235 enmType, GCPtr, GCPtrLast, pszHandlerRC, pszHandlerRC, pszModRC, pszModRC, pszDesc));
236
237 /* Not supported/relevant for VT-x and AMD-V. */
238 if (HWACCMIsEnabled(pVM))
239 return VERR_NOT_IMPLEMENTED;
240
241 /*
242 * Validate input.
243 */
244 if (!pszModRC)
245 pszModRC = VMMGC_MAIN_MODULE_NAME;
246 if (!pszModRC || !*pszModRC || !pszHandlerRC || !*pszHandlerRC)
247 {
248 AssertMsgFailed(("pfnHandlerGC or/and pszModRC is missing\n"));
249 return VERR_INVALID_PARAMETER;
250 }
251
252 /*
253 * Resolve the GC handler.
254 */
255 RTRCPTR pfnHandlerRC;
256 int rc = PDMR3LdrGetSymbolRCLazy(pVM, pszModRC, NULL /*pszSearchPath*/, pszHandlerRC, &pfnHandlerRC);
257 if (RT_SUCCESS(rc))
258 return PGMR3HandlerVirtualRegisterEx(pVM, enmType, GCPtr, GCPtrLast, pfnInvalidateR3, pfnHandlerR3, pfnHandlerRC, pszDesc);
259
260 AssertMsgFailed(("Failed to resolve %s.%s, rc=%Rrc.\n", pszModRC, pszHandlerRC, rc));
261 return rc;
262}
263
264
265/**
266 * Register an access handler for a virtual range.
267 *
268 * @returns VBox status code.
269 * @param pVM VM handle.
270 * @param enmType Handler type. Any of the PGMVIRTHANDLERTYPE_* enums.
271 * @param GCPtr Start address.
272 * @param GCPtrLast Last address (inclusive).
273 * @param pfnInvalidateR3 The R3 invalidate callback (can be 0)
274 * @param pfnHandlerR3 The R3 handler.
275 * @param pfnHandlerRC The RC handler.
276 * @param pszDesc Pointer to description string. This must not be freed.
277 * @thread EMT
278 */
279/** @todo create a template for virtual handlers (see async i/o), we're wasting space
280 * duplicating the function pointers now. (Or we will once we add the missing callbacks.) */
281VMMDECL(int) PGMR3HandlerVirtualRegisterEx(PVM pVM, PGMVIRTHANDLERTYPE enmType, RTGCPTR GCPtr, RTGCPTR GCPtrLast,
282 R3PTRTYPE(PFNPGMR3VIRTINVALIDATE) pfnInvalidateR3,
283 R3PTRTYPE(PFNPGMR3VIRTHANDLER) pfnHandlerR3,
284 RCPTRTYPE(PFNPGMRCVIRTHANDLER) pfnHandlerRC,
285 R3PTRTYPE(const char *) pszDesc)
286{
287 Log(("PGMR3HandlerVirtualRegister: enmType=%d GCPtr=%RGv GCPtrLast=%RGv pfnInvalidateR3=%RHv pfnHandlerR3=%RHv pfnHandlerRC=%RRv pszDesc=%s\n",
288 enmType, GCPtr, GCPtrLast, pfnInvalidateR3, pfnHandlerR3, pfnHandlerRC, pszDesc));
289
290 /* Not supported/relevant for VT-x and AMD-V. */
291 if (HWACCMIsEnabled(pVM))
292 return VERR_NOT_IMPLEMENTED;
293
294 /*
295 * Validate input.
296 */
297 switch (enmType)
298 {
299 case PGMVIRTHANDLERTYPE_ALL:
300 AssertReleaseMsgReturn( (GCPtr & PAGE_OFFSET_MASK) == 0
301 && (GCPtrLast & PAGE_OFFSET_MASK) == PAGE_OFFSET_MASK,
302 ("PGMVIRTHANDLERTYPE_ALL: GCPtr=%RGv GCPtrLast=%RGv\n", GCPtr, GCPtrLast),
303 VERR_NOT_IMPLEMENTED);
304 break;
305 case PGMVIRTHANDLERTYPE_WRITE:
306 if (!pfnHandlerR3)
307 {
308 AssertMsgFailed(("No HC handler specified!!\n"));
309 return VERR_INVALID_PARAMETER;
310 }
311 break;
312
313 case PGMVIRTHANDLERTYPE_HYPERVISOR:
314 if (pfnHandlerR3)
315 {
316 AssertMsgFailed(("R3 handler specified for hypervisor range!?!\n"));
317 return VERR_INVALID_PARAMETER;
318 }
319 break;
320 default:
321 AssertMsgFailed(("Invalid enmType! enmType=%d\n", enmType));
322 return VERR_INVALID_PARAMETER;
323 }
324 if (GCPtrLast < GCPtr)
325 {
326 AssertMsgFailed(("GCPtrLast < GCPtr (%#x < %#x)\n", GCPtrLast, GCPtr));
327 return VERR_INVALID_PARAMETER;
328 }
329 if (!pfnHandlerRC)
330 {
331 AssertMsgFailed(("pfnHandlerRC is missing\n"));
332 return VERR_INVALID_PARAMETER;
333 }
334
335 /*
336 * Allocate and initialize a new entry.
337 */
338 unsigned cPages = (RT_ALIGN(GCPtrLast + 1, PAGE_SIZE) - (GCPtr & PAGE_BASE_GC_MASK)) >> PAGE_SHIFT;
339 PPGMVIRTHANDLER pNew;
340 int rc = MMHyperAlloc(pVM, RT_OFFSETOF(PGMVIRTHANDLER, aPhysToVirt[cPages]), 0, MM_TAG_PGM_HANDLERS, (void **)&pNew); /** @todo r=bird: incorrect member name PhysToVirt? */
341 if (RT_FAILURE(rc))
342 return rc;
343
344 pNew->Core.Key = GCPtr;
345 pNew->Core.KeyLast = GCPtrLast;
346
347 pNew->enmType = enmType;
348 pNew->pfnInvalidateR3 = pfnInvalidateR3;
349 pNew->pfnHandlerRC = pfnHandlerRC;
350 pNew->pfnHandlerR3 = pfnHandlerR3;
351 pNew->pszDesc = pszDesc;
352 pNew->cb = GCPtrLast - GCPtr + 1;
353 pNew->cPages = cPages;
354 /* Will be synced at next guest execution attempt. */
355 while (cPages-- > 0)
356 {
357 pNew->aPhysToVirt[cPages].Core.Key = NIL_RTGCPHYS;
358 pNew->aPhysToVirt[cPages].Core.KeyLast = NIL_RTGCPHYS;
359 pNew->aPhysToVirt[cPages].offVirtHandler = -RT_OFFSETOF(PGMVIRTHANDLER, aPhysToVirt[cPages]);
360 pNew->aPhysToVirt[cPages].offNextAlias = 0;
361 }
362
363 /*
364 * Try to insert it into the tree.
365 *
366 * The current implementation doesn't allow multiple handlers for
367 * the same range this makes everything much simpler and faster.
368 */
369 AVLROGCPTRTREE *pRoot = enmType != PGMVIRTHANDLERTYPE_HYPERVISOR
370 ? &pVM->pgm.s.CTX_SUFF(pTrees)->VirtHandlers
371 : &pVM->pgm.s.CTX_SUFF(pTrees)->HyperVirtHandlers;
372 pgmLock(pVM);
373 if (*pRoot != 0)
374 {
375 PPGMVIRTHANDLER pCur = (PPGMVIRTHANDLER)RTAvlroGCPtrGetBestFit(pRoot, pNew->Core.Key, true);
376 if ( !pCur
377 || GCPtr > pCur->Core.KeyLast
378 || GCPtrLast < pCur->Core.Key)
379 pCur = (PPGMVIRTHANDLER)RTAvlroGCPtrGetBestFit(pRoot, pNew->Core.Key, false);
380 if ( pCur
381 && GCPtr <= pCur->Core.KeyLast
382 && GCPtrLast >= pCur->Core.Key)
383 {
384 /*
385 * The LDT sometimes conflicts with the IDT and LDT ranges while being
386 * updated on linux. So, we don't assert simply log it.
387 */
388 Log(("PGMR3HandlerVirtualRegister: Conflict with existing range %RGv-%RGv (%s), req. %RGv-%RGv (%s)\n",
389 pCur->Core.Key, pCur->Core.KeyLast, pCur->pszDesc, GCPtr, GCPtrLast, pszDesc));
390 MMHyperFree(pVM, pNew);
391 pgmUnlock(pVM);
392 return VERR_PGM_HANDLER_VIRTUAL_CONFLICT;
393 }
394 }
395 if (RTAvlroGCPtrInsert(pRoot, &pNew->Core))
396 {
397 if (enmType != PGMVIRTHANDLERTYPE_HYPERVISOR)
398 {
399 PVMCPU pVCpu = VMMGetCpu(pVM);
400
401 pVCpu->pgm.s.fSyncFlags |= PGM_SYNC_UPDATE_PAGE_BIT_VIRTUAL | PGM_SYNC_CLEAR_PGM_POOL;
402 VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
403 }
404 pgmUnlock(pVM);
405
406#ifdef VBOX_WITH_STATISTICS
407 char szPath[256];
408 RTStrPrintf(szPath, sizeof(szPath), "/PGM/VirtHandler/Calls/%RGv-%RGv", pNew->Core.Key, pNew->Core.KeyLast);
409 rc = STAMR3Register(pVM, &pNew->Stat, STAMTYPE_PROFILE, STAMVISIBILITY_USED, szPath, STAMUNIT_TICKS_PER_CALL, pszDesc);
410 AssertRC(rc);
411#endif
412 return VINF_SUCCESS;
413 }
414
415 pgmUnlock(pVM);
416 AssertFailed();
417 MMHyperFree(pVM, pNew);
418 return VERR_PGM_HANDLER_VIRTUAL_CONFLICT;
419}
420
421
422/**
423 * Modify the page invalidation callback handler for a registered virtual range.
424 * (add more when needed)
425 *
426 * @returns VBox status code.
427 * @param pVM VM handle.
428 * @param GCPtr Start address.
429 * @param pfnInvalidateR3 The R3 invalidate callback (can be 0)
430 * @remarks Doesn't work with the hypervisor access handler type.
431 */
432VMMDECL(int) PGMHandlerVirtualChangeInvalidateCallback(PVM pVM, RTGCPTR GCPtr, PFNPGMR3VIRTINVALIDATE pfnInvalidateR3)
433{
434 pgmLock(pVM);
435 PPGMVIRTHANDLER pCur = (PPGMVIRTHANDLER)RTAvlroGCPtrGet(&pVM->pgm.s.pTreesR3->VirtHandlers, GCPtr);
436 if (pCur)
437 {
438 pCur->pfnInvalidateR3 = pfnInvalidateR3;
439 pgmUnlock(pVM);
440 return VINF_SUCCESS;
441 }
442 pgmUnlock(pVM);
443 AssertMsgFailed(("Range %#x not found!\n", GCPtr));
444 return VERR_INVALID_PARAMETER;
445}
446
447/**
448 * Deregister an access handler for a virtual range.
449 *
450 * @returns VBox status code.
451 * @param pVM VM handle.
452 * @param GCPtr Start address.
453 * @thread EMT
454 */
455VMMDECL(int) PGMHandlerVirtualDeregister(PVM pVM, RTGCPTR GCPtr)
456{
457 pgmLock(pVM);
458
459 /*
460 * Find the handler.
461 * We naturally assume GCPtr is a unique specification.
462 */
463 PPGMVIRTHANDLER pCur = (PPGMVIRTHANDLER)RTAvlroGCPtrRemove(&pVM->pgm.s.CTX_SUFF(pTrees)->VirtHandlers, GCPtr);
464 if (RT_LIKELY(pCur))
465 {
466 Log(("PGMHandlerVirtualDeregister: Removing Virtual (%d) Range %RGv-%RGv %s\n", pCur->enmType,
467 pCur->Core.Key, pCur->Core.KeyLast, pCur->pszDesc));
468 Assert(pCur->enmType != PGMVIRTHANDLERTYPE_HYPERVISOR);
469
470 /*
471 * Reset the flags and remove phys2virt nodes.
472 */
473 PPGM pPGM = &pVM->pgm.s;
474 for (unsigned iPage = 0; iPage < pCur->cPages; iPage++)
475 if (pCur->aPhysToVirt[iPage].offNextAlias & PGMPHYS2VIRTHANDLER_IN_TREE)
476 pgmHandlerVirtualClearPage(pPGM, pCur, iPage);
477
478 /*
479 * Schedule CR3 sync.
480 */
481 PVMCPU pVCpu = VMMGetCpu(pVM);
482
483 pVCpu->pgm.s.fSyncFlags |= PGM_SYNC_UPDATE_PAGE_BIT_VIRTUAL | PGM_SYNC_CLEAR_PGM_POOL;
484 VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
485 }
486 else
487 {
488 /* must be a hypervisor one then. */
489 pCur = (PPGMVIRTHANDLER)RTAvlroGCPtrRemove(&pVM->pgm.s.CTX_SUFF(pTrees)->HyperVirtHandlers, GCPtr);
490 if (RT_UNLIKELY(!pCur))
491 {
492 pgmUnlock(pVM);
493 AssertMsgFailed(("Range %#x not found!\n", GCPtr));
494 return VERR_INVALID_PARAMETER;
495 }
496
497 Log(("PGMHandlerVirtualDeregister: Removing Hyper Virtual (%d) Range %RGv-%RGv %s\n", pCur->enmType,
498 pCur->Core.Key, pCur->Core.KeyLast, pCur->pszDesc));
499 Assert(pCur->enmType == PGMVIRTHANDLERTYPE_HYPERVISOR);
500 }
501
502 pgmUnlock(pVM);
503
504 STAM_DEREG(pVM, &pCur->Stat);
505 MMHyperFree(pVM, pCur);
506
507 return VINF_SUCCESS;
508}
509
510
511/**
512 * Arguments for pgmR3InfoHandlersPhysicalOne and pgmR3InfoHandlersVirtualOne.
513 */
514typedef struct PGMHANDLERINFOARG
515{
516 /** The output helpers.*/
517 PCDBGFINFOHLP pHlp;
518 /** Set if statistics should be dumped. */
519 bool fStats;
520} PGMHANDLERINFOARG, *PPGMHANDLERINFOARG;
521
522
523/**
524 * Info callback for 'pgmhandlers'.
525 *
526 * @param pHlp The output helpers.
527 * @param pszArgs The arguments. phys or virt.
528 */
529DECLCALLBACK(void) pgmR3InfoHandlers(PVM pVM, PCDBGFINFOHLP pHlp, const char *pszArgs)
530{
531 /*
532 * Test input.
533 */
534 PGMHANDLERINFOARG Args = { pHlp, /* .fStats = */ true };
535 bool fPhysical = !pszArgs || !*pszArgs;
536 bool fVirtual = fPhysical;
537 bool fHyper = fPhysical;
538 if (!fPhysical)
539 {
540 bool fAll = strstr(pszArgs, "all") != NULL;
541 fPhysical = fAll || strstr(pszArgs, "phys") != NULL;
542 fVirtual = fAll || strstr(pszArgs, "virt") != NULL;
543 fHyper = fAll || strstr(pszArgs, "hyper")!= NULL;
544 Args.fStats = strstr(pszArgs, "nost") == NULL;
545 }
546
547 /*
548 * Dump the handlers.
549 */
550 if (fPhysical)
551 {
552 pHlp->pfnPrintf(pHlp,
553 "Physical handlers: (PhysHandlers=%d (%#x))\n"
554 "From - To (incl) HandlerHC UserHC HandlerGC UserGC Type Description\n",
555 pVM->pgm.s.pTreesR3->PhysHandlers, pVM->pgm.s.pTreesR3->PhysHandlers);
556 RTAvlroGCPhysDoWithAll(&pVM->pgm.s.pTreesR3->PhysHandlers, true, pgmR3InfoHandlersPhysicalOne, &Args);
557 }
558
559 if (fVirtual)
560 {
561 pHlp->pfnPrintf(pHlp,
562 "Virtual handlers:\n"
563 "From - To (excl) HandlerHC HandlerGC Type Description\n");
564 RTAvlroGCPtrDoWithAll(&pVM->pgm.s.pTreesR3->VirtHandlers, true, pgmR3InfoHandlersVirtualOne, &Args);
565 }
566
567 if (fHyper)
568 {
569 pHlp->pfnPrintf(pHlp,
570 "Hypervisor Virtual handlers:\n"
571 "From - To (excl) HandlerHC HandlerGC Type Description\n");
572 RTAvlroGCPtrDoWithAll(&pVM->pgm.s.pTreesR3->HyperVirtHandlers, true, pgmR3InfoHandlersVirtualOne, &Args);
573 }
574}
575
576
577/**
578 * Displays one physical handler range.
579 *
580 * @returns 0
581 * @param pNode Pointer to a PGMPHYSHANDLER.
582 * @param pvUser Pointer to command helper functions.
583 */
584static DECLCALLBACK(int) pgmR3InfoHandlersPhysicalOne(PAVLROGCPHYSNODECORE pNode, void *pvUser)
585{
586 PPGMPHYSHANDLER pCur = (PPGMPHYSHANDLER)pNode;
587 PPGMHANDLERINFOARG pArgs= (PPGMHANDLERINFOARG)pvUser;
588 PCDBGFINFOHLP pHlp = pArgs->pHlp;
589 const char *pszType;
590 switch (pCur->enmType)
591 {
592 case PGMPHYSHANDLERTYPE_MMIO: pszType = "MMIO "; break;
593 case PGMPHYSHANDLERTYPE_PHYSICAL_WRITE: pszType = "Write "; break;
594 case PGMPHYSHANDLERTYPE_PHYSICAL_ALL: pszType = "All "; break;
595 default: pszType = "????"; break;
596 }
597 pHlp->pfnPrintf(pHlp,
598 "%RGp - %RGp %RHv %RHv %RRv %RRv %s %s\n",
599 pCur->Core.Key, pCur->Core.KeyLast, pCur->pfnHandlerR3, pCur->pvUserR3, pCur->pfnHandlerRC, pCur->pvUserRC, pszType, pCur->pszDesc);
600#ifdef VBOX_WITH_STATISTICS
601 if (pArgs->fStats)
602 pHlp->pfnPrintf(pHlp, " cPeriods: %9RU64 cTicks: %11RU64 Min: %11RU64 Avg: %11RU64 Max: %11RU64\n",
603 pCur->Stat.cPeriods, pCur->Stat.cTicks, pCur->Stat.cTicksMin,
604 pCur->Stat.cPeriods ? pCur->Stat.cTicks / pCur->Stat.cPeriods : 0, pCur->Stat.cTicksMax);
605#endif
606 return 0;
607}
608
609
610/**
611 * Displays one virtual handler range.
612 *
613 * @returns 0
614 * @param pNode Pointer to a PGMVIRTHANDLER.
615 * @param pvUser Pointer to command helper functions.
616 */
617static DECLCALLBACK(int) pgmR3InfoHandlersVirtualOne(PAVLROGCPTRNODECORE pNode, void *pvUser)
618{
619 PPGMVIRTHANDLER pCur = (PPGMVIRTHANDLER)pNode;
620 PPGMHANDLERINFOARG pArgs= (PPGMHANDLERINFOARG)pvUser;
621 PCDBGFINFOHLP pHlp = pArgs->pHlp;
622 const char *pszType;
623 switch (pCur->enmType)
624 {
625 case PGMVIRTHANDLERTYPE_WRITE: pszType = "Write "; break;
626 case PGMVIRTHANDLERTYPE_ALL: pszType = "All "; break;
627 case PGMVIRTHANDLERTYPE_HYPERVISOR: pszType = "WriteHyp "; break;
628 default: pszType = "????"; break;
629 }
630 pHlp->pfnPrintf(pHlp, "%RGv - %RGv %RHv %RRv %s %s\n",
631 pCur->Core.Key, pCur->Core.KeyLast, pCur->pfnHandlerR3, pCur->pfnHandlerRC, pszType, pCur->pszDesc);
632#ifdef VBOX_WITH_STATISTICS
633 if (pArgs->fStats)
634 pHlp->pfnPrintf(pHlp, " cPeriods: %9RU64 cTicks: %11RU64 Min: %11RU64 Avg: %11RU64 Max: %11RU64\n",
635 pCur->Stat.cPeriods, pCur->Stat.cTicks, pCur->Stat.cTicksMin,
636 pCur->Stat.cPeriods ? pCur->Stat.cTicks / pCur->Stat.cPeriods : 0, pCur->Stat.cTicksMax);
637#endif
638 return 0;
639}
640
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