VM.cpp revision 120f01afbe49cf87fc97b470b7d58e8318b2928a
/* $Id$ */
/** @file
* VM - Virtual Machine
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/** @page pg_vm VM API
*
* This is the encapsulating bit. It provides the APIs that Main and VBoxBFE
* use to create a VMM instance for running a guest in. It also provides
* facilities for queuing request for execution in EMT (serialization purposes
*
*
* @section sec_vm_design Design Critique / Things To Do
*
* In hindsight this component is a big design mistake, all this stuff really
* belongs in the VMM component. It just seemed like a kind of ok idea at a
* time when the VMM bit was a kind of vague. 'VM' also happend to be the name
* of the per-VM instance structure (see vm.h), so it kind of made sense.
* However as it turned out, VMM(.cpp) is almost empty all it provides in ring-3
* is some minor functionally and some "routing" services.
*
* Fixing this is just a matter of some more or less straight forward
* refactoring, the question is just when someone will get to it. Moving the EMT
* would be a good start.
*
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_VM
#include <VBox/pdmcritsect.h>
#include "VMInternal.h"
#include <iprt/semaphore.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* VM destruction callback registration record.
*/
typedef struct VMATDTOR
{
/** Pointer to the next record in the list. */
/** Pointer to the callback function. */
/** The user argument. */
void *pvUser;
} VMATDTOR;
/** Pointer to a VM destruction callback registration record. */
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Pointer to the list of VMs. */
/** Pointer to the list of at VM destruction callbacks. */
/** Lock the g_pVMAtDtorHead list. */
#define VM_ATDTOR_LOCK() do { } while (0)
/** Unlock the g_pVMAtDtorHead list. */
#define VM_ATDTOR_UNLOCK() do { } while (0)
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static int vmR3CreateU(PUVM pUVM, uint32_t cCpus, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM);
static DECLCALLBACK(size_t) vmR3LogPrefixCallback(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser);
/**
* Do global VMM init.
*
* @returns VBox status code.
*/
VMMR3DECL(int) VMR3GlobalInit(void)
{
/*
* Only once.
*/
static bool volatile s_fDone = false;
if (s_fDone)
return VINF_SUCCESS;
/*
* We're done.
*/
s_fDone = true;
return VINF_SUCCESS;
}
/**
* Creates a virtual machine by calling the supplied configuration constructor.
*
* On successful returned the VM is powered, i.e. VMR3PowerOn() should be
* called to start the execution.
*
* @returns 0 on success.
* @returns VBox error code on failure.
* @param cCpus Number of virtual CPUs for the new VM.
* @param pfnVMAtError Pointer to callback function for setting VM
* errors. This was added as an implicit call to
* VMR3AtErrorRegister() since there is no way the
* caller can get to the VM handle early enough to
* do this on its own.
* This is called in the context of an EMT.
* @param pvUserVM The user argument passed to pfnVMAtError.
* @param pfnCFGMConstructor Pointer to callback function for constructing the VM configuration tree.
* This is called in the context of an EMT0.
* @param pvUserCFGM The user argument passed to pfnCFGMConstructor.
* @param ppVM Where to store the 'handle' of the created VM.
*/
VMMR3DECL(int) VMR3Create(uint32_t cCpus, PFNVMATERROR pfnVMAtError, void *pvUserVM, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM, PVM *ppVM)
{
LogFlow(("VMR3Create: cCpus=%RU32 pfnVMAtError=%p pvUserVM=%p pfnCFGMConstructor=%p pvUserCFGM=%p ppVM=%p\n",
/*
* Because of the current hackiness of the applications
* we'll have to initialize global stuff from here.
* Later the applications will take care of this in a proper way.
*/
static bool fGlobalInitDone = false;
if (!fGlobalInitDone)
{
int rc = VMR3GlobalInit();
if (RT_FAILURE(rc))
return rc;
fGlobalInitDone = true;
}
/*
* Validate input.
*/
AssertLogRelMsgReturn(cCpus > 0 && cCpus <= VMM_MAX_CPU_COUNT, ("%RU32\n", cCpus), VERR_TOO_MANY_CPUS);
/*
* Create the UVM so we can register the at-error callback
* and consoliate a bit of cleanup code.
*/
if (RT_FAILURE(rc))
return rc;
if (pfnVMAtError)
if (RT_SUCCESS(rc))
{
/*
* Initialize the support library creating the session for this VM.
*/
if (RT_SUCCESS(rc))
{
/*
* Call vmR3CreateU in the EMT thread and wait for it to finish.
*
* Note! VMCPUID_ANY is used here because VMR3ReqQueueU would have trouble
* submitting a request to a specific VCPU without a pVM. So, to make
* sure init is running on EMT(0), vmR3EmulationThreadWithId makes sure
* that only EMT(0) is servicing VMCPUID_ANY requests when pVM is NULL.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/*
* Success!
*/
return VINF_SUCCESS;
}
}
else
/*
* An error occurred during VM creation. Set the error message directly
* using the initial callback, as the callback list doesn't exist yet.
*/
switch (rc)
{
#ifdef RT_OS_LINUX
"Please disable the KVM kernel extension, recompile your kernel and reboot");
#else
pszError = N_("VirtualBox can't operate in VMX root mode. Please close all other virtualization programs.");
#endif
break;
#ifndef RT_OS_DARWIN
"This hardware extension is required by the VM configuration");
break;
#endif
case VERR_SVM_IN_USE:
#ifdef RT_OS_LINUX
"Please disable the KVM kernel extension, recompile your kernel and reboot");
#else
pszError = N_("VirtualBox can't enable the AMD-V extension. Please close all other virtualization programs.");
#endif
break;
case VERR_VERSION_MISMATCH:
"VBoxNetDHCP is not running and try again. If you still get this error, "
"re-install VirtualBox");
break;
#ifdef RT_OS_LINUX
"that no kernel modules from an older version of VirtualBox exist. "
"Then try to recompile and reload the kernel modules by executing "
break;
#endif
"VirtualBox requires this hardware extension to emulate more than one "
"guest CPU");
break;
#ifdef RT_OS_LINUX
"extension. Either upgrade your kernel to Linux 2.6.13 or later or disable "
"the VT-x extension in the VM settings. Note that without VT-x you have "
"to reduce the number of guest CPUs to one");
#else
"extension. Either upgrade your kernel or disable the VT-x extension in the "
"VM settings. Note that without VT-x you have to reduce the number of guest "
"CPUs to one");
#endif
break;
default:
break;
}
}
else
{
/*
* An error occurred at support library initialization time (before the
* VM could be created). Set the error message directly using the
* initial callback, as the callback list doesn't exist yet.
*/
const char *pszError;
switch (rc)
{
#ifdef RT_OS_LINUX
"Re-setup the kernel module by executing "
#else
#endif
break;
break;
#ifdef VBOX_WITH_HARDENING
"Re-install VirtualBox. If you are building it yourself, you "
"should make sure it installed correctly and that the setuid "
"bit is set on the executables calling VMR3Create.");
#else
# if defined(RT_OS_DARWIN)
"If you have built VirtualBox yourself, make sure that you do not "
"have the vboxdrv KEXT from a different build or installation loaded.");
# elif defined(RT_OS_LINUX)
"If you have built VirtualBox yourself, make sure that you do "
"not have the vboxdrv kernel module from a different build or "
"installation loaded. Also, make sure the vboxdrv udev rule gives "
"you the permission you need to access the device.");
# elif defined(RT_OS_WINDOWS)
# else /* solaris, freebsd, ++. */
"If you have built VirtualBox yourself, make sure that you do "
"not have the vboxdrv kernel module from a different install loaded.");
# endif
#endif
break;
case VERR_INVALID_HANDLE: /** @todo track down and fix this error. */
#ifdef RT_OS_LINUX
"reason. Re-setup the kernel module by executing "
#else
#endif
break;
case VERR_NO_MEMORY:
break;
case VERR_VERSION_MISMATCH:
"version of VirtualBox. You can correct this by stopping all "
"running instances of VirtualBox and reinstalling the software.");
break;
default:
}
}
}
/* cleanup */
return rc;
}
/**
* Creates the UVM.
*
* This will not initialize the support library even if vmR3DestroyUVM
* will terminate that.
*
* @returns VBox status code.
* @param cCpus Number of virtual CPUs
* @param ppUVM Where to store the UVM pointer.
*/
{
uint32_t i;
/*
* Create and initialize the UVM.
*/
/* Initialize the VMCPU array in the UVM. */
for (i = 0; i < cCpus; i++)
{
}
/* Allocate a TLS entry to store the VMINTUSERPERVMCPU pointer. */
if (RT_SUCCESS(rc))
{
/* Allocate a halt method event semaphore for each VCPU. */
for (i = 0; i < cCpus; i++)
for (i = 0; i < cCpus; i++)
{
if (RT_FAILURE(rc))
break;
}
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/*
* Init fundamental (sub-)components - STAM, MMR3Heap and PDMLdr.
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/*
* Start the emulation threads for all VMCPUs.
*/
for (i = 0; i < cCpus; i++)
{
if (RT_FAILURE(rc))
break;
}
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
/* bail out. */
while (i-- > 0)
{
/** @todo rainy day: terminate the EMTs. */
}
}
}
}
}
}
}
for (i = 0; i < cCpus; i++)
{
}
}
return rc;
}
/**
* Creates and initializes the VM.
*
* @thread EMT
*/
static int vmR3CreateU(PUVM pUVM, uint32_t cCpus, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM)
{
int rc = VINF_SUCCESS;
/*
* Load the VMMR0.r0 module so that we can call GVMMR0CreateVM.
*/
if (RT_FAILURE(rc))
{
/** @todo we need a cleaner solution for this (VERR_VMX_IN_VMX_ROOT_MODE).
* bird: what about moving the message down here? Main picks the first message, right? */
if (rc == VERR_VMX_IN_VMX_ROOT_MODE)
return rc; /* proper error message set later on */
}
/*
* Request GVMM to create a new VM for us.
*/
if (RT_SUCCESS(rc))
{
Log(("VMR3Create: Created pUVM=%p pVM=%p pVMR0=%p hSelf=%#x cCpus=%RU32\n",
/*
* Initialize the VM structure and our internal data (VMINT).
*/
{
/* hNativeThreadR0 is initialized on EMT registration. */
}
/*
* Init the configuration.
*/
if (RT_SUCCESS(rc))
{
pVM->fHWACCMEnabled = true;
/*
* If executing in fake suplib mode disable RR3 and RR0 in the config.
*/
{
}
/*
* Make sure the CPU count in the config data matches.
*/
if (RT_SUCCESS(rc))
{
AssertLogRelMsgRC(rc, ("Configuration error: Querying \"NumCPUs\" as integer failed, rc=%Rrc\n", rc));
{
AssertLogRelMsgFailed(("Configuration error: \"NumCPUs\"=%RU32 and VMR3CreateVM::cCpus=%RU32 does not match!\n",
}
}
if (RT_SUCCESS(rc))
{
AssertLogRelMsgRC(rc, ("Configuration error: Querying \"CpuPriority\" as integer failed, rc=%Rrc\n", rc));
/*
* Init the ring-3 components and ring-3 per cpu data, finishing it off
* by a relocation round (intermediate context finalization will do this).
*/
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
{
LogFlow(("Ring-3 init succeeded\n"));
/*
* Init the Ring-0 components.
*/
if (RT_SUCCESS(rc))
{
/* Relocate again, because some switcher fixups depends on R0 init results. */
VMR3Relocate(pVM, 0);
#ifdef VBOX_WITH_DEBUGGER
/*
* Init the tcp debugger console if we're building
* with debugger support.
*/
if ( RT_SUCCESS(rc)
|| rc == VERR_NET_ADDRESS_IN_USE)
{
#endif
/*
* Init the Guest Context components.
*/
if (RT_SUCCESS(rc))
{
/*
* Now we can safely set the VM halt method to default.
*/
if (RT_SUCCESS(rc))
{
/*
* Set the state and link into the global list.
*/
g_pUVMsHead = pUVM;
#ifdef LOG_ENABLED
#endif
return VINF_SUCCESS;
}
}
#ifdef VBOX_WITH_DEBUGGER
}
#endif
//..
}
}
}
}
//..
/* Clean CFGM. */
}
/*
* Do automatic cleanups while the VM structure is still alive and all
* references to it are still working.
*/
/*
* Drop all references to VM and the VMCPU structures, then
* tell GVMM to destroy the VM.
*/
{
}
{
/* Poke the other EMTs since they may have stale pVM and pVCpu references
on the stack (see VMR3WaitU for instance) if they've been awakened after
VM creation. */
}
}
else
return rc;
}
/**
* Register the calling EMT with GVM.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param idCpu The Virtual CPU ID.
*/
{
if (RT_FAILURE(rc))
return rc;
}
/**
* Initializes all R3 components of the VM
*/
{
int rc;
/*
* Register the other EMTs with GVM.
*/
{
if (RT_FAILURE(rc))
return rc;
}
/*
* Init all R3 components, the order here might be important.
*/
if (RT_SUCCESS(rc))
{
STAM_REG(pVM, &pVM->StatTotalInGC, STAMTYPE_PROFILE_ADV, "/PROF/VM/InGC", STAMUNIT_TICKS_PER_CALL, "Profiling the total time spent in GC.");
STAM_REG(pVM, &pVM->StatSwitcherToGC, STAMTYPE_PROFILE_ADV, "/PROF/VM/SwitchToGC", STAMUNIT_TICKS_PER_CALL, "Profiling switching to GC.");
STAM_REG(pVM, &pVM->StatSwitcherToHC, STAMTYPE_PROFILE_ADV, "/PROF/VM/SwitchToHC", STAMUNIT_TICKS_PER_CALL, "Profiling switching to HC.");
STAM_REG(pVM, &pVM->StatSwitcherSaveRegs, STAMTYPE_PROFILE_ADV, "/VM/Switcher/ToGC/SaveRegs", STAMUNIT_TICKS_PER_CALL,"Profiling switching to GC.");
STAM_REG(pVM, &pVM->StatSwitcherSysEnter, STAMTYPE_PROFILE_ADV, "/VM/Switcher/ToGC/SysEnter", STAMUNIT_TICKS_PER_CALL,"Profiling switching to GC.");
STAM_REG(pVM, &pVM->StatSwitcherDebug, STAMTYPE_PROFILE_ADV, "/VM/Switcher/ToGC/Debug", STAMUNIT_TICKS_PER_CALL,"Profiling switching to GC.");
STAM_REG(pVM, &pVM->StatSwitcherCR0, STAMTYPE_PROFILE_ADV, "/VM/Switcher/ToGC/CR0", STAMUNIT_TICKS_PER_CALL, "Profiling switching to GC.");
STAM_REG(pVM, &pVM->StatSwitcherCR4, STAMTYPE_PROFILE_ADV, "/VM/Switcher/ToGC/CR4", STAMUNIT_TICKS_PER_CALL, "Profiling switching to GC.");
STAM_REG(pVM, &pVM->StatSwitcherLgdt, STAMTYPE_PROFILE_ADV, "/VM/Switcher/ToGC/Lgdt", STAMUNIT_TICKS_PER_CALL, "Profiling switching to GC.");
STAM_REG(pVM, &pVM->StatSwitcherLidt, STAMTYPE_PROFILE_ADV, "/VM/Switcher/ToGC/Lidt", STAMUNIT_TICKS_PER_CALL, "Profiling switching to GC.");
STAM_REG(pVM, &pVM->StatSwitcherLldt, STAMTYPE_PROFILE_ADV, "/VM/Switcher/ToGC/Lldt", STAMUNIT_TICKS_PER_CALL, "Profiling switching to GC.");
STAM_REG(pVM, &pVM->StatSwitcherTSS, STAMTYPE_PROFILE_ADV, "/VM/Switcher/ToGC/TSS", STAMUNIT_TICKS_PER_CALL, "Profiling switching to GC.");
STAM_REG(pVM, &pVM->StatSwitcherJmpCR3, STAMTYPE_PROFILE_ADV, "/VM/Switcher/ToGC/JmpCR3", STAMUNIT_TICKS_PER_CALL,"Profiling switching to GC.");
STAM_REG(pVM, &pVM->StatSwitcherRstrRegs, STAMTYPE_PROFILE_ADV, "/VM/Switcher/ToGC/RstrRegs", STAMUNIT_TICKS_PER_CALL,"Profiling switching to GC.");
{
rc = STAMR3RegisterF(pVM, &pUVM->aCpus[idCpu].vm.s.StatHaltYield, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling halted state yielding.", "/PROF/VM/CPU%d/Halt/Yield", idCpu);
rc = STAMR3RegisterF(pVM, &pUVM->aCpus[idCpu].vm.s.StatHaltBlock, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling halted state blocking.", "/PROF/VM/CPU%d/Halt/Block", idCpu);
rc = STAMR3RegisterF(pVM, &pUVM->aCpus[idCpu].vm.s.StatHaltTimers, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling halted state timer tasks.", "/PROF/VM/CPU%d/Halt/Timers", idCpu);
}
STAM_REG(pVM, &pUVM->vm.s.StatReqAllocNew, STAMTYPE_COUNTER, "/VM/Req/AllocNew", STAMUNIT_OCCURENCES, "Number of VMR3ReqAlloc returning a new packet.");
STAM_REG(pVM, &pUVM->vm.s.StatReqAllocRaces, STAMTYPE_COUNTER, "/VM/Req/AllocRaces", STAMUNIT_OCCURENCES, "Number of VMR3ReqAlloc causing races.");
STAM_REG(pVM, &pUVM->vm.s.StatReqAllocRecycled, STAMTYPE_COUNTER, "/VM/Req/AllocRecycled", STAMUNIT_OCCURENCES, "Number of VMR3ReqAlloc returning a recycled packet.");
STAM_REG(pVM, &pUVM->vm.s.StatReqFree, STAMTYPE_COUNTER, "/VM/Req/Free", STAMUNIT_OCCURENCES, "Number of VMR3ReqFree calls.");
STAM_REG(pVM, &pUVM->vm.s.StatReqFreeOverflow, STAMTYPE_COUNTER, "/VM/Req/FreeOverflow", STAMUNIT_OCCURENCES, "Number of times the request was actually freed.");
STAM_REG(pVM, &pUVM->vm.s.StatReqProcessed, STAMTYPE_COUNTER, "/VM/Req/Processed", STAMUNIT_OCCURENCES, "Number of processed requests (any queue).");
STAM_REG(pVM, &pUVM->vm.s.StatReqMoreThan1, STAMTYPE_COUNTER, "/VM/Req/MoreThan1", STAMUNIT_OCCURENCES, "Number of times there are more than one request on the queue when processing it.");
STAM_REG(pVM, &pUVM->vm.s.StatReqPushBackRaces, STAMTYPE_COUNTER, "/VM/Req/PushBackRaces", STAMUNIT_OCCURENCES, "Number of push back races.");
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
//int rc2 = CPUMR3Term(pVM);
//AssertRC(rc2);
}
/* MMR3Term is not called here because it'll kill the heap. */
}
return rc;
}
/**
* Initializes all VM CPU components of the VM
*/
{
int rc = VINF_SUCCESS;
int rc2;
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
return VINF_SUCCESS;
}
}
}
}
}
}
return rc;
}
/**
* Initializes all R0 components of the VM
*/
{
LogFlow(("vmR3InitRing0:\n"));
/*
* Check for FAKE suplib mode.
*/
int rc = VINF_SUCCESS;
{
/*
* Call the VMMR0 component and let it do the init.
*/
}
else
Log(("vmR3InitRing0: skipping because of VBOX_SUPLIB_FAKE=fake\n"));
/*
* Do notifications and return.
*/
if (RT_SUCCESS(rc))
/** @todo Move this to the VMINITCOMPLETED_RING0 notification handler. */
if (RT_SUCCESS(rc))
{
}
return rc;
}
/**
* Initializes all GC components of the VM
*/
{
LogFlow(("vmR3InitGC:\n"));
/*
* Check for FAKE suplib mode.
*/
int rc = VINF_SUCCESS;
{
/*
* Call the VMMR0 component and let it do the init.
*/
}
else
Log(("vmR3InitGC: skipping because of VBOX_SUPLIB_FAKE=fake\n"));
/*
* Do notifications and return.
*/
if (RT_SUCCESS(rc))
return rc;
}
/**
* Do init completed notifications.
* This notifications can fail.
*
* @param pVM The VM handle.
* @param enmWhat What's completed.
*/
{
return VINF_SUCCESS;
}
/**
* Logger callback for inserting a custom prefix.
*
* @returns Number of chars written.
* @param pLogger The logger.
* @param pchBuf The output buffer.
* @param cchBuf The output buffer size.
* @param pvUser Pointer to the UVM structure.
*/
static DECLCALLBACK(size_t) vmR3LogPrefixCallback(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser)
{
if (pUVCpu)
{
}
else
{
pchBuf[0] = 'x';
}
return 2;
}
/**
* Calls the relocation functions for all VMM components so they can update
* any GC pointers. When this function is called all the basic VM members
* have been updated and the actual memory relocation have been done
*
* This is used both on init and on runtime relocations.
*
* @param pVM VM handle.
* @param offDelta Relocation delta relative to old location.
*/
{
/*
* The order here is very important!
*/
}
/**
* EMT rendezvous worker for VMR3PowerOn.
*
* @returns VERR_VM_INVALID_VM_STATE or VINF_SUCCESS. (This is a strict return
* code, see FNVMMEMTRENDEZVOUS.)
*
* @param pVM The VM handle.
* @param pVCpu The VMCPU handle of the EMT.
* @param pvUser Ignored.
*/
{
/*
* The first thread thru here tries to change the state. We shouldn't be
* called again if this fails.
*/
{
if (RT_FAILURE(rc))
return rc;
}
/*
* All EMTs changes their state to started.
*/
/*
* EMT(0) is last thru here and it will make the notification calls
* and advance the state.
*/
{
}
return VINF_SUCCESS;
}
/**
* Powers on the virtual machine.
*
* @returns VBox status code.
*
* @param pVM The VM to power on.
*
* @thread Any thread.
* @vmstate Created
* @vmstateto PoweringOn+Running
*/
{
/*
* Gather all the EMTs to reduce the init TSC drift and keep
* the state changing APIs a bit uniform.
*/
int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_DESCENDING | VMMEMTRENDEZVOUS_FLAGS_STOP_ON_ERROR,
vmR3PowerOn, NULL);
return rc;
}
/**
* Does the suspend notifications.
*
* @param pVM The VM handle.
* @thread EMT(0)
*/
{
}
/**
* EMT rendezvous worker for VMR3Suspend.
*
* @returns VERR_VM_INVALID_VM_STATE or VINF_EM_SUSPEND. (This is a strict
* return code, see FNVMMEMTRENDEZVOUS.)
*
* @param pVM The VM handle.
* @param pVCpu The VMCPU handle of the EMT.
* @param pvUser Ignored.
*/
{
/*
* The first EMT switches the state to suspending. If this fails because
* something was racing us in one way or the other, there will be no more
* calls and thus the state assertion below is not going to annoy anyone.
*/
{
if (RT_FAILURE(rc))
return rc;
}
/*
* EMT(0) does the actually suspending *after* all the other CPUs have
* been thru here.
*/
{
if (RT_FAILURE(rc))
return VERR_INTERNAL_ERROR_3;
}
return VINF_EM_SUSPEND;
}
/**
* Suspends a running VM.
*
* @returns VBox status code. When called on EMT, this will be a strict status
* code that has to be propagated up the call stack.
*
* @param pVM The VM to suspend.
*
* @thread Any thread.
* @vmstate Running or RunningLS
* @vmstateto Suspending + Suspended or SuspendingExtLS + SuspendedExtLS
*/
{
/*
* Gather all the EMTs to make sure there are no races before
* changing the VM state.
*/
int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_DESCENDING | VMMEMTRENDEZVOUS_FLAGS_STOP_ON_ERROR,
vmR3Suspend, NULL);
return rc;
}
/**
* EMT rendezvous worker for VMR3Resume.
*
* @returns VERR_VM_INVALID_VM_STATE or VINF_EM_RESUME. (This is a strict
* return code, see FNVMMEMTRENDEZVOUS.)
*
* @param pVM The VM handle.
* @param pVCpu The VMCPU handle of the EMT.
* @param pvUser Ignored.
*/
{
/*
* The first thread thru here tries to change the state. We shouldn't be
* called again if this fails.
*/
{
if (RT_FAILURE(rc))
return rc;
}
#if 0
/*
* All EMTs changes their state to started.
*/
#endif
/*
* EMT(0) is last thru here and it will make the notification calls
* and advance the state.
*/
{
}
return VINF_EM_RESUME;
}
/**
* Resume VM execution.
*
* @returns VBox status code. When called on EMT, this will be a strict status
* code that has to be propagated up the call stack.
*
* @param pVM The VM to resume.
*
* @thread Any thread.
* @vmstate Suspended
* @vmstateto Running
*/
{
/*
* Gather all the EMTs to make sure there are no races before
* changing the VM state.
*/
int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_DESCENDING | VMMEMTRENDEZVOUS_FLAGS_STOP_ON_ERROR,
vmR3Resume, NULL);
return rc;
}
/**
* EMT rendezvous worker for VMR3Save and VMR3Teleport that suspends the VM
* after the live step has been completed.
*
* @returns VERR_VM_INVALID_VM_STATE or VINF_EM_RESUME. (This is a strict
* return code, see FNVMMEMTRENDEZVOUS.)
*
* @param pVM The VM handle.
* @param pVCpu The VMCPU handle of the EMT.
* @param pvUser The pfSuspended argument of vmR3SaveTeleport.
*/
{
bool *pfSuspended = (bool *)pvUser;
/*
* The first thread thru here tries to change the state. We shouldn't be
* called again if this fails.
*/
{
int rc;
switch (enmVMState)
{
case VMSTATE_RUNNING_LS:
rc = VINF_SUCCESS;
break;
case VMSTATE_SUSPENDED_EXT_LS:
case VMSTATE_SUSPENDED_LS: /* (via reset) */
rc = VINF_SUCCESS;
break;
case VMSTATE_DEBUGGING_LS:
rc = VERR_TRY_AGAIN;
break;
case VMSTATE_OFF_LS:
break;
case VMSTATE_FATAL_ERROR_LS:
break;
break;
case VMSTATE_POWERING_OFF_LS:
case VMSTATE_RESETTING_LS:
default:
break;
}
if (RT_FAILURE(rc))
{
return rc;
}
}
/*
* Only EMT(0) have work to do since it's last thru here.
*/
{
if (RT_FAILURE(rc))
return VERR_INTERNAL_ERROR_3;
*pfSuspended = true;
}
return VINF_EM_SUSPEND;
}
/**
* EMT rendezvous worker that VMR3Save and VMR3Teleport uses to clean up a
* SSMR3LiveDoStep1 failure.
*
* Doing this as a rendezvous operation avoids all annoying transition
* states.
*
* @returns VERR_VM_INVALID_VM_STATE, VINF_SUCCESS or some specific VERR_SSM_*
* status code. (This is a strict return code, see FNVMMEMTRENDEZVOUS.)
*
* @param pVM The VM handle.
* @param pVCpu The VMCPU handle of the EMT.
* @param pvUser The pfSuspended argument of vmR3SaveTeleport.
*/
{
bool *pfSuspended = (bool *)pvUser;
if (rc == 1)
else if (rc == 2)
else if (rc == 3)
else if (rc == 4)
{
*pfSuspended = true;
rc = VINF_SUCCESS;
}
else if (rc > 0)
rc = VINF_SUCCESS;
return rc;
}
/**
* EMT(0) worker for VMR3Save and VMR3Teleport that completes the live save.
*
* @returns VBox status code.
* @retval VINF_SSM_LIVE_SUSPENDED if VMR3Suspend was called.
*
* @param pVM The VM handle.
* @param pSSM The handle of saved state operation.
*
* @thread EMT(0)
*/
{
/*
* Advance the state and mark if VMR3Suspend was called.
*/
int rc = VINF_SUCCESS;
if (enmVMState == VMSTATE_SUSPENDED_LS)
else
{
if (enmVMState != VMSTATE_SAVING)
}
/*
* Finish up and release the handle. Careful with the status codes.
*/
/*
* Advance to the final state and return.
*/
return rc;
}
/**
* Worker for vmR3SaveTeleport that validates the state and calls SSMR3Save or
* SSMR3LiveSave.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param cMsMaxDowntime The maximum downtime given as milliseconds.
* @param pszFilename The name of the file. NULL if pStreamOps is used.
* @param pStreamOps The stream methods. NULL if pszFilename is used.
* @param pvStreamOpsUser The user argument to the stream methods.
* @param enmAfter What to do afterwards.
* @param pfnProgress Progress callback. Optional.
* @param pvProgressUser User argument for the progress callback.
* @param ppSSM Where to return the saved state handle in case of a
* live snapshot scenario.
* @thread EMT
*/
static DECLCALLBACK(int) vmR3Save(PVM pVM, uint32_t cMsMaxDowntime, const char *pszFilename, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
{
LogFlow(("vmR3Save: pVM=%p cMsMaxDowntime=%u pszFilename=%p:{%s} pStreamOps=%p pvStreamOpsUser=%p enmAfter=%d pfnProgress=%p pvProgressUser=%p ppSSM=%p\n",
pVM, cMsMaxDowntime, pszFilename, pszFilename, pStreamOps, pvStreamOpsUser, enmAfter, pfnProgress, pvProgressUser, ppSSM));
/*
* Validate input.
*/
|| enmAfter == SSMAFTER_CONTINUE
|| enmAfter == SSMAFTER_TELEPORT);
/*
*/
{
rc = SSMR3Save(pVM, pszFilename, pStreamOps, pvStreamOpsUser, enmAfter, pfnProgress, pvProgressUser);
}
{
if (enmAfter == SSMAFTER_TELEPORT)
/* (We're not subject to cancellation just yet.) */
}
else
return rc;
}
/**
* Commmon worker for VMR3Save and VMR3Teleport.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param cMsMaxDowntime The maximum downtime given as milliseconds.
* @param pszFilename The name of the file. NULL if pStreamOps is used.
* @param pStreamOps The stream methods. NULL if pszFilename is used.
* @param pvStreamOpsUser The user argument to the stream methods.
* @param enmAfter What to do afterwards.
* @param pfnProgress Progress callback. Optional.
* @param pvProgressUser User argument for the progress callback.
* @param pfSuspended Set if we suspended the VM.
*
* @thread Non-EMT
*/
{
/*
* Request the operation in EMT(0).
*/
if ( RT_SUCCESS(rc)
&& pSSM)
{
/*
* Live snapshot.
*
* The state handling here is kind of tricky, doing it on EMT(0) helps
* a bit. See the VMSTATE diagram for details.
*/
if (RT_SUCCESS(rc))
{
for (;;)
{
/* Try suspend the VM. */
rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_DESCENDING | VMMEMTRENDEZVOUS_FLAGS_STOP_ON_ERROR,
if (rc != VERR_TRY_AGAIN)
break;
/* Wait for the state to change. */
RTThreadSleep(250); /** @todo Live Migration: fix this polling wait by some smart use of multiple release event semaphores.. */
}
if (RT_SUCCESS(rc))
else
{
}
}
else
{
rc2 = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_ONCE, vmR3LiveDoStep1Cleanup, pfSuspended);
}
}
return rc;
}
/**
* Save current VM state.
*
* Can be used for both saving the state and creating snapshots.
*
* When called for a VM in the Running state, the saved state is created live
* and the VM is only suspended when the final part of the saving is preformed.
* The VM state will not be restored to Running in this case and it's up to the
* caller to call VMR3Resume if this is desirable. (The rational is that the
* caller probably wish to reconfigure the disks before resuming the VM.)
*
* @returns VBox status code.
*
* @param pVM The VM which state should be saved.
* @param pszFilename The name of the save state file.
* @param pStreamOps The stream methods.
* @param pvStreamOpsUser The user argument to the stream methods.
* @param fContinueAfterwards Whether continue execution afterwards or not.
* When in doubt, set this to true.
* @param pfnProgress Progress callback. Optional.
* @param pvUser User argument for the progress callback.
* @param pfSuspended Set if we suspended the VM.
*
* @thread Non-EMT.
* @vmstate Suspended or Running
* @vmstateto Saving+Suspended or
* RunningLS+SuspeningLS+SuspendedLS+Saving+Suspended.
*/
VMMR3DECL(int) VMR3Save(PVM pVM, const char *pszFilename, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
{
LogFlow(("VMR3Save: pVM=%p pszFilename=%p:{%s} fContinueAfterwards=%RTbool pfnProgress=%p pvUser=%p pfSuspended=%p\n",
/*
* Validate input.
*/
*pfSuspended = false;
/*
* Join paths with VMR3Teleport.
*/
return rc;
}
/**
* Teleport the VM (aka live migration).
*
* @returns VBox status code.
*
* @param pVM The VM which state should be saved.
* @param cMsMaxDowntime The maximum downtime given as milliseconds.
* @param pStreamOps The stream methods.
* @param pvStreamOpsUser The user argument to the stream methods.
* @param pfnProgress Progress callback. Optional.
* @param pvProgressUser User argument for the progress callback.
* @param pfSuspended Set if we suspended the VM.
*
* @thread Non-EMT.
* @vmstate Suspended or Running
* @vmstateto Saving+Suspended or
* RunningLS+SuspeningLS+SuspendedLS+Saving+Suspended.
*/
VMMR3DECL(int) VMR3Teleport(PVM pVM, uint32_t cMsMaxDowntime, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
{
LogFlow(("VMR3Teleport: pVM=%p cMsMaxDowntime=%u pStreamOps=%p pvStreamOps=%p pfnProgress=%p pvProgressUser=%p\n",
/*
* Validate input.
*/
*pfSuspended = false;
/*
* Join paths with VMR3Save.
*/
return rc;
}
/**
* EMT(0) worker for VMR3LoadFromFile and VMR3LoadFromStream.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pszFilename The name of the file. NULL if pStreamOps is used.
* @param pStreamOps The stream methods. NULL if pszFilename is used.
* @param pvStreamOpsUser The user argument to the stream methods.
* @param pfnProgress Progress callback. Optional.
* @param pvUser User argument for the progress callback.
* @param fTeleporting Indicates whether we're teleporting or not.
*
* @thread EMT.
*/
static DECLCALLBACK(int) vmR3Load(PVM pVM, const char *pszFilename, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
{
LogFlow(("vmR3Load: pVM=%p pszFilename=%p:{%s} pStreamOps=%p pvStreamOpsUser=%p pfnProgress=%p pvProgressUser=%p fTeleporting=%RTbool\n",
pVM, pszFilename, pszFilename, pStreamOps, pvStreamOpsUser, pfnProgress, pvProgressUser, fTeleporting));
/*
* Validate input (paranoia).
*/
/*
* Change the state and perform the load.
*
* Always perform a relocation round afterwards to make sure hypervisor
* selectors and such are correct.
*/
if (RT_FAILURE(rc))
return rc;
rc = SSMR3Load(pVM, pszFilename, pStreamOps, pvStreamOpsUser, SSMAFTER_RESUME, pfnProgress, pvProgressUser);
if (RT_SUCCESS(rc))
{
}
else
{
N_("Unable to restore the virtual machine's saved state from '%s'. "
"It may be damaged or from an older version of VirtualBox. "
"Please discard the saved state before starting the virtual machine"),
}
return rc;
}
/**
* Loads a VM state into a newly created VM or a one that is suspended.
*
* To restore a saved state on VM startup, call this function and then resume
* the VM instead of powering it on.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pszFilename The name of the save state file.
* @param pfnProgress Progress callback. Optional.
* @param pvUser User argument for the progress callback.
*
* @thread Any thread.
* @vmstate Created, Suspended
* @vmstateto Loading+Suspended
*/
VMMR3DECL(int) VMR3LoadFromFile(PVM pVM, const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser)
{
LogFlow(("VMR3LoadFromFile: pVM=%p pszFilename=%p:{%s} pfnProgress=%p pvUser=%p\n",
/*
* Validate input.
*/
/*
* Forward the request to EMT(0). No need to setup a rendezvous here
* since there is no execution taking place when this call is allowed.
*/
pVM, pszFilename, (uintptr_t)NULL /*pStreamOps*/, (uintptr_t)NULL /*pvStreamOpsUser*/, pfnProgress, pvUser,
false /*fTeleporting*/);
return rc;
}
/**
* VMR3LoadFromFile for arbritrary file streams.
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pStreamOps The stream methods.
* @param pvStreamOpsUser The user argument to the stream methods.
* @param pfnProgress Progress callback. Optional.
* @param pvProgressUser User argument for the progress callback.
*
* @thread Any thread.
* @vmstate Created, Suspended
* @vmstateto Loading+Suspended
*/
{
LogFlow(("VMR3LoadFromStream: pVM=%p pStreamOps=%p pvStreamOpsUser=%p pfnProgress=%p pvProgressUser=%p\n",
/*
* Validate input.
*/
/*
* Forward the request to EMT(0). No need to setup a rendezvous here
* since there is no execution taking place when this call is allowed.
*/
true /*fTeleporting*/);
return rc;
}
/**
* EMT rendezvous worker for VMR3PowerOff.
*
* @returns VERR_VM_INVALID_VM_STATE or VINF_EM_OFF. (This is a strict
* return code, see FNVMMEMTRENDEZVOUS.)
*
* @param pVM The VM handle.
* @param pVCpu The VMCPU handle of the EMT.
* @param pvUser Ignored.
*/
{
/*
* The first EMT thru here will change the state to PoweringOff.
*/
{
if (RT_FAILURE(rc))
return rc;
if (rc >= 7)
}
/*
* Check the state.
*/
/*
* EMT(0) does the actual power off work here *after* all the other EMTs
* have been thru and entered the STOPPED state.
*/
{
/*
* For debugging purposes, we will log a summary of the guest state at this point.
*/
if (enmVMState != VMSTATE_GURU_MEDITATION)
{
/** @todo SMP support? */
/** @todo make the state dumping at VMR3PowerOff optional. */
RTLogRelPrintf("****************** Guest state at power off ******************\n");
RTLogRelPrintf("***\n");
RTLogRelPrintf("***\n");
RTLogRelPrintf("***\n");
/** @todo dump guest call stack. */
#if 1 // "temporary" while debugging #1589
RTLogRelPrintf("***\n");
if ( CPUMGetGuestSS(pVCpu) == 0
{
RTLogRelPrintf("***\n"
"ss:sp=0000:%04x ", esp);
if (RT_SUCCESS(rc))
RTLogRelPrintf("0000:%04x TO 0000:%04x:\n"
"%.*Rhxd\n",
0x100, abBuf);
else
/* grub ... */
{
if (RT_SUCCESS(rc))
RTLogRelPrintf("0000:8000 TO 0000:87ff:\n"
"%.*Rhxd\n",
0x800, abBuf);
}
/* microsoft cdrom hang ... */
if (true)
{
if (RT_SUCCESS(rc))
RTLogRelPrintf("2000:0000 TO 2000:01ff:\n"
"%.*Rhxd\n",
0x200, abBuf);
}
}
#endif
RTLogRelPrintf("************** End of Guest state at power off ***************\n");
}
/*
* Perform the power off notifications and advance the state to
* Off or OffLS.
*/
if (enmVMState == VMSTATE_POWERING_OFF_LS)
else
}
return VINF_EM_OFF;
}
/**
* Power off the VM.
*
* @returns VBox status code. When called on EMT, this will be a strict status
* code that has to be propagated up the call stack.
*
* @param pVM The handle of the VM to be powered off.
*
* @thread Any thread.
* @vmstate Suspended, Running, Guru Meditation, Load Failure
* @vmstateto Off or OffLS
*/
{
/*
* Gather all the EMTs to make sure there are no races before
* changing the VM state.
*/
int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_DESCENDING | VMMEMTRENDEZVOUS_FLAGS_STOP_ON_ERROR,
vmR3PowerOff, NULL);
return rc;
}
/**
* Destroys the VM.
*
* The VM must be powered off (or never really powered on) to call this
* function. The VM handle is destroyed and can no longer be used up successful
* return.
*
* @returns VBox status code.
*
* @param pVM The handle of the VM which should be destroyed.
*
* @thread Any none emulation thread.
* @vmstate Off, Created
* @vmstateto N/A
*/
{
/*
* Validate input.
*/
if (!pVM)
return VERR_INVALID_PARAMETER;
/*
* Change VM state to destroying and unlink the VM.
*/
if (RT_FAILURE(rc))
return rc;
/** @todo lock this when we start having multiple machines in a process... */
if (g_pUVMsHead == pUVM)
else
{
}
/*
* Notify registered at destruction listeners.
*/
/*
* Call vmR3Destroy on each of the EMTs ending with EMT(0) doing the bulk
* of the cleanup.
*/
/* vmR3Destroy on all EMTs, ending with EMT(0). */
/* Wait for EMTs and destroy the UVM. */
LogFlow(("VMR3Destroy: returns VINF_SUCCESS\n"));
return VINF_SUCCESS;
}
/**
* Internal destruction worker.
*
* This is either called from VMR3Destroy via VMR3ReqCallU or from
* vmR3EmulationThreadWithId when EMT(0) terminates after having called
* VMR3Destroy().
*
* When called on EMT(0), it will performed the great bulk of the destruction.
* When called on the other EMTs, they will do nothing and the whole purpose is
* to return VINF_EM_TERMINATE so they break out of their run loops.
*
* @returns VINF_EM_TERMINATE.
* @param pVM The VM handle.
*/
{
/*
* Only VCPU 0 does the full cleanup (last).
*/
{
/*
* Dump statistics to the log.
*/
#if defined(VBOX_WITH_STATISTICS) || defined(LOG_ENABLED)
#endif
#ifdef VBOX_WITH_STATISTICS
#else
LogRel(("************************* Statistics *************************\n"));
LogRel(("********************* End of statistics **********************\n"));
#endif
/*
* Destroy the VM components.
*/
#ifdef VBOX_WITH_DEBUGGER
#endif
/*
* We're done, tell the other EMTs to quit.
*/
}
return VINF_EM_TERMINATE;
}
/**
* Destroys the UVM portion.
*
* This is called as the final step in the VM destruction or as the cleanup
* in case of a creation failure.
*
* @param pVM VM Handle.
* @param cMilliesEMTWait The number of milliseconds to wait for the emulation
* threads.
*/
{
/*
* Signal termination of each the emulation threads and
* wait for them to complete.
*/
/* Signal them. */
{
}
/* Wait for them. */
{
if ( hThread != NIL_RTTHREAD
{
: 2000,
NULL);
if (RT_SUCCESS(rc2))
}
}
/* Cleanup the semaphores. */
{
}
/*
* Free the event semaphores associated with the request packets.
*/
unsigned cReqs = 0;
{
{
}
}
/*
* Kill all queued requests. (There really shouldn't be any!)
*/
for (unsigned i = 0; i < 10; i++)
{
AssertMsg(!pReqHead, ("This isn't supposed to happen! VMR3Destroy caller has to serialize this.\n"));
if (!pReqHead)
break;
{
RTThreadSleep(2);
}
/* give them a chance to respond before we free the request memory. */
RTThreadSleep(32);
}
/*
* Now all queued VCPU requests (again, there shouldn't be any).
*/
{
for (unsigned i = 0; i < 10; i++)
{
AssertMsg(!pReqHead, ("This isn't supposed to happen! VMR3Destroy caller has to serialize this.\n"));
if (!pReqHead)
break;
{
RTThreadSleep(2);
}
/* give them a chance to respond before we free the request memory. */
RTThreadSleep(32);
}
}
/*
* Make sure the VMMR0.r0 module and whatever else is unloaded.
*/
/*
* Terminate the support library if initialized.
*/
{
}
/*
* Destroy the MM heap and free the UVM structure.
*/
#ifdef LOG_ENABLED
#endif
}
/**
* Enumerates the VMs in this process.
*
* @returns Pointer to the next VM.
* @returns NULL when no more VMs.
* @param pVMPrev The previous VM
* Use NULL to start the enumeration.
*/
{
/*
* This is quick and dirty. It has issues with VM being
* destroyed during the enumeration.
*/
if (pVMPrev)
else
pNext = g_pUVMsHead;
}
/**
* Registers an at VM destruction callback.
*
* @returns VBox status code.
* @param pfnAtDtor Pointer to callback.
* @param pvUser User argument.
*/
{
/*
* Check if already registered.
*/
while (pCur)
{
{
return VERR_INVALID_PARAMETER;
}
/* next */
}
/*
* Allocate new entry.
*/
if (!pVMAtDtor)
return VERR_NO_MEMORY;
return VINF_SUCCESS;
}
/**
* Deregisters an at VM destruction callback.
*
* @returns VBox status code.
* @param pfnAtDtor Pointer to callback.
*/
{
/*
* Find it, unlink it and free it.
*/
while (pCur)
{
{
if (pPrev)
else
return VINF_SUCCESS;
}
/* next */
}
return VERR_INVALID_PARAMETER;
}
/**
* Walks the list of at VM destructor callbacks.
* @param pVM The VM which is about to be destroyed.
*/
{
/*
* Find it, unlink it and free it.
*/
}
/**
* Worker which checks integrity of some internal structures.
* This is yet another attempt to track down that AVL tree crash.
*/
{
#ifdef VBOX_STRICT
#endif
}
/**
* EMT rendezvous worker for VMR3Reset.
*
* This is called by the emulation threads as a response to the reset request
* issued by VMR3Reset().
*
* @returns VERR_VM_INVALID_VM_STATE, VINF_EM_RESET or VINF_EM_SUSPEND. (This
* is a strict return code, see FNVMMEMTRENDEZVOUS.)
*
* @param pVM The VM handle.
* @param pVCpu The VMCPU handle of the EMT.
* @param pvUser Ignored.
*/
{
/*
* The first EMT will try change the state to resetting. If this fails,
* we won't get called for the other EMTs.
*/
{
if (RT_FAILURE(rc))
return rc;
}
/*
* Check the state.
*/
|| enmVMState == VMSTATE_RESETTING_LS,
/*
* EMT(0) does the full cleanup *after* all the other EMTs has been
* thru here and been told to enter the EMSTATE_WAIT_SIPI state.
*
* the following sequence looks a bit ugly...
*/
/* Reset the VCpu state. */
/* Clear all pending forced actions. */
/*
* Reset the VM components.
*/
{
/** @todo PGMR3Reset should be called after PDMR3Reset really, because we'll trash OS <-> hardware
* communication structures residing in RAM when done in the other order. I.e. the device must be
* quiesced first, then we clear the memory and plan tables. Probably have to make these things
* explicit in some way, some memory setup pass or something.
* (Example: DevAHCI may assert if memory is zeroed before it've read the FIS.)
*
* @bugref{4467}
*/
}
{
#ifdef LOG_ENABLED
/*
* Debug logging.
*/
RTLogPrintf("\n\nThe VM was reset:\n");
#endif
/*
* Since EMT(0) is the last to go thru here, it will advance the state.
* When a live save is active, we will move on to SuspendingLS but
* leave it for VMR3Reset to do the actual suspending due to deadlock risks.
*/
if (enmVMState == VMSTATE_RESETTING)
{
else
}
else
/*
* Do the suspend bit as well.
* It only requires some EMT(0) work at present.
*/
if (enmVMState != VMSTATE_RESETTING)
{
}
}
return enmVMState == VMSTATE_RESETTING
: VINF_EM_SUSPEND; /** @todo VINF_EM_SUSPEND has lower priority than VINF_EM_RESET, so fix races. Perhaps add a new code for this combined case. */
}
/**
* Reset the current VM.
*
* @returns VBox status code.
* @param pVM VM to reset.
*/
{
LogFlow(("VMR3Reset:\n"));
/*
* Gather all the EMTs to make sure there are no races before
* changing the VM state.
*/
int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_DESCENDING | VMMEMTRENDEZVOUS_FLAGS_STOP_ON_ERROR,
return rc;
}
/**
* Gets the current VM state.
*
* @returns The current VM state.
* @param pVM VM handle.
* @thread Any
*/
{
return pVM->enmVMState;
}
/**
* Gets the state name string for a VM state.
*
* @returns Pointer to the state name. (readonly)
* @param enmState The state.
*/
{
switch (enmState)
{
case VMSTATE_CREATING: return "CREATING";
case VMSTATE_CREATED: return "CREATED";
case VMSTATE_LOADING: return "LOADING";
case VMSTATE_POWERING_ON: return "POWERING_ON";
case VMSTATE_RESUMING: return "RESUMING";
case VMSTATE_RUNNING: return "RUNNING";
case VMSTATE_RUNNING_LS: return "RUNNING_LS";
case VMSTATE_RUNNING_FT: return "RUNNING_FT";
case VMSTATE_RESETTING: return "RESETTING";
case VMSTATE_RESETTING_LS: return "RESETTING_LS";
case VMSTATE_SUSPENDED: return "SUSPENDED";
case VMSTATE_SUSPENDED_LS: return "SUSPENDED_LS";
case VMSTATE_SUSPENDED_EXT_LS: return "SUSPENDED_EXT_LS";
case VMSTATE_SUSPENDING: return "SUSPENDING";
case VMSTATE_SUSPENDING_LS: return "SUSPENDING_LS";
case VMSTATE_SUSPENDING_EXT_LS: return "SUSPENDING_EXT_LS";
case VMSTATE_SAVING: return "SAVING";
case VMSTATE_DEBUGGING: return "DEBUGGING";
case VMSTATE_DEBUGGING_LS: return "DEBUGGING_LS";
case VMSTATE_POWERING_OFF: return "POWERING_OFF";
case VMSTATE_POWERING_OFF_LS: return "POWERING_OFF_LS";
case VMSTATE_FATAL_ERROR: return "FATAL_ERROR";
case VMSTATE_FATAL_ERROR_LS: return "FATAL_ERROR_LS";
case VMSTATE_GURU_MEDITATION: return "GURU_MEDITATION";
case VMSTATE_GURU_MEDITATION_LS:return "GURU_MEDITATION_LS";
case VMSTATE_LOAD_FAILURE: return "LOAD_FAILURE";
case VMSTATE_OFF: return "OFF";
case VMSTATE_OFF_LS: return "OFF_LS";
case VMSTATE_DESTROYING: return "DESTROYING";
case VMSTATE_TERMINATED: return "TERMINATED";
default:
return "Unknown!\n";
}
}
/**
* Validates the state transition in strict builds.
*
* @returns true if valid, false if not.
*
* @param enmStateOld The old (current) state.
* @param enmStateNew The proposed new state.
*
* diagram (under State Machine Diagram).
*/
{
#ifdef VBOX_STRICT
switch (enmStateOld)
{
case VMSTATE_CREATING:
AssertMsgReturn(enmStateNew == VMSTATE_CREATED, ("%s -> %s\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)), false);
break;
case VMSTATE_CREATED:
break;
case VMSTATE_LOADING:
break;
case VMSTATE_POWERING_ON:
/*|| enmStateNew == VMSTATE_FATAL_ERROR ?*/
break;
case VMSTATE_RESUMING:
/*|| enmStateNew == VMSTATE_FATAL_ERROR ?*/
break;
case VMSTATE_RUNNING:
|| enmStateNew == VMSTATE_RESETTING
|| enmStateNew == VMSTATE_DEBUGGING
break;
case VMSTATE_RUNNING_LS:
|| enmStateNew == VMSTATE_RUNNING
break;
case VMSTATE_RUNNING_FT:
break;
case VMSTATE_RESETTING:
AssertMsgReturn(enmStateNew == VMSTATE_RUNNING, ("%s -> %s\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)), false);
break;
case VMSTATE_RESETTING_LS:
break;
case VMSTATE_SUSPENDING:
AssertMsgReturn(enmStateNew == VMSTATE_SUSPENDED, ("%s -> %s\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)), false);
break;
case VMSTATE_SUSPENDING_LS:
break;
break;
case VMSTATE_SUSPENDED:
|| enmStateNew == VMSTATE_SAVING
|| enmStateNew == VMSTATE_RESETTING
|| enmStateNew == VMSTATE_RESUMING
|| enmStateNew == VMSTATE_LOADING
break;
case VMSTATE_SUSPENDED_LS:
|| enmStateNew == VMSTATE_SAVING
break;
case VMSTATE_SUSPENDED_EXT_LS:
|| enmStateNew == VMSTATE_SAVING
break;
case VMSTATE_SAVING:
AssertMsgReturn(enmStateNew == VMSTATE_SUSPENDED, ("%s -> %s\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)), false);
break;
case VMSTATE_DEBUGGING:
break;
case VMSTATE_DEBUGGING_LS:
break;
case VMSTATE_POWERING_OFF:
AssertMsgReturn(enmStateNew == VMSTATE_OFF, ("%s -> %s\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)), false);
break;
case VMSTATE_POWERING_OFF_LS:
|| enmStateNew == VMSTATE_OFF_LS
break;
case VMSTATE_OFF:
AssertMsgReturn(enmStateNew == VMSTATE_DESTROYING, ("%s -> %s\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)), false);
break;
case VMSTATE_OFF_LS:
AssertMsgReturn(enmStateNew == VMSTATE_OFF, ("%s -> %s\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)), false);
break;
case VMSTATE_FATAL_ERROR:
AssertMsgReturn(enmStateNew == VMSTATE_POWERING_OFF, ("%s -> %s\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)), false);
break;
case VMSTATE_FATAL_ERROR_LS:
break;
case VMSTATE_GURU_MEDITATION:
break;
break;
case VMSTATE_LOAD_FAILURE:
AssertMsgReturn(enmStateNew == VMSTATE_POWERING_OFF, ("%s -> %s\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)), false);
break;
case VMSTATE_DESTROYING:
AssertMsgReturn(enmStateNew == VMSTATE_TERMINATED, ("%s -> %s\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)), false);
break;
case VMSTATE_TERMINATED:
default:
AssertMsgFailedReturn(("%s -> %s\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)), false);
break;
}
#endif /* VBOX_STRICT */
return true;
}
/**
* Does the state change callouts.
*
* The caller owns the AtStateCritSect.
*
* @param pVM The VM handle.
* @param pUVM The UVM handle.
* @param enmStateNew The New state.
* @param enmStateOld The old state.
*/
{
LogRel(("Changing the VM state from '%s' to '%s'.\n", VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew)));
{
if ( enmStateNew != VMSTATE_DESTROYING
break;
("You are not allowed to change the state while in the change callback, except "
"from destroying the VM. There are restrictions in the way the state changes "
"are propagated up to the EM execution loop and it makes the program flow very "
"difficult to follow. (%s, expected %s, old %s)\n",
}
}
/**
* Sets the current VM state, with the AtStatCritSect already entered.
*
* @param pVM The VM handle.
* @param pUVM The UVM handle.
* @param enmStateNew The new state.
* @param enmStateOld The old state.
*/
{
}
/**
* Sets the current VM state.
*
* @param pVM VM handle.
* @param enmStateNew The new state.
* @param enmStateOld The old state (for asserting only).
*/
{
}
/**
* Tries to perform a state transition.
*
* @returns The 1-based ordinal of the succeeding transition.
* VERR_VM_INVALID_VM_STATE and Assert+LogRel on failure.
*
* @param pVM The VM handle.
* @param pszWho Who is trying to change it.
* @param cTransitions The number of transitions in the ellipsis.
* @param ... Transition pairs; new, old.
*/
{
#ifdef VBOX_STRICT
/*
* Validate the input first.
*/
for (unsigned i = 0; i < cTransitions; i++)
{
}
#endif
/*
* Grab the lock and see if any of the proposed transisions works out.
*/
int rc = VERR_VM_INVALID_VM_STATE;
for (unsigned i = 0; i < cTransitions; i++)
{
if (enmStateCur == enmStateOld)
{
rc = i + 1;
break;
}
}
if (RT_FAILURE(rc))
{
/*
* Complain about it.
*/
if (cTransitions == 1)
{
LogRel(("%s: %s -> %s failed, because the VM state is actually %s\n",
pszWho, VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew), VMR3GetStateName(enmStateCur)));
N_("%s failed because the VM state is %s instead of %s"),
AssertMsgFailed(("%s: %s -> %s failed, because the VM state is actually %s\n",
pszWho, VMR3GetStateName(enmStateOld), VMR3GetStateName(enmStateNew), VMR3GetStateName(enmStateCur)));
}
else
{
for (unsigned i = 0; i < cTransitions; i++)
{
LogRel(("%s%s -> %s",
}
N_("%s failed because the current VM state, %s, was not found in the state transition table"),
AssertMsgFailed(("%s - state=%s, see release log for full details. Check the cTransitions passed us.\n",
}
}
return rc;
}
/**
* Flag a guru meditation ... a hack.
*
* @param pVM The VM handle
*
* @todo Rewrite this part. The guru meditation should be flagged
* immediately by the VMM and not by VMEmt.cpp when it's all over.
*/
{
if (enmStateCur == VMSTATE_RUNNING)
else if (enmStateCur == VMSTATE_RUNNING_LS)
{
}
}
/**
* Called by vmR3EmulationThreadWithId just before the VM structure is freed.
*
* @param pVM The VM handle.
*/
{
}
/**
* Checks if the VM was teleported and hasn't been fully resumed yet.
*
* This applies to both sides of the teleportation since we may leave a working
* clone behind and the user is allowed to resume this...
*
* @returns true / false.
* @param pVM The VM handle.
* @thread Any thread.
*/
{
VM_ASSERT_VALID_EXT_RETURN(pVM, false);
}
/**
* Registers a VM state change callback.
*
* You are not allowed to call any function which changes the VM state from a
* state callback.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pfnAtState Pointer to callback.
* @param pvUser User argument.
* @thread Any.
*/
{
/*
* Validate input.
*/
/*
* Allocate a new record.
*/
if (!pNew)
return VERR_NO_MEMORY;
/* fill */
/* insert */
return VINF_SUCCESS;
}
/**
* Deregisters a VM state change callback.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pfnAtState Pointer to callback.
* @param pvUser User argument.
* @thread Any.
*/
{
/*
* Validate input.
*/
/*
* Search the list for the entry.
*/
while ( pCur
{
}
if (!pCur)
{
return VERR_FILE_NOT_FOUND;
}
/*
* Unlink it.
*/
if (pPrev)
{
}
else
{
}
/*
* Free it.
*/
return VINF_SUCCESS;
}
/**
* Registers a VM error callback.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pfnAtError Pointer to callback.
* @param pvUser User argument.
* @thread Any.
*/
{
}
/**
* Registers a VM error callback.
*
* @returns VBox status code.
* @param pUVM The VM handle.
* @param pfnAtError Pointer to callback.
* @param pvUser User argument.
* @thread Any.
*/
{
/*
* Validate input.
*/
/*
* Allocate a new record.
*/
if (!pNew)
return VERR_NO_MEMORY;
/* fill */
/* insert */
return VINF_SUCCESS;
}
/**
* Deregisters a VM error callback.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pfnAtError Pointer to callback.
* @param pvUser User argument.
* @thread Any.
*/
{
/*
* Validate input.
*/
/*
* Search the list for the entry.
*/
while ( pCur
{
}
if (!pCur)
{
return VERR_FILE_NOT_FOUND;
}
/*
* Unlink it.
*/
if (pPrev)
{
}
else
{
}
/*
* Free it.
*/
return VINF_SUCCESS;
}
/**
* Ellipsis to va_list wrapper for calling pfnAtError.
*/
static void vmR3SetErrorWorkerDoCall(PVM pVM, PVMATERROR pCur, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
{
}
/**
* This is a worker function for GC and Ring-0 calls to VMSetError and VMSetErrorV.
* The message is found in VMINT.
*
* @param pVM The VM handle.
* @thread EMT.
*/
{
AssertReleaseMsgFailed(("And we have a winner! You get to implement Ring-0 and GC VMSetErrorV! Contrats!\n"));
/*
* Unpack the error (if we managed to format one).
*/
const char *pszFunction = NULL;
const char *pszMessage;
if (pErr)
{
AssertCompile(sizeof(const char) == sizeof(uint8_t));
if (pErr->offFunction)
if (pErr->offMessage)
else
pszMessage = "No message!";
}
else
pszMessage = "No message! (Failed to allocate memory to put the error message in!)";
/*
* Call the at error callbacks.
*/
}
/**
* Gets the number of errors raised via VMSetError.
*
* This can be used avoid double error messages.
*
* @returns The error count.
* @param pVM The VM handle.
*/
{
}
/**
* Creation time wrapper for vmR3SetErrorUV.
*
* @returns rc.
* @param pUVM Pointer to the user mode VM structure.
* @param rc The VBox status code.
* @param RT_SRC_POS_DECL The source position of this error.
* @param pszFormat Format string.
* @param ... The arguments.
* @thread Any thread.
*/
{
return rc;
}
/**
* Worker which calls everyone listening to the VM error messages.
*
* @param pUVM Pointer to the user mode VM structure.
* @param rc The VBox status code.
* @param RT_SRC_POS_DECL The source position of this error.
* @param pszFormat Format string.
* @param pArgs Pointer to the format arguments.
* @thread EMT
*/
DECLCALLBACK(void) vmR3SetErrorUV(PUVM pUVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list *pArgs)
{
/*
* Log the error.
*/
RTLogRelPrintf("VMSetError: %s(%d) %s; rc=%Rrc\n"
"VMSetError: %N\n",
#ifdef LOG_ENABLED
RTLogPrintf("VMSetError: %s(%d) %s; rc=%Rrc\n"
"%N\n",
#endif
/*
* Make a copy of the message.
*/
/*
* Call the at error callbacks.
*/
bool fCalledSomeone = false;
{
fCalledSomeone = true;
}
}
/**
* Registers a VM runtime error callback.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pfnAtRuntimeError Pointer to callback.
* @param pvUser User argument.
* @thread Any.
*/
VMMR3DECL(int) VMR3AtRuntimeErrorRegister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser)
{
LogFlow(("VMR3AtRuntimeErrorRegister: pfnAtRuntimeError=%p pvUser=%p\n", pfnAtRuntimeError, pvUser));
/*
* Validate input.
*/
/*
* Allocate a new record.
*/
if (!pNew)
return VERR_NO_MEMORY;
/* fill */
/* insert */
return VINF_SUCCESS;
}
/**
* Deregisters a VM runtime error callback.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pfnAtRuntimeError Pointer to callback.
* @param pvUser User argument.
* @thread Any.
*/
VMMR3DECL(int) VMR3AtRuntimeErrorDeregister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser)
{
LogFlow(("VMR3AtRuntimeErrorDeregister: pfnAtRuntimeError=%p pvUser=%p\n", pfnAtRuntimeError, pvUser));
/*
* Validate input.
*/
/*
* Search the list for the entry.
*/
while ( pCur
{
}
if (!pCur)
{
return VERR_FILE_NOT_FOUND;
}
/*
* Unlink it.
*/
if (pPrev)
{
}
else
{
}
/*
* Free it.
*/
return VINF_SUCCESS;
}
/**
* EMT rendezvous worker that vmR3SetRuntimeErrorCommon uses to safely change
* the state to FatalError(LS).
*
* @returns VERR_VM_INVALID_VM_STATE or VINF_EM_SUSPENED. (This is a strict
* return code, see FNVMMEMTRENDEZVOUS.)
*
* @param pVM The VM handle.
* @param pVCpu The VMCPU handle of the EMT.
* @param pvUser Ignored.
*/
static DECLCALLBACK(VBOXSTRICTRC) vmR3SetRuntimeErrorChangeState(PVM pVM, PVMCPU pVCpu, void *pvUser)
{
/*
* The first EMT thru here changes the state.
*/
{
if (RT_FAILURE(rc))
return rc;
if (rc == 2)
}
/* This'll make sure we get out of whereever we are (e.g. REM). */
return VINF_EM_SUSPEND;
}
/**
* Worker for VMR3SetRuntimeErrorWorker and vmR3SetRuntimeErrorV.
*
* This does the common parts after the error has been saved / retrieved.
*
* @returns VBox status code with modifications, see VMSetRuntimeErrorV.
*
* @param pVM The VM handle.
* @param fFlags The error flags.
* @param pszErrorId Error ID string.
* @param pszFormat Format string.
* @param pVa Pointer to the format arguments.
*/
static int vmR3SetRuntimeErrorCommon(PVM pVM, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list *pVa)
{
/*
* Take actions before the call.
*/
int rc;
if (fFlags & VMSETRTERR_FLAGS_FATAL)
rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_DESCENDING | VMMEMTRENDEZVOUS_FLAGS_STOP_ON_ERROR,
else if (fFlags & VMSETRTERR_FLAGS_SUSPEND)
else
rc = VINF_SUCCESS;
/*
* Do the callback round.
*/
{
}
return rc;
}
/**
* Ellipsis to va_list wrapper for calling vmR3SetRuntimeErrorCommon.
*/
static int vmR3SetRuntimeErrorCommonF(PVM pVM, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
{
return rc;
}
/**
* This is a worker function for RC and Ring-0 calls to VMSetError and
* VMSetErrorV.
*
* The message is found in VMINT.
*
* @returns VBox status code, see VMSetRuntimeError.
* @param pVM The VM handle.
* @thread EMT.
*/
{
AssertReleaseMsgFailed(("And we have a winner! You get to implement Ring-0 and GC VMSetRuntimeErrorV! Congrats!\n"));
/*
* Unpack the error (if we managed to format one).
*/
const char *pszErrorId = "SetRuntimeError";
const char *pszMessage = "No message!";
if (pErr)
{
AssertCompile(sizeof(const char) == sizeof(uint8_t));
if (pErr->offErrorId)
if (pErr->offMessage)
}
/*
* Join cause with vmR3SetRuntimeErrorV.
*/
}
/**
* Worker for VMSetRuntimeErrorV for doing the job on EMT in ring-3.
*
* @returns VBox status code with modifications, see VMSetRuntimeErrorV.
*
* @param pVM The VM handle.
* @param fFlags The error flags.
* @param pszErrorId Error ID string.
* @param pszMessage The error message residing the MM heap.
*
* @thread EMT
*/
DECLCALLBACK(int) vmR3SetRuntimeError(PVM pVM, uint32_t fFlags, const char *pszErrorId, char *pszMessage)
{
#if 0 /** @todo make copy of the error msg. */
/*
* Make a copy of the message.
*/
#endif
/*
* Join paths with VMR3SetRuntimeErrorWorker.
*/
return rc;
}
/**
* Worker for VMSetRuntimeErrorV for doing the job on EMT in ring-3.
*
* @returns VBox status code with modifications, see VMSetRuntimeErrorV.
*
* @param pVM The VM handle.
* @param fFlags The error flags.
* @param pszErrorId Error ID string.
* @param pszFormat Format string.
* @param pVa Pointer to the format arguments.
*
* @thread EMT
*/
DECLCALLBACK(int) vmR3SetRuntimeErrorV(PVM pVM, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list *pVa)
{
/*
* Make a copy of the message.
*/
/*
* Join paths with VMR3SetRuntimeErrorWorker.
*/
}
/**
* Gets the number of runtime errors raised via VMR3SetRuntimeError.
*
* This can be used avoid double error messages.
*
* @returns The runtime error count.
* @param pVM The VM handle.
*/
{
}
/**
* Gets the ID virtual of the virtual CPU assoicated with the calling thread.
*
* @returns The CPU ID. NIL_VMCPUID if the thread isn't an EMT.
*
* @param pVM The VM handle.
*/
{
return pUVCpu
: NIL_VMCPUID;
}
/**
* Returns the native handle of the current EMT VMCPU thread.
*
* @returns Handle if this is an EMT thread; NIL_RTNATIVETHREAD otherwise
* @param pVM The VM handle.
* @thread EMT
*/
{
if (!pUVCpu)
return NIL_RTNATIVETHREAD;
}
/**
* Returns the native handle of the current EMT VMCPU thread.
*
* @returns Handle if this is an EMT thread; NIL_RTNATIVETHREAD otherwise
* @param pVM The VM handle.
* @thread EMT
*/
{
if (!pUVCpu)
return NIL_RTNATIVETHREAD;
}
/**
* Returns the handle of the current EMT VMCPU thread.
*
* @returns Handle if this is an EMT thread; NIL_RTNATIVETHREAD otherwise
* @param pVM The VM handle.
* @thread EMT
*/
{
if (!pUVCpu)
return NIL_RTTHREAD;
}
/**
* Returns the handle of the current EMT VMCPU thread.
*
* @returns Handle if this is an EMT thread; NIL_RTNATIVETHREAD otherwise
* @param pVM The VM handle.
* @thread EMT
*/
{
if (!pUVCpu)
return NIL_RTTHREAD;
}
/**
* Return the package and core id of a CPU.
*
* @returns VBOX status code.
* @param pVM The VM to operate on.
* @param idCpu Virtual CPU to get the ID from.
* @param pidCpuCore Where to store the core ID of the virtual CPU.
* @param pidCpuPackage Where to store the package ID of the virtual CPU.
*
*/
VMMR3DECL(int) VMR3GetCpuCoreAndPackageIdFromCpuId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage)
{
return VERR_INVALID_CPU_ID;
#ifdef VBOX_WITH_MULTI_CORE
*pidCpuCore = idCpu;
*pidCpuPackage = 0;
#else
*pidCpuCore = 0;
*pidCpuPackage = idCpu;
#endif
return VINF_SUCCESS;
}
/**
* Worker for VMR3HotUnplugCpu.
*
* @returns VINF_EM_WAIT_SPIP (strict status code).
* @param pVM The VM handle.
* @param idCpu The current CPU.
*/
{
/*
* Reset per CPU resources.
*
* Actually only needed for VT-x because the CPU seems to be still in some
* paged mode and startup fails after a new hot plug event. SVM works fine
* even without this.
*/
return VINF_EM_WAIT_SIPI;
}
/**
* Hot-unplugs a CPU from the guest.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param idCpu Virtual CPU to perform the hot unplugging operation on.
*/
{
/** @todo r=bird: Don't destroy the EMT, it'll break VMMR3EmtRendezvous and
* broadcast requests. Just note down somewhere that the CPU is
* offline and send it to SPIP wait. Maybe modify VMCPUSTATE and push
* it out of the EM loops when offline. */
}
/**
* Hot-plugs a CPU on the guest.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param idCpu Virtual CPU to perform the hot plugging operation on.
*/
{
/** @todo r-bird: Just mark it online and make sure it waits on SPIP. */
return VINF_SUCCESS;
}
/**
* Changes the VCPU priority.
*
* @returns VBox status code.
* @param pVM The VM to operate on.
* @param ulCpuPriority New CPU priority
*/
{
/* Note: not called from EMT. */
return VINF_SUCCESS;
}