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