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