VMMR0.cpp revision 321de479bc1f555103582dbf308df2ec9d271d62
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/* $Id$ */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/** @file
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * VMM - Host Context Ring 0.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Copyright (C) 2006-2007 Oracle Corporation
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * available from http://www.virtualbox.org. This file is free software;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * General Public License (GPL) as published by the Free Software
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*******************************************************************************
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync* Header Files *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync*******************************************************************************/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#define LOG_GROUP LOG_GROUP_VMM
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/vmm.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/sup.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/trpm.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/cpum.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/pdmapi.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/pgm.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/stam.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/tm.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include "VMMInternal.h"
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/vm.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/gvmm.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/gmm.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <VBox/intnet.h>
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#include <VBox/hwaccm.h>
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#include <VBox/param.h>
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#include <VBox/err.h>
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#include <VBox/version.h>
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#include <VBox/log.h>
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <iprt/asm-amd64-x86.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <iprt/assert.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <iprt/crc32.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <iprt/mp.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <iprt/stdarg.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#include <iprt/string.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_VMMR0_DISABLE_PREEMPTION
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync# include <iprt/thread.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#if defined(_MSC_VER) && defined(RT_ARCH_AMD64) /** @todo check this with with VC7! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync# pragma intrinsic(_AddressOfReturnAddress)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*******************************************************************************
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync* Internal Functions *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync*******************************************************************************/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncRT_C_DECLS_BEGIN
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMR0DECL(int) ModuleInit(void);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMR0DECL(void) ModuleTerm(void);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncRT_C_DECLS_END
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*******************************************************************************
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync* Global Variables *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync*******************************************************************************/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/** Drag in necessary library bits.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * The runtime lives here (in VMMR0.r0) and VBoxDD*R0.r0 links against us. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncPFNRT g_VMMGCDeps[] =
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync (PFNRT)RTCrc32
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync};
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Initialize the module.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This is called when we're first loaded.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns 0 on success.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status on failure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMR0DECL(int) ModuleInit(void)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlow(("ModuleInit:\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Initialize the GVMM, GMM, HWACCM, PGM (Darwin) and INTNET.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = GVMMR0Init();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = GMMR0Init();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = HWACCMR0Init();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = PGMRegisterStringFormatTypes();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = PGMR0DynMapInit();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = IntNetR0Init();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlow(("ModuleInit: returns success.\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VINF_SUCCESS;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* bail out */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlow(("ModuleTerm: returns %Rrc\n", rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PGMR0DynMapTerm();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PGMDeregisterStringFormatTypes();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HWACCMR0Term();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GMMR0Term();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync GVMMR0Term();
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlow(("ModuleInit: failed %Rrc\n", rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Terminate the module.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This is called when we're finally unloaded.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMR0DECL(void) ModuleTerm(void)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlow(("ModuleTerm:\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Terminate the internal network service.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync IntNetR0Term();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * PGM (Darwin) and HWACCM global cleanup.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PGMR0DynMapTerm();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PGMDeregisterStringFormatTypes();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HWACCMR0Term();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Destroy the GMM and GVMM instances.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GMMR0Term();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GVMMR0Term();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlow(("ModuleTerm: returns\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Initaties the R0 driver for a particular VM instance.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM instance in question.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param uSvnRev The SVN revision of the ring-3 part.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @thread EMT.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic int vmmR0InitVM(PVM pVM, uint32_t uSvnRev)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Match the SVN revisions.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (uSvnRev != VMMGetSvnRev())
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogRel(("VMMR0InitVM: Revision mismatch, r3=%d r0=%d\n", uSvnRev, VMMGetSvnRev()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync SUPR0Printf("VMMR0InitVM: Revision mismatch, r3=%d r0=%d\n", uSvnRev, VMMGetSvnRev());
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_VERSION_MISMATCH;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( !VALID_PTR(pVM)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || pVM->pVMR0 != pVM)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef LOG_ENABLED
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Register the EMT R0 logger instance for VCPU 0.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PVMCPU pVCpu = &pVM->aCpus[0];
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PVMMR0LOGGER pR0Logger = pVCpu->vmm.s.pR0LoggerR0;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pR0Logger)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync# if 0 /* testing of the logger. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: before %p\n", RTLogDefaultInstance()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: pfnFlush=%p actual=%p\n", pR0Logger->Logger.pfnFlush, vmmR0LoggerFlush));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: pfnLogger=%p actual=%p\n", pR0Logger->Logger.pfnLogger, vmmR0LoggerWrapper));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: offScratch=%d fFlags=%#x fDestFlags=%#x\n", pR0Logger->Logger.offScratch, pR0Logger->Logger.fFlags, pR0Logger->Logger.fDestFlags));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: after %p reg\n", RTLogDefaultInstance()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(NULL, pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: after %p dereg\n", RTLogDefaultInstance()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: returned succesfully from direct logger call.\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pR0Logger->Logger.pfnFlush(&pR0Logger->Logger);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: returned succesfully from direct flush call.\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: after %p reg2\n", RTLogDefaultInstance()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: returned succesfully from direct logger call (2). offScratch=%d\n", pR0Logger->Logger.offScratch));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(NULL, pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: after %p dereg2\n", RTLogDefaultInstance()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogLoggerEx(&pR0Logger->Logger, 0, ~0U, "hello ring-0 logger (RTLogLoggerEx)\n");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: RTLogLoggerEx returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogPrintf("hello ring-0 logger (RTLogPrintf)\n");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogCom(("vmmR0InitVM: RTLogPrintf returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync# endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Log(("Switching to per-thread logging instance %p (key=%p)\n", &pR0Logger->Logger, pVM->pSession));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pR0Logger->fRegistered = true;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif /* LOG_ENABLED */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Initialize the per VM data for GVMM and GMM.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = GVMMR0InitVM(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync// if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync// rc = GMMR0InitPerVMData(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Init HWACCM, CPUM and PGM (Darwin only).
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = HWACCMR0InitVM(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = CPUMR0Init(pVM); /** @todo rename to CPUMR0InitVM */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = PGMR0DynMapInitVM(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GVMMR0DoneInitVM(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* bail out */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HWACCMR0TermVM(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(NULL, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Terminates the R0 driver for a particular VM instance.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * This is normally called by ring-3 as part of the VM termination process, but
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * may alternatively be called during the support driver session cleanup when
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * the VM object is destroyed (see GVMM).
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM instance in question.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pGVM Pointer to the global VM structure. Optional.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @thread EMT or session clean up thread.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMR0DECL(int) VMMR0TermVM(PVM pVM, PGVM pGVM)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Tell GVMM what we're up to and check that we only do this once.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (GVMMR0DoingTermVM(pVM, pGVM))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PGMR0DynMapTermVM(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HWACCMR0TermVM(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Deregister the logger.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(NULL, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VINF_SUCCESS;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_STATISTICS
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Record return code statistics
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM handle.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVCpu The VMCPU handle.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param rc The status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic void vmmR0RecordRC(PVM pVM, PVMCPU pVCpu, int rc)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Collect statistics.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync switch (rc)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_SUCCESS:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetNormal);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_INTERRUPT:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterrupt);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_INTERRUPT_HYPER:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptHyper);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_GUEST_TRAP:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetGuestTrap);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_RING_SWITCH:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRingSwitch);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_RING_SWITCH_INT:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRingSwitchInt);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_STALE_SELECTOR:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetStaleSelector);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_IRET_TRAP:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIRETTrap);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_IOM_HC_IOPORT_READ:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIORead);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_IOM_HC_IOPORT_WRITE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIOWrite);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_IOM_HC_MMIO_READ:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIORead);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_IOM_HC_MMIO_WRITE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOWrite);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_IOM_HC_MMIO_READ_WRITE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOReadWrite);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_PATM_HC_MMIO_PATCH_READ:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchRead);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_PATM_HC_MMIO_PATCH_WRITE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchWrite);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_EMULATE_INSTR:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetEmulate);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_EMULATE_IO_BLOCK:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIOBlockEmulate);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_PATCH_EMULATE_INSTR:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchEmulate);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_EMULATE_INSTR_LDT_FAULT:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetLDTFault);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetGDTFault);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_EMULATE_INSTR_IDT_FAULT:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIDTFault);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_EMULATE_INSTR_TSS_FAULT:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetTSSFault);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_EMULATE_INSTR_PD_FAULT:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPDFault);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_CSAM_PENDING_ACTION:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetCSAMTask);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_PGM_SYNC_CR3:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetSyncCR3);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_PATM_PATCH_INT3:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchInt3);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_PATM_PATCH_TRAP_PF:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchPF);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_PATM_PATCH_TRAP_GP:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchGP);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_PATM_PENDING_IRQ_AFTER_IRET:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchIretIRQ);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RESCHEDULE_REM:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRescheduleREM);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_TO_R3:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_TIMER_PENDING:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetTimerPending);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_RAW_INTERRUPT_PENDING:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptPending);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_VMM_CALL_HOST:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync switch (pVCpu->vmm.s.enmCallRing3Operation)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_PDM_LOCK:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPDMLock);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_PDM_QUEUE_FLUSH:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPDMQueueFlush);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_PGM_POOL_GROW:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMPoolGrow);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_PGM_LOCK:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMLock);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_PGM_MAP_CHUNK:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMMapChunk);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_PGM_ALLOCATE_HANDY_PAGES:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMAllocHandy);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_REM_REPLAY_HANDLER_NOTIFICATIONS:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallRemReplay);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_VMM_LOGGER_FLUSH:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallLogFlush);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_VM_SET_ERROR:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetError);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_VM_SET_RUNTIME_ERROR:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetRuntimeError);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMCALLRING3_VM_R0_ASSERTION:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync default:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetCallRing3);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_PATM_DUPLICATE_FUNCTION:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPATMDuplicateFn);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_PGM_CHANGE_MODE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPGMChangeMode);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_PGM_POOL_FLUSH_PENDING:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPGMFlushPending);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_PENDING_REQUEST:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPendingRequest);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VINF_EM_HWACCM_PATCH_TPR_INSTR:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchTPR);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync default:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMisc);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif /* VBOX_WITH_STATISTICS */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Unused ring-0 entry point that used to be called from the interrupt gate.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Will be removed one of the next times we do a major SUPDrv version bump.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM to operate on.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param enmOperation Which operation to execute.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pvArg Argument to the operation.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @remarks Assume called with interrupts disabled.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMR0DECL(int) VMMR0EntryInt(PVM pVM, VMMR0OPERATION enmOperation, void *pvArg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * We're returning VERR_NOT_SUPPORT here so we've got something else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * than -1 which the interrupt gate glue code might return.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Log(("operation %#x is not supported\n", enmOperation));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_NOT_SUPPORTED;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * The Ring 0 entry point, called by the fast-ioctl path.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM to operate on.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * The return code is stored in pVM->vmm.s.iLastGZRc.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param idCpu The Virtual CPU ID of the calling EMT.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param enmOperation Which operation to execute.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @remarks Assume called with interrupts _enabled_.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMR0DECL(void) VMMR0EntryFast(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_UNLIKELY(idCpu >= pVM->cCpus))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PVMCPU pVCpu = &pVM->aCpus[idCpu];
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync switch (enmOperation)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Switch to GC and run guest raw mode code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Disable interrupts before doing the world switch.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_RAW_RUN:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Safety precaution as hwaccm disables the switcher. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_LIKELY(!pVM->vmm.s.fSwitcherDisabled))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTCCUINTREG uFlags = ASMIntDisableFlags();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync bool fVTxDisabled;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_UNLIKELY(pVM->cCpus > 1))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVCpu->vmm.s.iLastGZRc = VERR_RAW_MODE_INVALID_SMP;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMSetFlags(uFlags);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifndef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_UNLIKELY(!PGMGetHyperCR3(pVCpu)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVCpu->vmm.s.iLastGZRc = VERR_PGM_NO_CR3_SHADOW_ROOT;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMSetFlags(uFlags);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* We might need to disable VT-x if the active switcher turns off paging. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = HWACCMR0EnterSwitcher(pVM, &fVTxDisabled);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVCpu->vmm.s.iLastGZRc = rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMSetFlags(uFlags);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, RTMpCpuId());
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED_EXEC);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync TMNotifyStartOfExecution(pVCpu);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pVM->vmm.s.pfnHostToGuestR0(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVCpu->vmm.s.iLastGZRc = rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync TMNotifyEndOfExecution(pVCpu);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, NIL_RTCPUID);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Re-enable VT-x if previously turned off. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HWACCMR0LeaveSwitcher(pVM, fVTxDisabled);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( rc == VINF_EM_RAW_INTERRUPT
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || rc == VINF_EM_RAW_INTERRUPT_HYPER)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync TRPMR0DispatchHostInterrupt(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMSetFlags(uFlags);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_STATISTICS
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRunRC);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync vmmR0RecordRC(pVM, pVCpu, rc);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(!pVM->vmm.s.fSwitcherDisabled);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVCpu->vmm.s.iLastGZRc = VERR_NOT_SUPPORTED;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Run guest code using the available hardware acceleration technology.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Disable interrupts before we do anything interesting. On Windows we avoid
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * this by having the support driver raise the IRQL before calling us, this way
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * we hope to get away with page faults and later calling into the kernel.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_HWACC_RUN:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRunRC);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_VMMR0_DISABLE_PREEMPTION
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTThreadPreemptDisable(&PreemptState);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#elif !defined(RT_OS_WINDOWS)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTCCUINTREG uFlags = ASMIntDisableFlags();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, RTMpCpuId());
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef LOG_ENABLED
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pVCpu->idCpu > 0)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Lazy registration of ring 0 loggers. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PVMMR0LOGGER pR0Logger = pVCpu->vmm.s.pR0LoggerR0;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( pR0Logger
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync && !pR0Logger->fRegistered)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pR0Logger->fRegistered = true;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (!HWACCMR0SuspendPending())
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = HWACCMR0Enter(pVM, pVCpu);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = vmmR0CallRing3SetJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, HWACCMR0RunGuestCode, pVM, pVCpu); /* this may resume code. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc2 = HWACCMR0Leave(pVM, pVCpu);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AssertRC(rc2);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* System is about to go into suspend mode; go back to ring 3. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = VINF_EM_RAW_INTERRUPT;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVCpu->vmm.s.iLastGZRc = rc;
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, NIL_RTCPUID);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_VMMR0_DISABLE_PREEMPTION
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTThreadPreemptRestore(&PreemptState);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#elif !defined(RT_OS_WINDOWS)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMSetFlags(uFlags);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_STATISTICS
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync vmmR0RecordRC(pVM, pVCpu, rc);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* No special action required for external interrupts, just return. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * For profiling.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_NOP:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVCpu->vmm.s.iLastGZRc = VINF_SUCCESS;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Impossible.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync default:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync AssertMsgFailed(("%#x\n", enmOperation));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVCpu->vmm.s.iLastGZRc = VERR_NOT_SUPPORTED;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync break;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Validates a session or VM session argument.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns true / false accordingly.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM argument.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pSession The session argument.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncDECLINLINE(bool) vmmR0IsValidSession(PVM pVM, PSUPDRVSESSION pClaimedSession, PSUPDRVSESSION pSession)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* This must be set! */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (!pSession)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return false;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Only one out of the two. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pVM && pClaimedSession)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return false;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pVM)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pClaimedSession = pVM->pSession;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return pClaimedSession == pSession;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * VMMR0EntryEx worker function, either called directly or when ever possible
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * called thru a longjmp so we can exit safely on failure.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns VBox status code.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pVM The VM to operate on.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param idCpu Virtual CPU ID argument. Must be NIL_VMCPUID if pVM
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * is NIL_RTR0PTR, and may be NIL_VMCPUID if it isn't
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param enmOperation Which operation to execute.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pReqHdr This points to a SUPVMMR0REQHDR packet. Optional.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * The support driver validates this if it's present.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param u64Arg Some simple constant argument.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @param pSession The session of the caller.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @remarks Assume called with interrupts _enabled_.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic int vmmR0EntryExWorker(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReqHdr, uint64_t u64Arg, PSUPDRVSESSION pSession)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Common VM pointer validation.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pVM)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_UNLIKELY( !VALID_PTR(pVM)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || ((uintptr_t)pVM & PAGE_OFFSET_MASK)))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p! (op=%d)\n", pVM, enmOperation);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_POINTER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_UNLIKELY( pVM->enmVMState < VMSTATE_CREATING
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || pVM->enmVMState > VMSTATE_TERMINATED
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || pVM->pVMR0 != pVM))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p:{enmVMState=%d, .pVMR0=%p}! (op=%d)\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVM, pVM->enmVMState, pVM->pVMR0, enmOperation);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_POINTER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_UNLIKELY(idCpu >= pVM->cCpus && idCpu != NIL_VMCPUID))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid idCpu (%u vs cCpus=%u)\n", idCpu, pVM->cCpus);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else if (RT_UNLIKELY(idCpu != NIL_VMCPUID))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid idCpu=%u\n", idCpu);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync switch (enmOperation)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * GVM requests
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GVMM_CREATE_VM:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pVM || u64Arg || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0CreateVMReq((PGVMMCREATEVMREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GVMM_DESTROY_VM:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pReqHdr || u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0DestroyVM(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GVMM_REGISTER_VMCPU:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (!pVM)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0RegisterVCpu(pVM, idCpu);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GVMM_SCHED_HALT:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pReqHdr)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0SchedHalt(pVM, idCpu, u64Arg);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GVMM_SCHED_WAKE_UP:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pReqHdr || u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0SchedWakeUp(pVM, idCpu);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GVMM_SCHED_POKE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pReqHdr || u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0SchedPoke(pVM, idCpu);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GVMM_SCHED_WAKE_UP_AND_POKE_CPUS:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0SchedWakeUpAndPokeCpusReq(pVM, (PGVMMSCHEDWAKEUPANDPOKECPUSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GVMM_SCHED_POLL:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pReqHdr || u64Arg > 1)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0SchedPoll(pVM, idCpu, !!u64Arg);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GVMM_QUERY_STATISTICS:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0QueryStatisticsReq(pVM, (PGVMMQUERYSTATISTICSSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GVMM_RESET_STATISTICS:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0ResetStatisticsReq(pVM, (PGVMMRESETSTATISTICSSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Initialize the R0 part of a VM instance.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_VMMR0_INIT:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return vmmR0InitVM(pVM, (uint32_t)u64Arg);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Terminate the R0 part of a VM instance.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_VMMR0_TERM:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VMMR0TermVM(pVM, NULL);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Attempt to enable hwacc mode and check the current setting.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_HWACC_ENABLE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return HWACCMR0EnableAllCpus(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Setup the hardware accelerated session.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_HWACC_SETUP_VM:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTCCUINTREG fFlags = ASMIntDisableFlags();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = HWACCMR0SetupVM(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMSetFlags(fFlags);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Switch to RC to execute Hypervisor function.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_CALL_HYPERVISOR:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync bool fVTxDisabled;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Safety precaution as HWACCM can disable the switcher. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync Assert(!pVM->vmm.s.fSwitcherDisabled);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_UNLIKELY(pVM->vmm.s.fSwitcherDisabled))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_NOT_SUPPORTED;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifndef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_UNLIKELY(!PGMGetHyperCR3(VMMGetCpu0(pVM))))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_PGM_NO_CR3_SHADOW_ROOT;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTCCUINTREG fFlags = ASMIntDisableFlags();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* We might need to disable VT-x if the active switcher turns off paging. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = HWACCMR0EnterSwitcher(pVM, &fVTxDisabled);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = pVM->vmm.s.pfnHostToGuestR0(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Re-enable VT-x if previously turned off. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HWACCMR0LeaveSwitcher(pVM, fVTxDisabled);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo dispatch interrupts? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMSetFlags(fFlags);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * PGM wrappers.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_PGM_ALLOCATE_HANDY_PAGES:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (idCpu == NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_CPU_ID;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return PGMR0PhysAllocateHandyPages(pVM, &pVM->aCpus[idCpu]);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_PGM_ALLOCATE_LARGE_HANDY_PAGE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (idCpu == NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_CPU_ID;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return PGMR0PhysAllocateLargeHandyPage(pVM, &pVM->aCpus[idCpu]);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * GMM wrappers.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_INITIAL_RESERVATION:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0InitialReservationReq(pVM, idCpu, (PGMMINITIALRESERVATIONREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_UPDATE_RESERVATION:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0UpdateReservationReq(pVM, idCpu, (PGMMUPDATERESERVATIONREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_ALLOCATE_PAGES:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0AllocatePagesReq(pVM, idCpu, (PGMMALLOCATEPAGESREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_FREE_PAGES:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0FreePagesReq(pVM, idCpu, (PGMMFREEPAGESREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_FREE_LARGE_PAGE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0FreeLargePageReq(pVM, idCpu, (PGMMFREELARGEPAGEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_QUERY_HYPERVISOR_MEM_STATS:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0QueryHypervisorMemoryStatsReq(pVM, (PGMMMEMSTATSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_QUERY_MEM_STATS:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (idCpu == NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_CPU_ID;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0QueryMemoryStatsReq(pVM, idCpu, (PGMMMEMSTATSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_BALLOONED_PAGES:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0BalloonedPagesReq(pVM, idCpu, (PGMMBALLOONEDPAGESREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_MAP_UNMAP_CHUNK:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0MapUnmapChunkReq(pVM, idCpu, (PGMMMAPUNMAPCHUNKREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_SEED_CHUNK:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pReqHdr)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0SeedChunk(pVM, idCpu, (RTR3PTR)u64Arg);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_REGISTER_SHARED_MODULE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (idCpu == NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_CPU_ID;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0RegisterSharedModuleReq(pVM, idCpu, (PGMMREGISTERSHAREDMODULEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_UNREGISTER_SHARED_MODULE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (idCpu == NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_CPU_ID;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0UnregisterSharedModuleReq(pVM, idCpu, (PGMMUNREGISTERSHAREDMODULEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_RESET_SHARED_MODULES:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (idCpu == NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_CPU_ID;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( u64Arg
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || pReqHdr)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GMMR0ResetSharedModules(pVM, idCpu);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_PAGE_SHARING
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_CHECK_SHARED_MODULES:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (idCpu == NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_CPU_ID;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ( u64Arg
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || pReqHdr)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PVMCPU pVCpu = &pVM->aCpus[idCpu];
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Select a valid VCPU context. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, RTMpCpuId());
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = vmmR0CallRing3SetJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, GMMR0CheckSharedModules, pVM, pVCpu); /* this may resume code. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Clear the VCPU context. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, NIL_RTCPUID);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * A quick GCFGM mock-up.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo GCFGM with proper access control, ring-3 management interface and all that. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GCFGM_SET_VALUE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GCFGM_QUERY_VALUE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PGCFGMVALUEREQ pReq = (PGCFGMVALUEREQ)pReqHdr;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pReq->Hdr.cbReq != sizeof(*pReq))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (enmOperation == VMMR0_DO_GCFGM_SET_VALUE)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = GVMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync // rc = GMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync else
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync rc = GVMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync // rc = GMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * PDM Wrappers.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_PDM_DRIVER_CALL_REQ_HANDLER:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (!pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return PDMR0DriverCallReqHandler(pVM, (PPDMDRIVERCALLREQHANDLERREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Requests to the internal networking service.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_INTNET_OPEN:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PINTNETOPENREQ pReq = (PINTNETOPENREQ)pReqHdr;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReq || !vmmR0IsValidSession(pVM, pReq->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0OpenReq(pSession, pReq);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_INTNET_IF_CLOSE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFCLOSEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfCloseReq(pSession, (PINTNETIFCLOSEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_INTNET_IF_GET_BUFFER_PTRS:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFGETBUFFERPTRSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfGetBufferPtrsReq(pSession, (PINTNETIFGETBUFFERPTRSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfSetPromiscuousModeReq(pSession, (PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_INTNET_IF_SET_MAC_ADDRESS:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETMACADDRESSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfSetMacAddressReq(pSession, (PINTNETIFSETMACADDRESSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_INTNET_IF_SET_ACTIVE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETACTIVEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfSetActiveReq(pSession, (PINTNETIFSETACTIVEREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_INTNET_IF_SEND:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSENDREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfSendReq(pSession, (PINTNETIFSENDREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_INTNET_IF_WAIT:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return IntNetR0IfWaitReq(pSession, (PINTNETIFWAITREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * For profiling.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_NOP:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_SLOW_NOP:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VINF_SUCCESS;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * For testing Ring-0 APIs invoked in this environment.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_TESTS:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo make new test */
return VINF_SUCCESS;
#if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
case VMMR0_DO_TEST_SWITCHER3264:
if (idCpu == NIL_VMCPUID)
return VERR_INVALID_CPU_ID;
return HWACCMR0TestSwitcher3264(pVM);
#endif
default:
/*
* We're returning VERR_NOT_SUPPORT here so we've got something else
* than -1 which the interrupt gate glue code might return.
*/
Log(("operation %#x is not supported\n", enmOperation));
return VERR_NOT_SUPPORTED;
}
}
/**
* Argument for vmmR0EntryExWrapper containing the arguments for VMMR0EntryEx.
*/
typedef struct VMMR0ENTRYEXARGS
{
PVM pVM;
VMCPUID idCpu;
VMMR0OPERATION enmOperation;
PSUPVMMR0REQHDR pReq;
uint64_t u64Arg;
PSUPDRVSESSION pSession;
} VMMR0ENTRYEXARGS;
/** Pointer to a vmmR0EntryExWrapper argument package. */
typedef VMMR0ENTRYEXARGS *PVMMR0ENTRYEXARGS;
/**
* This is just a longjmp wrapper function for VMMR0EntryEx calls.
*
* @returns VBox status code.
* @param pvArgs The argument package
*/
static int vmmR0EntryExWrapper(void *pvArgs)
{
return vmmR0EntryExWorker(((PVMMR0ENTRYEXARGS)pvArgs)->pVM,
((PVMMR0ENTRYEXARGS)pvArgs)->idCpu,
((PVMMR0ENTRYEXARGS)pvArgs)->enmOperation,
((PVMMR0ENTRYEXARGS)pvArgs)->pReq,
((PVMMR0ENTRYEXARGS)pvArgs)->u64Arg,
((PVMMR0ENTRYEXARGS)pvArgs)->pSession);
}
/**
* The Ring 0 entry point, called by the support library (SUP).
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param idCpu Virtual CPU ID argument. Must be NIL_VMCPUID if pVM
* is NIL_RTR0PTR, and may be NIL_VMCPUID if it isn't
* @param enmOperation Which operation to execute.
* @param pReq This points to a SUPVMMR0REQHDR packet. Optional.
* @param u64Arg Some simple constant argument.
* @param pSession The session of the caller.
* @remarks Assume called with interrupts _enabled_.
*/
VMMR0DECL(int) VMMR0EntryEx(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession)
{
/*
* Requests that should only happen on the EMT thread will be
* wrapped in a setjmp so we can assert without causing trouble.
*/
if ( VALID_PTR(pVM)
&& pVM->pVMR0
&& idCpu < pVM->cCpus)
{
switch (enmOperation)
{
/* These might/will be called before VMMR3Init. */
case VMMR0_DO_GMM_INITIAL_RESERVATION:
case VMMR0_DO_GMM_UPDATE_RESERVATION:
case VMMR0_DO_GMM_ALLOCATE_PAGES:
case VMMR0_DO_GMM_FREE_PAGES:
case VMMR0_DO_GMM_BALLOONED_PAGES:
/* On the mac we might not have a valid jmp buf, so check these as well. */
case VMMR0_DO_VMMR0_INIT:
case VMMR0_DO_VMMR0_TERM:
{
PVMCPU pVCpu = &pVM->aCpus[idCpu];
if (!pVCpu->vmm.s.CallRing3JmpBufR0.pvSavedStack)
break;
/** @todo validate this EMT claim... GVM knows. */
VMMR0ENTRYEXARGS Args;
Args.pVM = pVM;
Args.idCpu = idCpu;
Args.enmOperation = enmOperation;
Args.pReq = pReq;
Args.u64Arg = u64Arg;
Args.pSession = pSession;
return vmmR0CallRing3SetJmpEx(&pVCpu->vmm.s.CallRing3JmpBufR0, vmmR0EntryExWrapper, &Args);
}
default:
break;
}
}
return vmmR0EntryExWorker(pVM, idCpu, enmOperation, pReq, u64Arg, pSession);
}
/**
* Internal R0 logger worker: Flush logger.
*
* @param pLogger The logger instance to flush.
* @remark This function must be exported!
*/
VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger)
{
#ifdef LOG_ENABLED
/*
* Convert the pLogger into a VM handle and 'call' back to Ring-3.
* (This is a bit paranoid code.)
*/
PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
if ( !VALID_PTR(pR0Logger)
|| !VALID_PTR(pR0Logger + 1)
|| pLogger->u32Magic != RTLOGGER_MAGIC)
{
# ifdef DEBUG
SUPR0Printf("vmmR0LoggerFlush: pLogger=%p!\n", pLogger);
# endif
return;
}
if (pR0Logger->fFlushingDisabled)
return; /* quietly */
PVM pVM = pR0Logger->pVM;
if ( !VALID_PTR(pVM)
|| pVM->pVMR0 != pVM)
{
# ifdef DEBUG
SUPR0Printf("vmmR0LoggerFlush: pVM=%p! pVMR0=%p! pLogger=%p\n", pVM, pVM->pVMR0, pLogger);
# endif
return;
}
PVMCPU pVCpu = VMMGetCpu(pVM);
/*
* Check that the jump buffer is armed.
*/
# ifdef RT_ARCH_X86
if ( !pVCpu->vmm.s.CallRing3JmpBufR0.eip
|| pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
# else
if ( !pVCpu->vmm.s.CallRing3JmpBufR0.rip
|| pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
# endif
{
# ifdef DEBUG
SUPR0Printf("vmmR0LoggerFlush: Jump buffer isn't armed!\n");
# endif
return;
}
VMMRZCallRing3(pVM, pVCpu, VMMCALLRING3_VMM_LOGGER_FLUSH, 0);
#endif
}
/**
* Interal R0 logger worker: Custom prefix.
*
* @returns Number of chars written.
*
* @param pLogger The logger instance.
* @param pchBuf The output buffer.
* @param cchBuf The size of the buffer.
* @param pvUser User argument (ignored).
*/
VMMR0DECL(size_t) vmmR0LoggerPrefix(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser)
{
NOREF(pvUser);
#ifdef LOG_ENABLED
PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
if ( !VALID_PTR(pR0Logger)
|| !VALID_PTR(pR0Logger + 1)
|| pLogger->u32Magic != RTLOGGER_MAGIC
|| cchBuf < 2)
return 0;
static const char s_szHex[17] = "0123456789abcdef";
VMCPUID const idCpu = pR0Logger->idCpu;
pchBuf[1] = s_szHex[ idCpu & 15];
pchBuf[0] = s_szHex[(idCpu >> 4) & 15];
return 2;
#else
return 0;
#endif
}
#ifdef LOG_ENABLED
/**
* Disables flushing of the ring-0 debug log.
*
* @param pVCpu The shared virtual cpu structure.
*/
VMMR0DECL(void) VMMR0LogFlushDisable(PVMCPU pVCpu)
{
PVM pVM = pVCpu->pVMR0;
if (pVCpu->vmm.s.pR0LoggerR0)
pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = true;
}
/**
* Enables flushing of the ring-0 debug log.
*
* @param pVCpu The shared virtual cpu structure.
*/
VMMR0DECL(void) VMMR0LogFlushEnable(PVMCPU pVCpu)
{
PVM pVM = pVCpu->pVMR0;
if (pVCpu->vmm.s.pR0LoggerR0)
pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = false;
}
#endif
/**
* Jump back to ring-3 if we're the EMT and the longjmp is armed.
*
* @returns true if the breakpoint should be hit, false if it should be ignored.
*/
DECLEXPORT(bool) RTCALL RTAssertShouldPanic(void)
{
#if 0
return true;
#else
PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
if (pVM)
{
PVMCPU pVCpu = VMMGetCpu(pVM);
if (pVCpu)
{
#ifdef RT_ARCH_X86
if ( pVCpu->vmm.s.CallRing3JmpBufR0.eip
&& !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
#else
if ( pVCpu->vmm.s.CallRing3JmpBufR0.rip
&& !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
#endif
{
int rc = VMMRZCallRing3(pVM, pVCpu, VMMCALLRING3_VM_R0_ASSERTION, 0);
return RT_FAILURE_NP(rc);
}
}
}
#ifdef RT_OS_LINUX
return true;
#else
return false;
#endif
#endif
}
/**
* Override this so we can push it up to ring-3.
*
* @param pszExpr Expression. Can be NULL.
* @param uLine Location line number.
* @param pszFile Location file name.
* @param pszFunction Location function name.
*/
DECLEXPORT(void) RTCALL RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
{
/*
* To the log.
*/
LogAlways(("\n!!R0-Assertion Failed!!\n"
"Expression: %s\n"
"Location : %s(%d) %s\n",
pszExpr, pszFile, uLine, pszFunction));
/*
* To the global VMM buffer.
*/
PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
if (pVM)
RTStrPrintf(pVM->vmm.s.szRing0AssertMsg1, sizeof(pVM->vmm.s.szRing0AssertMsg1),
"\n!!R0-Assertion Failed!!\n"
"Expression: %s\n"
"Location : %s(%d) %s\n",
pszExpr, pszFile, uLine, pszFunction);
/*
* Continue the normal way.
*/
RTAssertMsg1(pszExpr, uLine, pszFile, pszFunction);
}
/**
* Callback for RTLogFormatV which writes to the ring-3 log port.
* See PFNLOGOUTPUT() for details.
*/
static DECLCALLBACK(size_t) rtLogOutput(void *pv, const char *pachChars, size_t cbChars)
{
for (size_t i = 0; i < cbChars; i++)
LogAlways(("%c", pachChars[i]));
return cbChars;
}
/**
* Override this so we can push it up to ring-3.
*
* @param pszFormat The format string.
* @param va Arguments.
*/
DECLEXPORT(void) RTCALL RTAssertMsg2WeakV(const char *pszFormat, va_list va)
{
va_list vaCopy;
/*
* Push the message to the logger.
*/
PRTLOGGER pLog = RTLogDefaultInstance(); /** @todo we want this for release as well! */
if (pLog)
{
va_copy(vaCopy, va);
RTLogFormatV(rtLogOutput, pLog, pszFormat, vaCopy);
va_end(vaCopy);
}
/*
* Push it to the global VMM buffer.
*/
PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
if (pVM)
{
va_copy(vaCopy, va);
RTStrPrintfV(pVM->vmm.s.szRing0AssertMsg2, sizeof(pVM->vmm.s.szRing0AssertMsg2), pszFormat, vaCopy);
va_end(vaCopy);
}
/*
* Continue the normal way.
*/
RTAssertMsg2V(pszFormat, va);
}