Index: trunk/include/VBox/dbggui.h
===================================================================
--- trunk/include/VBox/dbggui.h	(revision 44339)
+++ trunk/include/VBox/dbggui.h	(revision 44340)
@@ -98,12 +98,12 @@
  *
  * @returns VBox status code.
- * @param   pVM         The VM handle.
+ * @param   pUVM        The VM handle.
  * @param   ppGui       Where to store the pointer to the debugger instance.
  * @param   ppGuiVT     Where to store the virtual method table pointer.
  *                      Optional.
  */
-DBGDECL(int) DBGGuiCreateForVM(PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT);
+DBGDECL(int) DBGGuiCreateForVM(PUVM pUVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT);
 /** @copydoc DBGGuiCreateForVM. */
-typedef DECLCALLBACK(int) FNDBGGUICREATEFORVM(PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT);
+typedef DECLCALLBACK(int) FNDBGGUICREATEFORVM(PUVM pUVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT);
 /** Pointer to DBGGuiCreateForVM. */
 typedef FNDBGGUICREATEFORVM *PFNDBGGUICREATEFORVM;
Index: trunk/include/VBox/vmm/cfgm.h
===================================================================
--- trunk/include/VBox/vmm/cfgm.h	(revision 44339)
+++ trunk/include/VBox/vmm/cfgm.h	(revision 44340)
@@ -186,4 +186,5 @@
  */
 VMMR3DECL(PCFGMNODE)    CFGMR3GetRoot(PVM pVM);
+VMMR3DECL(PCFGMNODE)    CFGMR3GetRootU(PUVM pUVM);
 VMMR3DECL(PCFGMNODE)    CFGMR3GetParent(PCFGMNODE pNode);
 VMMR3DECL(PCFGMNODE)    CFGMR3GetParentEx(PVM pVM, PCFGMNODE pNode);
Index: trunk/include/VBox/vmm/em.h
===================================================================
--- trunk/include/VBox/vmm/em.h	(revision 44339)
+++ trunk/include/VBox/vmm/em.h	(revision 44340)
@@ -225,13 +225,16 @@
  * @{
  */
-VMMR3DECL(int)      EMR3Init(PVM pVM);
-VMMR3DECL(void)     EMR3Relocate(PVM pVM);
-VMMR3DECL(void)     EMR3ResetCpu(PVMCPU pVCpu);
-VMMR3DECL(void)     EMR3Reset(PVM pVM);
-VMMR3DECL(int)      EMR3Term(PVM pVM);
+VMMR3DECL(int)          EMR3Init(PVM pVM);
+VMMR3DECL(void)         EMR3Relocate(PVM pVM);
+VMMR3DECL(void)         EMR3ResetCpu(PVMCPU pVCpu);
+VMMR3DECL(void)         EMR3Reset(PVM pVM);
+VMMR3DECL(int)          EMR3Term(PVM pVM);
 VMMR3DECL(DECLNORETURN(void)) EMR3FatalError(PVMCPU pVCpu, int rc);
-VMMR3DECL(int)      EMR3ExecuteVM(PVM pVM, PVMCPU pVCpu);
-VMMR3DECL(int)      EMR3CheckRawForcedActions(PVM pVM, PVMCPU pVCpu);
-VMMR3DECL(int)      EMR3Interpret(PVM pVM);
+VMMR3DECL(int)          EMR3ExecuteVM(PVM pVM, PVMCPU pVCpu);
+VMMR3DECL(int)          EMR3CheckRawForcedActions(PVM pVM, PVMCPU pVCpu);
+VMMR3DECL(int)          EMR3Interpret(PVM pVM);
+VMMR3_INT_DECL(int)     EMR3NotifyResume(PVM pVM);
+VMMR3_INT_DECL(int)     EMR3NotifySuspend(PVM pVM);
+VMMR3_INT_DECL(bool)    EMR3IsExecutionAllowed(PVM pVM, PVMCPU pVCpu);
 
 /**
Index: trunk/include/VBox/vmm/vmapi.h
===================================================================
--- trunk/include/VBox/vmm/vmapi.h	(revision 44339)
+++ trunk/include/VBox/vmm/vmapi.h	(revision 44340)
@@ -316,14 +316,4 @@
 } VMINITCOMPLETED;
 
-
-VMMR3DECL(int)  VMR3Create(uint32_t cCpus, PCVMM2USERMETHODS pVm2UserCbs,
-                           PFNVMATERROR pfnVMAtError, void *pvUserVM,
-                           PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM,
-                           PVM *ppVM);
-VMMR3DECL(int)  VMR3PowerOn(PVM pVM);
-VMMR3DECL(int)  VMR3Suspend(PVM pVM);
-VMMR3DECL(int)  VMR3Resume(PVM pVM);
-VMMR3DECL(int)  VMR3Reset(PVM pVM);
-
 /**
  * Progress callback.
@@ -340,13 +330,33 @@
 typedef FNVMPROGRESS *PFNVMPROGRESS;
 
-VMMR3DECL(int)  VMR3Save(PVM pVM, const char *pszFilename, bool fContinueAfterwards, PFNVMPROGRESS pfnProgress, void *pvUser, bool *pfSuspended);
-VMMR3DECL(int)  VMR3Teleport(PVM pVM, uint32_t cMsDowntime, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser, PFNVMPROGRESS pfnProgress, void *pvProgressUser, bool *pfSuspended);
-VMMR3DECL(int)  VMR3LoadFromFile(PVM pVM, const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser);
-VMMR3DECL(int)  VMR3LoadFromStream(PVM pVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
-                                   PFNVMPROGRESS pfnProgress, void *pvProgressUser);
-VMMR3DECL(int)  VMR3PowerOff(PVM pVM);
-VMMR3DECL(int)  VMR3Destroy(PVM pVM);
-VMMR3DECL(void) VMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
-VMMR3DECL(PVM)  VMR3EnumVMs(PVM pVMPrev);
+/**
+ * VM destruction callback.
+ * @param   pVM     The VM which is about to be destroyed.
+ * @param   pvUser  The user parameter specified at registration.
+ */
+typedef DECLCALLBACK(void) FNVMATDTOR(PVM pVM, void *pvUser);
+/** Pointer to a VM destruction callback. */
+typedef FNVMATDTOR *PFNVMATDTOR;
+
+
+VMMR3DECL(int)          VMR3Create(uint32_t cCpus, PCVMM2USERMETHODS pVm2UserCbs,
+                                   PFNVMATERROR pfnVMAtError, void *pvUserVM,
+                                   PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM,
+                                   PVM *ppVM, PUVM *ppUVM);
+VMMR3DECL(int)          VMR3PowerOn(PUVM pUVM);
+VMMR3DECL(int)          VMR3Suspend(PUVM pUVM);
+VMMR3DECL(int)          VMR3Resume(PUVM pUVM);
+VMMR3DECL(int)          VMR3Reset(PUVM pUVM);
+VMMR3DECL(int)          VMR3Save(PUVM pUVM, const char *pszFilename, bool fContinueAfterwards, PFNVMPROGRESS pfnProgress, void *pvUser, bool *pfSuspended);
+VMMR3_INT_DECL(int)     VMR3SaveFT(PUVM pUVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser, bool *pfSuspended, bool fSkipStateChanges);
+VMMR3DECL(int)          VMR3Teleport(PUVM pUVM, uint32_t cMsDowntime, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser, PFNVMPROGRESS pfnProgress, void *pvProgressUser, bool *pfSuspended);
+VMMR3DECL(int)          VMR3LoadFromFile(PUVM pUVM, const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser);
+VMMR3DECL(int)          VMR3LoadFromStream(PUVM pUVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
+                                           PFNVMPROGRESS pfnProgress, void *pvProgressUser);
+VMMR3_INT_DECL(int)     VMR3LoadFromStreamFT(PUVM pUVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser);
+
+VMMR3DECL(int)          VMR3PowerOff(PUVM pUVM);
+VMMR3DECL(int)          VMR3Destroy(PUVM pUVM);
+VMMR3_INT_DECL(void)    VMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
 
 VMMR3DECL(PVM)          VMR3GetVM(PUVM pUVM);
@@ -359,46 +369,34 @@
 VMMR3DECL(VMSTATE)      VMR3GetStateU(PUVM pUVM);
 VMMR3DECL(const char *) VMR3GetStateName(VMSTATE enmState);
-
-/**
- * VM destruction callback.
- * @param   pVM     The VM which is about to be destroyed.
- * @param   pvUser  The user parameter specified at registration.
- */
-typedef DECLCALLBACK(void) FNVMATDTOR(PVM pVM, void *pvUser);
-/** Pointer to a VM destruction callback. */
-typedef FNVMATDTOR *PFNVMATDTOR;
-
-VMMR3DECL(int)      VMR3AtDtorRegister(PFNVMATDTOR pfnAtDtor, void *pvUser);
-VMMR3DECL(int)      VMR3AtDtorDeregister(PFNVMATDTOR pfnAtDtor);
-VMMR3DECL(int)      VMR3AtStateRegister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser);
-VMMR3DECL(int)      VMR3AtStateDeregister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser);
-VMMR3DECL(bool)     VMR3TeleportedAndNotFullyResumedYet(PVM pVM);
-VMMR3DECL(int)      VMR3AtErrorRegister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
-VMMR3DECL(int)      VMR3AtErrorRegisterU(PUVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
-VMMR3DECL(int)      VMR3AtErrorDeregister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser);
-VMMR3DECL(void)     VMR3SetErrorWorker(PVM pVM);
-VMMR3DECL(uint32_t) VMR3GetErrorCount(PVM pVM);
-VMMR3DECL(uint32_t) VMR3GetErrorCountU(PUVM pUVM);
-VMMR3DECL(int)      VMR3AtRuntimeErrorRegister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
-VMMR3DECL(int)      VMR3AtRuntimeErrorDeregister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
-VMMR3DECL(int)      VMR3SetRuntimeErrorWorker(PVM pVM);
-VMMR3DECL(uint32_t) VMR3GetRuntimeErrorCount(PVM pVM);
-VMMR3DECL(int)      VMR3ReqCall(PVM pVM, VMCPUID idDstCpu, PVMREQ *ppReq, RTMSINTERVAL cMillies, uint32_t fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
-VMMR3DECL(int)      VMR3ReqCallU(PUVM pUVM, VMCPUID idDstCpu, PVMREQ *ppReq, RTMSINTERVAL cMillies, uint32_t fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
-VMMR3DECL(int)      VMR3ReqCallVU(PUVM pUVM, VMCPUID idDstCpu, PVMREQ *ppReq, RTMSINTERVAL cMillies, uint32_t fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args);
-VMMR3DECL(int)      VMR3ReqCallWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
-VMMR3DECL(int)      VMR3ReqCallNoWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
-VMMR3DECL(int)      VMR3ReqCallVoidWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
-VMMR3DECL(int)      VMR3ReqCallVoidNoWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
-VMMR3DECL(int)      VMR3ReqPriorityCallWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
-VMMR3DECL(int)      VMR3ReqPriorityCallVoidWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
-VMMR3DECL(int)      VMR3ReqAlloc(PVM pVM, PVMREQ *ppReq, VMREQTYPE enmType, VMCPUID idDstCpu);
-VMMR3DECL(int)      VMR3ReqAllocU(PUVM pUVM, PVMREQ *ppReq, VMREQTYPE enmType, VMCPUID idDstCpu);
-VMMR3DECL(int)      VMR3ReqFree(PVMREQ pReq);
-VMMR3DECL(int)      VMR3ReqQueue(PVMREQ pReq, RTMSINTERVAL cMillies);
-VMMR3DECL(int)      VMR3ReqWait(PVMREQ pReq, RTMSINTERVAL cMillies);
-VMMR3DECL(int)      VMR3ReqProcessU(PUVM pUVM, VMCPUID idDstCpu, bool fPriorityOnly);
-VMMR3DECL(void)     VMR3NotifyGlobalFFU(PUVM pUVM, uint32_t fFlags);
-VMMR3DECL(void)     VMR3NotifyCpuFFU(PUVMCPU pUVMCpu, uint32_t fFlags);
+VMMR3DECL(int)          VMR3AtStateRegister(PUVM pUVM, PFNVMATSTATE pfnAtState, void *pvUser);
+VMMR3DECL(int)          VMR3AtStateDeregister(PUVM pUVM, PFNVMATSTATE pfnAtState, void *pvUser);
+VMMR3_INT_DECL(bool)    VMR3TeleportedAndNotFullyResumedYet(PVM pVM);
+VMMR3DECL(int)          VMR3AtErrorRegister(PUVM pUVM, PFNVMATERROR pfnAtError, void *pvUser);
+VMMR3DECL(int)          VMR3AtErrorDeregister(PUVM pUVM, PFNVMATERROR pfnAtError, void *pvUser);
+VMMR3_INT_DECL(void)    VMR3SetErrorWorker(PVM pVM);
+VMMR3_INT_DECL(uint32_t) VMR3GetErrorCount(PUVM pUVM);
+VMMR3DECL(int)          VMR3AtRuntimeErrorRegister(PUVM pUVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
+VMMR3DECL(int)          VMR3AtRuntimeErrorDeregister(PUVM pUVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser);
+VMMR3_INT_DECL(int)     VMR3SetRuntimeErrorWorker(PVM pVM);
+VMMR3_INT_DECL(uint32_t) VMR3GetRuntimeErrorCount(PUVM pUVM);
+
+VMMR3DECL(int)          VMR3ReqCallU(PUVM pUVM, VMCPUID idDstCpu, PVMREQ *ppReq, RTMSINTERVAL cMillies, uint32_t fFlags, PFNRT pfnFunction, unsigned cArgs, ...);
+VMMR3DECL(int)          VMR3ReqCallVU(PUVM pUVM, VMCPUID idDstCpu, PVMREQ *ppReq, RTMSINTERVAL cMillies, uint32_t fFlags, PFNRT pfnFunction, unsigned cArgs, va_list Args);
+VMMR3_INT_DECL(int)     VMR3ReqCallWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
+VMMR3DECL(int)          VMR3ReqCallWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
+VMMR3DECL(int)          VMR3ReqCallNoWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
+VMMR3DECL(int)          VMR3ReqCallNoWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
+VMMR3_INT_DECL(int)     VMR3ReqCallVoidWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
+VMMR3DECL(int)          VMR3ReqCallVoidWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
+VMMR3DECL(int)          VMR3ReqCallVoidNoWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
+VMMR3DECL(int)          VMR3ReqPriorityCallWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
+VMMR3DECL(int)          VMR3ReqPriorityCallWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
+VMMR3DECL(int)          VMR3ReqPriorityCallVoidWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...);
+VMMR3DECL(int)          VMR3ReqAlloc(PUVM pUVM, PVMREQ *ppReq, VMREQTYPE enmType, VMCPUID idDstCpu);
+VMMR3DECL(int)          VMR3ReqFree(PVMREQ pReq);
+VMMR3DECL(int)          VMR3ReqQueue(PVMREQ pReq, RTMSINTERVAL cMillies);
+VMMR3DECL(int)          VMR3ReqWait(PVMREQ pReq, RTMSINTERVAL cMillies);
+VMMR3_INT_DECL(int)     VMR3ReqProcessU(PUVM pUVM, VMCPUID idDstCpu, bool fPriorityOnly);
+
 /** @name Flags for VMR3NotifyCpuFFU and VMR3NotifyGlobalFFU.
  * @{ */
@@ -408,18 +406,18 @@
 #define VMNOTIFYFF_FLAGS_POKE       RT_BIT_32(1)
 /** @} */
-
-VMMR3DECL(int)              VMR3WaitHalted(PVM pVM, PVMCPU pVCpu, bool fIgnoreInterrupts);
-VMMR3DECL(int)              VMR3WaitU(PUVMCPU pUVMCpu);
+VMMR3_INT_DECL(void)        VMR3NotifyGlobalFFU(PUVM pUVM, uint32_t fFlags);
+VMMR3_INT_DECL(void)        VMR3NotifyCpuFFU(PUVMCPU pUVMCpu, uint32_t fFlags);
+VMMR3_INT_DECL(int)         VMR3WaitHalted(PVM pVM, PVMCPU pVCpu, bool fIgnoreInterrupts);
+VMMR3_INT_DECL(int)         VMR3WaitU(PUVMCPU pUVMCpu);
 VMMR3_INT_DECL(int)         VMR3AsyncPdmNotificationWaitU(PUVMCPU pUVCpu);
 VMMR3_INT_DECL(void)        VMR3AsyncPdmNotificationWakeupU(PUVM pUVM);
-VMMR3DECL(RTCPUID)          VMR3GetVMCPUId(PVM pVM);
-VMMR3DECL(RTTHREAD)         VMR3GetVMCPUThread(PVM pVM);
-VMMR3DECL(RTTHREAD)         VMR3GetVMCPUThreadU(PUVM pUVM);
+VMMR3_INT_DECL(RTCPUID)     VMR3GetVMCPUId(PVM pVM);
+VMMR3DECL(RTTHREAD)         VMR3GetVMCPUThread(PUVM pUVM);
 VMMR3DECL(RTNATIVETHREAD)   VMR3GetVMCPUNativeThread(PVM pVM);
 VMMR3DECL(RTNATIVETHREAD)   VMR3GetVMCPUNativeThreadU(PUVM pUVM);
-VMMR3DECL(int)              VMR3GetCpuCoreAndPackageIdFromCpuId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage);
-VMMR3DECL(int)              VMR3HotUnplugCpu(PVM pVM, VMCPUID idCpu);
-VMMR3DECL(int)              VMR3HotPlugCpu(PVM pVM, VMCPUID idCpu);
-VMMR3DECL(int)              VMR3SetCpuExecutionCap(PVM pVM, uint32_t uCpuExecutionCap);
+VMMR3DECL(int)              VMR3GetCpuCoreAndPackageIdFromCpuId(PUVM pUVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage);
+VMMR3DECL(int)              VMR3HotUnplugCpu(PUVM pUVM, VMCPUID idCpu);
+VMMR3DECL(int)              VMR3HotPlugCpu(PUVM pUVM, VMCPUID idCpu);
+VMMR3DECL(int)              VMR3SetCpuExecutionCap(PUVM pUVM, uint32_t uCpuExecutionCap);
 /** @} */
 #endif /* IN_RING3 */
Index: trunk/src/VBox/Debugger/VBoxDbg.cpp
===================================================================
--- trunk/src/VBox/Debugger/VBoxDbg.cpp	(revision 44339)
+++ trunk/src/VBox/Debugger/VBoxDbg.cpp	(revision 44340)
@@ -72,9 +72,9 @@
  * @returns VBox status code.
  * @param   pSession    The ISession interface. (DBGGuiCreate)
- * @param   pVM         The VM handle. (DBGGuiCreateForVM)
+ * @param   pUVM        The VM handle. (DBGGuiCreateForVM)
  * @param   ppGui       See DBGGuiCreate.
  * @param   ppGuiVT     See DBGGuiCreate.
  */
-static int dbgGuiCreate(ISession *pSession, PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
+static int dbgGuiCreate(ISession *pSession, PUVM pUVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
 {
     /*
@@ -91,5 +91,5 @@
         rc = pGui->pVBoxDbgGui->init(pSession);
     else
-        rc = pGui->pVBoxDbgGui->init(pVM);
+        rc = pGui->pVBoxDbgGui->init(pUVM);
     if (RT_SUCCESS(rc))
     {
@@ -135,13 +135,18 @@
  *
  * @returns VBox status code.
- * @param   pVM         The VM handle.
+ * @param   pUVM        The VM handle.
  * @param   ppGui       Where to store the pointer to the debugger instance.
  * @param   ppGuiVT     Where to store the virtual method table pointer.
  *                      Optional.
  */
-DBGDECL(int) DBGGuiCreateForVM(PVM pVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
-{
-    AssertPtrReturn(pVM, VERR_INVALID_POINTER);
-    return dbgGuiCreate(NULL, pVM, ppGui, ppGuiVT);
+DBGDECL(int) DBGGuiCreateForVM(PUVM pUVM, PDBGGUI *ppGui, PCDBGGUIVT *ppGuiVT)
+{
+    AssertPtrReturn(pUVM, VERR_INVALID_POINTER);
+    AssertPtrReturn(VMR3RetainUVM(pUVM) != UINT32_MAX, VERR_INVALID_POINTER);
+
+    int rc = dbgGuiCreate(NULL, pUVM, ppGui, ppGuiVT);
+
+    VMR3ReleaseUVM(pUVM);
+    return rc;
 }
 
Index: trunk/src/VBox/Debugger/VBoxDbgBase.cpp
===================================================================
--- trunk/src/VBox/Debugger/VBoxDbgBase.cpp	(revision 44339)
+++ trunk/src/VBox/Debugger/VBoxDbgBase.cpp	(revision 44340)
@@ -33,14 +33,15 @@
 
 VBoxDbgBase::VBoxDbgBase(VBoxDbgGui *a_pDbgGui)
-    : m_pDbgGui(a_pDbgGui), m_pVM(NULL), m_hGUIThread(RTThreadNativeSelf())
+    : m_pDbgGui(a_pDbgGui), m_pUVM(NULL), m_hGUIThread(RTThreadNativeSelf())
 {
     /*
      * Register
      */
-    PVM pVM = a_pDbgGui->getVMHandle();
-    if (pVM)
-    {
-        m_pVM = pVM;
-        int rc = VMR3AtStateRegister(pVM, atStateChange, this);
+    m_pUVM = a_pDbgGui->getUvmHandle();
+    if (m_pUVM)
+    {
+        VMR3RetainUVM(m_pUVM);
+
+        int rc = VMR3AtStateRegister(m_pUVM, atStateChange, this);
         AssertRC(rc);
     }
@@ -54,9 +55,11 @@
      */
     /** @todo need to do some locking here?  */
-    PVM pVM = ASMAtomicXchgPtrT(&m_pVM, NULL, PVM);
-    if (pVM)
-    {
-        int rc = VMR3AtStateDeregister(pVM, atStateChange, this);
+    PUVM pUVM = ASMAtomicXchgPtrT(&m_pUVM, NULL, PUVM);
+    if (pUVM)
+    {
+        int rc = VMR3AtStateDeregister(pUVM, atStateChange, this);
         AssertRC(rc);
+
+        VMR3ReleaseUVM(pUVM);
     }
 }
@@ -68,8 +71,8 @@
     QByteArray Utf8Array = rPat.toUtf8();
     const char *pszPat = !rPat.isEmpty() ? Utf8Array.constData() : NULL;
-    PVM pVM = m_pVM;
-    if (    pVM
-        &&  VMR3GetState(pVM) < VMSTATE_DESTROYING)
-        return STAMR3Reset(pVM, pszPat);
+    PUVM pUVM = m_pUVM;
+    if (    pUVM
+        &&  VMR3GetStateU(pUVM) < VMSTATE_DESTROYING)
+        return STAMR3Reset(VMR3GetVM(pUVM), pszPat);
     return VERR_INVALID_HANDLE;
 }
@@ -81,8 +84,8 @@
     QByteArray Utf8Array = rPat.toUtf8();
     const char *pszPat = !rPat.isEmpty() ? Utf8Array.constData() : NULL;
-    PVM pVM = m_pVM;
-    if (    pVM
-        &&  VMR3GetState(pVM) < VMSTATE_DESTROYING)
-        return STAMR3Enum(pVM, pszPat, pfnEnum, pvUser);
+    PUVM pUVM = m_pUVM;
+    if (    pUVM
+        &&  VMR3GetStateU(pUVM) < VMSTATE_DESTROYING)
+        return STAMR3Enum(VMR3GetVM(pUVM), pszPat, pfnEnum, pvUser);
     return VERR_INVALID_HANDLE;
 }
@@ -92,8 +95,8 @@
 VBoxDbgBase::dbgcCreate(PDBGCBACK pBack, unsigned fFlags)
 {
-    PVM pVM = m_pVM;
-    if (    pVM
-        &&  VMR3GetState(pVM) < VMSTATE_DESTROYING)
-        return DBGCCreate(pVM, pBack, fFlags);
+    PUVM pUVM = m_pUVM;
+    if (    pUVM
+        &&  VMR3GetStateU(pUVM) < VMSTATE_DESTROYING)
+        return DBGCCreate(VMR3GetVM(pUVM), pBack, fFlags);
     return VERR_INVALID_HANDLE;
 }
@@ -107,8 +110,14 @@
     {
         case VMSTATE_TERMINATED:
+        {
             /** @todo need to do some locking here?  */
-            if (ASMAtomicCmpXchgPtr(&pThis->m_pVM, NULL, pVM))
+            PUVM pUVM = ASMAtomicXchgPtrT(&m_pUVM, NULL, PUVM);
+            if (pUVM)
+            {
                 pThis->sigTerminated();
+                VMR3ReleaseUVM(pUVM);
+            }
             break;
+        }
 
         case VMSTATE_DESTROYING:
Index: trunk/src/VBox/Debugger/VBoxDbgBase.h
===================================================================
--- trunk/src/VBox/Debugger/VBoxDbgBase.h	(revision 44339)
+++ trunk/src/VBox/Debugger/VBoxDbgBase.h	(revision 44340)
@@ -60,5 +60,5 @@
     bool isVMOk() const
     {
-        return m_pVM != NULL;
+        return m_pUVM != NULL;
     }
 
@@ -120,6 +120,6 @@
     /** Pointer to the debugger GUI object. */
     VBoxDbgGui *m_pDbgGui;
-    /** The VM handle. */
-    PVM volatile m_pVM;
+    /** The user mode VM handle. */
+    PUVM volatile m_pUVM;
     /** The handle of the GUI thread. */
     RTNATIVETHREAD m_hGUIThread;
Index: trunk/src/VBox/Debugger/VBoxDbgGui.cpp
===================================================================
--- trunk/src/VBox/Debugger/VBoxDbgGui.cpp	(revision 44339)
+++ trunk/src/VBox/Debugger/VBoxDbgGui.cpp	(revision 44340)
@@ -33,5 +33,5 @@
 VBoxDbgGui::VBoxDbgGui() :
     m_pDbgStats(NULL), m_pDbgConsole(NULL), m_pSession(NULL), m_pConsole(NULL),
-    m_pMachineDebugger(NULL), m_pMachine(NULL), m_pVM(NULL),
+    m_pMachineDebugger(NULL), m_pMachine(NULL), m_pUVM(NULL),
     m_pParent(NULL), m_pMenu(NULL),
     m_x(0), m_y(0), m_cx(0), m_cy(0), m_xDesktop(0), m_yDesktop(0), m_cxDesktop(0), m_cyDesktop(0)
@@ -41,10 +41,10 @@
 
 
-int VBoxDbgGui::init(PVM pVM)
+int VBoxDbgGui::init(PUVM pUVM)
 {
     /*
      * Set the VM handle and update the desktop size.
      */
-    m_pVM = pVM;
+    m_pUVM = pUVM; /* Note! This eats the incoming reference to the handle! */
     updateDesktopSize();
 
@@ -79,7 +79,10 @@
                 if (SUCCEEDED(hrc))
                 {
-                    rc = init((PVM)(intptr_t)llVM);
+                    PUVM pUVM = (PUVM)(intptr_t)llVM;
+                    rc = init(pUVM);
                     if (RT_SUCCESS(rc))
                         return rc;
+
+                    VMR3ReleaseUVM(pUVM);
                 }
 
@@ -137,5 +140,9 @@
     }
 
-    m_pVM = NULL;
+    if (m_pUVM)
+    {
+        VMR3ReleaseUVM(m_pUVM);
+        m_pUVM = NULL;
+    }
 }
 
Index: trunk/src/VBox/Debugger/VBoxDbgGui.h
===================================================================
--- trunk/src/VBox/Debugger/VBoxDbgGui.h	(revision 44339)
+++ trunk/src/VBox/Debugger/VBoxDbgGui.h	(revision 44340)
@@ -58,7 +58,8 @@
      *
      * @returns VBox status code.
-     * @param   pVM         The VM handle.
+     * @param   pUVM        The user mode VM handle. The caller's reference will be
+     *                      consumed on success.
      */
-    int init(PVM pVM);
+    int init(PUVM pUVM);
 
     /**
@@ -129,10 +130,10 @@
 
     /**
-     * Gets the VM handle.
-     * @returns The VM handle.
+     * Gets the user mode VM handle.
+     * @returns The UVM handle.
      */
-    PVM getVMHandle() const
+    PUVM getUvmHandle() const
     {
-        return m_pVM;
+        return m_pUVM;
     }
 
@@ -162,4 +163,6 @@
     /** The VM instance. */
     PVM m_pVM;
+    /** The user mode VM handle. */
+    PUVM m_pUVM;
 
     /** The parent widget. */
Index: trunk/src/VBox/Debugger/testcase/tstVBoxDbg.cpp
===================================================================
--- trunk/src/VBox/Debugger/testcase/tstVBoxDbg.cpp	(revision 44339)
+++ trunk/src/VBox/Debugger/testcase/tstVBoxDbg.cpp	(revision 44340)
@@ -46,5 +46,6 @@
      */
     PVM pVM;
-    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, &pVM);
+    PUVM pUVM;
+    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, &pVM, &pUVM);
     if (RT_SUCCESS(rc))
     {
@@ -55,5 +56,5 @@
         PDBGGUI pGui;
         PCDBGGUIVT pGuiVT;
-        rc = DBGGuiCreateForVM(pVM, &pGui, &pGuiVT);
+        rc = DBGGuiCreateForVM(pUVM, &pGui, &pGuiVT);
         if (RT_SUCCESS(rc))
         {
@@ -93,5 +94,5 @@
          * Cleanup.
          */
-        rc = VMR3Destroy(pVM);
+        rc = VMR3Destroy(pUVM);
         if (!RT_SUCCESS(rc))
         {
@@ -99,4 +100,5 @@
             cErrors++;
         }
+        VMR3ReleaseUVM(pUVM);
     }
     else
Index: trunk/src/VBox/Main/idl/VirtualBox.xidl
===================================================================
--- trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 44339)
+++ trunk/src/VBox/Main/idl/VirtualBox.xidl	(revision 44340)
@@ -15424,6 +15424,7 @@
     <attribute name="VM" type="long long" readonly="yes" wsmap="suppress">
       <desc>
-        Gets the VM handle. This is only for internal use while
-        we carve the details of this interface.
+        Gets the user-mode VM handle, with a reference.  Must be passed to
+        VMR3ReleaseUVM when done.  This is only for internal use while we carve
+        the details of this interface.
       </desc>
     </attribute>
Index: trunk/src/VBox/Main/include/ConsoleImpl.h
===================================================================
--- trunk/src/VBox/Main/include/ConsoleImpl.h	(revision 44339)
+++ trunk/src/VBox/Main/include/ConsoleImpl.h	(revision 44340)
@@ -544,5 +544,5 @@
                                bool fForceUnmount,
                                bool fHotplug,
-                               PVM pVM,
+                               PUVM pUVM,
                                DeviceType_T *paLedDevType);
     int configMedium(PCFGMNODE pLunL0,
@@ -560,5 +560,5 @@
                      HRESULT *phrc);
     static DECLCALLBACK(int) reconfigureMediumAttachment(Console *pConsole,
-                                                         PVM pVM,
+                                                         PUVM pUVM,
                                                          const char *pcszDevice,
                                                          unsigned uInstance,
@@ -573,5 +573,5 @@
                                                          HRESULT *phrc);
     static DECLCALLBACK(int) changeRemovableMedium(Console *pThis,
-                                                   PVM pVM,
+                                                   PUVM pUVM,
                                                    const char *pcszDevice,
                                                    unsigned uInstance,
@@ -592,5 +592,5 @@
                       bool fAttachDetach, bool fIgnoreConnectFailure);
 
-    static DECLCALLBACK(int) configGuestProperties(void *pvConsole, PVM pVM);
+    static DECLCALLBACK(int) configGuestProperties(void *pvConsole, PUVM pUVM);
     static DECLCALLBACK(int) configGuestControl(void *pvConsole);
     static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState,
@@ -598,11 +598,11 @@
     static DECLCALLBACK(int) unplugCpu(Console *pThis, PVM pVM, unsigned uCpu);
     static DECLCALLBACK(int) plugCpu(Console *pThis, PVM pVM, unsigned uCpu);
-    HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PVM pVM);
+    HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM);
     HRESULT doCPURemove(ULONG aCpu, PVM pVM);
     HRESULT doCPUAdd(ULONG aCpu, PVM pVM);
 
-    HRESULT doNetworkAdapterChange(PVM pVM, const char *pszDevice, unsigned uInstance,
+    HRESULT doNetworkAdapterChange(PUVM pUVM, const char *pszDevice, unsigned uInstance,
                                    unsigned uLun, INetworkAdapter *aNetworkAdapter);
-    static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, PVM pVM, const char *pszDevice,
+    static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, PUVM pUVM, const char *pszDevice,
                                                      unsigned uInstance, unsigned uLun,
                                                      INetworkAdapter *aNetworkAdapter);
@@ -615,11 +615,11 @@
     HRESULT detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
 
-    static DECLCALLBACK(int) usbAttachCallback(Console *that, PVM pVM, IUSBDevice *aHostDevice, PCRTUUID aUuid,
+    static DECLCALLBACK(int) usbAttachCallback(Console *that, PUVM pUVM, IUSBDevice *aHostDevice, PCRTUUID aUuid,
                        bool aRemote, const char *aAddress, void *pvRemoteBackend, USHORT aPortVersion, ULONG aMaskedIfs);
-    static DECLCALLBACK(int) usbDetachCallback(Console *that, PVM pVM, PCRTUUID aUuid);
+    static DECLCALLBACK(int) usbDetachCallback(Console *that, PUVM pUVM, PCRTUUID aUuid);
 #endif
 
     static DECLCALLBACK(int) attachStorageDevice(Console *pThis,
-                                                 PVM pVM,
+                                                 PUVM pUVM,
                                                  const char *pcszDevice,
                                                  unsigned uInstance,
@@ -628,11 +628,11 @@
                                                  IMediumAttachment *aMediumAtt);
     static DECLCALLBACK(int) detachStorageDevice(Console *pThis,
-                                                 PVM pVM,
+                                                 PUVM pUVM,
                                                  const char *pcszDevice,
                                                  unsigned uInstance,
                                                  StorageBus_T enmBus,
                                                  IMediumAttachment *aMediumAtt);
-    HRESULT doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PVM pVM);
-    HRESULT doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PVM pVM);
+    HRESULT doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM);
+    HRESULT doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM);
 
     static DECLCALLBACK(int)    fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
@@ -648,5 +648,5 @@
                                                           const char *pszErrorId, const char *pszFormat, va_list va);
 
-    HRESULT                     captureUSBDevices(PVM pVM);
+    HRESULT                     captureUSBDevices(PUVM pUVM);
     void                        detachAllUSBDevices(bool aDone);
 
Index: trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-client/ConsoleImpl.cpp	(revision 44339)
+++ trunk/src/VBox/Main/src-client/ConsoleImpl.cpp	(revision 44340)
@@ -157,4 +157,5 @@
           mServerProgress(aServerProgress),
           mpVM(NULL),
+          mpUVM(NULL),
           mRC(E_FAIL),
           mpSafeVMPtr(NULL)
@@ -168,5 +169,8 @@
             mpSafeVMPtr = new Console::SafeVMPtr(aConsole);
             if (mpSafeVMPtr->isOk())
+            {
                 mpVM = mpSafeVMPtr->raw();
+                mpUVM = mpSafeVMPtr->rawUVM();
+            }
             else
                 mRC = mpSafeVMPtr->rc();
@@ -198,4 +202,5 @@
     const ComPtr<IProgress>     mServerProgress;
     PVM                         mpVM;
+    PUVM                        mpUVM;
 
 private:
@@ -2229,5 +2234,5 @@
     alock.release();
 
-    int vrc = VMR3Reset(ptrVM);
+    int vrc = VMR3Reset(ptrVM.rawUVM());
 
     HRESULT rc = RT_SUCCESS(vrc) ? S_OK :
@@ -2255,4 +2260,5 @@
 HRESULT Console::doCPURemove(ULONG aCpu, PVM pVM)
 {
+    PUVM pUVM = VMR3GetUVM(pVM);
     HRESULT rc = S_OK;
 
@@ -2297,5 +2303,5 @@
         /* Notify the guest if possible. */
         uint32_t idCpuCore, idCpuPackage;
-        vrc = VMR3GetCpuCoreAndPackageIdFromCpuId(pVM, aCpu, &idCpuCore, &idCpuPackage); AssertRC(vrc);
+        vrc = VMR3GetCpuCoreAndPackageIdFromCpuId(pUVM, aCpu, &idCpuCore, &idCpuPackage); AssertRC(vrc);
         if (RT_SUCCESS(vrc))
             vrc = pVmmDevPort->pfnCpuHotUnplug(pVmmDevPort, idCpuCore, idCpuPackage);
@@ -2329,7 +2335,7 @@
          */
         PVMREQ pReq;
-        vrc = VMR3ReqCall(pVM, 0, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
-                          (PFNRT)Console::unplugCpu, 3,
-                          this, pVM, aCpu);
+        vrc = VMR3ReqCallU(pUVM, 0, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
+                           (PFNRT)Console::unplugCpu, 3,
+                           this, pVM, aCpu);
         if (vrc == VERR_TIMEOUT || RT_SUCCESS(vrc))
         {
@@ -2344,5 +2350,5 @@
         {
             /* Detach it from the VM  */
-            vrc = VMR3HotUnplugCpu(pVM, aCpu);
+            vrc = VMR3HotUnplugCpu(pUVM, aCpu);
             AssertRC(vrc);
         }
@@ -2362,12 +2368,13 @@
 /*static*/ DECLCALLBACK(int) Console::plugCpu(Console *pThis, PVM pVM, unsigned uCpu)
 {
+    PUVM pUVM = VMR3GetUVM(pVM);
     LogFlowFunc(("pThis=%p uCpu=%u\n", pThis, uCpu));
 
     AssertReturn(pThis, VERR_INVALID_PARAMETER);
 
-    int rc = VMR3HotPlugCpu(pVM, uCpu);
+    int rc = VMR3HotPlugCpu(pUVM, uCpu);
     AssertRC(rc);
 
-    PCFGMNODE pInst = CFGMR3GetChild(CFGMR3GetRoot(pVM), "Devices/acpi/0/");
+    PCFGMNODE pInst = CFGMR3GetChild(CFGMR3GetRootU(pUVM), "Devices/acpi/0/");
     AssertRelease(pInst);
     /* nuke anything which might have been left behind. */
@@ -2399,4 +2406,5 @@
 HRESULT Console::doCPUAdd(ULONG aCpu, PVM pVM)
 {
+    PUVM pUVM = VMR3GetUVM(pVM);
     HRESULT rc = S_OK;
 
@@ -2435,7 +2443,7 @@
      */
     PVMREQ pReq;
-    int vrc = VMR3ReqCall(pVM, 0, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
-                          (PFNRT)Console::plugCpu, 3,
-                          this, pVM, aCpu);
+    int vrc = VMR3ReqCallU(pUVM, 0, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
+                           (PFNRT)Console::plugCpu, 3,
+                           this, pVM, aCpu);
 
     /* release the lock before a VMR3* call (EMT will call us back)! */
@@ -2460,5 +2468,5 @@
         /* Notify the guest if possible. */
         uint32_t idCpuCore, idCpuPackage;
-        vrc = VMR3GetCpuCoreAndPackageIdFromCpuId(pVM, aCpu, &idCpuCore, &idCpuPackage); AssertRC(vrc);
+        vrc = VMR3GetCpuCoreAndPackageIdFromCpuId(pUVM, aCpu, &idCpuCore, &idCpuPackage); AssertRC(vrc);
         if (RT_SUCCESS(vrc))
             vrc = pDevPort->pfnCpuHotPlug(pDevPort, idCpuCore, idCpuPackage);
@@ -2506,5 +2514,5 @@
     alock.release();
 
-    int vrc = VMR3Suspend(ptrVM);
+    int vrc = VMR3Suspend(ptrVM.rawUVM());
 
     HRESULT hrc = S_OK;
@@ -2548,8 +2556,8 @@
     if (RT_SUCCESS(vrc))
     {
-        if (VMR3GetState(ptrVM) == VMSTATE_CREATED)
-            vrc = VMR3PowerOn(ptrVM); /* (PowerUpPaused) */
+        if (VMR3GetStateU(ptrVM.rawUVM()) == VMSTATE_CREATED)
+            vrc = VMR3PowerOn(ptrVM.rawUVM()); /* (PowerUpPaused) */
         else
-            vrc = VMR3Resume(ptrVM);
+            vrc = VMR3Resume(ptrVM.rawUVM());
     }
 
@@ -2785,5 +2793,5 @@
         /* release the lock before a VMR3* call (EMT will call us back)! */
         alock.release();
-        int vrc = VMR3Suspend(ptrVM);
+        int vrc = VMR3Suspend(ptrVM.rawUVM());
         alock.acquire();
 
@@ -2893,5 +2901,5 @@
             {
                 alock.release();
-                VMR3Resume(ptrVM);
+                VMR3Resume(ptrVM.rawUVM());
                 alock.acquire();
             }
@@ -3660,9 +3668,9 @@
  * @param aMediumAttachment The medium attachment with the new medium state.
  * @param fForce            Force medium chance, if it is locked or not.
- * @param pVM               Safe VM handle.
+ * @param pUVM              Safe VM handle.
  *
  * @note Locks this object for writing.
  */
-HRESULT Console::doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PVM pVM)
+HRESULT Console::doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM)
 {
     AutoCaller autoCaller(this);
@@ -3728,19 +3736,19 @@
      */
     PVMREQ pReq;
-    int vrc = VMR3ReqCall(pVM,
-                          VMCPUID_ANY,
-                          &pReq,
-                          0 /* no wait! */,
-                          VMREQFLAGS_VBOX_STATUS,
-                          (PFNRT)Console::changeRemovableMedium,
-                          8,
-                          this,
-                          pVM,
-                          pszDevice,
-                          uInstance,
-                          enmBus,
-                          fUseHostIOCache,
-                          aMediumAttachment,
-                          fForce);
+    int vrc = VMR3ReqCallU(pUVM,
+                           VMCPUID_ANY,
+                           &pReq,
+                           0 /* no wait! */,
+                           VMREQFLAGS_VBOX_STATUS,
+                           (PFNRT)Console::changeRemovableMedium,
+                           8,
+                           this,
+                           pUVM,
+                           pszDevice,
+                           uInstance,
+                           enmBus,
+                           fUseHostIOCache,
+                           aMediumAttachment,
+                           fForce);
 
     /* release the lock before waiting for a result (EMT will call us back!) */
@@ -3778,5 +3786,5 @@
  *
  * @param   pThis           Pointer to the Console object.
- * @param   pVM             The VM handle.
+ * @param   pUVM            The VM handle.
  * @param   pcszDevice      The PDM device name.
  * @param   uInstance       The PDM device instance.
@@ -3793,5 +3801,5 @@
  */
 DECLCALLBACK(int) Console::changeRemovableMedium(Console *pConsole,
-                                                 PVM pVM,
+                                                 PUVM pUVM,
                                                  const char *pcszDevice,
                                                  unsigned uInstance,
@@ -3816,5 +3824,5 @@
      */
     bool fResume;
-    VMSTATE enmVMState = VMR3GetState(pVM);
+    VMSTATE enmVMState = VMR3GetStateU(pUVM);
     switch (enmVMState)
     {
@@ -3825,5 +3833,5 @@
             /* disable the callback to prevent Console-level state change */
             pConsole->mVMStateChangeCallbackDisabled = true;
-            int rc = VMR3Suspend(pVM);
+            int rc = VMR3Suspend(pUVM);
             pConsole->mVMStateChangeCallbackDisabled = false;
             AssertRCReturn(rc, rc);
@@ -3853,5 +3861,5 @@
     /* Determine the base path for the device instance. */
     PCFGMNODE pCtlInst;
-    pCtlInst = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "Devices/%s/%u/", pcszDevice, uInstance);
+    pCtlInst = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "Devices/%s/%u/", pcszDevice, uInstance);
     AssertReturn(pCtlInst, VERR_INTERNAL_ERROR);
 
@@ -3874,5 +3882,5 @@
                                              fForce /* fForceUnmount */,
                                              false  /* fHotplug */,
-                                             pVM,
+                                             pUVM,
                                              NULL /* paLedDevType */);
     /** @todo this dumps everything attached to this device instance, which
@@ -3888,5 +3896,5 @@
         /* disable the callback to prevent Console-level state change */
         pConsole->mVMStateChangeCallbackDisabled = true;
-        rc = VMR3Resume(pVM);
+        rc = VMR3Resume(pUVM);
         pConsole->mVMStateChangeCallbackDisabled = false;
         AssertRC(rc);
@@ -3894,5 +3902,5 @@
         {
             /* too bad, we failed. try to sync the console state with the VMM state */
-            vmstateChangeCallback(pVM, VMSTATE_SUSPENDED, enmVMState, pConsole);
+            vmstateChangeCallback(VMR3GetVM(pUVM), VMSTATE_SUSPENDED, enmVMState, pConsole);
         }
         /// @todo (r=dmik) if we failed with drive mount, then the VMR3Resume
@@ -3914,9 +3922,9 @@
  *
  * @param aMediumAttachment The medium attachment which is added.
- * @param pVM               Safe VM handle.
+ * @param pUVM              Safe VM handle.
  *
  * @note Locks this object for writing.
  */
-HRESULT Console::doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PVM pVM)
+HRESULT Console::doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM)
 {
     AutoCaller autoCaller(this);
@@ -3982,18 +3990,18 @@
      */
     PVMREQ pReq;
-    int vrc = VMR3ReqCall(pVM,
-                          VMCPUID_ANY,
-                          &pReq,
-                          0 /* no wait! */,
-                          VMREQFLAGS_VBOX_STATUS,
-                          (PFNRT)Console::attachStorageDevice,
-                          7,
-                          this,
-                          pVM,
-                          pszDevice,
-                          uInstance,
-                          enmBus,
-                          fUseHostIOCache,
-                          aMediumAttachment);
+    int vrc = VMR3ReqCallU(pUVM,
+                           VMCPUID_ANY,
+                           &pReq,
+                           0 /* no wait! */,
+                           VMREQFLAGS_VBOX_STATUS,
+                           (PFNRT)Console::attachStorageDevice,
+                           7,
+                           this,
+                           pUVM,
+                           pszDevice,
+                           uInstance,
+                           enmBus,
+                           fUseHostIOCache,
+                           aMediumAttachment);
 
     /* release the lock before waiting for a result (EMT will call us back!) */
@@ -4032,5 +4040,5 @@
  *
  * @param   pThis           Pointer to the Console object.
- * @param   pVM             The VM handle.
+ * @param   pUVM            The VM handle.
  * @param   pcszDevice      The PDM device name.
  * @param   uInstance       The PDM device instance.
@@ -4039,5 +4047,5 @@
  */
 DECLCALLBACK(int) Console::attachStorageDevice(Console *pConsole,
-                                               PVM pVM,
+                                               PUVM pUVM,
                                                const char *pcszDevice,
                                                unsigned uInstance,
@@ -4061,5 +4069,5 @@
      */
     bool fResume;
-    VMSTATE enmVMState = VMR3GetState(pVM);
+    VMSTATE enmVMState = VMR3GetStateU(pUVM);
     switch (enmVMState)
     {
@@ -4070,5 +4078,5 @@
             /* disable the callback to prevent Console-level state change */
             pConsole->mVMStateChangeCallbackDisabled = true;
-            int rc = VMR3Suspend(pVM);
+            int rc = VMR3Suspend(pUVM);
             pConsole->mVMStateChangeCallbackDisabled = false;
             AssertRCReturn(rc, rc);
@@ -4098,5 +4106,5 @@
     /* Determine the base path for the device instance. */
     PCFGMNODE pCtlInst;
-    pCtlInst = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "Devices/%s/%u/", pcszDevice, uInstance);
+    pCtlInst = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "Devices/%s/%u/", pcszDevice, uInstance);
     AssertReturn(pCtlInst, VERR_INTERNAL_ERROR);
 
@@ -4119,5 +4127,5 @@
                                              false /* fForceUnmount */,
                                              true   /* fHotplug */,
-                                             pVM,
+                                             pUVM,
                                              NULL /* paLedDevType */);
     /** @todo this dumps everything attached to this device instance, which
@@ -4133,5 +4141,5 @@
         /* disable the callback to prevent Console-level state change */
         pConsole->mVMStateChangeCallbackDisabled = true;
-        rc = VMR3Resume(pVM);
+        rc = VMR3Resume(pUVM);
         pConsole->mVMStateChangeCallbackDisabled = false;
         AssertRC(rc);
@@ -4139,5 +4147,5 @@
         {
             /* too bad, we failed. try to sync the console state with the VMM state */
-            vmstateChangeCallback(pVM, VMSTATE_SUSPENDED, enmVMState, pConsole);
+            vmstateChangeCallback(VMR3GetVM(pUVM), VMSTATE_SUSPENDED, enmVMState, pConsole);
         }
         /** @todo: if we failed with drive mount, then the VMR3Resume
@@ -4159,9 +4167,9 @@
  *
  * @param aMediumAttachment The medium attachment which is added.
- * @param pVM               Safe VM handle.
+ * @param pUVM              Safe VM handle.
  *
  * @note Locks this object for writing.
  */
-HRESULT Console::doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PVM pVM)
+HRESULT Console::doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM)
 {
     AutoCaller autoCaller(this);
@@ -4224,17 +4232,17 @@
      */
     PVMREQ pReq;
-    int vrc = VMR3ReqCall(pVM,
-                          VMCPUID_ANY,
-                          &pReq,
-                          0 /* no wait! */,
-                          VMREQFLAGS_VBOX_STATUS,
-                          (PFNRT)Console::detachStorageDevice,
-                          6,
-                          this,
-                          pVM,
-                          pszDevice,
-                          uInstance,
-                          enmBus,
-                          aMediumAttachment);
+    int vrc = VMR3ReqCallU(pUVM,
+                           VMCPUID_ANY,
+                           &pReq,
+                           0 /* no wait! */,
+                           VMREQFLAGS_VBOX_STATUS,
+                           (PFNRT)Console::detachStorageDevice,
+                           6,
+                           this,
+                           pUVM,
+                           pszDevice,
+                           uInstance,
+                           enmBus,
+                           aMediumAttachment);
 
     /* release the lock before waiting for a result (EMT will call us back!) */
@@ -4272,5 +4280,5 @@
  *
  * @param   pThis           Pointer to the Console object.
- * @param   pVM             The VM handle.
+ * @param   pUVM            The VM handle.
  * @param   pcszDevice      The PDM device name.
  * @param   uInstance       The PDM device instance.
@@ -4279,5 +4287,5 @@
  */
 DECLCALLBACK(int) Console::detachStorageDevice(Console *pConsole,
-                                               PVM pVM,
+                                               PUVM pUVM,
                                                const char *pcszDevice,
                                                unsigned uInstance,
@@ -4300,5 +4308,5 @@
      */
     bool fResume;
-    VMSTATE enmVMState = VMR3GetState(pVM);
+    VMSTATE enmVMState = VMR3GetStateU(pUVM);
     switch (enmVMState)
     {
@@ -4309,5 +4317,5 @@
             /* disable the callback to prevent Console-level state change */
             pConsole->mVMStateChangeCallbackDisabled = true;
-            int rc = VMR3Suspend(pVM);
+            int rc = VMR3Suspend(pUVM);
             pConsole->mVMStateChangeCallbackDisabled = false;
             AssertRCReturn(rc, rc);
@@ -4337,5 +4345,5 @@
     /* Determine the base path for the device instance. */
     PCFGMNODE pCtlInst;
-    pCtlInst = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "Devices/%s/%u/", pcszDevice, uInstance);
+    pCtlInst = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "Devices/%s/%u/", pcszDevice, uInstance);
     AssertReturn(pCtlInst, VERR_INTERNAL_ERROR);
 
@@ -4363,5 +4371,5 @@
     if (pLunL0)
     {
-        rc = PDMR3DeviceDetach(pVM, pcszDevice, uInstance, uLUN, 0);
+        rc = PDMR3DeviceDetach(VMR3GetVM(pUVM), pcszDevice, uInstance, uLUN, 0);
         if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
             rc = VINF_SUCCESS;
@@ -4386,5 +4394,5 @@
         /* disable the callback to prevent Console-level state change */
         pConsole->mVMStateChangeCallbackDisabled = true;
-        rc = VMR3Resume(pVM);
+        rc = VMR3Resume(pUVM);
         pConsole->mVMStateChangeCallbackDisabled = false;
         AssertRC(rc);
@@ -4392,5 +4400,5 @@
         {
             /* too bad, we failed. try to sync the console state with the VMM state */
-            vmstateChangeCallback(pVM, VMSTATE_SUSPENDED, enmVMState, pConsole);
+            vmstateChangeCallback(VMR3GetVM(pUVM), VMSTATE_SUSPENDED, enmVMState, pConsole);
         }
         /** @todo: if we failed with drive mount, then the VMR3Resume
@@ -4474,5 +4482,5 @@
                     if (RT_SUCCESS(vrc) && changeAdapter)
                     {
-                        VMSTATE enmVMState = VMR3GetState(ptrVM);
+                        VMSTATE enmVMState = VMR3GetStateU(ptrVM.rawUVM());
                         if (    enmVMState == VMSTATE_RUNNING    /** @todo LiveMigration: Forbid or deal correctly with the _LS variants */
                             ||  enmVMState == VMSTATE_SUSPENDED)
@@ -4484,5 +4492,5 @@
                             }
 
-                            rc = doNetworkAdapterChange(ptrVM, pszAdapterName, ulInstance, 0, aNetworkAdapter);
+                            rc = doNetworkAdapterChange(ptrVM.rawUVM(), pszAdapterName, ulInstance, 0, aNetworkAdapter);
 
                             if (fTraceEnabled && fCableConnected && pINetCfg)
@@ -4615,5 +4623,5 @@
  * @returns COM status code.
  *
- * @parma   pVM                 The VM handle (caller hold this safely).
+ * @parma   pUVM                The VM handle (caller hold this safely).
  * @param   pszDevice           The PDM device name.
  * @param   uInstance           The PDM device instance.
@@ -4621,5 +4629,5 @@
  * @param   aNetworkAdapter     The network adapter whose attachment needs to be changed
  */
-HRESULT Console::doNetworkAdapterChange(PVM pVM,
+HRESULT Console::doNetworkAdapterChange(PUVM pUVM,
                                         const char *pszDevice,
                                         unsigned uInstance,
@@ -4632,9 +4640,4 @@
     AutoCaller autoCaller(this);
     AssertComRCReturnRC(autoCaller.rc());
-
-    /* Get the VM handle. */
-    SafeVMPtr ptrVM(this);
-    if (!ptrVM.isOk())
-        return ptrVM.rc();
 
     /*
@@ -4644,7 +4647,7 @@
      */
     PVMREQ pReq;
-    int vrc = VMR3ReqCall(pVM, 0 /*idDstCpu*/, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
-                          (PFNRT) Console::changeNetworkAttachment, 6,
-                          this, ptrVM.raw(), pszDevice, uInstance, uLun, aNetworkAdapter);
+    int vrc = VMR3ReqCallU(pUVM, 0 /*idDstCpu*/, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,
+                           (PFNRT)Console::changeNetworkAttachment, 6,
+                           this, pUVM, pszDevice, uInstance, uLun, aNetworkAdapter);
 
     if (vrc == VERR_TIMEOUT || RT_SUCCESS(vrc))
@@ -4675,5 +4678,5 @@
  *
  * @param   pThis               Pointer to the Console object.
- * @param   pVM                 The VM handle.
+ * @param   pUVM                The VM handle.
  * @param   pszDevice           The PDM device name.
  * @param   uInstance           The PDM device instance.
@@ -4685,5 +4688,5 @@
  */
 DECLCALLBACK(int) Console::changeNetworkAttachment(Console *pThis,
-                                                   PVM pVM,
+                                                   PUVM pUVM,
                                                    const char *pszDevice,
                                                    unsigned uInstance,
@@ -4724,5 +4727,5 @@
      */
     bool fResume;
-    VMSTATE enmVMState = VMR3GetState(pVM);
+    VMSTATE enmVMState = VMR3GetStateU(pUVM);
     switch (enmVMState)
     {
@@ -4733,5 +4736,5 @@
             /* disable the callback to prevent Console-level state change */
             pThis->mVMStateChangeCallbackDisabled = true;
-            int rc = VMR3Suspend(pVM);
+            int rc = VMR3Suspend(pUVM);
             pThis->mVMStateChangeCallbackDisabled = false;
             AssertRCReturn(rc, rc);
@@ -4755,5 +4758,5 @@
     PCFGMNODE pCfg = NULL;          /* /Devices/Dev/.../Config/ */
     PCFGMNODE pLunL0 = NULL;        /* /Devices/Dev/0/LUN#0/ */
-    PCFGMNODE pInst = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "Devices/%s/%d/", pszDevice, uInstance);
+    PCFGMNODE pInst = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "Devices/%s/%d/", pszDevice, uInstance);
     AssertRelease(pInst);
 
@@ -4769,5 +4772,5 @@
         /* disable the callback to prevent Console-level state change */
         pThis->mVMStateChangeCallbackDisabled = true;
-        rc = VMR3Resume(pVM);
+        rc = VMR3Resume(pUVM);
         pThis->mVMStateChangeCallbackDisabled = false;
         AssertRC(rc);
@@ -4775,5 +4778,5 @@
         {
             /* too bad, we failed. try to sync the console state with the VMM state */
-            vmstateChangeCallback(pVM, VMSTATE_SUSPENDED, enmVMState, pThis);
+            vmstateChangeCallback(VMR3GetVM(pUVM), VMSTATE_SUSPENDED, enmVMState, pThis);
         }
         /// @todo (r=dmik) if we failed with drive mount, then the VMR3Resume
@@ -4855,5 +4858,5 @@
     if (ptrVM.isOk())
     {
-        rc = doMediumChange(aMediumAttachment, !!aForce, ptrVM);
+        rc = doMediumChange(aMediumAttachment, !!aForce, ptrVM.rawUVM());
         ptrVM.release();
     }
@@ -4926,5 +4929,5 @@
         {
             /* No need to call in the EMT thread. */
-            rc = VMR3SetCpuExecutionCap(ptrVM, aExecutionCap);
+            rc = VMR3SetCpuExecutionCap(ptrVM.rawUVM(), aExecutionCap);
         }
         else
@@ -5389,7 +5392,7 @@
     {
         if (aRemove)
-            rc = doStorageDeviceDetach(aMediumAttachment, ptrVM);
+            rc = doStorageDeviceDetach(aMediumAttachment, ptrVM.rawUVM());
         else
-            rc = doStorageDeviceAttach(aMediumAttachment, ptrVM);
+            rc = doStorageDeviceAttach(aMediumAttachment, ptrVM.rawUVM());
         ptrVM.release();
     }
@@ -5712,5 +5715,5 @@
 
     /* Pause the VM, as it might have pending IO on this drive */
-    VMSTATE enmVMState = VMR3GetState(ptrVM);
+    VMSTATE enmVMState = VMR3GetStateU(ptrVM.rawUVM());
     if (mMachineState == MachineState_DeletingSnapshotOnline)
     {
@@ -5718,26 +5721,26 @@
         /* disable the callback to prevent Console-level state change */
         mVMStateChangeCallbackDisabled = true;
-        int vrc2 = VMR3Suspend(ptrVM);
+        int vrc2 = VMR3Suspend(ptrVM.rawUVM());
         mVMStateChangeCallbackDisabled = false;
         AssertRCReturn(vrc2, E_FAIL);
     }
 
-    vrc = VMR3ReqCallWait(ptrVM,
-                          VMCPUID_ANY,
-                          (PFNRT)reconfigureMediumAttachment,
-                          13,
-                          this,
-                          ptrVM.raw(),
-                          pcszDevice,
-                          uInstance,
-                          enmBus,
-                          fUseHostIOCache,
-                          fBuiltinIOCache,
-                          true /* fSetupMerge */,
-                          aSourceIdx,
-                          aTargetIdx,
-                          aMediumAttachment,
-                          mMachineState,
-                          &rc);
+    vrc = VMR3ReqCallWaitU(ptrVM.rawUVM(),
+                           VMCPUID_ANY,
+                           (PFNRT)reconfigureMediumAttachment,
+                           13,
+                           this,
+                           ptrVM.rawUVM(),
+                           pcszDevice,
+                           uInstance,
+                           enmBus,
+                           fUseHostIOCache,
+                           fBuiltinIOCache,
+                           true /* fSetupMerge */,
+                           aSourceIdx,
+                           aTargetIdx,
+                           aMediumAttachment,
+                           mMachineState,
+                           &rc);
     /* error handling is after resuming the VM */
 
@@ -5747,5 +5750,5 @@
         /* disable the callback to prevent Console-level state change */
         mVMStateChangeCallbackDisabled = true;
-        int vrc2 = VMR3Resume(ptrVM);
+        int vrc2 = VMR3Resume(ptrVM.rawUVM());
         mVMStateChangeCallbackDisabled = false;
         if (RT_FAILURE(vrc2))
@@ -5783,5 +5786,5 @@
 
     /* Pause the VM, as it might have pending IO on this drive */
-    enmVMState = VMR3GetState(ptrVM);
+    enmVMState = VMR3GetStateU(ptrVM.rawUVM());
     if (mMachineState == MachineState_DeletingSnapshotOnline)
     {
@@ -5789,5 +5792,5 @@
         /* disable the callback to prevent Console-level state change */
         mVMStateChangeCallbackDisabled = true;
-        int vrc2 = VMR3Suspend(ptrVM);
+        int vrc2 = VMR3Suspend(ptrVM.rawUVM());
         mVMStateChangeCallbackDisabled = false;
         AssertRCReturn(vrc2, E_FAIL);
@@ -5799,21 +5802,21 @@
                                            ComSafeArrayInArg(aChildrenToReparent));
 
-    vrc = VMR3ReqCallWait(ptrVM,
-                          VMCPUID_ANY,
-                          (PFNRT)reconfigureMediumAttachment,
-                          13,
-                          this,
-                          ptrVM.raw(),
-                          pcszDevice,
-                          uInstance,
-                          enmBus,
-                          fUseHostIOCache,
-                          fBuiltinIOCache,
-                          false /* fSetupMerge */,
-                          0 /* uMergeSource */,
-                          0 /* uMergeTarget */,
-                          aMediumAttachment,
-                          mMachineState,
-                          &rc);
+    vrc = VMR3ReqCallWaitU(ptrVM.rawUVM(),
+                           VMCPUID_ANY,
+                           (PFNRT)reconfigureMediumAttachment,
+                           13,
+                           this,
+                           ptrVM.rawUVM(),
+                           pcszDevice,
+                           uInstance,
+                           enmBus,
+                           fUseHostIOCache,
+                           fBuiltinIOCache,
+                           false /* fSetupMerge */,
+                           0 /* uMergeSource */,
+                           0 /* uMergeTarget */,
+                           aMediumAttachment,
+                           mMachineState,
+                           &rc);
     /* error handling is after resuming the VM */
 
@@ -5823,5 +5826,5 @@
         /* disable the callback to prevent Console-level state change */
         mVMStateChangeCallbackDisabled = true;
-        int vrc2 = VMR3Resume(ptrVM);
+        int vrc2 = VMR3Resume(ptrVM.rawUVM());
         mVMStateChangeCallbackDisabled = false;
         AssertRC(vrc2);
@@ -6198,5 +6201,5 @@
         return a_Quiet
             ? E_ACCESSDENIED
-            : setError(E_ACCESSDENIED, tr("The virtual machine is was powered off"));
+            : setError(E_ACCESSDENIED, tr("The virtual machine is powered off"));
 
     /*
@@ -6207,5 +6210,5 @@
         return a_Quiet
             ? E_ACCESSDENIED
-            : setError(E_ACCESSDENIED, tr("The virtual machine is was powered off"));
+            : setError(E_ACCESSDENIED, tr("The virtual machine is powered off"));
 
     PVM pVM = VMR3GetVM(pUVM);
@@ -6215,5 +6218,5 @@
         return a_Quiet
             ? E_ACCESSDENIED
-            : setError(E_ACCESSDENIED, tr("The virtual machine is was powered off"));
+            : setError(E_ACCESSDENIED, tr("The virtual machine is powered off"));
     }
 
@@ -6936,5 +6939,5 @@
         LogFlowThisFunc(("Powering off the VM...\n"));
         alock.release();
-        vrc = VMR3PowerOff(VMR3GetVM(pUVM));
+        vrc = VMR3PowerOff(pUVM);
 #ifdef VBOX_WITH_EXTPACK
         mptrExtPackManager->callAllVmPowerOffHooks(this, VMR3GetVM(pUVM));
@@ -7004,5 +7007,5 @@
         alock.release();
 
-        vrc = VMR3Destroy(VMR3GetVM(pUVM));
+        vrc = VMR3Destroy(pUVM);
 
         /* take the lock again */
@@ -7958,7 +7961,8 @@
     Assert(portVersion == 1 || portVersion == 2);
 
-    int vrc = VMR3ReqCallWait(ptrVM, 0 /* idDstCpu (saved state, see #6232) */,
-                              (PFNRT)usbAttachCallback, 9,
-                              this, ptrVM.raw(), aHostDevice, uuid.raw(), fRemote, Address.c_str(), pvRemoteBackend, portVersion, aMaskedIfs);
+    int vrc = VMR3ReqCallWaitU(ptrVM.rawUVM(), 0 /* idDstCpu (saved state, see #6232) */,
+                               (PFNRT)usbAttachCallback, 9,
+                               this, ptrVM.rawUVM(), aHostDevice, uuid.raw(), fRemote,
+                               Address.c_str(), pvRemoteBackend, portVersion, aMaskedIfs);
 
     if (RT_SUCCESS(vrc))
@@ -7986,15 +7990,11 @@
         {
             case VERR_VUSB_NO_PORTS:
-                hrc = setError(E_FAIL,
-                    tr("Failed to attach the USB device. (No available ports on the USB controller)."));
+                hrc = setError(E_FAIL, tr("Failed to attach the USB device. (No available ports on the USB controller)."));
                 break;
             case VERR_VUSB_USBFS_PERMISSION:
-                hrc = setError(E_FAIL,
-                    tr("Not permitted to open the USB device, check usbfs options"));
+                hrc = setError(E_FAIL, tr("Not permitted to open the USB device, check usbfs options"));
                 break;
             default:
-                hrc = setError(E_FAIL,
-                    tr("Failed to create a proxy device for the USB device. (Error: %Rrc)"),
-                    vrc);
+                hrc = setError(E_FAIL, tr("Failed to create a proxy device for the USB device. (Error: %Rrc)"), vrc);
                 break;
         }
@@ -8015,5 +8015,6 @@
 //static
 DECLCALLBACK(int)
-Console::usbAttachCallback(Console *that, PVM pVM, IUSBDevice *aHostDevice, PCRTUUID aUuid, bool aRemote, const char *aAddress, void *pvRemoteBackend, USHORT aPortVersion, ULONG aMaskedIfs)
+Console::usbAttachCallback(Console *that, PUVM pUVM, IUSBDevice *aHostDevice, PCRTUUID aUuid, bool aRemote,
+                           const char *aAddress, void *pvRemoteBackend, USHORT aPortVersion, ULONG aMaskedIfs)
 {
     LogFlowFuncEnter();
@@ -8023,5 +8024,5 @@
     AssertReturn(!that->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE);
 
-    int vrc = PDMR3USBCreateProxyDevice(pVM, aUuid, aRemote, aAddress, pvRemoteBackend,
+    int vrc = PDMR3USBCreateProxyDevice(VMR3GetVM(pUVM), aUuid, aRemote, aAddress, pvRemoteBackend,
                                         aPortVersion == 1 ? VUSB_STDVER_11 : VUSB_STDVER_20, aMaskedIfs);
     LogFlowFunc(("vrc=%Rrc\n", vrc));
@@ -8073,7 +8074,7 @@
 
     alock.release();
-    int vrc = VMR3ReqCallWait(ptrVM, 0 /* idDstCpu (saved state, see #6232) */,
-                              (PFNRT)usbDetachCallback, 5,
-                              this, ptrVM.raw(), pUuid);
+    int vrc = VMR3ReqCallWaitU(ptrVM.rawUVM(), 0 /* idDstCpu (saved state, see #6232) */,
+                               (PFNRT)usbDetachCallback, 5,
+                               this, ptrVM.rawUVM(), pUuid);
     if (RT_SUCCESS(vrc))
     {
@@ -8091,4 +8092,5 @@
 /**
  * USB device detach callback used by DetachUSBDevice().
+ *
  * Note that DetachUSBDevice() doesn't return until this callback is executed,
  * so we don't use AutoCaller and don't care about reference counters of
@@ -8099,5 +8101,5 @@
 //static
 DECLCALLBACK(int)
-Console::usbDetachCallback(Console *that, PVM pVM, PCRTUUID aUuid)
+Console::usbDetachCallback(Console *that, PUVM pUVM, PCRTUUID aUuid)
 {
     LogFlowFuncEnter();
@@ -8107,5 +8109,5 @@
     AssertReturn(!that->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE);
 
-    int vrc = PDMR3USBDetachDevice(pVM, aUuid);
+    int vrc = PDMR3USBDetachDevice(VMR3GetVM(pUVM), aUuid);
 
     LogFlowFunc(("vrc=%Rrc\n", vrc));
@@ -8493,7 +8495,7 @@
  * Called at VM startup.
  *
- * @param   pVM     The VM handle.
+ * @param   pUVM    The VM handle.
  */
-HRESULT Console::captureUSBDevices(PVM pVM)
+HRESULT Console::captureUSBDevices(PUVM pUVM)
 {
     LogFlowThisFunc(("\n"));
@@ -8506,5 +8508,5 @@
      * capture devices */
     PPDMIBASE pBase;
-    int vrc = PDMR3QueryLun(pVM, "usb-ohci", 0, 0, &pBase);
+    int vrc = PDMR3QueryLun(VMR3GetVM(pUVM), "usb-ohci", 0, 0, &pBase);
     if (RT_SUCCESS(vrc))
     {
@@ -8871,12 +8873,11 @@
         /*
          * Create the VM
-         */
-        PVM pVM;
-        /*
-         * release the lock since EMT will call Console. It's safe because
-         * mMachineState is either Starting or Restoring state here.
+         *
+         * Note! Release the lock since EMT will call Console. It's safe because
+         *       mMachineState is either Starting or Restoring state here.
          */
         alock.release();
 
+        PVM pVM;
         vrc = VMR3Create(cCpus,
                          pConsole->mpVmm2UserMethods,
@@ -8885,5 +8886,5 @@
                          task->mConfigConstructor,
                          static_cast<Console *>(pConsole),
-                         &pVM);
+                         &pVM, NULL);
 
         alock.acquire();
@@ -8955,6 +8956,7 @@
                  * Capture USB devices.
                  */
-                rc = pConsole->captureUSBDevices(pVM);
-                if (FAILED(rc)) break;
+                rc = pConsole->captureUSBDevices(pConsole->mpUVM);
+                if (FAILED(rc))
+                    break;
 
                 /* Load saved state? */
@@ -8964,5 +8966,5 @@
                                  task->mSavedStateFile.c_str()));
 
-                    vrc = VMR3LoadFromFile(pVM,
+                    vrc = VMR3LoadFromFile(pConsole->mpUVM,
                                            task->mSavedStateFile.c_str(),
                                            Console::stateProgressCallback,
@@ -8981,5 +8983,5 @@
 #endif
                             if (RT_SUCCESS(vrc))
-                                vrc = VMR3Resume(pVM);
+                                vrc = VMR3Resume(pConsole->mpUVM);
                             AssertLogRelRC(vrc);
                         }
@@ -8989,5 +8991,5 @@
                     if (RT_FAILURE(vrc))
                     {
-                        int vrc2 = VMR3PowerOff(pVM); AssertLogRelRC(vrc2);
+                        int vrc2 = VMR3PowerOff(pConsole->mpUVM); AssertLogRelRC(vrc2);
 #ifdef VBOX_WITH_EXTPACK
                         pConsole->mptrExtPackManager->callAllVmPowerOffHooks(pConsole, pVM);
@@ -8999,10 +9001,10 @@
                     /* -> ConsoleImplTeleporter.cpp */
                     bool fPowerOffOnFailure;
-                    rc = pConsole->teleporterTrg(VMR3GetUVM(pVM), pMachine, &task->mErrorMsg, task->mStartPaused,
+                    rc = pConsole->teleporterTrg(pConsole->mpUVM, pMachine, &task->mErrorMsg, task->mStartPaused,
                                                  task->mProgress, &fPowerOffOnFailure);
                     if (FAILED(rc) && fPowerOffOnFailure)
                     {
                         ErrorInfoKeeper eik;
-                        int vrc2 = VMR3PowerOff(pVM); AssertLogRelRC(vrc2);
+                        int vrc2 = VMR3PowerOff(pConsole->mpUVM); AssertLogRelRC(vrc2);
 #ifdef VBOX_WITH_EXTPACK
                         pConsole->mptrExtPackManager->callAllVmPowerOffHooks(pConsole, pVM);
@@ -9065,5 +9067,5 @@
 #endif
                     if (RT_SUCCESS(vrc))
-                        vrc = VMR3PowerOn(pVM);
+                        vrc = VMR3PowerOn(pConsole->mpUVM);
                     AssertLogRelRC(vrc);
                 }
@@ -9095,5 +9097,5 @@
                  */
                 alock.release();
-                VMR3AtErrorDeregister(pVM, Console::genericVMSetErrorCallback, &task->mErrorMsg);
+                VMR3AtErrorDeregister(pConsole->mpUVM, Console::genericVMSetErrorCallback, &task->mErrorMsg);
                 /** @todo register another VMSetError callback? */
                 alock.acquire();
@@ -9196,5 +9198,5 @@
  *
  * @param   pConsole      Reference to the console object.
- * @param   pVM           The VM handle.
+ * @param   pUVM          The VM handle.
  * @param   lInstance     The instance of the controller.
  * @param   pcszDevice    The name of the controller type.
@@ -9210,5 +9212,5 @@
 /* static */
 DECLCALLBACK(int) Console::reconfigureMediumAttachment(Console *pConsole,
-                                                       PVM pVM,
+                                                       PUVM pUVM,
                                                        const char *pcszDevice,
                                                        unsigned uInstance,
@@ -9223,5 +9225,5 @@
                                                        HRESULT *phrc)
 {
-    LogFlowFunc(("pVM=%p aMediumAtt=%p phrc=%p\n", pVM, aMediumAtt, phrc));
+    LogFlowFunc(("pUVM=%p aMediumAtt=%p phrc=%p\n", pUVM, aMediumAtt, phrc));
 
     int             rc;
@@ -9241,5 +9243,5 @@
     /* Determine the base path for the device instance. */
     PCFGMNODE pCtlInst;
-    pCtlInst = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "Devices/%s/%u/", pcszDevice, uInstance);
+    pCtlInst = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "Devices/%s/%u/", pcszDevice, uInstance);
     AssertReturn(pCtlInst, VERR_INTERNAL_ERROR);
 
@@ -9260,5 +9262,5 @@
                                           false /* fForceUnmount */,
                                           false /* fHotplug */,
-                                          pVM,
+                                          pUVM,
                                           NULL /* paLedDevType */);
     /** @todo this dumps everything attached to this device instance, which
@@ -9368,5 +9370,5 @@
                 alock.release();
                 LogFlowFunc(("VMR3Save...\n"));
-                vrc = VMR3Save(ptrVM,
+                vrc = VMR3Save(ptrVM.rawUVM(),
                                strSavedStateFile.c_str(),
                                true /*fContinueAfterwards*/,
@@ -9449,21 +9451,21 @@
                  * isn't going to need the Console lock.
                  */
-                vrc = VMR3ReqCallWait(ptrVM,
-                                      VMCPUID_ANY,
-                                      (PFNRT)reconfigureMediumAttachment,
-                                      13,
-                                      that,
-                                      ptrVM.raw(),
-                                      pcszDevice,
-                                      lInstance,
-                                      enmBus,
-                                      fUseHostIOCache,
-                                      fBuiltinIOCache,
-                                      false /* fSetupMerge */,
-                                      0 /* uMergeSource */,
-                                      0 /* uMergeTarget */,
-                                      atts[i],
-                                      that->mMachineState,
-                                      &rc);
+                vrc = VMR3ReqCallWaitU(ptrVM.rawUVM(),
+                                       VMCPUID_ANY,
+                                       (PFNRT)reconfigureMediumAttachment,
+                                       13,
+                                       that,
+                                       ptrVM.rawUVM(),
+                                       pcszDevice,
+                                       lInstance,
+                                       enmBus,
+                                       fUseHostIOCache,
+                                       fBuiltinIOCache,
+                                       false /* fSetupMerge */,
+                                       0 /* uMergeSource */,
+                                       0 /* uMergeTarget */,
+                                       atts[i],
+                                       that->mMachineState,
+                                       &rc);
                 if (RT_FAILURE(vrc))
                     throw setErrorStatic(E_FAIL, Console::tr("%Rrc"), vrc);
@@ -9522,5 +9524,5 @@
                 SafeVMPtr ptrVM(that);
                 alock.release();
-                int vrc = VMR3Resume(ptrVM);
+                int vrc = VMR3Resume(ptrVM.rawUVM());
                 alock.acquire();
                 if (RT_FAILURE(vrc))
@@ -9580,5 +9582,5 @@
                         SafeVMPtr ptrVM(that);
                         alock.release();
-                        int vrc = VMR3Resume(ptrVM); AssertLogRelRC(vrc);
+                        int vrc = VMR3Resume(ptrVM.rawUVM()); AssertLogRelRC(vrc);
                         alock.acquire();
                         if (RT_FAILURE(vrc))
@@ -9640,5 +9642,5 @@
 
     bool fSuspenededBySave;
-    int vrc = VMR3Save(task->mpVM,
+    int vrc = VMR3Save(task->mpUVM,
                        task->mSavedStateFile.c_str(),
                        false, /*fContinueAfterwards*/
Index: trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp
===================================================================
--- trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp	(revision 44339)
+++ trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp	(revision 44340)
@@ -707,7 +707,6 @@
 int Console::configConstructorInner(PVM pVM, AutoWriteLock *pAlock)
 {
-    VMMDev *pVMMDev = m_pVMMDev;
-    Assert(pVMMDev);
-
+    PUVM            pUVM      = VMR3GetUVM(pVM);
+    VMMDev         *pVMMDev   = m_pVMMDev; Assert(pVMMDev);
     ComPtr<IMachine> pMachine = machine();
 
@@ -1795,5 +1794,5 @@
                                             false /* fForceUnmount */,
                                             false /* fHotplug */,
-                                            pVM,
+                                            pUVM,
                                             paLedDevType);
                 if (RT_FAILURE(rc))
@@ -2659,5 +2658,5 @@
          */
 
-        rc = configGuestProperties(this, pVM);
+        rc = configGuestProperties(this, pUVM);
 #endif /* VBOX_WITH_GUEST_PROPS defined */
 
@@ -2835,5 +2834,5 @@
      * Register VM state change handler.
      */
-    int rc2 = VMR3AtStateRegister(pVM, Console::vmstateChangeCallback, this);
+    int rc2 = VMR3AtStateRegister(pUVM, Console::vmstateChangeCallback, this);
     AssertRC(rc2);
     if (RT_SUCCESS(rc))
@@ -2843,5 +2842,5 @@
      * Register VM runtime error handler.
      */
-    rc2 = VMR3AtRuntimeErrorRegister(pVM, Console::setVMRuntimeErrorCallback, this);
+    rc2 = VMR3AtRuntimeErrorRegister(pUVM, Console::setVMRuntimeErrorCallback, this);
     AssertRC(rc2);
     if (RT_SUCCESS(rc))
@@ -3120,5 +3119,5 @@
                                     bool fForceUnmount,
                                     bool fHotplug,
-                                    PVM pVM,
+                                    PUVM pUVM,
                                     DeviceType_T *paLedDevType)
 {
@@ -3158,5 +3157,5 @@
                     /* Unmount existing media only for floppy and DVD drives. */
                     PPDMIBASE pBase;
-                    rc = PDMR3QueryLun(pVM, pcszDevice, uInstance, uLUN, &pBase);
+                    rc = PDMR3QueryLun(VMR3GetVM(pUVM), pcszDevice, uInstance, uLUN, &pBase);
                     if (RT_FAILURE(rc))
                     {
@@ -3180,5 +3179,5 @@
                 }
 
-                rc = PDMR3DeviceDetach(pVM, pcszDevice, uInstance, uLUN, fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG);
+                rc = PDMR3DeviceDetach(VMR3GetVM(pUVM), pcszDevice, uInstance, uLUN, fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG);
                 if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
                     rc = VINF_SUCCESS;
@@ -3284,5 +3283,5 @@
                     const char *pszUnit;
                     uint64_t u64Print = formatDiskSize((uint64_t)i64Size, &pszUnit);
-                    setVMRuntimeErrorCallbackF(pVM, this, 0,
+                    setVMRuntimeErrorCallbackF(VMR3GetVM(pUVM), this, 0,
                             "FatPartitionDetected",
                             N_("The medium '%ls' has a logical size of %RU64%s "
@@ -3316,5 +3315,5 @@
                             uint64_t u64PrintSiz = formatDiskSize((LONG64)i64Size, &pszUnitSiz);
                             uint64_t u64PrintMax = formatDiskSize(maxSize, &pszUnitMax);
-                            setVMRuntimeErrorCallbackF(pVM, this, 0,
+                            setVMRuntimeErrorCallbackF(VMR3GetVM(pUVM), this, 0,
                                     "FatPartitionDetected", /* <= not exact but ... */
                                     N_("The medium '%ls' has a logical size of %RU64%s "
@@ -3340,5 +3339,5 @@
                     const char *pszUnit;
                     uint64_t u64Print = formatDiskSize(i64Size, &pszUnit);
-                    setVMRuntimeErrorCallbackF(pVM, this, 0,
+                    setVMRuntimeErrorCallbackF(VMR3GetVM(pUVM), this, 0,
                             "FatPartitionDetected",
 #ifdef RT_OS_WINDOWS
@@ -3382,5 +3381,5 @@
                         || enmFsTypeFile == RTFSTYPE_XFS)
                     {
-                        setVMRuntimeErrorCallbackF(pVM, this, 0,
+                        setVMRuntimeErrorCallbackF(VMR3GetVM(pUVM), this, 0,
                                 "Ext4PartitionDetected",
                                 N_("The host I/O cache for at least one controller is disabled "
@@ -3400,5 +3399,5 @@
                              && !mfSnapshotFolderExt4WarningShown)
                     {
-                        setVMRuntimeErrorCallbackF(pVM, this, 0,
+                        setVMRuntimeErrorCallbackF(VMR3GetVM(pUVM), this, 0,
                                 "Ext4PartitionDetected",
                                 N_("The host I/O cache for at least one controller is disabled "
@@ -3475,6 +3474,6 @@
         {
             /* Attach the new driver. */
-            rc = PDMR3DeviceAttach(pVM, pcszDevice, uInstance, uLUN,
-                                fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG, NULL /*ppBase*/);
+            rc = PDMR3DeviceAttach(VMR3GetVM(pUVM), pcszDevice, uInstance, uLUN,
+                                   fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG, NULL /*ppBase*/);
             AssertRCReturn(rc, rc);
 
@@ -3849,6 +3848,4 @@
         AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-        PVM pVM = VMR3GetVM(mpUVM);     /* We're on an EMT, so this is safe. */
-
         ComPtr<IMachine> pMachine = machine();
 
@@ -3875,5 +3872,5 @@
         if (fAttachDetach)
         {
-            rc = PDMR3DeviceDetach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/);
+            rc = PDMR3DeviceDetach(VMR3GetVM(mpUVM), pszDevice, uInstance, uLun, 0 /*fFlags*/);
             if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
                 rc = VINF_SUCCESS;
@@ -4081,5 +4078,5 @@
                     {
                         case VERR_ACCESS_DENIED:
-                            return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,  N_(
+                            return VMSetError(VMR3GetVM(mpUVM), VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,  N_(
                                             "Failed to open '/dev/net/tun' for read/write access. Please check the "
                                             "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
@@ -4089,5 +4086,5 @@
                         default:
                             AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
-                            return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
+                            return VMSetError(VMR3GetVM(mpUVM), VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
                                             "Failed to initialize Host Interface Networking"));
                     }
@@ -4132,5 +4129,5 @@
 //                     * hrc = aNetworkAdapter->Detach();                                   H();
 //                     */
-//                     return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
+//                     return VMSetError(VMR3GetVM(mpUVM), VERR_INTERNAL_ERROR, RT_SRC_POS,
 //                                       N_("Malformed host interface networking name '%ls'"),
 //                                       BridgedIfName.raw());
@@ -4168,5 +4165,5 @@
                 {
                     AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: FindByName failed, rc=%Rhrc (0x%x)", hrc, hrc));
-                    return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
+                    return VMSetError(VMR3GetVM(mpUVM), VERR_INTERNAL_ERROR, RT_SRC_POS,
                                       N_("Nonexistent host networking interface, name '%ls'"),
                                       BridgedIfName.raw());
@@ -4183,5 +4180,5 @@
                 if (eIfType != HostNetworkInterfaceType_Bridged)
                 {
-                    return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
+                    return VMSetError(VMR3GetVM(mpUVM), VERR_INTERNAL_ERROR, RT_SRC_POS,
                                       N_("Interface ('%ls') is not a Bridged Adapter interface"),
                                       BridgedIfName.raw());
@@ -4280,5 +4277,5 @@
                         {
                             case VERR_ACCESS_DENIED:
-                                return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,  N_(
+                                return VMSetError(VMR3GetVM(mpUVM), VERR_HOSTIF_INIT_FAILED, RT_SRC_POS,  N_(
                                                 "Failed to open '/dev/%s' for read/write access.  Please check the "
                                                 "permissions of that node, and that the net.link.tap.user_open "
@@ -4288,5 +4285,5 @@
                             default:
                                 AssertMsgFailed(("Could not attach to tap interface! Bad!\n"));
-                                return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
+                                return VMSetError(VMR3GetVM(mpUVM), VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
                                                 "Failed to initialize Host Interface Networking"));
                         }
@@ -4316,5 +4313,5 @@
                         if (ioctl(iSock, SIOCGIFFLAGS, &Req) >= 0)
                             if ((Req.ifr_flags & IFF_UP) == 0)
-                                setVMRuntimeErrorCallbackF(pVM, this, 0, "BridgedInterfaceDown",
+                                setVMRuntimeErrorCallbackF(VMR3GetVM(mpUVM), this, 0, "BridgedInterfaceDown",
                                                            "Bridged interface %s is down. Guest will not be able to use this interface",
                                                            pszBridgedIfName);
@@ -4539,5 +4536,5 @@
                 {
                     LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)\n", rc));
-                    return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
+                    return VMSetError(VMR3GetVM(mpUVM), VERR_INTERNAL_ERROR, RT_SRC_POS,
                                       N_("Nonexistent host networking interface, name '%ls'"),
                                       HostOnlyName.raw());
@@ -4564,5 +4561,5 @@
 
                 if (eIfType != HostNetworkInterfaceType_HostOnly)
-                    return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
+                    return VMSetError(VMR3GetVM(mpUVM), VERR_INTERNAL_ERROR, RT_SRC_POS,
                                       N_("Interface ('%ls') is not a Host-Only Adapter interface"),
                                       HostOnlyName.raw());
@@ -4763,5 +4760,5 @@
                     if (fAttachDetach)
                     {
-                        rc = PDMR3DriverAttach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/, NULL /* ppBase */);
+                        rc = PDMR3DriverAttach(VMR3GetVM(mpUVM), pszDevice, uInstance, uLun, 0 /*fFlags*/, NULL /* ppBase */);
                         //AssertRC(rc);
                     }
@@ -4915,5 +4912,5 @@
  * the machine XML and set a couple of initial properties.
  */
-/* static */ int Console::configGuestProperties(void *pvConsole, PVM pVM)
+/* static */ int Console::configGuestProperties(void *pvConsole, PUVM pUVM)
 {
 #ifdef VBOX_WITH_GUEST_PROPS
@@ -4947,5 +4944,5 @@
                 PFNDBGFHANDLEREXT pfnHandler = (PFNDBGFHANDLEREXT)(uintptr_t)Params[0].u.pointer.addr;
                 void *pService = (void*)Params[1].u.pointer.addr;
-                DBGFR3InfoRegisterExternal(pVM, "guestprops", "Display the guest properties", pfnHandler, pService);
+                DBGFR3InfoRegisterExternal(VMR3GetVM(pUVM), "guestprops", "Display the guest properties", pfnHandler, pService);
             }
         }
Index: trunk/src/VBox/Main/src-client/ConsoleImplTeleporter.cpp
===================================================================
--- trunk/src/VBox/Main/src-client/ConsoleImplTeleporter.cpp	(revision 44339)
+++ trunk/src/VBox/Main/src-client/ConsoleImplTeleporter.cpp	(revision 44340)
@@ -686,5 +686,5 @@
     RTSocketRetain(pState->mhSocket);
     void *pvUser = static_cast<void *>(static_cast<TeleporterState *>(pState));
-    vrc = VMR3Teleport(VMR3GetVM(pState->mpUVM),
+    vrc = VMR3Teleport(pState->mpUVM,
                        pState->mcMsMaxDowntime,
                        &g_teleporterTcpOps,         pvUser,
@@ -887,5 +887,5 @@
                         {
                             autoLock.release();
-                            int rc = VMR3Resume(VMR3GetVM(pState->mpUVM));
+                            int rc = VMR3Resume(pState->mpUVM);
                             AssertLogRelMsgRC(rc, ("VMR3Resume -> %Rrc\n", rc));
                             autoLock.acquire();
@@ -1338,16 +1338,16 @@
                 break;
 
-            int vrc2 = VMR3AtErrorRegisterU(pState->mpUVM,
-                                            Console::genericVMSetErrorCallback, &pState->mErrorText); AssertRC(vrc2);
+            int vrc2 = VMR3AtErrorRegister(pState->mpUVM,
+                                           Console::genericVMSetErrorCallback, &pState->mErrorText); AssertRC(vrc2);
             RTSocketRetain(pState->mhSocket); /* For concurrent access by I/O thread and EMT. */
             pState->moffStream = 0;
 
             void *pvUser2 = static_cast<void *>(static_cast<TeleporterState *>(pState));
-            vrc = VMR3LoadFromStream(VMR3GetVM(pState->mpUVM),
+            vrc = VMR3LoadFromStream(pState->mpUVM,
                                      &g_teleporterTcpOps, pvUser2,
                                      teleporterProgressCallback, pvUser2);
 
             RTSocketRelease(pState->mhSocket);
-            vrc2 = VMR3AtErrorDeregister(VMR3GetVM(pState->mpUVM), Console::genericVMSetErrorCallback, &pState->mErrorText); AssertRC(vrc2);
+            vrc2 = VMR3AtErrorDeregister(pState->mpUVM, Console::genericVMSetErrorCallback, &pState->mErrorText); AssertRC(vrc2);
 
             if (RT_FAILURE(vrc))
@@ -1412,5 +1412,5 @@
                 {
                     if (!strcmp(szCmd, "hand-over-resume"))
-                        vrc = VMR3Resume(VMR3GetVM(pState->mpUVM));
+                        vrc = VMR3Resume(pState->mpUVM);
                     else
                         pState->mptrConsole->setMachineState(MachineState_Paused);
Index: trunk/src/VBox/Main/src-client/DisplayImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-client/DisplayImpl.cpp	(revision 44339)
+++ trunk/src/VBox/Main/src-client/DisplayImpl.cpp	(revision 44340)
@@ -223,6 +223,6 @@
     uint32_t cyPNG = 0;
 
-    Console::SafeVMPtr pVM (that->mParent);
-    if (SUCCEEDED(pVM.rc()))
+    Console::SafeVMPtr ptrVM(that->mParent);
+    if (ptrVM.isOk())
     {
         /* Query RGB bitmap. */
@@ -264,5 +264,5 @@
     else
     {
-        LogFunc(("Failed to get VM pointer 0x%x\n", pVM.rc()));
+        LogFunc(("Failed to get VM pointer 0x%x\n", ptrVM.rc()));
     }
 
@@ -859,8 +859,8 @@
         {
             /* protect mpVM */
-            Console::SafeVMPtr pVM (mParent);
-            AssertComRC (pVM.rc());
-
-            STAM_REG(pVM, &StatDisplayRefresh, STAMTYPE_PROFILE, "/PROF/Display/Refresh", STAMUNIT_TICKS_PER_CALL, "Time spent in EMT for display updates.");
+            Console::SafeVMPtr ptrVM (mParent);
+            AssertComRC (ptrVM.rc());
+
+            STAM_REG(ptrVM.raw(), &StatDisplayRefresh, STAMTYPE_PROFILE, "/PROF/Display/Refresh", STAMUNIT_TICKS_PER_CALL, "Time spent in EMT for display updates.");
             stam = 1;
         }
@@ -2069,6 +2069,5 @@
 }
 
-STDMETHODIMP Display::SetFramebuffer (ULONG aScreenId,
-    IFramebuffer *aFramebuffer)
+STDMETHODIMP Display::SetFramebuffer(ULONG aScreenId, IFramebuffer *aFramebuffer)
 {
     LogRelFlowFunc (("\n"));
@@ -2078,10 +2077,11 @@
 
     AutoCaller autoCaller(this);
-    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+    if (FAILED(autoCaller.rc()))
+        return autoCaller.rc();
 
     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
 
-    Console::SafeVMPtrQuiet pVM (mParent);
-    if (pVM.isOk())
+    Console::SafeVMPtrQuiet ptrVM(mParent);
+    if (ptrVM.isOk())
     {
         /* Must release the lock here because the changeFramebuffer will
@@ -2090,6 +2090,6 @@
 
         /* send request to the EMT thread */
-        int vrc = VMR3ReqCallWait (pVM, VMCPUID_ANY,
-                                   (PFNRT) changeFramebuffer, 3, this, aFramebuffer, aScreenId);
+        int vrc = VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY,
+                                   (PFNRT)changeFramebuffer, 3, this, aFramebuffer, aScreenId);
 
         alock.acquire();
@@ -2323,5 +2323,6 @@
 }
 
-static int displayTakeScreenshot(PVM pVM, Display *pDisplay, struct DRVMAINDISPLAY *pDrv, ULONG aScreenId, BYTE *address, ULONG width, ULONG height)
+static int displayTakeScreenshot(PUVM pUVM, Display *pDisplay, struct DRVMAINDISPLAY *pDrv, ULONG aScreenId,
+                                 BYTE *address, ULONG width, ULONG height)
 {
     uint8_t *pu8Data = NULL;
@@ -2338,6 +2339,6 @@
                  it would be nice to have an accurate screenshot for the bug
                  report if the VM deadlocks. */
-        vrc = VMR3ReqPriorityCallWait(pVM, VMCPUID_ANY, (PFNRT)Display::displayTakeScreenshotEMT, 6,
-                                      pDisplay, aScreenId, &pu8Data, &cbData, &cx, &cy);
+        vrc = VMR3ReqPriorityCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)Display::displayTakeScreenshotEMT, 6,
+                                       pDisplay, aScreenId, &pu8Data, &cbData, &cx, &cy);
         if (vrc != VERR_TRY_AGAIN)
         {
@@ -2417,6 +2418,7 @@
     CHECK_CONSOLE_DRV(mpDrv);
 
-    Console::SafeVMPtr pVM(mParent);
-    if (FAILED(pVM.rc())) return pVM.rc();
+    Console::SafeVMPtr ptrVM(mParent);
+    if (!ptrVM.isOk())
+        return ptrVM.rc();
 
     HRESULT rc = S_OK;
@@ -2431,5 +2433,5 @@
     alock.release();
 
-    int vrc = displayTakeScreenshot(pVM, this, mpDrv, aScreenId, address, width, height);
+    int vrc = displayTakeScreenshot(ptrVM.rawUVM(), this, mpDrv, aScreenId, address, width, height);
 
     if (vrc == VERR_NOT_IMPLEMENTED)
@@ -2469,6 +2471,7 @@
     CHECK_CONSOLE_DRV(mpDrv);
 
-    Console::SafeVMPtr pVM(mParent);
-    if (FAILED(pVM.rc())) return pVM.rc();
+    Console::SafeVMPtr ptrVM(mParent);
+    if (!ptrVM.isOk())
+        return ptrVM.rc();
 
     HRESULT rc = S_OK;
@@ -2489,5 +2492,5 @@
         return E_OUTOFMEMORY;
 
-    int vrc = displayTakeScreenshot(pVM, this, mpDrv, aScreenId, pu8Data, width, height);
+    int vrc = displayTakeScreenshot(ptrVM.rawUVM(), this, mpDrv, aScreenId, pu8Data, width, height);
 
     if (RT_SUCCESS(vrc))
@@ -2545,6 +2548,7 @@
     CHECK_CONSOLE_DRV(mpDrv);
 
-    Console::SafeVMPtr pVM(mParent);
-    if (FAILED(pVM.rc())) return pVM.rc();
+    Console::SafeVMPtr ptrVM(mParent);
+    if (!ptrVM.isOk())
+        return ptrVM.rc();
 
     HRESULT rc = S_OK;
@@ -2565,5 +2569,5 @@
         return E_OUTOFMEMORY;
 
-    int vrc = displayTakeScreenshot(pVM, this, mpDrv, aScreenId, pu8Data, width, height);
+    int vrc = displayTakeScreenshot(ptrVM.rawUVM(), this, mpDrv, aScreenId, pu8Data, width, height);
 
     if (RT_SUCCESS(vrc))
@@ -2732,6 +2736,7 @@
     CHECK_CONSOLE_DRV (mpDrv);
 
-    Console::SafeVMPtr pVM(mParent);
-    if (FAILED(pVM.rc())) return pVM.rc();
+    Console::SafeVMPtr ptrVM(mParent);
+    if (!ptrVM.isOk())
+        return ptrVM.rc();
 
     /* Release lock because the call scheduled on EMT may also try to take it. */
@@ -2742,6 +2747,6 @@
      * dirty conversion work.
      */
-    int rcVBox = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)Display::drawToScreenEMT, 7,
-                                 this, aScreenId, address, x, y, width, height);
+    int rcVBox = VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::drawToScreenEMT, 7,
+                                  this, aScreenId, address, x, y, width, height);
 
     /*
@@ -2852,6 +2857,7 @@
     CHECK_CONSOLE_DRV (mpDrv);
 
-    Console::SafeVMPtr pVM(mParent);
-    if (FAILED(pVM.rc())) return pVM.rc();
+    Console::SafeVMPtr ptrVM(mParent);
+    if (!ptrVM.isOk())
+        return ptrVM.rc();
 
     HRESULT rc = S_OK;
@@ -2863,6 +2869,6 @@
 
     /* pdm.h says that this has to be called from the EMT thread */
-    int rcVBox = VMR3ReqCallVoidWait(pVM, VMCPUID_ANY, (PFNRT)Display::InvalidateAndUpdateEMT,
-                                     1, this);
+    int rcVBox = VMR3ReqCallVoidWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::InvalidateAndUpdateEMT,
+                                      1, this);
     alock.acquire();
 
@@ -2979,7 +2985,7 @@
      *  time-critical method.
      */
-    Console::SafeVMPtrQuiet pVM (mParent);
-    if (pVM.isOk())
-        VM_ASSERT_EMT (pVM.raw());
+    Console::SafeVMPtrQuiet ptrVM (mParent);
+    if (ptrVM.isOk())
+        Assert(VM_IS_EMT(ptrVM.raw()));
 #endif
 
Index: trunk/src/VBox/Main/src-client/MachineDebuggerImpl.cpp
===================================================================
--- trunk/src/VBox/Main/src-client/MachineDebuggerImpl.cpp	(revision 44339)
+++ trunk/src/VBox/Main/src-client/MachineDebuggerImpl.cpp	(revision 44340)
@@ -28,4 +28,5 @@
 #include <VBox/vmm/csam.h>
 #include <VBox/vmm/vm.h>
+#include <VBox/vmm/uvm.h>
 #include <VBox/vmm/tm.h>
 #include <VBox/vmm/hm.h>
@@ -826,5 +827,5 @@
 
 /**
- * Hack for getting the VM handle.
+ * Hack for getting the user mode VM handle (UVM).
  *
  * This is only temporary (promise) while prototyping the debugger.
@@ -834,8 +835,10 @@
  *                      uintptr_t in COM, we're using the max integer.
  *                      (No, ULONG is not pointer sized!)
- */
-STDMETHODIMP MachineDebugger::COMGETTER(VM)(LONG64 *a_u64Vm)
-{
-    CheckComArgOutPointerValid(a_u64Vm);
+ * @remarks The returned handle must be passed to VMR3ReleaseUVM()!
+ * @remarks Prior to 4.3 this returned PVM.
+ */
+STDMETHODIMP MachineDebugger::COMGETTER(VM)(LONG64 *a_i64Vm)
+{
+    CheckComArgOutPointerValid(a_i64Vm);
 
     AutoCaller autoCaller(this);
@@ -848,5 +851,8 @@
         hrc = ptrVM.rc();
         if (SUCCEEDED(hrc))
-            *a_u64Vm = (intptr_t)ptrVM.raw();
+        {
+            VMR3RetainUVM(ptrVM.rawUVM());
+            *a_i64Vm = (intptr_t)ptrVM.rawUVM();
+        }
 
         /*
Index: trunk/src/VBox/VMM/VMMR3/CFGM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/CFGM.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/CFGM.cpp	(revision 44340)
@@ -61,8 +61,10 @@
 #include "CFGMInternal.h"
 #include <VBox/vmm/vm.h>
+#include <VBox/vmm/uvm.h>
 #include <VBox/err.h>
 
 #include <VBox/log.h>
 #include <iprt/assert.h>
+#include <iprt/param.h>
 #include <iprt/string.h>
 #include <iprt/uuid.h>
@@ -159,4 +161,19 @@
 VMMR3DECL(PCFGMNODE) CFGMR3GetRoot(PVM pVM)
 {
+    return pVM->cfgm.s.pRoot;
+}
+
+
+/**
+ * Gets the root node for the VM.
+ *
+ * @returns Pointer to root node.
+ * @param   pVM             Pointer to the VM.
+ */
+VMMR3DECL(PCFGMNODE) CFGMR3GetRootU(PUVM pUVM)
+{
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL);
+    PVM pVM = pUVM->pVM;
+    AssertReturn(pVM, NULL);
     return pVM->cfgm.s.pRoot;
 }
Index: trunk/src/VBox/VMM/VMMR3/DBGFOS.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/DBGFOS.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/DBGFOS.cpp	(revision 44340)
@@ -442,5 +442,5 @@
      */
     void *pvIf = NULL;
-    VMR3ReqPriorityCallVoidWait(pVM, VMCPUID_ANY, (PFNRT)dbgfR3OSQueryInterface, 3, pVM, enmIf, &pvIf);
+    VMR3ReqPriorityCallVoidWaitU(pVM->pUVM, VMCPUID_ANY, (PFNRT)dbgfR3OSQueryInterface, 3, pVM, enmIf, &pvIf);
     return pvIf;
 }
Index: trunk/src/VBox/VMM/VMMR3/EM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/EM.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/EM.cpp	(revision 44340)
@@ -62,5 +62,4 @@
 #endif
 #include "EMInternal.h"
-#include "internal/em.h"
 #include <VBox/vmm/vm.h>
 #include <VBox/vmm/cpumdis.h>
@@ -1516,5 +1515,5 @@
         if (VM_FF_TESTANDCLEAR(pVM, VM_FF_RESET))
         {
-            rc2 = VMR3Reset(pVM);
+            rc2 = VMR3Reset(pVM->pUVM);
             UPDATE_RC();
         }
@@ -1861,5 +1860,5 @@
  *
  */
-VMMR3DECL(bool) EMR3IsExecutionAllowed(PVM pVM, PVMCPU pVCpu)
+VMMR3_INT_DECL(bool) EMR3IsExecutionAllowed(PVM pVM, PVMCPU pVCpu)
 {
     uint64_t u64UserTime, u64KernelTime;
@@ -2382,5 +2381,5 @@
  * @param   pVM             Pointer to the VM.
  */
-VMMR3DECL(int) EMR3NotifySuspend(PVM pVM)
+VMMR3_INT_DECL(int) EMR3NotifySuspend(PVM pVM)
 {
     PVMCPU pVCpu = VMMGetCpu(pVM);
@@ -2397,5 +2396,5 @@
  * @param   pVM             Pointer to the VM.
  */
-VMMR3DECL(int) EMR3NotifyResume(PVM pVM)
+VMMR3_INT_DECL(int) EMR3NotifyResume(PVM pVM)
 {
     PVMCPU pVCpu = VMMGetCpu(pVM);
Index: trunk/src/VBox/VMM/VMMR3/EMHM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/EMHM.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/EMHM.cpp	(revision 44340)
@@ -40,5 +40,4 @@
 #include <VBox/vmm/hm.h>
 #include "EMInternal.h"
-#include "internal/em.h"
 #include <VBox/vmm/vm.h>
 #include <VBox/vmm/cpumdis.h>
Index: trunk/src/VBox/VMM/VMMR3/EMRaw.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/EMRaw.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/EMRaw.cpp	(revision 44340)
@@ -42,5 +42,4 @@
 #include <VBox/vmm/patm.h>
 #include "EMInternal.h"
-#include "internal/em.h"
 #include <VBox/vmm/vm.h>
 #include <VBox/vmm/cpumdis.h>
Index: trunk/src/VBox/VMM/VMMR3/FTM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/FTM.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/FTM.cpp	(revision 44340)
@@ -21,13 +21,15 @@
 *******************************************************************************/
 #define LOG_GROUP LOG_GROUP_FTM
+#include <VBox/vmm/ftm.h>
+#include <VBox/vmm/em.h>
+#include <VBox/vmm/pdm.h>
+#include <VBox/vmm/pgm.h>
+#include <VBox/vmm/ssm.h>
+#include <VBox/vmm/vmm.h>
 #include "FTMInternal.h"
 #include <VBox/vmm/vm.h>
-#include <VBox/vmm/vmm.h>
 #include <VBox/err.h>
 #include <VBox/param.h>
-#include <VBox/vmm/ssm.h>
 #include <VBox/log.h>
-#include <VBox/vmm/pgm.h>
-#include <VBox/vmm/pdm.h>
 
 #include <iprt/assert.h>
@@ -40,7 +42,6 @@
 #include <iprt/asm.h>
 
-#include "internal/vm.h"
-#include "internal/em.h"
 #include "internal/pgm.h"
+
 
 /*******************************************************************************
@@ -636,5 +637,5 @@
     bool fSuspended = false;
 
-    int rc = VMR3Suspend(pVM);
+    int rc = VMR3Suspend(pVM->pUVM);
     AssertRCReturn(rc, rc);
 
@@ -654,5 +655,5 @@
 
     pVM->ftm.s.fDeltaLoadSaveActive = false;
-    rc = VMR3SaveFT(pVM, &g_ftmR3TcpOps, pVM, &fSuspended, false /* fSkipStateChanges */);
+    rc = VMR3SaveFT(pVM->pUVM, &g_ftmR3TcpOps, pVM, &fSuspended, false /* fSkipStateChanges */);
     AssertRC(rc);
 
@@ -666,5 +667,5 @@
     AssertRCReturn(rc, rc);
 
-    rc = VMR3Resume(pVM);
+    rc = VMR3Resume(pVM->pUVM);
     AssertRC(rc);
 
@@ -1089,5 +1090,5 @@
 
             pVM->ftm.s.fDeltaLoadSaveActive = (fFullSync == false);
-            rc = VMR3LoadFromStreamFT(pVM, &g_ftmR3TcpOps, pVM);
+            rc = VMR3LoadFromStreamFT(pVM->pUVM, &g_ftmR3TcpOps, pVM);
             pVM->ftm.s.fDeltaLoadSaveActive = false;
             RTSocketRelease(pVM->ftm.s.hSocket);
@@ -1175,34 +1176,33 @@
         /** @todo might need to disable page fusion as well */
 
-        return VMR3PowerOn(pVM);
-    }
-    else
-    {
-        /* standby */
-        rc = RTThreadCreate(NULL, ftmR3StandbyThread, pVM,
-                            0, RTTHREADTYPE_DEFAULT, 0, "ftmStandby");
-        if (RT_FAILURE(rc))
-            return rc;
-
-        rc = RTTcpServerCreateEx(pszAddress, uPort, &pVM->ftm.s.standby.hServer);
-        if (RT_FAILURE(rc))
-            return rc;
-        pVM->ftm.s.fIsStandbyNode = true;
-
-        rc = RTTcpServerListen(pVM->ftm.s.standby.hServer, ftmR3StandbyServeConnection, pVM);
-        /** @todo deal with the exit code to check if we should activate this standby VM. */
-        if (pVM->ftm.s.fActivateStandby)
-        {
-            /** @todo fallover. */
-        }
-
-        if (pVM->ftm.s.standby.hServer)
-        {
-            RTTcpServerDestroy(pVM->ftm.s.standby.hServer);
-            pVM->ftm.s.standby.hServer = NULL;
-        }
-        if (rc == VERR_TCP_SERVER_SHUTDOWN)
-            rc = VINF_SUCCESS;  /* ignore this error; the standby process was cancelled. */
-    }
+        return VMR3PowerOn(pVM->pUVM);
+    }
+
+
+    /* standby */
+    rc = RTThreadCreate(NULL, ftmR3StandbyThread, pVM,
+                        0, RTTHREADTYPE_DEFAULT, 0, "ftmStandby");
+    if (RT_FAILURE(rc))
+        return rc;
+
+    rc = RTTcpServerCreateEx(pszAddress, uPort, &pVM->ftm.s.standby.hServer);
+    if (RT_FAILURE(rc))
+        return rc;
+    pVM->ftm.s.fIsStandbyNode = true;
+
+    rc = RTTcpServerListen(pVM->ftm.s.standby.hServer, ftmR3StandbyServeConnection, pVM);
+    /** @todo deal with the exit code to check if we should activate this standby VM. */
+    if (pVM->ftm.s.fActivateStandby)
+    {
+        /** @todo fallover. */
+    }
+
+    if (pVM->ftm.s.standby.hServer)
+    {
+        RTTcpServerDestroy(pVM->ftm.s.standby.hServer);
+        pVM->ftm.s.standby.hServer = NULL;
+    }
+    if (rc == VERR_TCP_SERVER_SHUTDOWN)
+        rc = VINF_SUCCESS;  /* ignore this error; the standby process was cancelled. */
     return rc;
 }
@@ -1267,5 +1267,5 @@
 
     pVM->ftm.s.fDeltaLoadSaveActive = true;
-    rc = VMR3SaveFT(pVM, &g_ftmR3TcpOps, pVM, &fSuspended, true /* fSkipStateChanges */);
+    rc = VMR3SaveFT(pVM->pUVM, &g_ftmR3TcpOps, pVM, &fSuspended, true /* fSkipStateChanges */);
     pVM->ftm.s.fDeltaLoadSaveActive = false;
     AssertRC(rc);
Index: trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp	(revision 44340)
@@ -3164,10 +3164,10 @@
     {
         /* We own the IOM lock here and could cause a deadlock by waiting for a VCPU that is blocking on the IOM lock. */
-        rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)VMR3Suspend, 1, pVM);
+        rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)VMR3Suspend, 1, pVM->pUVM);
         AssertRC(rc);
         rc = VINF_EM_SUSPEND;
     }
     else
-        rc = VMR3Suspend(pVM);
+        rc = VMR3Suspend(pVM->pUVM);
 
     LogFlow(("pdmR3DevHlp_VMSuspend: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
@@ -3189,5 +3189,5 @@
      * Suspend the VM first then do the saving.
      */
-    int rc = VMR3Suspend(pVM);
+    int rc = VMR3Suspend(pVM->pUVM);
     if (RT_SUCCESS(rc))
     {
@@ -3200,5 +3200,5 @@
         if (RT_SUCCESS(rc))
         {
-            rc = VMR3PowerOff(pVM);
+            rc = VMR3PowerOff(pVM->pUVM);
             if (RT_FAILURE(rc))
                 LogRel(("%s/SSP: VMR3PowerOff failed: %Rrc\n", pDevIns->pReg->szName, rc));
@@ -3255,5 +3255,5 @@
     {
         /* We own the IOM lock here and could cause a deadlock by waiting for a VCPU that is blocking on the IOM lock. */
-        rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)VMR3PowerOff, 1, pVM);
+        rc = VMR3ReqCallNoWait(pVM, VMCPUID_ANY_QUEUE, (PFNRT)VMR3PowerOff, 1, pVM->pUVM);
         AssertRC(rc);
         /* Set the VCPU state to stopped here as well to make sure no
@@ -3264,5 +3264,5 @@
     }
     else
-        rc = VMR3PowerOff(pVM);
+        rc = VMR3PowerOff(pVM->pUVM);
 
     LogFlow(("pdmR3DevHlp_VMPowerOff: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc));
Index: trunk/src/VBox/VMM/VMMR3/PGM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/PGM.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/PGM.cpp	(revision 44340)
@@ -1369,5 +1369,5 @@
      */
 #ifdef VBOX_STRICT
-    VMR3AtStateRegister(pVM, pgmR3ResetNoMorePhysWritesFlag, NULL);
+    VMR3AtStateRegister(pVM->pUVM, pgmR3ResetNoMorePhysWritesFlag, NULL);
 #endif
     PGMRegisterStringFormatTypes();
Index: trunk/src/VBox/VMM/VMMR3/VM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/VM.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/VM.cpp	(revision 44340)
@@ -91,34 +91,8 @@
 
 /*******************************************************************************
-*   Structures and Typedefs                                                    *
-*******************************************************************************/
-/**
- * VM destruction callback registration record.
- */
-typedef struct VMATDTOR
-{
-    /** Pointer to the next record in the list. */
-    struct VMATDTOR        *pNext;
-    /** Pointer to the callback function. */
-    PFNVMATDTOR             pfnAtDtor;
-    /** The user argument. */
-    void                   *pvUser;
-} VMATDTOR;
-/** Pointer to a VM destruction callback registration record. */
-typedef VMATDTOR *PVMATDTOR;
-
-
-/*******************************************************************************
 *   Global Variables                                                           *
 *******************************************************************************/
 /** Pointer to the list of VMs. */
 static PUVM         g_pUVMsHead = NULL;
-
-/** Pointer to the list of at VM destruction callbacks. */
-static PVMATDTOR    g_pVMAtDtorHead = NULL;
-/** Lock the g_pVMAtDtorHead list. */
-#define VM_ATDTOR_LOCK() do { } while (0)
-/** Unlock the g_pVMAtDtorHead list. */
-#define VM_ATDTOR_UNLOCK() do { } while (0)
 
 
@@ -194,13 +168,19 @@
  *                              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.
+ * @param   ppVM                Where to optionally store the 'handle' of the
+ *                              created VM.
+ * @param   ppUVM               Where to optionally store the user 'handle' of
+ *                              the created VM, this includes one reference as
+ *                              if VMR3RetainUVM() was called.  The caller
+ *                              *MUST* remember to pass the returned value to
+ *                              VMR3ReleaseUVM() once done with the handle.
  */
 VMMR3DECL(int)   VMR3Create(uint32_t cCpus, PCVMM2USERMETHODS pVmm2UserMethods,
                             PFNVMATERROR pfnVMAtError, void *pvUserVM,
                             PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM,
-                            PVM *ppVM)
-{
-    LogFlow(("VMR3Create: cCpus=%RU32 pVmm2UserMethods=%p pfnVMAtError=%p pvUserVM=%p  pfnCFGMConstructor=%p pvUserCFGM=%p ppVM=%p\n",
-             cCpus, pVmm2UserMethods, pfnVMAtError, pvUserVM, pfnCFGMConstructor, pvUserCFGM, ppVM));
+                            PVM *ppVM, PUVM *ppUVM)
+{
+    LogFlow(("VMR3Create: cCpus=%RU32 pVmm2UserMethods=%p pfnVMAtError=%p pvUserVM=%p  pfnCFGMConstructor=%p pvUserCFGM=%p ppVM=%p ppUVM=%p\n",
+             cCpus, pVmm2UserMethods, pfnVMAtError, pvUserVM, pfnCFGMConstructor, pvUserCFGM, ppVM, ppUVM));
 
     if (pVmm2UserMethods)
@@ -218,5 +198,7 @@
     AssertPtrNullReturn(pfnVMAtError, VERR_INVALID_POINTER);
     AssertPtrNullReturn(pfnCFGMConstructor, VERR_INVALID_POINTER);
-    AssertPtrReturn(ppVM, VERR_INVALID_POINTER);
+    AssertPtrNullReturn(ppVM, VERR_INVALID_POINTER);
+    AssertPtrNullReturn(ppUVM, VERR_INVALID_POINTER);
+    AssertReturn(ppVM || ppUVM, VERR_INVALID_PARAMETER);
 
     /*
@@ -248,5 +230,5 @@
         return rc;
     if (pfnVMAtError)
-        rc = VMR3AtErrorRegisterU(pUVM, pfnVMAtError, pvUserVM);
+        rc = VMR3AtErrorRegister(pUVM, pfnVMAtError, pvUserVM);
     if (RT_SUCCESS(rc))
     {
@@ -277,6 +259,12 @@
                      * Success!
                      */
-                    *ppVM = pUVM->pVM;
-                    LogFlow(("VMR3Create: returns VINF_SUCCESS *ppVM=%p\n", *ppVM));
+                    if (ppVM)
+                        *ppVM = pUVM->pVM;
+                    if (ppUVM)
+                    {
+                        VMR3RetainUVM(pUVM);
+                        *ppUVM = pUVM;
+                    }
+                    LogFlow(("VMR3Create: returns VINF_SUCCESS (pVM=%p, pUVM=%p\n", pUVM->pVM, pUVM));
                     return VINF_SUCCESS;
                 }
@@ -364,5 +352,5 @@
 
                 default:
-                    if (VMR3GetErrorCountU(pUVM) == 0)
+                    if (VMR3GetErrorCount(pUVM) == 0)
                         pszError = RTErrGetFull(rc);
                     else
@@ -761,9 +749,7 @@
                                     {
                                         /*
-                                         * Set the state and link into the global list.
+                                         * Set the state and we're done.
                                          */
                                         vmR3SetState(pVM, VMSTATE_CREATED, VMSTATE_CREATING);
-                                        pUVM->pNext = g_pUVMsHead;
-                                        g_pUVMsHead = pUVM;
 
 #ifdef LOG_ENABLED
@@ -1177,5 +1163,5 @@
  * @param   offDelta    Relocation delta relative to old location.
  */
-VMMR3DECL(void)   VMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
+VMMR3_INT_DECL(void) VMR3Relocate(PVM pVM, RTGCINTPTR offDelta)
 {
     LogFlow(("VMR3Relocate: offDelta=%RGv\n", offDelta));
@@ -1259,5 +1245,5 @@
  * @returns VBox status code.
  *
- * @param   pVM         The VM to power on.
+ * @param   pUVM        The VM to power on.
  *
  * @thread      Any thread.
@@ -1265,7 +1251,9 @@
  * @vmstateto   PoweringOn+Running
  */
-VMMR3DECL(int) VMR3PowerOn(PVM pVM)
-{
-    LogFlow(("VMR3PowerOn: pVM=%p\n", pVM));
+VMMR3DECL(int) VMR3PowerOn(PUVM pUVM)
+{
+    LogFlow(("VMR3PowerOn: pUVM=%p\n", pUVM));
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
 
@@ -1353,5 +1341,5 @@
  *          code that has to be propagated up the call stack.
  *
- * @param   pVM     The VM to suspend.
+ * @param   pUVM    The VM to suspend.
  *
  * @thread      Any thread.
@@ -1359,8 +1347,8 @@
  * @vmstateto   Suspending + Suspended or SuspendingExtLS + SuspendedExtLS
  */
-VMMR3DECL(int) VMR3Suspend(PVM pVM)
-{
-    LogFlow(("VMR3Suspend: pVM=%p\n", pVM));
-    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
+VMMR3DECL(int) VMR3Suspend(PUVM pUVM)
+{
+    LogFlow(("VMR3Suspend: pUVM=%p\n", pUVM));
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
 
     /*
@@ -1368,5 +1356,5 @@
      * changing the VM state.
      */
-    int rc = VMMR3EmtRendezvous(pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_DESCENDING | VMMEMTRENDEZVOUS_FLAGS_STOP_ON_ERROR,
+    int rc = VMMR3EmtRendezvous(pUVM->pVM, VMMEMTRENDEZVOUS_FLAGS_TYPE_DESCENDING | VMMEMTRENDEZVOUS_FLAGS_STOP_ON_ERROR,
                                 vmR3Suspend, NULL);
     LogFlow(("VMR3Suspend: returns %Rrc\n", rc));
@@ -1440,7 +1428,9 @@
  * @vmstateto   Running
  */
-VMMR3DECL(int) VMR3Resume(PVM pVM)
-{
-    LogFlow(("VMR3Resume: pVM=%p\n", pVM));
+VMMR3DECL(int) VMR3Resume(PUVM pUVM)
+{
+    LogFlow(("VMR3Resume: pUVM=%p\n", pUVM));
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
 
@@ -1818,5 +1808,5 @@
  * @returns VBox status code.
  *
- * @param   pVM                 The VM which state should be saved.
+ * @param   pUVM                The VM which state should be saved.
  * @param   pszFilename         The name of the save state file.
  * @param   pStreamOps          The stream methods.
@@ -1833,8 +1823,8 @@
  *              RunningLS+SuspendingLS+SuspendedLS+Saving+Suspended.
  */
-VMMR3DECL(int) VMR3Save(PVM pVM, const char *pszFilename, bool fContinueAfterwards, PFNVMPROGRESS pfnProgress, void *pvUser, bool *pfSuspended)
-{
-    LogFlow(("VMR3Save: pVM=%p pszFilename=%p:{%s} fContinueAfterwards=%RTbool pfnProgress=%p pvUser=%p pfSuspended=%p\n",
-             pVM, pszFilename, pszFilename, fContinueAfterwards, pfnProgress, pvUser, pfSuspended));
+VMMR3DECL(int) VMR3Save(PUVM pUVM, const char *pszFilename, bool fContinueAfterwards, PFNVMPROGRESS pfnProgress, void *pvUser, bool *pfSuspended)
+{
+    LogFlow(("VMR3Save: pUVM=%p pszFilename=%p:{%s} fContinueAfterwards=%RTbool pfnProgress=%p pvUser=%p pfSuspended=%p\n",
+             pUVM, pszFilename, pszFilename, fContinueAfterwards, pfnProgress, pvUser, pfSuspended));
 
     /*
@@ -1843,4 +1833,6 @@
     AssertPtr(pfSuspended);
     *pfSuspended = false;
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     VM_ASSERT_OTHER_THREAD(pVM);
@@ -1864,11 +1856,4 @@
  * Save current VM state (used by FTM)
  *
- * 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.
@@ -1885,9 +1870,8 @@
  *              RunningLS+SuspendingLS+SuspendedLS+Saving+Suspended.
  */
-VMMR3DECL(int) VMR3SaveFT(PVM pVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser, bool *pfSuspended,
-                          bool fSkipStateChanges)
-{
-    LogFlow(("VMR3SaveFT: pVM=%p pStreamOps=%p pvSteamOpsUser=%p pfSuspended=%p\n",
-             pVM, pStreamOps, pvStreamOpsUser, pfSuspended));
+VMMR3_INT_DECL(int) VMR3SaveFT(PUVM pUVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser, bool *pfSuspended, bool fSkipStateChanges)
+{
+    LogFlow(("VMR3SaveFT: pUVM=%p pStreamOps=%p pvSteamOpsUser=%p pfSuspended=%p\n",
+             pUVM, pStreamOps, pvStreamOpsUser, pfSuspended));
 
     /*
@@ -1896,4 +1880,6 @@
     AssertPtr(pfSuspended);
     *pfSuspended = false;
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     AssertReturn(pStreamOps, VERR_INVALID_PARAMETER);
@@ -1916,5 +1902,5 @@
  * @returns VBox status code.
  *
- * @param   pVM                 The VM which state should be saved.
+ * @param   pUVM                The VM which state should be saved.
  * @param   cMsMaxDowntime      The maximum downtime given as milliseconds.
  * @param   pStreamOps          The stream methods.
@@ -1929,9 +1915,9 @@
  *              RunningLS+SuspendingLS+SuspendedLS+Saving+Suspended.
  */
-VMMR3DECL(int) VMR3Teleport(PVM pVM, uint32_t cMsMaxDowntime, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
+VMMR3DECL(int) VMR3Teleport(PUVM pUVM, uint32_t cMsMaxDowntime, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
                             PFNVMPROGRESS pfnProgress, void *pvProgressUser, bool *pfSuspended)
 {
-    LogFlow(("VMR3Teleport: pVM=%p cMsMaxDowntime=%u pStreamOps=%p pvStreamOps=%p pfnProgress=%p pvProgressUser=%p\n",
-             pVM, cMsMaxDowntime, pStreamOps, pvStreamOpsUser, pfnProgress, pvProgressUser));
+    LogFlow(("VMR3Teleport: pUVM=%p cMsMaxDowntime=%u pStreamOps=%p pvStreamOps=%p pfnProgress=%p pvProgressUser=%p\n",
+             pUVM, cMsMaxDowntime, pStreamOps, pvStreamOpsUser, pfnProgress, pvProgressUser));
 
     /*
@@ -1940,4 +1926,6 @@
     AssertPtr(pfSuspended);
     *pfSuspended = false;
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     VM_ASSERT_OTHER_THREAD(pVM);
@@ -1963,5 +1951,5 @@
  * @returns VBox status code.
  *
- * @param   pVM                 Pointer to the VM.
+ * @param   pUVM                Pointer to the VM.
  * @param   pszFilename         The name of the file.  NULL if pStreamOps is used.
  * @param   pStreamOps          The stream methods.  NULL if pszFilename is used.
@@ -1974,5 +1962,5 @@
  * @thread  EMT.
  */
-static DECLCALLBACK(int) vmR3Load(PVM pVM, const char *pszFilename, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
+static DECLCALLBACK(int) vmR3Load(PUVM pUVM, const char *pszFilename, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
                                   PFNVMPROGRESS pfnProgress, void *pvProgressUser, bool fTeleporting,
                                   bool fSkipStateChanges)
@@ -1980,11 +1968,13 @@
     int rc = VINF_SUCCESS;
 
-    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));
+    LogFlow(("vmR3Load: pUVM=%p pszFilename=%p:{%s} pStreamOps=%p pvStreamOpsUser=%p pfnProgress=%p pvProgressUser=%p fTeleporting=%RTbool\n",
+             pUVM, pszFilename, pszFilename, pStreamOps, pvStreamOpsUser, pfnProgress, pvProgressUser, fTeleporting));
 
     /*
      * Validate input (paranoia).
      */
-    AssertPtr(pVM);
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
+    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     AssertPtrNull(pszFilename);
     AssertPtrNull(pStreamOps);
@@ -2000,6 +1990,6 @@
          */
         rc = vmR3TrySetState(pVM, "VMR3Load", 2,
-                                 VMSTATE_LOADING, VMSTATE_CREATED,
-                                 VMSTATE_LOADING, VMSTATE_SUSPENDED);
+                             VMSTATE_LOADING, VMSTATE_CREATED,
+                             VMSTATE_LOADING, VMSTATE_SUSPENDED);
         if (RT_FAILURE(rc))
             return rc;
@@ -2007,5 +1997,5 @@
     pVM->vm.s.fTeleportedAndNotFullyResumedYet = fTeleporting;
 
-    uint32_t cErrorsPriorToSave = VMR3GetErrorCount(pVM);
+    uint32_t cErrorsPriorToSave = VMR3GetErrorCount(pUVM);
     rc = SSMR3Load(pVM, pszFilename, pStreamOps, pvStreamOpsUser, SSMAFTER_RESUME, pfnProgress, pvProgressUser);
     if (RT_SUCCESS(rc))
@@ -2021,5 +2011,5 @@
             vmR3SetState(pVM, VMSTATE_LOAD_FAILURE, VMSTATE_LOADING);
 
-        if (cErrorsPriorToSave == VMR3GetErrorCount(pVM))
+        if (cErrorsPriorToSave == VMR3GetErrorCount(pUVM))
             rc = VMSetError(pVM, rc, RT_SRC_POS,
                             N_("Unable to restore the virtual machine's saved state from '%s'. "
@@ -2050,13 +2040,13 @@
  * @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",
-             pVM, pszFilename, pszFilename, pfnProgress, pvUser));
+VMMR3DECL(int) VMR3LoadFromFile(PUVM pUVM, const char *pszFilename, PFNVMPROGRESS pfnProgress, void *pvUser)
+{
+    LogFlow(("VMR3LoadFromFile: pUVM=%p pszFilename=%p:{%s} pfnProgress=%p pvUser=%p\n",
+             pUVM, pszFilename, pszFilename, pfnProgress, pvUser));
 
     /*
      * Validate input.
      */
-    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
     AssertPtrReturn(pszFilename, VERR_INVALID_POINTER);
 
@@ -2065,7 +2055,7 @@
      * since there is no execution taking place when this call is allowed.
      */
-    int rc = VMR3ReqCallWait(pVM, 0 /*idDstCpu*/, (PFNRT)vmR3Load, 8,
-                             pVM, pszFilename, (uintptr_t)NULL /*pStreamOps*/, (uintptr_t)NULL /*pvStreamOpsUser*/, pfnProgress, pvUser,
-                             false /*fTeleporting*/, false /* fSkipStateChanges */);
+    int rc = VMR3ReqCallWaitU(pUVM, 0 /*idDstCpu*/, (PFNRT)vmR3Load, 8,
+                              pUVM, pszFilename, (uintptr_t)NULL /*pStreamOps*/, (uintptr_t)NULL /*pvStreamOpsUser*/, pfnProgress, pvUser,
+                              false /*fTeleporting*/, false /* fSkipStateChanges */);
     LogFlow(("VMR3LoadFromFile: returns %Rrc\n", rc));
     return rc;
@@ -2078,5 +2068,5 @@
  * @returns VBox status code.
  *
- * @param   pVM             Pointer to the VM.
+ * @param   pUVM            Pointer to the VM.
  * @param   pStreamOps      The stream methods.
  * @param   pvStreamOpsUser The user argument to the stream methods.
@@ -2088,14 +2078,14 @@
  * @vmstateto   Loading+Suspended
  */
-VMMR3DECL(int) VMR3LoadFromStream(PVM pVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
+VMMR3DECL(int) VMR3LoadFromStream(PUVM pUVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
                                   PFNVMPROGRESS pfnProgress, void *pvProgressUser)
 {
-    LogFlow(("VMR3LoadFromStream: pVM=%p pStreamOps=%p pvStreamOpsUser=%p pfnProgress=%p pvProgressUser=%p\n",
-             pVM, pStreamOps, pvStreamOpsUser, pfnProgress, pvProgressUser));
+    LogFlow(("VMR3LoadFromStream: pUVM=%p pStreamOps=%p pvStreamOpsUser=%p pfnProgress=%p pvProgressUser=%p\n",
+             pUVM, pStreamOps, pvStreamOpsUser, pfnProgress, pvProgressUser));
 
     /*
      * Validate input.
      */
-    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
     AssertPtrReturn(pStreamOps, VERR_INVALID_POINTER);
 
@@ -2104,7 +2094,7 @@
      * since there is no execution taking place when this call is allowed.
      */
-    int rc = VMR3ReqCallWait(pVM, 0 /*idDstCpu*/, (PFNRT)vmR3Load, 8,
-                             pVM, (uintptr_t)NULL /*pszFilename*/, pStreamOps, pvStreamOpsUser, pfnProgress, pvProgressUser,
-                             true /*fTeleporting*/, false /* fSkipStateChanges */);
+    int rc = VMR3ReqCallWaitU(pUVM, 0 /*idDstCpu*/, (PFNRT)vmR3Load, 8,
+                              pUVM, (uintptr_t)NULL /*pszFilename*/, pStreamOps, pvStreamOpsUser, pfnProgress, pvProgressUser,
+                              true /*fTeleporting*/, false /* fSkipStateChanges */);
     LogFlow(("VMR3LoadFromStream: returns %Rrc\n", rc));
     return rc;
@@ -2113,9 +2103,9 @@
 
 /**
- * VMR3LoadFromFileFT for arbitrary file streams.
+ * Special version for the FT component, it skips state changes.
  *
  * @returns VBox status code.
  *
- * @param   pVM             Pointer to the VM.
+ * @param   pUVM            The VM handle.
  * @param   pStreamOps      The stream methods.
  * @param   pvStreamOpsUser The user argument to the stream methods.
@@ -2127,13 +2117,12 @@
  * @vmstateto   Loading+Suspended
  */
-VMMR3DECL(int) VMR3LoadFromStreamFT(PVM pVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser)
-{
-    LogFlow(("VMR3LoadFromStreamFT: pVM=%p pStreamOps=%p pvStreamOpsUser=%p\n",
-             pVM, pStreamOps, pvStreamOpsUser));
+VMMR3_INT_DECL(int) VMR3LoadFromStreamFT(PUVM pUVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser)
+{
+    LogFlow(("VMR3LoadFromStreamFT: pUVM=%p pStreamOps=%p pvStreamOpsUser=%p\n", pUVM, pStreamOps, pvStreamOpsUser));
 
     /*
      * Validate input.
      */
-    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
     AssertPtrReturn(pStreamOps, VERR_INVALID_POINTER);
 
@@ -2142,7 +2131,7 @@
      * since there is no execution taking place when this call is allowed.
      */
-    int rc = VMR3ReqCallWait(pVM, 0 /*idDstCpu*/, (PFNRT)vmR3Load, 8,
-                             pVM, (uintptr_t)NULL /*pszFilename*/, pStreamOps, pvStreamOpsUser, NULL, NULL,
-                             true /*fTeleporting*/, true /* fSkipStateChanges */);
+    int rc = VMR3ReqCallWaitU(pUVM, 0 /*idDstCpu*/, (PFNRT)vmR3Load, 8,
+                              pUVM, (uintptr_t)NULL /*pszFilename*/, pStreamOps, pvStreamOpsUser, NULL, NULL,
+                              true /*fTeleporting*/, true /* fSkipStateChanges */);
     LogFlow(("VMR3LoadFromStream: returns %Rrc\n", rc));
     return rc;
@@ -2288,5 +2277,5 @@
  *          code that has to be propagated up the call stack.
  *
- * @param   pVM     The handle of the VM to be powered off.
+ * @param   pUVM    The handle of the VM to be powered off.
  *
  * @thread      Any thread.
@@ -2294,7 +2283,9 @@
  * @vmstateto   Off or OffLS
  */
-VMMR3DECL(int)   VMR3PowerOff(PVM pVM)
-{
-    LogFlow(("VMR3PowerOff: pVM=%p\n", pVM));
+VMMR3DECL(int)   VMR3PowerOff(PUVM pUVM)
+{
+    LogFlow(("VMR3PowerOff: pUVM=%p\n", pUVM));
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
 
@@ -2325,18 +2316,21 @@
  * @vmstateto   N/A
  */
-VMMR3DECL(int) VMR3Destroy(PVM pVM)
-{
-    LogFlow(("VMR3Destroy: pVM=%p\n", pVM));
+VMMR3DECL(int) VMR3Destroy(PUVM pUVM)
+{
+    LogFlow(("VMR3Destroy: pUVM=%p\n", pUVM));
 
     /*
      * Validate input.
      */
-    if (!pVM)
+    if (!pUVM)
         return VERR_INVALID_VM_HANDLE;
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     AssertLogRelReturn(!VM_IS_EMT(pVM), VERR_VM_THREAD_IS_EMT);
 
     /*
-     * Change VM state to destroying and unlink the VM.
+     * Change VM state to destroying and aall vmR3Destroy on each of the EMTs
+     * ending with EMT(0) doing the bulk of the cleanup.
      */
     int rc = vmR3TrySetState(pVM, "VMR3Destroy", 1, VMSTATE_DESTROYING, VMSTATE_OFF);
@@ -2344,33 +2338,10 @@
         return rc;
 
-    /** @todo lock this when we start having multiple machines in a process... */
-    PUVM pUVM = pVM->pUVM; AssertPtr(pUVM);
-    if (g_pUVMsHead == pUVM)
-        g_pUVMsHead = pUVM->pNext;
-    else
-    {
-        PUVM pPrev = g_pUVMsHead;
-        while (pPrev && pPrev->pNext != pUVM)
-            pPrev = pPrev->pNext;
-        AssertMsgReturn(pPrev, ("pUVM=%p / pVM=%p  is INVALID!\n", pUVM, pVM), VERR_INVALID_PARAMETER);
-
-        pPrev->pNext = pUVM->pNext;
-    }
-    pUVM->pNext = NULL;
-
-    /*
-     * Notify registered at destruction listeners.
-     */
-    vmR3AtDtor(pVM);
-
-    /*
-     * 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). */
     rc = VMR3ReqCallWait(pVM, VMCPUID_ALL_REVERSE, (PFNRT)vmR3Destroy, 1, pVM);
     AssertLogRelRC(rc);
 
-    /* Wait for EMTs and destroy the UVM. */
+    /*
+     * Wait for EMTs to quit and destroy the UVM.
+     */
     vmR3DestroyUVM(pUVM, 30000);
 
@@ -2640,128 +2611,4 @@
 
 /**
- * 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.
- */
-VMMR3DECL(PVM) VMR3EnumVMs(PVM pVMPrev)
-{
-    /*
-     * This is quick and dirty. It has issues with VM being
-     * destroyed during the enumeration.
-     */
-    PUVM pNext;
-    if (pVMPrev)
-        pNext = pVMPrev->pUVM->pNext;
-    else
-        pNext = g_pUVMsHead;
-    return pNext ? pNext->pVM : NULL;
-}
-
-
-/**
- * Registers an at VM destruction callback.
- *
- * @returns VBox status code.
- * @param   pfnAtDtor       Pointer to callback.
- * @param   pvUser          User argument.
- */
-VMMR3DECL(int) VMR3AtDtorRegister(PFNVMATDTOR pfnAtDtor, void *pvUser)
-{
-    /*
-     * Check if already registered.
-     */
-    VM_ATDTOR_LOCK();
-    PVMATDTOR   pCur = g_pVMAtDtorHead;
-    while (pCur)
-    {
-        if (pfnAtDtor == pCur->pfnAtDtor)
-        {
-            VM_ATDTOR_UNLOCK();
-            AssertMsgFailed(("Already registered at destruction callback %p!\n", pfnAtDtor));
-            return VERR_INVALID_PARAMETER;
-        }
-
-        /* next */
-        pCur = pCur->pNext;
-    }
-    VM_ATDTOR_UNLOCK();
-
-    /*
-     * Allocate new entry.
-     */
-    PVMATDTOR   pVMAtDtor = (PVMATDTOR)RTMemAlloc(sizeof(*pVMAtDtor));
-    if (!pVMAtDtor)
-        return VERR_NO_MEMORY;
-
-    VM_ATDTOR_LOCK();
-    pVMAtDtor->pfnAtDtor = pfnAtDtor;
-    pVMAtDtor->pvUser    = pvUser;
-    pVMAtDtor->pNext     = g_pVMAtDtorHead;
-    g_pVMAtDtorHead      = pVMAtDtor;
-    VM_ATDTOR_UNLOCK();
-
-    return VINF_SUCCESS;
-}
-
-
-/**
- * Deregisters an at VM destruction callback.
- *
- * @returns VBox status code.
- * @param   pfnAtDtor       Pointer to callback.
- */
-VMMR3DECL(int) VMR3AtDtorDeregister(PFNVMATDTOR pfnAtDtor)
-{
-    /*
-     * Find it, unlink it and free it.
-     */
-    VM_ATDTOR_LOCK();
-    PVMATDTOR   pPrev = NULL;
-    PVMATDTOR   pCur = g_pVMAtDtorHead;
-    while (pCur)
-    {
-        if (pfnAtDtor == pCur->pfnAtDtor)
-        {
-            if (pPrev)
-                pPrev->pNext = pCur->pNext;
-            else
-                g_pVMAtDtorHead = pCur->pNext;
-            pCur->pNext = NULL;
-            VM_ATDTOR_UNLOCK();
-
-            RTMemFree(pCur);
-            return VINF_SUCCESS;
-        }
-
-        /* next */
-        pPrev = pCur;
-        pCur = pCur->pNext;
-    }
-    VM_ATDTOR_UNLOCK();
-
-    return VERR_INVALID_PARAMETER;
-}
-
-
-/**
- * Walks the list of at VM destructor callbacks.
- * @param   pVM     The VM which is about to be destroyed.
- */
-static void vmR3AtDtor(PVM pVM)
-{
-    /*
-     * Find it, unlink it and free it.
-     */
-    VM_ATDTOR_LOCK();
-    for (PVMATDTOR pCur = g_pVMAtDtorHead; pCur; pCur = pCur->pNext)
-        pCur->pfnAtDtor(pVM, pCur->pvUser);
-    VM_ATDTOR_UNLOCK();
-}
-
-
-/**
  * Worker which checks integrity of some internal structures.
  * This is yet another attempt to track down that AVL tree crash.
@@ -2914,9 +2761,11 @@
  *
  * @returns VBox status code.
- * @param   pVM     VM to reset.
- */
-VMMR3DECL(int) VMR3Reset(PVM pVM)
+ * @param   pUVM    The VM to reset.
+ */
+VMMR3DECL(int) VMR3Reset(PUVM pUVM)
 {
     LogFlow(("VMR3Reset:\n"));
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
 
@@ -3550,5 +3399,5 @@
  * @thread  Any thread.
  */
-VMMR3DECL(bool) VMR3TeleportedAndNotFullyResumedYet(PVM pVM)
+VMMR3_INT_DECL(bool) VMR3TeleportedAndNotFullyResumedYet(PVM pVM)
 {
     VM_ASSERT_VALID_EXT_RETURN(pVM, false);
@@ -3564,10 +3413,10 @@
  *
  * @returns VBox status code.
- * @param   pVM             Pointer to the VM.
+ * @param   pUVM            The VM handle.
  * @param   pfnAtState      Pointer to callback.
  * @param   pvUser          User argument.
  * @thread  Any.
  */
-VMMR3DECL(int) VMR3AtStateRegister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser)
+VMMR3DECL(int) VMR3AtStateRegister(PUVM pUVM, PFNVMATSTATE pfnAtState, void *pvUser)
 {
     LogFlow(("VMR3AtStateRegister: pfnAtState=%p pvUser=%p\n", pfnAtState, pvUser));
@@ -3577,10 +3426,9 @@
      */
     AssertPtrReturn(pfnAtState, VERR_INVALID_PARAMETER);
-    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
 
     /*
      * Allocate a new record.
      */
-    PUVM pUVM = pVM->pUVM;
     PVMATSTATE pNew = (PVMATSTATE)MMR3HeapAllocU(pUVM, MM_TAG_VM, sizeof(*pNew));
     if (!pNew)
@@ -3606,10 +3454,10 @@
  *
  * @returns VBox status code.
- * @param   pVM             Pointer to the VM.
+ * @param   pUVM            The VM handle.
  * @param   pfnAtState      Pointer to callback.
  * @param   pvUser          User argument.
  * @thread  Any.
  */
-VMMR3DECL(int) VMR3AtStateDeregister(PVM pVM, PFNVMATSTATE pfnAtState, void *pvUser)
+VMMR3DECL(int) VMR3AtStateDeregister(PUVM pUVM, PFNVMATSTATE pfnAtState, void *pvUser)
 {
     LogFlow(("VMR3AtStateDeregister: pfnAtState=%p pvUser=%p\n", pfnAtState, pvUser));
@@ -3619,7 +3467,6 @@
      */
     AssertPtrReturn(pfnAtState, VERR_INVALID_PARAMETER);
-    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
-
-    PUVM pUVM = pVM->pUVM;
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+
     RTCritSectEnter(&pUVM->vm.s.AtStateCritSect);
 
@@ -3676,26 +3523,10 @@
  *
  * @returns VBox status code.
- * @param   pVM             Pointer to the VM.
+ * @param   pUVM            The VM handle.
  * @param   pfnAtError      Pointer to callback.
  * @param   pvUser          User argument.
  * @thread  Any.
  */
-VMMR3DECL(int)   VMR3AtErrorRegister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser)
-{
-    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
-    return VMR3AtErrorRegisterU(pVM->pUVM, pfnAtError, pvUser);
-}
-
-
-/**
- * Registers a VM error callback.
- *
- * @returns VBox status code.
- * @param   pUVM            Pointer to the VM.
- * @param   pfnAtError      Pointer to callback.
- * @param   pvUser          User argument.
- * @thread  Any.
- */
-VMMR3DECL(int)   VMR3AtErrorRegisterU(PUVM pUVM, PFNVMATERROR pfnAtError, void *pvUser)
+VMMR3DECL(int)  VMR3AtErrorRegister(PUVM pUVM, PFNVMATERROR pfnAtError, void *pvUser)
 {
     LogFlow(("VMR3AtErrorRegister: pfnAtError=%p pvUser=%p\n", pfnAtError, pvUser));
@@ -3733,10 +3564,10 @@
  *
  * @returns VBox status code.
- * @param   pVM             Pointer to the VM.
+ * @param   pUVM            The VM handle.
  * @param   pfnAtError      Pointer to callback.
  * @param   pvUser          User argument.
  * @thread  Any.
  */
-VMMR3DECL(int) VMR3AtErrorDeregister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser)
+VMMR3DECL(int) VMR3AtErrorDeregister(PUVM pUVM, PFNVMATERROR pfnAtError, void *pvUser)
 {
     LogFlow(("VMR3AtErrorDeregister: pfnAtError=%p pvUser=%p\n", pfnAtError, pvUser));
@@ -3746,7 +3577,6 @@
      */
     AssertPtrReturn(pfnAtError, VERR_INVALID_PARAMETER);
-    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
-
-    PUVM pUVM = pVM->pUVM;
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+
     RTCritSectEnter(&pUVM->vm.s.AtErrorCritSect);
 
@@ -3818,5 +3648,5 @@
  * @thread  EMT.
  */
-VMMR3DECL(void) VMR3SetErrorWorker(PVM pVM)
+VMMR3_INT_DECL(void) VMR3SetErrorWorker(PVM pVM)
 {
     VM_ASSERT_EMT(pVM);
@@ -3866,22 +3696,7 @@
  *
  * @returns The error count.
- * @param   pVM             Pointer to the VM.
- */
-VMMR3DECL(uint32_t) VMR3GetErrorCount(PVM pVM)
-{
-    AssertPtrReturn(pVM, 0);
-    return VMR3GetErrorCountU(pVM->pUVM);
-}
-
-
-/**
- * Gets the number of errors raised via VMSetError.
- *
- * This can be used avoid double error messages.
- *
- * @returns The error count.
- * @param   pVM             Pointer to the VM.
- */
-VMMR3DECL(uint32_t) VMR3GetErrorCountU(PUVM pUVM)
+ * @param   pUVM            The VM handle.
+ */
+VMMR3_INT_DECL(uint32_t) VMR3GetErrorCount(PUVM pUVM)
 {
     AssertPtrReturn(pUVM, 0);
@@ -3977,5 +3792,5 @@
  * @thread  Any.
  */
-VMMR3DECL(int)   VMR3AtRuntimeErrorRegister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser)
+VMMR3DECL(int)   VMR3AtRuntimeErrorRegister(PUVM pUVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser)
 {
     LogFlow(("VMR3AtRuntimeErrorRegister: pfnAtRuntimeError=%p pvUser=%p\n", pfnAtRuntimeError, pvUser));
@@ -3985,10 +3800,9 @@
      */
     AssertPtrReturn(pfnAtRuntimeError, VERR_INVALID_PARAMETER);
-    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
 
     /*
      * Allocate a new record.
      */
-    PUVM pUVM = pVM->pUVM;
     PVMATRUNTIMEERROR pNew = (PVMATRUNTIMEERROR)MMR3HeapAllocU(pUVM, MM_TAG_VM, sizeof(*pNew));
     if (!pNew)
@@ -4014,10 +3828,10 @@
  *
  * @returns VBox status code.
- * @param   pVM                 Pointer to the VM.
+ * @param   pUVM                The user mode VM handle.
  * @param   pfnAtRuntimeError   Pointer to callback.
  * @param   pvUser              User argument.
  * @thread  Any.
  */
-VMMR3DECL(int)   VMR3AtRuntimeErrorDeregister(PVM pVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser)
+VMMR3DECL(int) VMR3AtRuntimeErrorDeregister(PUVM pUVM, PFNVMATRUNTIMEERROR pfnAtRuntimeError, void *pvUser)
 {
     LogFlow(("VMR3AtRuntimeErrorDeregister: pfnAtRuntimeError=%p pvUser=%p\n", pfnAtRuntimeError, pvUser));
@@ -4027,7 +3841,6 @@
      */
     AssertPtrReturn(pfnAtRuntimeError, VERR_INVALID_PARAMETER);
-    VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
-
-    PUVM pUVM = pVM->pUVM;
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+
     RTCritSectEnter(&pUVM->vm.s.AtErrorCritSect);
 
@@ -4142,5 +3955,5 @@
                                 vmR3SetRuntimeErrorChangeState, NULL);
     else if (fFlags & VMSETRTERR_FLAGS_SUSPEND)
-        rc = VMR3Suspend(pVM);
+        rc = VMR3Suspend(pVM->pUVM);
     else
         rc = VINF_SUCCESS;
@@ -4188,5 +4001,5 @@
  * @thread  EMT.
  */
-VMMR3DECL(int) VMR3SetRuntimeErrorWorker(PVM pVM)
+VMMR3_INT_DECL(int) VMR3SetRuntimeErrorWorker(PVM pVM)
 {
     VM_ASSERT_EMT(pVM);
@@ -4286,20 +4099,20 @@
  *
  * @returns The runtime error count.
+ * @param   pUVM            The user mode VM handle.
+ */
+VMMR3_INT_DECL(uint32_t) VMR3GetRuntimeErrorCount(PUVM pUVM)
+{
+    return pUVM->vm.s.cRuntimeErrors;
+}
+
+
+/**
+ * Gets the ID virtual of the virtual CPU associated with the calling thread.
+ *
+ * @returns The CPU ID. NIL_VMCPUID if the thread isn't an EMT.
+ *
  * @param   pVM             Pointer to the VM.
  */
-VMMR3DECL(uint32_t) VMR3GetRuntimeErrorCount(PVM pVM)
-{
-    return pVM->pUVM->vm.s.cRuntimeErrors;
-}
-
-
-/**
- * Gets the ID virtual of the virtual CPU associated with the calling thread.
- *
- * @returns The CPU ID. NIL_VMCPUID if the thread isn't an EMT.
- *
- * @param   pVM             Pointer to the VM.
- */
-VMMR3DECL(RTCPUID) VMR3GetVMCPUId(PVM pVM)
+VMMR3_INT_DECL(RTCPUID) VMR3GetVMCPUId(PVM pVM)
 {
     PUVMCPU pUVCpu = (PUVMCPU)RTTlsGet(pVM->pUVM->vm.s.idxTLS);
@@ -4350,10 +4163,10 @@
  *
  * @returns Handle if this is an EMT thread; NIL_RTNATIVETHREAD otherwise
- * @param   pVM             Pointer to the VM.
+ * @param   pUVM            The user mode VM handle.
  * @thread  EMT
  */
-VMMR3DECL(RTTHREAD) VMR3GetVMCPUThread(PVM pVM)
-{
-    PUVMCPU pUVCpu = (PUVMCPU)RTTlsGet(pVM->pUVM->vm.s.idxTLS);
+VMMR3DECL(RTTHREAD) VMR3GetVMCPUThread(PUVM pUVM)
+{
+    PUVMCPU pUVCpu = (PUVMCPU)RTTlsGet(pUVM->vm.s.idxTLS);
 
     if (!pUVCpu)
@@ -4365,26 +4178,8 @@
 
 /**
- * Returns the handle of the current EMT VMCPU thread.
- *
- * @returns Handle if this is an EMT thread; NIL_RTNATIVETHREAD otherwise
- * @param   pVM             Pointer to the VM.
- * @thread  EMT
- */
-VMMR3DECL(RTTHREAD) VMR3GetVMCPUThreadU(PUVM pUVM)
-{
-    PUVMCPU pUVCpu = (PUVMCPU)RTTlsGet(pUVM->vm.s.idxTLS);
-
-    if (!pUVCpu)
-        return NIL_RTTHREAD;
-
-    return pUVCpu->vm.s.ThreadEMT;
-}
-
-
-/**
- * Return the package and core id of a CPU.
+ * Return the package and core ID of a CPU.
  *
  * @returns VBOX status code.
- * @param   pVM              Pointer to the VM.
+ * @param   pUVM             The user mode VM handle.
  * @param   idCpu            Virtual CPU to get the ID from.
  * @param   pidCpuCore       Where to store the core ID of the virtual CPU.
@@ -4392,9 +4187,11 @@
  *
  */
-VMMR3DECL(int) VMR3GetCpuCoreAndPackageIdFromCpuId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage)
+VMMR3DECL(int) VMR3GetCpuCoreAndPackageIdFromCpuId(PUVM pUVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage)
 {
     /*
      * Validate input.
      */
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     AssertPtrReturn(pidCpuCore, VERR_INVALID_POINTER);
@@ -4452,9 +4249,11 @@
  *
  * @returns VBox status code.
- * @param   pVM     Pointer to the VM.
+ * @param   pUVM    The user mode VM handle.
  * @param   idCpu   Virtual CPU to perform the hot unplugging operation on.
  */
-VMMR3DECL(int) VMR3HotUnplugCpu(PVM pVM, VMCPUID idCpu)
-{
+VMMR3DECL(int) VMR3HotUnplugCpu(PUVM pUVM, VMCPUID idCpu)
+{
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
@@ -4464,5 +4263,5 @@
      *        offline and send it to SPIP wait.  Maybe modify VMCPUSTATE and push
      *        it out of the EM loops when offline. */
-    return VMR3ReqCallNoWait(pVM, idCpu, (PFNRT)vmR3HotUnplugCpu, 2, pVM, idCpu);
+    return VMR3ReqCallNoWaitU(pUVM, idCpu, (PFNRT)vmR3HotUnplugCpu, 2, pVM, idCpu);
 }
 
@@ -4472,9 +4271,11 @@
  *
  * @returns VBox status code.
- * @param   pVM     Pointer to the VM.
+ * @param   pUVM    The user mode VM handle.
  * @param   idCpu   Virtual CPU to perform the hot plugging operation on.
  */
-VMMR3DECL(int) VMR3HotPlugCpu(PVM pVM, VMCPUID idCpu)
-{
+VMMR3DECL(int) VMR3HotPlugCpu(PUVM pUVM, VMCPUID idCpu)
+{
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID);
@@ -4493,6 +4294,8 @@
  *                              100 is max performance (default).
  */
-VMMR3DECL(int) VMR3SetCpuExecutionCap(PVM pVM, uint32_t uCpuExecutionCap)
-{
+VMMR3DECL(int) VMR3SetCpuExecutionCap(PUVM pUVM, uint32_t uCpuExecutionCap)
+{
+    UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
+    PVM pVM = pUVM->pVM;
     VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
     AssertReturn(uCpuExecutionCap > 0 && uCpuExecutionCap <= 100, VERR_INVALID_PARAMETER);
Index: trunk/src/VBox/VMM/VMMR3/VMEmt.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/VMEmt.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/VMEmt.cpp	(revision 44340)
@@ -195,5 +195,5 @@
                  * Service a delayed reset request.
                  */
-                rc = VMR3Reset(pVM);
+                rc = VMR3Reset(pVM->pUVM);
                 VM_FF_CLEAR(pVM, VM_FF_RESET);
                 Log(("vmR3EmulationThread: Reset rc=%Rrc, VM state %s -> %s\n", rc, VMR3GetStateName(enmBefore), VMR3GetStateName(pVM->enmVMState)));
@@ -1002,6 +1002,7 @@
  * @param   pUVM            Pointer to the user mode VM structure.
  * @param   fFlags          Notification flags, VMNOTIFYFF_FLAGS_*.
- */
-VMMR3DECL(void) VMR3NotifyGlobalFFU(PUVM pUVM, uint32_t fFlags)
+ * @internal
+ */
+VMMR3_INT_DECL(void) VMR3NotifyGlobalFFU(PUVM pUVM, uint32_t fFlags)
 {
     LogFlow(("VMR3NotifyGlobalFFU:\n"));
@@ -1024,6 +1025,7 @@
  * @param   pUVM            Pointer to the user mode VM structure.
  * @param   fFlags          Notification flags, VMNOTIFYFF_FLAGS_*.
- */
-VMMR3DECL(void) VMR3NotifyCpuFFU(PUVMCPU pUVCpu, uint32_t fFlags)
+ * @internal
+ */
+VMMR3_INT_DECL(void) VMR3NotifyCpuFFU(PUVMCPU pUVCpu, uint32_t fFlags)
 {
     PUVM pUVM = pUVCpu->pUVM;
@@ -1044,6 +1046,7 @@
  * @param   fIgnoreInterrupts   If set the VM_FF_INTERRUPT flags is ignored.
  * @thread  The emulation thread.
- */
-VMMR3DECL(int) VMR3WaitHalted(PVM pVM, PVMCPU pVCpu, bool fIgnoreInterrupts)
+ * @internal
+ */
+VMMR3_INT_DECL(int) VMR3WaitHalted(PVM pVM, PVMCPU pVCpu, bool fIgnoreInterrupts)
 {
     LogFlow(("VMR3WaitHalted: fIgnoreInterrupts=%d\n", fIgnoreInterrupts));
@@ -1123,6 +1126,7 @@
  * @param   pUVCpu          Pointer to the user mode VMCPU structure.
  * @thread  The emulation thread.
- */
-VMMR3DECL(int) VMR3WaitU(PUVMCPU pUVCpu)
+ * @internal
+ */
+VMMR3_INT_DECL(int) VMR3WaitU(PUVMCPU pUVCpu)
 {
     LogFlow(("VMR3WaitU:\n"));
Index: trunk/src/VBox/VMM/VMMR3/VMM.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/VMM.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/VMM.cpp	(revision 44340)
@@ -1680,4 +1680,5 @@
      * Validate input.
      */
+    AssertReturn(pVM, VERR_INVALID_VM_HANDLE);
     AssertMsg(   (fFlags & VMMEMTRENDEZVOUS_FLAGS_TYPE_MASK) != VMMEMTRENDEZVOUS_FLAGS_TYPE_INVALID
               && (fFlags & VMMEMTRENDEZVOUS_FLAGS_TYPE_MASK) <= VMMEMTRENDEZVOUS_FLAGS_TYPE_DESCENDING
Index: trunk/src/VBox/VMM/VMMR3/VMReq.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMR3/VMReq.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/VMMR3/VMReq.cpp	(revision 44340)
@@ -45,43 +45,4 @@
 
 /**
- * Allocate and queue a call request.
- *
- * If it's desired to poll on the completion of the request set cMillies
- * to 0 and use VMR3ReqWait() to check for completion. In the other case
- * use RT_INDEFINITE_WAIT.
- * The returned request packet must be freed using VMR3ReqFree().
- *
- * @returns VBox status code.
- *          Will not return VERR_INTERRUPTED.
- * @returns VERR_TIMEOUT if cMillies was reached without the packet being completed.
- *
- * @param   pVM             Pointer to the VM.
- * @param   idDstCpu        The destination CPU(s). Either a specific CPU ID or
- *                          one of the following special values:
- *                              VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
- * @param   ppReq           Where to store the pointer to the request.
- *                          This will be NULL or a valid request pointer not matter what happens.
- * @param   cMillies        Number of milliseconds to wait for the request to
- *                          be completed. Use RT_INDEFINITE_WAIT to only
- *                          wait till it's completed.
- * @param   fFlags          A combination of the VMREQFLAGS values.
- * @param   pfnFunction     Pointer to the function to call.
- * @param   cArgs           Number of arguments following in the ellipsis.
- * @param   ...             Function arguments.
- *
- * @remarks See remarks on VMR3ReqCallVU.
- */
-VMMR3DECL(int) VMR3ReqCall(PVM pVM, VMCPUID idDstCpu, PVMREQ *ppReq, RTMSINTERVAL cMillies, uint32_t fFlags,
-                           PFNRT pfnFunction, unsigned cArgs, ...)
-{
-    va_list va;
-    va_start(va, cArgs);
-    int rc = VMR3ReqCallVU(pVM->pUVM, idDstCpu, ppReq, cMillies, fFlags, pfnFunction, cArgs, va);
-    va_end(va);
-    return rc;
-}
-
-
-/**
  * Convenience wrapper for VMR3ReqCallU.
  *
@@ -103,6 +64,7 @@
  *
  * @remarks See remarks on VMR3ReqCallVU.
- */
-VMMR3DECL(int) VMR3ReqCallWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
+ * @internal
+ */
+VMMR3_INT_DECL(int) VMR3ReqCallWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
 {
     PVMREQ pReq;
@@ -122,8 +84,11 @@
  * Convenience wrapper for VMR3ReqCallU.
  *
- * This assumes (1) you're calling a function that returns an VBox status code
- * and that you do not wish to wait for it to complete.
- *
- * @returns VBox status code returned by VMR3ReqCallVU.
+ * This assumes (1) you're calling a function that returns an VBox status code,
+ * (2) that you want it's return code on success, and (3) that you wish to wait
+ * for ever for it to return.
+ *
+ * @returns VBox status code.  In the unlikely event that VMR3ReqCallVU fails,
+ *          its status code is return.  Otherwise, the status of pfnFunction is
+ *          returned.
  *
  * @param   pVM             Pointer to the VM.
@@ -136,12 +101,17 @@
  *
  * @remarks See remarks on VMR3ReqCallVU.
- */
-VMMR3DECL(int) VMR3ReqCallNoWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
-{
+ * @internal
+ */
+VMMR3DECL(int) VMR3ReqCallWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
+{
+    PVMREQ pReq;
     va_list va;
     va_start(va, cArgs);
-    int rc = VMR3ReqCallVU(pVM->pUVM, idDstCpu, NULL, 0, VMREQFLAGS_VBOX_STATUS | VMREQFLAGS_NO_WAIT,
+    int rc = VMR3ReqCallVU(pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VBOX_STATUS,
                            pfnFunction, cArgs, va);
     va_end(va);
+    if (RT_SUCCESS(rc))
+        rc = pReq->iStatus;
+    VMR3ReqFree(pReq);
     return rc;
 }
@@ -151,8 +121,8 @@
  * Convenience wrapper for VMR3ReqCallU.
  *
- * This assumes (1) you're calling a function that returns void, and (2) that
- * you wish to wait for ever for it to return.
- *
- * @returns VBox status code of VMR3ReqCallVU.
+ * This assumes (1) you're calling a function that returns an VBox status code
+ * and that you do not wish to wait for it to complete.
+ *
+ * @returns VBox status code returned by VMR3ReqCallVU.
  *
  * @param   pVM             Pointer to the VM.
@@ -165,6 +135,66 @@
  *
  * @remarks See remarks on VMR3ReqCallVU.
- */
-VMMR3DECL(int) VMR3ReqCallVoidWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
+ * @internal
+ */
+VMMR3DECL(int) VMR3ReqCallNoWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
+{
+    va_list va;
+    va_start(va, cArgs);
+    int rc = VMR3ReqCallVU(pVM->pUVM, idDstCpu, NULL, 0, VMREQFLAGS_VBOX_STATUS | VMREQFLAGS_NO_WAIT,
+                           pfnFunction, cArgs, va);
+    va_end(va);
+    return rc;
+}
+
+
+/**
+ * Convenience wrapper for VMR3ReqCallU.
+ *
+ * This assumes (1) you're calling a function that returns an VBox status code
+ * and that you do not wish to wait for it to complete.
+ *
+ * @returns VBox status code returned by VMR3ReqCallVU.
+ *
+ * @param   pUVM            Pointer to the VM.
+ * @param   idDstCpu        The destination CPU(s). Either a specific CPU ID or
+ *                          one of the following special values:
+ *                              VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
+ * @param   pfnFunction     Pointer to the function to call.
+ * @param   cArgs           Number of arguments following in the ellipsis.
+ * @param   ...             Function arguments.
+ *
+ * @remarks See remarks on VMR3ReqCallVU.
+ */
+VMMR3DECL(int) VMR3ReqCallNoWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
+{
+    va_list va;
+    va_start(va, cArgs);
+    int rc = VMR3ReqCallVU(pUVM, idDstCpu, NULL, 0, VMREQFLAGS_VBOX_STATUS | VMREQFLAGS_NO_WAIT,
+                           pfnFunction, cArgs, va);
+    va_end(va);
+    return rc;
+}
+
+
+/**
+ * Convenience wrapper for VMR3ReqCallU.
+ *
+ * This assumes (1) you're calling a function that returns void, and (2) that
+ * you wish to wait for ever for it to return.
+ *
+ * @returns VBox status code of VMR3ReqCallVU.
+ *
+ * @param   pVM             Pointer to the VM.
+ * @param   idDstCpu        The destination CPU(s). Either a specific CPU ID or
+ *                          one of the following special values:
+ *                              VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
+ * @param   pfnFunction     Pointer to the function to call.
+ * @param   cArgs           Number of arguments following in the ellipsis.
+ * @param   ...             Function arguments.
+ *
+ * @remarks See remarks on VMR3ReqCallVU.
+ * @internal
+ */
+VMMR3_INT_DECL(int) VMR3ReqCallVoidWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
 {
     PVMREQ pReq;
@@ -183,4 +213,35 @@
  *
  * This assumes (1) you're calling a function that returns void, and (2) that
+ * you wish to wait for ever for it to return.
+ *
+ * @returns VBox status code of VMR3ReqCallVU.
+ *
+ * @param   pUVM            Pointer to the VM.
+ * @param   idDstCpu        The destination CPU(s). Either a specific CPU ID or
+ *                          one of the following special values:
+ *                              VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
+ * @param   pfnFunction     Pointer to the function to call.
+ * @param   cArgs           Number of arguments following in the ellipsis.
+ * @param   ...             Function arguments.
+ *
+ * @remarks See remarks on VMR3ReqCallVU.
+ */
+VMMR3DECL(int) VMR3ReqCallVoidWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
+{
+    PVMREQ pReq;
+    va_list va;
+    va_start(va, cArgs);
+    int rc = VMR3ReqCallVU(pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VOID,
+                           pfnFunction, cArgs, va);
+    va_end(va);
+    VMR3ReqFree(pReq);
+    return rc;
+}
+
+
+/**
+ * Convenience wrapper for VMR3ReqCallU.
+ *
+ * This assumes (1) you're calling a function that returns void, and (2) that
  * you do not wish to wait for it to complete.
  *
@@ -196,4 +257,5 @@
  *
  * @remarks See remarks on VMR3ReqCallVU.
+ * @internal
  */
 VMMR3DECL(int) VMR3ReqCallVoidNoWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
@@ -231,4 +293,5 @@
  *
  * @remarks See remarks on VMR3ReqCallVU.
+ * @internal
  */
 VMMR3DECL(int) VMR3ReqPriorityCallWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
@@ -250,11 +313,14 @@
  * Convenience wrapper for VMR3ReqCallU.
  *
- * This assumes (1) you're calling a function that returns void, (2) that you
- * wish to wait for ever for it to return, and (3) that it's priority request
- * that can be safely be handled during async suspend and power off.
- *
- * @returns VBox status code of VMR3ReqCallVU.
- *
- * @param   pVM             Pointer to the VM.
+ * This assumes (1) you're calling a function that returns an VBox status code,
+ * (2) that you want it's return code on success, (3) that you wish to wait for
+ * ever for it to return, and (4) that it's priority request that can be safely
+ * be handled during async suspend and power off.
+ *
+ * @returns VBox status code.  In the unlikely event that VMR3ReqCallVU fails,
+ *          its status code is return.  Otherwise, the status of pfnFunction is
+ *          returned.
+ *
+ * @param   pUVM            The user mode VM handle.
  * @param   idDstCpu        The destination CPU(s). Either a specific CPU ID or
  *                          one of the following special values:
@@ -266,10 +332,44 @@
  * @remarks See remarks on VMR3ReqCallVU.
  */
-VMMR3DECL(int) VMR3ReqPriorityCallVoidWait(PVM pVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
+VMMR3DECL(int) VMR3ReqPriorityCallWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
 {
     PVMREQ pReq;
     va_list va;
     va_start(va, cArgs);
-    int rc = VMR3ReqCallVU(pVM->pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VOID | VMREQFLAGS_PRIORITY,
+    int rc = VMR3ReqCallVU(pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VBOX_STATUS | VMREQFLAGS_PRIORITY,
+                           pfnFunction, cArgs, va);
+    va_end(va);
+    if (RT_SUCCESS(rc))
+        rc = pReq->iStatus;
+    VMR3ReqFree(pReq);
+    return rc;
+}
+
+
+/**
+ * Convenience wrapper for VMR3ReqCallU.
+ *
+ * This assumes (1) you're calling a function that returns void, (2) that you
+ * wish to wait for ever for it to return, and (3) that it's priority request
+ * that can be safely be handled during async suspend and power off.
+ *
+ * @returns VBox status code of VMR3ReqCallVU.
+ *
+ * @param   pUVM            The user mode VM handle.
+ * @param   idDstCpu        The destination CPU(s). Either a specific CPU ID or
+ *                          one of the following special values:
+ *                              VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
+ * @param   pfnFunction     Pointer to the function to call.
+ * @param   cArgs           Number of arguments following in the ellipsis.
+ * @param   ...             Function arguments.
+ *
+ * @remarks See remarks on VMR3ReqCallVU.
+ */
+VMMR3DECL(int) VMR3ReqPriorityCallVoidWaitU(PUVM pUVM, VMCPUID idDstCpu, PFNRT pfnFunction, unsigned cArgs, ...)
+{
+    PVMREQ pReq;
+    va_list va;
+    va_start(va, cArgs);
+    int rc = VMR3ReqCallVU(pUVM, idDstCpu, &pReq, RT_INDEFINITE_WAIT, VMREQFLAGS_VOID | VMREQFLAGS_PRIORITY,
                            pfnFunction, cArgs, va);
     va_end(va);
@@ -380,5 +480,5 @@
      * Allocate request
      */
-    int rc = VMR3ReqAllocU(pUVM, &pReq, VMREQTYPE_INTERNAL, idDstCpu);
+    int rc = VMR3ReqAlloc(pUVM, &pReq, VMREQTYPE_INTERNAL, idDstCpu);
     if (RT_FAILURE(rc))
         return rc;
@@ -478,25 +578,4 @@
  * @returns VBox status code.
  *
- * @param   pVM             Pointer to the VM.
- * @param   ppReq           Where to store the pointer to the allocated packet.
- * @param   enmType         Package type.
- * @param   idDstCpu        The destination CPU(s). Either a specific CPU ID or
- *                          one of the following special values:
- *                              VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
- */
-VMMR3DECL(int) VMR3ReqAlloc(PVM pVM, PVMREQ *ppReq, VMREQTYPE enmType, VMCPUID idDstCpu)
-{
-    return VMR3ReqAllocU(pVM->pUVM, ppReq, enmType, idDstCpu);
-}
-
-
-/**
- * Allocates a request packet.
- *
- * The caller allocates a request packet, fills in the request data
- * union and queues the request.
- *
- * @returns VBox status code.
- *
  * @param   pUVM            Pointer to the user mode VM structure.
  * @param   ppReq           Where to store the pointer to the allocated packet.
@@ -506,5 +585,5 @@
  *                              VMCPUID_ANY, VMCPUID_ANY_QUEUE, VMCPUID_ALL or VMCPUID_ALL_REVERSE.
  */
-VMMR3DECL(int) VMR3ReqAllocU(PUVM pUVM, PVMREQ *ppReq, VMREQTYPE enmType, VMCPUID idDstCpu)
+VMMR3DECL(int) VMR3ReqAlloc(PUVM pUVM, PVMREQ *ppReq, VMREQTYPE enmType, VMCPUID idDstCpu)
 {
     /*
@@ -1021,6 +1100,7 @@
  * @remarks This was made reentrant for async PDM handling, the debugger and
  *          others.
- */
-VMMR3DECL(int) VMR3ReqProcessU(PUVM pUVM, VMCPUID idDstCpu, bool fPriorityOnly)
+ * @internal
+ */
+VMMR3_INT_DECL(int) VMR3ReqProcessU(PUVM pUVM, VMCPUID idDstCpu, bool fPriorityOnly)
 {
     LogFlow(("VMR3ReqProcessU: (enmVMState=%d) idDstCpu=%d\n", pUVM->pVM ? pUVM->pVM->enmVMState : VMSTATE_CREATING, idDstCpu));
Index: trunk/src/VBox/VMM/include/internal/em.h
===================================================================
--- trunk/src/VBox/VMM/include/internal/em.h	(revision 44339)
+++ 	(revision )
@@ -1,28 +1,0 @@
-/* $Id$ */
-/** @file
- * EM - Internal VMM header file.
- */
-
-/*
- * 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;
- * you can redistribute it and/or modify it under the terms of the GNU
- * 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.
- */
-
-#ifndef ___EM_include_internal_h
-#define ___EM_include_internal_h
-
-#include <VBox/vmm/em.h>
-
-VMMR3DECL(int)  EMR3NotifyResume(PVM pVM);
-VMMR3DECL(int)  EMR3NotifySuspend(PVM pVM);
-
-VMMR3DECL(bool) EMR3IsExecutionAllowed(PVM pVM, PVMCPU pVCpu);
-
-#endif
Index: trunk/src/VBox/VMM/include/internal/vm.h
===================================================================
--- trunk/src/VBox/VMM/include/internal/vm.h	(revision 44339)
+++ 	(revision )
@@ -1,26 +1,0 @@
-/* $Id$ */
-/** @file
- * VM - Internal VMM header file.
- */
-
-/*
- * 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;
- * you can redistribute it and/or modify it under the terms of the GNU
- * 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.
- */
-
-#ifndef ___VM_include_internal_h
-#define ___VM_include_internal_h
-
-#include <VBox/vmm/vm.h>
-
-VMMR3DECL(int) VMR3SaveFT(PVM pVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser, bool *pfSuspended, bool fSkipStateChanges);
-VMMR3DECL(int) VMR3LoadFromStreamFT(PVM pVM, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser);
-
-#endif
Index: trunk/src/VBox/VMM/testcase/tstAnimate.cpp
===================================================================
--- trunk/src/VBox/VMM/testcase/tstAnimate.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/testcase/tstAnimate.cpp	(revision 44340)
@@ -832,5 +832,6 @@
      */
     PVM pVM;
-    rc = VMR3Create(1, NULL, NULL, NULL, cfgmR3CreateDefault, &cbMem, &pVM);
+    PUVM pUVM;
+    rc = VMR3Create(1, NULL, NULL, NULL, cfgmR3CreateDefault, &cbMem, &pVM, &pUVM);
     if (RT_SUCCESS(rc))
     {
@@ -839,9 +840,9 @@
          */
         if (FileRawMem != NIL_RTFILE)
-            rc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)loadMem, 3, pVM, FileRawMem, &offRawMem);
+            rc = VMR3ReqCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)loadMem, 3, pVM, FileRawMem, &offRawMem);
         else
-            rc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)SSMR3Load,
-                                 7, pVM, pszSavedState, (uintptr_t)NULL /*pStreamOps*/, (uintptr_t)NULL /*pvUser*/,
-                                 SSMAFTER_DEBUG_IT, (uintptr_t)NULL /*pfnProgress*/, (uintptr_t)NULL /*pvProgressUser*/);
+            rc = VMR3ReqCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)SSMR3Load,
+                                  7, pVM, pszSavedState, (uintptr_t)NULL /*pStreamOps*/, (uintptr_t)NULL /*pvUser*/,
+                                  SSMAFTER_DEBUG_IT, (uintptr_t)NULL /*pfnProgress*/, (uintptr_t)NULL /*pvProgressUser*/);
         if (RT_SUCCESS(rc))
         {
@@ -850,5 +851,5 @@
              */
             if (FileScript != NIL_RTFILE)
-                rc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)scriptRun, 2, pVM, FileScript);
+                rc = VMR3ReqCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)scriptRun, 2, pVM, FileScript);
             if (RT_SUCCESS(rc))
             {
@@ -882,5 +883,5 @@
                         DBGFR3Info(pVM, "cpumguest", "verbose", NULL);
                         if (fPowerOn)
-                            rc = VMR3PowerOn(pVM);
+                            rc = VMR3PowerOn(pUVM);
                         if (RT_SUCCESS(rc))
                         {
@@ -918,5 +919,5 @@
          * Cleanup.
          */
-        rc = VMR3Destroy(pVM);
+        rc = VMR3Destroy(pUVM);
         if (!RT_SUCCESS(rc))
         {
@@ -924,4 +925,6 @@
             rcRet++;
         }
+
+        VMR3ReleaseUVM(pUVM);
     }
     else
Index: trunk/src/VBox/VMM/testcase/tstMicro.cpp
===================================================================
--- trunk/src/VBox/VMM/testcase/tstMicro.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/testcase/tstMicro.cpp	(revision 44340)
@@ -347,5 +347,6 @@
      */
     PVM pVM;
-    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, &pVM);
+    PUVM pUVM;
+    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, &pVM, &pUVM);
     if (RT_SUCCESS(rc))
     {
@@ -353,5 +354,5 @@
          * Do testing.
          */
-        rc = VMR3ReqCallVoidWait(pVM, VMCPUID_ANY, (PFNRT)doit, 1, pVM);
+        rc = VMR3ReqCallVoidWaitU(pUVM, VMCPUID_ANY, (PFNRT)doit, 1, pVM);
         AssertRC(rc);
         STAMR3Dump(pVM, "*");
@@ -360,5 +361,5 @@
          * Cleanup.
          */
-        rc = VMR3PowerOff(pVM);
+        rc = VMR3PowerOff(pUVM);
         if (!RT_SUCCESS(rc))
         {
@@ -366,5 +367,5 @@
             rcRet++;
         }
-        rc = VMR3Destroy(pVM);
+        rc = VMR3Destroy(pUVM);
         if (!RT_SUCCESS(rc))
         {
@@ -372,4 +373,5 @@
             rcRet++;
         }
+        VMR3ReleaseUVM(pUVM);
     }
     else
Index: trunk/src/VBox/VMM/testcase/tstPDMAsyncCompletion.cpp
===================================================================
--- trunk/src/VBox/VMM/testcase/tstPDMAsyncCompletion.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/testcase/tstPDMAsyncCompletion.cpp	(revision 44340)
@@ -87,9 +87,8 @@
 
     PVM pVM;
-    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, &pVM);
+    PUVM pUVM;
+    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, &pVM, &pUVM);
     if (RT_SUCCESS(rc))
     {
-        PPDMASYNCCOMPLETIONTEMPLATE pTemplate;
-
         /*
          * Little hack to avoid the VM_ASSERT_EMT assertion.
@@ -102,4 +101,5 @@
          * Create the template.
          */
+        PPDMASYNCCOMPLETIONTEMPLATE pTemplate;
         rc = PDMR3AsyncCompletionTemplateCreateInternal(pVM, &pTemplate, pfnAsyncTaskCompleted, NULL, "Test");
         if (RT_FAILURE(rc))
@@ -236,6 +236,7 @@
         }
 
-        rc = VMR3Destroy(pVM);
+        rc = VMR3Destroy(pUVM);
         AssertMsg(rc == VINF_SUCCESS, ("%s: Destroying VM failed rc=%Rrc!!\n", __FUNCTION__, rc));
+        VMR3ReleaseUVM(pUVM);
 
         /*
Index: trunk/src/VBox/VMM/testcase/tstPDMAsyncCompletionStress.cpp
===================================================================
--- trunk/src/VBox/VMM/testcase/tstPDMAsyncCompletionStress.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/testcase/tstPDMAsyncCompletionStress.cpp	(revision 44340)
@@ -575,5 +575,6 @@
 
     PVM pVM;
-    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, &pVM);
+    PUVM pUVM;
+    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, &pVM, &pUVM);
     if (RT_SUCCESS(rc))
     {
@@ -617,5 +618,5 @@
         }
 
-        rc = VMR3Destroy(pVM);
+        rc = VMR3Destroy(pUVM);
         AssertMsg(rc == VINF_SUCCESS, ("%s: Destroying VM failed rc=%Rrc!!\n", __FUNCTION__, rc));
     }
Index: trunk/src/VBox/VMM/testcase/tstVMM-HM.cpp
===================================================================
--- trunk/src/VBox/VMM/testcase/tstVMM-HM.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/testcase/tstVMM-HM.cpp	(revision 44340)
@@ -84,5 +84,6 @@
     RTPrintf(TESTCASE ": Initializing...\n");
     PVM pVM;
-    int rc = VMR3Create(1, NULL, NULL, NULL, CFGMConstructor, NULL, &pVM);
+    PUVM pUVM;
+    int rc = VMR3Create(1, NULL, NULL, NULL, CFGMConstructor, NULL, &pVM, &pUVM);
     if (RT_SUCCESS(rc))
     {
@@ -91,5 +92,5 @@
          */
         RTPrintf(TESTCASE ": Testing...\n");
-        rc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)VMMDoHmTest, 1, pVM);
+        rc = VMR3ReqCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)VMMDoHmTest, 1, pVM);
         AssertRC(rc);
 
@@ -99,5 +100,5 @@
          * Cleanup.
          */
-        rc = VMR3Destroy(pVM);
+        rc = VMR3Destroy(pUVM);
         if (RT_FAILURE(rc))
         {
@@ -105,4 +106,5 @@
             rcRet++;
         }
+        VMR3ReleaseUVM(pUVM);
     }
     else
Index: trunk/src/VBox/VMM/testcase/tstVMM.cpp
===================================================================
--- trunk/src/VBox/VMM/testcase/tstVMM.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/testcase/tstVMM.cpp	(revision 44340)
@@ -248,5 +248,6 @@
     RTPrintf(TESTCASE ": Initializing...\n");
     PVM pVM;
-    rc = VMR3Create(g_cCpus, NULL, NULL, NULL, tstVMMConfigConstructor, NULL, &pVM);
+    PUVM pUVM;
+    rc = VMR3Create(g_cCpus, NULL, NULL, NULL, tstVMMConfigConstructor, NULL, &pVM, &pUVM);
     if (RT_SUCCESS(rc))
     {
@@ -263,5 +264,5 @@
             {
                 RTTestSub(hTest, "VMM");
-                rc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)VMMDoTest, 1, pVM);
+                rc = VMR3ReqCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)VMMDoTest, 1, pVM);
                 if (RT_FAILURE(rc))
                     RTTestFailed(hTest, "VMMDoTest failed: rc=%Rrc\n", rc);
@@ -274,10 +275,10 @@
                 for (VMCPUID idCpu = 1; idCpu < g_cCpus; idCpu++)
                 {
-                    rc = VMR3ReqCallNoWait(pVM, idCpu, (PFNRT)tstTMWorker, 2, pVM, hTest);
+                    rc = VMR3ReqCallNoWaitU(pUVM, idCpu, (PFNRT)tstTMWorker, 2, pVM, hTest);
                     if (RT_FAILURE(rc))
                         RTTestFailed(hTest, "VMR3ReqCall failed: rc=%Rrc\n", rc);
                 }
 
-                rc = VMR3ReqCallWait(pVM, 0 /*idDstCpu*/, (PFNRT)tstTMWorker, 2, pVM, hTest);
+                rc = VMR3ReqCallWaitU(pUVM, 0 /*idDstCpu*/, (PFNRT)tstTMWorker, 2, pVM, hTest);
                 if (RT_FAILURE(rc))
                     RTTestFailed(hTest, "VMMDoTest failed: rc=%Rrc\n", rc);
@@ -291,10 +292,11 @@
          * Cleanup.
          */
-        rc = VMR3PowerOff(pVM);
+        rc = VMR3PowerOff(pUVM);
         if (RT_FAILURE(rc))
             RTTestFailed(hTest, "VMR3PowerOff failed: rc=%Rrc\n", rc);
-        rc = VMR3Destroy(pVM);
+        rc = VMR3Destroy(pUVM);
         if (RT_FAILURE(rc))
             RTTestFailed(hTest, "VMR3Destroy failed: rc=%Rrc\n", rc);
+        VMR3ReleaseUVM(pUVM);
     }
     else
Index: trunk/src/VBox/VMM/testcase/tstVMMFork.cpp
===================================================================
--- trunk/src/VBox/VMM/testcase/tstVMMFork.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/testcase/tstVMMFork.cpp	(revision 44340)
@@ -67,5 +67,6 @@
     RTPrintf(TESTCASE ": Initializing...\n");
     PVM pVM;
-    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, &pVM);
+    PUVM pUVM;
+    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, &pVM, &pUVM);
     if (RT_SUCCESS(rc))
     {
@@ -132,5 +133,5 @@
                 RTPrintf(TESTCASE ": fork() returned fine.\n");
                 RTPrintf(TESTCASE ": testing VM after fork.\n");
-                VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)VMMDoTest, 1, pVM);
+                VMR3ReqCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)VMMDoTest, 1, pVM);
 
                 STAMR3Dump(pVM, "*");
@@ -146,5 +147,5 @@
          * Cleanup.
          */
-        rc = VMR3PowerOff(pVM);
+        rc = VMR3PowerOff(pUVM);
         if (!RT_SUCCESS(rc))
         {
@@ -152,5 +153,5 @@
             rcErrors++;
         }
-        rc = VMR3Destroy(pVM);
+        rc = VMR3Destroy(pUVM);
         if (!RT_SUCCESS(rc))
         {
@@ -158,4 +159,5 @@
             rcErrors++;
         }
+        VMR3ReleaseUVM(pUVM);
     }
     else
Index: trunk/src/VBox/VMM/testcase/tstVMREQ.cpp
===================================================================
--- trunk/src/VBox/VMM/testcase/tstVMREQ.cpp	(revision 44339)
+++ trunk/src/VBox/VMM/testcase/tstVMREQ.cpp	(revision 44340)
@@ -86,7 +86,7 @@
  * The function PassVA and PassVA2 calls.
  */
-static DECLCALLBACK(int) PassVACallback(PVM pVM, unsigned u4K, unsigned u1G, const char *pszFormat, va_list *pva)
-{
-    NOREF(pVM);
+static DECLCALLBACK(int) PassVACallback(PUVM pUVM, unsigned u4K, unsigned u1G, const char *pszFormat, va_list *pva)
+{
+    NOREF(pUVM);
     if (u4K != _4K)
     {
@@ -122,5 +122,5 @@
  * similar to VMSetRuntimeError.
  */
-static void PassVA2(PVM pVM, const char *pszFormat, va_list va)
+static void PassVA2(PUVM pUVM, const char *pszFormat, va_list va)
 {
 #if 0 /** @todo test if this is a GCC problem only or also happens with AMD64+VCC80... */
@@ -132,5 +132,5 @@
 #endif
 
-    int rc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)PassVACallback, 5, pVM, _4K, _1G, pszFormat, pvVA);
+    int rc = VMR3ReqCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)PassVACallback, 5, pUVM, _4K, _1G, pszFormat, pvVA);
     NOREF(rc);
 
@@ -145,10 +145,10 @@
  * similar to VMSetRuntimeError.
  */
-static void PassVA(PVM pVM, const char *pszFormat, ...)
+static void PassVA(PUVM pUVM, const char *pszFormat, ...)
 {
     /* 1st test */
     va_list va1;
     va_start(va1, pszFormat);
-    int rc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)PassVACallback, 5, pVM, _4K, _1G, pszFormat, &va1);
+    int rc = VMR3ReqCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)PassVACallback, 5, pUVM, _4K, _1G, pszFormat, &va1);
     va_end(va1);
     NOREF(rc);
@@ -157,5 +157,5 @@
     va_list va2;
     va_start(va2, pszFormat);
-    PassVA2(pVM, pszFormat, va2);
+    PassVA2(pUVM, pszFormat, va2);
     va_end(va2);
 }
@@ -168,5 +168,5 @@
 {
     int rc = VINF_SUCCESS;
-    PVM pVM = (PVM)pvUser;
+    PUVM pUVM = (PUVM)pvUser;
     NOREF(hThreadSelf);
 
@@ -178,5 +178,5 @@
         for (iReq = 0; iReq < cReqs; iReq++)
         {
-            rc = VMR3ReqAlloc(pVM, &apReq[iReq], VMREQTYPE_INTERNAL, VMCPUID_ANY);
+            rc = VMR3ReqAlloc(pUVM, &apReq[iReq], VMREQTYPE_INTERNAL, VMCPUID_ANY);
             if (RT_FAILURE(rc))
             {
@@ -219,6 +219,6 @@
      * Create empty VM.
      */
-    PVM pVM;
-    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, &pVM);
+    PUVM pUVM;
+    int rc = VMR3Create(1, NULL, NULL, NULL, NULL, NULL, NULL, &pUVM);
     if (RT_SUCCESS(rc))
     {
@@ -228,9 +228,9 @@
         uint64_t u64StartTS = RTTimeNanoTS();
         RTTHREAD Thread0;
-        rc = RTThreadCreate(&Thread0, Thread, pVM, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "REQ1");
+        rc = RTThreadCreate(&Thread0, Thread, pUVM, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "REQ1");
         if (RT_SUCCESS(rc))
         {
             RTTHREAD Thread1;
-            rc = RTThreadCreate(&Thread1, Thread, pVM, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "REQ1");
+            rc = RTThreadCreate(&Thread1, Thread, pUVM, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "REQ1");
             if (RT_SUCCESS(rc))
             {
@@ -273,5 +273,5 @@
          * Print stats.
          */
-        STAMR3Print(pVM, "/VM/Req/*");
+        STAMR3Print(VMR3GetVM(pUVM), "/VM/Req/*");
 
         /*
@@ -279,12 +279,12 @@
          */
         RTPrintf(TESTCASE ": va_list argument test...\n"); RTStrmFlush(g_pStdOut);
-        PassVA(pVM, "hello %s", "world");
-        VMR3AtRuntimeErrorRegister(pVM, MyAtRuntimeError, (void *)"user argument");
-        VMSetRuntimeError(pVM, 0 /*fFlags*/, "enum", "some %s string", "error");
+        PassVA(pUVM, "hello %s", "world");
+        VMR3AtRuntimeErrorRegister(pUVM, MyAtRuntimeError, (void *)"user argument");
+        VMSetRuntimeError(VMR3GetVM(pUVM), 0 /*fFlags*/, "enum", "some %s string", "error");
 
         /*
          * Cleanup.
          */
-        rc = VMR3PowerOff(pVM);
+        rc = VMR3PowerOff(pUVM);
         if (!RT_SUCCESS(rc))
         {
@@ -292,5 +292,5 @@
             g_cErrors++;
         }
-        rc = VMR3Destroy(pVM);
+        rc = VMR3Destroy(pUVM);
         if (!RT_SUCCESS(rc))
         {
@@ -298,4 +298,5 @@
             g_cErrors++;
         }
+        VMR3ReleaseUVM(pUVM);
     }
     else
Index: trunk/src/recompiler/VBoxREMWrapper.cpp
===================================================================
--- trunk/src/recompiler/VBoxREMWrapper.cpp	(revision 44339)
+++ trunk/src/recompiler/VBoxREMWrapper.cpp	(revision 44340)
@@ -1310,9 +1310,6 @@
     { "TRPMSetFaultAddress",                    VMM_FN(TRPMSetFaultAddress),            &g_aArgsTRPMSetFaultAddress[0],             RT_ELEMENTS(g_aArgsTRPMSetFaultAddress),               REMFNDESC_FLAGS_RET_VOID,   0,                  NULL },
     { "VMMGetCpu",                              VMM_FN(VMMGetCpu),                      &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_INT,    sizeof(PVMCPU),     NULL },
-    { "VMR3ReqCallWait",                        VMM_FN(VMR3ReqCallWait),                &g_aArgsVMR3ReqCallWait[0],                 RT_ELEMENTS(g_aArgsVMR3ReqCallWait),                   REMFNDESC_FLAGS_RET_INT | REMFNDESC_FLAGS_ELLIPSIS, sizeof(int), NULL },
     { "VMR3ReqPriorityCallWait",                VMM_FN(VMR3ReqPriorityCallWait),        &g_aArgsVMR3ReqCallWait[0],                 RT_ELEMENTS(g_aArgsVMR3ReqCallWait),                   REMFNDESC_FLAGS_RET_INT | REMFNDESC_FLAGS_ELLIPSIS, sizeof(int), NULL },
     { "VMR3ReqFree",                            VMM_FN(VMR3ReqFree),                    &g_aArgsVMR3ReqFree[0],                     RT_ELEMENTS(g_aArgsVMR3ReqFree),                       REMFNDESC_FLAGS_RET_INT,    sizeof(int),        NULL },
-    { "VMR3GetVMCPUId",                         VMM_FN(VMR3GetVMCPUId),                 &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_INT,    sizeof(int),        NULL },
-    { "VMR3GetVMCPUNativeThread",               VMM_FN(VMR3GetVMCPUNativeThread),       &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_INT,    sizeof(void *),     NULL },
 //    { "",                        VMM_FN(),                &g_aArgsVM[0],                              RT_ELEMENTS(g_aArgsVM),                                REMFNDESC_FLAGS_RET_INT,    sizeof(int),   NULL },
 };
