VMMR0.cpp revision 52079e6b4668b5688cdd52891721f322fa721643
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/* $Id$ */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/** @file
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * VMM - Host Context Ring 0.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * additional information or have any questions.
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>
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#include <VBox/cpum.h>
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#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>
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync#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>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#include <iprt/assert.h>
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#include <iprt/mp.h>
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#include <iprt/stdarg.h>
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#include <iprt/string.h>
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#ifdef VBOX_WITH_VMMR0_DISABLE_PREEMPTION
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync# include <iprt/thread.h>
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync#if defined(_MSC_VER) && defined(RT_ARCH_AMD64) /** @todo check this with with VC7! */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync# pragma intrinsic(_AddressOfReturnAddress)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync#endif
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync/*******************************************************************************
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync* Internal Functions *
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync*******************************************************************************/
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsyncRT_C_DECLS_BEGIN
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsyncVMMR0DECL(int) ModuleInit(void);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMR0DECL(void) ModuleTerm(void);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncRT_C_DECLS_END
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/*******************************************************************************
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync* Global Variables *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync*******************************************************************************/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/** Pointer to the internal networking service instance. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncPINTNET g_pIntNet = 0;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Initialize the module.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * This is called when we're first loaded.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync *
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @returns 0 on success.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @returns VBox status on failure.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsyncVMMR0DECL(int) ModuleInit(void)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync{
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync LogFlow(("ModuleInit:\n"));
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync /*
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * Initialize the GVMM, GMM, HWACCM, PGM (Darwin) and INTNET.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync int rc = GVMMR0Init();
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync if (RT_SUCCESS(rc))
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync {
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync rc = GMMR0Init();
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync if (RT_SUCCESS(rc))
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync {
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync rc = HWACCMR0Init();
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync 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 LogFlow(("ModuleInit: g_pIntNet=%p\n", g_pIntNet));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync g_pIntNet = NULL;
ffb50166c9adb4ae583b914d405197035cf890advboxsync LogFlow(("ModuleInit: g_pIntNet=%p should be NULL now...\n", g_pIntNet));
ffb50166c9adb4ae583b914d405197035cf890advboxsync rc = INTNETR0Create(&g_pIntNet);
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (RT_SUCCESS(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync LogFlow(("ModuleInit: returns success. g_pIntNet=%p\n", g_pIntNet));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VINF_SUCCESS;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* bail out */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync g_pIntNet = NULL;
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 }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync GVMMR0Term();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlow(("ModuleInit: failed %Rrc\n", rc));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
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 * Destroy the internal networking instance.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (g_pIntNet)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync INTNETR0Destroy(g_pIntNet);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync g_pIntNet = NULL;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync /*
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync * PGM (Darwin) and HWACCM global cleanup.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Destroy the GMM and GVMM instances.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PGMR0DynMapTerm();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PGMDeregisterStringFormatTypes();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HWACCMR0Term();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync GMMR0Term();
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync GVMMR0Term();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogFlow(("ModuleTerm: returns\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync
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:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRescheduleREM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync 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:
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallRemReplay);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync 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;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync 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
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync/**
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync * 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 */
ffb50166c9adb4ae583b914d405197035cf890advboxsync case VMMR0_DO_GVMM_CREATE_VM:
ffb50166c9adb4ae583b914d405197035cf890advboxsync 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)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync 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:
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (pReqHdr || u64Arg > 1)
ffb50166c9adb4ae583b914d405197035cf890advboxsync 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
ffb50166c9adb4ae583b914d405197035cf890advboxsync case VMMR0_DO_GVMM_RESET_STATISTICS:
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return GVMMR0ResetStatisticsReq(pVM, (PGVMMRESETSTATISTICSSREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * Initialize the R0 part of a VM instance.
ffb50166c9adb4ae583b914d405197035cf890advboxsync */
ffb50166c9adb4ae583b914d405197035cf890advboxsync case VMMR0_DO_VMMR0_INIT:
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync return vmmR0InitVM(pVM, (uint32_t)u64Arg);
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync /*
ffb50166c9adb4ae583b914d405197035cf890advboxsync * Terminate the R0 part of a VM instance.
ffb50166c9adb4ae583b914d405197035cf890advboxsync */
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 */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_HWACC_ENABLE:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return HWACCMR0EnableAllCpus(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Setup the hardware accelerated session.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_HWACC_SETUP_VM:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTCCUINTREG fFlags = ASMIntDisableFlags();
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc = HWACCMR0SetupVM(pVM);
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync ASMSetFlags(fFlags);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Switch to RC to execute Hypervisor function.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_CALL_HYPERVISOR:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync bool fVTxDisabled;
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync
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);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (RT_FAILURE(rc))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync rc = pVM->vmm.s.pfnHostToGuestR0(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Re-enable VT-x if previously turned off. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync HWACCMR0LeaveSwitcher(pVM, fVTxDisabled);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync /** @todo dispatch interrupts? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ASMSetFlags(fFlags);
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync return rc;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync }
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync * PGM wrappers.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_PGM_ALLOCATE_HANDY_PAGES:
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync if (idCpu == NIL_VMCPUID)
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync return VERR_INVALID_CPU_ID;
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync return PGMR0PhysAllocateHandyPages(pVM, &pVM->aCpus[idCpu]);
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync case VMMR0_DO_PGM_ALLOCATE_LARGE_HANDY_PAGE:
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync if (idCpu == NIL_VMCPUID)
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync return VERR_INVALID_CPU_ID;
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync return PGMR0PhysAllocateLargeHandyPage(pVM, &pVM->aCpus[idCpu]);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * GMM wrappers.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_INITIAL_RESERVATION:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (u64Arg)
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync 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
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync case VMMR0_DO_GMM_BALLOONED_PAGES:
0dd3967035b8a02985920baa57f948dc542b9388vboxsync if (u64Arg)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return VERR_INVALID_PARAMETER;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return GMMR0BalloonedPagesReq(pVM, idCpu, (PGMMBALLOONEDPAGESREQ)pReqHdr);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync case VMMR0_DO_GMM_MAP_UNMAP_CHUNK:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (u64Arg)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_INVALID_PARAMETER;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return GMMR0MapUnmapChunkReq(pVM, idCpu, (PGMMMAPUNMAPCHUNKREQ)pReqHdr);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_GMM_SEED_CHUNK:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (pReqHdr)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_INVALID_PARAMETER;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return GMMR0SeedChunk(pVM, idCpu, (RTR3PTR)u64Arg);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /*
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * A quick GCFGM mock-up.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo GCFGM with proper access control, ring-3 management interface and all that. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync case VMMR0_DO_GCFGM_SET_VALUE:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync case VMMR0_DO_GCFGM_QUERY_VALUE:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_INVALID_PARAMETER;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync PGCFGMVALUEREQ pReq = (PGCFGMVALUEREQ)pReqHdr;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync if (pReq->Hdr.cbReq != sizeof(*pReq))
0dd3967035b8a02985920baa57f948dc542b9388vboxsync return VERR_INVALID_PARAMETER;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync int rc;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync if (enmOperation == VMMR0_DO_GCFGM_SET_VALUE)
0dd3967035b8a02985920baa57f948dc542b9388vboxsync {
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync rc = GVMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
0dd3967035b8a02985920baa57f948dc542b9388vboxsync //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
0dd3967035b8a02985920baa57f948dc542b9388vboxsync // rc = GMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
0dd3967035b8a02985920baa57f948dc542b9388vboxsync }
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync else
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync {
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync rc = GVMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync // rc = GMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync }
0dd3967035b8a02985920baa57f948dc542b9388vboxsync return rc;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync }
0dd3967035b8a02985920baa57f948dc542b9388vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /*
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * Requests to the internal networking service.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync case VMMR0_DO_INTNET_OPEN:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync PINTNETOPENREQ pReq = (PINTNETOPENREQ)pReqHdr;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (u64Arg || !pReq || !vmmR0IsValidSession(pVM, pReq->pSession, pSession) || idCpu != NIL_VMCPUID)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_INVALID_PARAMETER;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (!g_pIntNet)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_NOT_SUPPORTED;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return INTNETR0OpenReq(g_pIntNet, pSession, pReq);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync case VMMR0_DO_INTNET_IF_CLOSE:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFCLOSEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_INVALID_PARAMETER;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync if (!g_pIntNet)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_NOT_SUPPORTED;
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync return INTNETR0IfCloseReq(g_pIntNet, pSession, (PINTNETIFCLOSEREQ)pReqHdr);
0dd3967035b8a02985920baa57f948dc542b9388vboxsync
0dd3967035b8a02985920baa57f948dc542b9388vboxsync case VMMR0_DO_INTNET_IF_GET_RING3_BUFFER:
0dd3967035b8a02985920baa57f948dc542b9388vboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFGETRING3BUFFERREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_INVALID_PARAMETER;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (!g_pIntNet)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_NOT_SUPPORTED;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return INTNETR0IfGetRing3BufferReq(g_pIntNet, pSession, (PINTNETIFGETRING3BUFFERREQ)pReqHdr);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_INVALID_PARAMETER;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (!g_pIntNet)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_NOT_SUPPORTED;
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync return INTNETR0IfSetPromiscuousModeReq(g_pIntNet, pSession, (PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr);
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync case VMMR0_DO_INTNET_IF_SET_MAC_ADDRESS:
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETMACADDRESSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync return VERR_INVALID_PARAMETER;
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync if (!g_pIntNet)
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync return VERR_NOT_SUPPORTED;
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync return INTNETR0IfSetMacAddressReq(g_pIntNet, pSession, (PINTNETIFSETMACADDRESSREQ)pReqHdr);
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync case VMMR0_DO_INTNET_IF_SET_ACTIVE:
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETACTIVEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync return VERR_INVALID_PARAMETER;
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync if (!g_pIntNet)
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync return VERR_NOT_SUPPORTED;
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync return INTNETR0IfSetActiveReq(g_pIntNet, pSession, (PINTNETIFSETACTIVEREQ)pReqHdr);
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync case VMMR0_DO_INTNET_IF_SEND:
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSENDREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync return VERR_INVALID_PARAMETER;
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync if (!g_pIntNet)
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync return VERR_NOT_SUPPORTED;
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync return INTNETR0IfSendReq(g_pIntNet, pSession, (PINTNETIFSENDREQ)pReqHdr);
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync case VMMR0_DO_INTNET_IF_WAIT:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VERR_INVALID_PARAMETER;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (!g_pIntNet)
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync return VERR_NOT_SUPPORTED;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return INTNETR0IfWaitReq(g_pIntNet, pSession, (PINTNETIFWAITREQ)pReqHdr);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync /*
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * For profiling.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync */
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync case VMMR0_DO_NOP:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync case VMMR0_DO_SLOW_NOP:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VINF_SUCCESS;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /*
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * For testing Ring-0 APIs invoked in this environment.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync case VMMR0_DO_TESTS:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /** @todo make new test */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return VINF_SUCCESS;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync case VMMR0_DO_TEST_SWITCHER3264:
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (idCpu == NIL_VMCPUID)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync return VERR_INVALID_CPU_ID;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return HWACCMR0TestSwitcher3264(pVM);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync default:
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 }
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync}
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Argument for vmmR0EntryExWrapper containing the arguments for VMMR0EntryEx.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsynctypedef struct VMMR0ENTRYEXARGS
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync{
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PVM pVM;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync VMCPUID idCpu;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync VMMR0OPERATION enmOperation;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync PSUPVMMR0REQHDR pReq;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync uint64_t u64Arg;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync PSUPDRVSESSION pSession;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync} VMMR0ENTRYEXARGS;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync/** Pointer to a vmmR0EntryExWrapper argument package. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsynctypedef VMMR0ENTRYEXARGS *PVMMR0ENTRYEXARGS;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync/**
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * This is just a longjmp wrapper function for VMMR0EntryEx calls.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync *
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @returns VBox status code.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @param pvArgs The argument package
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsyncstatic int vmmR0EntryExWrapper(void *pvArgs)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync{
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return vmmR0EntryExWorker(((PVMMR0ENTRYEXARGS)pvArgs)->pVM,
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync ((PVMMR0ENTRYEXARGS)pvArgs)->idCpu,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ((PVMMR0ENTRYEXARGS)pvArgs)->enmOperation,
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync ((PVMMR0ENTRYEXARGS)pvArgs)->pReq,
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync ((PVMMR0ENTRYEXARGS)pvArgs)->u64Arg,
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync ((PVMMR0ENTRYEXARGS)pvArgs)->pSession);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync/**
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * The Ring 0 entry point, called by the support library (SUP).
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync *
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @returns VBox status code.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @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 pReq This points to a SUPVMMR0REQHDR packet. Optional.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @param u64Arg Some simple constant argument.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @param pSession The session of the caller.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @remarks Assume called with interrupts _enabled_.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync */
ffb50166c9adb4ae583b914d405197035cf890advboxsyncVMMR0DECL(int) VMMR0EntryEx(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync{
ffb50166c9adb4ae583b914d405197035cf890advboxsync /*
ffb50166c9adb4ae583b914d405197035cf890advboxsync * Requests that should only happen on the EMT thread will be
ffb50166c9adb4ae583b914d405197035cf890advboxsync * wrapped in a setjmp so we can assert without causing trouble.
ffb50166c9adb4ae583b914d405197035cf890advboxsync */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if ( VALID_PTR(pVM)
ffb50166c9adb4ae583b914d405197035cf890advboxsync && pVM->pVMR0
ffb50166c9adb4ae583b914d405197035cf890advboxsync && idCpu < pVM->cCpus)
ffb50166c9adb4ae583b914d405197035cf890advboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync switch (enmOperation)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync /* These might/will be called before VMMR3Init. */
ffb50166c9adb4ae583b914d405197035cf890advboxsync case VMMR0_DO_GMM_INITIAL_RESERVATION:
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync case VMMR0_DO_GMM_UPDATE_RESERVATION:
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync case VMMR0_DO_GMM_ALLOCATE_PAGES:
ffb50166c9adb4ae583b914d405197035cf890advboxsync case VMMR0_DO_GMM_FREE_PAGES:
ffb50166c9adb4ae583b914d405197035cf890advboxsync case VMMR0_DO_GMM_BALLOONED_PAGES:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /* On the mac we might not have a valid jmp buf, so check these as well. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync case VMMR0_DO_VMMR0_INIT:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync case VMMR0_DO_VMMR0_TERM:
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync {
f75c6db919d277952ca03b7acf643e5e3ac96cafvboxsync PVMCPU pVCpu = &pVM->aCpus[idCpu];
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (!pVCpu->vmm.s.CallRing3JmpBufR0.pvSavedStack)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync break;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /** @todo validate this EMT claim... GVM knows. */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync VMMR0ENTRYEXARGS Args;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Args.pVM = pVM;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Args.idCpu = idCpu;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Args.enmOperation = enmOperation;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Args.pReq = pReq;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Args.u64Arg = u64Arg;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync Args.pSession = pSession;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return vmmR0CallRing3SetJmpEx(&pVCpu->vmm.s.CallRing3JmpBufR0, vmmR0EntryExWrapper, &Args);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync default:
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync break;
0dd3967035b8a02985920baa57f948dc542b9388vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return vmmR0EntryExWorker(pVM, idCpu, enmOperation, pReq, u64Arg, pSession);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync}
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync/**
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * Internal R0 logger worker: Flush logger.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync *
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @param pLogger The logger instance to flush.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * @remark This function must be exported!
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsyncVMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger)
0dd3967035b8a02985920baa57f948dc542b9388vboxsync{
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync#ifdef LOG_ENABLED
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync /*
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * Convert the pLogger into a VM handle and 'call' back to Ring-3.
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync * (This is a bit paranoid code.)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if ( !VALID_PTR(pR0Logger)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync || !VALID_PTR(pR0Logger + 1)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync || pLogger->u32Magic != RTLOGGER_MAGIC)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync {
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync# ifdef DEBUG
ffb50166c9adb4ae583b914d405197035cf890advboxsync SUPR0Printf("vmmR0LoggerFlush: pLogger=%p!\n", pLogger);
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync# endif
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return;
ffb50166c9adb4ae583b914d405197035cf890advboxsync }
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (pR0Logger->fFlushingDisabled)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return; /* quietly */
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync PVM pVM = pR0Logger->pVM;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if ( !VALID_PTR(pVM)
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync || pVM->pVMR0 != pVM)
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync {
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync# ifdef DEBUG
ffb50166c9adb4ae583b914d405197035cf890advboxsync SUPR0Printf("vmmR0LoggerFlush: pVM=%p! pVMR0=%p! pLogger=%p\n", pVM, pVM->pVMR0, pLogger);
ffb50166c9adb4ae583b914d405197035cf890advboxsync# endif
ffb50166c9adb4ae583b914d405197035cf890advboxsync return;
ffb50166c9adb4ae583b914d405197035cf890advboxsync }
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync PVMCPU pVCpu = VMMGetCpu(pVM);
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync /*
ffb50166c9adb4ae583b914d405197035cf890advboxsync * Check that the jump buffer is armed.
ffb50166c9adb4ae583b914d405197035cf890advboxsync */
ffb50166c9adb4ae583b914d405197035cf890advboxsync# ifdef RT_ARCH_X86
ffb50166c9adb4ae583b914d405197035cf890advboxsync if ( !pVCpu->vmm.s.CallRing3JmpBufR0.eip
ffb50166c9adb4ae583b914d405197035cf890advboxsync || pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
ffb50166c9adb4ae583b914d405197035cf890advboxsync# else
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if ( !pVCpu->vmm.s.CallRing3JmpBufR0.rip
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync || pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
ffb50166c9adb4ae583b914d405197035cf890advboxsync# endif
ffb50166c9adb4ae583b914d405197035cf890advboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync# ifdef DEBUG
ffb50166c9adb4ae583b914d405197035cf890advboxsync SUPR0Printf("vmmR0LoggerFlush: Jump buffer isn't armed!\n");
ffb50166c9adb4ae583b914d405197035cf890advboxsync# endif
ffb50166c9adb4ae583b914d405197035cf890advboxsync return;
ffb50166c9adb4ae583b914d405197035cf890advboxsync }
ffb50166c9adb4ae583b914d405197035cf890advboxsync VMMRZCallRing3(pVM, pVCpu, VMMCALLRING3_VMM_LOGGER_FLUSH, 0);
ffb50166c9adb4ae583b914d405197035cf890advboxsync#endif
3c6306a66deef467e3c13483dd6529e1e1c6b822vboxsync}
ffb50166c9adb4ae583b914d405197035cf890advboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Interal R0 logger worker: Custom prefix.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync *
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * @returns Number of chars written.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync *
ffb50166c9adb4ae583b914d405197035cf890advboxsync * @param pLogger The logger instance.
ffb50166c9adb4ae583b914d405197035cf890advboxsync * @param pchBuf The output buffer.
ffb50166c9adb4ae583b914d405197035cf890advboxsync * @param cchBuf The size of the buffer.
ffb50166c9adb4ae583b914d405197035cf890advboxsync * @param pvUser User argument (ignored).
ffb50166c9adb4ae583b914d405197035cf890advboxsync */
ffb50166c9adb4ae583b914d405197035cf890advboxsyncVMMR0DECL(size_t) vmmR0LoggerPrefix(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser)
ffb50166c9adb4ae583b914d405197035cf890advboxsync{
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync NOREF(pvUser);
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#ifdef LOG_ENABLED
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if ( !VALID_PTR(pR0Logger)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync || !VALID_PTR(pR0Logger + 1)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync || pLogger->u32Magic != RTLOGGER_MAGIC
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync || cchBuf < 2)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return 0;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync static const char s_szHex[17] = "0123456789abcdef";
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync VMCPUID const idCpu = pR0Logger->idCpu;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync pchBuf[1] = s_szHex[ idCpu & 15];
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync pchBuf[0] = s_szHex[(idCpu >> 4) & 15];
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync
b4d7b4dbcc45b8bde7502aa129440d92d7ffd038vboxsync return 2;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync#else
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync return 0;
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#endif
ffb50166c9adb4ae583b914d405197035cf890advboxsync}
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync#ifdef LOG_ENABLED
ffb50166c9adb4ae583b914d405197035cf890advboxsync/**
ffb50166c9adb4ae583b914d405197035cf890advboxsync * Disables flushing of the ring-0 debug log.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync *
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync * @param pVCpu The shared virtual cpu structure.
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncVMMR0DECL(void) VMMR0LogFlushDisable(PVMCPU pVCpu)
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync{
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync PVM pVM = pVCpu->pVMR0;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync if (pVCpu->vmm.s.pR0LoggerR0)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = true;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync/**
ffb50166c9adb4ae583b914d405197035cf890advboxsync * Enables flushing of the ring-0 debug log.
ffb50166c9adb4ae583b914d405197035cf890advboxsync *
ffb50166c9adb4ae583b914d405197035cf890advboxsync * @param pVCpu The shared virtual cpu structure.
ffb50166c9adb4ae583b914d405197035cf890advboxsync */
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsyncVMMR0DECL(void) VMMR0LogFlushEnable(PVMCPU pVCpu)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync{
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync PVM pVM = pVCpu->pVMR0;
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (pVCpu->vmm.s.pR0LoggerR0)
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = false;
c89333d3e41e439ed9e74768000edc399d3e72e6vboxsync}
ffb50166c9adb4ae583b914d405197035cf890advboxsync#endif
ffb50166c9adb4ae583b914d405197035cf890advboxsync
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync/**
ffb50166c9adb4ae583b914d405197035cf890advboxsync * Jump back to ring-3 if we're the EMT and the longjmp is armed.
ffb50166c9adb4ae583b914d405197035cf890advboxsync *
ffb50166c9adb4ae583b914d405197035cf890advboxsync * @returns true if the breakpoint should be hit, false if it should be ignored.
ffb50166c9adb4ae583b914d405197035cf890advboxsync */
ffb50166c9adb4ae583b914d405197035cf890advboxsyncDECLEXPORT(bool) RTCALL RTAssertShouldPanic(void)
ffb50166c9adb4ae583b914d405197035cf890advboxsync{
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync#if 0
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync return true;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#else
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
750df3fe104e01cadbc3d5bd20243055d283d4e5vboxsync if (pVM)
ffb50166c9adb4ae583b914d405197035cf890advboxsync {
ffb50166c9adb4ae583b914d405197035cf890advboxsync PVMCPU pVCpu = VMMGetCpu(pVM);
ffb50166c9adb4ae583b914d405197035cf890advboxsync
ffb50166c9adb4ae583b914d405197035cf890advboxsync if (pVCpu)
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync {
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync#ifdef RT_ARCH_X86
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync if ( pVCpu->vmm.s.CallRing3JmpBufR0.eip
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync && !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync#else
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync if ( pVCpu->vmm.s.CallRing3JmpBufR0.rip
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync && !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync#endif
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync {
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync int rc = VMMRZCallRing3(pVM, pVCpu, VMMCALLRING3_VM_R0_ASSERTION, 0);
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync return RT_FAILURE_NP(rc);
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync }
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync }
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync }
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync#ifdef RT_OS_LINUX
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync return true;
ffb50166c9adb4ae583b914d405197035cf890advboxsync#else
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync return false;
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync#endif
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync#endif
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync}
ffb50166c9adb4ae583b914d405197035cf890advboxsync
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync/**
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync * Override this so we can push it up to ring-3.
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync *
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync * @param pszExpr Expression. Can be NULL.
ffb50166c9adb4ae583b914d405197035cf890advboxsync * @param uLine Location line number.
ffb50166c9adb4ae583b914d405197035cf890advboxsync * @param pszFile Location file name.
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync * @param pszFunction Location function name.
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncDECLEXPORT(void) RTCALL RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync{
6475559a7e0e52892efbab4fbdedc879f6866109vboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * To the log.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogAlways(("\n!!R0-Assertion Failed!!\n"
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync "Expression: %s\n"
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync "Location : %s(%d) %s\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pszExpr, pszFile, uLine, pszFunction));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * To the global VMM buffer.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (pVM)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTStrPrintf(pVM->vmm.s.szRing0AssertMsg1, sizeof(pVM->vmm.s.szRing0AssertMsg1),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync "\n!!R0-Assertion Failed!!\n"
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync "Expression: %s\n"
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync "Location : %s(%d) %s\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync pszExpr, pszFile, uLine, pszFunction);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Continue the normal way.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync RTAssertMsg1(pszExpr, uLine, pszFile, pszFunction);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync}
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync/**
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Callback for RTLogFormatV which writes to the ring-3 log port.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * See PFNLOGOUTPUT() for details.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic DECLCALLBACK(size_t) rtLogOutput(void *pv, const char *pachChars, size_t cbChars)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync{
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);
}