VirtualBox

Changeset 36437 in vbox for trunk


Ignore:
Timestamp:
Mar 25, 2011 3:36:59 PM (14 years ago)
Author:
vboxsync
Message:

VMM,Main: Added VMM thread init and term notifications so that Main can make sure COM is uninitialized. (Maybe we should just say IPRT cleans up COM?)

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/vmm.h

    r35855 r36437  
    153153     * @returns VBox status code.
    154154     * @param   pThis       Pointer to the callback method table.
    155      * @param   pVM         The VM handle.
     155     * @param   pUVM        The user mode VM handle.
    156156     *
    157157     * @remarks This member shall be set to NULL if the operation is not
    158158     *          supported.
    159159     */
    160     DECLR3CALLBACKMEMBER(int, pfnSaveState,(PCVMM2USERMETHODS pThis, PVM pVM));
     160    DECLR3CALLBACKMEMBER(int, pfnSaveState,(PCVMM2USERMETHODS pThis, PUVM pUVM));
    161161    /** @todo Move pfnVMAtError and pfnCFGMConstructor here? */
     162
     163    /**
     164     * EMT initialization notification callback.
     165     *
     166     * This is intended for doing per-thread initialization for EMTs (like COM
     167     * init).
     168     *
     169     * @param   pThis       Pointer to the callback method table.
     170     * @param   pUVM        The user mode VM handle.
     171     * @param   pUVCpu      The user mode virtual CPU handle.
     172     *
     173     * @remarks This is optional and shall be set to NULL if not wanted.
     174     */
     175    DECLR3CALLBACKMEMBER(void, pfnNotifyEmtInit,(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu));
     176
     177    /**
     178     * EMT termination notification callback.
     179     *
     180     * This is intended for doing per-thread cleanups for EMTs (like COM).
     181     *
     182     * @param   pThis       Pointer to the callback method table.
     183     * @param   pUVM        The user mode VM handle.
     184     * @param   pUVCpu      The user mode virtual CPU handle.
     185     *
     186     * @remarks This is optional and shall be set to NULL if not wanted.
     187     */
     188    DECLR3CALLBACKMEMBER(void, pfnNotifyEmtTerm,(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu));
     189
     190    /**
     191     * PDM thread initialization notification callback.
     192     *
     193     * This is intended for doing per-thread initialization (like COM init).
     194     *
     195     * @param   pThis       Pointer to the callback method table.
     196     * @param   pUVM        The user mode VM handle.
     197     *
     198     * @remarks This is optional and shall be set to NULL if not wanted.
     199     */
     200    DECLR3CALLBACKMEMBER(void, pfnNotifyPdmtInit,(PCVMM2USERMETHODS pThis, PUVM pUVM));
     201
     202    /**
     203     * EMT termination notification callback.
     204     *
     205     * This is intended for doing per-thread cleanups for EMTs (like COM).
     206     *
     207     * @param   pThis       Pointer to the callback method table.
     208     * @param   pUVM        The user mode VM handle.
     209     *
     210     * @remarks This is optional and shall be set to NULL if not wanted.
     211     */
     212    DECLR3CALLBACKMEMBER(void, pfnNotifyPdmtTerm,(PCVMM2USERMETHODS pThis, PUVM pUVM));
    162213
    163214    /** Magic value (VMM2USERMETHODS_MAGIC) marking the end of the structure. */
     
    168219#define VMM2USERMETHODS_MAGIC         UINT32_C(0x18830703)
    169220/** The VMM2USERMETHODS structure version. */
    170 #define VMM2USERMETHODS_VERSION       UINT32_C(0x00010000)
     221#define VMM2USERMETHODS_VERSION       UINT32_C(0x00020000)
    171222
    172223
  • trunk/src/VBox/Main/include/ConsoleImpl.h

    r36178 r36437  
    590590    static DECLCALLBACK(int)   powerDownThread(RTTHREAD Thread, void *pvUser);
    591591
    592     static DECLCALLBACK(int)    vmm2User_SaveState(PCVMM2USERMETHODS pThis, PVM pVM);
     592    static DECLCALLBACK(int)    vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
     593    static DECLCALLBACK(void)   vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
     594    static DECLCALLBACK(void)   vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
    593595
    594596    static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
     
    682684    bool mfSnapshotFolderDiskTypeShown : 1;
    683685
    684     /** Pointer to the VMM -> User (that's us) callbacks.
    685      * This structure is followed by a pointer to the Console object. */
    686     PCVMM2USERMETHODS mpVmm2UserMethods;
     686    /** Pointer to the VMM -> User (that's us) callbacks. */
     687    struct MYVMM2USERMETHODS : public VMM2USERMETHODS
     688    {
     689        Console *pConsole;
     690    } *mpVmm2UserMethods;
    687691
    688692    /** The current network attachment type in the VM.
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r36381 r36437  
    346346typedef ListenerImpl<VmEventListener, Console*> VmEventListenerImpl;
    347347
     348
    348349VBOX_LISTENER_DECLARE(VmEventListenerImpl)
    349350
     
    390391        maStorageDevType[i] = DeviceType_Null;
    391392
    392     VMM2USERMETHODS *pVmm2UserMethods = (VMM2USERMETHODS *)RTMemAlloc(sizeof(*mpVmm2UserMethods) + sizeof(Console *));
     393    MYVMM2USERMETHODS *pVmm2UserMethods = (MYVMM2USERMETHODS *)RTMemAllocZ(sizeof(*mpVmm2UserMethods) + sizeof(Console *));
    393394    if (!pVmm2UserMethods)
    394395        return E_OUTOFMEMORY;
    395     pVmm2UserMethods->u32Magic      = VMM2USERMETHODS_MAGIC;
    396     pVmm2UserMethods->u32Version    = VMM2USERMETHODS_VERSION;
    397     pVmm2UserMethods->pfnSaveState  = Console::vmm2User_SaveState;
    398     pVmm2UserMethods->u32EndMagic   = VMM2USERMETHODS_MAGIC;
    399     *(Console **)(pVmm2UserMethods + 1) = this; /* lazy bird. */
     396    pVmm2UserMethods->u32Magic          = VMM2USERMETHODS_MAGIC;
     397    pVmm2UserMethods->u32Version        = VMM2USERMETHODS_VERSION;
     398    pVmm2UserMethods->pfnSaveState      = Console::vmm2User_SaveState;
     399    pVmm2UserMethods->pfnNotifyEmtInit  = NULL;
     400    pVmm2UserMethods->pfnNotifyEmtTerm  = Console::vmm2User_NotifyEmtTerm;
     401    pVmm2UserMethods->pfnNotifyPdmtInit = NULL;
     402    pVmm2UserMethods->pfnNotifyPdmtTerm = Console::vmm2User_NotifyPdmtTerm;
     403    pVmm2UserMethods->u32EndMagic       = VMM2USERMETHODS_MAGIC;
     404    pVmm2UserMethods->pConsole          = this;
    400405    mpVmm2UserMethods = pVmm2UserMethods;
    401406
     
    87908795 * @interface_method_impl{VMM2USERMETHODS,pfnSaveState}
    87918796 */
    8792 /*static*/
    8793 DECLCALLBACK(int) Console::vmm2User_SaveState(PCVMM2USERMETHODS pThis, PVM pVM)
    8794 {
    8795     Console *pConsole = *(Console **)(pThis + 1); /* lazy bird */
     8797/*static*/ DECLCALLBACK(int)
     8798Console::vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM)
     8799{
     8800    Console *pConsole = ((MYVMM2USERMETHODS *)pThis)->pConsole;
     8801    NOREF(pUVM);
    87968802
    87978803    /*
     
    88028808    return SUCCEEDED(hrc) ? VINF_SUCCESS : Global::vboxStatusCodeFromCOM(hrc);
    88038809}
     8810
     8811/**
     8812 * @interface_method_impl{VMM2USERMETHODS,pfnNotifyEmtTerm}
     8813 */
     8814/*static*/ DECLCALLBACK(void)
     8815Console::vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu)
     8816{
     8817    NOREF(pThis); NOREF(pUVM); NOREF(pUVCpu);
     8818#ifdef RT_OS_WINDOWS
     8819    CoUninitialize();
     8820#endif
     8821}
     8822
     8823/**
     8824 * @interface_method_impl{VMM2USERMETHODS,pfnNotifyPdmtTerm}
     8825 */
     8826/*static*/ DECLCALLBACK(void)
     8827Console::vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM)
     8828{
     8829    NOREF(pThis); NOREF(pUVM);
     8830#ifdef RT_OS_WINDOWS
     8831    CoUninitialize();
     8832#endif
     8833}
     8834
    88048835
    88058836
  • trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp

    r36157 r36437  
    30293029    if (RT_SUCCESS(rc))
    30303030    {
    3031         rc = pVM->pUVM->pVmm2UserMethods->pfnSaveState(pVM->pUVM->pVmm2UserMethods, pVM);
     3031        PUVM pUVM = pVM->pUVM;
     3032        rc = pUVM->pVmm2UserMethods->pfnSaveState(pVM->pUVM->pVmm2UserMethods, pUVM);
    30323033
    30333034        /*
  • trunk/src/VBox/VMM/VMMR3/PDMThread.cpp

    r35346 r36437  
    759759    pThread->Thread = Thread;
    760760
     761    PUVM pUVM = pThread->Internal.s.pVM->pUVM;
     762    if (   pUVM->pVmm2UserMethods
     763        && pUVM->pVmm2UserMethods->pfnNotifyPdmtInit)
     764        pUVM->pVmm2UserMethods->pfnNotifyPdmtInit(pUVM->pVmm2UserMethods, pUVM);
     765
    761766    /*
    762767     * The run loop.
     
    840845    int rc2 = RTThreadUserSignal(Thread); AssertRC(rc2);
    841846
     847    if (   pUVM->pVmm2UserMethods
     848        && pUVM->pVmm2UserMethods->pfnNotifyPdmtTerm)
     849        pUVM->pVmm2UserMethods->pfnNotifyPdmtTerm(pUVM->pVmm2UserMethods, pUVM);
    842850    Log(("PDMThread: Terminating thread %RTthrd / %p / '%s': %Rrc\n", Thread, pThread, RTThreadGetName(Thread), rc));
    843851    return rc;
  • trunk/src/VBox/VMM/VMMR3/VM.cpp

    r36041 r36437  
    169169 * @returns VBox error code on failure.
    170170 * @param   cCpus               Number of virtual CPUs for the new VM.
    171  * @param   pVmm2UserMethods    An optional method table that the VMM can use to
    172  *                              make the user perform various action, like for
    173  *                              instance state saving.
     171 * @param   pVmm2UserMethods    An optional method table that the VMM can use
     172 *                              to make the user perform various action, like
     173 *                              for instance state saving.
    174174 * @param   pfnVMAtError        Pointer to callback function for setting VM
    175  *                              errors. This was added as an implicit call to
     175 *                              errors.  This was added as an implicit call to
    176176 *                              VMR3AtErrorRegister() since there is no way the
    177177 *                              caller can get to the VM handle early enough to
     
    197197        AssertReturn(pVmm2UserMethods->u32Magic    == VMM2USERMETHODS_MAGIC,   VERR_INVALID_PARAMETER);
    198198        AssertReturn(pVmm2UserMethods->u32Version  == VMM2USERMETHODS_VERSION, VERR_INVALID_PARAMETER);
    199         AssertPtrReturn(pVmm2UserMethods->pfnSaveState, VERR_INVALID_POINTER);
     199        AssertPtrNullReturn(pVmm2UserMethods->pfnSaveState, VERR_INVALID_POINTER);
     200        AssertPtrNullReturn(pVmm2UserMethods->pfnNotifyEmtInit, VERR_INVALID_POINTER);
     201        AssertPtrNullReturn(pVmm2UserMethods->pfnNotifyEmtTerm, VERR_INVALID_POINTER);
     202        AssertPtrNullReturn(pVmm2UserMethods->pfnNotifyPdmtInit, VERR_INVALID_POINTER);
     203        AssertPtrNullReturn(pVmm2UserMethods->pfnNotifyPdmtTerm, VERR_INVALID_POINTER);
    200204        AssertReturn(pVmm2UserMethods->u32EndMagic == VMM2USERMETHODS_MAGIC,   VERR_INVALID_PARAMETER);
    201205    }
  • trunk/src/VBox/VMM/VMMR3/VMEmt.cpp

    r36255 r36437  
    8181    AssertReleaseMsgRCReturn(rc, ("RTTlsSet %x failed with %Rrc\n", pUVM->vm.s.idxTLS, rc), rc);
    8282
     83    if (   pUVM->pVmm2UserMethods
     84        && pUVM->pVmm2UserMethods->pfnNotifyEmtInit)
     85        pUVM->pVmm2UserMethods->pfnNotifyEmtInit(pUVM->pVmm2UserMethods, pUVM, pUVCpu);
     86
    8387    /*
    8488     * The request loop.
     
    254258        AssertLogRelRC(rc2);
    255259    }
     260
     261    if (   pUVM->pVmm2UserMethods
     262        && pUVM->pVmm2UserMethods->pfnNotifyEmtTerm)
     263        pUVM->pVmm2UserMethods->pfnNotifyEmtTerm(pUVM->pVmm2UserMethods, pUVM, pUVCpu);
    256264
    257265    pUVCpu->vm.s.NativeThreadEMT = NIL_RTNATIVETHREAD;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette