Changeset 36041 in vbox for trunk/src/VBox
- Timestamp:
- Feb 21, 2011 4:04:53 PM (14 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/ConsoleImpl.h
r35965 r36041 271 271 } 272 272 /** Decreases the number of callers before the instance is destroyed. */ 273 void release ()273 void releaseCaller() 274 274 { 275 275 AssertReturnVoid(SUCCEEDED(mRC)); … … 279 279 /** Restores the number of callers after by #release(). #rc() must be 280 280 * rechecked to ensure the operation succeeded. */ 281 void add ()281 void addYY() 282 282 { 283 283 AssertReturnVoid(!SUCCEEDED(mRC)); … … 293 293 private: 294 294 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase) 295 DECLARE_CLS_NEW_DELETE_NOOP(AutoVMCallerBase)296 295 }; 297 296 297 #if 0 298 298 /** 299 299 * Helper class that protects sections of code using the mpVM pointer by … … 311 311 * 312 312 * @sa SafeVMPtr, SafeVMPtrQuiet 313 * @obsolete Use SafeVMPtr 313 314 */ 314 315 typedef AutoVMCallerBase<false, false> AutoVMCaller; 316 #endif 315 317 316 318 /** … … 318 320 * 319 321 * @note Temporarily locks the argument for writing. 322 * @obsolete Use SafeVMPtrQuiet 320 323 */ 321 324 typedef AutoVMCallerBase<true, false> AutoVMCallerQuiet; … … 326 329 * 327 330 * @note Temporarily locks the argument for writing. 331 * @obsolete Use SafeVMPtr 328 332 */ 329 333 typedef AutoVMCallerBase<false, true> AutoVMCallerWeak; … … 335 339 * 336 340 * @note Temporarily locks the argument for writing. 341 * @obsolete Use SafeVMPtrQuiet 337 342 */ 338 343 typedef AutoVMCallerBase<true, true> AutoVMCallerQuietWeak; … … 346 351 typedef AutoVMCallerBase<taQuiet, true> Base; 347 352 public: 348 SafeVMPtrBase(Console *aThat) : Base(aThat), mpVM(NULL) 353 SafeVMPtrBase(Console *aThat) : Base(aThat), mpVM(NULL), mpUVM(NULL) 349 354 { 350 355 if (SUCCEEDED(Base::mRC)) 351 { 352 mpVM = aThat->mpVM; 353 if (!mpVM) 354 Base::mRC = E_FAIL; /** @todo use setError here. */ 355 } 356 Base::mRC = aThat->safeVMPtrRetainer(&mpVM, &mpUVM, taQuiet); 357 } 358 ~SafeVMPtrBase() 359 { 360 if (SUCCEEDED(Base::mRC)) 361 release(); 356 362 } 357 363 /** Smart SaveVMPtr to PVM cast operator */ … … 359 365 /** Direct PVM access for printf()-like functions */ 360 366 PVM raw() const { return mpVM; } 367 /** Direct PUVM access for printf()-like functions */ 368 PUVM rawUVM() const { return mpUVM; } 369 /** Release the handles. */ 370 void release() 371 { 372 AssertReturnVoid(SUCCEEDED(Base::mRC)); 373 Base::mThat->safeVMPtrReleaser(&mpVM, &mpUVM); 374 Base::releaseCaller(); 375 } 376 361 377 private: 362 PVM mpVM; 378 PVM mpVM; 379 PUVM mpUVM; 363 380 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase) 364 DECLARE_CLS_NEW_DELETE_NOOP(SafeVMPtrBase)365 381 }; 366 382 … … 438 454 439 455 HRESULT addVMCaller(bool aQuiet = false, bool aAllowNullVM = false); 440 void releaseVMCaller(); 456 void releaseVMCaller(); 457 HRESULT safeVMPtrRetainer(PVM *a_ppVM, PUVM *a_ppUVM, bool aQuiet); 458 void safeVMPtrReleaser(PVM *a_ppVM, PUVM *a_ppUVM); 441 459 442 460 HRESULT consoleInitReleaseLog(const ComPtr<IMachine> aMachine); … … 515 533 HRESULT *phrc); 516 534 static DECLCALLBACK(int) changeRemovableMedium(Console *pThis, 535 PVM pVM, 517 536 const char *pcszDevice, 518 537 unsigned uInstance, … … 531 550 static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState, 532 551 VMSTATE aOldState, void *aUser); 533 static DECLCALLBACK(int) unplugCpu(Console *pThis, unsigned uCpu);534 static DECLCALLBACK(int) plugCpu(Console *pThis, unsigned uCpu);535 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce );536 HRESULT doCPURemove(ULONG aCpu );537 HRESULT doCPUAdd(ULONG aCpu );538 539 HRESULT doNetworkAdapterChange( const char *pszDevice, unsigned uInstance,552 static DECLCALLBACK(int) unplugCpu(Console *pThis, PVM pVM, unsigned uCpu); 553 static DECLCALLBACK(int) plugCpu(Console *pThis, PVM pVM, unsigned uCpu); 554 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PVM pVM); 555 HRESULT doCPURemove(ULONG aCpu, PVM pVM); 556 HRESULT doCPUAdd(ULONG aCpu, PVM pVM); 557 558 HRESULT doNetworkAdapterChange(PVM pVM, const char *pszDevice, unsigned uInstance, 540 559 unsigned uLun, INetworkAdapter *aNetworkAdapter); 541 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, const char *pszDevice,560 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, PVM pVM, const char *pszDevice, 542 561 unsigned uInstance, unsigned uLun, 543 562 INetworkAdapter *aNetworkAdapter); … … 547 566 HRESULT detachUSBDevice(USBDeviceList::iterator &aIt); 548 567 549 static DECLCALLBACK(int) usbAttachCallback(Console *that, IUSBDevice *aHostDevice, PCRTUUID aUuid,568 static DECLCALLBACK(int) usbAttachCallback(Console *that, PVM pVM, IUSBDevice *aHostDevice, PCRTUUID aUuid, 550 569 bool aRemote, const char *aAddress, ULONG aMaskedIfs); 551 static DECLCALLBACK(int) usbDetachCallback(Console *that, USBDeviceList::iterator *aIt, PCRTUUID aUuid);570 static DECLCALLBACK(int) usbDetachCallback(Console *that, PVM pVM, USBDeviceList::iterator *aIt, PCRTUUID aUuid); 552 571 #endif 553 572 … … 559 578 const char *pszErrorFmt, va_list va); 560 579 561 static DECLCALLBACK(void) setVMRuntimeErrorCallbackF(PVM pVM, void *pvUser, uint32_t fFatal, 562 const char *pszErrorId, 563 const char *pszFormat, ...); 564 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PVM pVM, void *pvUser, uint32_t fFatal, 565 const char *pszErrorId, 566 const char *pszFormat, va_list va); 580 static void setVMRuntimeErrorCallbackF(PVM pVM, void *pvUser, uint32_t fFatal, 581 const char *pszErrorId, const char *pszFormat, ...); 582 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PVM pVM, void *pvUser, uint32_t fFatal, 583 const char *pszErrorId, const char *pszFormat, va_list va); 567 584 568 585 HRESULT captureUSBDevices(PVM pVM); … … 613 630 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL); 614 631 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true); 615 HRESULT teleporterTrg(P VM pVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,632 HRESULT teleporterTrg(PUVM pUVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused, 616 633 Progress *pProgress, bool *pfPowerOffOnFailure); 617 634 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser); … … 645 662 SharedFolderMap m_mapSharedFolders; // the console instances 646 663 647 /** The VM instancehandle. */648 P VM mpVM;664 /** The user mode VM handle. */ 665 PUVM mpUVM; 649 666 /** Holds the number of "readonly" mpVM callers (users) */ 650 667 uint32_t mVMCallers; -
trunk/src/VBox/Main/src-client/ConsoleImpl.cpp
r35965 r36041 137 137 * 138 138 * If \a aUsesVMPtr parameter is true, the task structure will also add itself 139 * as a Console::mp VM caller with the same meaning as above. See139 * as a Console::mpUVM caller with the same meaning as above. See 140 140 * Console::addVMCaller() for more info. 141 141 */ … … 150 150 mProgress(aProgress), 151 151 mServerProgress(aServerProgress), 152 mVMCallerAdded(false) 152 mpVM(NULL), 153 mRC(E_FAIL), 154 mpSafeVMPtr(NULL) 153 155 { 154 156 AssertReturnVoid(aConsole); … … 158 160 if (aUsesVMPtr) 159 161 { 160 mRC = aConsole->addVMCaller(); 161 if (SUCCEEDED(mRC)) 162 mVMCallerAdded = true; 162 mpSafeVMPtr = new Console::SafeVMPtr(aConsole); 163 if (mpSafeVMPtr->isOk()) 164 mpVM = mpSafeVMPtr->raw(); 165 else 166 mRC = mpSafeVMPtr->rc(); 163 167 } 164 168 } … … 166 170 ~VMTask() 167 171 { 168 if (mVMCallerAdded) 169 mConsole->releaseVMCaller(); 172 releaseVMCaller(); 170 173 } 171 174 … … 176 179 void releaseVMCaller() 177 180 { 178 AssertReturnVoid(mVMCallerAdded); 179 mConsole->releaseVMCaller(); 180 mVMCallerAdded = false; 181 } 182 183 const ComObjPtr<Console> mConsole; 184 AutoCaller mConsoleCaller; 185 const ComObjPtr<Progress> mProgress; 186 Utf8Str mErrorMsg; 187 const ComPtr<IProgress> mServerProgress; 181 if (mpSafeVMPtr) 182 { 183 delete mpSafeVMPtr; 184 mpSafeVMPtr = NULL; 185 } 186 } 187 188 const ComObjPtr<Console> mConsole; 189 AutoCaller mConsoleCaller; 190 const ComObjPtr<Progress> mProgress; 191 Utf8Str mErrorMsg; 192 const ComPtr<IProgress> mServerProgress; 193 PVM mpVM; 188 194 189 195 private: 190 191 HRESULT mRC; 192 bool mVMCallerAdded : 1; 196 HRESULT mRC; 197 Console::SafeVMPtr *mpSafeVMPtr; 193 198 }; 194 199 … … 350 355 : mSavedStateDataLoaded(false) 351 356 , mConsoleVRDPServer(NULL) 352 , mp VM(NULL)357 , mpUVM(NULL) 353 358 , mVMCallers(0) 354 359 , mVMZeroCallersSem(NIL_RTSEMEVENT) … … 567 572 568 573 /* power down the VM if necessary */ 569 if (mp VM)574 if (mpUVM) 570 575 { 571 576 powerDown(); 572 Assert(mp VM == NULL);577 Assert(mpUVM == NULL); 573 578 } 574 579 … … 1908 1913 return setInvalidMachineStateError(); 1909 1914 1910 /* protect mpVM */ 1911 AutoVMCaller autoVMCaller(this); 1912 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 1915 /* protect mpUVM */ 1916 SafeVMPtr ptrVM(this); 1917 if (!ptrVM.isOk()) 1918 return ptrVM.rc(); 1913 1919 1914 1920 /* leave the lock before a VMR3* call (EMT will call us back)! */ 1915 1921 alock.leave(); 1916 1922 1917 int vrc = VMR3Reset( mpVM);1923 int vrc = VMR3Reset(ptrVM); 1918 1924 1919 1925 HRESULT rc = RT_SUCCESS(vrc) ? S_OK : … … 1927 1933 } 1928 1934 1929 DECLCALLBACK(int) Console::unplugCpu(Console *pThis, unsigned uCpu)1930 { 1931 LogFlowFunc(("pThis=%p uCpu=%u\n", pThis, uCpu));1935 /*static*/ DECLCALLBACK(int) Console::unplugCpu(Console *pThis, PVM pVM, unsigned uCpu) 1936 { 1937 LogFlowFunc(("pThis=%p pVM=%p uCpu=%u\n", pThis, pVM, uCpu)); 1932 1938 1933 1939 AssertReturn(pThis, VERR_INVALID_PARAMETER); 1934 1940 1935 int vrc = PDMR3DeviceDetach(p This->mpVM, "acpi", 0, uCpu, 0);1941 int vrc = PDMR3DeviceDetach(pVM, "acpi", 0, uCpu, 0); 1936 1942 Log(("UnplugCpu: rc=%Rrc\n", vrc)); 1937 1943 … … 1939 1945 } 1940 1946 1941 HRESULT Console::doCPURemove(ULONG aCpu )1947 HRESULT Console::doCPURemove(ULONG aCpu, PVM pVM) 1942 1948 { 1943 1949 HRESULT rc = S_OK; … … 1952 1958 1953 1959 AssertReturn(m_pVMMDev, E_FAIL); 1954 PPDMIVMMDEVPORT p DevPort = m_pVMMDev->getVMMDevPort();1955 AssertReturn(p DevPort, E_FAIL);1960 PPDMIVMMDEVPORT pVmmDevPort = m_pVMMDev->getVMMDevPort(); 1961 AssertReturn(pVmmDevPort, E_FAIL); 1956 1962 1957 1963 if ( mMachineState != MachineState_Running … … 1961 1967 return setInvalidMachineStateError(); 1962 1968 1963 /* protect mpVM */1964 AutoVMCaller autoVMCaller(this);1965 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();1966 1967 1969 /* Check if the CPU is present */ 1968 1970 BOOL fCpuAttached; 1969 1971 rc = mMachine->GetCPUStatus(aCpu, &fCpuAttached); 1970 if (FAILED(rc)) return rc;1971 1972 if (FAILED(rc)) 1973 return rc; 1972 1974 if (!fCpuAttached) 1973 return setError(E_FAIL, 1974 tr("CPU %d is not attached"), aCpu); 1975 return setError(E_FAIL, tr("CPU %d is not attached"), aCpu); 1975 1976 1976 1977 /* Leave the lock before any EMT/VMMDev call. */ 1977 1978 alock.release(); 1979 bool fLocked = true; 1978 1980 1979 1981 /* Check if the CPU is unlocked */ 1980 1982 PPDMIBASE pBase; 1981 int vrc = PDMR3QueryDeviceLun(mpVM, "acpi", 0, aCpu, &pBase); 1982 bool fLocked = true; 1983 int vrc = PDMR3QueryDeviceLun(pVM, "acpi", 0, aCpu, &pBase); 1983 1984 if (RT_SUCCESS(vrc)) 1984 1985 { 1986 Assert(pBase); 1987 PPDMIACPIPORT pApicPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT); 1988 1989 /* Notify the guest if possible. */ 1985 1990 uint32_t idCpuCore, idCpuPackage; 1986 1987 /* Notify the guest if possible. */ 1988 vrc = VMR3GetCpuCoreAndPackageIdFromCpuId(mpVM, aCpu, &idCpuCore, &idCpuPackage); 1989 AssertRC(vrc); 1990 1991 Assert(pBase); 1992 1993 PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT); 1994 1995 vrc = pDevPort->pfnCpuHotUnplug(pDevPort, idCpuCore, idCpuPackage); 1991 vrc = VMR3GetCpuCoreAndPackageIdFromCpuId(pVM, aCpu, &idCpuCore, &idCpuPackage); AssertRC(vrc); 1996 1992 if (RT_SUCCESS(vrc)) 1993 vrc = pVmmDevPort->pfnCpuHotUnplug(pVmmDevPort, idCpuCore, idCpuPackage); 1994 if (RT_SUCCESS(vrc)) 1997 1995 { 1998 1996 unsigned cTries = 100; 1999 2000 1997 do 2001 1998 { 2002 /* It will take some time until the event is processed in the guest. Wait */ 2003 vrc = pPort ? pPort->pfnGetCpuStatus(pPort, aCpu, &fLocked) : VERR_INVALID_POINTER; 2004 1999 /* It will take some time until the event is processed in the guest. Wait... */ 2000 vrc = pApicPort ? pApicPort->pfnGetCpuStatus(pApicPort, aCpu, &fLocked) : VERR_INVALID_POINTER; 2005 2001 if (RT_SUCCESS(vrc) && !fLocked) 2006 2002 break; … … 2013 2009 { 2014 2010 /* Query one time. It is possible that the user ejected the CPU. */ 2015 vrc = p Port ? pPort->pfnGetCpuStatus(pPort, aCpu, &fLocked) : VERR_INVALID_POINTER;2011 vrc = pApicPort ? pApicPort->pfnGetCpuStatus(pApicPort, aCpu, &fLocked) : VERR_INVALID_POINTER; 2016 2012 } 2017 2013 } … … 2025 2021 */ 2026 2022 PVMREQ pReq; 2027 vrc = VMR3ReqCall(mpVM, 0, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS, 2028 (PFNRT)Console::unplugCpu, 2, 2029 this, aCpu); 2030 2023 vrc = VMR3ReqCall(pVM, 0, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS, 2024 (PFNRT)Console::unplugCpu, 3, 2025 this, pVM, aCpu); 2031 2026 if (vrc == VERR_TIMEOUT || RT_SUCCESS(vrc)) 2032 2027 { … … 2041 2036 { 2042 2037 /* Detach it from the VM */ 2043 vrc = VMR3HotUnplugCpu( mpVM, aCpu);2038 vrc = VMR3HotUnplugCpu(pVM, aCpu); 2044 2039 AssertRC(vrc); 2045 2040 } … … 2057 2052 } 2058 2053 2059 DECLCALLBACK(int) Console::plugCpu(Console *pThis, unsigned uCpu)2054 /*static*/ DECLCALLBACK(int) Console::plugCpu(Console *pThis, PVM pVM, unsigned uCpu) 2060 2055 { 2061 2056 LogFlowFunc(("pThis=%p uCpu=%u\n", pThis, uCpu)); … … 2063 2058 AssertReturn(pThis, VERR_INVALID_PARAMETER); 2064 2059 2065 int rc = VMR3HotPlugCpu(p This->mpVM, uCpu);2060 int rc = VMR3HotPlugCpu(pVM, uCpu); 2066 2061 AssertRC(rc); 2067 2062 2068 PCFGMNODE pInst = CFGMR3GetChild(CFGMR3GetRoot(p This->mpVM), "Devices/acpi/0/");2063 PCFGMNODE pInst = CFGMR3GetChild(CFGMR3GetRoot(pVM), "Devices/acpi/0/"); 2069 2064 AssertRelease(pInst); 2070 2065 /* nuke anything which might have been left behind. */ … … 2083 2078 */ 2084 2079 PPDMIBASE pBase; 2085 rc = PDMR3DeviceAttach(p This->mpVM, "acpi", 0, uCpu, 0, &pBase); RC_CHECK();2080 rc = PDMR3DeviceAttach(pVM, "acpi", 0, uCpu, 0, &pBase); RC_CHECK(); 2086 2081 2087 2082 Log(("PlugCpu: rc=%Rrc\n", rc)); … … 2094 2089 } 2095 2090 2096 HRESULT Console::doCPUAdd(ULONG aCpu )2091 HRESULT Console::doCPUAdd(ULONG aCpu, PVM pVM) 2097 2092 { 2098 2093 HRESULT rc = S_OK; … … 2117 2112 AssertReturn(pDevPort, E_FAIL); 2118 2113 2119 /* protect mpVM */2120 AutoVMCaller autoVMCaller(this);2121 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();2122 2123 2114 /* Check if the CPU is present */ 2124 2115 BOOL fCpuAttached; … … 2136 2127 */ 2137 2128 PVMREQ pReq; 2138 int vrc = VMR3ReqCall( mpVM, 0, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,2139 (PFNRT)Console::plugCpu, 2,2140 this, aCpu);2129 int vrc = VMR3ReqCall(pVM, 0, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS, 2130 (PFNRT)Console::plugCpu, 3, 2131 this, pVM, aCpu); 2141 2132 2142 2133 /* leave the lock before a VMR3* call (EMT will call us back)! */ … … 2159 2150 if (RT_SUCCESS(vrc)) 2160 2151 { 2152 /* Notify the guest if possible. */ 2161 2153 uint32_t idCpuCore, idCpuPackage; 2162 2163 /* Notify the guest if possible. */ 2164 vrc = VMR3GetCpuCoreAndPackageIdFromCpuId(mpVM, aCpu, &idCpuCore, &idCpuPackage); 2165 AssertRC(vrc); 2166 2167 vrc = pDevPort->pfnCpuHotPlug(pDevPort, idCpuCore, idCpuPackage); 2154 vrc = VMR3GetCpuCoreAndPackageIdFromCpuId(pVM, aCpu, &idCpuCore, &idCpuPackage); AssertRC(vrc); 2155 if (RT_SUCCESS(vrc)) 2156 vrc = pDevPort->pfnCpuHotPlug(pDevPort, idCpuCore, idCpuPackage); 2168 2157 /** @todo warning if the guest doesn't support it */ 2169 2158 } … … 2199 2188 } 2200 2189 2201 /* protect mpVM */ 2202 AutoVMCaller autoVMCaller(this); 2203 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 2190 /* get the VM handle. */ 2191 SafeVMPtr ptrVM(this); 2192 if (!ptrVM.isOk()) 2193 return ptrVM.rc(); 2204 2194 2205 2195 LogFlowThisFunc(("Sending PAUSE request...\n")); … … 2208 2198 alock.leave(); 2209 2199 2210 int vrc = VMR3Suspend( mpVM);2200 int vrc = VMR3Suspend(ptrVM); 2211 2201 2212 2202 HRESULT hrc = S_OK; … … 2233 2223 Global::stringifyMachineState(mMachineState)); 2234 2224 2235 /* protect mpVM */ 2236 AutoVMCaller autoVMCaller(this); 2237 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 2225 /* get the VM handle. */ 2226 SafeVMPtr ptrVM(this); 2227 if (!ptrVM.isOk()) 2228 return ptrVM.rc(); 2238 2229 2239 2230 LogFlowThisFunc(("Sending RESUME request...\n")); … … 2243 2234 2244 2235 #ifdef VBOX_WITH_EXTPACK 2245 int vrc = mptrExtPackManager->callAllVmPowerOnHooks(this, mpVM); /** @todo called a few times too many... */2236 int vrc = mptrExtPackManager->callAllVmPowerOnHooks(this, ptrVM); /** @todo called a few times too many... */ 2246 2237 #else 2247 2238 int vrc = VINF_SUCCESS; … … 2249 2240 if (RT_SUCCESS(vrc)) 2250 2241 { 2251 if (VMR3GetState( mpVM) == VMSTATE_CREATED)2252 vrc = VMR3PowerOn( mpVM); /* (PowerUpPaused) */2242 if (VMR3GetState(ptrVM) == VMSTATE_CREATED) 2243 vrc = VMR3PowerOn(ptrVM); /* (PowerUpPaused) */ 2253 2244 else 2254 vrc = VMR3Resume( mpVM);2245 vrc = VMR3Resume(ptrVM); 2255 2246 } 2256 2247 … … 2280 2271 return setInvalidMachineStateError(); 2281 2272 2282 /* protect mpVM */ 2283 AutoVMCaller autoVMCaller(this); 2284 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 2285 2273 /* get the VM handle. */ 2274 SafeVMPtr ptrVM(this); 2275 if (!ptrVM.isOk()) 2276 return ptrVM.rc(); 2277 /** @todo leave the console lock? */ 2278 2279 /* get the acpi device interface and press the button. */ 2286 2280 PPDMIBASE pBase; 2287 int vrc = PDMR3QueryDeviceLun( mpVM, "acpi", 0, 0, &pBase);2281 int vrc = PDMR3QueryDeviceLun(ptrVM, "acpi", 0, 0, &pBase); 2288 2282 if (RT_SUCCESS(vrc)) 2289 2283 { 2290 2284 Assert(pBase); 2291 2285 PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT); 2292 vrc = pPort ? pPort->pfnPowerButtonPress(pPort) : VERR_INVALID_POINTER; 2286 if (pPort) 2287 vrc = pPort->pfnPowerButtonPress(pPort); 2288 else 2289 vrc = VERR_PDM_MISSING_INTERFACE; 2293 2290 } 2294 2291 … … 2321 2318 return setInvalidMachineStateError(); 2322 2319 2323 /* protect mpVM */ 2324 AutoVMCaller autoVMCaller(this); 2325 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 2326 2320 /* get the VM handle. */ 2321 SafeVMPtr ptrVM(this); 2322 if (!ptrVM.isOk()) 2323 return ptrVM.rc(); 2324 /** @todo leave the console lock? */ 2325 2326 /* get the acpi device interface and check if the button press was handled. */ 2327 2327 PPDMIBASE pBase; 2328 int vrc = PDMR3QueryDeviceLun(mpVM, "acpi", 0, 0, &pBase); 2329 bool handled = false; 2328 int vrc = PDMR3QueryDeviceLun(ptrVM, "acpi", 0, 0, &pBase); 2330 2329 if (RT_SUCCESS(vrc)) 2331 2330 { 2332 2331 Assert(pBase); 2333 2332 PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT); 2334 vrc = pPort ? pPort->pfnGetPowerButtonHandled(pPort, &handled) : VERR_INVALID_POINTER; 2333 if (pPort) 2334 { 2335 bool fHandled = false; 2336 vrc = pPort->pfnGetPowerButtonHandled(pPort, &fHandled); 2337 if (RT_SUCCESS(vrc)) 2338 *aHandled = fHandled; 2339 } 2340 else 2341 vrc = VERR_PDM_MISSING_INTERFACE; 2335 2342 } 2336 2343 … … 2339 2346 tr("Checking if the ACPI Power Button event was handled by the guest OS failed (%Rrc)"), 2340 2347 vrc); 2341 2342 *aHandled = handled;2343 2348 2344 2349 LogFlowThisFunc(("rc=%Rhrc\n", rc)); … … 2367 2372 Global::stringifyMachineState(mMachineState)); 2368 2373 2369 /* protect mpVM */ 2370 AutoVMCaller autoVMCaller(this); 2371 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 2372 2374 /* get the VM handle. */ 2375 SafeVMPtr ptrVM(this); 2376 if (!ptrVM.isOk()) 2377 return ptrVM.rc(); 2378 2379 /** @todo leave the console lock? */ 2380 2381 /* get the acpi device interface and query the information. */ 2373 2382 PPDMIBASE pBase; 2374 int vrc = PDMR3QueryDeviceLun(mpVM, "acpi", 0, 0, &pBase); 2375 bool entered = false; 2383 int vrc = PDMR3QueryDeviceLun(ptrVM, "acpi", 0, 0, &pBase); 2376 2384 if (RT_SUCCESS(vrc)) 2377 2385 { 2378 2386 Assert(pBase); 2379 2387 PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT); 2380 vrc = pPort ? pPort->pfnGetGuestEnteredACPIMode(pPort, &entered) : VERR_INVALID_POINTER; 2381 } 2382 2383 *aEntered = RT_SUCCESS(vrc) ? entered : false; 2388 if (pPort) 2389 { 2390 bool fEntered = false; 2391 vrc = pPort->pfnGetGuestEnteredACPIMode(pPort, &fEntered); 2392 if (RT_SUCCESS(vrc)) 2393 *aEntered = fEntered; 2394 } 2395 else 2396 vrc = VERR_PDM_MISSING_INTERFACE; 2397 } 2384 2398 2385 2399 LogFlowThisFuncLeave(); … … 2399 2413 return setInvalidMachineStateError(); 2400 2414 2401 /* protect mpVM */ 2402 AutoVMCaller autoVMCaller(this); 2403 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 2404 2415 /* get the VM handle. */ 2416 SafeVMPtr ptrVM(this); 2417 if (!ptrVM.isOk()) 2418 return ptrVM.rc(); 2419 2420 /** @todo leave the console lock? */ 2421 2422 /* get the acpi device interface and press the sleep button. */ 2405 2423 PPDMIBASE pBase; 2406 int vrc = PDMR3QueryDeviceLun( mpVM, "acpi", 0, 0, &pBase);2424 int vrc = PDMR3QueryDeviceLun(ptrVM, "acpi", 0, 0, &pBase); 2407 2425 if (RT_SUCCESS(vrc)) 2408 2426 { 2409 2427 Assert(pBase); 2410 2428 PPDMIACPIPORT pPort = PDMIBASE_QUERY_INTERFACE(pBase, PDMIACPIPORT); 2411 vrc = pPort ? pPort->pfnSleepButtonPress(pPort) : VERR_INVALID_POINTER; 2429 if (pPort) 2430 vrc = pPort->pfnSleepButtonPress(pPort); 2431 else 2432 vrc = VERR_PDM_MISSING_INTERFACE; 2412 2433 } 2413 2434 … … 2448 2469 { 2449 2470 HRESULT rc = Pause(); 2450 if (FAILED(rc)) return rc; 2471 if (FAILED(rc)) 2472 return rc; 2451 2473 } 2452 2474 … … 2467 2489 rc = mControl->BeginSavingState(pProgress.asOutParam(), 2468 2490 stateFilePath.asOutParam()); 2469 if (FAILED(rc)) break; 2491 if (FAILED(rc)) 2492 break; 2470 2493 2471 2494 fBeganSavingState = true; … … 2508 2531 2509 2532 /* create a thread to wait until the VM state is saved */ 2510 int vrc = RTThreadCreate(NULL, Console::saveStateThread, (void *) 2533 int vrc = RTThreadCreate(NULL, Console::saveStateThread, (void *)task.get(), 2511 2534 0, RTTHREADTYPE_MAIN_WORKER, 0, "VMSave"); 2512 2535 if (RT_FAILURE(vrc)) … … 2521 2544 /* return the progress to the caller */ 2522 2545 pProgress.queryInterfaceTo(aProgress); 2523 } 2524 while (0); 2546 } while (0); 2525 2547 2526 2548 if (FAILED(rc) && !fTaskCreationFailed) … … 2694 2716 Global::stringifyMachineState(mMachineState)); 2695 2717 2696 /* protect mpVM */ 2697 AutoVMCaller autoVMCaller(this); 2698 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 2718 /* Get the VM handle. */ 2719 SafeVMPtr ptrVM(this); 2720 if (!ptrVM.isOk()) 2721 return ptrVM.rc(); 2699 2722 2700 2723 /* Don't proceed unless we've found the usb controller. */ 2701 2724 PPDMIBASE pBase = NULL; 2702 int vrc = PDMR3QueryLun( mpVM, "usb-ohci", 0, 0, &pBase);2725 int vrc = PDMR3QueryLun(ptrVM, "usb-ohci", 0, 0, &pBase); 2703 2726 if (RT_FAILURE(vrc)) 2704 2727 return setError(VBOX_E_PDM_ERROR, … … 2710 2733 2711 2734 /* Request the device capture */ 2712 HRESULT rc = mControl->CaptureUSBDevice(aId); 2713 if (FAILED(rc)) return rc; 2714 2715 return rc; 2735 return mControl->CaptureUSBDevice(aId); 2716 2736 2717 2737 #else /* !VBOX_WITH_USB */ … … 2898 2918 if (FAILED(rc)) return rc; 2899 2919 2900 /* protect mpVM (if not NULL) */ 2901 AutoVMCallerQuietWeak autoVMCaller(this); 2902 2903 if ( mpVM 2904 && autoVMCaller.isOk() 2920 /* If the VM is online and supports shared folders, share this folder 2921 * under the specified name. (Ignore any failure to obtain the VM handle.) */ 2922 SafeVMPtrQuiet ptrVM(this); 2923 if ( ptrVM.isOk() 2905 2924 && m_pVMMDev 2906 2925 && m_pVMMDev->isShFlActive() 2907 2926 ) 2908 2927 { 2909 /* If the VM is online and supports shared folders, share this folder2910 * under the specified name. */2911 2912 2928 /* first, remove the machine or the global folder if there is any */ 2913 2929 SharedFolderDataMap::const_iterator it; … … 2915 2931 { 2916 2932 rc = removeSharedFolder(aName); 2917 if (FAILED(rc)) return rc; 2933 if (FAILED(rc)) 2934 return rc; 2918 2935 } 2919 2936 2920 2937 /* second, create the given folder */ 2921 2938 rc = createSharedFolder(aName, SharedFolderData(aHostPath, aWritable, aAutoMount)); 2922 if (FAILED(rc)) return rc; 2939 if (FAILED(rc)) 2940 return rc; 2923 2941 } 2924 2942 … … 2964 2982 if (FAILED(rc)) return rc; 2965 2983 2966 /* protect mpVM (if not NULL) */ 2967 AutoVMCallerQuietWeak autoVMCaller(this); 2968 2969 if ( mpVM 2970 && autoVMCaller.isOk() 2984 /* protect the VM handle (if not NULL) */ 2985 SafeVMPtrQuiet ptrVM(this); 2986 if ( ptrVM.isOk() 2971 2987 && m_pVMMDev 2972 2988 && m_pVMMDev->isShFlActive() … … 3110 3126 int vrc = RTThreadCreate(NULL, 3111 3127 Console::fntTakeSnapshotWorker, 3112 (void *)pTask,3128 (void *)pTask, 3113 3129 0, 3114 3130 RTTHREADTYPE_MAIN_WORKER, … … 3291 3307 * @param aMediumAttachment The medium attachment with the new medium state. 3292 3308 * @param fForce Force medium chance, if it is locked or not. 3309 * @param pVM Safe VM handle. 3293 3310 * 3294 3311 * @note Locks this object for writing. 3295 3312 */ 3296 HRESULT Console::doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce )3313 HRESULT Console::doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PVM pVM) 3297 3314 { 3298 3315 AutoCaller autoCaller(this); … … 3352 3369 AssertComRC(rc); 3353 3370 3354 /* protect mpVM */3355 AutoVMCaller autoVMCaller(this);3356 AssertComRCReturnRC(autoVMCaller.rc());3357 3358 3371 /* 3359 3372 * Call worker in EMT, that's faster and safer than doing everything … … 3362 3375 */ 3363 3376 PVMREQ pReq; 3364 int vrc = VMR3ReqCall( mpVM,3377 int vrc = VMR3ReqCall(pVM, 3365 3378 VMCPUID_ANY, 3366 &pReq,3379 &pReq, 3367 3380 0 /* no wait! */, 3368 3381 VMREQFLAGS_VBOX_STATUS, 3369 3382 (PFNRT)Console::changeRemovableMedium, 3370 7,3383 8, 3371 3384 this, 3385 pVM, 3372 3386 pszDevice, 3373 3387 uInstance, … … 3411 3425 * 3412 3426 * @param pThis Pointer to the Console object. 3427 * @param pVM The VM handle. 3413 3428 * @param pcszDevice The PDM device name. 3414 3429 * @param uInstance The PDM device instance. … … 3425 3440 */ 3426 3441 DECLCALLBACK(int) Console::changeRemovableMedium(Console *pConsole, 3442 PVM pVM, 3427 3443 const char *pcszDevice, 3428 3444 unsigned uInstance, … … 3439 3455 AutoCaller autoCaller(pConsole); 3440 3456 AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED); 3441 3442 PVM pVM = pConsole->mpVM;3443 3457 3444 3458 /* … … 3559 3573 3560 3574 /* don't trigger network change if the VM isn't running */ 3561 if (mpVM) 3562 { 3563 /* protect mpVM */ 3564 AutoVMCaller autoVMCaller(this); 3565 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3566 3575 SafeVMPtrQuiet ptrVM(this); 3576 if (ptrVM.isOk()) 3577 { 3567 3578 /* Get the properties we need from the adapter */ 3568 3579 BOOL fCableConnected, fTraceEnabled; … … 3590 3601 const char *pszAdapterName = networkAdapterTypeToName(adapterType); 3591 3602 PPDMIBASE pBase; 3592 int vrc = PDMR3QueryDeviceLun( mpVM, pszAdapterName, ulInstance, 0, &pBase);3603 int vrc = PDMR3QueryDeviceLun(ptrVM, pszAdapterName, ulInstance, 0, &pBase); 3593 3604 if (RT_SUCCESS(vrc)) 3594 3605 { … … 3607 3618 if (RT_SUCCESS(vrc) && changeAdapter) 3608 3619 { 3609 VMSTATE enmVMState = VMR3GetState( mpVM);3620 VMSTATE enmVMState = VMR3GetState(ptrVM); 3610 3621 if ( enmVMState == VMSTATE_RUNNING /** @todo LiveMigration: Forbid or deal correctly with the _LS variants */ 3611 3622 || enmVMState == VMSTATE_SUSPENDED) … … 3617 3628 } 3618 3629 3619 rc = doNetworkAdapterChange(p szAdapterName, ulInstance, 0, aNetworkAdapter);3630 rc = doNetworkAdapterChange(ptrVM, pszAdapterName, ulInstance, 0, aNetworkAdapter); 3620 3631 3621 3632 if (fTraceEnabled && fCableConnected && pINetCfg) … … 3628 3639 } 3629 3640 else if (vrc == VERR_PDM_DEVICE_INSTANCE_NOT_FOUND) 3630 {3631 3641 return setError(E_FAIL, 3632 3642 tr("The network adapter #%u is not enabled"), ulInstance); 3633 }3634 3643 else 3635 3644 ComAssertRC(vrc); … … 3639 3648 } 3640 3649 } 3650 ptrVM.release(); 3641 3651 } 3642 3652 … … 3655 3665 */ 3656 3666 HRESULT Console::onNATRedirectRuleChange(ULONG ulInstance, BOOL aNatRuleRemove, 3657 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort)3667 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort) 3658 3668 { 3659 3669 LogFlowThisFunc(("\n")); … … 3665 3675 3666 3676 HRESULT rc = S_OK; 3667 int vrc = VINF_SUCCESS; 3668 PPDMINETWORKNATCONFIG pNetNatCfg = NULL; 3677 3669 3678 /* don't trigger nat engine change if the VM isn't running */ 3670 if (mpVM) 3671 { 3672 /* protect mpVM */ 3673 AutoVMCaller autoVMCaller(this); 3674 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3675 3676 ComPtr<INetworkAdapter> pNetworkAdapter; 3677 rc = machine()->GetNetworkAdapter(ulInstance, pNetworkAdapter.asOutParam()); 3678 if ( FAILED(rc) 3679 || pNetworkAdapter.isNull()) 3680 goto done; 3681 3682 /* 3683 * Find the adapter instance, get the config interface and update 3684 * the link state. 3685 */ 3686 NetworkAdapterType_T adapterType; 3687 rc = pNetworkAdapter->COMGETTER(AdapterType)(&adapterType); 3688 AssertComRC(rc); 3689 if (FAILED(rc)) 3690 { 3691 rc = E_FAIL; 3692 goto done; 3693 } 3694 3695 const char *pszAdapterName = networkAdapterTypeToName(adapterType); 3696 PPDMIBASE pBase; 3697 vrc = PDMR3QueryLun(mpVM, pszAdapterName, ulInstance, 0, &pBase); 3698 ComAssertRC(vrc); 3699 if (RT_FAILURE(vrc)) 3700 { 3701 rc = E_FAIL; 3702 goto done; 3703 } 3704 NetworkAttachmentType_T attachmentType; 3705 vrc = pNetworkAdapter->COMGETTER(AttachmentType)(&attachmentType); 3706 3707 if ( RT_FAILURE(vrc) 3708 || attachmentType != NetworkAttachmentType_NAT) 3709 { 3710 rc = (RT_FAILURE(vrc)) ? E_FAIL: rc; 3711 goto done; 3712 } 3713 3714 /* look down for PDMINETWORKNATCONFIG interface */ 3715 while (pBase) 3716 { 3717 if ((pNetNatCfg = (PPDMINETWORKNATCONFIG)pBase->pfnQueryInterface(pBase, PDMINETWORKNATCONFIG_IID))) 3679 SafeVMPtrQuiet ptrVM(this); 3680 if (ptrVM.isOk()) 3681 { 3682 do 3683 { 3684 ComPtr<INetworkAdapter> pNetworkAdapter; 3685 rc = machine()->GetNetworkAdapter(ulInstance, pNetworkAdapter.asOutParam()); 3686 if ( FAILED(rc) 3687 || pNetworkAdapter.isNull()) 3718 3688 break; 3719 PPDMDRVINS drvins = PDMIBASE_2_PDMDRV(pBase); 3720 pBase = drvins->pDownBase; 3721 } 3722 if (!pNetNatCfg) 3723 goto done; 3724 bool fUdp = (aProto == NATProtocol_UDP); 3725 vrc = pNetNatCfg->pfnRedirectRuleCommand(pNetNatCfg, aNatRuleRemove, fUdp, 3726 Utf8Str(aHostIp).c_str(), aHostPort, Utf8Str(aGuestIp).c_str(), 3727 aGuestPort); 3728 if (RT_FAILURE(vrc)) 3729 rc = E_FAIL; 3730 } 3731 done: 3689 3690 /* 3691 * Find the adapter instance, get the config interface and update 3692 * the link state. 3693 */ 3694 NetworkAdapterType_T adapterType; 3695 rc = pNetworkAdapter->COMGETTER(AdapterType)(&adapterType); 3696 if (FAILED(rc)) 3697 { 3698 AssertComRC(rc); 3699 rc = E_FAIL; 3700 break; 3701 } 3702 3703 const char *pszAdapterName = networkAdapterTypeToName(adapterType); 3704 PPDMIBASE pBase; 3705 int vrc = PDMR3QueryLun(ptrVM, pszAdapterName, ulInstance, 0, &pBase); 3706 if (RT_FAILURE(vrc)) 3707 { 3708 ComAssertRC(vrc); 3709 rc = E_FAIL; 3710 break; 3711 } 3712 3713 NetworkAttachmentType_T attachmentType; 3714 rc = pNetworkAdapter->COMGETTER(AttachmentType)(&attachmentType); 3715 if ( FAILED(rc) 3716 || attachmentType != NetworkAttachmentType_NAT) 3717 { 3718 rc = E_FAIL; 3719 break; 3720 } 3721 3722 /* look down for PDMINETWORKNATCONFIG interface */ 3723 PPDMINETWORKNATCONFIG pNetNatCfg = NULL; 3724 while (pBase) 3725 { 3726 pNetNatCfg = (PPDMINETWORKNATCONFIG)pBase->pfnQueryInterface(pBase, PDMINETWORKNATCONFIG_IID); 3727 if (pNetNatCfg) 3728 break; 3729 /** @todo r=bird: This stinks! */ 3730 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pBase); 3731 pBase = pDrvIns->pDownBase; 3732 } 3733 if (!pNetNatCfg) 3734 break; 3735 3736 bool fUdp = aProto == NATProtocol_UDP; 3737 vrc = pNetNatCfg->pfnRedirectRuleCommand(pNetNatCfg, aNatRuleRemove, fUdp, 3738 Utf8Str(aHostIp).c_str(), aHostPort, Utf8Str(aGuestIp).c_str(), 3739 aGuestPort); 3740 if (RT_FAILURE(vrc)) 3741 rc = E_FAIL; 3742 } while (0); /* break loop */ 3743 ptrVM.release(); 3744 } 3745 3732 3746 LogFlowThisFunc(("Leaving rc=%#x\n", rc)); 3733 3747 return rc; … … 3740 3754 * @returns COM status code. 3741 3755 * 3756 * @parma pVM The VM handle (caller hold this safely). 3742 3757 * @param pszDevice The PDM device name. 3743 3758 * @param uInstance The PDM device instance. … … 3747 3762 * @note Locks this object for writing. 3748 3763 */ 3749 HRESULT Console::doNetworkAdapterChange(const char *pszDevice, 3764 HRESULT Console::doNetworkAdapterChange(PVM pVM, 3765 const char *pszDevice, 3750 3766 unsigned uInstance, 3751 3767 unsigned uLun, … … 3761 3777 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3762 3778 3763 /* protect mpVM */ 3764 AutoVMCaller autoVMCaller(this); 3765 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3779 /* Get the VM handle. */ 3780 SafeVMPtr ptrVM(this); 3781 if (!ptrVM.isOk()) 3782 return ptrVM.rc(); 3766 3783 3767 3784 /* … … 3771 3788 */ 3772 3789 PVMREQ pReq; 3773 int vrc = VMR3ReqCall( mpVM, 0 /*idDstCpu*/, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS,3774 (PFNRT) Console::changeNetworkAttachment, 5,3775 this, p szDevice, uInstance, uLun, aNetworkAdapter);3790 int vrc = VMR3ReqCall(pVM, 0 /*idDstCpu*/, &pReq, 0 /* no wait! */, VMREQFLAGS_VBOX_STATUS, 3791 (PFNRT) Console::changeNetworkAttachment, 6, 3792 this, ptrVM.raw(), pszDevice, uInstance, uLun, aNetworkAdapter); 3776 3793 3777 3794 /* leave the lock before waiting for a result (EMT will call us back!) */ … … 3805 3822 * 3806 3823 * @param pThis Pointer to the Console object. 3824 * @param pVM The VM handle. 3807 3825 * @param pszDevice The PDM device name. 3808 3826 * @param uInstance The PDM device instance. … … 3814 3832 */ 3815 3833 DECLCALLBACK(int) Console::changeNetworkAttachment(Console *pThis, 3834 PVM pVM, 3816 3835 const char *pszDevice, 3817 3836 unsigned uInstance, … … 3827 3846 || !strcmp(pszDevice, "e1000") 3828 3847 || !strcmp(pszDevice, "virtio-net")) 3829 && (uLun == 0)3830 && (uInstance < SchemaDefs::NetworkAdapterCount),3848 && uLun == 0 3849 && uInstance < SchemaDefs::NetworkAdapterCount, 3831 3850 ("pszDevice=%s uLun=%d uInstance=%d\n", pszDevice, uLun, uInstance)); 3832 3851 Log(("pszDevice=%s uLun=%d uInstance=%d\n", pszDevice, uLun, uInstance)); … … 3834 3853 AutoCaller autoCaller(pThis); 3835 3854 AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED); 3836 3837 /* protect mpVM */3838 AutoVMCaller autoVMCaller(pThis);3839 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();3840 3841 PVM pVM = pThis->mpVM;3842 3855 3843 3856 /* … … 3932 3945 3933 3946 /* don't trigger serial port change if the VM isn't running */ 3934 if (mpVM) 3935 { 3936 /* protect mpVM */ 3937 AutoVMCaller autoVMCaller(this); 3938 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3939 3947 SafeVMPtrQuiet ptrVM(this); 3948 if (ptrVM.isOk()) 3949 { 3940 3950 /* nothing to do so far */ 3951 ptrVM.release(); 3941 3952 } 3942 3953 … … 3966 3977 3967 3978 /* don't trigger parallel port change if the VM isn't running */ 3968 if (mpVM) 3969 { 3970 /* protect mpVM */ 3971 AutoVMCaller autoVMCaller(this); 3972 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 3973 3979 SafeVMPtrQuiet ptrVM(this); 3980 if (ptrVM.isOk()) 3981 { 3974 3982 /* nothing to do so far */ 3983 ptrVM.release(); 3975 3984 } 3976 3985 … … 4000 4009 4001 4010 /* don't trigger storage controller change if the VM isn't running */ 4002 if (mpVM) 4003 { 4004 /* protect mpVM */ 4005 AutoVMCaller autoVMCaller(this); 4006 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 4007 4011 SafeVMPtrQuiet ptrVM(this); 4012 if (ptrVM.isOk()) 4013 { 4008 4014 /* nothing to do so far */ 4015 ptrVM.release(); 4009 4016 } 4010 4017 … … 4034 4041 4035 4042 /* don't trigger medium change if the VM isn't running */ 4036 if (mpVM) 4037 { 4038 /* protect mpVM */ 4039 AutoVMCaller autoVMCaller(this); 4040 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 4041 4042 rc = doMediumChange(aMediumAttachment, !!aForce); 4043 SafeVMPtrQuiet ptrVM(this); 4044 if (ptrVM.isOk()) 4045 { 4046 rc = doMediumChange(aMediumAttachment, !!aForce, ptrVM); 4047 ptrVM.release(); 4043 4048 } 4044 4049 … … 4066 4071 4067 4072 /* don't trigger CPU change if the VM isn't running */ 4068 if (mpVM) 4073 SafeVMPtrQuiet ptrVM(this); 4074 if (ptrVM.isOk()) 4069 4075 { 4070 4076 if (aRemove) 4071 rc = doCPURemove(aCPU );4077 rc = doCPURemove(aCPU, ptrVM); 4072 4078 else 4073 rc = doCPUAdd(aCPU); 4079 rc = doCPUAdd(aCPU, ptrVM); 4080 ptrVM.release(); 4074 4081 } 4075 4082 … … 4099 4106 4100 4107 /* don't trigger the CPU priority change if the VM isn't running */ 4101 if (mpVM) 4102 { 4103 /* protect mpVM */ 4104 AutoVMCaller autoVMCaller(this); 4105 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 4106 4108 SafeVMPtrQuiet ptrVM(this); 4109 if (ptrVM.isOk()) 4110 { 4107 4111 if ( mMachineState == MachineState_Running 4108 4112 || mMachineState == MachineState_Teleporting … … 4111 4115 { 4112 4116 /* No need to call in the EMT thread. */ 4113 rc = VMR3SetCpuExecutionCap( mpVM, aExecutionCap);4117 rc = VMR3SetCpuExecutionCap(ptrVM, aExecutionCap); 4114 4118 } 4115 4119 else 4116 4120 rc = setInvalidMachineStateError(); 4121 ptrVM.release(); 4117 4122 } 4118 4123 … … 4215 4220 4216 4221 /* don't trigger USB controller change if the VM isn't running */ 4217 if (mpVM) 4222 SafeVMPtrQuiet ptrVM(this); 4223 if (ptrVM.isOk()) 4218 4224 { 4219 4225 /// @todo implement one day. … … 4224 4230 // handle it at this time... :-) 4225 4231 4226 /* protect mpVM */4227 AutoVMCaller autoVMCaller(this);4228 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();4229 4230 4232 /* nothing to do so far */ 4233 ptrVM.release(); 4231 4234 } 4232 4235 … … 4288 4291 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 4289 4292 4290 /* protect mpVM (we don't need error info, since it's a callback)*/4291 AutoVMCallerQuiet autoVMCaller(this);4292 if ( FAILED(autoVMCaller.rc()))4293 /* Get the VM pointer (we don't need error info, since it's a callback). */ 4294 SafeVMPtrQuiet ptrVM(this); 4295 if (!ptrVM.isOk()) 4293 4296 { 4294 4297 /* The VM may be no more operational when this message arrives … … 4297 4300 LogFlowThisFunc(("Attach request ignored (mMachineState=%d).\n", 4298 4301 mMachineState)); 4299 return autoVMCaller.rc();4302 return ptrVM.rc(); 4300 4303 } 4301 4304 … … 4308 4311 4309 4312 /* Don't proceed unless there's at least one USB hub. */ 4310 if (!PDMR3USBHasHub( mpVM))4313 if (!PDMR3USBHasHub(ptrVM)) 4311 4314 { 4312 4315 LogFlowThisFunc(("Attach request ignored (no USB controller).\n")); … … 4437 4440 4438 4441 /* don't trigger the CPU priority change if the VM isn't running */ 4439 if (mpVM) 4440 { 4441 /* protect mpVM */ 4442 AutoVMCaller autoVMCaller(this); 4443 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 4444 4442 SafeVMPtrQuiet ptrVM(this); 4443 if (ptrVM.isOk()) 4444 { 4445 4445 if ( mMachineState == MachineState_Running 4446 4446 || mMachineState == MachineState_Teleporting … … 4458 4458 { 4459 4459 int vrc; 4460 vrc = PDMR3AsyncCompletionBwMgrSetMaxForFile( mpVM, Utf8Str(strName).c_str(),4460 vrc = PDMR3AsyncCompletionBwMgrSetMaxForFile(ptrVM, Utf8Str(strName).c_str(), 4461 4461 cMax * _1M); 4462 4462 AssertRC(vrc); … … 4465 4465 else 4466 4466 rc = setInvalidMachineStateError(); 4467 ptrVM.release(); 4467 4468 } 4468 4469 … … 4683 4684 4684 4685 /** 4685 * @note Temporarily locks this object for writing. 4686 * @note Temporarily locks this object for writing. bird: And/or reading? 4686 4687 */ 4687 4688 HRESULT Console::onlineMergeMedium(IMediumAttachment *aMediumAttachment, … … 4698 4699 HRESULT rc = S_OK; 4699 4700 int vrc = VINF_SUCCESS; 4700 PVM pVM = mpVM; 4701 4702 /* Get the VM - must be done before the read-locking. */ 4703 SafeVMPtr ptrVM(this); 4704 if (!ptrVM.isOk()) 4705 return ptrVM.rc(); 4701 4706 4702 4707 /* We will need to release the lock before doing the actual merge */ … … 4714 4719 } 4715 4720 4721 /** @todo AssertComRC -> AssertComRCReturn! Could potentially end up 4722 * using uninitialized variables here. */ 4716 4723 BOOL fBuiltinIoCache; 4717 4724 rc = mMachine->COMGETTER(IoCacheEnabled)(&fBuiltinIoCache); … … 4778 4785 4779 4786 /* Pause the VM, as it might have pending IO on this drive */ 4780 VMSTATE enmVMState = VMR3GetState(p VM);4787 VMSTATE enmVMState = VMR3GetState(ptrVM); 4781 4788 if (mMachineState == MachineState_DeletingSnapshotOnline) 4782 4789 { … … 4784 4791 /* disable the callback to prevent Console-level state change */ 4785 4792 mVMStateChangeCallbackDisabled = true; 4786 int vrc2 = VMR3Suspend(p VM);4793 int vrc2 = VMR3Suspend(ptrVM); 4787 4794 mVMStateChangeCallbackDisabled = false; 4788 4795 AssertRCReturn(vrc2, E_FAIL); 4789 4796 } 4790 4797 4791 vrc = VMR3ReqCallWait(p VM,4798 vrc = VMR3ReqCallWait(ptrVM, 4792 4799 VMCPUID_ANY, 4793 4800 (PFNRT)reconfigureMediumAttachment, 4794 4801 13, 4795 4802 this, 4796 p VM,4803 ptrVM.raw(), 4797 4804 pcszDevice, 4798 4805 uInstance, … … 4813 4820 /* disable the callback to prevent Console-level state change */ 4814 4821 mVMStateChangeCallbackDisabled = true; 4815 int vrc2 = VMR3Resume(p VM);4822 int vrc2 = VMR3Resume(ptrVM); 4816 4823 mVMStateChangeCallbackDisabled = false; 4817 4824 if (RT_FAILURE(vrc2)) … … 4819 4826 /* too bad, we failed. try to sync the console state with the VMM state */ 4820 4827 AssertLogRelRC(vrc2); 4821 vmstateChangeCallback(p VM, VMSTATE_SUSPENDED, enmVMState, this);4828 vmstateChangeCallback(ptrVM, VMSTATE_SUSPENDED, enmVMState, this); 4822 4829 } 4823 4830 } … … 4830 4837 PPDMIBASE pIBase = NULL; 4831 4838 PPDMIMEDIA pIMedium = NULL; 4832 vrc = PDMR3QueryDriverOnLun(p VM, pcszDevice, uInstance, uLUN, "VD", &pIBase);4839 vrc = PDMR3QueryDriverOnLun(ptrVM, pcszDevice, uInstance, uLUN, "VD", &pIBase); 4833 4840 if (RT_SUCCESS(vrc)) 4834 4841 { … … 4849 4856 4850 4857 /* Pause the VM, as it might have pending IO on this drive */ 4851 enmVMState = VMR3GetState(p VM);4858 enmVMState = VMR3GetState(ptrVM); 4852 4859 if (mMachineState == MachineState_DeletingSnapshotOnline) 4853 4860 { … … 4855 4862 /* disable the callback to prevent Console-level state change */ 4856 4863 mVMStateChangeCallbackDisabled = true; 4857 int vrc2 = VMR3Suspend(p VM);4864 int vrc2 = VMR3Suspend(ptrVM); 4858 4865 mVMStateChangeCallbackDisabled = false; 4859 4866 AssertRCReturn(vrc2, E_FAIL); … … 4865 4872 ComSafeArrayInArg(aChildrenToReparent)); 4866 4873 4867 vrc = VMR3ReqCallWait(p VM,4874 vrc = VMR3ReqCallWait(ptrVM, 4868 4875 VMCPUID_ANY, 4869 4876 (PFNRT)reconfigureMediumAttachment, 4870 4877 13, 4871 4878 this, 4872 p VM,4879 ptrVM.raw(), 4873 4880 pcszDevice, 4874 4881 uInstance, … … 4889 4896 /* disable the callback to prevent Console-level state change */ 4890 4897 mVMStateChangeCallbackDisabled = true; 4891 int vrc2 = VMR3Resume(p VM);4898 int vrc2 = VMR3Resume(ptrVM); 4892 4899 mVMStateChangeCallbackDisabled = false; 4893 4900 AssertRC(vrc2); … … 4895 4902 { 4896 4903 /* too bad, we failed. try to sync the console state with the VMM state */ 4897 vmstateChangeCallback(p VM, VMSTATE_SUSPENDED, enmVMState, this);4904 vmstateChangeCallback(ptrVM, VMSTATE_SUSPENDED, enmVMState, this); 4898 4905 } 4899 4906 } … … 5197 5204 } 5198 5205 5199 if (mp VM == NULL)5206 if (mpUVM == NULL) 5200 5207 { 5201 5208 Assert(aAllowNullVM == true); … … 5224 5231 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 5225 5232 5226 AssertReturnVoid(mp VM != NULL);5233 AssertReturnVoid(mpUVM != NULL); 5227 5234 5228 5235 Assert(mVMCallers > 0); … … 5235 5242 } 5236 5243 } 5244 5245 5246 HRESULT Console::safeVMPtrRetainer(PVM *a_ppVM, PUVM *a_ppUVM, bool a_Quiet) 5247 { 5248 *a_ppVM = NULL; 5249 *a_ppUVM = NULL; 5250 5251 AutoCaller autoCaller(this); 5252 AssertComRCReturnRC(autoCaller.rc()); 5253 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 5254 5255 /* 5256 * Repeat the checks done by addVMCaller. 5257 */ 5258 if (mVMDestroying) /* powerDown() is waiting for all callers to finish */ 5259 return a_Quiet 5260 ? E_ACCESSDENIED 5261 : setError(E_ACCESSDENIED, tr("The virtual machine is being powered down")); 5262 PUVM pUVM = mpUVM; 5263 if (!pUVM) 5264 return a_Quiet 5265 ? E_ACCESSDENIED 5266 : setError(E_ACCESSDENIED, tr("The virtual machine is was powered off")); 5267 5268 /* 5269 * Retain a reference to the user mode VM handle and get the global handle. 5270 */ 5271 uint32_t cRefs = VMR3RetainUVM(pUVM); 5272 if (cRefs == UINT32_MAX) 5273 return a_Quiet 5274 ? E_ACCESSDENIED 5275 : setError(E_ACCESSDENIED, tr("The virtual machine is was powered off")); 5276 5277 PVM pVM = VMR3GetVM(pUVM); 5278 if (!pVM) 5279 { 5280 VMR3ReleaseUVM(pUVM); 5281 return a_Quiet 5282 ? E_ACCESSDENIED 5283 : setError(E_ACCESSDENIED, tr("The virtual machine is was powered off")); 5284 } 5285 5286 /* done */ 5287 *a_ppVM = pVM; 5288 *a_ppUVM = pUVM; 5289 return S_OK; 5290 } 5291 5292 void Console::safeVMPtrReleaser(PVM *a_ppVM, PUVM *a_ppUVM) 5293 { 5294 if (*a_ppVM && *a_ppUVM) 5295 VMR3ReleaseUVM(*a_ppUVM); 5296 *a_ppVM = NULL; 5297 *a_ppUVM = NULL; 5298 } 5299 5237 5300 5238 5301 /** … … 5870 5933 Assert(mVMDestroying == false); 5871 5934 5872 Assert(mpVM != NULL); 5935 PUVM pUVM = mpUVM; Assert(pUVM != NULL); 5936 uint32_t cRefs = VMR3RetainUVM(pUVM); Assert(cRefs != UINT32_MAX); 5873 5937 5874 5938 AssertMsg( mMachineState == MachineState_Running … … 5986 6050 LogFlowThisFunc(("Powering off the VM...\n")); 5987 6051 alock.leave(); 5988 vrc = VMR3PowerOff( mpVM);6052 vrc = VMR3PowerOff(VMR3GetVM(pUVM)); 5989 6053 #ifdef VBOX_WITH_EXTPACK 5990 mptrExtPackManager->callAllVmPowerOffHooks(this, mpVM);6054 mptrExtPackManager->callAllVmPowerOffHooks(this, VMR3GetVM(pUVM)); 5991 6055 #endif 5992 6056 alock.enter(); … … 6028 6092 { 6029 6093 PPDMIBASE pBase; 6030 vrc = PDMR3QueryLun( mpVM, "usb-ohci", 0, 0, &pBase);6094 vrc = PDMR3QueryLun(VMR3GetVM(pUVM), "usb-ohci", 0, 0, &pBase); 6031 6095 if (RT_SUCCESS(vrc)) 6032 6096 { … … 6043 6107 * mVMDestroying is set which should prevent any activity. */ 6044 6108 6045 /* Set mp VM to NULL early just in case if some old code is not using6046 * addVMCaller()/releaseVMCaller(). */6047 PVM pVM = mpVM;6048 mp VM = NULL;6109 /* Set mpUVM to NULL early just in case if some old code is not using 6110 * addVMCaller()/releaseVMCaller(). (We have our own ref on pUVM.) */ 6111 VMR3ReleaseUVM(mpUVM); 6112 mpUVM = NULL; 6049 6113 6050 6114 LogFlowThisFunc(("Destroying the VM...\n")); … … 6052 6116 alock.leave(); 6053 6117 6054 vrc = VMR3Destroy( pVM);6118 vrc = VMR3Destroy(VMR3GetVM(pUVM)); 6055 6119 6056 6120 /* take the lock again */ … … 6075 6139 else 6076 6140 { 6077 /* bad bad bad, but what to do? */ 6078 mpVM = pVM; 6141 /* bad bad bad, but what to do? (Give Console our UVM ref.) */ 6142 mpUVM = pUVM; 6143 pUVM = NULL; 6079 6144 rc = setError(VBOX_E_VM_ERROR, 6080 6145 tr("Could not destroy the machine. (Error: %Rrc)"), … … 6097 6162 } 6098 6163 6099 /* Finished with destruction. Note that if something impossible happened and 6100 * we've failed to destroy the VM, mVMDestroying will remain true and 6101 * mMachineState will be something like Stopping, so most Console methods 6102 * will return an error to the caller. */ 6103 if (mpVM == NULL) 6164 /* 6165 * Finished with the destruction. 6166 * 6167 * Note that if something impossible happened and we've failed to destroy 6168 * the VM, mVMDestroying will remain true and mMachineState will be 6169 * something like Stopping, so most Console methods will return an error 6170 * to the caller. 6171 */ 6172 if (mpUVM != NULL) 6173 VMR3ReleaseUVM(pUVM); 6174 else 6104 6175 mVMDestroying = false; 6105 6176 … … 6215 6286 LogFlowThisFunc(("Entering\n")); 6216 6287 6217 /* protect mpVM (if not NULL) */ 6288 /* Check if we're online and keep it that way. */ 6289 SafeVMPtrQuiet ptrVM(this); 6218 6290 AutoVMCallerQuietWeak autoVMCaller(this); 6291 bool const online = ptrVM.isOk() 6292 && m_pVMMDev 6293 && m_pVMMDev->isShFlActive(); 6219 6294 6220 6295 HRESULT rc = S_OK; 6221 6222 bool online = mpVM6223 && autoVMCaller.isOk()6224 && m_pVMMDev6225 && m_pVMMDev->isShFlActive();6226 6296 6227 6297 try … … 6336 6406 { 6337 6407 if (online) 6338 setVMRuntimeErrorCallbackF( mpVM, this, 0, "BrokenSharedFolder",6408 setVMRuntimeErrorCallbackF(ptrVM, this, 0, "BrokenSharedFolder", 6339 6409 N_("Broken shared folder!")); 6340 6410 } … … 6389 6459 6390 6460 /* sanity checks */ 6391 AssertReturn(mp VM, E_FAIL);6461 AssertReturn(mpUVM, E_FAIL); 6392 6462 AssertReturn(m_pVMMDev && m_pVMMDev->isShFlActive(), E_FAIL); 6393 6463 … … 6494 6564 6495 6565 /* sanity checks */ 6496 AssertReturn(mp VM, E_FAIL);6566 AssertReturn(mpUVM, E_FAIL); 6497 6567 AssertReturn(m_pVMMDev && m_pVMMDev->isShFlActive(), E_FAIL); 6498 6568 … … 6889 6959 ComAssertComRCRetRC(hrc); 6890 6960 6891 /* protect mpVM */ 6892 AutoVMCaller autoVMCaller(this); 6893 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 6961 /* Get the VM handle. */ 6962 SafeVMPtr ptrVM(this); 6963 if (!ptrVM.isOk()) 6964 return ptrVM.rc(); 6894 6965 6895 6966 LogFlowThisFunc(("Proxying USB device '%s' {%RTuuid}...\n", … … 6900 6971 6901 6972 /** @todo just do everything here and only wrap the PDMR3Usb call. That'll offload some notification stuff from the EMT thread. */ 6902 int vrc = VMR3ReqCallWait(mpVM, VMCPUID_ANY, 6903 (PFNRT)usbAttachCallback, 6, this, aHostDevice, uuid.raw(), fRemote, Address.c_str(), aMaskedIfs); 6973 int vrc = VMR3ReqCallWait(ptrVM, VMCPUID_ANY, 6974 (PFNRT)usbAttachCallback, 7, 6975 this, ptrVM.raw(), aHostDevice, uuid.raw(), fRemote, Address.c_str(), aMaskedIfs); 6904 6976 6905 6977 /* restore the lock */ … … 6911 6983 { 6912 6984 LogWarningThisFunc(("Failed to create proxy device for '%s' {%RTuuid} (%Rrc)\n", 6913 6985 Address.c_str(), uuid.raw(), vrc)); 6914 6986 6915 6987 switch (vrc) … … 6945 7017 //static 6946 7018 DECLCALLBACK(int) 6947 Console::usbAttachCallback(Console *that, IUSBDevice *aHostDevice, PCRTUUID aUuid, bool aRemote, const char *aAddress, ULONG aMaskedIfs)7019 Console::usbAttachCallback(Console *that, PVM pVM, IUSBDevice *aHostDevice, PCRTUUID aUuid, bool aRemote, const char *aAddress, ULONG aMaskedIfs) 6948 7020 { 6949 7021 LogFlowFuncEnter(); … … 6968 7040 Assert(portVersion == 1 || portVersion == 2); 6969 7041 6970 int vrc = PDMR3USBCreateProxyDevice( that->mpVM, aUuid, aRemote, aAddress, pvRemoteBackend,7042 int vrc = PDMR3USBCreateProxyDevice(pVM, aUuid, aRemote, aAddress, pvRemoteBackend, 6971 7043 portVersion == 1 ? VUSB_STDVER_11 : VUSB_STDVER_20, aMaskedIfs); 6972 7044 if (RT_SUCCESS(vrc)) … … 7008 7080 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 7009 7081 7010 /* protect mpVM */ 7011 AutoVMCaller autoVMCaller(this); 7012 if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc(); 7082 /* Get the VM handle. */ 7083 SafeVMPtr ptrVM(this); 7084 if (!ptrVM.isOk()) 7085 return ptrVM.rc(); 7013 7086 7014 7087 /* if the device is attached, then there must at least one USB hub. */ 7015 AssertReturn(PDMR3USBHasHub( mpVM), E_FAIL);7088 AssertReturn(PDMR3USBHasHub(ptrVM), E_FAIL); 7016 7089 7017 7090 LogFlowThisFunc(("Detaching USB proxy device {%RTuuid}...\n", 7018 7091 (*aIt)->id().raw())); 7019 7092 7020 7093 /* leave the lock before a VMR3* call (EMT will call us back)! */ … … 7022 7095 7023 7096 /** @todo just do everything here and only wrap the PDMR3Usb call. That'll offload some notification stuff from the EMT thread. */ 7024 int vrc = VMR3ReqCallWait(mpVM, VMCPUID_ANY, 7025 (PFNRT) usbDetachCallback, 4, this, &aIt, (*aIt)->id().raw()); 7097 int vrc = VMR3ReqCallWait(ptrVM, VMCPUID_ANY, 7098 (PFNRT)usbDetachCallback, 5, 7099 this, ptrVM.raw(), &aIt, (*aIt)->id().raw()); 7026 7100 ComAssertRCRet(vrc, E_FAIL); 7027 7101 … … 7040 7114 //static 7041 7115 DECLCALLBACK(int) 7042 Console::usbDetachCallback(Console *that, USBDeviceList::iterator *aIt, PCRTUUID aUuid)7116 Console::usbDetachCallback(Console *that, PVM pVM, USBDeviceList::iterator *aIt, PCRTUUID aUuid) 7043 7117 { 7044 7118 LogFlowFuncEnter(); … … 7064 7138 } 7065 7139 7066 int vrc = PDMR3USBDetachDevice( that->mpVM, aUuid);7140 int vrc = PDMR3USBDetachDevice(pVM, aUuid); 7067 7141 7068 7142 if (RT_SUCCESS(vrc)) … … 7731 7805 7732 7806 /* sanity */ 7733 Assert(pConsole->mp VM == NULL);7807 Assert(pConsole->mpUVM == NULL); 7734 7808 7735 7809 try … … 7956 8030 /* -> ConsoleImplTeleporter.cpp */ 7957 8031 bool fPowerOffOnFailure; 7958 rc = pConsole->teleporterTrg( pVM, pMachine, &task->mErrorMsg, task->mStartPaused,8032 rc = pConsole->teleporterTrg(VMR3GetUVM(pVM), pMachine, &task->mErrorMsg, task->mStartPaused, 7959 8033 task->mProgress, &fPowerOffOnFailure); 7960 8034 if (FAILED(rc) && fPowerOffOnFailure) … … 8060 8134 * If VMR3Create() failed it has released the VM memory. 8061 8135 */ 8062 pConsole->mpVM = NULL; 8136 VMR3ReleaseUVM(pConsole->mpUVM); 8137 pConsole->mpUVM = NULL; 8063 8138 } 8064 8139 … … 8107 8182 ErrorInfoKeeper eik; 8108 8183 8109 Assert(pConsole->mp VM == NULL);8184 Assert(pConsole->mpUVM == NULL); 8110 8185 vmstateChangeCallback(NULL, VMSTATE_TERMINATED, VMSTATE_CREATING, 8111 8186 pConsole); … … 8232 8307 static void takesnapshotProgressCancelCallback(void *pvUser) 8233 8308 { 8234 P VM pVM = (PVM)pvUser;8235 SSMR3Cancel( pVM);8309 PUVM pUVM = (PUVM)pvUser; 8310 SSMR3Cancel(VMR3GetVM(pUVM)); 8236 8311 } 8237 8312 … … 8308 8383 Utf8Str strSavedStateFile(pTask->bstrSavedStateFile); 8309 8384 8385 SafeVMPtr ptrVM(that); 8386 if (!ptrVM.isOk()) 8387 throw ptrVM.rc(); 8388 8310 8389 pTask->mProgress->SetNextOperation(Bstr(tr("Saving the machine state")).raw(), 8311 8390 pTask->ulMemSize); // operation weight, same as computed when setting up progress object 8312 pTask->mProgress->setCancelCallback(takesnapshotProgressCancelCallback, that->mpVM);8391 pTask->mProgress->setCancelCallback(takesnapshotProgressCancelCallback, ptrVM.rawUVM()); 8313 8392 8314 8393 alock.leave(); 8315 8394 LogFlowFunc(("VMR3Save...\n")); 8316 int vrc = VMR3Save( that->mpVM,8395 int vrc = VMR3Save(ptrVM, 8317 8396 strSavedStateFile.c_str(), 8318 8397 true /*fContinueAfterwards*/, … … 8391 8470 * isn't going to need the Console lock. 8392 8471 */ 8393 vrc = VMR3ReqCallWait( that->mpVM,8472 vrc = VMR3ReqCallWait(ptrVM, 8394 8473 VMCPUID_ANY, 8395 8474 (PFNRT)reconfigureMediumAttachment, 8396 8475 13, 8397 8476 that, 8398 that->mpVM,8477 ptrVM.raw(), 8399 8478 pcszDevice, 8400 8479 lInstance, … … 8462 8541 { 8463 8542 LogFlowFunc(("VMR3Resume...\n")); 8543 SafeVMPtr ptrVM(that); 8464 8544 alock.leave(); 8465 int vrc = VMR3Resume( that->mpVM);8545 int vrc = VMR3Resume(ptrVM); 8466 8546 alock.enter(); 8467 8547 if (RT_FAILURE(vrc)) … … 8480 8560 /** @todo this could probably be made more generic and reused elsewhere. */ 8481 8561 /* paranoid cleanup on for a failed online snapshot. */ 8482 VMSTATE enmVMState = VMR3GetState (that->mpVM);8562 VMSTATE enmVMState = VMR3GetStateU(that->mpUVM); 8483 8563 switch (enmVMState) 8484 8564 { … … 8519 8599 Assert(pTask->lastMachineState == MachineState_Running); 8520 8600 LogFlowFunc(("VMR3Resume (on failure)...\n")); 8601 SafeVMPtr ptrVM(that); 8521 8602 alock.leave(); 8522 int vrc = VMR3Resume( that->mpVM); AssertLogRelRC(vrc);8603 int vrc = VMR3Resume(ptrVM); AssertLogRelRC(vrc); 8523 8604 alock.enter(); 8524 8605 if (RT_FAILURE(vrc)) … … 8580 8661 8581 8662 bool fSuspenededBySave; 8582 int vrc = VMR3Save(t hat->mpVM,8663 int vrc = VMR3Save(task->mpVM, 8583 8664 task->mSavedStateFile.c_str(), 8584 8665 false, /*fContinueAfterwards*/ -
trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp
r36024 r36041 557 557 * can easily reset the VM handle on failure. 558 558 */ 559 pConsole->mpVM = pVM; 559 PUVM pUVM = pConsole->mpUVM = VMR3GetUVM(pVM); 560 VMR3RetainUVM(pUVM); 560 561 int vrc = pConsole->configConstructorInner(pVM, &alock); 561 562 if (RT_FAILURE(vrc)) 562 pConsole->mpVM = NULL; 563 { 564 pConsole->mpUVM = NULL; 565 VMR3ReleaseUVM(pUVM); 566 } 563 567 564 568 return vrc; … … 3169 3173 Bstr loc; 3170 3174 hrc = pMedium->COMGETTER(Location)(loc.asOutParam()); H(); 3171 setVMRuntimeErrorCallbackF( mpVM,3172 this,3173 0,3174 "DvdOrFloppyImageInaccessible",3175 "The image file '%ls' is inaccessible and is being ignored. Please select a different image file for the virtual %s drive.",3176 loc.raw(),3177 (enmType == DeviceType_DVD)? "DVD" : "floppy");3175 setVMRuntimeErrorCallbackF(VMR3GetVM(mpUVM), 3176 this, 3177 0, 3178 "DvdOrFloppyImageInaccessible", 3179 "The image file '%ls' is inaccessible and is being ignored. Please select a different image file for the virtual %s drive.", 3180 loc.raw(), 3181 enmType == DeviceType_DVD ? "DVD" : "floppy"); 3178 3182 pMedium = NULL; 3179 3183 } … … 3391 3395 * (makes only sense for bridged/host-only networks). 3392 3396 * 3393 * @note Locks this object for writing. 3397 * @note Locks this object for writing. 3398 * @thread EMT 3394 3399 */ 3395 3400 int Console::configNetwork(const char *pszDevice, … … 3422 3427 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3423 3428 3424 PVM pVM = mpVM;3429 PVM pVM = VMR3GetVM(mpUVM); /* We're on an EMT, so this is safe. */ 3425 3430 3426 3431 ComPtr<IMachine> pMachine = machine(); … … 3904 3909 { 3905 3910 struct ifreq Req; 3906 3907 memset(&Req, 0, sizeof(Req)); 3911 RT_ZERO(Req); 3908 3912 strncpy(Req.ifr_name, pszHifName, sizeof(Req.ifr_name) - 1); 3909 3913 if (ioctl(iSock, SIOCGIFFLAGS, &Req) >= 0) 3910 3914 if ((Req.ifr_flags & IFF_UP) == 0) 3911 {3912 setVMRuntimeErrorCallbackF(pVM, this, 0, "BridgedInterfaceDown", "Bridged interface %s is down. Guest will not be able to use this interface", pszHifName);3913 }3915 setVMRuntimeErrorCallbackF(pVM, this, 0, "BridgedInterfaceDown", 3916 "Bridged interface %s is down. Guest will not be able to use this interface", 3917 pszHifName); 3914 3918 3915 3919 close(iSock); -
trunk/src/VBox/Main/src-client/ConsoleImplTeleporter.cpp
r35368 r36041 54 54 public: 55 55 ComPtr<Console> mptrConsole; 56 P VM mpVM;56 PUVM mpUVM; 57 57 ComObjPtr<Progress> mptrProgress; 58 58 Utf8Str mstrPassword; … … 69 69 /** @} */ 70 70 71 TeleporterState(Console *pConsole, P VM pVM, Progress *pProgress, bool fIsSource)71 TeleporterState(Console *pConsole, PUVM pUVM, Progress *pProgress, bool fIsSource) 72 72 : mptrConsole(pConsole) 73 , mp VM(pVM)73 , mpUVM(pUVM) 74 74 , mptrProgress(pProgress) 75 75 , mfIsSource(fIsSource) … … 81 81 , mfIOError(false) 82 82 { 83 VMR3RetainUVM(mpUVM); 84 } 85 86 ~TeleporterState() 87 { 88 VMR3ReleaseUVM(mpUVM); 89 mpUVM = NULL; 83 90 } 84 91 }; … … 98 105 bool mfUnlockedMedia; 99 106 100 TeleporterStateSrc(Console *pConsole, P VM pVM, Progress *pProgress, MachineState_T enmOldMachineState)101 : TeleporterState(pConsole, p VM, pProgress, true /*fIsSource*/)107 TeleporterStateSrc(Console *pConsole, PUVM pUVM, Progress *pProgress, MachineState_T enmOldMachineState) 108 : TeleporterState(pConsole, pUVM, pProgress, true /*fIsSource*/) 102 109 , muPort(UINT32_MAX) 103 110 , mcMsMaxDowntime(250) … … 124 131 Utf8Str mErrorText; 125 132 126 TeleporterStateTrg(Console *pConsole, P VM pVM, Progress *pProgress,133 TeleporterStateTrg(Console *pConsole, PUVM pUVM, Progress *pProgress, 127 134 IMachine *pMachine, IInternalMachineControl *pControl, 128 135 PRTTIMERLR phTimerLR, bool fStartPaused) 129 : TeleporterState(pConsole, p VM, pProgress, false /*fIsSource*/)136 : TeleporterState(pConsole, pUVM, pProgress, false /*fIsSource*/) 130 137 , mpMachine(pMachine) 131 138 , mpControl(pControl) … … 566 573 { 567 574 TeleporterState *pState = (TeleporterState *)pvUser; 568 SSMR3Cancel( pState->mpVM);575 SSMR3Cancel(VMR3GetVM(pState->mpUVM)); 569 576 if (!pState->mfIsSource) 570 577 { … … 590 597 if (SUCCEEDED(hrc) && fCanceled) 591 598 { 592 SSMR3Cancel( pState->mpVM);599 SSMR3Cancel(VMR3GetVM(pState->mpUVM)); 593 600 return VERR_SSM_CANCELLED; 594 601 } … … 678 685 RTSocketRetain(pState->mhSocket); 679 686 void *pvUser = static_cast<void *>(static_cast<TeleporterState *>(pState)); 680 vrc = VMR3Teleport(pState->mpVM, pState->mcMsMaxDowntime, 681 &g_teleporterTcpOps, pvUser, 682 teleporterProgressCallback, pvUser, 687 vrc = VMR3Teleport(VMR3GetVM(pState->mpUVM), 688 pState->mcMsMaxDowntime, 689 &g_teleporterTcpOps, pvUser, 690 teleporterProgressCallback, pvUser, 683 691 &pState->mfSuspendedByUs); 684 692 RTSocketRelease(pState->mhSocket); … … 758 766 * and do the cleanups afterwards. 759 767 */ 760 AutoVMCaller autoVMCaller(pState->mptrConsole);761 HRESULT hrc = autoVMCaller.rc();768 SafeVMPtr ptrVM(pState->mptrConsole); 769 HRESULT hrc = ptrVM.rc(); 762 770 763 771 if (SUCCEEDED(hrc)) … … 786 794 pState->mptrConsole->mptrCancelableProgress.setNull(); 787 795 788 VMSTATE const enmVMState = VMR3GetState (pState->mpVM);796 VMSTATE const enmVMState = VMR3GetStateU(pState->mpUVM); 789 797 MachineState_T const enmMachineState = pState->mptrConsole->mMachineState; 790 798 if (SUCCEEDED(hrc)) … … 799 807 AssertLogRelMsg(enmMachineState == MachineState_TeleportingPausedVM, ("%s\n", Global::stringifyMachineState(enmMachineState))); 800 808 801 autoVMCaller.release();809 ptrVM.release(); 802 810 803 811 pState->mptrConsole->mVMIsAlreadyPoweringOff = true; /* (Make sure we stick in the TeleportingPausedVM state.) */ … … 878 886 { 879 887 autoLock.leave(); 880 int rc = VMR3Resume( pState->mpVM);888 int rc = VMR3Resume(VMR3GetVM(pState->mpUVM)); 881 889 AssertLogRelMsgRC(rc, ("VMR3Resume -> %Rrc\n", rc)); 882 890 autoLock.enter(); … … 955 963 ComObjPtr<Progress> ptrProgress; 956 964 HRESULT hrc = ptrProgress.createObject(); 957 if (FAILED(hrc)) return hrc; 958 hrc = ptrProgress->init(static_cast<IConsole *>(this), 959 Bstr(tr("Teleporter")).raw(), 960 TRUE /*aCancelable*/); 961 if (FAILED(hrc)) return hrc; 962 963 TeleporterStateSrc *pState = new TeleporterStateSrc(this, mpVM, ptrProgress, mMachineState); 965 if (SUCCEEDED(hrc)) 966 hrc = ptrProgress->init(static_cast<IConsole *>(this), 967 Bstr(tr("Teleporter")).raw(), 968 TRUE /*aCancelable*/); 969 if (FAILED(hrc)) 970 return hrc; 971 972 TeleporterStateSrc *pState = new TeleporterStateSrc(this, mpUVM, ptrProgress, mMachineState); 964 973 pState->mstrPassword = aPassword; 965 974 pState->mstrHostname = aHostname; … … 1002 1011 * 1003 1012 * @returns VBox status code. 1004 * @param p VM The VM handle1013 * @param pUVM The user-mode VM handle 1005 1014 * @param pMachine The IMachine for the virtual machine. 1006 1015 * @param pErrorMsg Pointer to the error string for VMSetError. … … 1015 1024 */ 1016 1025 HRESULT 1017 Console::teleporterTrg(P VM pVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,1026 Console::teleporterTrg(PUVM pUVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused, 1018 1027 Progress *pProgress, bool *pfPowerOffOnFailure) 1019 1028 { 1020 LogThisFunc(("p VM=%p pMachine=%p fStartPaused=%RTbool pProgress=%p\n", pVM, pMachine, fStartPaused, pProgress));1029 LogThisFunc(("pUVM=%p pMachine=%p fStartPaused=%RTbool pProgress=%p\n", pUVM, pMachine, fStartPaused, pProgress)); 1021 1030 1022 1031 *pfPowerOffOnFailure = true; … … 1087 1096 * Do the job, when it returns we're done. 1088 1097 */ 1089 TeleporterStateTrg theState(this, p VM, pProgress, pMachine, mControl, &hTimerLR, fStartPaused);1098 TeleporterStateTrg theState(this, pUVM, pProgress, pMachine, mControl, &hTimerLR, fStartPaused); 1090 1099 theState.mstrPassword = strPassword; 1091 1100 theState.mhServer = hServer; … … 1111 1120 else 1112 1121 { 1113 VMSTATE enmVMState = VMR3GetState (pVM);1122 VMSTATE enmVMState = VMR3GetStateU(pUVM); 1114 1123 if ( enmVMState != VMSTATE_OFF 1115 1124 && enmVMState != VMSTATE_POWERING_OFF) … … 1320 1329 break; 1321 1330 1322 int vrc2 = VMR3AtErrorRegister(pState->mpVM, Console::genericVMSetErrorCallback, &pState->mErrorText); AssertRC(vrc2); 1331 int vrc2 = VMR3AtErrorRegisterU(pState->mpUVM, 1332 Console::genericVMSetErrorCallback, &pState->mErrorText); AssertRC(vrc2); 1323 1333 RTSocketRetain(pState->mhSocket); /* For concurrent access by I/O thread and EMT. */ 1324 1334 pState->moffStream = 0; 1325 1335 1326 1336 void *pvUser2 = static_cast<void *>(static_cast<TeleporterState *>(pState)); 1327 vrc = VMR3LoadFromStream(pState->mpVM, &g_teleporterTcpOps, pvUser2, 1337 vrc = VMR3LoadFromStream(VMR3GetVM(pState->mpUVM), 1338 &g_teleporterTcpOps, pvUser2, 1328 1339 teleporterProgressCallback, pvUser2); 1329 1340 1330 1341 RTSocketRelease(pState->mhSocket); 1331 vrc2 = VMR3AtErrorDeregister( pState->mpVM, Console::genericVMSetErrorCallback, &pState->mErrorText); AssertRC(vrc2);1342 vrc2 = VMR3AtErrorDeregister(VMR3GetVM(pState->mpUVM), Console::genericVMSetErrorCallback, &pState->mErrorText); AssertRC(vrc2); 1332 1343 1333 1344 if (RT_FAILURE(vrc)) … … 1392 1403 { 1393 1404 if (!strcmp(szCmd, "hand-over-resume")) 1394 vrc = VMR3Resume( pState->mpVM);1405 vrc = VMR3Resume(VMR3GetVM(pState->mpUVM)); 1395 1406 else 1396 1407 pState->mptrConsole->setMachineState(MachineState_Paused); -
trunk/src/VBox/VMM/VMMR3/PDM.cpp
r35787 r36041 2087 2087 LogFlow(("PDMR3QueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n", 2088 2088 pszDevice, pszDevice, iInstance, iLun, ppBase)); 2089 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 2089 2090 2090 2091 /* -
trunk/src/VBox/VMM/VMMR3/VM.cpp
r35810 r36041 81 81 #include <iprt/semaphore.h> 82 82 #include <iprt/thread.h> 83 #include <iprt/uuid.h> 83 84 84 85 … … 461 462 AssertCompile(sizeof(pUVM->vm.s) <= sizeof(pUVM->vm.padding)); 462 463 464 pUVM->vm.s.cUvmRefs = 1; 463 465 pUVM->vm.s.ppAtStateNext = &pUVM->vm.s.pAtState; 464 466 pUVM->vm.s.ppAtErrorNext = &pUVM->vm.s.pAtError; … … 466 468 467 469 pUVM->vm.s.enmHaltMethod = VMHALTMETHOD_BOOTSTRAP; 470 RTUuidClear(&pUVM->vm.s.Uuid); 468 471 469 472 /* Initialize the VMCPU array in the UVM. */ … … 563 566 static int vmR3CreateU(PUVM pUVM, uint32_t cCpus, PFNCFGMCONSTRUCTOR pfnCFGMConstructor, void *pvUserCFGM) 564 567 { 565 int rc = VINF_SUCCESS;566 567 568 /* 568 569 * Load the VMMR0.r0 module so that we can call GVMMR0CreateVM. 569 570 */ 570 rc = PDMR3LdrLoadVMMR0U(pUVM);571 int rc = PDMR3LdrLoadVMMR0U(pUVM); 571 572 if (RT_FAILURE(rc)) 572 573 { … … 657 658 } 658 659 } 660 661 /* 662 * Get the CPU execution cap. 663 */ 659 664 if (RT_SUCCESS(rc)) 660 665 { 661 666 rc = CFGMR3QueryU32Def(pRoot, "CpuExecutionCap", &pVM->uCpuExecutionCap, 100); 662 667 AssertLogRelMsgRC(rc, ("Configuration error: Querying \"CpuExecutionCap\" as integer failed, rc=%Rrc\n", rc)); 663 668 } 669 670 /* 671 * Get the VM name and UUID. 672 */ 673 if (RT_SUCCESS(rc)) 674 { 675 rc = CFGMR3QueryStringAllocDef(pRoot, "Name", &pUVM->vm.s.pszName, "<unknown>"); 676 AssertLogRelMsg(RT_SUCCESS(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND, ("Configuration error: Querying \"Name\" failed, rc=%Rrc\n", rc)); 677 } 678 679 if (RT_SUCCESS(rc)) 680 { 681 rc = CFGMR3QueryBytes(pRoot, "UUID", &pUVM->vm.s.Uuid, sizeof(pUVM->vm.s.Uuid)); 682 AssertLogRelMsg(RT_SUCCESS(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND, ("Configuration error: Querying \"UUID\" failed, rc=%Rrc\n", rc)); 683 } 684 685 if (RT_SUCCESS(rc)) 686 { 664 687 /* 665 688 * Init the ring-3 components and ring-3 per cpu data, finishing it off … … 2263 2286 */ 2264 2287 if (!pVM) 2265 return VERR_INVALID_ PARAMETER;2288 return VERR_INVALID_VM_HANDLE; 2266 2289 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 2267 2290 AssertLogRelReturn(!VM_IS_EMT(pVM), VERR_VM_THREAD_IS_EMT); … … 2541 2564 2542 2565 /* 2543 * Destroy the MM heap and free the UVM structure. 2544 */ 2545 MMR3TermUVM(pUVM); 2546 STAMR3TermUVM(pUVM); 2547 2566 * Release the UVM structure reference. 2567 */ 2568 VMR3ReleaseUVM(pUVM); 2569 2570 /* 2571 * Clean up and flush logs. 2572 */ 2548 2573 #ifdef LOG_ENABLED 2549 2574 RTLogSetCustomPrefixCallback(NULL, NULL, NULL); 2550 2575 #endif 2551 RTTlsFree(pUVM->vm.s.idxTLS);2552 2553 ASMAtomicUoWriteU32(&pUVM->u32Magic, UINT32_MAX);2554 RTMemPageFree(pUVM, RT_OFFSETOF(UVM, aCpus[pUVM->cCpus]));2555 2556 2576 RTLogFlush(NULL); 2557 2577 } … … 2852 2872 2853 2873 /** 2874 * Gets the user mode VM structure pointer given the VM handle. 2875 * 2876 * @returns Pointer to the user mode VM structure on success. NULL if @a pVM is 2877 * invalid (asserted). 2878 * @param pVM The VM handle. 2879 * @sa VMR3GetVM, VMR3RetainUVM 2880 */ 2881 VMMR3DECL(PUVM) VMR3GetUVM(PVM pVM) 2882 { 2883 VM_ASSERT_VALID_EXT_RETURN(pVM, NULL); 2884 return pVM->pUVM; 2885 } 2886 2887 2888 /** 2889 * Gets the shared VM structure pointer given the pointer to the user mode VM 2890 * structure. 2891 * 2892 * @returns Pointer to the shared VM structure. 2893 * NULL if @a pUVM is invalid (asserted) or if no shared VM structure 2894 * is currently associated with it. 2895 * @param pUVM The user mode VM handle. 2896 * @sa VMR3GetUVM 2897 */ 2898 VMMR3DECL(PVM) VMR3GetVM(PUVM pUVM) 2899 { 2900 UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL); 2901 return pUVM->pVM; 2902 } 2903 2904 2905 /** 2906 * Retain the user mode VM handle. 2907 * 2908 * @returns Reference count. 2909 * UINT32_MAX if @a pUVM is invalid. 2910 * 2911 * @param pUVM The user mode VM handle. 2912 * @sa VMR3ReleaseUVM 2913 */ 2914 VMMR3DECL(uint32_t) VMR3RetainUVM(PUVM pUVM) 2915 { 2916 UVM_ASSERT_VALID_EXT_RETURN(pUVM, UINT32_MAX); 2917 uint32_t cRefs = ASMAtomicIncU32(&pUVM->vm.s.cUvmRefs); 2918 AssertMsg(cRefs > 0 && cRefs < _64K, ("%u\n", cRefs)); 2919 return cRefs; 2920 } 2921 2922 2923 /** 2924 * Does the final release of the UVM structure. 2925 * 2926 * @param pUVM The user mode VM handle. 2927 */ 2928 static void vmR3DoReleaseUVM(PUVM pUVM) 2929 { 2930 /* 2931 * Free the UVM. 2932 */ 2933 Assert(!pUVM->pVM); 2934 2935 MMR3TermUVM(pUVM); 2936 STAMR3TermUVM(pUVM); 2937 2938 ASMAtomicUoWriteU32(&pUVM->u32Magic, UINT32_MAX); 2939 RTTlsFree(pUVM->vm.s.idxTLS); 2940 RTMemPageFree(pUVM, RT_OFFSETOF(UVM, aCpus[pUVM->cCpus])); 2941 } 2942 2943 2944 /** 2945 * Releases a refernece to the mode VM handle. 2946 * 2947 * @returns The new reference count, 0 if destroyed. 2948 * UINT32_MAX if @a pUVM is invalid. 2949 * 2950 * @param pUVM The user mode VM handle. 2951 * @sa VMR3RetainUVM 2952 */ 2953 VMMR3DECL(uint32_t) VMR3ReleaseUVM(PUVM pUVM) 2954 { 2955 if (!pUVM) 2956 return 0; 2957 UVM_ASSERT_VALID_EXT_RETURN(pUVM, UINT32_MAX); 2958 uint32_t cRefs = ASMAtomicDecU32(&pUVM->vm.s.cUvmRefs); 2959 if (!cRefs) 2960 vmR3DoReleaseUVM(pUVM); 2961 else 2962 AssertMsg(cRefs < _64K, ("%u\n", cRefs)); 2963 return cRefs; 2964 } 2965 2966 2967 /** 2968 * Gets the VM name. 2969 * 2970 * @returns Pointer to a read-only string containing the name. NULL if called 2971 * too early. 2972 * @param pUVM The user mode VM handle. 2973 */ 2974 VMMR3DECL(const char *) VMR3GetName(PUVM pUVM) 2975 { 2976 UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL); 2977 return pUVM->vm.s.pszName; 2978 } 2979 2980 2981 /** 2982 * Gets the VM UUID. 2983 * 2984 * @returns pUuid on success, NULL on failure. 2985 * @param pUVM The user mode VM handle. 2986 * @param pUuid Where to store the UUID. 2987 */ 2988 VMMR3DECL(PRTUUID) VMR3GetUuid(PUVM pUVM, PRTUUID pUuid) 2989 { 2990 UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL); 2991 AssertPtrReturn(pUuid, NULL); 2992 2993 *pUuid = pUVM->vm.s.Uuid; 2994 return pUuid; 2995 } 2996 2997 2998 /** 2854 2999 * Gets the current VM state. 2855 3000 * … … 2860 3005 VMMR3DECL(VMSTATE) VMR3GetState(PVM pVM) 2861 3006 { 3007 VM_ASSERT_VALID_EXT_RETURN(pVM, VMSTATE_TERMINATED); 2862 3008 return pVM->enmVMState; 3009 } 3010 3011 3012 /** 3013 * Gets the current VM state. 3014 * 3015 * @returns The current VM state. 3016 * @param pUVM The user-mode VM handle. 3017 * @thread Any 3018 */ 3019 VMMR3DECL(VMSTATE) VMR3GetStateU(PUVM pUVM) 3020 { 3021 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VMSTATE_TERMINATED); 3022 if (RT_UNLIKELY(!pUVM->pVM)) 3023 return VMSTATE_TERMINATED; 3024 return pUVM->pVM->enmVMState; 2863 3025 } 2864 3026 … … 3459 3621 VMMR3DECL(int) VMR3AtErrorRegister(PVM pVM, PFNVMATERROR pfnAtError, void *pvUser) 3460 3622 { 3623 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 3461 3624 return VMR3AtErrorRegisterU(pVM->pUVM, pfnAtError, pvUser); 3462 3625 } … … 4169 4332 VMMR3DECL(int) VMR3GetCpuCoreAndPackageIdFromCpuId(PVM pVM, VMCPUID idCpu, uint32_t *pidCpuCore, uint32_t *pidCpuPackage) 4170 4333 { 4334 /* 4335 * Validate input. 4336 */ 4337 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 4338 AssertPtrReturn(pidCpuCore, VERR_INVALID_POINTER); 4339 AssertPtrReturn(pidCpuPackage, VERR_INVALID_POINTER); 4171 4340 if (idCpu >= pVM->cCpus) 4172 4341 return VERR_INVALID_CPU_ID; 4173 4342 4343 /* 4344 * Set return values. 4345 */ 4174 4346 #ifdef VBOX_WITH_MULTI_CORE 4175 4347 *pidCpuCore = idCpu; … … 4223 4395 VMMR3DECL(int) VMR3HotUnplugCpu(PVM pVM, VMCPUID idCpu) 4224 4396 { 4397 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 4225 4398 AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID); 4226 4399 … … 4242 4415 VMMR3DECL(int) VMR3HotPlugCpu(PVM pVM, VMCPUID idCpu) 4243 4416 { 4417 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 4244 4418 AssertReturn(idCpu < pVM->cCpus, VERR_INVALID_CPU_ID); 4245 4419 … … 4254 4428 * @returns VBox status code. 4255 4429 * @param pVM The VM to operate on. 4256 * @param ulCpuExecutionCap New CPU execution cap 4257 */ 4258 VMMR3DECL(int) VMR3SetCpuExecutionCap(PVM pVM, unsigned ulCpuExecutionCap) 4259 { 4260 AssertReturn(ulCpuExecutionCap > 0 && ulCpuExecutionCap <= 100, VERR_INVALID_PARAMETER); 4261 4262 Log(("VMR3SetCpuExecutionCap: new priority = %d\n", ulCpuExecutionCap)); 4430 * @param uCpuExecutionCap New CPU execution cap in precent, 1-100. Where 4431 * 100 is max performance (default). 4432 */ 4433 VMMR3DECL(int) VMR3SetCpuExecutionCap(PVM pVM, uint32_t uCpuExecutionCap) 4434 { 4435 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 4436 AssertReturn(uCpuExecutionCap > 0 && uCpuExecutionCap <= 100, VERR_INVALID_PARAMETER); 4437 4438 Log(("VMR3SetCpuExecutionCap: new priority = %d\n", uCpuExecutionCap)); 4263 4439 /* Note: not called from EMT. */ 4264 pVM->uCpuExecutionCap = u lCpuExecutionCap;4440 pVM->uCpuExecutionCap = uCpuExecutionCap; 4265 4441 return VINF_SUCCESS; 4266 4442 } -
trunk/src/VBox/VMM/include/VMInternal.h
r35346 r36041 181 181 volatile uint32_t cReqFree; 182 182 /** Array of pointers to lists of free request packets. Atomic. */ 183 volatile PVMREQ apReqFree[9]; 183 volatile PVMREQ apReqFree[16-4]; 184 185 /** The reference count of the UVM handle. */ 186 volatile uint32_t cUvmRefs; 184 187 185 188 #ifdef VBOX_WITH_STATISTICS … … 294 297 /** TLS index for the VMINTUSERPERVMCPU pointer. */ 295 298 RTTLS idxTLS; 299 300 /** The VM name. (Set after the config constructure has been called.) */ 301 char *pszName; 302 /** The VM UUID. (Set after the config constructure has been called.) */ 303 RTUUID Uuid; 296 304 } VMINTUSERPERVM; 297 305
Note:
See TracChangeset
for help on using the changeset viewer.