VirtualBox

Changeset 10305 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jul 7, 2008 10:33:33 AM (16 years ago)
Author:
vboxsync
Message:

Main: Lock the object before switching on non-const data members.

Location:
trunk/src/VBox/Main
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r10247 r10305  
    35333533}
    35343534
     3535/**
     3536 * @note Temporarily locks this object for writing.
     3537 */
    35353538HRESULT Console::getGuestProperty (INPTR BSTR aKey, BSTR *aValue)
    35363539{
    3537 #ifndef VBOX_WITH_INFO_SVC
    3538     HRESULT hrc = E_NOTIMPL;
     3540#if !defined (VBOX_WITH_INFO_SVC)
     3541    return E_NOTIMPL;
    35393542#else
    3540     if (!VALID_PTR(aKey))
     3543    if (!VALID_PTR (aKey))
     3544        return E_INVALIDARG;
     3545    if (!VALID_PTR (aValue))
    35413546        return E_POINTER;
    3542     if (!VALID_PTR(aValue))
    3543         return E_POINTER;
    35443547
    35453548    AutoCaller autoCaller (this);
    3546     CheckComRCReturnRC (autoCaller.rc());
     3549    AssertComRCReturnRC (autoCaller.rc());
    35473550
    35483551    /* protect mpVM (if not NULL) */
     
    35503553    CheckComRCReturnRC (autoVMCaller.rc());
    35513554
    3552     HRESULT hrc = E_UNEXPECTED;
     3555    /* Note: validity of mVMMDev which is bound to uninit() is guaranteed by
     3556     * autoVMCaller, so there is no need to hold a lock of this */
     3557
     3558    HRESULT rc = E_UNEXPECTED;
    35533559    using namespace svcInfo;
    35543560
    35553561    VBOXHGCMSVCPARM parm[3];
    35563562    Utf8Str Utf8Key = aKey;
    3557     Utf8Str Utf8Value(KEY_MAX_VALUE_LEN);
     3563    Utf8Str Utf8Value (KEY_MAX_VALUE_LEN);
    35583564
    35593565    parm[0].type = VBOX_HGCM_SVC_PARM_PTR;
     
    35653571    parm[1].u.pointer.addr = Utf8Value.mutableRaw();
    35663572    parm[1].u.pointer.size = KEY_MAX_VALUE_LEN;
    3567     int rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", GET_CONFIG_KEY_HOST, 3, &parm[0]);
     3573    int vrc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", GET_CONFIG_KEY_HOST,
     3574                                     3, &parm[0]);
    35683575    /* The returned string should never be able to be greater than our buffer */
    3569     AssertLogRel(rc != VERR_BUFFER_OVERFLOW);
    3570     if (RT_SUCCESS(rc) || (VERR_NOT_FOUND == rc))
    3571     {
    3572         hrc = S_OK;
    3573         if (rc != VERR_NOT_FOUND)
    3574             Utf8Value.cloneTo(aValue);
     3576    AssertLogRel (vrc != VERR_BUFFER_OVERFLOW);
     3577    if (RT_SUCCESS (vrc) || (VERR_NOT_FOUND == vrc))
     3578    {
     3579        rc = S_OK;
     3580        if (vrc != VERR_NOT_FOUND)
     3581            Utf8Value.cloneTo (aValue);
    35753582        else
    35763583            aValue = NULL;
    35773584    }
    35783585    else
    3579         hrc = setError (E_UNEXPECTED, tr ("hgcmHostCall to VBoxSharedInfoSvc failed: %Rrc"), rc);
    3580 #endif
    3581     return hrc;
    3582 }
    3583 
     3586        rc = setError (E_UNEXPECTED,
     3587            tr ("Failed to call the VBoxSharedInfoSvc service (%Rrc)"), vrc);
     3588    return rc;
     3589#endif /* else !defined (VBOX_WITH_INFO_SVC) */
     3590}
     3591
     3592/**
     3593 * @note Temporarily locks this object for writing.
     3594 */
    35843595HRESULT Console::setGuestProperty (INPTR BSTR aKey, INPTR BSTR aValue)
    35853596{
    3586 #ifndef VBOX_WITH_INFO_SVC
    3587     HRESULT hrc = E_NOTIMPL;
     3597#if !defined (VBOX_WITH_INFO_SVC)
     3598    return E_NOTIMPL;
    35883599#else
    3589     if (!VALID_PTR(aKey))
    3590         return E_POINTER;
    3591     if ((aValue != NULL) && !VALID_PTR(aValue))
    3592         return E_POINTER;
     3600    if (!VALID_PTR (aKey))
     3601        return E_INVALIDARG;
     3602    if ((aValue != NULL) && !VALID_PTR (aValue))
     3603        return E_INVALIDARG;
    35933604
    35943605    AutoCaller autoCaller (this);
    3595     CheckComRCReturnRC (autoCaller.rc());
     3606    AssertComRCReturnRC (autoCaller.rc());
    35963607
    35973608    /* protect mpVM (if not NULL) */
     
    35993610    CheckComRCReturnRC (autoVMCaller.rc());
    36003611
    3601     HRESULT hrc = E_UNEXPECTED;
     3612    /* Note: validity of mVMMDev which is bound to uninit() is guaranteed by
     3613     * autoVMCaller, so there is no need to hold a lock of this */
     3614
     3615    HRESULT rc = E_UNEXPECTED;
    36023616    using namespace svcInfo;
    36033617
    36043618    VBOXHGCMSVCPARM parm[2];
    36053619    Utf8Str Utf8Key = aKey;
    3606     int rc = VINF_SUCCESS;
     3620    int vrc = VINF_SUCCESS;
    36073621
    36083622    parm[0].type = VBOX_HGCM_SVC_PARM_PTR;
     
    36193633        /* The + 1 is the null terminator */
    36203634        parm[1].u.pointer.size = Utf8Value.length() + 1;
    3621         rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", SET_CONFIG_KEY_HOST, 2, &parm[0]);
     3635        vrc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", SET_CONFIG_KEY_HOST,
     3636                                     2, &parm[0]);
    36223637    }
    36233638    else
    3624         rc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", DEL_CONFIG_KEY_HOST, 1, &parm[0]);
    3625     if (RT_SUCCESS(rc))
    3626         hrc = S_OK;
     3639        vrc = mVMMDev->hgcmHostCall ("VBoxSharedInfoSvc", DEL_CONFIG_KEY_HOST,
     3640                                     1, &parm[0]);
     3641    if (RT_SUCCESS (vrc))
     3642        rc = S_OK;
    36273643    else
    3628         hrc = setError (E_UNEXPECTED, tr ("hgcmHostCall to VBoxSharedInfoSvc failed: %Rrc"), rc);
    3629 #endif
    3630     return hrc;
     3644        rc = setError (E_UNEXPECTED,
     3645            tr ("Failed to call the VBoxSharedInfoSvc service (%Rrc)"), vrc);
     3646    return rc;
     3647#endif /* else !defined (VBOX_WITH_INFO_SVC) */
    36313648}
    36323649
     
    41814198            pValue = CFGMR3GetNextValue (pValue);
    41824199    }
    4183     /* In a second stage, we remove any extra data keys corresponding to 
     4200    /* In a second stage, we remove any extra data keys corresponding to
    41844201     * properties which aren't in the CFGM node. */
    41854202    Bstr strExtraDataKey;
  • trunk/src/VBox/Main/MachineImpl.cpp

    r10233 r10305  
    26782678}
    26792679
    2680 /**
    2681  * Read a value from the host/guest property store.  If a session is
    2682  * currently open for the guest then query the session object for the value,
    2683  * since the current values of the property store will be held in RAM in the
    2684  * session.  Otherwise read the value from machine extra data, where it is
    2685  * stored between sessions.  Returns E_FAIL if we are currently transitioning
    2686  * between states.
    2687  */
    26882680STDMETHODIMP Machine::GetGuestProperty (INPTR BSTR aKey, BSTR *aValue)
    26892681{
    2690 #ifndef VBOX_WITH_INFO_SVC
    2691     HRESULT hrc = E_NOTIMPL;
     2682#if !defined (VBOX_WITH_INFO_SVC)
     2683    return E_NOTIMPL;
    26922684#else
    2693     if (!VALID_PTR(aKey))
     2685    if (!VALID_PTR (aKey))
     2686        return E_INVALIDARG;
     2687    if (!VALID_PTR (aValue))
    26942688        return E_POINTER;
    2695     if (!VALID_PTR(aValue))
    2696         return E_POINTER;
    26972689
    26982690    AutoCaller autoCaller (this);
    26992691    CheckComRCReturnRC (autoCaller.rc());
    27002692
     2693    AutoReadLock alock (this);
     2694
    27012695    using namespace svcInfo;
    2702     HRESULT hrc = E_FAIL;
     2696    HRESULT rc = E_FAIL;
    27032697
    27042698    switch (mData->mSession.mState)
     
    27062700        case SessionState_Closed:
    27072701        {
    2708             AutoReadLock alock (this);
    2709 
    27102702            /* The "+ 1" in the length is the null terminator. */
    2711             Bstr strKey(Bstr(aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1);
     2703            Bstr strKey (Bstr (aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1);
    27122704            BSTR strKeyRaw = strKey.mutableRaw();
    27132705
     
    27162708            for (unsigned i = 0; i < VBOX_SHARED_INFO_PREFIX_LEN; ++i)
    27172709                /* I take it this is legal, at least g++ accepts it. */
    2718                 strKeyRaw[i] = VBOX_SHARED_INFO_KEY_PREFIX[i];
     2710                strKeyRaw [i] = VBOX_SHARED_INFO_KEY_PREFIX[i];
    27192711            /* The "+ 1" in the length is the null terminator. */
    2720             for (unsigned i = 0, len = Bstr(aKey).length() + 1; i < len; ++i)
    2721                 strKeyRaw[i + VBOX_SHARED_INFO_PREFIX_LEN] = aKey[i];
    2722             hrc = GetExtraData(strKey, aValue);
     2712            for (unsigned i = 0, len = Bstr (aKey).length() + 1; i < len; ++i)
     2713                strKeyRaw [i + VBOX_SHARED_INFO_PREFIX_LEN] = aKey [i];
     2714            rc = GetExtraData (strKey, aValue);
    27232715            break;
    27242716        }
    27252717        case SessionState_Open:
    27262718        {
    2727             ComPtr <IInternalSessionControl> directControl;
     2719            if (mData->mSession.mState != SessionState_Open)
    27282720            {
    2729                 AutoReadLock alock (this);
    2730        
    2731                 if (mData->mSession.mState != SessionState_Open)
    2732                     return setError (E_FAIL,
    2733                         tr ("Machine session is not open (session state: %d) - please retry."),
    2734                         mData->mSession.mState);
    2735        
    2736                 directControl = mData->mSession.mDirectControl;
     2721                rc = setError (E_FAIL,
     2722                    tr ("Session is not open (session state: %d)"),
     2723                    mData->mSession.mState);
     2724                break;
    27372725            }
    27382726
    2739             hrc = directControl->AccessGuestProperty (aKey, NULL,
    2740                                                       false /* isSetter */,
    2741                                                       aValue);
     2727            ComPtr <IInternalSessionControl> directControl =
     2728                mData->mSession.mDirectControl;
     2729
     2730            /* just be on the safe side when calling another process */
     2731            alock.unlock();
     2732
     2733            rc = directControl->AccessGuestProperty (aKey, NULL,
     2734                                                     false /* isSetter */,
     2735                                                     aValue);
    27422736            break;
    27432737        }
    27442738        default:
    2745             hrc = setError (E_FAIL, tr ("Machine session is currently transitioning (session state: %d) - please retry."),
    2746                             mData->mSession.mState);
    2747     }
    2748 #endif  /* VBOX_WITH_INFO_SVC not defined */
    2749     return hrc;
     2739            rc = setError (E_FAIL,
     2740                tr ("Session is currently transitioning (session state: %d)"),
     2741                mData->mSession.mState);
     2742    }
     2743    return rc;
     2744#endif /* else !defined (VBOX_WITH_INFO_SVC) */
    27502745}
    27512746
     
    27602755STDMETHODIMP Machine::SetGuestProperty (INPTR BSTR aKey, INPTR BSTR aValue)
    27612756{
    2762 #ifndef VBOX_WITH_INFO_SVC
    2763     HRESULT hrc = E_NOTIMPL;
     2757#if !defined (VBOX_WITH_INFO_SVC)
     2758    return E_NOTIMPL;
    27642759#else
    2765     if (!VALID_PTR(aKey))
    2766         return E_POINTER;
    2767     if ((aValue != NULL) && !VALID_PTR(aValue))
    2768         return E_POINTER;
     2760    if (!VALID_PTR (aKey))
     2761        return E_INVALIDARG;
     2762    if ((aValue != NULL) && !VALID_PTR (aValue))
     2763        return E_INVALIDARG;
    27692764
    27702765    AutoCaller autoCaller (this);
    27712766    CheckComRCReturnRC (autoCaller.rc());
    27722767
     2768    /* SetExtraData() needs a write lock */
     2769    AutoWriteLock alock (this);
     2770
    27732771    using namespace svcInfo;
    2774     HRESULT hrc = E_FAIL;
     2772    HRESULT rc = E_FAIL;
    27752773
    27762774    switch (mData->mSession.mState)
     
    27782776        case SessionState_Closed:
    27792777        {
    2780             AutoWriteLock alock (this);
    2781 
    27822778            /* The "+ 1" in the length is the null terminator. */
    2783             Bstr strKey(Bstr(aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1);
     2779            Bstr strKey (Bstr (aKey).length() + VBOX_SHARED_INFO_PREFIX_LEN + 1);
    27842780            BSTR strKeyRaw = strKey.mutableRaw();
    27852781
     
    27882784            for (unsigned i = 0; i < VBOX_SHARED_INFO_PREFIX_LEN; ++i)
    27892785                /* I take it this is legal, at least g++ accepts it. */
    2790                 strKeyRaw[i] = VBOX_SHARED_INFO_KEY_PREFIX[i];
     2786                strKeyRaw [i] = VBOX_SHARED_INFO_KEY_PREFIX[i];
    27912787            /* The "+ 1" in the length is the null terminator. */
    2792             for (unsigned i = 0, len = Bstr(aKey).length() + 1; i < len; ++i)
    2793                 strKeyRaw[i + VBOX_SHARED_INFO_PREFIX_LEN] = aKey[i];
    2794             hrc = SetExtraData(strKey, aValue);
     2788            for (unsigned i = 0, len = Bstr (aKey).length() + 1; i < len; ++i)
     2789                strKeyRaw [i + VBOX_SHARED_INFO_PREFIX_LEN] = aKey [i];
     2790            rc = SetExtraData (strKey, aValue);
    27952791            break;
    27962792        }
    27972793        case SessionState_Open:
    27982794        {
    2799             ComPtr <IInternalSessionControl> directControl;
     2795            if (mData->mSession.mState != SessionState_Open)
    28002796            {
    2801                 AutoReadLock alock (this);
    2802        
    2803                 if (mData->mSession.mState != SessionState_Open)
    2804                     return setError (E_FAIL,
    2805                         tr ("Machine session is not open (session state: %d) - please retry."),
    2806                         mData->mSession.mState);
    2807        
    2808                 directControl = mData->mSession.mDirectControl;
     2797                rc = setError (E_FAIL,
     2798                    tr ("Session is not open (session state: %d)"),
     2799                    mData->mSession.mState);
     2800                break;
    28092801            }
    28102802
    2811             BSTR dummy;
    2812             hrc = directControl->AccessGuestProperty (aKey, aValue,
    2813                                                       true /* isSetter */,
    2814                                                       &dummy);
     2803            ComPtr <IInternalSessionControl> directControl =
     2804                mData->mSession.mDirectControl;
     2805
     2806            /* just be on the safe side when calling another process */
     2807            alock.leave();
     2808
     2809            BSTR dummy = NULL;
     2810            rc = directControl->AccessGuestProperty (aKey, aValue,
     2811                                                     true /* isSetter */,
     2812                                                     &dummy);
    28152813            break;
    28162814        }
    28172815        default:
    2818             hrc = setError (E_FAIL, tr ("Machine session is currently transitioning (session state: %d) - please retry."),
    2819                             mData->mSession.mState);
    2820     }
    2821 #endif  /* VBOX_WITH_INFO_SVC not defined */
    2822     return hrc;
     2816            rc = setError (E_FAIL,
     2817                tr ("Session is currently transitioning (session state: %d)"),
     2818                mData->mSession.mState);
     2819    }
     2820    return rc;
     2821#endif /* else !defined (VBOX_WITH_INFO_SVC) */
    28232822}
    28242823
  • trunk/src/VBox/Main/SessionImpl.cpp

    r10233 r10305  
    655655
    656656STDMETHODIMP Session::AccessGuestProperty (INPTR BSTR aKey, INPTR BSTR aValue,
    657                                            BOOL isSetter, BSTR *retValue)
     657                                           BOOL aIsSetter, BSTR *aRetValue)
    658658{
    659659#ifdef VBOX_WITH_INFO_SVC
     
    663663    if (mState != SessionState_Open)
    664664        return setError (E_FAIL,
    665                          tr ("Machine session is not open (session state: %d) - please retry."),
    666                          mState);
     665            tr ("Machine session is not open (session state: %d)."),
     666            mState);
    667667    AssertReturn (mType == SessionType_Direct, E_UNEXPECTED);
    668     if (!VALID_PTR(aKey))
     668    if (!VALID_PTR (aKey))
    669669        return E_POINTER;
    670     if (!isSetter && !VALID_PTR(retValue))
     670    if (!aIsSetter && !VALID_PTR (aRetValue))
    671671        return E_POINTER;
    672672    /* aValue can be NULL for a setter call if the property is to be deleted. */
    673     if (isSetter && (aValue != NULL) && !VALID_PTR(aValue))
    674         return E_POINTER;
    675     if (!isSetter)
    676         return mConsole->getGuestProperty(aKey, retValue);
     673    if (aIsSetter && (aValue != NULL) && !VALID_PTR (aValue))
     674        return E_INVALIDARG;
     675    if (!aIsSetter)
     676        return mConsole->getGuestProperty (aKey, aRetValue);
    677677    else
    678         return mConsole->setGuestProperty(aKey, aValue);
     678        return mConsole->setGuestProperty (aKey, aValue);
    679679#else
    680680    return E_NOTIMPL;
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r10233 r10305  
    34713471      <desc>
    34723472        Reads a value from the machine's host/guest property store.
     3473
     3474        Reads a value from the machine's host/guest property store.
     3475
     3476        If a session for this virtual machine is currently open then queries the
     3477        session object for the value, since the current values of the property
     3478        store will be held in RAM in the session. Otherwise reads the value from
     3479        machine extra data, where it is stored between sessions.
     3480
     3481        This method will fail if we are currently transitioning between session
     3482        states.
    34733483      </desc>
    34743484      <param name="key" type="wstring" dir="in">
     
    34893499        Sets, changes or deletes a value in the machine's host/guest
    34903500        property store.
     3501
     3502        If a session for this virtual machine is currently open then changes the
     3503        value on the session object, since the current values of the property
     3504        store will be held in RAM in the session. Otherwise changes the value
     3505        in machine extra data, where it is stored between sessions.
     3506
     3507        This method will fail if we are currently transitioning between session
     3508        states.
    34913509      </desc>
    34923510      <param name="key" type="wstring" dir="in">
  • trunk/src/VBox/Main/include/SessionImpl.h

    r10233 r10305  
    106106    STDMETHOD(OnUSBDeviceDetach) (INPTR GUIDPARAM aId, IVirtualBoxErrorInfo *aError);
    107107    STDMETHOD(OnShowWindow) (BOOL aCheck, BOOL *aCanShow, ULONG64 *aWinId);
    108     STDMETHOD(AccessGuestProperty) (INPTR BSTR aKey, INPTR BSTR aValue, BOOL isSetter, BSTR *retValue);
     108    STDMETHOD(AccessGuestProperty) (INPTR BSTR aKey, INPTR BSTR aValue,
     109                                    BOOL aIsSetter, BSTR *aRetValue);
    109110
    110111    // for VirtualBoxSupportErrorInfoImpl
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