Index: /trunk/include/iprt/log.h
===================================================================
--- /trunk/include/iprt/log.h	(revision 37817)
+++ /trunk/include/iprt/log.h	(revision 37818)
@@ -1577,4 +1577,14 @@
 
 /**
+ * Flushes a R0 logger instance to a R3 logger.
+ *
+ * @returns iprt status code.
+ * @param   pLogger      The R3 logger instance to flush pLoggerR0 to. If NULL
+ *                       the default logger is used.
+ * @param   pLoggerR0    The R0 logger instance to flush.
+ */
+RTDECL(void) RTLogFlushR0(PRTLOGGER pLogger, PRTLOGGER pLoggerR0);
+
+/**
  * Sets the custom prefix callback.
  *
Index: /trunk/include/iprt/mangling.h
===================================================================
--- /trunk/include/iprt/mangling.h	(revision 37817)
+++ /trunk/include/iprt/mangling.h	(revision 37818)
@@ -656,4 +656,5 @@
 # define RTLogFlush                                     RT_MANGLER(RTLogFlush)
 # define RTLogFlushRC                                   RT_MANGLER(RTLogFlushRC)
+# define RTLogFlushR0                                   RT_MANGLER(RTLogFlushR0)
 # define RTLogFlushToLogger                             RT_MANGLER(RTLogFlushToLogger)
 # define RTLogFormatV                                   RT_MANGLER(RTLogFormatV)
Index: /trunk/src/VBox/Runtime/common/log/log.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/log/log.cpp	(revision 37817)
+++ /trunk/src/VBox/Runtime/common/log/log.cpp	(revision 37818)
@@ -1060,4 +1060,51 @@
 RT_EXPORT_SYMBOL(RTLogSetCustomPrefixCallbackForR0);
 
+RTDECL(void) RTLogFlushR0(PRTLOGGER pLogger, PRTLOGGER pLoggerR0)
+{
+    /*
+     * Resolve defaults.
+     */
+    if (!pLogger)
+    {
+        pLogger = RTLogDefaultInstance();
+        if (!pLogger)
+        {
+            /* flushing to "/dev/null". */
+            if (pLoggerR0->offScratch)
+                    pLoggerR0->offScratch = 0;
+            return;
+        }
+    }
+
+    /*
+     * Any thing to flush?
+     */
+    if (    pLoggerR0->offScratch
+        ||  pLogger->offScratch)
+    {
+        /*
+         * Acquire logger semaphores.
+         */
+        int rc = rtlogLock(pLogger);
+        if (RT_FAILURE(rc))
+            return;
+        if (RT_SUCCESS(rc))
+        {
+            /*
+             * Write whatever the GC instance contains to the HC one, and then
+             * flush the HC instance.
+             */
+            if (pLoggerR0->offScratch)
+            {
+                rtLogOutput(pLogger, pLoggerR0->achScratch, pLoggerR0->offScratch);
+                rtLogOutput(pLogger, NULL, 0);
+                pLoggerR0->offScratch = 0;
+            }
+        }
+        rtlogUnlock(pLogger);
+    }
+}
+RT_EXPORT_SYMBOL(RTLogFlushR0);
+
 # endif /* IN_RING3 */
 
@@ -1089,5 +1136,5 @@
                 {
                     pSrcLogger->offScratch = 0;
-                    rtlogLock(pSrcLogger);
+                    rtlogUnlock(pSrcLogger);
                 }
             }
Index: /trunk/src/VBox/VMM/VMMR3/VMM.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/VMM.cpp	(revision 37817)
+++ /trunk/src/VBox/VMM/VMMR3/VMM.cpp	(revision 37818)
@@ -884,5 +884,5 @@
      * in ring-0. Only initialize it once.
      */
-    PRTLOGGER const pDefault = RTLogRelDefaultInstance();
+    PRTLOGGER const pDefault = RTLogDefaultInstance();
     for (VMCPUID i = 0; i < pVM->cCpus; i++)
     {
@@ -901,5 +901,5 @@
                 AssertReleaseMsgRCReturn(rc, ("vmmR0LoggerFlush not found! rc=%Rra\n", rc), rc);
 
-                rc = RTLogCreateForR0(&pR0LoggerR3->Logger, pR0LoggerR3->cbLogger, pVCpu->vmm.s.pR0LoggerR0,
+                rc = RTLogCreateForR0(&pR0LoggerR3->Logger, pR0LoggerR3->cbLogger, pVCpu->vmm.s.pR0LoggerR0 + RT_OFFSETOF(VMMR0LOGGER, Logger),
                                       pfnLoggerWrapper, pfnLoggerFlush,
                                       RTLOGFLAGS_BUFFERED, RTLOGDEST_DUMMY);
@@ -909,5 +909,5 @@
                 rc = PDMR3LdrGetSymbolR0(pVM, VMMR0_MAIN_MODULE_NAME, "vmmR0LoggerPrefix", &pfnLoggerPrefix);
                 AssertReleaseMsgRCReturn(rc, ("vmmR0LoggerPrefix not found! rc=%Rra\n", rc), rc);
-                rc = RTLogSetCustomPrefixCallbackForR0(&pR0LoggerR3->Logger, pVCpu->vmm.s.pR0LoggerR0, pfnLoggerPrefix, NIL_RTR0PTR);
+                rc = RTLogSetCustomPrefixCallbackForR0(&pR0LoggerR3->Logger, pVCpu->vmm.s.pR0LoggerR0 + RT_OFFSETOF(VMMR0LOGGER, Logger), pfnLoggerPrefix, NIL_RTR0PTR);
                 AssertReleaseMsgRCReturn(rc, ("RTLogSetCustomPrefixCallback failed! rc=%Rra\n", rc), rc);
 
@@ -918,6 +918,6 @@
             }
 
-            rc = RTLogCopyGroupsAndFlagsForR0(&pR0LoggerR3->Logger, pVCpu->vmm.s.pR0LoggerR0, pDefault,
-                                              UINT32_MAX, RTLOGFLAGS_BUFFERED);
+            rc = RTLogCopyGroupsAndFlagsForR0(&pR0LoggerR3->Logger, pVCpu->vmm.s.pR0LoggerR0 + RT_OFFSETOF(VMMR0LOGGER, Logger), pDefault,
+                                              RTLOGFLAGS_BUFFERED, UINT32_MAX);
             AssertRC(rc);
         }
@@ -1293,5 +1293,5 @@
         if (    pR0LoggerR3
             &&  pR0LoggerR3->Logger.offScratch > 0)
-            RTLogFlushToLogger(&pR0LoggerR3->Logger, NULL);
+            RTLogFlushR0(NULL, &pR0LoggerR3->Logger);
 #endif /* !LOG_ENABLED */
         if (rc != VINF_VMM_CALL_HOST)
@@ -1980,5 +1980,5 @@
         if (    pVCpu->vmm.s.pR0LoggerR3
             &&  pVCpu->vmm.s.pR0LoggerR3->Logger.offScratch > 0)
-            RTLogFlushToLogger(&pVCpu->vmm.s.pR0LoggerR3->Logger, NULL);
+            RTLogFlushR0(NULL, &pVCpu->vmm.s.pR0LoggerR3->Logger);
 #endif
         if (rc != VINF_VMM_CALL_HOST)
