VMMR0.cpp revision f26998e651e8194c412c6de164723b32da1bff3e
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/* $Id$ */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/** @file
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * VMM - Host Context Ring 0.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Copyright (C) 2006-2012 Oracle Corporation
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * available from http://www.virtualbox.org. This file is free software;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * you can redistribute it and/or modify it under the terms of the GNU
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * General Public License (GPL) as published by the Free Software
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/*******************************************************************************
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync* Header Files *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync*******************************************************************************/
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#define LOG_GROUP LOG_GROUP_VMM
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/vmm/vmm.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/sup.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/vmm/trpm.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/vmm/cpum.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/vmm/pdmapi.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/vmm/pgm.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/vmm/stam.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/vmm/tm.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include "VMMInternal.h"
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/vmm/vm.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_PCI_PASSTHROUGH
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync# include <VBox/vmm/pdmpci.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/vmm/gvmm.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/vmm/gmm.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/intnet.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/vmm/hm.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/param.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/err.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/version.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <VBox/log.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <iprt/asm-amd64-x86.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <iprt/assert.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <iprt/crc.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <iprt/mp.h>
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#include <iprt/once.h>
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#include <iprt/stdarg.h>
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#include <iprt/string.h>
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#include <iprt/thread.h>
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#include <iprt/timer.h>
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#include "dtrace/VBoxVMM.h"
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#if defined(_MSC_VER) && defined(RT_ARCH_AMD64) /** @todo check this with with VC7! */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync# pragma intrinsic(_AddressOfReturnAddress)
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#endif
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/*******************************************************************************
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync* Internal Functions *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync*******************************************************************************/
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncRT_C_DECLS_BEGIN
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#if defined(RT_ARCH_X86) && (defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncextern uint64_t __udivdi3(uint64_t, uint64_t);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncextern uint64_t __umoddi3(uint64_t, uint64_t);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncRT_C_DECLS_END
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/*******************************************************************************
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync* Global Variables *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync*******************************************************************************/
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/** Drag in necessary library bits.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * The runtime lives here (in VMMR0.r0) and VBoxDD*R0.r0 links against us. */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncPFNRT g_VMMGCDeps[] =
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync (PFNRT)RTCrc32,
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync (PFNRT)RTOnce,
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#if defined(RT_ARCH_X86) && (defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync (PFNRT)__udivdi3,
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync (PFNRT)__umoddi3,
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync NULL
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync};
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef RT_OS_SOLARIS
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/* Dependency information for the native solaris loader. */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncextern "C" { char _depends_on[] = "vboxdrv"; }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/**
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Initialize the module.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * This is called when we're first loaded.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @returns 0 on success.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @returns VBox status on failure.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param hMod Image handle for use in APIs.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncDECLEXPORT(int) ModuleInit(void *hMod)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_DTRACE_R0
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * The first thing to do is register the static tracepoints.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * (Deregistration is automatic.)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync int rc2 = SUPR0TracerRegisterModule(hMod, &g_VTGObjHeader);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_FAILURE(rc2))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return rc2;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync LogFlow(("ModuleInit:\n"));
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_64ON32_CMOS_DEBUG
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Display the CMOS debug code.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync ASMOutU8(0x72, 0x03);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync uint8_t bDebugCode = ASMInU8(0x73);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogRel(("CMOS Debug Code: %#x (%d)\n", bDebugCode, bDebugCode));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync RTLogComPrintf("CMOS Debug Code: %#x (%d)\n", bDebugCode, bDebugCode);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Initialize the VMM, GVMM, GMM, HM, PGM (Darwin) and INTNET.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync int rc = vmmInitFormatTypes();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_SUCCESS(rc))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = GVMMR0Init();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_SUCCESS(rc))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = GMMR0Init();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_SUCCESS(rc))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = HMR0Init();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_SUCCESS(rc))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = PGMRegisterStringFormatTypes();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_SUCCESS(rc))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = PGMR0DynMapInit();
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_SUCCESS(rc))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = IntNetR0Init();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_SUCCESS(rc))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_PCI_PASSTHROUGH
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = PciRawR0Init();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_SUCCESS(rc))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = CPUMR0ModuleInit();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_SUCCESS(rc))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_TRIPLE_FAULT_HACK
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = vmmR0TripleFaultHackInit();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_SUCCESS(rc))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogFlow(("ModuleInit: returns success.\n"));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VINF_SUCCESS;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Bail out.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_TRIPLE_FAULT_HACK
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync vmmR0TripleFaultHackTerm();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogRel(("ModuleInit: CPUMR0ModuleInit -> %Rrc\n", rc));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_PCI_PASSTHROUGH
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync PciRawR0Term();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogRel(("ModuleInit: PciRawR0Init -> %Rrc\n", rc));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync IntNetR0Term();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogRel(("ModuleInit: IntNetR0Init -> %Rrc\n", rc));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync PGMR0DynMapTerm();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogRel(("ModuleInit: PGMR0DynMapInit -> %Rrc\n", rc));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync PGMDeregisterStringFormatTypes();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogRel(("ModuleInit: PGMRegisterStringFormatTypes -> %Rrc\n", rc));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync HMR0Term();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogRel(("ModuleInit: HMR0Init -> %Rrc\n", rc));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync GMMR0Term();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogRel(("ModuleInit: GMMR0Init -> %Rrc\n", rc));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync GVMMR0Term();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogRel(("ModuleInit: GVMMR0Init -> %Rrc\n", rc));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync vmmTermFormatTypes();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogRel(("ModuleInit: vmmInitFormatTypes -> %Rrc\n", rc));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogFlow(("ModuleInit: failed %Rrc\n", rc));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return rc;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync}
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/**
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Terminate the module.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * This is called when we're finally unloaded.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param hMod Image handle for use in APIs.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncDECLEXPORT(void) ModuleTerm(void *hMod)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogFlow(("ModuleTerm:\n"));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Terminate the CPUM module (Local APIC cleanup).
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync CPUMR0ModuleTerm();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Terminate the internal network service.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync IntNetR0Term();
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /*
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync * PGM (Darwin), HM and PciRaw global cleanup.
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync PGMR0DynMapTerm();
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#endif
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#ifdef VBOX_WITH_PCI_PASSTHROUGH
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync PciRawR0Term();
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#endif
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync PGMDeregisterStringFormatTypes();
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync HMR0Term();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_TRIPLE_FAULT_HACK
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync vmmR0TripleFaultHackTerm();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Destroy the GMM and GVMM instances.
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync */
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync GMMR0Term();
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync GVMMR0Term();
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync vmmTermFormatTypes();
270236340676d2385b27ea992e07fcb643bb78b6vboxsync
270236340676d2385b27ea992e07fcb643bb78b6vboxsync LogFlow(("ModuleTerm: returns\n"));
270236340676d2385b27ea992e07fcb643bb78b6vboxsync}
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
270236340676d2385b27ea992e07fcb643bb78b6vboxsync
270236340676d2385b27ea992e07fcb643bb78b6vboxsync/**
270236340676d2385b27ea992e07fcb643bb78b6vboxsync * Initiates the R0 driver for a particular VM instance.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @returns VBox status code.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param pVM Pointer to the VM.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param uSvnRev The SVN revision of the ring-3 part.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param uBuildType Build type indicator.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @thread EMT.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncstatic int vmmR0InitVM(PVM pVM, uint32_t uSvnRev, uint32_t uBuildType)
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Match the SVN revisions and build type.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (uSvnRev != VMMGetSvnRev())
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync LogRel(("VMMR0InitVM: Revision mismatch, r3=%d r0=%d\n", uSvnRev, VMMGetSvnRev()));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync SUPR0Printf("VMMR0InitVM: Revision mismatch, r3=%d r0=%d\n", uSvnRev, VMMGetSvnRev());
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_VMM_R0_VERSION_MISMATCH;
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync }
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync if (uBuildType != vmmGetBuildType())
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync {
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync LogRel(("VMMR0InitVM: Build type mismatch, r3=%#x r0=%#x\n", uBuildType, vmmGetBuildType()));
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync SUPR0Printf("VMMR0InitVM: Build type mismatch, r3=%#x r0=%#x\n", uBuildType, vmmGetBuildType());
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync return VERR_VMM_R0_VERSION_MISMATCH;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if ( !VALID_PTR(pVM)
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync || pVM->pVMR0 != pVM)
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync return VERR_INVALID_PARAMETER;
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef LOG_ENABLED
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync * Register the EMT R0 logger instance for VCPU 0.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync PVMCPU pVCpu = &pVM->aCpus[0];
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync PVMMR0LOGGER pR0Logger = pVCpu->vmm.s.pR0LoggerR0;
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync if (pR0Logger)
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync {
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync# if 0 /* testing of the logger. */
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: before %p\n", RTLogDefaultInstance()));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: pfnFlush=%p actual=%p\n", pR0Logger->Logger.pfnFlush, vmmR0LoggerFlush));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: pfnLogger=%p actual=%p\n", pR0Logger->Logger.pfnLogger, vmmR0LoggerWrapper));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: offScratch=%d fFlags=%#x fDestFlags=%#x\n", pR0Logger->Logger.offScratch, pR0Logger->Logger.fFlags, pR0Logger->Logger.fDestFlags));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: after %p reg\n", RTLogDefaultInstance()));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync RTLogSetDefaultInstanceThread(NULL, pVM->pSession);
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: after %p dereg\n", RTLogDefaultInstance()));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: returned successfully from direct logger call.\n"));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync pR0Logger->Logger.pfnFlush(&pR0Logger->Logger);
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: returned successfully from direct flush call.\n"));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: after %p reg2\n", RTLogDefaultInstance()));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: returned successfully from direct logger call (2). offScratch=%d\n", pR0Logger->Logger.offScratch));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync RTLogSetDefaultInstanceThread(NULL, pVM->pSession);
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: after %p dereg2\n", RTLogDefaultInstance()));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync RTLogLoggerEx(&pR0Logger->Logger, 0, ~0U, "hello ring-0 logger (RTLogLoggerEx)\n");
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: RTLogLoggerEx returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync RTLogPrintf("hello ring-0 logger (RTLogPrintf)\n");
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync LogCom(("vmmR0InitVM: RTLogPrintf returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync# endif
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync Log(("Switching to per-thread logging instance %p (key=%p)\n", &pR0Logger->Logger, pVM->pSession));
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync pR0Logger->fRegistered = true;
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync }
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync#endif /* LOG_ENABLED */
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync /*
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync * Check if the host supports high resolution timers or not.
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync */
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync if ( pVM->vmm.s.fUsePeriodicPreemptionTimers
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync && !RTTimerCanDoHighResolution())
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync pVM->vmm.s.fUsePeriodicPreemptionTimers = false;
270236340676d2385b27ea992e07fcb643bb78b6vboxsync
270236340676d2385b27ea992e07fcb643bb78b6vboxsync /*
270236340676d2385b27ea992e07fcb643bb78b6vboxsync * Initialize the per VM data for GVMM and GMM.
270236340676d2385b27ea992e07fcb643bb78b6vboxsync */
270236340676d2385b27ea992e07fcb643bb78b6vboxsync int rc = GVMMR0InitVM(pVM);
270236340676d2385b27ea992e07fcb643bb78b6vboxsync// if (RT_SUCCESS(rc))
270236340676d2385b27ea992e07fcb643bb78b6vboxsync// rc = GMMR0InitPerVMData(pVM);
270236340676d2385b27ea992e07fcb643bb78b6vboxsync if (RT_SUCCESS(rc))
270236340676d2385b27ea992e07fcb643bb78b6vboxsync {
270236340676d2385b27ea992e07fcb643bb78b6vboxsync /*
270236340676d2385b27ea992e07fcb643bb78b6vboxsync * Init HM, CPUM and PGM (Darwin only).
270236340676d2385b27ea992e07fcb643bb78b6vboxsync */
270236340676d2385b27ea992e07fcb643bb78b6vboxsync rc = HMR0InitVM(pVM);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_SUCCESS(rc))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = CPUMR0InitVM(pVM);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync if (RT_SUCCESS(rc))
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync {
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync rc = PGMR0DynMapInitVM(pVM);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync#endif
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if (RT_SUCCESS(rc))
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync {
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync#ifdef VBOX_WITH_PCI_PASSTHROUGH
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync rc = PciRawR0InitVM(pVM);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync#endif
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync if (RT_SUCCESS(rc))
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync {
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync GVMMR0DoneInitVM(pVM);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync return rc;
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /* bail out */
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync }
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#ifdef VBOX_WITH_PCI_PASSTHROUGH
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync PciRawR0TermVM(pVM);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync HMR0TermVM(pVM);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync }
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync }
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync RTLogSetDefaultInstanceThread(NULL, (uintptr_t)pVM->pSession);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync return rc;
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync}
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync/**
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * Terminates the R0 bits for a particular VM instance.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync *
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * This is normally called by ring-3 as part of the VM termination process, but
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * may alternatively be called during the support driver session cleanup when
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * the VM object is destroyed (see GVMM).
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync *
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @returns VBox status code.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync *
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @param pVM Pointer to the VM.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @param pGVM Pointer to the global VM structure. Optional.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @thread EMT or session clean up thread.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync */
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsyncVMMR0DECL(int) VMMR0TermVM(PVM pVM, PGVM pGVM)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_PCI_PASSTHROUGH
270236340676d2385b27ea992e07fcb643bb78b6vboxsync PciRawR0TermVM(pVM);
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync#endif
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync /*
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync * Tell GVMM what we're up to and check that we only do this once.
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync */
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync if (GVMMR0DoingTermVM(pVM, pGVM))
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync {
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync /** @todo I wish to call PGMR0PhysFlushHandyPages(pVM, &pVM->aCpus[idCpu])
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * here to make sure we don't leak any shared pages if we crash... */
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync PGMR0DynMapTermVM(pVM);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync#endif
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync HMR0TermVM(pVM);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync }
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync /*
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * Deregister the logger.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync */
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync RTLogSetDefaultInstanceThread(NULL, (uintptr_t)pVM->pSession);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync return VINF_SUCCESS;
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync}
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync/**
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * Creates R0 thread-context hooks for the current EMT thread.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync *
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @returns VBox status code.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync *
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @param pVCpu Pointer to the VMCPU.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @thread EMT.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync */
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsyncVMMR0DECL(int) VMMR0ThreadCtxHooksCreate(PVMCPU pVCpu)
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync{
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync VMCPU_ASSERT_EMT(pVCpu);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync Assert(pVCpu->vmm.s.hR0ThreadCtx == NIL_RTTHREADCTX);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync#if defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS)
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync int rc = RTThreadCtxHooksCreate(&pVCpu->vmm.s.hR0ThreadCtx);
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync if ( RT_FAILURE(rc)
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync && rc != VERR_NOT_SUPPORTED)
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync {
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync Log(("RTThreadCtxHooksCreate failed! rc=%Rrc pVCpu=%p idCpu=%RU32\n", rc, pVCpu, pVCpu->idCpu));
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync return rc;
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync }
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync#endif
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync return VINF_SUCCESS;
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync}
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync/**
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync * Releases the object reference for the thread-context hook.
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync *
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @param pVCpu Pointer to the VMCPU.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @remarks Can be called from any thread.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync */
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsyncVMMR0DECL(void) VMMR0ThreadCtxHooksRelease(PVMCPU pVCpu)
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync RTThreadCtxHooksRelease(pVCpu->vmm.s.hR0ThreadCtx);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync}
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync/**
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync * Registers the thread-context hook for this VCPU.
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync *
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync * @returns VBox status code.
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync * @param pVCpu Pointer to the VMCPU.
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync * @param pfnThreadHook Pointer to the thread-context callback.
270236340676d2385b27ea992e07fcb643bb78b6vboxsync *
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync * @thread EMT.
270236340676d2385b27ea992e07fcb643bb78b6vboxsync */
270236340676d2385b27ea992e07fcb643bb78b6vboxsyncVMMR0DECL(int) VMMR0ThreadCtxHooksRegister(PVMCPU pVCpu, PFNRTTHREADCTXHOOK pfnThreadHook)
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync{
270236340676d2385b27ea992e07fcb643bb78b6vboxsync VMCPU_ASSERT_EMT(pVCpu);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync return RTThreadCtxHooksRegister(pVCpu->vmm.s.hR0ThreadCtx, pfnThreadHook, pVCpu);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync}
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync/**
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * Deregisters the thread-context hook for this VCPU.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync *
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @returns VBox status code.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @param pVCpu Pointer to the VMCPU.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync *
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @thread EMT.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync */
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsyncVMMR0DECL(int) VMMR0ThreadCtxHooksDeregister(PVMCPU pVCpu)
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync{
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync return RTThreadCtxHooksDeregister(pVCpu->vmm.s.hR0ThreadCtx);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync}
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync/**
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync * Whether thread-context hooks are created (implying they're supported) on this
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * platform.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @returns true if the hooks are created, false otherwise.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @param pVCpu Pointer to the VMCPU.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync *
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @remarks Can be called from any thread.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync */
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsyncVMMR0DECL(bool) VMMR0ThreadCtxHooksAreCreated(PVMCPU pVCpu)
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync{
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync return pVCpu->vmm.s.hR0ThreadCtx != NIL_RTTHREADCTX;
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync}
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync/**
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * Whether thread-context hooks are registered for this VCPU.
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync *
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync * @returns true if registered, false otherwise.
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync * @param pVCpu Pointer to the VMCPU.
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync */
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsyncVMMR0DECL(bool) VMMR0ThreadCtxHooksAreRegistered(PVMCPU pVCpu)
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return RTThreadCtxHooksAreRegistered(pVCpu->vmm.s.hR0ThreadCtx);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync}
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/**
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * VMM ring-0 thread-context callback.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * This does common HM state updating and calls the HM-specific thread-context
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * callback.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param enmEvent The thread-context event.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param pvUser Opaque pointer to the VMCPU.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsyncstatic DECLCALLBACK(void) vmmR0ThreadCtxCallback(RTTHREADCTXEVENT enmEvent, void *pvUser)
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync{
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync PVMCPU pVCpu = (PVMCPU)pvUser;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync switch (enmEvent)
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync case RTTHREADCTXEVENT_RESUMED:
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /** @todo Linux may call us with preemption enabled (really!) but technically we
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync * cannot get preempted here, otherwise we end up in an infinite recursion
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync * scenario (i.e. preempted in resume hook -> preempt hook -> resume hook... ad
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync * infinitum). Let's just disable preemption for now...
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync HM_DISABLE_PREEMPT_IF_NEEDED();
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /* We need to update the VCPU <-> host CPU mapping. */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync RTCPUID idHostCpu = RTMpCpuId();
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, idHostCpu);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /* Invoke the HM-specific thread-context callback. */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync HMR0ThreadCtxCallback(enmEvent, pvUser);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /* Restore preemption. */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync HM_RESTORE_PREEMPT_IF_NEEDED();
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case RTTHREADCTXEVENT_PREEMPTING:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /* Invoke the HM-specific thread-context callback. */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync HMR0ThreadCtxCallback(enmEvent, pvUser);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Sigh. See VMMGetCpu() used by VMCPU_ASSERT_EMT(). We cannot let several VCPUs
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * have the same host CPU associated with it.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, NIL_RTCPUID);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync default:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /* Invoke the HM-specific thread-context callback. */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync HMR0ThreadCtxCallback(enmEvent, pvUser);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync }
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync}
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_STATISTICS
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/**
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Record return code statistics
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param pVM Pointer to the VM.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param pVCpu Pointer to the VMCPU.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param rc The status code.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncstatic void vmmR0RecordRC(PVM pVM, PVMCPU pVCpu, int rc)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Collect statistics.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync switch (rc)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_SUCCESS:
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetNormal);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_INTERRUPT:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterrupt);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_INTERRUPT_HYPER:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptHyper);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_GUEST_TRAP:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetGuestTrap);
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync break;
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync case VINF_EM_RAW_RING_SWITCH:
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRingSwitch);
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync break;
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync case VINF_EM_RAW_RING_SWITCH_INT:
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRingSwitchInt);
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync break;
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync case VINF_EM_RAW_STALE_SELECTOR:
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetStaleSelector);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_IRET_TRAP:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIRETTrap);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_IOM_R3_IOPORT_READ:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIORead);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_IOM_R3_IOPORT_WRITE:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIOWrite);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_IOM_R3_MMIO_READ:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIORead);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_IOM_R3_MMIO_WRITE:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOWrite);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync case VINF_IOM_R3_MMIO_READ_WRITE:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOReadWrite);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_PATM_HC_MMIO_PATCH_READ:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchRead);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_PATM_HC_MMIO_PATCH_WRITE:
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchWrite);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_EMULATE_INSTR:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetEmulate);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_EMULATE_IO_BLOCK:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIOBlockEmulate);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_PATCH_EMULATE_INSTR:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchEmulate);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_EMULATE_INSTR_LDT_FAULT:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetLDTFault);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetGDTFault);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_EMULATE_INSTR_IDT_FAULT:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIDTFault);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_EMULATE_INSTR_TSS_FAULT:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetTSSFault);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_EMULATE_INSTR_PD_FAULT:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPDFault);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_CSAM_PENDING_ACTION:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetCSAMTask);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_PGM_SYNC_CR3:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetSyncCR3);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_PATM_PATCH_INT3:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchInt3);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_PATM_PATCH_TRAP_PF:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchPF);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_PATM_PATCH_TRAP_GP:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchGP);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_PATM_PENDING_IRQ_AFTER_IRET:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchIretIRQ);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RESCHEDULE_REM:
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRescheduleREM);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync break;
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync case VINF_EM_RAW_TO_R3:
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync if (VM_FF_IS_PENDING(pVM, VM_FF_TM_VIRTUAL_SYNC))
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3TMVirt);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync else if (VM_FF_IS_PENDING(pVM, VM_FF_PGM_NEED_HANDY_PAGES))
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3HandyPages);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync else if (VM_FF_IS_PENDING(pVM, VM_FF_PDM_QUEUES))
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3PDMQueues);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync else if (VM_FF_IS_PENDING(pVM, VM_FF_EMT_RENDEZVOUS))
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3Rendezvous);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync else if (VM_FF_IS_PENDING(pVM, VM_FF_PDM_DMA))
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3DMA);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_TIMER))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3Timer);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_PDM_CRITSECT))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3CritSect);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else if (VMCPU_FF_IS_PENDING(pVCpu, VMCPU_FF_TO_R3))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3Unknown);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_TIMER_PENDING:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetTimerPending);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_EM_RAW_INTERRUPT_PENDING:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptPending);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync case VINF_VMM_CALL_HOST:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync switch (pVCpu->vmm.s.enmCallRing3Operation)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMCALLRING3_PDM_CRIT_SECT_ENTER:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPDMCritSectEnter);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMCALLRING3_PDM_LOCK:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPDMLock);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMCALLRING3_PGM_POOL_GROW:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMPoolGrow);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMCALLRING3_PGM_LOCK:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMLock);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMCALLRING3_PGM_MAP_CHUNK:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMMapChunk);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMCALLRING3_PGM_ALLOCATE_HANDY_PAGES:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMAllocHandy);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMCALLRING3_REM_REPLAY_HANDLER_NOTIFICATIONS:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallRemReplay);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMCALLRING3_VMM_LOGGER_FLUSH:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallLogFlush);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMCALLRING3_VM_SET_ERROR:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetError);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMCALLRING3_VM_SET_RUNTIME_ERROR:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetRuntimeError);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMCALLRING3_VM_R0_ASSERTION:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync default:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetCallRing3);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_PATM_DUPLICATE_FUNCTION:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPATMDuplicateFn);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_PGM_CHANGE_MODE:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPGMChangeMode);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VINF_PGM_POOL_FLUSH_PENDING:
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPGMFlushPending);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync break;
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync case VINF_EM_PENDING_REQUEST:
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPendingRequest);
f372af8e6ee2a011213b11cc69f4a29530ff7ce5vboxsync break;
270236340676d2385b27ea992e07fcb643bb78b6vboxsync case VINF_EM_HM_PATCH_TPR_INSTR:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchTPR);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync default:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMisc);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync}
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif /* VBOX_WITH_STATISTICS */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/**
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Unused ring-0 entry point that used to be called from the interrupt gate.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Will be removed one of the next times we do a major SUPDrv version bump.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @returns VBox status code.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param pVM Pointer to the VM.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param enmOperation Which operation to execute.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param pvArg Argument to the operation.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @remarks Assume called with interrupts disabled.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncVMMR0DECL(int) VMMR0EntryInt(PVM pVM, VMMR0OPERATION enmOperation, void *pvArg)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * We're returning VERR_NOT_SUPPORT here so we've got something else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * than -1 which the interrupt gate glue code might return.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync Log(("operation %#x is not supported\n", enmOperation));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync NOREF(enmOperation); NOREF(pvArg); NOREF(pVM);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_NOT_SUPPORTED;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync}
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/**
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * The Ring 0 entry point, called by the fast-ioctl path.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param pVM Pointer to the VM.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * The return code is stored in pVM->vmm.s.iLastGZRc.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param idCpu The Virtual CPU ID of the calling EMT.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param enmOperation Which operation to execute.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @remarks Assume called with interrupts _enabled_.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncVMMR0DECL(void) VMMR0EntryFast(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_UNLIKELY(idCpu >= pVM->cCpus))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync PVMCPU pVCpu = &pVM->aCpus[idCpu];
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync switch (enmOperation)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Switch to GC and run guest raw mode code.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Disable interrupts before doing the world switch.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_RAW_RUN:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifndef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /* Some safety precautions first. */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_UNLIKELY(!PGMGetHyperCR3(pVCpu)))
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync pVCpu->vmm.s.iLastGZRc = VERR_PGM_NO_CR3_SHADOW_ROOT;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync break;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync }
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#endif
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /* Disable preemption and update the periodic preemption timer. */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync RTThreadPreemptDisable(&PreemptState);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync RTCPUID idHostCpu = RTMpCpuId();
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#ifdef VBOX_WITH_VMMR0_DISABLE_LAPIC_NMI
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync CPUMR0SetLApic(pVCpu, idHostCpu);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#endif
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, idHostCpu);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if (pVM->vmm.s.fUsePeriodicPreemptionTimers)
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync GVMMR0SchedUpdatePeriodicPreemptionTimer(pVM, pVCpu->idHostCpu, TMCalcHostTimerFrequency(pVM, pVCpu));
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /* We might need to disable VT-x if the active switcher turns off paging. */
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync bool fVTxDisabled;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync int rc = HMR0EnterSwitcher(pVM, pVM->vmm.s.enmSwitcher, &fVTxDisabled);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if (RT_SUCCESS(rc))
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync RTCCUINTREG uFlags = ASMIntDisableFlags();
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync for (;;)
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED_EXEC);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync TMNotifyStartOfExecution(pVCpu);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync rc = pVM->vmm.s.pfnR0ToRawMode(pVM);
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync pVCpu->vmm.s.iLastGZRc = rc;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync TMNotifyEndOfExecution(pVCpu);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync if (rc != VINF_VMM_CALL_TRACER)
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync break;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync SUPR0TracerUmodProbeFire(pVM->pSession, &pVCpu->vmm.s.TracerCtx);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync }
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /* Re-enable VT-x if previously turned off. */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync HMR0LeaveSwitcher(pVM, fVTxDisabled);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if ( rc == VINF_EM_RAW_INTERRUPT
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync || rc == VINF_EM_RAW_INTERRUPT_HYPER)
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync TRPMR0DispatchHostInterrupt(pVM);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync ASMSetFlags(uFlags);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#ifdef VBOX_WITH_STATISTICS
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRunRC);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync vmmR0RecordRC(pVM, pVCpu, rc);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#endif
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync }
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync else
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync pVCpu->vmm.s.iLastGZRc = rc;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, NIL_RTCPUID);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync RTThreadPreemptRestore(&PreemptState);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync break;
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync }
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /*
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync * Run guest code using the available hardware acceleration technology.
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync case VMMR0_DO_HM_RUN:
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync Assert(!VMMR0ThreadCtxHooksAreRegistered(pVCpu));
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync RTThreadPreemptDisable(&PreemptState);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /* Update the VCPU <-> host CPU mapping before doing anything else. */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, RTMpCpuId());
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if (pVM->vmm.s.fUsePeriodicPreemptionTimers)
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync GVMMR0SchedUpdatePeriodicPreemptionTimer(pVM, pVCpu->idHostCpu, TMCalcHostTimerFrequency(pVM, pVCpu));
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#ifdef LOG_ENABLED
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if (pVCpu->idCpu > 0)
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync /* Lazy registration of ring 0 loggers. */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync PVMMR0LOGGER pR0Logger = pVCpu->vmm.s.pR0LoggerR0;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if ( pR0Logger
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync && !pR0Logger->fRegistered)
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync pR0Logger->fRegistered = true;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync }
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync }
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync#endif
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync int rc;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync bool fPreemptRestored = false;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if (!HMR0SuspendPending())
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /* Register thread-context hooks if required. */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if ( VMMR0ThreadCtxHooksAreCreated(pVCpu)
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync && !VMMR0ThreadCtxHooksAreRegistered(pVCpu))
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync rc = VMMR0ThreadCtxHooksRegister(pVCpu, vmmR0ThreadCtxCallback);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync AssertRC(rc);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync }
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /* Enter HM context. */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync rc = HMR0Enter(pVM, pVCpu);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if (RT_SUCCESS(rc))
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED_HM);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /* When preemption hooks are in place, enable preemption now that we're in HM context. */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if (VMMR0ThreadCtxHooksAreRegistered(pVCpu))
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync {
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync fPreemptRestored = true;
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync RTThreadPreemptRestore(&PreemptState);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync }
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /* Setup the longjmp machinery and execute guest code. */
bec4d1c0274e4712fe01426313aab120b5ad1c17vboxsync rc = vmmR0CallRing3SetJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, HMR0RunGuestCode, pVM, pVCpu);
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync /* Manual assert as normal assertions are going to crash in this case. */
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync if (RT_UNLIKELY( VMCPU_GET_STATE(pVCpu) != VMCPUSTATE_STARTED_HM
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync && RT_SUCCESS_NP(rc) && rc != VINF_VMM_CALL_HOST ))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync pVM->vmm.s.szRing0AssertMsg1[0] = '\0';
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync RTStrPrintf(pVM->vmm.s.szRing0AssertMsg2, sizeof(pVM->vmm.s.szRing0AssertMsg2),
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync "Got VMCPU state %d expected %d.\n", VMCPU_GET_STATE(pVCpu), VMCPUSTATE_STARTED_HM);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = VERR_VMM_WRONG_HM_VMCPU_STATE;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else if (RT_UNLIKELY(VMMR0ThreadCtxHooksAreRegistered(pVCpu)))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync pVM->vmm.s.szRing0AssertMsg1[0] = '\0';
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync RTStrPrintf(pVM->vmm.s.szRing0AssertMsg2, sizeof(pVM->vmm.s.szRing0AssertMsg2),
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync "Thread-context hooks still registered! VCPU=%p Id=%u rc=%d.\n", pVCpu, pVCpu->idCpu, rc);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = VERR_INVALID_STATE;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync STAM_COUNTER_INC(&pVM->vmm.s.StatRunRC);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync else
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /* System is about to go into suspend mode; go back to ring 3. */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync rc = VINF_EM_RAW_INTERRUPT;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync pVCpu->vmm.s.iLastGZRc = rc;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /* Clear the VCPU <-> host CPU mapping as we've left HM context. */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync ASMAtomicWriteU32(&pVCpu->idHostCpu, NIL_RTCPUID);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (!fPreemptRestored)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync RTThreadPreemptRestore(&PreemptState);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#ifdef VBOX_WITH_STATISTICS
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync vmmR0RecordRC(pVM, pVCpu, rc);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync#endif
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /* No special action required for external interrupts, just return. */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * For profiling.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_NOP:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync pVCpu->vmm.s.iLastGZRc = VINF_SUCCESS;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Impossible.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync default:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync AssertMsgFailed(("%#x\n", enmOperation));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync pVCpu->vmm.s.iLastGZRc = VERR_NOT_SUPPORTED;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync break;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync}
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/**
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Validates a session or VM session argument.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @returns true / false accordingly.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param pVM Pointer to the VM.
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync * @param pSession The session argument.
c6383709c15c809f8cfb09b5cfe670760f06e2b9vboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncDECLINLINE(bool) vmmR0IsValidSession(PVM pVM, PSUPDRVSESSION pClaimedSession, PSUPDRVSESSION pSession)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /* This must be set! */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (!pSession)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return false;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /* Only one out of the two. */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (pVM && pClaimedSession)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return false;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (pVM)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync pClaimedSession = pVM->pSession;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return pClaimedSession == pSession;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync}
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync/**
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * VMMR0EntryEx worker function, either called directly or when ever possible
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * called thru a longjmp so we can exit safely on failure.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync *
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @returns VBox status code.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param pVM Pointer to the VM.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param idCpu Virtual CPU ID argument. Must be NIL_VMCPUID if pVM
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * is NIL_RTR0PTR, and may be NIL_VMCPUID if it isn't
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param enmOperation Which operation to execute.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param pReqHdr This points to a SUPVMMR0REQHDR packet. Optional.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * The support driver validates this if it's present.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param u64Arg Some simple constant argument.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @param pSession The session of the caller.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * @remarks Assume called with interrupts _enabled_.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsyncstatic int vmmR0EntryExWorker(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReqHdr, uint64_t u64Arg, PSUPDRVSESSION pSession)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync{
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Common VM pointer validation.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (pVM)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_UNLIKELY( !VALID_PTR(pVM)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync || ((uintptr_t)pVM & PAGE_OFFSET_MASK)))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p! (op=%d)\n", pVM, enmOperation);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_POINTER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_UNLIKELY( pVM->enmVMState < VMSTATE_CREATING
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync || pVM->enmVMState > VMSTATE_TERMINATED
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync || pVM->pVMR0 != pVM))
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p:{enmVMState=%d, .pVMR0=%p}! (op=%d)\n",
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync pVM, pVM->enmVMState, pVM->pVMR0, enmOperation);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_POINTER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (RT_UNLIKELY(idCpu >= pVM->cCpus && idCpu != NIL_VMCPUID))
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync {
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid idCpu (%u vs cCpus=%u)\n", idCpu, pVM->cCpus);
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync return VERR_INVALID_PARAMETER;
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync }
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync }
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync else if (RT_UNLIKELY(idCpu != NIL_VMCPUID))
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync {
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync SUPR0Printf("vmmR0EntryExWorker: Invalid idCpu=%u\n", idCpu);
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync return VERR_INVALID_PARAMETER;
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync }
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync
51ef69064b4ea4d571ed129ab883b0c08967c901vboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync switch (enmOperation)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * GVM requests
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_GVMM_CREATE_VM:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (pVM || u64Arg || idCpu != NIL_VMCPUID)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_PARAMETER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return GVMMR0CreateVMReq((PGVMMCREATEVMREQ)pReqHdr);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_GVMM_DESTROY_VM:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (pReqHdr || u64Arg)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_PARAMETER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return GVMMR0DestroyVM(pVM);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_GVMM_REGISTER_VMCPU:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync {
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (!pVM)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_PARAMETER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return GVMMR0RegisterVCpu(pVM, idCpu);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync }
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_GVMM_SCHED_HALT:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (pReqHdr)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_PARAMETER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return GVMMR0SchedHalt(pVM, idCpu, u64Arg);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_GVMM_SCHED_WAKE_UP:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (pReqHdr || u64Arg)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_PARAMETER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return GVMMR0SchedWakeUp(pVM, idCpu);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_GVMM_SCHED_POKE:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (pReqHdr || u64Arg)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_PARAMETER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return GVMMR0SchedPoke(pVM, idCpu);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_GVMM_SCHED_WAKE_UP_AND_POKE_CPUS:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (u64Arg)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_PARAMETER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return GVMMR0SchedWakeUpAndPokeCpusReq(pVM, (PGVMMSCHEDWAKEUPANDPOKECPUSREQ)pReqHdr);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_GVMM_SCHED_POLL:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (pReqHdr || u64Arg > 1)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_PARAMETER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return GVMMR0SchedPoll(pVM, idCpu, !!u64Arg);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_GVMM_QUERY_STATISTICS:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (u64Arg)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_PARAMETER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return GVMMR0QueryStatisticsReq(pVM, (PGVMMQUERYSTATISTICSSREQ)pReqHdr);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_GVMM_RESET_STATISTICS:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync if (u64Arg)
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VERR_INVALID_PARAMETER;
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return GVMMR0ResetStatisticsReq(pVM, (PGVMMRESETSTATISTICSSREQ)pReqHdr);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync /*
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync * Initialize the R0 part of a VM instance.
0ab80a5f847b8c908ee2d9db5cc37da8e8dd5697vboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_VMMR0_INIT:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return vmmR0InitVM(pVM, RT_LODWORD(u64Arg), RT_HIDWORD(u64Arg));
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Terminate the R0 part of a VM instance.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_VMMR0_TERM:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return VMMR0TermVM(pVM, NULL);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Attempt to enable hm mode and check the current setting.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_HM_ENABLE:
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync return HMR0EnableAllCpus(pVM);
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync /*
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync * Setup the hardware accelerated session.
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync */
917f4ee9f101c9786cf09ea0fe7923a7f6dfe40cvboxsync case VMMR0_DO_HM_SETUP_VM:
return HMR0SetupVM(pVM);
/*
* Switch to RC to execute Hypervisor function.
*/
case VMMR0_DO_CALL_HYPERVISOR:
{
int rc;
bool fVTxDisabled;
#ifndef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
if (RT_UNLIKELY(!PGMGetHyperCR3(VMMGetCpu0(pVM))))
return VERR_PGM_NO_CR3_SHADOW_ROOT;
#endif
RTCCUINTREG fFlags = ASMIntDisableFlags();
#ifdef VBOX_WITH_VMMR0_DISABLE_LAPIC_NMI
RTCPUID idHostCpu = RTMpCpuId();
CPUMR0SetLApic(&pVM->aCpus[0], idHostCpu);
#endif
/* We might need to disable VT-x if the active switcher turns off paging. */
rc = HMR0EnterSwitcher(pVM, pVM->vmm.s.enmSwitcher, &fVTxDisabled);
if (RT_FAILURE(rc))
return rc;
rc = pVM->vmm.s.pfnR0ToRawMode(pVM);
/* Re-enable VT-x if previously turned off. */
HMR0LeaveSwitcher(pVM, fVTxDisabled);
/** @todo dispatch interrupts? */
ASMSetFlags(fFlags);
return rc;
}
/*
* PGM wrappers.
*/
case VMMR0_DO_PGM_ALLOCATE_HANDY_PAGES:
if (idCpu == NIL_VMCPUID)
return VERR_INVALID_CPU_ID;
return PGMR0PhysAllocateHandyPages(pVM, &pVM->aCpus[idCpu]);
case VMMR0_DO_PGM_FLUSH_HANDY_PAGES:
if (idCpu == NIL_VMCPUID)
return VERR_INVALID_CPU_ID;
return PGMR0PhysFlushHandyPages(pVM, &pVM->aCpus[idCpu]);
case VMMR0_DO_PGM_ALLOCATE_LARGE_HANDY_PAGE:
if (idCpu == NIL_VMCPUID)
return VERR_INVALID_CPU_ID;
return PGMR0PhysAllocateLargeHandyPage(pVM, &pVM->aCpus[idCpu]);
case VMMR0_DO_PGM_PHYS_SETUP_IOMMU:
if (idCpu != 0)
return VERR_INVALID_CPU_ID;
return PGMR0PhysSetupIommu(pVM);
/*
* GMM wrappers.
*/
case VMMR0_DO_GMM_INITIAL_RESERVATION:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0InitialReservationReq(pVM, idCpu, (PGMMINITIALRESERVATIONREQ)pReqHdr);
case VMMR0_DO_GMM_UPDATE_RESERVATION:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0UpdateReservationReq(pVM, idCpu, (PGMMUPDATERESERVATIONREQ)pReqHdr);
case VMMR0_DO_GMM_ALLOCATE_PAGES:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0AllocatePagesReq(pVM, idCpu, (PGMMALLOCATEPAGESREQ)pReqHdr);
case VMMR0_DO_GMM_FREE_PAGES:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0FreePagesReq(pVM, idCpu, (PGMMFREEPAGESREQ)pReqHdr);
case VMMR0_DO_GMM_FREE_LARGE_PAGE:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0FreeLargePageReq(pVM, idCpu, (PGMMFREELARGEPAGEREQ)pReqHdr);
case VMMR0_DO_GMM_QUERY_HYPERVISOR_MEM_STATS:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0QueryHypervisorMemoryStatsReq(pVM, (PGMMMEMSTATSREQ)pReqHdr);
case VMMR0_DO_GMM_QUERY_MEM_STATS:
if (idCpu == NIL_VMCPUID)
return VERR_INVALID_CPU_ID;
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0QueryMemoryStatsReq(pVM, idCpu, (PGMMMEMSTATSREQ)pReqHdr);
case VMMR0_DO_GMM_BALLOONED_PAGES:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0BalloonedPagesReq(pVM, idCpu, (PGMMBALLOONEDPAGESREQ)pReqHdr);
case VMMR0_DO_GMM_MAP_UNMAP_CHUNK:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0MapUnmapChunkReq(pVM, (PGMMMAPUNMAPCHUNKREQ)pReqHdr);
case VMMR0_DO_GMM_SEED_CHUNK:
if (pReqHdr)
return VERR_INVALID_PARAMETER;
return GMMR0SeedChunk(pVM, idCpu, (RTR3PTR)u64Arg);
case VMMR0_DO_GMM_REGISTER_SHARED_MODULE:
if (idCpu == NIL_VMCPUID)
return VERR_INVALID_CPU_ID;
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0RegisterSharedModuleReq(pVM, idCpu, (PGMMREGISTERSHAREDMODULEREQ)pReqHdr);
case VMMR0_DO_GMM_UNREGISTER_SHARED_MODULE:
if (idCpu == NIL_VMCPUID)
return VERR_INVALID_CPU_ID;
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0UnregisterSharedModuleReq(pVM, idCpu, (PGMMUNREGISTERSHAREDMODULEREQ)pReqHdr);
case VMMR0_DO_GMM_RESET_SHARED_MODULES:
if (idCpu == NIL_VMCPUID)
return VERR_INVALID_CPU_ID;
if ( u64Arg
|| pReqHdr)
return VERR_INVALID_PARAMETER;
return GMMR0ResetSharedModules(pVM, idCpu);
#ifdef VBOX_WITH_PAGE_SHARING
case VMMR0_DO_GMM_CHECK_SHARED_MODULES:
{
if (idCpu == NIL_VMCPUID)
return VERR_INVALID_CPU_ID;
if ( u64Arg
|| pReqHdr)
return VERR_INVALID_PARAMETER;
PVMCPU pVCpu = &pVM->aCpus[idCpu];
Assert(pVCpu->hNativeThreadR0 == RTThreadNativeSelf());
# ifdef DEBUG_sandervl
/* Make sure that log flushes can jump back to ring-3; annoying to get an incomplete log (this is risky though as the code doesn't take this into account). */
/* Todo: this can have bad side effects for unexpected jumps back to r3. */
int rc = GMMR0CheckSharedModulesStart(pVM);
if (rc == VINF_SUCCESS)
{
rc = vmmR0CallRing3SetJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, GMMR0CheckSharedModules, pVM, pVCpu); /* this may resume code. */
Assert( rc == VINF_SUCCESS
|| (rc == VINF_VMM_CALL_HOST && pVCpu->vmm.s.enmCallRing3Operation == VMMCALLRING3_VMM_LOGGER_FLUSH));
GMMR0CheckSharedModulesEnd(pVM);
}
# else
int rc = GMMR0CheckSharedModules(pVM, pVCpu);
# endif
return rc;
}
#endif
#if defined(VBOX_STRICT) && HC_ARCH_BITS == 64
case VMMR0_DO_GMM_FIND_DUPLICATE_PAGE:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0FindDuplicatePageReq(pVM, (PGMMFINDDUPLICATEPAGEREQ)pReqHdr);
#endif
case VMMR0_DO_GMM_QUERY_STATISTICS:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0QueryStatisticsReq(pVM, (PGMMQUERYSTATISTICSSREQ)pReqHdr);
case VMMR0_DO_GMM_RESET_STATISTICS:
if (u64Arg)
return VERR_INVALID_PARAMETER;
return GMMR0ResetStatisticsReq(pVM, (PGMMRESETSTATISTICSSREQ)pReqHdr);
/*
* A quick GCFGM mock-up.
*/
/** @todo GCFGM with proper access control, ring-3 management interface and all that. */
case VMMR0_DO_GCFGM_SET_VALUE:
case VMMR0_DO_GCFGM_QUERY_VALUE:
{
if (pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
PGCFGMVALUEREQ pReq = (PGCFGMVALUEREQ)pReqHdr;
if (pReq->Hdr.cbReq != sizeof(*pReq))
return VERR_INVALID_PARAMETER;
int rc;
if (enmOperation == VMMR0_DO_GCFGM_SET_VALUE)
{
rc = GVMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
//if (rc == VERR_CFGM_VALUE_NOT_FOUND)
// rc = GMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
}
else
{
rc = GVMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
//if (rc == VERR_CFGM_VALUE_NOT_FOUND)
// rc = GMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
}
return rc;
}
/*
* PDM Wrappers.
*/
case VMMR0_DO_PDM_DRIVER_CALL_REQ_HANDLER:
{
if (!pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return PDMR0DriverCallReqHandler(pVM, (PPDMDRIVERCALLREQHANDLERREQ)pReqHdr);
}
case VMMR0_DO_PDM_DEVICE_CALL_REQ_HANDLER:
{
if (!pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return PDMR0DeviceCallReqHandler(pVM, (PPDMDEVICECALLREQHANDLERREQ)pReqHdr);
}
/*
* Requests to the internal networking service.
*/
case VMMR0_DO_INTNET_OPEN:
{
PINTNETOPENREQ pReq = (PINTNETOPENREQ)pReqHdr;
if (u64Arg || !pReq || !vmmR0IsValidSession(pVM, pReq->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return IntNetR0OpenReq(pSession, pReq);
}
case VMMR0_DO_INTNET_IF_CLOSE:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFCLOSEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return IntNetR0IfCloseReq(pSession, (PINTNETIFCLOSEREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_GET_BUFFER_PTRS:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFGETBUFFERPTRSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return IntNetR0IfGetBufferPtrsReq(pSession, (PINTNETIFGETBUFFERPTRSREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return IntNetR0IfSetPromiscuousModeReq(pSession, (PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_SET_MAC_ADDRESS:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETMACADDRESSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return IntNetR0IfSetMacAddressReq(pSession, (PINTNETIFSETMACADDRESSREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_SET_ACTIVE:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETACTIVEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return IntNetR0IfSetActiveReq(pSession, (PINTNETIFSETACTIVEREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_SEND:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSENDREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return IntNetR0IfSendReq(pSession, (PINTNETIFSENDREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_WAIT:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return IntNetR0IfWaitReq(pSession, (PINTNETIFWAITREQ)pReqHdr);
case VMMR0_DO_INTNET_IF_ABORT_WAIT:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return IntNetR0IfAbortWaitReq(pSession, (PINTNETIFABORTWAITREQ)pReqHdr);
#ifdef VBOX_WITH_PCI_PASSTHROUGH
/*
* Requests to host PCI driver service.
*/
case VMMR0_DO_PCIRAW_REQ:
if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PPCIRAWSENDREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
return VERR_INVALID_PARAMETER;
return PciRawR0ProcessReq(pSession, pVM, (PPCIRAWSENDREQ)pReqHdr);
#endif
/*
* For profiling.
*/
case VMMR0_DO_NOP:
case VMMR0_DO_SLOW_NOP:
return VINF_SUCCESS;
/*
* For testing Ring-0 APIs invoked in this environment.
*/
case VMMR0_DO_TESTS:
/** @todo make new test */
return VINF_SUCCESS;
#if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
case VMMR0_DO_TEST_SWITCHER3264:
if (idCpu == NIL_VMCPUID)
return VERR_INVALID_CPU_ID;
return HMR0TestSwitcher3264(pVM);
#endif
default:
/*
* We're returning VERR_NOT_SUPPORT here so we've got something else
* than -1 which the interrupt gate glue code might return.
*/
Log(("operation %#x is not supported\n", enmOperation));
return VERR_NOT_SUPPORTED;
}
}
/**
* Argument for vmmR0EntryExWrapper containing the arguments for VMMR0EntryEx.
*/
typedef struct VMMR0ENTRYEXARGS
{
PVM pVM;
VMCPUID idCpu;
VMMR0OPERATION enmOperation;
PSUPVMMR0REQHDR pReq;
uint64_t u64Arg;
PSUPDRVSESSION pSession;
} VMMR0ENTRYEXARGS;
/** Pointer to a vmmR0EntryExWrapper argument package. */
typedef VMMR0ENTRYEXARGS *PVMMR0ENTRYEXARGS;
/**
* This is just a longjmp wrapper function for VMMR0EntryEx calls.
*
* @returns VBox status code.
* @param pvArgs The argument package
*/
static DECLCALLBACK(int) vmmR0EntryExWrapper(void *pvArgs)
{
return vmmR0EntryExWorker(((PVMMR0ENTRYEXARGS)pvArgs)->pVM,
((PVMMR0ENTRYEXARGS)pvArgs)->idCpu,
((PVMMR0ENTRYEXARGS)pvArgs)->enmOperation,
((PVMMR0ENTRYEXARGS)pvArgs)->pReq,
((PVMMR0ENTRYEXARGS)pvArgs)->u64Arg,
((PVMMR0ENTRYEXARGS)pvArgs)->pSession);
}
/**
* The Ring 0 entry point, called by the support library (SUP).
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
* @param idCpu Virtual CPU ID argument. Must be NIL_VMCPUID if pVM
* is NIL_RTR0PTR, and may be NIL_VMCPUID if it isn't
* @param enmOperation Which operation to execute.
* @param pReq Pointer to the SUPVMMR0REQHDR packet. Optional.
* @param u64Arg Some simple constant argument.
* @param pSession The session of the caller.
* @remarks Assume called with interrupts _enabled_.
*/
VMMR0DECL(int) VMMR0EntryEx(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession)
{
/*
* Requests that should only happen on the EMT thread will be
* wrapped in a setjmp so we can assert without causing trouble.
*/
if ( VALID_PTR(pVM)
&& pVM->pVMR0
&& idCpu < pVM->cCpus)
{
switch (enmOperation)
{
/* These might/will be called before VMMR3Init. */
case VMMR0_DO_GMM_INITIAL_RESERVATION:
case VMMR0_DO_GMM_UPDATE_RESERVATION:
case VMMR0_DO_GMM_ALLOCATE_PAGES:
case VMMR0_DO_GMM_FREE_PAGES:
case VMMR0_DO_GMM_BALLOONED_PAGES:
/* On the mac we might not have a valid jmp buf, so check these as well. */
case VMMR0_DO_VMMR0_INIT:
case VMMR0_DO_VMMR0_TERM:
{
PVMCPU pVCpu = &pVM->aCpus[idCpu];
if (!pVCpu->vmm.s.CallRing3JmpBufR0.pvSavedStack)
break;
/** @todo validate this EMT claim... GVM knows. */
VMMR0ENTRYEXARGS Args;
Args.pVM = pVM;
Args.idCpu = idCpu;
Args.enmOperation = enmOperation;
Args.pReq = pReq;
Args.u64Arg = u64Arg;
Args.pSession = pSession;
return vmmR0CallRing3SetJmpEx(&pVCpu->vmm.s.CallRing3JmpBufR0, vmmR0EntryExWrapper, &Args);
}
default:
break;
}
}
return vmmR0EntryExWorker(pVM, idCpu, enmOperation, pReq, u64Arg, pSession);
}
/**
* Checks whether we've armed the ring-0 long jump machinery.
*
* @returns @c true / @c false
* @param pVCpu Pointer to the VMCPU.
* @thread EMT
* @sa VMMIsLongJumpArmed
*/
VMMR0_INT_DECL(bool) VMMR0IsLongJumpArmed(PVMCPU pVCpu)
{
#ifdef RT_ARCH_X86
return pVCpu->vmm.s.CallRing3JmpBufR0.eip
&& !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call;
#else
return pVCpu->vmm.s.CallRing3JmpBufR0.rip
&& !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call;
#endif
}
/**
* Checks whether we've done a ring-3 long jump.
*
* @returns @c true / @c false
* @param pVCpu Pointer to the VMCPU.
* @thread EMT
*/
VMMR0_INT_DECL(bool) VMMR0IsInRing3LongJump(PVMCPU pVCpu)
{
return pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call;
}
/**
* Internal R0 logger worker: Flush logger.
*
* @param pLogger The logger instance to flush.
* @remark This function must be exported!
*/
VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger)
{
#ifdef LOG_ENABLED
/*
* Convert the pLogger into a VM handle and 'call' back to Ring-3.
* (This is a bit paranoid code.)
*/
PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
if ( !VALID_PTR(pR0Logger)
|| !VALID_PTR(pR0Logger + 1)
|| pLogger->u32Magic != RTLOGGER_MAGIC)
{
# ifdef DEBUG
SUPR0Printf("vmmR0LoggerFlush: pLogger=%p!\n", pLogger);
# endif
return;
}
if (pR0Logger->fFlushingDisabled)
return; /* quietly */
PVM pVM = pR0Logger->pVM;
if ( !VALID_PTR(pVM)
|| pVM->pVMR0 != pVM)
{
# ifdef DEBUG
SUPR0Printf("vmmR0LoggerFlush: pVM=%p! pVMR0=%p! pLogger=%p\n", pVM, pVM->pVMR0, pLogger);
# endif
return;
}
PVMCPU pVCpu = VMMGetCpu(pVM);
if (pVCpu)
{
/*
* Check that the jump buffer is armed.
*/
# ifdef RT_ARCH_X86
if ( !pVCpu->vmm.s.CallRing3JmpBufR0.eip
|| pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
# else
if ( !pVCpu->vmm.s.CallRing3JmpBufR0.rip
|| pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
# endif
{
# ifdef DEBUG
SUPR0Printf("vmmR0LoggerFlush: Jump buffer isn't armed!\n");
# endif
return;
}
VMMRZCallRing3(pVM, pVCpu, VMMCALLRING3_VMM_LOGGER_FLUSH, 0);
}
# ifdef DEBUG
else
SUPR0Printf("vmmR0LoggerFlush: invalid VCPU context!\n");
# endif
#endif
}
/**
* Internal R0 logger worker: Custom prefix.
*
* @returns Number of chars written.
*
* @param pLogger The logger instance.
* @param pchBuf The output buffer.
* @param cchBuf The size of the buffer.
* @param pvUser User argument (ignored).
*/
VMMR0DECL(size_t) vmmR0LoggerPrefix(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser)
{
NOREF(pvUser);
#ifdef LOG_ENABLED
PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
if ( !VALID_PTR(pR0Logger)
|| !VALID_PTR(pR0Logger + 1)
|| pLogger->u32Magic != RTLOGGER_MAGIC
|| cchBuf < 2)
return 0;
static const char s_szHex[17] = "0123456789abcdef";
VMCPUID const idCpu = pR0Logger->idCpu;
pchBuf[1] = s_szHex[ idCpu & 15];
pchBuf[0] = s_szHex[(idCpu >> 4) & 15];
return 2;
#else
return 0;
#endif
}
#ifdef LOG_ENABLED
/**
* Disables flushing of the ring-0 debug log.
*
* @param pVCpu Pointer to the VMCPU.
*/
VMMR0DECL(void) VMMR0LogFlushDisable(PVMCPU pVCpu)
{
if (pVCpu->vmm.s.pR0LoggerR0)
pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = true;
}
/**
* Enables flushing of the ring-0 debug log.
*
* @param pVCpu Pointer to the VMCPU.
*/
VMMR0DECL(void) VMMR0LogFlushEnable(PVMCPU pVCpu)
{
if (pVCpu->vmm.s.pR0LoggerR0)
pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = false;
}
/**
* Checks if log flushing is disabled or not.
*
* @param pVCpu Pointer to the VMCPU.
*/
VMMR0DECL(bool) VMMR0IsLogFlushDisabled(PVMCPU pVCpu)
{
if (pVCpu->vmm.s.pR0LoggerR0)
return pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled;
return true;
}
#endif /* LOG_ENABLED */
/**
* Jump back to ring-3 if we're the EMT and the longjmp is armed.
*
* @returns true if the breakpoint should be hit, false if it should be ignored.
*/
DECLEXPORT(bool) RTCALL RTAssertShouldPanic(void)
{
#if 0
return true;
#else
PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
if (pVM)
{
PVMCPU pVCpu = VMMGetCpu(pVM);
if (pVCpu)
{
#ifdef RT_ARCH_X86
if ( pVCpu->vmm.s.CallRing3JmpBufR0.eip
&& !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
#else
if ( pVCpu->vmm.s.CallRing3JmpBufR0.rip
&& !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
#endif
{
int rc = VMMRZCallRing3(pVM, pVCpu, VMMCALLRING3_VM_R0_ASSERTION, 0);
return RT_FAILURE_NP(rc);
}
}
}
#ifdef RT_OS_LINUX
return true;
#else
return false;
#endif
#endif
}
/**
* Override this so we can push it up to ring-3.
*
* @param pszExpr Expression. Can be NULL.
* @param uLine Location line number.
* @param pszFile Location file name.
* @param pszFunction Location function name.
*/
DECLEXPORT(void) RTCALL RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
{
/*
* To the log.
*/
LogAlways(("\n!!R0-Assertion Failed!!\n"
"Expression: %s\n"
"Location : %s(%d) %s\n",
pszExpr, pszFile, uLine, pszFunction));
/*
* To the global VMM buffer.
*/
PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
if (pVM)
RTStrPrintf(pVM->vmm.s.szRing0AssertMsg1, sizeof(pVM->vmm.s.szRing0AssertMsg1),
"\n!!R0-Assertion Failed!!\n"
"Expression: %s\n"
"Location : %s(%d) %s\n",
pszExpr, pszFile, uLine, pszFunction);
/*
* Continue the normal way.
*/
RTAssertMsg1(pszExpr, uLine, pszFile, pszFunction);
}
/**
* Callback for RTLogFormatV which writes to the ring-3 log port.
* See PFNLOGOUTPUT() for details.
*/
static DECLCALLBACK(size_t) rtLogOutput(void *pv, const char *pachChars, size_t cbChars)
{
for (size_t i = 0; i < cbChars; i++)
LogAlways(("%c", pachChars[i]));
NOREF(pv);
return cbChars;
}
/**
* Override this so we can push it up to ring-3.
*
* @param pszFormat The format string.
* @param va Arguments.
*/
DECLEXPORT(void) RTCALL RTAssertMsg2WeakV(const char *pszFormat, va_list va)
{
va_list vaCopy;
/*
* Push the message to the loggers.
*/
PRTLOGGER pLog = RTLogGetDefaultInstance(); /* Don't initialize it here... */
if (pLog)
{
va_copy(vaCopy, va);
RTLogFormatV(rtLogOutput, pLog, pszFormat, vaCopy);
va_end(vaCopy);
}
pLog = RTLogRelDefaultInstance();
if (pLog)
{
va_copy(vaCopy, va);
RTLogFormatV(rtLogOutput, pLog, pszFormat, vaCopy);
va_end(vaCopy);
}
/*
* Push it to the global VMM buffer.
*/
PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
if (pVM)
{
va_copy(vaCopy, va);
RTStrPrintfV(pVM->vmm.s.szRing0AssertMsg2, sizeof(pVM->vmm.s.szRing0AssertMsg2), pszFormat, vaCopy);
va_end(vaCopy);
}
/*
* Continue the normal way.
*/
RTAssertMsg2V(pszFormat, va);
}