Index: /trunk/include/VBox/VBoxCrHgsmi.h
===================================================================
--- /trunk/include/VBox/VBoxCrHgsmi.h	(revision 41373)
+++ /trunk/include/VBox/VBoxCrHgsmi.h	(revision 41374)
@@ -30,11 +30,11 @@
 /* enable this in case we include this in a dll*/
 # ifdef IN_VBOXCRHGSMI
-#  define VBOXCRHGSMI_DECL(a_Type) DECLEXPORT(a_Type)
+#  define VBOXCRHGSMI_DECL(a_Type) DECLEXPORT(a_Type) RTCALL
 # else
-#  define VBOXCRHGSMI_DECL(a_Type) DECLIMPORT(a_Type)
+#  define VBOXCRHGSMI_DECL(a_Type) DECLIMPORT(a_Type) RTCALL
 # endif
 #else
 /*enable this in case we include this in a static lib*/
-# define VBOXCRHGSMI_DECL(a_Type) a_Type
+# define VBOXCRHGSMI_DECL(a_Type) a_Type RTCALL
 #endif
 
@@ -63,8 +63,4 @@
 VBOXCRHGSMI_DECL(int) VBoxCrHgsmiTerm(void);
 
-VBOXCRHGSMI_DECL(void) VBoxCrHgsmiLog(char * szString);
-
-VBOXCRHGSMI_DECL(int) VBoxCrHgsmiTerm(void);
-
 VBOXCRHGSMI_DECL(int) VBoxCrHgsmiCtlConGetClientID(PVBOXUHGSMI pHgsmi, uint32_t *pu32ClientID);
 VBOXCRHGSMI_DECL(int) VBoxCrHgsmiCtlConCall(PVBOXUHGSMI pHgsmi, struct VBoxGuestHGCMCallInfo *pCallInfo, int cbCallInfo);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/Makefile.kmk	(revision 41373)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/Makefile.kmk	(revision 41374)
@@ -122,5 +122,6 @@
 	$(VBOX_LIB_IPRT_GUEST_R3) \
 	$(VBOX_LIB_VBGL_R3) \
-	Psapi.lib
+	Psapi.lib \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger$(VBOX_SUFF_LIB)
 
 #
@@ -133,5 +134,6 @@
 	$(VBOX_LIB_IPRT_GUEST_R3_X86) \
 	$(VBOX_LIB_VBGL_R3_X86) \
-	Psapi.lib
+	Psapi.lib \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger-x86$(VBOX_SUFF_LIB)
 VBoxDispD3D-x86_DEFS = $(VBoxDispD3D_DEFS) VBOX_WDDM_WOW64
 
@@ -161,4 +163,24 @@
 endif #VBOX_WITH_CRHGSMI
 
+#
+# VBoxDispMpLogger - display backdoor logger library
+#
+LIBRARIES += VBoxDispMpLogger
+VBoxDispMpLogger_TEMPLATE    = VBOXGUESTR3LIB
+VBoxDispMpLogger_DEFS        = UNICODE _UNICODE VBOX_WITH_CRHGSMI IN_VBOXCRHGSMI VBOX_WITH_WDDM VBOX_WITH_VDMA VBOX_WITH_HGCM
+VBoxDispMpLogger_INCS        = ../../../include ..
+VBoxDispMpLogger_SOURCES     = \
+    wddm/VBoxDispMpLogger.cpp
+VBoxDispMpLogger_SDKS        = WINDDKWLH
+
+#
+# 64-bit systems needs a 32-bit version of VBoxCrHgsmi.
+#
+LIBRARIES.amd64 += VBoxDispMpLogger-x86
+VBoxDispMpLogger-x86_TEMPLATE    = VBOXGUESTR3LIB
+VBoxDispMpLogger-x86_EXTENDS = VBoxDispMpLogger
+VBoxDispMpLogger-x86_BLD_TRG_ARCH = x86
+VBoxDispMpLogger-x86_DEFS = $(VBoxDispMpLogger_DEFS) VBOX_WDDM_WOW64
+
 endif #ifdef VBOX_WITH_WDDM
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxCrHgsmi.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxCrHgsmi.cpp	(revision 41373)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxCrHgsmi.cpp	(revision 41374)
@@ -253,9 +253,4 @@
 }
 
-VBOXCRHGSMI_DECL(void) VBoxCrHgsmiLog(char * szString)
-{
-    vboxVDbgPrint(("%s", szString));
-}
-
 VBOXCRHGSMI_DECL(int) VBoxCrHgsmiCtlConGetClientID(PVBOXUHGSMI pHgsmi, uint32_t *pu32ClientID)
 {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.cpp	(revision 41373)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.cpp	(revision 41374)
@@ -715,162 +715,4 @@
 
 #if defined(VBOXWDDMDISP_DEBUG) || defined(LOG_TO_BACKDOOR_DRV)
-typedef enum
-{
-    VBOXDISPDBG_STATE_UNINITIALIZED = 0,
-    VBOXDISPDBG_STATE_INITIALIZING,
-    VBOXDISPDBG_STATE_INITIALIZED,
-} VBOXDISPDBG_STATE;
-
-typedef struct VBOXDISPDBG
-{
-    VBOXDISPKMT_CALLBACKS KmtCallbacks;
-    VBOXDISPDBG_STATE enmState;
-} VBOXDISPDBG, *PVBOXDISPDBG;
-
-static VBOXDISPDBG g_VBoxDispDbg = {0};
-
-PVBOXDISPDBG vboxDispDbgGet()
-{
-    if (ASMAtomicCmpXchgU32((volatile uint32_t *)&g_VBoxDispDbg.enmState, VBOXDISPDBG_STATE_INITIALIZING, VBOXDISPDBG_STATE_UNINITIALIZED))
-    {
-        HRESULT hr = vboxDispKmtCallbacksInit(&g_VBoxDispDbg.KmtCallbacks);
-        Assert(hr == S_OK);
-        if (hr == S_OK)
-        {
-            ASMAtomicWriteU32((volatile uint32_t *)&g_VBoxDispDbg.enmState, VBOXDISPDBG_STATE_INITIALIZED);
-            return &g_VBoxDispDbg;
-        }
-        else
-        {
-            ASMAtomicWriteU32((volatile uint32_t *)&g_VBoxDispDbg.enmState, VBOXDISPDBG_STATE_UNINITIALIZED);
-        }
-    }
-    else if (ASMAtomicReadU32((volatile uint32_t *)&g_VBoxDispDbg.enmState) == VBOXDISPDBG_STATE_INITIALIZED)
-    {
-        return &g_VBoxDispDbg;
-    }
-    Assert(0);
-    return NULL;
-}
-
-void vboxDispLogDrv(char * szString)
-{
-    PVBOXDISPDBG pDbg = vboxDispDbgGet();
-    if (!pDbg)
-    {
-        /* do not use WARN her esince this would lead to a recursion */
-        BP_WARN();
-        return;
-    }
-
-    VBOXDISPKMT_ADAPTER Adapter;
-    HRESULT hr = vboxDispKmtOpenAdapter(&pDbg->KmtCallbacks, &Adapter);
-    if (hr == S_OK)
-    {
-        uint32_t cbString = (uint32_t)strlen(szString) + 1;
-        uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGPRINT, aStringBuf[cbString]);
-        PVBOXDISPIFESCAPE_DBGPRINT pCmd = (PVBOXDISPIFESCAPE_DBGPRINT)RTMemAllocZ(cbCmd);
-        if (pCmd)
-        {
-            pCmd->EscapeHdr.escapeCode = VBOXESC_DBGPRINT;
-            memcpy(pCmd->aStringBuf, szString, cbString);
-
-            D3DKMT_ESCAPE EscapeData = {0};
-            EscapeData.hAdapter = Adapter.hAdapter;
-            //EscapeData.hDevice = NULL;
-            EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
-    //        EscapeData.Flags.HardwareAccess = 1;
-            EscapeData.pPrivateDriverData = pCmd;
-            EscapeData.PrivateDriverDataSize = cbCmd;
-            //EscapeData.hContext = NULL;
-
-            int Status = pDbg->KmtCallbacks.pfnD3DKMTEscape(&EscapeData);
-            if (Status)
-            {
-                BP_WARN();
-            }
-
-            RTMemFree(pCmd);
-        }
-        else
-        {
-            BP_WARN();
-        }
-        hr = vboxDispKmtCloseAdapter(&Adapter);
-        if(hr != S_OK)
-        {
-            BP_WARN();
-        }
-    }
-}
-
-void vboxDispLogDrvF(char * szString, ...)
-{
-    char szBuffer[4096] = {0};
-    va_list pArgList;
-    va_start(pArgList, szString);
-    _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), szString, pArgList);
-    va_end(pArgList);
-
-    vboxDispLogDrv(szBuffer);
-}
-
-static void vboxDispDumpBufDrv(void *pvBuf, uint32_t cbBuf, VBOXDISPIFESCAPE_DBGDUMPBUF_TYPE enmBuf)
-{
-    PVBOXDISPDBG pDbg = vboxDispDbgGet();
-    if (!pDbg)
-    {
-        /* do not use WARN her esince this would lead to a recursion */
-        BP_WARN();
-        return;
-    }
-
-    VBOXDISPKMT_ADAPTER Adapter;
-    HRESULT hr = vboxDispKmtOpenAdapter(&pDbg->KmtCallbacks, &Adapter);
-    if (hr == S_OK)
-    {
-        uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGDUMPBUF, aBuf[cbBuf]);
-        PVBOXDISPIFESCAPE_DBGDUMPBUF pCmd = (PVBOXDISPIFESCAPE_DBGDUMPBUF)RTMemAllocZ(cbCmd);
-        if (pCmd)
-        {
-            pCmd->EscapeHdr.escapeCode = VBOXESC_DBGDUMPBUF;
-            pCmd->enmType = enmBuf;
-#ifdef VBOX_WDDM_WOW64
-            pCmd->Flags.WoW64 = 1;
+
 #endif
-            memcpy(pCmd->aBuf, pvBuf, cbBuf);
-
-            D3DKMT_ESCAPE EscapeData = {0};
-            EscapeData.hAdapter = Adapter.hAdapter;
-            //EscapeData.hDevice = NULL;
-            EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
-    //        EscapeData.Flags.HardwareAccess = 1;
-            EscapeData.pPrivateDriverData = pCmd;
-            EscapeData.PrivateDriverDataSize = cbCmd;
-            //EscapeData.hContext = NULL;
-
-            int Status = pDbg->KmtCallbacks.pfnD3DKMTEscape(&EscapeData);
-            if (Status)
-            {
-                BP_WARN();
-            }
-
-            RTMemFree(pCmd);
-        }
-        else
-        {
-            BP_WARN();
-        }
-        hr = vboxDispKmtCloseAdapter(&Adapter);
-        if(hr != S_OK)
-        {
-            BP_WARN();
-        }
-    }
-}
-
-void vboxDispDumpD3DCAPS9Drv(D3DCAPS9 *pCaps)
-{
-    vboxDispDumpBufDrv(pCaps, sizeof (*pCaps), VBOXDISPIFESCAPE_DBGDUMPBUF_TYPE_D3DCAPS9);
-}
-#endif
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h	(revision 41373)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h	(revision 41374)
@@ -111,7 +111,7 @@
 
 #if defined(LOG_TO_BACKDOOR_DRV) || defined(VBOXWDDMDISP_DEBUG_PRINTDRV)
-# define DbgPrintDrv(_m) do { vboxDispLogDrvF _m; } while (0)
-# define DbgPrintDrvRel(_m) do { vboxDispLogDrvF _m; } while (0)
-# define DbgPrintDrvFlow(_m) do { vboxDispLogDrvF _m; } while (0)
+# define DbgPrintDrv(_m) do { VBoxDispMpLoggerLogF _m; } while (0)
+# define DbgPrintDrvRel(_m) do { VBoxDispMpLoggerLogF _m; } while (0)
+# define DbgPrintDrvFlow(_m) do { VBoxDispMpLoggerLogF _m; } while (0)
 #else
 # define DbgPrintDrv(_m) do { } while (0)
@@ -171,9 +171,9 @@
 #if defined(VBOXWDDMDISP_DEBUG) || defined(LOG_TO_BACKDOOR_DRV)
 
-void vboxDispLogDrvF(char * szString, ...);
-void vboxDispLogDrv(char * szString);
-void vboxDispDumpD3DCAPS9Drv(D3DCAPS9 *pCaps);
-
-# define vboxDispDumpD3DCAPS9(_pCaps) do { vboxDispDumpD3DCAPS9Drv(_pCaps); } while (0)
+#include "VBoxDispMpLogger.h"
+
+VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerDumpD3DCAPS9(struct _D3DCAPS9 *pCaps);
+
+# define vboxDispDumpD3DCAPS9(_pCaps) do { VBoxDispMpLoggerDumpD3DCAPS9(_pCaps); } while (0)
 #else
 # define vboxDispDumpD3DCAPS9(_pCaps) do { } while (0)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMp.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMp.cpp	(revision 41373)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMp.cpp	(revision 41374)
@@ -193,5 +193,4 @@
     pCallbacks->pfnDisableEvents = vboxDispMpDisableEvents;
     pCallbacks->pfnGetRegions = vboxDispMpGetRegions;
-    pCallbacks->pfnLog = vboxDispMpLog;
     return S_OK;
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMp.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMp.h	(revision 41373)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMp.h	(revision 41374)
@@ -58,6 +58,4 @@
      */
     PFNVBOXDISPMP_GETREGIONS pfnGetRegions;
-
-    PFNVBOXDISPMP_LOG pfnLog;
 } VBOXDISPMP_CALLBACKS, *PVBOXDISPMP_CALLBACKS;
 
@@ -68,10 +66,10 @@
 /* enable this in case we include this in a dll*/
 # ifdef VBOXWDDMDISP
-#  define VBOXDISPMP_DECL(_type) DECLEXPORT(_type)
+#  define VBOXDISPMP_DECL(_type) DECLEXPORT(_type) VBOXCALL
 # else
-#  define VBOXDISPMP_DECL(_type) DECLIMPORT(_type)
+#  define VBOXDISPMP_DECL(_type) DECLIMPORT(_type) VBOXCALL
 # endif
 
-#define VBOXDISPMP_IFVERSION 2
+#define VBOXDISPMP_IFVERSION 3
 #define VBOXDISPMP_VERSION (VBOXVIDEOIF_VERSION | (VBOXDISPMP_IFVERSION < 16))
 /**
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpLogger.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpLogger.cpp	(revision 41374)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpLogger.cpp	(revision 41374)
@@ -0,0 +1,243 @@
+/* $Id$ */
+
+/** @file
+ * VBox WDDM Display backdoor logger implementation
+ */
+
+/*
+ * Copyright (C) 2012 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+/* We're unable to use standard r3 vbgl-based backdoor logging API because win8 Metro apps
+ * can not do CreateFile/Read/Write by default
+ * this is why we use miniport escape functionality to issue backdoor log string to the miniport
+ * and submit it to host via standard r0 backdoor logging api accordingly */
+#   if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
+#       define _InterlockedExchange           _InterlockedExchange_StupidDDKVsCompilerCrap
+#       define _InterlockedExchangeAdd        _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
+#       define _InterlockedCompareExchange    _InterlockedCompareExchange_StupidDDKVsCompilerCrap
+#       define _InterlockedAddLargeStatistic  _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
+#       define _interlockedbittestandset      _interlockedbittestandset_StupidDDKVsCompilerCrap
+#       define _interlockedbittestandreset    _interlockedbittestandreset_StupidDDKVsCompilerCrap
+#       define _interlockedbittestandset64    _interlockedbittestandset64_StupidDDKVsCompilerCrap
+#       define _interlockedbittestandreset64  _interlockedbittestandreset64_StupidDDKVsCompilerCrap
+#       pragma warning(disable : 4163)
+#       include <windows.h>
+#       pragma warning(default : 4163)
+#       undef  _InterlockedExchange
+#       undef  _InterlockedExchangeAdd
+#       undef  _InterlockedCompareExchange
+#       undef  _InterlockedAddLargeStatistic
+#       undef  _interlockedbittestandset
+#       undef  _interlockedbittestandreset
+#       undef  _interlockedbittestandset64
+#       undef  _interlockedbittestandreset64
+#   else
+#       include <windows.h>
+#   endif
+#include "VBoxDispMpLogger.h"
+#include <d3d9types.h>
+#include <D3dumddi.h>
+#include <d3dhal.h>
+#include "../../common/wddm/VBoxMPIf.h"
+#include "VBoxDispKmt.h"
+
+#define VBOX_VIDEO_LOG_NAME "VBoxDispMpLogger"
+#include <common/VBoxVideoLog.h>
+
+#include <iprt/asm.h>
+#include <iprt/assert.h>
+#include <iprt/mem.h>
+
+#include <stdio.h>
+
+typedef enum
+{
+    VBOXDISPMPLOGGER_STATE_UNINITIALIZED = 0,
+    VBOXDISPMPLOGGER_STATE_INITIALIZING,
+    VBOXDISPMPLOGGER_STATE_INITIALIZED,
+    VBOXDISPMPLOGGER_STATE_UNINITIALIZING
+} VBOXDISPMPLOGGER_STATE;
+
+typedef struct VBOXDISPMPLOGGER
+{
+    VBOXDISPKMT_CALLBACKS KmtCallbacks;
+    VBOXDISPMPLOGGER_STATE enmState;
+} VBOXDISPMPLOGGER, *PVBOXDISPMPLOGGER;
+
+static VBOXDISPMPLOGGER g_VBoxDispMpLogger = {0};
+
+static PVBOXDISPMPLOGGER vboxDispMpLoggerGet()
+{
+    if (ASMAtomicCmpXchgU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_INITIALIZING, VBOXDISPMPLOGGER_STATE_UNINITIALIZED))
+    {
+        HRESULT hr = vboxDispKmtCallbacksInit(&g_VBoxDispMpLogger.KmtCallbacks);
+        if (hr == S_OK)
+        {
+            /* we are on Vista+
+             * check if we can Open Adapter, i.e. WDDM driver is installed */
+            VBOXDISPKMT_ADAPTER Adapter;
+            hr = vboxDispKmtOpenAdapter(&g_VBoxDispMpLogger.KmtCallbacks, &Adapter);
+            if (hr == S_OK)
+            {
+                ASMAtomicWriteU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_INITIALIZED);
+                vboxDispKmtCloseAdapter(&Adapter);
+                return &g_VBoxDispMpLogger;
+            }
+            vboxDispKmtCallbacksTerm(&g_VBoxDispMpLogger.KmtCallbacks);
+        }
+    }
+    else if (ASMAtomicReadU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState) == VBOXDISPMPLOGGER_STATE_INITIALIZED)
+    {
+        return &g_VBoxDispMpLogger;
+    }
+    return NULL;
+}
+
+VBOXDISPMPLOGGER_DECL(int) VBoxDispMpLoggerInit()
+{
+    PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
+    if (!pLogger)
+        return VERR_NOT_SUPPORTED;
+    return VINF_SUCCESS;
+}
+
+VBOXDISPMPLOGGER_DECL(int) VBoxDispMpLoggerTerm()
+{
+    if (ASMAtomicCmpXchgU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_UNINITIALIZING, VBOXDISPMPLOGGER_STATE_INITIALIZED))
+    {
+        vboxDispKmtCallbacksTerm(&g_VBoxDispMpLogger.KmtCallbacks);
+        ASMAtomicWriteU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_UNINITIALIZED);
+        return S_OK;
+    }
+    else if (ASMAtomicReadU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState) == VBOXDISPMPLOGGER_STATE_UNINITIALIZED)
+    {
+        return S_OK;
+    }
+    return VERR_NOT_SUPPORTED;
+}
+
+VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLog(char * szString)
+{
+    PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
+    if (!pLogger)
+        return;
+
+    VBOXDISPKMT_ADAPTER Adapter;
+    HRESULT hr = vboxDispKmtOpenAdapter(&pLogger->KmtCallbacks, &Adapter);
+    if (hr == S_OK)
+    {
+        uint32_t cbString = (uint32_t)strlen(szString) + 1;
+        uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGPRINT, aStringBuf[cbString]);
+        PVBOXDISPIFESCAPE_DBGPRINT pCmd = (PVBOXDISPIFESCAPE_DBGPRINT)RTMemAllocZ(cbCmd);
+        if (pCmd)
+        {
+            pCmd->EscapeHdr.escapeCode = VBOXESC_DBGPRINT;
+            memcpy(pCmd->aStringBuf, szString, cbString);
+
+            D3DKMT_ESCAPE EscapeData = {0};
+            EscapeData.hAdapter = Adapter.hAdapter;
+            //EscapeData.hDevice = NULL;
+            EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
+    //        EscapeData.Flags.HardwareAccess = 1;
+            EscapeData.pPrivateDriverData = pCmd;
+            EscapeData.PrivateDriverDataSize = cbCmd;
+            //EscapeData.hContext = NULL;
+
+            int Status = pLogger->KmtCallbacks.pfnD3DKMTEscape(&EscapeData);
+            if (Status)
+            {
+                BP_WARN();
+            }
+
+            RTMemFree(pCmd);
+        }
+        else
+        {
+            BP_WARN();
+        }
+        hr = vboxDispKmtCloseAdapter(&Adapter);
+        if(hr != S_OK)
+        {
+            BP_WARN();
+        }
+    }
+}
+
+VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLogF(char * szString, ...)
+{
+    PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
+    if (!pLogger)
+        return;
+
+    char szBuffer[4096] = {0};
+    va_list pArgList;
+    va_start(pArgList, szString);
+    _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), szString, pArgList);
+    va_end(pArgList);
+
+    VBoxDispMpLoggerLog(szBuffer);
+}
+
+static void vboxDispMpLoggerDumpBuf(void *pvBuf, uint32_t cbBuf, VBOXDISPIFESCAPE_DBGDUMPBUF_TYPE enmBuf)
+{
+    PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
+    if (!pLogger)
+        return;
+
+    VBOXDISPKMT_ADAPTER Adapter;
+    HRESULT hr = vboxDispKmtOpenAdapter(&pLogger->KmtCallbacks, &Adapter);
+    if (hr == S_OK)
+    {
+        uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGDUMPBUF, aBuf[cbBuf]);
+        PVBOXDISPIFESCAPE_DBGDUMPBUF pCmd = (PVBOXDISPIFESCAPE_DBGDUMPBUF)RTMemAllocZ(cbCmd);
+        if (pCmd)
+        {
+            pCmd->EscapeHdr.escapeCode = VBOXESC_DBGDUMPBUF;
+            pCmd->enmType = enmBuf;
+#ifdef VBOX_WDDM_WOW64
+            pCmd->Flags.WoW64 = 1;
+#endif
+            memcpy(pCmd->aBuf, pvBuf, cbBuf);
+
+            D3DKMT_ESCAPE EscapeData = {0};
+            EscapeData.hAdapter = Adapter.hAdapter;
+            //EscapeData.hDevice = NULL;
+            EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
+    //        EscapeData.Flags.HardwareAccess = 1;
+            EscapeData.pPrivateDriverData = pCmd;
+            EscapeData.PrivateDriverDataSize = cbCmd;
+            //EscapeData.hContext = NULL;
+
+            int Status = pLogger->KmtCallbacks.pfnD3DKMTEscape(&EscapeData);
+            if (Status)
+            {
+                BP_WARN();
+            }
+
+            RTMemFree(pCmd);
+        }
+        else
+        {
+            BP_WARN();
+        }
+        hr = vboxDispKmtCloseAdapter(&Adapter);
+        if(hr != S_OK)
+        {
+            BP_WARN();
+        }
+    }
+}
+
+VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerDumpD3DCAPS9(struct _D3DCAPS9 *pCaps)
+{
+    vboxDispMpLoggerDumpBuf(pCaps, sizeof (*pCaps), VBOXDISPIFESCAPE_DBGDUMPBUF_TYPE_D3DCAPS9);
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpLogger.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpLogger.h	(revision 41374)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpLogger.h	(revision 41374)
@@ -0,0 +1,52 @@
+/* $Id$ */
+
+/** @file
+ * VBox WDDM Display backdoor logger API
+ */
+
+/*
+ * Copyright (C) 2012 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ */
+
+/* We're unable to use standard r3 vbgl-based backdoor logging API because win8 Metro apps
+ * can not do CreateFile/Read/Write by default
+ * this is why we use miniport escape functionality to issue backdoor log string to the miniport
+ * and submit it to host via standard r0 backdoor logging api accordingly */
+#ifndef ___VBoxDispMpLogger_h__
+#define ___VBoxDispMpLogger_h__
+
+#include <iprt/cdefs.h>
+
+#if 0
+/* enable this in case we include this in a dll*/
+# ifdef IN_VBOXCRHGSMI
+#  define VBOXDISPMPLOGGER_DECL(a_Type) DECLEXPORT(a_Type) RTCALL
+# else
+#  define VBOXDISPMPLOGGER_DECL(a_Type) DECLIMPORT(a_Type) RTCALL
+# endif
+#else
+/*enable this in case we include this in a static lib*/
+# define VBOXDISPMPLOGGER_DECL(a_Type) a_Type RTCALL
+#endif
+
+RT_C_DECLS_BEGIN
+
+VBOXDISPMPLOGGER_DECL(int) VBoxDispMpLoggerInit();
+
+VBOXDISPMPLOGGER_DECL(int) VBoxDispMpLoggerTerm();
+
+VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLog(char * szString);
+
+VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLogF(char * szString, ...);
+
+RT_C_DECLS_END
+
+#endif /* #ifndef ___VBoxDispMpLogger_h__ */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 41373)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPWddm.cpp	(revision 41374)
@@ -31,4 +31,6 @@
 #include <VBoxDisplay.h> /* this is from Additions/WINNT/include/ to include escape codes */
 #include <VBox/Hardware/VBoxVideoVBE.h>
+
+DWORD g_VBoxLogUm = 0;
 
 #define VBOXWDDM_MEMTAG 'MDBV'
@@ -4055,9 +4057,8 @@
                     /* ensure the last char is \0*/
                     *((uint8_t*)pDbgPrint + pEscape->PrivateDriverDataSize - 1) = '\0';
-#if defined(DEBUG_misha) || defined(DEBUG_leo)
-                    DbgPrint("%s", pDbgPrint->aStringBuf);
-#else
-                    LOGREL_EXACT(("%s", pDbgPrint->aStringBuf));
-#endif
+                    if (g_VBoxLogUm & VBOXWDDM_CFG_LOG_UM_DBGPRINT)
+                        DbgPrint("%s\n", pDbgPrint->aStringBuf);
+                    if (g_VBoxLogUm & VBOXWDDM_CFG_LOG_UM_BACKDOOR)
+                        LOGREL_EXACT(("%s\n", pDbgPrint->aStringBuf));
                 }
                 Status = STATUS_SUCCESS;
@@ -6093,4 +6094,6 @@
     }
 
+    vboxWddmDrvCfgInit(RegistryPath);
+
     ULONG major, minor, build;
     BOOLEAN checkedBuild = PsGetVersion(&major, &minor, &build, NULL);
Index: /trunk/src/VBox/GuestHost/OpenGL/Makefile.kmk
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/Makefile.kmk	(revision 41373)
+++ /trunk/src/VBox/GuestHost/OpenGL/Makefile.kmk	(revision 41374)
@@ -92,4 +92,9 @@
 VBoxOGLcrutil_LIBS.win    += $(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi$(VBOX_SUFF_LIB)
 endif
+ifdef VBOX_WITH_WDDM
+VBoxOGLcrutil_DEFS.win    += CR_DEBUG_TO_BACKDOOR_ENABLE
+VBoxOGLcrutil_INCS.win    += $(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm
+VBoxOGLcrutil_LIBS.win    += $(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger$(VBOX_SUFF_LIB)
+endif
 VBoxOGLcrutil_CLEAN = \
 	$(VBOX_PATH_CROGL_GENFILES)/debug_opcodes.c
@@ -117,4 +122,9 @@
 endif
 VBoxOGLcrutil-x86_DEFS = $(VBoxOGLcrutil_DEFS) VBOX_WDDM_WOW64
+ifdef VBOX_WITH_WDDM
+# CR_DEBUG_TO_BACKDOOR_ENABLE define is inherited from VBoxOGLcrutil
+VBoxOGLcrutil-x86_INCS.win    += $(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm
+VBoxOGLcrutil-x86_LIBS.win    += $(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger-x86$(VBOX_SUFF_LIB)
+endif
 # vc7 hangs during compilation of this file when optimizations are enabled.
 VBoxOGLcrutil-x86_pixel.c_CFLAGS += -Od
@@ -141,4 +151,9 @@
 VBoxOGLhostcrutil_DEFS    += VBOX_WITH_CRHGSMI
 VBoxOGLhostcrutil_LIBS.win = $(subst $(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi$(VBOX_SUFF_LIB),,$(VBoxOGLcrutil_LIBS.win))
+endif
+ifdef VBOX_WITH_WDDM
+VBoxOGLhostcrutil_LIBS.win = $(subst $(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger$(VBOX_SUFF_LIB),,$(VBoxOGLcrutil_LIBS.win))
+VBoxOGLhostcrutil_INCS.win = $(NO_SUCH_VARIABLE)
+VBoxOGLhostcrutil_DEFS.win = $(NO_SUCH_VARIABLE)
 endif
 
Index: /trunk/src/VBox/GuestHost/OpenGL/util/error.c
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/util/error.c	(revision 41373)
+++ /trunk/src/VBox/GuestHost/OpenGL/util/error.c	(revision 41374)
@@ -27,4 +27,25 @@
 #include <VBox/log.h>
 #endif
+
+#if defined(WINDOWS)
+# define CR_DEBUG_TO_CONSOLE_ENABLE
+#endif
+
+#if defined(WINDOWS) && defined(IN_GUEST)
+# ifndef CR_DEBUG_TO_BACKDOOR_ENABLE
+#  error "CR_DEBUG_TO_BACKDOOR_ENABLE is expected!"
+# endif
+#else
+# ifdef CR_DEBUG_TO_BACKDOOR_ENABLE
+#  error "CR_DEBUG_TO_BACKDOOR_ENABLE is NOT expected!"
+# endif
+#endif
+
+
+#ifdef CR_DEBUG_TO_BACKDOOR_ENABLE
+# include <VBoxDispMpLogger.h>
+# include <iprt/err.h>
+#endif
+
 
 static char my_hostname[256];
@@ -291,24 +312,46 @@
     static int first_time = 1;
     static int silent = 0;
+#ifdef CR_DEBUG_TO_BACKDOOR_ENABLE
+    static int logBackdoor = 0;
+#endif
 
     if (first_time)
     {
         const char *fname = crGetenv( "CR_DEBUG_FILE" );
-        char str[1024];
-
-#if defined(Linux) && defined(IN_GUEST) && defined(DEBUG_leo)
-        if (!fname)
+        const char *fnamePrefix = crGetenv( "CR_DEBUG_FILE_PREFIX" );
+        char str[2048];
+#ifdef CR_DEBUG_TO_CONSOLE_ENABLE
+        int logToConsole = 0;
+#endif
+#ifdef CR_DEBUG_TO_BACKDOOR_ENABLE
+        if (crGetenv( "CR_DEBUG_TO_BACKDOOR" ))
+        {
+            int rc = VBoxDispMpLoggerInit();
+            if (RT_SUCCESS(rc))
+                logBackdoor = 1;
+        }
+#endif
+
+        if (!fname && fnamePrefix)
         {
             char pname[1024];
-            crGetProcName(pname, 1024);
-            sprintf(str, "/home/leo/crlog_%s.txt", pname);
-            fname = &str[0];
-        }
-#endif
+            if (strlen(fnamePrefix) < sizeof (str) - sizeof (pname) - 20)
+            {
+                crGetProcName(pname, 1024);
+                sprintf(str, "%s_%s_%d.txt", fnamePrefix, pname,
+#ifdef RT_OS_WINDOWS
+                        GetCurrentProcessId()
+#else
+                        crGetPID()
+#endif
+                        );
+                fname = &str[0];
+            }
+        }
 
         first_time = 0;
         if (fname)
         {
-            char debugFile[1000], *p;
+            char debugFile[2048], *p;
             crStrcpy(debugFile, fname);
             p = crStrstr(debugFile, "%p");
@@ -327,14 +370,26 @@
         else
         {
-#if defined(WINDOWS) && defined(IN_GUEST) && (defined(DEBUG_leo) || defined(DEBUG_ll158262) || defined(DEBUG_misha))
-            crRedirectIOToConsole();
+#ifdef CR_DEBUG_TO_CONSOLE_ENABLE
+            if (crGetenv( "CR_DEBUG_TO_CONSOLE" ))
+            {
+                crRedirectIOToConsole();
+                logToConsole = 1;
+            }
 #endif
             output = stderr;
         }
+
 #if !defined(DEBUG)/* || defined(DEBUG_misha)*/
         /* Release mode: only emit crDebug messages if CR_DEBUG
          * or CR_DEBUG_FILE is set.
          */
-        if (!fname && !crGetenv("CR_DEBUG"))
+        if (!fname && !crGetenv("CR_DEBUG")
+#ifdef CR_DEBUG_TO_CONSOLE_ENABLE
+                    && !logToConsole
+#endif
+#ifdef CR_DEBUG_TO_BACKDOOR_ENABLE
+                    && !logBackdoor
+#endif
+                )
             silent = 1;
 #endif
@@ -380,27 +435,33 @@
     else
     {
-        offset = sprintf( txt, "[0x%x] OpenGL Debug: ", crThreadID());
-    }
-#else
-    offset = sprintf( txt, "[0x%lx] OpenGL Debug: ", crThreadID());
+        offset = sprintf( txt, "[0x%x.0x%x] OpenGL Debug: ", GetCurrentProcessId(), crThreadID());
+    }
+#else
+    offset = sprintf( txt, "[0x%lx.0x%lx] OpenGL Debug: ", crGetPID(), crThreadID());
 #endif
     va_start( args, format );
     vsprintf( txt + offset, format, args );
+#ifdef CR_DEBUG_TO_BACKDOOR_ENABLE
+    if (logBackdoor)
+    {
+        VBoxDispMpLoggerLog(txt);
+    }
+#endif
 #if defined(IN_GUEST)
     outputChromiumMessage( output, txt );
 #else
-# if defined(DEBUG) && (defined(DEBUG_leo) || defined(DEBUG_ll158262))
-    outputChromiumMessage( output, txt );
+    if (!output
+# ifndef DEBUG_misha
+            || output==stderr
 # endif
-#ifndef DEBUG_misha
-    if (output==stderr)
-#endif
+            )
     {
         LogRel(("%s\n", txt));
     }
-#ifndef DEBUG_misha
     else
-#endif
-    {
+    {
+# ifndef DEBUG_misha
+        LogRel(("%s\n", txt));
+# endif
         outputChromiumMessage(output, txt);
     }
