Index: /trunk/src/VBox/Main/src-client/GuestCtrlImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/GuestCtrlImpl.cpp	(revision 71559)
+++ /trunk/src/VBox/Main/src-client/GuestCtrlImpl.cpp	(revision 71560)
@@ -372,9 +372,12 @@
 #else /* VBOX_WITH_GUEST_CONTROL */
 
-    LogFlowFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     /* Do not allow anonymous sessions (with system rights) with public API. */
     if (RT_UNLIKELY(!aUser.length()))
         return setError(E_INVALIDARG, tr("No user name specified"));
+
+    LogFlowFuncEnter();
 
     GuestSessionStartupInfo startupInfo;
Index: /trunk/src/VBox/Main/src-client/GuestDirectoryImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/GuestDirectoryImpl.cpp	(revision 71559)
+++ /trunk/src/VBox/Main/src-client/GuestDirectoryImpl.cpp	(revision 71560)
@@ -334,8 +334,8 @@
 HRESULT GuestDirectory::close()
 {
-    LogFlowThisFuncEnter();
-
     AutoCaller autoCaller(this);
     if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    LogFlowThisFuncEnter();
 
     HRESULT hr = S_OK;
@@ -369,8 +369,8 @@
 HRESULT GuestDirectory::read(ComPtr<IFsObjInfo> &aObjInfo)
 {
-    LogFlowThisFuncEnter();
-
     AutoCaller autoCaller(this);
     if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    LogFlowThisFuncEnter();
 
     HRESULT hr = S_OK;
Index: /trunk/src/VBox/Main/src-client/GuestFileImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/GuestFileImpl.cpp	(revision 71559)
+++ /trunk/src/VBox/Main/src-client/GuestFileImpl.cpp	(revision 71560)
@@ -1177,4 +1177,7 @@
 HRESULT GuestFile::close()
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     LogFlowThisFuncEnter();
 
@@ -1217,6 +1220,11 @@
 HRESULT GuestFile::read(ULONG aToRead, ULONG aTimeoutMS, std::vector<BYTE> &aData)
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     if (aToRead == 0)
         return setError(E_INVALIDARG, tr("The size to read is zero"));
+
+    LogFlowThisFuncEnter();
 
     aData.resize(aToRead);
@@ -1253,6 +1261,11 @@
 
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     if (aToRead == 0)
         return setError(E_INVALIDARG, tr("The size to read is zero"));
+
+    LogFlowThisFuncEnter();
 
     aData.resize(aToRead);
@@ -1288,5 +1301,6 @@
 HRESULT GuestFile::seek(LONG64 aOffset, FileSeekOrigin_T aWhence, LONG64 *aNewOffset)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     HRESULT hr = S_OK;
@@ -1311,4 +1325,6 @@
             break; /* Never reached. */
     }
+
+    LogFlowThisFuncEnter();
 
     uint64_t uNewOffset;
@@ -1347,4 +1363,7 @@
 HRESULT GuestFile::write(const std::vector<BYTE> &aData, ULONG aTimeoutMS, ULONG *aWritten)
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     LogFlowThisFuncEnter();
 
@@ -1353,6 +1372,5 @@
     uint32_t cbData = (uint32_t)aData.size();
     void *pvData = cbData > 0? (void *)&aData.front(): NULL;
-    int vrc = i_writeData(aTimeoutMS, pvData, cbData,
-                          (uint32_t*)aWritten);
+    int vrc = i_writeData(aTimeoutMS, pvData, cbData, (uint32_t*)aWritten);
     if (RT_FAILURE(vrc))
     {
@@ -1374,4 +1392,7 @@
 
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     LogFlowThisFuncEnter();
 
@@ -1380,6 +1401,5 @@
     uint32_t cbData = (uint32_t)aData.size();
     void *pvData = cbData > 0? (void *)&aData.front(): NULL;
-    int vrc = i_writeData(aTimeoutMS, pvData, cbData,
-                          (uint32_t*)aWritten);
+    int vrc = i_writeData(aTimeoutMS, pvData, cbData, (uint32_t*)aWritten);
     if (RT_FAILURE(vrc))
     {
Index: /trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp	(revision 71559)
+++ /trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp	(revision 71560)
@@ -1758,8 +1758,11 @@
 HRESULT GuestProcess::read(ULONG aHandle, ULONG aToRead, ULONG aTimeoutMS, std::vector<BYTE> &aData)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (aToRead == 0)
         return setError(E_INVALIDARG, tr("The size to read is zero"));
+
+    LogFlowThisFuncEnter();
 
     aData.resize(aToRead);
@@ -1800,4 +1803,9 @@
 HRESULT GuestProcess::terminate()
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    LogFlowThisFuncEnter();
+
     HRESULT hr = S_OK;
 
@@ -1837,8 +1845,11 @@
 }
 
-HRESULT GuestProcess::waitFor(ULONG aWaitFor,
-                              ULONG aTimeoutMS,
-                              ProcessWaitResult_T *aReason)
-{
+HRESULT GuestProcess::waitFor(ULONG aWaitFor, ULONG aTimeoutMS, ProcessWaitResult_T *aReason)
+{
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    LogFlowThisFuncEnter();
+
     /*
      * Note: Do not hold any locks here while waiting!
@@ -1880,7 +1891,4 @@
                                    ULONG aTimeoutMS, ProcessWaitResult_T *aReason)
 {
-    /*
-     * Note: Do not hold any locks here while waiting!
-     */
     uint32_t fWaitFor = ProcessWaitForFlag_None;
     for (size_t i = 0; i < aWaitFor.size(); i++)
@@ -1893,4 +1901,7 @@
                             ULONG aTimeoutMS, ULONG *aWritten)
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     LogFlowThisFuncEnter();
 
@@ -1930,7 +1941,4 @@
     LogFlowThisFuncEnter();
 
-    /*
-     * Note: Do not hold any locks here while writing!
-     */
     ULONG fWrite = ProcessInputFlag_None;
     for (size_t i = 0; i < aFlags.size(); i++)
Index: /trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
===================================================================
--- /trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp	(revision 71559)
+++ /trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp	(revision 71560)
@@ -2518,8 +2518,8 @@
 HRESULT GuestSession::close()
 {
-    LogFlowThisFuncEnter();
-
     AutoCaller autoCaller(this);
     if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    LogFlowThisFuncEnter();
 
     HRESULT hr = i_isReadyExternal();
@@ -2566,5 +2566,6 @@
                                         ComPtr<IProgress> &aProgress)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aSource.c_str()) == NULL || *(aSource.c_str()) == '\0'))
@@ -2587,4 +2588,6 @@
         return hrc;
 
+    LogFlowThisFuncEnter();
+
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
 
@@ -2643,5 +2646,6 @@
                                       const std::vector<FileCopyFlag_T> &aFlags, ComPtr<IProgress> &aProgress)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aSource.c_str()) == NULL || *(aSource.c_str()) == '\0'))
@@ -2664,4 +2668,6 @@
         return hrc;
 
+    LogFlowThisFuncEnter();
+
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
 
@@ -2725,5 +2731,6 @@
                                              const std::vector<DirectoryCopyFlag_T> &aFlags, ComPtr<IProgress> &aProgress)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aSource.c_str()) == NULL || *(aSource.c_str()) == '\0'))
@@ -2749,4 +2756,6 @@
     if (FAILED(hrc))
         return hrc;
+
+    LogFlowThisFuncEnter();
 
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
@@ -2806,5 +2815,6 @@
                                            const std::vector<DirectoryCopyFlag_T> &aFlags, ComPtr<IProgress> &aProgress)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aSource.c_str()) == NULL || *(aSource.c_str()) == '\0'))
@@ -2833,4 +2843,6 @@
     if (FAILED(hrc))
         return hrc;
+
+    LogFlowThisFuncEnter();
 
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
@@ -2890,5 +2902,6 @@
                                       const std::vector<DirectoryCreateFlag_T> &aFlags)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
@@ -2909,4 +2922,6 @@
     if (FAILED(hrc))
         return hrc;
+
+    LogFlowThisFuncEnter();
 
     ComObjPtr <GuestDirectory> pDirectory; int rcGuest;
@@ -2945,5 +2960,7 @@
 {
     RT_NOREF(aMode, aSecure);
-    LogFlowThisFuncEnter();
+
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aTemplateName.c_str()) == NULL || *(aTemplateName.c_str()) == '\0'))
@@ -2956,4 +2973,6 @@
         return hrc;
 
+    LogFlowThisFuncEnter();
+
     int rcGuest;
     int rc = i_fsCreateTemp(aTemplateName, aPath, true /* Directory */, aDirectory, &rcGuest);
@@ -2978,5 +2997,6 @@
 HRESULT GuestSession::directoryExists(const com::Utf8Str &aPath, BOOL aFollowSymlinks, BOOL *aExists)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
@@ -2986,4 +3006,6 @@
     if (FAILED(hrc))
         return hrc;
+
+    LogFlowThisFuncEnter();
 
     GuestFsObjData objData; int rcGuest;
@@ -3023,5 +3045,6 @@
                                     const std::vector<DirectoryOpenFlag_T> &aFlags, ComPtr<IGuestDirectory> &aDirectory)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
@@ -3044,4 +3067,6 @@
         return hrc;
 
+    LogFlowThisFuncEnter();
+
     GuestDirectoryOpenInfo openInfo;
     openInfo.mPath = aPath;
@@ -3081,5 +3106,6 @@
 HRESULT GuestSession::directoryRemove(const com::Utf8Str &aPath)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
@@ -3089,4 +3115,6 @@
     if (FAILED(hrc))
         return hrc;
+
+    LogFlowThisFuncEnter();
 
     /* No flags; only remove the directory when empty. */
@@ -3122,5 +3150,7 @@
 {
     RT_NOREF(aFlags);
-    LogFlowThisFuncEnter();
+
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
@@ -3133,4 +3163,6 @@
     if (FAILED(hrc))
         return hrc;
+
+    LogFlowThisFuncEnter();
 
     ComObjPtr<Progress> pProgress;
@@ -3185,5 +3217,6 @@
 HRESULT GuestSession::environmentScheduleSet(const com::Utf8Str &aName, const com::Utf8Str &aValue)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     HRESULT hrc;
@@ -3192,4 +3225,6 @@
         if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL))
         {
+            LogFlowThisFuncEnter();
+
             AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
             int vrc = mData.mEnvironmentChanges.setVariable(aName, aValue);
@@ -3211,5 +3246,7 @@
 HRESULT GuestSession::environmentScheduleUnset(const com::Utf8Str &aName)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     HRESULT hrc;
     if (RT_LIKELY(aName.isNotEmpty()))
@@ -3217,4 +3254,6 @@
         if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL))
         {
+            LogFlowThisFuncEnter();
+
             AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
             int vrc = mData.mEnvironmentChanges.unsetVariable(aName);
@@ -3236,5 +3275,7 @@
 HRESULT GuestSession::environmentGetBaseVariable(const com::Utf8Str &aName, com::Utf8Str &aValue)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     HRESULT hrc;
     if (RT_LIKELY(aName.isNotEmpty()))
@@ -3242,4 +3283,6 @@
         if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL))
         {
+            LogFlowThisFuncEnter();
+
             AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
             if (mData.mpBaseEnvironment)
@@ -3268,6 +3311,9 @@
 HRESULT GuestSession::environmentDoesBaseVariableExist(const com::Utf8Str &aName, BOOL *aExists)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     *aExists = FALSE;
+
     HRESULT hrc;
     if (RT_LIKELY(aName.isNotEmpty()))
@@ -3275,4 +3321,6 @@
         if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL))
         {
+            LogFlowThisFuncEnter();
+
             AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
             if (mData.mpBaseEnvironment)
@@ -3305,5 +3353,6 @@
 HRESULT GuestSession::fileExists(const com::Utf8Str &aPath, BOOL aFollowSymlinks, BOOL *aExists)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
@@ -3316,4 +3365,6 @@
     if (FAILED(hrc))
         return hrc;
+
+    LogFlowThisFuncEnter();
 
     GuestFsObjData objData; int rcGuest;
@@ -3350,4 +3401,5 @@
 {
     LogFlowThisFuncEnter();
+
     const std::vector<FileOpenExFlag_T> EmptyFlags;
     return fileOpenEx(aPath, aAccessMode, aOpenAction, FileSharingMode_All, aCreationMode, EmptyFlags, aFile);
@@ -3358,5 +3410,6 @@
                                  const std::vector<FileOpenExFlag_T> &aFlags, ComPtr<IGuestFile> &aFile)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
@@ -3366,4 +3419,6 @@
     if (FAILED(hrc))
         return hrc;
+
+    LogFlowThisFuncEnter();
 
     GuestFileOpenInfo openInfo;
@@ -3458,4 +3513,7 @@
 HRESULT GuestSession::fileQuerySize(const com::Utf8Str &aPath, BOOL aFollowSymlinks, LONG64 *aSize)
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     if (aPath.isEmpty())
         return setError(E_INVALIDARG, tr("No path specified"));
@@ -3486,4 +3544,7 @@
 HRESULT GuestSession::fsObjExists(const com::Utf8Str &aPath, BOOL aFollowSymlinks, BOOL *aExists)
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     if (aPath.isEmpty())
         return setError(E_INVALIDARG, tr("No path specified"));
@@ -3527,4 +3588,7 @@
 HRESULT GuestSession::fsObjQueryInfo(const com::Utf8Str &aPath, BOOL aFollowSymlinks, ComPtr<IGuestFsObjInfo> &aInfo)
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     if (aPath.isEmpty())
         return setError(E_INVALIDARG, tr("No path specified"));
@@ -3566,4 +3630,7 @@
 HRESULT GuestSession::fsObjRemove(const com::Utf8Str &aPath)
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     if (RT_UNLIKELY(aPath.isEmpty()))
         return setError(E_INVALIDARG, tr("No path specified"));
@@ -3594,4 +3661,7 @@
                                   const std::vector<FsObjRenameFlag_T> &aFlags)
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
     if (RT_UNLIKELY(aSource.isEmpty()))
         return setError(E_INVALIDARG, tr("No source path specified"));
@@ -3599,6 +3669,4 @@
     if (RT_UNLIKELY(aDestination.isEmpty()))
         return setError(E_INVALIDARG, tr("No destination path specified"));
-
-    LogFlowThisFunc(("aSource=%s, aDestination=%s\n", aSource.c_str(), aDestination.c_str()));
 
     HRESULT hrc = i_isReadyExternal();
@@ -3612,4 +3680,6 @@
     if (fApiFlags & ~((uint32_t)FsObjRenameFlag_NoReplace | (uint32_t)FsObjRenameFlag_Replace))
         return setError(E_INVALIDARG, tr("Unknown rename flag: %#x"), fApiFlags);
+
+    LogFlowThisFunc(("aSource=%s, aDestination=%s\n", aSource.c_str(), aDestination.c_str()));
 
     AssertCompile(FsObjRenameFlag_NoReplace == 0);
@@ -3670,5 +3740,4 @@
 
     std::vector<LONG> affinityIgnored;
-
     return processCreateEx(aExecutable, aArguments, aEnvironment, aFlags, aTimeoutMS, ProcessPriority_Default,
                            affinityIgnored, aGuestProcess);
@@ -3681,5 +3750,10 @@
                                       ComPtr<IGuestProcess> &aGuestProcess)
 {
-    LogFlowThisFuncEnter();
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    HRESULT hr = i_isReadyExternal();
+    if (FAILED(hr))
+        return hr;
 
     /** @todo r=bird: Check input better? aPriority is passed on to the guest
@@ -3701,10 +3775,5 @@
     }
 
-    /*
-     * Check the session.
-     */
-    HRESULT hr = i_isReadyExternal();
-    if (FAILED(hr))
-        return hr;
+    LogFlowThisFuncEnter();
 
     /*
@@ -3784,8 +3853,11 @@
 
 {
-    LogFlowThisFunc(("PID=%RU32\n", aPid));
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
 
     if (aPid == 0)
         return setError(E_INVALIDARG, tr("No valid process ID (PID) specified"));
+
+    LogFlowThisFunc(("PID=%RU32\n", aPid));
 
     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
@@ -3829,9 +3901,12 @@
 HRESULT GuestSession::waitFor(ULONG aWaitFor, ULONG aTimeoutMS, GuestSessionWaitResult_T *aReason)
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    /* Note: No call to i_isReadyExternal() needed here, as the session might not has been started (yet). */
+
     LogFlowThisFuncEnter();
 
-    HRESULT hrc = i_isReadyExternal();
-    if (FAILED(hrc))
-        return hrc;
+    HRESULT hrc = S_OK;
 
     /*
@@ -3872,9 +3947,10 @@
                                    GuestSessionWaitResult_T *aReason)
 {
+    AutoCaller autoCaller(this);
+    if (FAILED(autoCaller.rc())) return autoCaller.rc();
+
+    /* Note: No call to i_isReadyExternal() needed here, as the session might not has been started (yet). */
+
     LogFlowThisFuncEnter();
-
-    HRESULT hrc = i_isReadyExternal();
-    if (FAILED(hrc))
-        return hrc;
 
     /*
@@ -3887,3 +3963,2 @@
     return WaitFor(fWaitFor, aTimeoutMS, aReason);
 }
-
