VMMR0.cpp revision 293f7221f6f43c3c53c52b3d2788f7d196bb383c
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/* $Id$ */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/** @file
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * VMM - Host Context Ring 0.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * available from http://www.virtualbox.org. This file is free software;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * General Public License (GPL) as published by the Free Software
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * additional information or have any questions.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/*******************************************************************************
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync* Header Files *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync*******************************************************************************/
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define LOG_GROUP LOG_GROUP_VMM
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/vmm.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/sup.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/trpm.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/cpum.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/pgm.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/stam.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/tm.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include "VMMInternal.h"
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/vm.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/gvmm.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/gmm.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/intnet.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <VBox/hwaccm.h>
628ddfbd43ad5365d69fddda4007598242956577vboxsync#include <VBox/param.h>
628ddfbd43ad5365d69fddda4007598242956577vboxsync
628ddfbd43ad5365d69fddda4007598242956577vboxsync#include <VBox/err.h>
628ddfbd43ad5365d69fddda4007598242956577vboxsync#include <VBox/version.h>
628ddfbd43ad5365d69fddda4007598242956577vboxsync#include <VBox/log.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <iprt/assert.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <iprt/stdarg.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <iprt/mp.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#include <iprt/string.h>
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#if defined(_MSC_VER) && defined(RT_ARCH_AMD64) /** @todo check this with with VC7! */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync# pragma intrinsic(_AddressOfReturnAddress)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/*******************************************************************************
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync* Internal Functions *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync*******************************************************************************/
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync__BEGIN_DECLS
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncVMMR0DECL(int) ModuleInit(void);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncVMMR0DECL(void) ModuleTerm(void);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync__END_DECLS
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/*******************************************************************************
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync* Global Variables *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync*******************************************************************************/
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/** Pointer to the internal networking service instance. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncPINTNET g_pIntNet = 0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Initialize the module.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * This is called when we're first loaded.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @returns 0 on success.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @returns VBox status on failure.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncVMMR0DECL(int) ModuleInit(void)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogFlow(("ModuleInit:\n"));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Initialize the GVMM, GMM, HWACCM, PGM (Darwin) and INTNET.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync int rc = GVMMR0Init();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_SUCCESS(rc))
54d3b0107d9bf326fe6e0de92e012c791dbb1587vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = GMMR0Init();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_SUCCESS(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = HWACCMR0Init();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_SUCCESS(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = PGMR0DynMapInit();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_SUCCESS(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogFlow(("ModuleInit: g_pIntNet=%p\n", g_pIntNet));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync g_pIntNet = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogFlow(("ModuleInit: g_pIntNet=%p should be NULL now...\n", g_pIntNet));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = INTNETR0Create(&g_pIntNet);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_SUCCESS(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogFlow(("ModuleInit: returns success. g_pIntNet=%p\n", g_pIntNet));
77cce7691847be5aef145f31ba3f9d66fc2cf594vboxsync return VINF_SUCCESS;
9e293277b378073ce86910209a246b744b4caa2cvboxsync }
9e293277b378073ce86910209a246b744b4caa2cvboxsync
54d3b0107d9bf326fe6e0de92e012c791dbb1587vboxsync /* bail out */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync g_pIntNet = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogFlow(("ModuleTerm: returns %Rrc\n", rc));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync PGMR0DynMapTerm();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
9e293277b378073ce86910209a246b744b4caa2cvboxsync }
9e293277b378073ce86910209a246b744b4caa2cvboxsync HWACCMR0Term();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync GMMR0Term();
9e293277b378073ce86910209a246b744b4caa2cvboxsync }
9e293277b378073ce86910209a246b744b4caa2cvboxsync GVMMR0Term();
9e293277b378073ce86910209a246b744b4caa2cvboxsync }
9e293277b378073ce86910209a246b744b4caa2cvboxsync
9e293277b378073ce86910209a246b744b4caa2cvboxsync LogFlow(("ModuleInit: failed %Rrc\n", rc));
9e293277b378073ce86910209a246b744b4caa2cvboxsync return rc;
9e293277b378073ce86910209a246b744b4caa2cvboxsync}
9e293277b378073ce86910209a246b744b4caa2cvboxsync
9e293277b378073ce86910209a246b744b4caa2cvboxsync
9e293277b378073ce86910209a246b744b4caa2cvboxsync/**
9e293277b378073ce86910209a246b744b4caa2cvboxsync * Terminate the module.
9e293277b378073ce86910209a246b744b4caa2cvboxsync * This is called when we're finally unloaded.
9e293277b378073ce86910209a246b744b4caa2cvboxsync */
9e293277b378073ce86910209a246b744b4caa2cvboxsyncVMMR0DECL(void) ModuleTerm(void)
9e293277b378073ce86910209a246b744b4caa2cvboxsync{
9e293277b378073ce86910209a246b744b4caa2cvboxsync LogFlow(("ModuleTerm:\n"));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Destroy the internal networking instance.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (g_pIntNet)
9e293277b378073ce86910209a246b744b4caa2cvboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync INTNETR0Destroy(g_pIntNet);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync g_pIntNet = NULL;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * PGM (Darwin) and HWACCM global cleanup.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Destroy the GMM and GVMM instances.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
9e293277b378073ce86910209a246b744b4caa2cvboxsync PGMR0DynMapTerm();
9e293277b378073ce86910209a246b744b4caa2cvboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HWACCMR0Term();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync GMMR0Term();
9e293277b378073ce86910209a246b744b4caa2cvboxsync GVMMR0Term();
9e293277b378073ce86910209a246b744b4caa2cvboxsync
9e293277b378073ce86910209a246b744b4caa2cvboxsync LogFlow(("ModuleTerm: returns\n"));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
8e0c2ca3abd721979958f95b9af73b60665478c8vboxsync
9e293277b378073ce86910209a246b744b4caa2cvboxsync/**
9e293277b378073ce86910209a246b744b4caa2cvboxsync * Initaties the R0 driver for a particular VM instance.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
9e293277b378073ce86910209a246b744b4caa2cvboxsync * @returns VBox status code.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pVM The VM instance in question.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param uSvnRev The SVN revision of the ring-3 part.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @thread EMT.
9e293277b378073ce86910209a246b744b4caa2cvboxsync */
9e293277b378073ce86910209a246b744b4caa2cvboxsyncstatic int vmmR0InitVM(PVM pVM, uint32_t uSvnRev)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Match the SVN revisions.
9e293277b378073ce86910209a246b744b4caa2cvboxsync */
9e293277b378073ce86910209a246b744b4caa2cvboxsync if (uSvnRev != VMMGetSvnRev())
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_VERSION_MISMATCH;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if ( !VALID_PTR(pVM)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync || pVM->pVMR0 != pVM)
9e293277b378073ce86910209a246b744b4caa2cvboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Register the EMT R0 logger instance.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync PVMMR0LOGGER pR0Logger = pVM->vmm.s.pR0LoggerR0;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pR0Logger)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#if 0 /* testing of the logger. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: before %p\n", RTLogDefaultInstance()));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: pfnFlush=%p actual=%p\n", pR0Logger->Logger.pfnFlush, vmmR0LoggerFlush));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: pfnLogger=%p actual=%p\n", pR0Logger->Logger.pfnLogger, vmmR0LoggerWrapper));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: offScratch=%d fFlags=%#x fDestFlags=%#x\n", pR0Logger->Logger.offScratch, pR0Logger->Logger.fFlags, pR0Logger->Logger.fDestFlags));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: after %p reg\n", RTLogDefaultInstance()));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTLogSetDefaultInstanceThread(NULL, 0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: after %p dereg\n", RTLogDefaultInstance()));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: returned succesfully from direct logger call.\n"));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pR0Logger->Logger.pfnFlush(&pR0Logger->Logger);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: returned succesfully from direct flush call.\n"));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: after %p reg2\n", RTLogDefaultInstance()));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: returned succesfully from direct logger call (2). offScratch=%d\n", pR0Logger->Logger.offScratch));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTLogSetDefaultInstanceThread(NULL, 0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: after %p dereg2\n", RTLogDefaultInstance()));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTLogLoggerEx(&pR0Logger->Logger, 0, ~0U, "hello ring-0 logger (RTLogLoggerEx)\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: RTLogLoggerEx returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTLogPrintf("hello ring-0 logger (RTLogPrintf)\n");
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogCom(("vmmR0InitVM: RTLogPrintf returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Log(("Switching to per-thread logging instance %p (key=%p)\n", &pR0Logger->Logger, pVM->pSession));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Initialize the per VM data for GVMM and GMM.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync int rc = GVMMR0InitVM(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync// if (RT_SUCCESS(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync// rc = GMMR0InitPerVMData(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_SUCCESS(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Init HWACCM, CPUM and PGM (Darwin only).
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = HWACCMR0InitVM(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_SUCCESS(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = CPUMR0Init(pVM); /** @todo rename to CPUMR0InitVM */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_SUCCESS(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = PGMR0DynMapInitVM(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_SUCCESS(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync GVMMR0DoneInitVM(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return rc;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* bail out */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HWACCMR0TermVM(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTLogSetDefaultInstanceThread(NULL, 0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return rc;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Terminates the R0 driver for a particular VM instance.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * This is normally called by ring-3 as part of the VM termination process, but
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * may alternatively be called during the support driver session cleanup when
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * the VM object is destroyed (see GVMM).
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @returns VBox status code.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pVM The VM instance in question.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pGVM Pointer to the global VM structure. Optional.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @thread EMT or session clean up thread.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncVMMR0DECL(int) VMMR0TermVM(PVM pVM, PGVM pGVM)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Tell GVMM what we're up to and check that we only do this once.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (GVMMR0DoingTermVM(pVM, pGVM))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync PGMR0DynMapTermVM(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync HWACCMR0TermVM(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Deregister the logger.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTLogSetDefaultInstanceThread(NULL, 0);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VINF_SUCCESS;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Calls the ring-3 host code.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @returns VBox status code of the ring-3 call.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pVM The VM handle.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param enmOperation The operation.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param uArg The argument to the operation.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncVMMR0DECL(int) VMMR0CallHost(PVM pVM, VMMCALLHOST enmOperation, uint64_t uArg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/** @todo profile this! */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pVM->vmm.s.enmCallHostOperation = enmOperation;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pVM->vmm.s.u64CallHostArg = uArg;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pVM->vmm.s.rcCallHost = VERR_INTERNAL_ERROR;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync int rc = vmmR0CallHostLongJmp(&pVM->vmm.s.CallHostR0JmpBuf, VINF_VMM_CALL_HOST);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (rc == VINF_SUCCESS)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = pVM->vmm.s.rcCallHost;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return rc;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_STATISTICS
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Record return code statistics
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pVM The VM handle.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param rc The status code.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic void vmmR0RecordRC(PVM pVM, int rc)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Collect statistics.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync switch (rc)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_SUCCESS:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetNormal);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_INTERRUPT:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterrupt);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_INTERRUPT_HYPER:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptHyper);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_GUEST_TRAP:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetGuestTrap);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_RING_SWITCH:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRingSwitch);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_RING_SWITCH_INT:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRingSwitchInt);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_EXCEPTION_PRIVILEGED:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetExceptionPrivilege);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_STALE_SELECTOR:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetStaleSelector);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_IRET_TRAP:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIRETTrap);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_IOM_HC_IOPORT_READ:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIORead);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_IOM_HC_IOPORT_WRITE:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIOWrite);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_IOM_HC_MMIO_READ:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIORead);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_IOM_HC_MMIO_WRITE:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOWrite);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_IOM_HC_MMIO_READ_WRITE:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOReadWrite);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_PATM_HC_MMIO_PATCH_READ:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchRead);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_PATM_HC_MMIO_PATCH_WRITE:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchWrite);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_EMULATE_INSTR:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetEmulate);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_PATCH_EMULATE_INSTR:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchEmulate);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_EMULATE_INSTR_LDT_FAULT:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetLDTFault);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetGDTFault);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_EMULATE_INSTR_IDT_FAULT:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIDTFault);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_EMULATE_INSTR_TSS_FAULT:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetTSSFault);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_EMULATE_INSTR_PD_FAULT:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPDFault);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_CSAM_PENDING_ACTION:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetCSAMTask);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_PGM_SYNC_CR3:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetSyncCR3);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_PATM_PATCH_INT3:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchInt3);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_PATM_PATCH_TRAP_PF:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchPF);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_PATM_PATCH_TRAP_GP:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchGP);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_PATM_PENDING_IRQ_AFTER_IRET:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchIretIRQ);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VERR_REM_FLUSHED_PAGES_OVERFLOW:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPageOverflow);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RESCHEDULE_REM:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRescheduleREM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_TO_R3:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_TIMER_PENDING:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetTimerPending);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_INTERRUPT_PENDING:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptPending);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_VMM_CALL_HOST:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync switch (pVM->vmm.s.enmCallHostOperation)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_PDM_LOCK:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPDMLock);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_PDM_QUEUE_FLUSH:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPDMQueueFlush);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_PGM_POOL_GROW:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMPoolGrow);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_PGM_LOCK:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMLock);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_PGM_MAP_CHUNK:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMMapChunk);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_PGM_ALLOCATE_HANDY_PAGES:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMAllocHandy);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifndef VBOX_WITH_NEW_PHYS_CODE
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_PGM_RAM_GROW_RANGE:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMGrowRAM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_REM_REPLAY_HANDLER_NOTIFICATIONS:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallRemReplay);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_VMM_LOGGER_FLUSH:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallLogFlush);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_VM_SET_ERROR:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetError);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_VM_SET_RUNTIME_ERROR:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetRuntimeError);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMCALLHOST_VM_R0_ASSERTION:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync default:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetCallHost);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_PATM_DUPLICATE_FUNCTION:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPATMDuplicateFn);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_PGM_CHANGE_MODE:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPGMChangeMode);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_RAW_EMULATE_INSTR_HLT:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetEmulHlt);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VINF_EM_PENDING_REQUEST:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPendingRequest);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync default:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMisc);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif /* VBOX_WITH_STATISTICS */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Unused ring-0 entry point that used to be called from the interrupt gate.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Will be removed one of the next times we do a major SUPDrv version bump.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @returns VBox status code.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pVM The VM to operate on.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param enmOperation Which operation to execute.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pvArg Argument to the operation.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @remarks Assume called with interrupts disabled.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncVMMR0DECL(int) VMMR0EntryInt(PVM pVM, VMMR0OPERATION enmOperation, void *pvArg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync switch (enmOperation)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync default:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * We're returning VERR_NOT_SUPPORT here so we've got something else
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * than -1 which the interrupt gate glue code might return.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Log(("operation %#x is not supported\n", enmOperation));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_NOT_SUPPORTED;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * The Ring 0 entry point, called by the fast-ioctl path.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pVM The VM to operate on.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * The return code is stored in pVM->vmm.s.iLastGZRc.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param idCpu VMCPU id.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param enmOperation Which operation to execute.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @remarks Assume called with interrupts _enabled_.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncVMMR0DECL(void) VMMR0EntryFast(PVM pVM, unsigned idCpu, VMMR0OPERATION enmOperation)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_UNLIKELY(idCpu >= pVM->cCPUs))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pVM->vmm.s.iLastGZRc = VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync switch (enmOperation)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Switch to GC and run guest raw mode code.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Disable interrupts before doing the world switch.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_RAW_RUN:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Safety precaution as hwaccm disables the switcher. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_LIKELY(!pVM->vmm.s.fSwitcherDisabled))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTCCUINTREG uFlags = ASMIntDisableFlags();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync TMNotifyStartOfExecution(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync int rc = pVM->vmm.s.pfnHostToGuestR0(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pVM->vmm.s.iLastGZRc = rc;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync TMNotifyEndOfExecution(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if ( rc == VINF_EM_RAW_INTERRUPT
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync || rc == VINF_EM_RAW_INTERRUPT_HYPER)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync TRPMR0DispatchHostInterrupt(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ASMSetFlags(uFlags);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_STATISTICS
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRunRC);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync vmmR0RecordRC(pVM, rc);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync else
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Assert(!pVM->vmm.s.fSwitcherDisabled);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pVM->vmm.s.iLastGZRc = VERR_NOT_SUPPORTED;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Run guest code using the available hardware acceleration technology.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Disable interrupts before we do anything interesting. On Windows we avoid
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * this by having the support driver raise the IRQL before calling us, this way
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * we hope to get away with page faults and later calling into the kernel.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_HWACC_RUN:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync int rc;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync PVMCPU pVCpu = &pVM->aCpus[idCpu];
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRunRC);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifndef RT_OS_WINDOWS /** @todo check other hosts */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTCCUINTREG uFlags = ASMIntDisableFlags();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (!HWACCMR0SuspendPending())
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = HWACCMR0Enter(pVM, pVCpu);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_SUCCESS(rc))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = vmmR0CallHostSetJmp(&pVM->vmm.s.CallHostR0JmpBuf, HWACCMR0RunGuestCode, pVM, pVCpu); /* this may resume code. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync int rc2 = HWACCMR0Leave(pVM, pVCpu);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync AssertRC(rc2);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync else
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* System is about to go into suspend mode; go back to ring 3. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = VINF_EM_RAW_INTERRUPT;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pVM->vmm.s.iLastGZRc = rc;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifndef RT_OS_WINDOWS /** @todo check other hosts */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ASMSetFlags(uFlags);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#ifdef VBOX_WITH_STATISTICS
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync vmmR0RecordRC(pVM, rc);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* No special action required for external interrupts, just return. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * For profiling.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_NOP:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pVM->vmm.s.iLastGZRc = VINF_SUCCESS;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Impossible.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync default:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync AssertMsgFailed(("%#x\n", enmOperation));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pVM->vmm.s.iLastGZRc = VERR_NOT_SUPPORTED;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync break;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Validates a session or VM session argument.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @returns true / false accordingly.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pVM The VM argument.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pSession The session argument.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncDECLINLINE(bool) vmmR0IsValidSession(PVM pVM, PSUPDRVSESSION pClaimedSession, PSUPDRVSESSION pSession)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* This must be set! */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (!pSession)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return false;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Only one out of the two. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pVM && pClaimedSession)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return false;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pVM)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pClaimedSession = pVM->pSession;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return pClaimedSession == pSession;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync}
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/**
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * VMMR0EntryEx worker function, either called directly or when ever possible
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * called thru a longjmp so we can exit safely on failure.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @returns VBox status code.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pVM The VM to operate on.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param enmOperation Which operation to execute.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pReqHdr This points to a SUPVMMR0REQHDR packet. Optional.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * The support driver validates this if it's present.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param u64Arg Some simple constant argument.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pSession The session of the caller.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @remarks Assume called with interrupts _enabled_.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic int vmmR0EntryExWorker(PVM pVM, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReqHdr, uint64_t u64Arg, PSUPDRVSESSION pSession)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync{
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Common VM pointer validation.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pVM)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_UNLIKELY( !VALID_PTR(pVM)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync || ((uintptr_t)pVM & PAGE_OFFSET_MASK)))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p! (op=%d)\n", pVM, enmOperation);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_POINTER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_UNLIKELY( pVM->enmVMState < VMSTATE_CREATING
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync || pVM->enmVMState > VMSTATE_TERMINATED
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync || pVM->pVMR0 != pVM))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p:{enmVMState=%d, .pVMR0=%p}! (op=%d)\n",
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pVM, pVM->enmVMState, pVM->pVMR0, enmOperation);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_POINTER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync switch (enmOperation)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * GVM requests
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GVMM_CREATE_VM:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pVM || u64Arg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GVMMR0CreateVMReq((PGVMMCREATEVMREQ)pReqHdr);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GVMM_DESTROY_VM:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pReqHdr || u64Arg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GVMMR0DestroyVM(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GVMM_SCHED_HALT:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pReqHdr)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GVMMR0SchedHalt(pVM, u64Arg);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GVMM_SCHED_WAKE_UP:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pReqHdr || u64Arg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GVMMR0SchedWakeUp(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GVMM_SCHED_POLL:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pReqHdr || u64Arg > 1)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GVMMR0SchedPoll(pVM, !!u64Arg);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GVMM_QUERY_STATISTICS:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (u64Arg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GVMMR0QueryStatisticsReq(pVM, (PGVMMQUERYSTATISTICSSREQ)pReqHdr);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GVMM_RESET_STATISTICS:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (u64Arg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GVMMR0ResetStatisticsReq(pVM, (PGVMMRESETSTATISTICSSREQ)pReqHdr);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Initialize the R0 part of a VM instance.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_VMMR0_INIT:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return vmmR0InitVM(pVM, (uint32_t)u64Arg);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Terminate the R0 part of a VM instance.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_VMMR0_TERM:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VMMR0TermVM(pVM, NULL);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Attempt to enable hwacc mode and check the current setting.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_HWACC_ENABLE:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return HWACCMR0EnableAllCpus(pVM, (HWACCMSTATE)u64Arg);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Setup the hardware accelerated raw-mode session.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_HWACC_SETUP_VM:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTCCUINTREG fFlags = ASMIntDisableFlags();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync int rc = HWACCMR0SetupVM(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ASMSetFlags(fFlags);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return rc;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Switch to GC to execute Hypervisor function.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_CALL_HYPERVISOR:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Safety precaution as HWACCM can disable the switcher. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Assert(!pVM->vmm.s.fSwitcherDisabled);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (RT_UNLIKELY(pVM->vmm.s.fSwitcherDisabled))
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_NOT_SUPPORTED;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTCCUINTREG fFlags = ASMIntDisableFlags();
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync int rc = pVM->vmm.s.pfnHostToGuestR0(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** @todo dispatch interrupts? */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ASMSetFlags(fFlags);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return rc;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync }
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * PGM wrappers.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_PGM_ALLOCATE_HANDY_PAGES:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return PGMR0PhysAllocateHandyPages(pVM);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /*
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * GMM wrappers.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GMM_INITIAL_RESERVATION:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (u64Arg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GMMR0InitialReservationReq(pVM, (PGMMINITIALRESERVATIONREQ)pReqHdr);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GMM_UPDATE_RESERVATION:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (u64Arg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GMMR0UpdateReservationReq(pVM, (PGMMUPDATERESERVATIONREQ)pReqHdr);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GMM_ALLOCATE_PAGES:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (u64Arg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GMMR0AllocatePagesReq(pVM, (PGMMALLOCATEPAGESREQ)pReqHdr);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GMM_FREE_PAGES:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (u64Arg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GMMR0FreePagesReq(pVM, (PGMMFREEPAGESREQ)pReqHdr);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GMM_BALLOONED_PAGES:
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (u64Arg)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return VERR_INVALID_PARAMETER;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync return GMMR0BalloonedPagesReq(pVM, (PGMMBALLOONEDPAGESREQ)pReqHdr);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync case VMMR0_DO_GMM_DEFLATED_BALLOON:
if (pReqHdr)
return VERR_INVALID_PARAMETER;
return GMMR0DeflatedBalloon(pVM, (uint32_t)u64Arg);
case VMMR0_DO_GMM_MAP_UNMAP_CHUNK:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0MapUnmapChunkReq(pVM, (PGMMMAPUNMAPCHUNKREQ)pReqHdr);
case VMMR0_DO_GMM_SEED_CHUNK:
if (pReqHdr)
return VERR_INVALID_PARAMETER;
return GMMR0SeedChunk(pVM, (RTR3PTR)u64Arg);
/*
* A quick GCFGM mock-up.
*/
/** @todo GCFGM with proper access control, ring-3 management interface and all that. */
case VMMR0_DO_GCFGM_SET_VALUE:
case VMMR0_DO_GCFGM_QUERY_VALUE:
{
if (pVM || !pReqHdr || u64Arg)
return VERR_INVALID_PARAMETER;
PGCFGMVALUEREQ pReq = (PGCFGMVALUEREQ)pReqHdr;
if (pReq->Hdr.cbReq != sizeof(*pReq))
return VERR_INVALID_PARAMETER;
int rc;
if (enmOperation == VMMR0_DO_GCFGM_SET_VALUE)
{
rc = GVMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
//if (rc == VERR_CFGM_VALUE_NOT_FOUND)
// rc = GMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
}
else
{
rc = GVMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
//if (rc == VERR_CFGM_VALUE_NOT_FOUND)
// rc = GMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
}
return rc;
}
/*
* Requests to the internal networking service.
*/
case VMMR0_DO_INTNET_OPEN:
{
PINTNETOPENREQ pReq = (PINTNETOPENREQ)pReqHdr;
if (u64Arg || !pReq || !vmmR0IsValidSession(pVM, pReq->pSession, pSession))
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
return INTNETR0OpenReq(g_pIntNet, pSession, pReq);
}
case VMMR0_DO_INTNET_IF_CLOSE:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFCLOSEREQ)pReqHdr)->pSession, pSession))
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
return INTNETR0IfCloseReq(g_pIntNet, pSession, (PINTNETIFCLOSEREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_GET_RING3_BUFFER:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFGETRING3BUFFERREQ)pReqHdr)->pSession, pSession))
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
return INTNETR0IfGetRing3BufferReq(g_pIntNet, pSession, (PINTNETIFGETRING3BUFFERREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr)->pSession, pSession))
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
return INTNETR0IfSetPromiscuousModeReq(g_pIntNet, pSession, (PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_SET_MAC_ADDRESS:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETMACADDRESSREQ)pReqHdr)->pSession, pSession))
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
return INTNETR0IfSetMacAddressReq(g_pIntNet, pSession, (PINTNETIFSETMACADDRESSREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_SET_ACTIVE:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETACTIVEREQ)pReqHdr)->pSession, pSession))
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
return INTNETR0IfSetActiveReq(g_pIntNet, pSession, (PINTNETIFSETACTIVEREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_SEND:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSENDREQ)pReqHdr)->pSession, pSession))
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
return INTNETR0IfSendReq(g_pIntNet, pSession, (PINTNETIFSENDREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_WAIT:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession))
return VERR_INVALID_PARAMETER;
if (!g_pIntNet)
return VERR_NOT_SUPPORTED;
return INTNETR0IfWaitReq(g_pIntNet, pSession, (PINTNETIFWAITREQ)pReqHdr);
/*
* For profiling.
*/
case VMMR0_DO_NOP:
case VMMR0_DO_SLOW_NOP:
return VINF_SUCCESS;
/*
* For testing Ring-0 APIs invoked in this environment.
*/
case VMMR0_DO_TESTS:
/** @todo make new test */
return VINF_SUCCESS;
#if defined(DEBUG) && HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS)
case VMMR0_DO_TEST_SWITCHER3264:
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 argument s ofr VMMR0EntryEx.
*/
typedef struct VMMR0ENTRYEXARGS
{
PVM pVM;
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)->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 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, 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)
{
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:
case VMMR0_DO_GMM_DEFLATED_BALLOON:
case VMMR0_DO_GMM_MAP_UNMAP_CHUNK:
case VMMR0_DO_GMM_SEED_CHUNK:
/* 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:
{
if (!pVM->vmm.s.CallHostR0JmpBuf.pvSavedStack)
break;
/** @todo validate this EMT claim... GVM knows. */
VMMR0ENTRYEXARGS Args;
Args.pVM = pVM;
Args.enmOperation = enmOperation;
Args.pReq = pReq;
Args.u64Arg = u64Arg;
Args.pSession = pSession;
return vmmR0CallHostSetJmpEx(&pVM->vmm.s.CallHostR0JmpBuf, vmmR0EntryExWrapper, &Args);
}
default:
break;
}
}
return vmmR0EntryExWorker(pVM, 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)
{
/*
* 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;
}
/*
* Check that the jump buffer is armed.
*/
#ifdef RT_ARCH_X86
if (!pVM->vmm.s.CallHostR0JmpBuf.eip)
#else
if (!pVM->vmm.s.CallHostR0JmpBuf.rip)
#endif
{
#ifdef DEBUG
SUPR0Printf("vmmR0LoggerFlush: Jump buffer isn't armed!\n");
#endif
return;
}
VMMR0CallHost(pVM, VMMCALLHOST_VMM_LOGGER_FLUSH, 0);
}
/**
* 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 (pVM->vmm.s.pR0LoggerR0)
pVM->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 (pVM->vmm.s.pR0LoggerR0)
pVM->vmm.s.pR0LoggerR0->fFlushingDisabled = false;
}
/**
* 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)
{
#ifdef RT_ARCH_X86
if (pVM->vmm.s.CallHostR0JmpBuf.eip)
#else
if (pVM->vmm.s.CallHostR0JmpBuf.rip)
#endif
{
int rc = VMMR0CallHost(pVM, VMMCALLHOST_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 AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
{
#if !defined(DEBUG_sandervl) && !defined(RT_OS_DARWIN)
SUPR0Printf("\n!!R0-Assertion Failed!!\n"
"Expression: %s\n"
"Location : %s(%d) %s\n",
pszExpr, pszFile, uLine, pszFunction);
#endif
LogAlways(("\n!!R0-Assertion Failed!!\n"
"Expression: %s\n"
"Location : %s(%d) %s\n",
pszExpr, pszFile, uLine, pszFunction));
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);
#ifdef RT_OS_DARWIN
RTAssertMsg1(pszExpr, uLine, pszFile, pszFunction);
#endif
}
/**
* 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++)
{
#if !defined(DEBUG_sandervl) && !defined(RT_OS_DARWIN)
SUPR0Printf("%c", pachChars[i]);
#endif
LogAlways(("%c", pachChars[i]));
}
return cbChars;
}
DECLEXPORT(void) RTCALL AssertMsg2(const char *pszFormat, ...)
{
va_list va;
PRTLOGGER pLog = RTLogDefaultInstance(); /** @todo we want this for release as well! */
if (pLog)
{
va_start(va, pszFormat);
RTLogFormatV(rtLogOutput, pLog, pszFormat, va);
va_end(va);
PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
if (pVM)
{
va_start(va, pszFormat);
RTStrPrintfV(pVM->vmm.s.szRing0AssertMsg2, sizeof(pVM->vmm.s.szRing0AssertMsg2), pszFormat, va);
va_end(va);
}
}
#ifdef RT_OS_DARWIN
va_start(va, pszFormat);
RTAssertMsg2V(pszFormat, va);
va_end(va);
#endif
}