PGMR0.cpp revision 42c1972c22e09797b4b24afbd0ec114ed076c37c
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/* $Id$ */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/** @file
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * PGM - Page Manager and Monitor, Ring-0.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/*
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Copyright (C) 2007 Sun Microsystems, Inc.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * available from http://www.virtualbox.org. This file is free software;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * you can redistribute it and/or modify it under the terms of the GNU
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * General Public License (GPL) as published by the Free Software
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * additional information or have any questions.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/*******************************************************************************
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync* Header Files *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync*******************************************************************************/
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#define LOG_GROUP LOG_GROUP_PGM
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <VBox/pgm.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include "PGMInternal.h"
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <VBox/vm.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <VBox/log.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <VBox/err.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include <iprt/assert.h>
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync__BEGIN_DECLS
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#define PGM_BTH_NAME(name) PGM_BTH_NAME_32BIT_PROT(name)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include "PGMR0Bth.h"
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#undef PGM_BTH_NAME
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#define PGM_BTH_NAME(name) PGM_BTH_NAME_PAE_PROT(name)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include "PGMR0Bth.h"
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#undef PGM_BTH_NAME
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#define PGM_BTH_NAME(name) PGM_BTH_NAME_AMD64_PROT(name)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include "PGMR0Bth.h"
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#undef PGM_BTH_NAME
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#define PGM_BTH_NAME(name) PGM_BTH_NAME_EPT_PROT(name)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#include "PGMR0Bth.h"
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#undef PGM_BTH_NAME
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync__END_DECLS
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync/**
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Worker function for PGMR3PhysAllocateHandyPages and pgmPhysEnsureHandyPage.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @returns The following VBox status codes.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @retval VINF_SUCCESS on success. FF cleared.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @retval VINF_EM_NO_MEMORY if we're out of memory. The FF is set in this case.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @param pVM The VM handle.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * @remarks Must be called from within the PGM critical section. The caller
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * must clear the new pages.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsyncVMMR0DECL(int) PGMR0PhysAllocateHandyPages(PVM pVM)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync{
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(PDMCritSectIsOwner(&pVM->pgm.s.CritSect));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /*
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Check for error injection.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (RT_UNLIKELY(pVM->pgm.s.fErrInjHandyPages))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return VERR_NO_MEMORY;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /*
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Try allocate a full set of handy pages.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync uint32_t iFirst = pVM->pgm.s.cHandyPages;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync AssertReturn(iFirst <= RT_ELEMENTS(pVM->pgm.s.aHandyPages), VERR_INTERNAL_ERROR);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync uint32_t cPages = RT_ELEMENTS(pVM->pgm.s.aHandyPages) - iFirst;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (!cPages)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return VINF_SUCCESS;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync int rc = GMMR0AllocateHandyPages(pVM, cPages, cPages, &pVM->pgm.s.aHandyPages[iFirst]);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (RT_SUCCESS(rc))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync for (uint32_t i = 0; i < RT_ELEMENTS(pVM->pgm.s.aHandyPages); i++)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pgm.s.aHandyPages[i].idPage != NIL_GMM_PAGEID);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pgm.s.aHandyPages[i].idPage <= GMM_PAGEID_LAST);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pgm.s.aHandyPages[i].idSharedPage == NIL_GMM_PAGEID);
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync Assert(pVM->pgm.s.aHandyPages[i].HCPhysGCPhys != NIL_RTHCPHYS);
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync Assert(!(pVM->pgm.s.aHandyPages[i].HCPhysGCPhys & ~X86_PTE_PAE_PG_MASK));
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync pVM->pgm.s.cHandyPages = RT_ELEMENTS(pVM->pgm.s.aHandyPages);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync else if (rc != VERR_GMM_SEED_ME)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync if ( ( rc == VERR_GMM_HIT_GLOBAL_LIMIT
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync || rc == VERR_GMM_HIT_VM_ACCOUNT_LIMIT)
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync && iFirst < PGM_HANDY_PAGES_MIN)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync#ifdef VBOX_STRICT
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync /* We're ASSUMING that GMM has updated all the entires before failing us. */
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync uint32_t i;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync for (i = iFirst; i < RT_ELEMENTS(pVM->pgm.s.aHandyPages); i++)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pgm.s.aHandyPages[i].idPage == NIL_GMM_PAGEID);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pgm.s.aHandyPages[i].idSharedPage == NIL_GMM_PAGEID);
476493afbafe452ee52b3b3b2bb77e07e5e56285vboxsync Assert(pVM->pgm.s.aHandyPages[i].HCPhysGCPhys == NIL_RTHCPHYS);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /*
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Reduce the number of pages until we hit the minimum limit.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
dc45a8f3e936581748c248e00ce572cfe3ea331evboxsync do
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync cPages >>= 2;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (cPages + iFirst < PGM_HANDY_PAGES_MIN)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync cPages = PGM_HANDY_PAGES_MIN - iFirst;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = GMMR0AllocateHandyPages(pVM, cPages, cPages, &pVM->pgm.s.aHandyPages[iFirst]);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync } while ( ( rc == VERR_GMM_HIT_GLOBAL_LIMIT
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync || rc == VERR_GMM_HIT_VM_ACCOUNT_LIMIT)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync && cPages + iFirst > PGM_HANDY_PAGES_MIN);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (RT_SUCCESS(rc))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#ifdef VBOX_STRICT
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync i = iFirst + cPages;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync while (i-- > 0)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pgm.s.aHandyPages[i].idPage != NIL_GMM_PAGEID);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pgm.s.aHandyPages[i].idPage <= GMM_PAGEID_LAST);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pgm.s.aHandyPages[i].idSharedPage == NIL_GMM_PAGEID);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pgm.s.aHandyPages[i].HCPhysGCPhys != NIL_RTHCPHYS);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync Assert(!(pVM->pgm.s.aHandyPages[i].HCPhysGCPhys & ~X86_PTE_PAE_PG_MASK));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync for (i = cPages + iFirst; i < RT_ELEMENTS(pVM->pgm.s.aHandyPages); i++)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync Assert(pVM->pgm.s.aHandyPages[i].idPage == NIL_GMM_PAGEID);
87c5113417e917cdf64545d4f8e0a27047cea783vboxsync Assert(pVM->pgm.s.aHandyPages[i].idSharedPage == NIL_GMM_PAGEID);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync Assert(pVM->pgm.s.aHandyPages[i].HCPhysGCPhys == NIL_RTHCPHYS);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync }
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#endif
476493afbafe452ee52b3b3b2bb77e07e5e56285vboxsync
81c6115ff3bb02e166ee8f762d30c4ba5e3db08avboxsync pVM->pgm.s.cHandyPages = iFirst + cPages;
81c6115ff3bb02e166ee8f762d30c4ba5e3db08avboxsync }
81c6115ff3bb02e166ee8f762d30c4ba5e3db08avboxsync }
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (RT_FAILURE(rc) && rc != VERR_GMM_SEED_ME)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync LogRel(("PGMR0PhysAllocateHandyPages: rc=%Rrc iFirst=%d cPages=%d\n", rc, iFirst, cPages));
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync VM_FF_SET(pVM, VM_FF_PGM_NO_MEMORY);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync LogFlow(("PGMR0PhysAllocateHandyPages: cPages=%d rc=%Rrc\n", cPages, rc));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync return rc;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync}
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync/**
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * #PF Handler for nested paging.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync *
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @returns VBox status code (appropriate for trap handling and GC return).
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pVM VM Handle.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pVCpu VMCPU Handle.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param enmShwPagingMode Paging mode for the nested page tables
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param uErr The trap error code.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pRegFrame Trap register frame.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * @param pvFault The fault address.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsyncVMMR0DECL(int) PGMR0Trap0eHandlerNestedPaging(PVM pVM, PVMCPU pVCpu, PGMMODE enmShwPagingMode, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPHYS pvFault)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync{
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync int rc;
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync LogFlow(("PGMTrap0eHandler: uErr=%#x pvFault=%RGp eip=%RGv\n", uErr, pvFault, (RTGCPTR)pRegFrame->rip));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync STAM_PROFILE_START(&pVCpu->pgm.s.StatRZTrap0e, a);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync STAM_STATS({ pVCpu->pgm.s.CTX_SUFF(pStatTrap0eAttribution) = NULL; } );
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync /* AMD uses the host's paging mode; Intel has a single mode (EPT). */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync AssertMsg(enmShwPagingMode == PGMMODE_32_BIT || enmShwPagingMode == PGMMODE_PAE || enmShwPagingMode == PGMMODE_PAE_NX || enmShwPagingMode == PGMMODE_AMD64 || enmShwPagingMode == PGMMODE_AMD64_NX || enmShwPagingMode == PGMMODE_EPT, ("enmShwPagingMode=%d\n", enmShwPagingMode));
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync#ifdef VBOX_WITH_STATISTICS
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync /*
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync * Error code stats.
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync */
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (uErr & X86_TRAP_PF_US)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync {
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (!(uErr & X86_TRAP_PF_P))
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync {
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync if (uErr & X86_TRAP_PF_RW)
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync STAM_COUNTER_INC(&pVCpu->pgm.s.StatRZTrap0eUSNotPresentWrite);
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync else
50671c30431539dd7d6ff6a5f2ceb6c9f9f471b2vboxsync STAM_COUNTER_INC(&pVCpu->pgm.s.StatRZTrap0eUSNotPresentRead);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync else if (uErr & X86_TRAP_PF_RW)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync STAM_COUNTER_INC(&pVCpu->pgm.s.StatRZTrap0eUSWrite);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync else if (uErr & X86_TRAP_PF_RSVD)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync STAM_COUNTER_INC(&pVCpu->pgm.s.StatRZTrap0eUSReserved);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync else if (uErr & X86_TRAP_PF_ID)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync STAM_COUNTER_INC(&pVCpu->pgm.s.StatRZTrap0eUSNXE);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync else
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync STAM_COUNTER_INC(&pVCpu->pgm.s.StatRZTrap0eUSRead);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync else
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync { /* Supervisor */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (!(uErr & X86_TRAP_PF_P))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (uErr & X86_TRAP_PF_RW)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync STAM_COUNTER_INC(&pVCpu->pgm.s.StatRZTrap0eSVNotPresentWrite);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync else
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync STAM_COUNTER_INC(&pVCpu->pgm.s.StatRZTrap0eSVNotPresentRead);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync else if (uErr & X86_TRAP_PF_RW)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync STAM_COUNTER_INC(&pVCpu->pgm.s.StatRZTrap0eSVWrite);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync else if (uErr & X86_TRAP_PF_ID)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync STAM_COUNTER_INC(&pVCpu->pgm.s.StatRZTrap0eSNXE);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync else if (uErr & X86_TRAP_PF_RSVD)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync STAM_COUNTER_INC(&pVCpu->pgm.s.StatRZTrap0eSVReserved);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync#endif
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync /*
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * Call the worker.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync *
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * We pretend the guest is in protected mode without paging, so we can use existing code to build the
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync * nested page tables.
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync */
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync switch(enmShwPagingMode)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync {
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync case PGMMODE_32_BIT:
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = PGM_BTH_NAME_32BIT_PROT(Trap0eHandler)(pVM, pVCpu, uErr, pRegFrame, pvFault);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync break;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync case PGMMODE_PAE:
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync case PGMMODE_PAE_NX:
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = PGM_BTH_NAME_PAE_PROT(Trap0eHandler)(pVM, pVCpu, uErr, pRegFrame, pvFault);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync break;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync case PGMMODE_AMD64:
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync case PGMMODE_AMD64_NX:
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = PGM_BTH_NAME_AMD64_PROT(Trap0eHandler)(pVM, pVCpu, uErr, pRegFrame, pvFault);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync break;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync case PGMMODE_EPT:
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = PGM_BTH_NAME_EPT_PROT(Trap0eHandler)(pVM, pVCpu, uErr, pRegFrame, pvFault);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync break;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync default:
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync AssertFailed();
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = VERR_INVALID_PARAMETER;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync break;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync }
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync if (rc == VINF_PGM_SYNCPAGE_MODIFIED_PDE)
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync rc = VINF_SUCCESS;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync STAM_STATS({ if (!pVCpu->pgm.s.CTX_SUFF(pStatTrap0eAttribution))
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync pVCpu->pgm.s.CTX_SUFF(pStatTrap0eAttribution) = &pVCpu->pgm.s.StatRZTrap0eTime2Misc; });
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync STAM_PROFILE_STOP_EX(&pVCpu->pgm.s.StatRZTrap0e, pVCpu->pgm.s.CTX_SUFF(pStatTrap0eAttribution), a);
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync return rc;
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync}
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync
9888fffcfbe2d41dce14a1249b12cb88cc9b149fvboxsync