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