Index: /trunk/include/VBox/gmm.h
===================================================================
--- /trunk/include/VBox/gmm.h	(revision 29556)
+++ /trunk/include/VBox/gmm.h	(revision 29557)
@@ -298,7 +298,10 @@
 GMMR0DECL(int)  GMMR0UnregisterSharedModule(PVM pVM, VMCPUID idCpu, char *pszModuleName, char *pszVersion, RTGCPTR GCBaseAddr, uint32_t cbModule);
 GMMR0DECL(int)  GMMR0UnregisterAllSharedModules(PVM pVM, VMCPUID idCpu);
-GMMR0DECL(int)  GMMR0CheckSharedModules(PVM pVM, VMCPUID idCpu);
+GMMR0DECL(int) GMMR0CheckSharedModules(PVM pVM, PVMCPU pVCpu);
 GMMR0DECL(int)  GMMR0ResetSharedModules(PVM pVM, VMCPUID idCpu);
-
+#ifdef LOG_ENABLED
+GMMR0DECL(int) GMMR0CheckSharedModulesStart(PVM pVM);
+GMMR0DECL(int) GMMR0CheckSharedModulesEnd(PVM pVM);
+#endif
 
 
Index: /trunk/src/VBox/VMM/VMMR0/GMMR0.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR0/GMMR0.cpp	(revision 29556)
+++ /trunk/src/VBox/VMM/VMMR0/GMMR0.cpp	(revision 29557)
@@ -151,4 +151,5 @@
 *******************************************************************************/
 #define LOG_GROUP LOG_GROUP_GMM
+#include <VBox/vm.h>
 #include <VBox/gmm.h>
 #include "GMMR0Internal.h"
@@ -3993,12 +3994,59 @@
 #endif
 
-/**
- * Check all shared modules for the specified VM
+#ifdef DEBUG_sandervl
+/**
+ * Setup for a GMMR0CheckSharedModules call (to allow log flush jumps back to ring 3)
  *
  * @returns VBox status code.
  * @param   pVM                 VM handle
- * @param   idCpu               VCPU id
- */
-GMMR0DECL(int) GMMR0CheckSharedModules(PVM pVM, VMCPUID idCpu)
+ */
+GMMR0DECL(int) GMMR0CheckSharedModulesStart(PVM pVM)
+{
+    /*
+     * Validate input and get the basics.
+     */
+    PGMM pGMM;
+    GMM_GET_VALID_INSTANCE(pGMM, VERR_INTERNAL_ERROR);
+
+    /*
+     * Take the sempahore and do some more validations.
+     */
+    int rc = RTSemFastMutexRequest(pGMM->Mtx);
+    AssertRC(rc);
+    if (!GMM_CHECK_SANITY_UPON_ENTERING(pGMM))
+        rc = VERR_INTERNAL_ERROR_5;
+    else
+        rc = VINF_SUCCESS;
+
+    return rc;
+}
+
+/**
+ * Clean up after a GMMR0CheckSharedModules call (to allow log flush jumps back to ring 3)
+ *
+ * @returns VBox status code.
+ * @param   pVM                 VM handle
+ */
+GMMR0DECL(int) GMMR0CheckSharedModulesEnd(PVM pVM)
+{
+    /*
+     * Validate input and get the basics.
+     */
+    PGMM pGMM;
+    GMM_GET_VALID_INSTANCE(pGMM, VERR_INTERNAL_ERROR);
+
+    RTSemFastMutexRelease(pGMM->Mtx);
+    return VINF_SUCCESS;
+}
+#endif
+
+/**
+ * Check all shared modules for the specified VM
+ *
+ * @returns VBox status code.
+ * @param   pVM                 VM handle
+ * @param   pVCpu               VMCPU handle
+ */
+GMMR0DECL(int) GMMR0CheckSharedModules(PVM pVM, PVMCPU pVCpu)
 {
 #ifdef VBOX_WITH_PAGE_SHARING
@@ -4009,8 +4057,9 @@
     GMM_GET_VALID_INSTANCE(pGMM, VERR_INTERNAL_ERROR);
     PGVM pGVM;
-    int rc = GVMMR0ByVMAndEMT(pVM, idCpu, &pGVM);
+    int rc = GVMMR0ByVMAndEMT(pVM, pVCpu->idCpu, &pGVM);
     if (RT_FAILURE(rc))
         return rc;
 
+# ifndef DEBUG_sandervl
     /*
      * Take the sempahore and do some more validations.
@@ -4018,4 +4067,5 @@
     rc = RTSemFastMutexRequest(pGMM->Mtx);
     AssertRC(rc);
+# endif
     if (GMM_CHECK_SANITY_UPON_ENTERING(pGMM))
     {
@@ -4024,5 +4074,5 @@
         Log(("GMMR0CheckSharedModules\n"));
         Info.pGVM = pGVM;
-        Info.idCpu = idCpu;
+        Info.idCpu = pVCpu->idCpu;
 
         RTAvlGCPtrDoWithAll(&pGVM->gmm.s.pSharedModuleTree, true /* fFromLeft */, gmmR0CheckSharedModule, &Info);
@@ -4035,5 +4085,7 @@
         rc = VERR_INTERNAL_ERROR_5;
 
+# ifndef DEBUG_sandervl
     RTSemFastMutexRelease(pGMM->Mtx);
+# endif
     return rc;
 #else
Index: /trunk/src/VBox/VMM/VMMR0/VMMR0.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR0/VMMR0.cpp	(revision 29556)
+++ /trunk/src/VBox/VMM/VMMR0/VMMR0.cpp	(revision 29557)
@@ -969,5 +969,15 @@
             ASMAtomicWriteU32(&pVCpu->idHostCpu, RTMpCpuId());
 
-            int rc = GMMR0CheckSharedModules(pVM, idCpu);
+# ifdef DEBUG_sandervl
+            /* Make sure that log flushes can jump back to ring-3; annoying to get an incomplete log (this is risky though as the code doesn't take this into account). */
+            int rc = GMMR0CheckSharedModulesStart(pVM);
+            if (rc == VINF_SUCCESS)
+            {
+                rc = vmmR0CallRing3SetJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, GMMR0CheckSharedModules, pVM, pVCpu); /* this may resume code. */
+                GMMR0CheckSharedModulesEnd(pVM);
+            }
+# else
+            int rc = GMMR0CheckSharedModules(pVM, pVCpu);
+# endif
 
             /* Clear the VCPU context. */
