Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/Makefile.kmk	(revision 68260)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/Makefile.kmk	(revision 68261)
@@ -111,4 +111,5 @@
 	.. \
 	$(VBOX_PATH_CROGL_INCLUDE) \
+	$(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared \
 	$(VBOX_GRAPHICS_INCS)
 VBoxDispD3D_SOURCES  = \
@@ -116,5 +117,4 @@
 	wddm/VBoxDispD3DIf.cpp \
 	wddm/VBoxDispCm.cpp \
-	wddm/VBoxDispKmt.cpp \
 	wddm/VBoxDispDbg.cpp \
 	wddm/VBoxD3DIf.cpp \
@@ -129,4 +129,5 @@
 	Psapi.lib \
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger$(VBOX_SUFF_LIB) \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt$(VBOX_SUFF_LIB) \
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi$(VBOX_SUFF_LIB)
 
@@ -142,4 +143,5 @@
 	Psapi.lib \
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger-x86$(VBOX_SUFF_LIB) \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt-x86$(VBOX_SUFF_LIB) \
 	$(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi-x86$(VBOX_SUFF_LIB)
 VBoxDispD3D-x86_DEFS = $(VBoxDispD3D_DEFS) VBOX_WDDM_WOW64
@@ -158,8 +160,8 @@
 	.. \
 	$(VBOX_PATH_CROGL_INCLUDE) \
+	$(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared \
 	$(VBOX_GRAPHICS_INCS)
 VBoxCrHgsmi_SOURCES     = \
 	wddm/VBoxCrHgsmi.cpp \
-	wddm/VBoxDispKmt.cpp \
 	wddm/VBoxDispDbg.cpp \
 	wddm/VBoxUhgsmiKmt.cpp \
@@ -177,23 +179,5 @@
 endif #VBOX_WITH_CRHGSMI
 
-#
-# VBoxDispMpLogger - display backdoor logger library
-#
-LIBRARIES += VBoxDispMpLogger
-VBoxDispMpLogger_TEMPLATE    = VBoxGuestR3Lib
-VBoxDispMpLogger_SDKS        = ReorderCompilerIncs $(VBOX_WINDDK_GST_WLH)
-VBoxDispMpLogger_DEFS        = UNICODE _UNICODE VBOX_WITH_CRHGSMI IN_VBOXCRHGSMI VBOX_WITH_WDDM VBOX_WITH_VDMA VBOX_WITH_HGCM
-VBoxDispMpLogger_INCS        = ../../../include .. $(VBOX_GRAPHICS_INCS)
-VBoxDispMpLogger_SOURCES     = \
-    wddm/VBoxDispMpLogger.cpp
-
-#
-# 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
+include $(PATH_SUB_CURRENT)/wddm/shared/Makefile.kmk
 
 endif #ifdef VBOX_WITH_WDDM
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DCmn.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DCmn.h	(revision 68260)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispD3DCmn.h	(revision 68261)
@@ -34,5 +34,5 @@
 #include "VBoxDispCm.h"
 #include "VBoxDispMpInternal.h"
-#include "VBoxDispKmt.h"
+#include <VBoxDispKmt.h>
 #ifdef VBOX_WITH_CRHGSMI
 #include "VBoxUhgsmiBase.h"
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h	(revision 68260)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h	(revision 68261)
@@ -186,5 +186,5 @@
 }
 
-#include "VBoxDispMpLogger.h"
+#include <VBoxDispMpLogger.h>
 
 VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerDumpD3DCAPS9(struct _D3DCAPS9 *pCaps);
Index: unk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispKmt.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispKmt.cpp	(revision 68260)
+++ 	(revision )
@@ -1,420 +1,0 @@
-/* $Id$ */
-/** @file
- * VBoxVideo Display D3D User Mode Dll.
- */
-
-/*
- * Copyright (C) 2011-2016 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.
- */
-
-#include "VBoxDispD3DBase.h"
-#include "VBoxDispKmt.h"
-
-#include <iprt/assert.h>
-#include <iprt/log.h>
-
-
-/**
- * Loads a system DLL.
- *
- * @returns Module handle or NULL
- * @param   pszName             The DLL name.
- */
-static HMODULE loadSystemDll(const char *pszName)
-{
-    char   szPath[MAX_PATH];
-    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
-    size_t cbName  = strlen(pszName) + 1;
-    if (cchPath + 1 + cbName > sizeof(szPath))
-        return NULL;
-    szPath[cchPath] = '\\';
-    memcpy(&szPath[cchPath + 1], pszName, cbName);
-    return LoadLibraryA(szPath);
-}
-
-HRESULT vboxDispKmtCallbacksInit(PVBOXDISPKMT_CALLBACKS pCallbacks)
-{
-    HRESULT hr = S_OK;
-
-    memset(pCallbacks, 0, sizeof (*pCallbacks));
-
-    pCallbacks->hGdi32 = loadSystemDll("gdi32.dll");
-    if (pCallbacks->hGdi32 != NULL)
-    {
-        bool bSupported = true;
-        bool bSupportedWin8 = true;
-        pCallbacks->pfnD3DKMTOpenAdapterFromHdc = (PFND3DKMT_OPENADAPTERFROMHDC)GetProcAddress(pCallbacks->hGdi32, "D3DKMTOpenAdapterFromHdc");
-        LogFunc(("pfnD3DKMTOpenAdapterFromHdc = %p\n", pCallbacks->pfnD3DKMTOpenAdapterFromHdc));
-        bSupported &= !!(pCallbacks->pfnD3DKMTOpenAdapterFromHdc);
-
-        pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName = (PFND3DKMT_OPENADAPTERFROMGDIDISPLAYNAME)GetProcAddress(pCallbacks->hGdi32, "D3DKMTOpenAdapterFromGdiDisplayName");
-        LogFunc(("pfnD3DKMTOpenAdapterFromGdiDisplayName = %p\n", pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName));
-        bSupported &= !!(pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName);
-
-        pCallbacks->pfnD3DKMTCloseAdapter = (PFND3DKMT_CLOSEADAPTER)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCloseAdapter");
-        LogFunc(("pfnD3DKMTCloseAdapter = %p\n", pCallbacks->pfnD3DKMTCloseAdapter));
-        bSupported &= !!(pCallbacks->pfnD3DKMTCloseAdapter);
-
-        pCallbacks->pfnD3DKMTEscape = (PFND3DKMT_ESCAPE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTEscape");
-        LogFunc(("pfnD3DKMTEscape = %p\n", pCallbacks->pfnD3DKMTEscape));
-        bSupported &= !!(pCallbacks->pfnD3DKMTEscape);
-
-        pCallbacks->pfnD3DKMTQueryAdapterInfo = (PFND3DKMT_QUERYADAPTERINFO)GetProcAddress(pCallbacks->hGdi32, "D3DKMTQueryAdapterInfo");
-        LogFunc(("pfnD3DKMTQueryAdapterInfo = %p\n", pCallbacks->pfnD3DKMTQueryAdapterInfo));
-        bSupported &= !!(pCallbacks->pfnD3DKMTQueryAdapterInfo);
-
-                pCallbacks->pfnD3DKMTCreateDevice = (PFND3DKMT_CREATEDEVICE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateDevice");
-        LogFunc(("pfnD3DKMTCreateDevice = %p\n", pCallbacks->pfnD3DKMTCreateDevice));
-        bSupported &= !!(pCallbacks->pfnD3DKMTCreateDevice);
-
-        pCallbacks->pfnD3DKMTDestroyDevice = (PFND3DKMT_DESTROYDEVICE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyDevice");
-        LogFunc(("pfnD3DKMTDestroyDevice = %p\n", pCallbacks->pfnD3DKMTDestroyDevice));
-        bSupported &= !!(pCallbacks->pfnD3DKMTDestroyDevice);
-
-        pCallbacks->pfnD3DKMTCreateContext = (PFND3DKMT_CREATECONTEXT)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateContext");
-        LogFunc(("pfnD3DKMTCreateContext = %p\n", pCallbacks->pfnD3DKMTCreateContext));
-        bSupported &= !!(pCallbacks->pfnD3DKMTCreateContext);
-
-        pCallbacks->pfnD3DKMTDestroyContext = (PFND3DKMT_DESTROYCONTEXT)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyContext");
-        LogFunc(("pfnD3DKMTDestroyContext = %p\n", pCallbacks->pfnD3DKMTDestroyContext));
-        bSupported &= !!(pCallbacks->pfnD3DKMTDestroyContext);
-
-        pCallbacks->pfnD3DKMTRender = (PFND3DKMT_RENDER)GetProcAddress(pCallbacks->hGdi32, "D3DKMTRender");
-        LogFunc(("pfnD3DKMTRender = %p\n", pCallbacks->pfnD3DKMTRender));
-        bSupported &= !!(pCallbacks->pfnD3DKMTRender);
-
-        pCallbacks->pfnD3DKMTCreateAllocation = (PFND3DKMT_CREATEALLOCATION)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateAllocation");
-        LogFunc(("pfnD3DKMTCreateAllocation = %p\n", pCallbacks->pfnD3DKMTCreateAllocation));
-        bSupported &= !!(pCallbacks->pfnD3DKMTCreateAllocation);
-
-        pCallbacks->pfnD3DKMTDestroyAllocation = (PFND3DKMT_DESTROYALLOCATION)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyAllocation");
-        LogFunc(("pfnD3DKMTDestroyAllocation = %p\n", pCallbacks->pfnD3DKMTDestroyAllocation));
-        bSupported &= !!(pCallbacks->pfnD3DKMTDestroyAllocation);
-
-        pCallbacks->pfnD3DKMTLock = (PFND3DKMT_LOCK)GetProcAddress(pCallbacks->hGdi32, "D3DKMTLock");
-        LogFunc(("pfnD3DKMTLock = %p\n", pCallbacks->pfnD3DKMTLock));
-        bSupported &= !!(pCallbacks->pfnD3DKMTLock);
-
-        pCallbacks->pfnD3DKMTUnlock = (PFND3DKMT_UNLOCK)GetProcAddress(pCallbacks->hGdi32, "D3DKMTUnlock");
-        LogFunc(("pfnD3DKMTUnlock = %p\n", pCallbacks->pfnD3DKMTUnlock));
-        bSupported &= !!(pCallbacks->pfnD3DKMTUnlock);
-
-        pCallbacks->pfnD3DKMTInvalidateActiveVidPn = (PFND3DKMT_INVALIDATEACTIVEVIDPN)GetProcAddress(pCallbacks->hGdi32, "D3DKMTInvalidateActiveVidPn");
-        LogFunc(("pfnD3DKMTInvalidateActiveVidPn = %p\n", pCallbacks->pfnD3DKMTInvalidateActiveVidPn));
-        bSupported &= !!(pCallbacks->pfnD3DKMTInvalidateActiveVidPn);
-
-        pCallbacks->pfnD3DKMTPollDisplayChildren = (PFND3DKMT_POLLDISPLAYCHILDREN)GetProcAddress(pCallbacks->hGdi32, "D3DKMTPollDisplayChildren");
-        LogFunc(("pfnD3DKMTPollDisplayChildren = %p\n", pCallbacks->pfnD3DKMTPollDisplayChildren));
-        bSupported &= !!(pCallbacks->pfnD3DKMTPollDisplayChildren);
-
-        pCallbacks->pfnD3DKMTEnumAdapters = (PFND3DKMT_ENUMADAPTERS)GetProcAddress(pCallbacks->hGdi32, "D3DKMTEnumAdapters");
-        LogFunc(("pfnD3DKMTEnumAdapters = %p\n", pCallbacks->pfnD3DKMTEnumAdapters));
-        /* this present starting win8 release preview only, so keep going if it is not available,
-         * i.e. do not clear the bSupported on its absence */
-        bSupportedWin8 &= !!(pCallbacks->pfnD3DKMTEnumAdapters);
-
-        pCallbacks->pfnD3DKMTOpenAdapterFromLuid = (PFND3DKMT_OPENADAPTERFROMLUID)GetProcAddress(pCallbacks->hGdi32, "D3DKMTOpenAdapterFromLuid");
-        LogFunc(("pfnD3DKMTOpenAdapterFromLuid = %p\n", pCallbacks->pfnD3DKMTOpenAdapterFromLuid));
-        /* this present starting win8 release preview only, so keep going if it is not available,
-         * i.e. do not clear the bSupported on its absence */
-        bSupportedWin8 &= !!(pCallbacks->pfnD3DKMTOpenAdapterFromLuid);
-
-        /*Assert(bSupported);*/
-        if (bSupported)
-        {
-            if (bSupportedWin8)
-                pCallbacks->enmVersion = VBOXDISPKMT_CALLBACKS_VERSION_WIN8;
-            else
-                pCallbacks->enmVersion = VBOXDISPKMT_CALLBACKS_VERSION_VISTA_WIN7;
-            return S_OK;
-        }
-        else
-        {
-            LogFunc(("one of pfnD3DKMT function pointers failed to initialize\n"));
-            hr = E_NOINTERFACE;
-        }
-
-        FreeLibrary(pCallbacks->hGdi32);
-    }
-    else
-    {
-        DWORD winEr = GetLastError();
-        hr = HRESULT_FROM_WIN32(winEr);
-        Assert(0);
-        Assert(hr != S_OK);
-        Assert(hr != S_FALSE);
-        if (hr == S_OK || hr == S_FALSE)
-            hr = E_FAIL;
-    }
-
-    return hr;
-}
-
-HRESULT vboxDispKmtCallbacksTerm(PVBOXDISPKMT_CALLBACKS pCallbacks)
-{
-    FreeLibrary(pCallbacks->hGdi32);
-#ifdef DEBUG_misha
-    memset(pCallbacks, 0, sizeof (*pCallbacks));
-#endif
-    return S_OK;
-}
-
-HRESULT vboxDispKmtAdpHdcCreate(HDC *phDc)
-{
-    HRESULT hr = E_FAIL;
-    DISPLAY_DEVICE DDev;
-    memset(&DDev, 0, sizeof (DDev));
-    DDev.cb = sizeof (DDev);
-
-    *phDc = NULL;
-
-    for (int i = 0; ; ++i)
-    {
-        if (EnumDisplayDevices(NULL, /* LPCTSTR lpDevice */ i, /* DWORD iDevNum */
-                &DDev, 0 /* DWORD dwFlags*/))
-        {
-            if (DDev.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
-            {
-                HDC hDc = CreateDC(NULL, DDev.DeviceName, NULL, NULL);
-                if (hDc)
-                {
-                    *phDc = hDc;
-                    return S_OK;
-                }
-                else
-                {
-                    DWORD winEr = GetLastError();
-                    Assert(0);
-                    hr = HRESULT_FROM_WIN32(winEr);
-                    Assert(FAILED(hr));
-                    break;
-                }
-            }
-        }
-        else
-        {
-            DWORD winEr = GetLastError();
-//            BP_WARN();
-            hr = HRESULT_FROM_WIN32(winEr);
-#ifdef DEBUG_misha
-            Assert(FAILED(hr));
-#endif
-            if (!FAILED(hr))
-            {
-                hr = E_FAIL;
-            }
-            break;
-        }
-    }
-
-    return hr;
-}
-
-static HRESULT vboxDispKmtOpenAdapterViaHdc(const VBOXDISPKMT_CALLBACKS *pCallbacks, PVBOXDISPKMT_ADAPTER pAdapter)
-{
-    D3DKMT_OPENADAPTERFROMHDC OpenAdapterData = {0};
-    HRESULT hr = vboxDispKmtAdpHdcCreate(&OpenAdapterData.hDc);
-    if (!SUCCEEDED(hr))
-        return hr;
-
-    Assert(OpenAdapterData.hDc);
-    NTSTATUS Status = pCallbacks->pfnD3DKMTOpenAdapterFromHdc(&OpenAdapterData);
-    if (NT_SUCCESS(Status))
-    {
-        pAdapter->hAdapter = OpenAdapterData.hAdapter;
-        pAdapter->hDc = OpenAdapterData.hDc;
-        pAdapter->pCallbacks = pCallbacks;
-        memset(&pAdapter->Luid, 0, sizeof (pAdapter->Luid));
-        return S_OK;
-    }
-    else
-    {
-        LogFunc(("pfnD3DKMTOpenAdapterFromGdiDisplayName failed, Status (0x%x)\n", Status));
-        hr = E_FAIL;
-    }
-
-    DeleteDC(OpenAdapterData.hDc);
-
-    return hr;
-}
-
-static HRESULT vboxDispKmtOpenAdapterViaLuid(const VBOXDISPKMT_CALLBACKS *pCallbacks, PVBOXDISPKMT_ADAPTER pAdapter)
-{
-    if (pCallbacks->enmVersion < VBOXDISPKMT_CALLBACKS_VERSION_WIN8)
-        return E_NOTIMPL;
-
-    D3DKMT_ENUMADAPTERS EnumAdapters = {0};
-    EnumAdapters.NumAdapters = RT_ELEMENTS(EnumAdapters.Adapters);
-
-    NTSTATUS Status = pCallbacks->pfnD3DKMTEnumAdapters(&EnumAdapters);
-#ifdef DEBUG_misha
-    Assert(!Status);
-#endif
-    if (!NT_SUCCESS(Status))
-        return E_FAIL;
-
-    Assert(EnumAdapters.NumAdapters);
-
-    /* try the same twice: if we fail to open the adapter containing present sources,
-     * try to open any adapter */
-    for (ULONG f = 0; f < 2; ++f)
-    {
-        for (ULONG i = 0; i < EnumAdapters.NumAdapters; ++i)
-        {
-            if (f || EnumAdapters.Adapters[i].NumOfSources)
-            {
-                D3DKMT_OPENADAPTERFROMLUID OpenAdapterData = {0};
-                OpenAdapterData.AdapterLuid = EnumAdapters.Adapters[i].AdapterLuid;
-                Status = pCallbacks->pfnD3DKMTOpenAdapterFromLuid(&OpenAdapterData);
-    #ifdef DEBUG_misha
-                Assert(!Status);
-    #endif
-                if (NT_SUCCESS(Status))
-                {
-                    pAdapter->hAdapter = OpenAdapterData.hAdapter;
-                    pAdapter->hDc = NULL;
-                    pAdapter->Luid = EnumAdapters.Adapters[i].AdapterLuid;
-                    pAdapter->pCallbacks = pCallbacks;
-                    return S_OK;
-                }
-            }
-        }
-    }
-
-#ifdef DEBUG_misha
-    Assert(0);
-#endif
-    return E_FAIL;
-}
-
-HRESULT vboxDispKmtOpenAdapter(const VBOXDISPKMT_CALLBACKS *pCallbacks, PVBOXDISPKMT_ADAPTER pAdapter)
-{
-    HRESULT hr = vboxDispKmtOpenAdapterViaHdc(pCallbacks, pAdapter);
-    if (SUCCEEDED(hr))
-        return S_OK;
-
-    hr = vboxDispKmtOpenAdapterViaLuid(pCallbacks, pAdapter);
-    if (SUCCEEDED(hr))
-        return S_OK;
-
-    return hr;
-}
-
-HRESULT vboxDispKmtCloseAdapter(PVBOXDISPKMT_ADAPTER pAdapter)
-{
-    D3DKMT_CLOSEADAPTER ClosaAdapterData = {0};
-    ClosaAdapterData.hAdapter = pAdapter->hAdapter;
-    NTSTATUS Status = pAdapter->pCallbacks->pfnD3DKMTCloseAdapter(&ClosaAdapterData);
-    Assert(!Status);
-    if (!Status)
-    {
-        DeleteDC(pAdapter->hDc);
-#ifdef DEBUG_misha
-        memset(pAdapter, 0, sizeof (*pAdapter));
-#endif
-        return S_OK;
-    }
-
-    LogFunc(("pfnD3DKMTCloseAdapter failed, Status (0x%x)\n", Status));
-
-    return E_FAIL;
-}
-
-HRESULT vboxDispKmtCreateDevice(PVBOXDISPKMT_ADAPTER pAdapter, PVBOXDISPKMT_DEVICE pDevice)
-{
-    D3DKMT_CREATEDEVICE CreateDeviceData = {0};
-    CreateDeviceData.hAdapter = pAdapter->hAdapter;
-    NTSTATUS Status = pAdapter->pCallbacks->pfnD3DKMTCreateDevice(&CreateDeviceData);
-    Assert(!Status);
-    if (!Status)
-    {
-        pDevice->pAdapter = pAdapter;
-        pDevice->hDevice = CreateDeviceData.hDevice;
-        pDevice->pCommandBuffer = CreateDeviceData.pCommandBuffer;
-        pDevice->CommandBufferSize = CreateDeviceData.CommandBufferSize;
-        pDevice->pAllocationList = CreateDeviceData.pAllocationList;
-        pDevice->AllocationListSize = CreateDeviceData.AllocationListSize;
-        pDevice->pPatchLocationList = CreateDeviceData.pPatchLocationList;
-        pDevice->PatchLocationListSize = CreateDeviceData.PatchLocationListSize;
-
-        return S_OK;
-    }
-
-    return E_FAIL;
-}
-
-HRESULT vboxDispKmtDestroyDevice(PVBOXDISPKMT_DEVICE pDevice)
-{
-    D3DKMT_DESTROYDEVICE DestroyDeviceData = {0};
-    DestroyDeviceData.hDevice = pDevice->hDevice;
-    NTSTATUS Status = pDevice->pAdapter->pCallbacks->pfnD3DKMTDestroyDevice(&DestroyDeviceData);
-    Assert(!Status);
-    if (!Status)
-    {
-#ifdef DEBUG_misha
-        memset(pDevice, 0, sizeof (*pDevice));
-#endif
-        return S_OK;
-    }
-    return E_FAIL;
-}
-
-HRESULT vboxDispKmtCreateContext(PVBOXDISPKMT_DEVICE pDevice, PVBOXDISPKMT_CONTEXT pContext,
-                                    VBOXWDDM_CONTEXT_TYPE enmType,
-                                    uint32_t crVersionMajor, uint32_t crVersionMinor,
-                                    HANDLE hEvent, uint64_t u64UmInfo)
-{
-    VBOXWDDM_CREATECONTEXT_INFO Info = {0};
-    Info.u32IfVersion = 9;
-    Info.enmType = enmType;
-    Info.crVersionMajor = crVersionMajor;
-    Info.crVersionMinor = crVersionMinor;
-    Info.hUmEvent = (uintptr_t)hEvent;
-    Info.u64UmInfo = u64UmInfo;
-    D3DKMT_CREATECONTEXT ContextData = {0};
-    ContextData.hDevice = pDevice->hDevice;
-    ContextData.NodeOrdinal = VBOXWDDM_NODE_ID_3D_KMT;
-    ContextData.EngineAffinity = VBOXWDDM_ENGINE_ID_3D_KMT;
-    ContextData.pPrivateDriverData = &Info;
-    ContextData.PrivateDriverDataSize = sizeof (Info);
-    ContextData.ClientHint = enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_UHGSMI_GL ? D3DKMT_CLIENTHINT_OPENGL : D3DKMT_CLIENTHINT_DX9;
-    NTSTATUS Status = pDevice->pAdapter->pCallbacks->pfnD3DKMTCreateContext(&ContextData);
-    Assert(!Status);
-    if (!Status)
-    {
-        pContext->pDevice = pDevice;
-        pContext->hContext = ContextData.hContext;
-        pContext->pCommandBuffer = ContextData.pCommandBuffer;
-        pContext->CommandBufferSize = ContextData.CommandBufferSize;
-        pContext->pAllocationList = ContextData.pAllocationList;
-        pContext->AllocationListSize = ContextData.AllocationListSize;
-        pContext->pPatchLocationList = ContextData.pPatchLocationList;
-        pContext->PatchLocationListSize = ContextData.PatchLocationListSize;
-        return S_OK;
-    }
-    return E_FAIL;
-}
-
-HRESULT vboxDispKmtDestroyContext(PVBOXDISPKMT_CONTEXT pContext)
-{
-    D3DKMT_DESTROYCONTEXT DestroyContextData = {0};
-    DestroyContextData.hContext = pContext->hContext;
-    NTSTATUS Status = pContext->pDevice->pAdapter->pCallbacks->pfnD3DKMTDestroyContext(&DestroyContextData);
-    Assert(!Status);
-    if (!Status)
-    {
-#ifdef DEBUG_misha
-        memset(pContext, 0, sizeof (*pContext));
-#endif
-        return S_OK;
-    }
-    return E_FAIL;
-}
Index: unk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispKmt.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispKmt.h	(revision 68260)
+++ 	(revision )
@@ -1,143 +1,0 @@
-/* $Id$ */
-
-/** @file
- * VBoxVideo Display D3D User mode dll
- */
-
-/*
- * Copyright (C) 2011-2016 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.
- */
-
-#ifndef ___VBoxDispKmt_h__
-#define ___VBoxDispKmt_h__
-
-#include <D3dkmthk.h>
-
-#include "../../common/wddm/VBoxMPIf.h"
-
-/* win8 release preview-specific stuff */
-typedef struct _D3DKMT_ADAPTERINFO
-{
-  D3DKMT_HANDLE hAdapter;
-  LUID          AdapterLuid;
-  ULONG         NumOfSources;
-  BOOL          bPresentMoveRegionsPreferred;
-} D3DKMT_ADAPTERINFO;
-
-#define MAX_ENUM_ADAPTERS 16
-
-typedef struct _D3DKMT_ENUMADAPTERS
-{
-  ULONG              NumAdapters;
-  D3DKMT_ADAPTERINFO Adapters[MAX_ENUM_ADAPTERS];
-} D3DKMT_ENUMADAPTERS;
-
-typedef NTSTATUS (APIENTRY *PFND3DKMT_ENUMADAPTERS)(IN OUT D3DKMT_ENUMADAPTERS*);
-
-typedef struct _D3DKMT_OPENADAPTERFROMLUID
-{
-  LUID          AdapterLuid;
-  D3DKMT_HANDLE hAdapter;
-} D3DKMT_OPENADAPTERFROMLUID;
-
-typedef NTSTATUS (APIENTRY *PFND3DKMT_OPENADAPTERFROMLUID)(IN OUT D3DKMT_OPENADAPTERFROMLUID*);
-/* END OF win8 release preview-specific stuff */
-
-typedef enum
-{
-    VBOXDISPKMT_CALLBACKS_VERSION_UNDEFINED = 0,
-    VBOXDISPKMT_CALLBACKS_VERSION_VISTA_WIN7,
-    VBOXDISPKMT_CALLBACKS_VERSION_WIN8
-} VBOXDISPKMT_CALLBACKS_VERSION;
-
-typedef struct VBOXDISPKMT_CALLBACKS
-{
-    HMODULE hGdi32;
-    VBOXDISPKMT_CALLBACKS_VERSION enmVersion;
-    /* open adapter */
-    PFND3DKMT_OPENADAPTERFROMHDC pfnD3DKMTOpenAdapterFromHdc;
-    PFND3DKMT_OPENADAPTERFROMGDIDISPLAYNAME pfnD3DKMTOpenAdapterFromGdiDisplayName;
-    /* close adapter */
-    PFND3DKMT_CLOSEADAPTER pfnD3DKMTCloseAdapter;
-    /* escape */
-    PFND3DKMT_ESCAPE pfnD3DKMTEscape;
-
-    PFND3DKMT_QUERYADAPTERINFO pfnD3DKMTQueryAdapterInfo;
-
-    PFND3DKMT_CREATEDEVICE pfnD3DKMTCreateDevice;
-    PFND3DKMT_DESTROYDEVICE pfnD3DKMTDestroyDevice;
-    PFND3DKMT_CREATECONTEXT pfnD3DKMTCreateContext;
-    PFND3DKMT_DESTROYCONTEXT pfnD3DKMTDestroyContext;
-
-    PFND3DKMT_RENDER pfnD3DKMTRender;
-
-    PFND3DKMT_CREATEALLOCATION pfnD3DKMTCreateAllocation;
-    PFND3DKMT_DESTROYALLOCATION pfnD3DKMTDestroyAllocation;
-
-    PFND3DKMT_LOCK pfnD3DKMTLock;
-    PFND3DKMT_UNLOCK pfnD3DKMTUnlock;
-
-    /* auto resize support */
-    PFND3DKMT_INVALIDATEACTIVEVIDPN pfnD3DKMTInvalidateActiveVidPn;
-    PFND3DKMT_POLLDISPLAYCHILDREN pfnD3DKMTPollDisplayChildren;
-
-    /* win8 specifics */
-    PFND3DKMT_ENUMADAPTERS pfnD3DKMTEnumAdapters;
-    PFND3DKMT_OPENADAPTERFROMLUID pfnD3DKMTOpenAdapterFromLuid;
-} VBOXDISPKMT_CALLBACKS, *PVBOXDISPKMT_CALLBACKS;
-
-typedef struct VBOXDISPKMT_ADAPTER
-{
-    D3DKMT_HANDLE hAdapter;
-    HDC hDc;
-    LUID Luid;
-    const VBOXDISPKMT_CALLBACKS *pCallbacks;
-}VBOXDISPKMT_ADAPTER, *PVBOXDISPKMT_ADAPTER;
-
-typedef struct VBOXDISPKMT_DEVICE
-{
-    struct VBOXDISPKMT_ADAPTER *pAdapter;
-    D3DKMT_HANDLE hDevice;
-    VOID *pCommandBuffer;
-    UINT CommandBufferSize;
-    D3DDDI_ALLOCATIONLIST *pAllocationList;
-    UINT AllocationListSize;
-    D3DDDI_PATCHLOCATIONLIST *pPatchLocationList;
-    UINT PatchLocationListSize;
-}VBOXDISPKMT_DEVICE, *PVBOXDISPKMT_DEVICE;
-
-typedef struct VBOXDISPKMT_CONTEXT
-{
-    struct VBOXDISPKMT_DEVICE *pDevice;
-    D3DKMT_HANDLE hContext;
-    VOID *pCommandBuffer;
-    UINT CommandBufferSize;
-    D3DDDI_ALLOCATIONLIST *pAllocationList;
-    UINT AllocationListSize;
-    D3DDDI_PATCHLOCATIONLIST *pPatchLocationList;
-    UINT PatchLocationListSize;
-} VBOXDISPKMT_CONTEXT, *PVBOXDISPKMT_CONTEXT;
-
-HRESULT vboxDispKmtCallbacksInit(PVBOXDISPKMT_CALLBACKS pCallbacks);
-HRESULT vboxDispKmtCallbacksTerm(PVBOXDISPKMT_CALLBACKS pCallbacks);
-
-HRESULT vboxDispKmtOpenAdapter(const VBOXDISPKMT_CALLBACKS *pCallbacks, PVBOXDISPKMT_ADAPTER pAdapter);
-HRESULT vboxDispKmtCloseAdapter(PVBOXDISPKMT_ADAPTER pAdapter);
-HRESULT vboxDispKmtCreateDevice(PVBOXDISPKMT_ADAPTER pAdapter, PVBOXDISPKMT_DEVICE pDevice);
-HRESULT vboxDispKmtDestroyDevice(PVBOXDISPKMT_DEVICE pDevice);
-HRESULT vboxDispKmtCreateContext(PVBOXDISPKMT_DEVICE pDevice, PVBOXDISPKMT_CONTEXT pContext,
-        VBOXWDDM_CONTEXT_TYPE enmType,
-        uint32_t crVersionMajor, uint32_t crVersionMinor,
-        HANDLE hEvent, uint64_t u64UmInfo);
-HRESULT vboxDispKmtDestroyContext(PVBOXDISPKMT_CONTEXT pContext);
-
-
-#endif /* #ifndef ___VBoxDispKmt_h__ */
Index: unk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpLogger.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpLogger.cpp	(revision 68260)
+++ 	(revision )
@@ -1,244 +1,0 @@
-/* $Id$ */
-
-/** @file
- * VBox WDDM Display backdoor logger implementation
- */
-
-/*
- * Copyright (C) 2012-2016 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 <iprt/win/windows.h>
-#       pragma warning(default : 4163)
-#       undef  _InterlockedExchange
-#       undef  _InterlockedExchangeAdd
-#       undef  _InterlockedCompareExchange
-#       undef  _InterlockedAddLargeStatistic
-#       undef  _interlockedbittestandset
-#       undef  _interlockedbittestandreset
-#       undef  _interlockedbittestandset64
-#       undef  _interlockedbittestandreset64
-#   else
-#       include <iprt/win/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/err.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(void)
-{
-    PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
-    if (!pLogger)
-        return VERR_NOT_SUPPORTED;
-    return VINF_SUCCESS;
-}
-
-VBOXDISPMPLOGGER_DECL(int) VBoxDispMpLoggerTerm(void)
-{
-    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(const char *pszString)
-{
-    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(pszString) + 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, pszString, 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(const char *pszString, ...)
-{
-    PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
-    if (!pLogger)
-        return;
-
-    char szBuffer[4096] = {0};
-    va_list pArgList;
-    va_start(pArgList, pszString);
-    _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), pszString, 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: unk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpLogger.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpLogger.h	(revision 68260)
+++ 	(revision )
@@ -1,53 +1,0 @@
-/* $Id$ */
-/** @file
- * VBox WDDM Display backdoor logger API
- */
-
-/*
- * Copyright (C) 2012-2016 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(void);
-
-VBOXDISPMPLOGGER_DECL(int) VBoxDispMpLoggerTerm(void);
-
-VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLog(const char *pszString);
-
-VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLogF(const char *pszString, ...);
-
-RT_C_DECLS_END
-
-#endif /* #ifndef ___VBoxDispMpLogger_h__ */
-
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/Makefile.kmk	(revision 68261)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/Makefile.kmk	(revision 68261)
@@ -0,0 +1,68 @@
+# $Id$
+## @file
+# Sub-Makefile for the VirtualBox WDDM user mode driver
+#
+
+#
+# Copyright (C) 2017 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.
+#
+
+SUB_DEPTH = ../../../../../../../../..
+include $(KBUILD_PATH)/subheader.kmk
+
+
+#
+# VBoxDispMpLogger - display backdoor logger library
+#
+LIBRARIES += VBoxDispMpLogger
+VBoxDispMpLogger_TEMPLATE    = VBoxGuestR3Lib
+VBoxDispMpLogger_SDKS        = ReorderCompilerIncs $(VBOX_WINDDK_GST_WLH)
+VBoxDispMpLogger_DEFS        = UNICODE _UNICODE VBOX_WITH_CRHGSMI IN_VBOXCRHGSMI VBOX_WITH_WDDM VBOX_WITH_VDMA VBOX_WITH_HGCM
+VBoxDispMpLogger_INCS        = \
+	$(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared \
+	$(VBOX_GRAPHICS_INCS)
+VBoxDispMpLogger_SOURCES     = \
+	VBoxDispMpLogger.cpp
+
+#
+# 64-bit systems needs a 32-bit version of VBoxDispMpLogger.
+#
+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
+
+
+#
+# VBoxWddmUmKmt - User mode kernel mode thunk (KMT) interfaces
+#
+LIBRARIES += VBoxWddmUmKmt
+VBoxWddmUmKmt_TEMPLATE    = VBoxGuestR3Lib
+VBoxWddmUmKmt_SDKS        = ReorderCompilerIncs $(VBOX_WINDDK_GST_WLH)
+VBoxWddmUmKmt_DEFS        = UNICODE _UNICODE VBOX_WITH_CRHGSMI IN_VBOXCRHGSMI VBOX_WITH_WDDM VBOX_WITH_VDMA VBOX_WITH_HGCM
+VBoxWddmUmKmt_INCS        = \
+	$(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared \
+	$(VBOX_GRAPHICS_INCS)
+VBoxWddmUmKmt_SOURCES     = \
+	VBoxDispKmt.cpp
+
+#
+# 64-bit systems needs a 32-bit version of VBoxWddmUmKmt.
+#
+LIBRARIES.amd64 += VBoxWddmUmKmt-x86
+VBoxWddmUmKmt-x86_TEMPLATE     = VBoxGuestR3Lib
+VBoxWddmUmKmt-x86_EXTENDS      = VBoxWddmUmKmt
+VBoxWddmUmKmt-x86_BLD_TRG_ARCH = x86
+VBoxWddmUmKmt-x86_DEFS         = $(VBoxWddmUmKmt_DEFS) VBOX_WDDM_WOW64
+
+
+include $(FILE_KBUILD_SUB_FOOTER)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispKmt.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispKmt.cpp	(revision 68261)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispKmt.cpp	(revision 68261)
@@ -0,0 +1,420 @@
+/* $Id$ */
+/** @file
+ * VBoxVideo Display D3D User Mode Dll.
+ */
+
+/*
+ * Copyright (C) 2011-2016 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.
+ */
+
+#include <../VBoxDispD3DBase.h>
+#include <VBoxDispKmt.h>
+
+#include <iprt/assert.h>
+#include <iprt/log.h>
+
+
+/**
+ * Loads a system DLL.
+ *
+ * @returns Module handle or NULL
+ * @param   pszName             The DLL name.
+ */
+static HMODULE loadSystemDll(const char *pszName)
+{
+    char   szPath[MAX_PATH];
+    UINT   cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
+    size_t cbName  = strlen(pszName) + 1;
+    if (cchPath + 1 + cbName > sizeof(szPath))
+        return NULL;
+    szPath[cchPath] = '\\';
+    memcpy(&szPath[cchPath + 1], pszName, cbName);
+    return LoadLibraryA(szPath);
+}
+
+HRESULT vboxDispKmtCallbacksInit(PVBOXDISPKMT_CALLBACKS pCallbacks)
+{
+    HRESULT hr = S_OK;
+
+    memset(pCallbacks, 0, sizeof (*pCallbacks));
+
+    pCallbacks->hGdi32 = loadSystemDll("gdi32.dll");
+    if (pCallbacks->hGdi32 != NULL)
+    {
+        bool bSupported = true;
+        bool bSupportedWin8 = true;
+        pCallbacks->pfnD3DKMTOpenAdapterFromHdc = (PFND3DKMT_OPENADAPTERFROMHDC)GetProcAddress(pCallbacks->hGdi32, "D3DKMTOpenAdapterFromHdc");
+        LogFunc(("pfnD3DKMTOpenAdapterFromHdc = %p\n", pCallbacks->pfnD3DKMTOpenAdapterFromHdc));
+        bSupported &= !!(pCallbacks->pfnD3DKMTOpenAdapterFromHdc);
+
+        pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName = (PFND3DKMT_OPENADAPTERFROMGDIDISPLAYNAME)GetProcAddress(pCallbacks->hGdi32, "D3DKMTOpenAdapterFromGdiDisplayName");
+        LogFunc(("pfnD3DKMTOpenAdapterFromGdiDisplayName = %p\n", pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName));
+        bSupported &= !!(pCallbacks->pfnD3DKMTOpenAdapterFromGdiDisplayName);
+
+        pCallbacks->pfnD3DKMTCloseAdapter = (PFND3DKMT_CLOSEADAPTER)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCloseAdapter");
+        LogFunc(("pfnD3DKMTCloseAdapter = %p\n", pCallbacks->pfnD3DKMTCloseAdapter));
+        bSupported &= !!(pCallbacks->pfnD3DKMTCloseAdapter);
+
+        pCallbacks->pfnD3DKMTEscape = (PFND3DKMT_ESCAPE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTEscape");
+        LogFunc(("pfnD3DKMTEscape = %p\n", pCallbacks->pfnD3DKMTEscape));
+        bSupported &= !!(pCallbacks->pfnD3DKMTEscape);
+
+        pCallbacks->pfnD3DKMTQueryAdapterInfo = (PFND3DKMT_QUERYADAPTERINFO)GetProcAddress(pCallbacks->hGdi32, "D3DKMTQueryAdapterInfo");
+        LogFunc(("pfnD3DKMTQueryAdapterInfo = %p\n", pCallbacks->pfnD3DKMTQueryAdapterInfo));
+        bSupported &= !!(pCallbacks->pfnD3DKMTQueryAdapterInfo);
+
+                pCallbacks->pfnD3DKMTCreateDevice = (PFND3DKMT_CREATEDEVICE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateDevice");
+        LogFunc(("pfnD3DKMTCreateDevice = %p\n", pCallbacks->pfnD3DKMTCreateDevice));
+        bSupported &= !!(pCallbacks->pfnD3DKMTCreateDevice);
+
+        pCallbacks->pfnD3DKMTDestroyDevice = (PFND3DKMT_DESTROYDEVICE)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyDevice");
+        LogFunc(("pfnD3DKMTDestroyDevice = %p\n", pCallbacks->pfnD3DKMTDestroyDevice));
+        bSupported &= !!(pCallbacks->pfnD3DKMTDestroyDevice);
+
+        pCallbacks->pfnD3DKMTCreateContext = (PFND3DKMT_CREATECONTEXT)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateContext");
+        LogFunc(("pfnD3DKMTCreateContext = %p\n", pCallbacks->pfnD3DKMTCreateContext));
+        bSupported &= !!(pCallbacks->pfnD3DKMTCreateContext);
+
+        pCallbacks->pfnD3DKMTDestroyContext = (PFND3DKMT_DESTROYCONTEXT)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyContext");
+        LogFunc(("pfnD3DKMTDestroyContext = %p\n", pCallbacks->pfnD3DKMTDestroyContext));
+        bSupported &= !!(pCallbacks->pfnD3DKMTDestroyContext);
+
+        pCallbacks->pfnD3DKMTRender = (PFND3DKMT_RENDER)GetProcAddress(pCallbacks->hGdi32, "D3DKMTRender");
+        LogFunc(("pfnD3DKMTRender = %p\n", pCallbacks->pfnD3DKMTRender));
+        bSupported &= !!(pCallbacks->pfnD3DKMTRender);
+
+        pCallbacks->pfnD3DKMTCreateAllocation = (PFND3DKMT_CREATEALLOCATION)GetProcAddress(pCallbacks->hGdi32, "D3DKMTCreateAllocation");
+        LogFunc(("pfnD3DKMTCreateAllocation = %p\n", pCallbacks->pfnD3DKMTCreateAllocation));
+        bSupported &= !!(pCallbacks->pfnD3DKMTCreateAllocation);
+
+        pCallbacks->pfnD3DKMTDestroyAllocation = (PFND3DKMT_DESTROYALLOCATION)GetProcAddress(pCallbacks->hGdi32, "D3DKMTDestroyAllocation");
+        LogFunc(("pfnD3DKMTDestroyAllocation = %p\n", pCallbacks->pfnD3DKMTDestroyAllocation));
+        bSupported &= !!(pCallbacks->pfnD3DKMTDestroyAllocation);
+
+        pCallbacks->pfnD3DKMTLock = (PFND3DKMT_LOCK)GetProcAddress(pCallbacks->hGdi32, "D3DKMTLock");
+        LogFunc(("pfnD3DKMTLock = %p\n", pCallbacks->pfnD3DKMTLock));
+        bSupported &= !!(pCallbacks->pfnD3DKMTLock);
+
+        pCallbacks->pfnD3DKMTUnlock = (PFND3DKMT_UNLOCK)GetProcAddress(pCallbacks->hGdi32, "D3DKMTUnlock");
+        LogFunc(("pfnD3DKMTUnlock = %p\n", pCallbacks->pfnD3DKMTUnlock));
+        bSupported &= !!(pCallbacks->pfnD3DKMTUnlock);
+
+        pCallbacks->pfnD3DKMTInvalidateActiveVidPn = (PFND3DKMT_INVALIDATEACTIVEVIDPN)GetProcAddress(pCallbacks->hGdi32, "D3DKMTInvalidateActiveVidPn");
+        LogFunc(("pfnD3DKMTInvalidateActiveVidPn = %p\n", pCallbacks->pfnD3DKMTInvalidateActiveVidPn));
+        bSupported &= !!(pCallbacks->pfnD3DKMTInvalidateActiveVidPn);
+
+        pCallbacks->pfnD3DKMTPollDisplayChildren = (PFND3DKMT_POLLDISPLAYCHILDREN)GetProcAddress(pCallbacks->hGdi32, "D3DKMTPollDisplayChildren");
+        LogFunc(("pfnD3DKMTPollDisplayChildren = %p\n", pCallbacks->pfnD3DKMTPollDisplayChildren));
+        bSupported &= !!(pCallbacks->pfnD3DKMTPollDisplayChildren);
+
+        pCallbacks->pfnD3DKMTEnumAdapters = (PFND3DKMT_ENUMADAPTERS)GetProcAddress(pCallbacks->hGdi32, "D3DKMTEnumAdapters");
+        LogFunc(("pfnD3DKMTEnumAdapters = %p\n", pCallbacks->pfnD3DKMTEnumAdapters));
+        /* this present starting win8 release preview only, so keep going if it is not available,
+         * i.e. do not clear the bSupported on its absence */
+        bSupportedWin8 &= !!(pCallbacks->pfnD3DKMTEnumAdapters);
+
+        pCallbacks->pfnD3DKMTOpenAdapterFromLuid = (PFND3DKMT_OPENADAPTERFROMLUID)GetProcAddress(pCallbacks->hGdi32, "D3DKMTOpenAdapterFromLuid");
+        LogFunc(("pfnD3DKMTOpenAdapterFromLuid = %p\n", pCallbacks->pfnD3DKMTOpenAdapterFromLuid));
+        /* this present starting win8 release preview only, so keep going if it is not available,
+         * i.e. do not clear the bSupported on its absence */
+        bSupportedWin8 &= !!(pCallbacks->pfnD3DKMTOpenAdapterFromLuid);
+
+        /*Assert(bSupported);*/
+        if (bSupported)
+        {
+            if (bSupportedWin8)
+                pCallbacks->enmVersion = VBOXDISPKMT_CALLBACKS_VERSION_WIN8;
+            else
+                pCallbacks->enmVersion = VBOXDISPKMT_CALLBACKS_VERSION_VISTA_WIN7;
+            return S_OK;
+        }
+        else
+        {
+            LogFunc(("one of pfnD3DKMT function pointers failed to initialize\n"));
+            hr = E_NOINTERFACE;
+        }
+
+        FreeLibrary(pCallbacks->hGdi32);
+    }
+    else
+    {
+        DWORD winEr = GetLastError();
+        hr = HRESULT_FROM_WIN32(winEr);
+        Assert(0);
+        Assert(hr != S_OK);
+        Assert(hr != S_FALSE);
+        if (hr == S_OK || hr == S_FALSE)
+            hr = E_FAIL;
+    }
+
+    return hr;
+}
+
+HRESULT vboxDispKmtCallbacksTerm(PVBOXDISPKMT_CALLBACKS pCallbacks)
+{
+    FreeLibrary(pCallbacks->hGdi32);
+#ifdef DEBUG_misha
+    memset(pCallbacks, 0, sizeof (*pCallbacks));
+#endif
+    return S_OK;
+}
+
+HRESULT vboxDispKmtAdpHdcCreate(HDC *phDc)
+{
+    HRESULT hr = E_FAIL;
+    DISPLAY_DEVICE DDev;
+    memset(&DDev, 0, sizeof (DDev));
+    DDev.cb = sizeof (DDev);
+
+    *phDc = NULL;
+
+    for (int i = 0; ; ++i)
+    {
+        if (EnumDisplayDevices(NULL, /* LPCTSTR lpDevice */ i, /* DWORD iDevNum */
+                &DDev, 0 /* DWORD dwFlags*/))
+        {
+            if (DDev.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
+            {
+                HDC hDc = CreateDC(NULL, DDev.DeviceName, NULL, NULL);
+                if (hDc)
+                {
+                    *phDc = hDc;
+                    return S_OK;
+                }
+                else
+                {
+                    DWORD winEr = GetLastError();
+                    Assert(0);
+                    hr = HRESULT_FROM_WIN32(winEr);
+                    Assert(FAILED(hr));
+                    break;
+                }
+            }
+        }
+        else
+        {
+            DWORD winEr = GetLastError();
+//            BP_WARN();
+            hr = HRESULT_FROM_WIN32(winEr);
+#ifdef DEBUG_misha
+            Assert(FAILED(hr));
+#endif
+            if (!FAILED(hr))
+            {
+                hr = E_FAIL;
+            }
+            break;
+        }
+    }
+
+    return hr;
+}
+
+static HRESULT vboxDispKmtOpenAdapterViaHdc(const VBOXDISPKMT_CALLBACKS *pCallbacks, PVBOXDISPKMT_ADAPTER pAdapter)
+{
+    D3DKMT_OPENADAPTERFROMHDC OpenAdapterData = {0};
+    HRESULT hr = vboxDispKmtAdpHdcCreate(&OpenAdapterData.hDc);
+    if (!SUCCEEDED(hr))
+        return hr;
+
+    Assert(OpenAdapterData.hDc);
+    NTSTATUS Status = pCallbacks->pfnD3DKMTOpenAdapterFromHdc(&OpenAdapterData);
+    if (NT_SUCCESS(Status))
+    {
+        pAdapter->hAdapter = OpenAdapterData.hAdapter;
+        pAdapter->hDc = OpenAdapterData.hDc;
+        pAdapter->pCallbacks = pCallbacks;
+        memset(&pAdapter->Luid, 0, sizeof (pAdapter->Luid));
+        return S_OK;
+    }
+    else
+    {
+        LogFunc(("pfnD3DKMTOpenAdapterFromGdiDisplayName failed, Status (0x%x)\n", Status));
+        hr = E_FAIL;
+    }
+
+    DeleteDC(OpenAdapterData.hDc);
+
+    return hr;
+}
+
+static HRESULT vboxDispKmtOpenAdapterViaLuid(const VBOXDISPKMT_CALLBACKS *pCallbacks, PVBOXDISPKMT_ADAPTER pAdapter)
+{
+    if (pCallbacks->enmVersion < VBOXDISPKMT_CALLBACKS_VERSION_WIN8)
+        return E_NOTIMPL;
+
+    D3DKMT_ENUMADAPTERS EnumAdapters = {0};
+    EnumAdapters.NumAdapters = RT_ELEMENTS(EnumAdapters.Adapters);
+
+    NTSTATUS Status = pCallbacks->pfnD3DKMTEnumAdapters(&EnumAdapters);
+#ifdef DEBUG_misha
+    Assert(!Status);
+#endif
+    if (!NT_SUCCESS(Status))
+        return E_FAIL;
+
+    Assert(EnumAdapters.NumAdapters);
+
+    /* try the same twice: if we fail to open the adapter containing present sources,
+     * try to open any adapter */
+    for (ULONG f = 0; f < 2; ++f)
+    {
+        for (ULONG i = 0; i < EnumAdapters.NumAdapters; ++i)
+        {
+            if (f || EnumAdapters.Adapters[i].NumOfSources)
+            {
+                D3DKMT_OPENADAPTERFROMLUID OpenAdapterData = {0};
+                OpenAdapterData.AdapterLuid = EnumAdapters.Adapters[i].AdapterLuid;
+                Status = pCallbacks->pfnD3DKMTOpenAdapterFromLuid(&OpenAdapterData);
+    #ifdef DEBUG_misha
+                Assert(!Status);
+    #endif
+                if (NT_SUCCESS(Status))
+                {
+                    pAdapter->hAdapter = OpenAdapterData.hAdapter;
+                    pAdapter->hDc = NULL;
+                    pAdapter->Luid = EnumAdapters.Adapters[i].AdapterLuid;
+                    pAdapter->pCallbacks = pCallbacks;
+                    return S_OK;
+                }
+            }
+        }
+    }
+
+#ifdef DEBUG_misha
+    Assert(0);
+#endif
+    return E_FAIL;
+}
+
+HRESULT vboxDispKmtOpenAdapter(const VBOXDISPKMT_CALLBACKS *pCallbacks, PVBOXDISPKMT_ADAPTER pAdapter)
+{
+    HRESULT hr = vboxDispKmtOpenAdapterViaHdc(pCallbacks, pAdapter);
+    if (SUCCEEDED(hr))
+        return S_OK;
+
+    hr = vboxDispKmtOpenAdapterViaLuid(pCallbacks, pAdapter);
+    if (SUCCEEDED(hr))
+        return S_OK;
+
+    return hr;
+}
+
+HRESULT vboxDispKmtCloseAdapter(PVBOXDISPKMT_ADAPTER pAdapter)
+{
+    D3DKMT_CLOSEADAPTER ClosaAdapterData = {0};
+    ClosaAdapterData.hAdapter = pAdapter->hAdapter;
+    NTSTATUS Status = pAdapter->pCallbacks->pfnD3DKMTCloseAdapter(&ClosaAdapterData);
+    Assert(!Status);
+    if (!Status)
+    {
+        DeleteDC(pAdapter->hDc);
+#ifdef DEBUG_misha
+        memset(pAdapter, 0, sizeof (*pAdapter));
+#endif
+        return S_OK;
+    }
+
+    LogFunc(("pfnD3DKMTCloseAdapter failed, Status (0x%x)\n", Status));
+
+    return E_FAIL;
+}
+
+HRESULT vboxDispKmtCreateDevice(PVBOXDISPKMT_ADAPTER pAdapter, PVBOXDISPKMT_DEVICE pDevice)
+{
+    D3DKMT_CREATEDEVICE CreateDeviceData = {0};
+    CreateDeviceData.hAdapter = pAdapter->hAdapter;
+    NTSTATUS Status = pAdapter->pCallbacks->pfnD3DKMTCreateDevice(&CreateDeviceData);
+    Assert(!Status);
+    if (!Status)
+    {
+        pDevice->pAdapter = pAdapter;
+        pDevice->hDevice = CreateDeviceData.hDevice;
+        pDevice->pCommandBuffer = CreateDeviceData.pCommandBuffer;
+        pDevice->CommandBufferSize = CreateDeviceData.CommandBufferSize;
+        pDevice->pAllocationList = CreateDeviceData.pAllocationList;
+        pDevice->AllocationListSize = CreateDeviceData.AllocationListSize;
+        pDevice->pPatchLocationList = CreateDeviceData.pPatchLocationList;
+        pDevice->PatchLocationListSize = CreateDeviceData.PatchLocationListSize;
+
+        return S_OK;
+    }
+
+    return E_FAIL;
+}
+
+HRESULT vboxDispKmtDestroyDevice(PVBOXDISPKMT_DEVICE pDevice)
+{
+    D3DKMT_DESTROYDEVICE DestroyDeviceData = {0};
+    DestroyDeviceData.hDevice = pDevice->hDevice;
+    NTSTATUS Status = pDevice->pAdapter->pCallbacks->pfnD3DKMTDestroyDevice(&DestroyDeviceData);
+    Assert(!Status);
+    if (!Status)
+    {
+#ifdef DEBUG_misha
+        memset(pDevice, 0, sizeof (*pDevice));
+#endif
+        return S_OK;
+    }
+    return E_FAIL;
+}
+
+HRESULT vboxDispKmtCreateContext(PVBOXDISPKMT_DEVICE pDevice, PVBOXDISPKMT_CONTEXT pContext,
+                                    VBOXWDDM_CONTEXT_TYPE enmType,
+                                    uint32_t crVersionMajor, uint32_t crVersionMinor,
+                                    HANDLE hEvent, uint64_t u64UmInfo)
+{
+    VBOXWDDM_CREATECONTEXT_INFO Info = {0};
+    Info.u32IfVersion = 9;
+    Info.enmType = enmType;
+    Info.crVersionMajor = crVersionMajor;
+    Info.crVersionMinor = crVersionMinor;
+    Info.hUmEvent = (uintptr_t)hEvent;
+    Info.u64UmInfo = u64UmInfo;
+    D3DKMT_CREATECONTEXT ContextData = {0};
+    ContextData.hDevice = pDevice->hDevice;
+    ContextData.NodeOrdinal = VBOXWDDM_NODE_ID_3D_KMT;
+    ContextData.EngineAffinity = VBOXWDDM_ENGINE_ID_3D_KMT;
+    ContextData.pPrivateDriverData = &Info;
+    ContextData.PrivateDriverDataSize = sizeof (Info);
+    ContextData.ClientHint = enmType == VBOXWDDM_CONTEXT_TYPE_CUSTOM_UHGSMI_GL ? D3DKMT_CLIENTHINT_OPENGL : D3DKMT_CLIENTHINT_DX9;
+    NTSTATUS Status = pDevice->pAdapter->pCallbacks->pfnD3DKMTCreateContext(&ContextData);
+    Assert(!Status);
+    if (!Status)
+    {
+        pContext->pDevice = pDevice;
+        pContext->hContext = ContextData.hContext;
+        pContext->pCommandBuffer = ContextData.pCommandBuffer;
+        pContext->CommandBufferSize = ContextData.CommandBufferSize;
+        pContext->pAllocationList = ContextData.pAllocationList;
+        pContext->AllocationListSize = ContextData.AllocationListSize;
+        pContext->pPatchLocationList = ContextData.pPatchLocationList;
+        pContext->PatchLocationListSize = ContextData.PatchLocationListSize;
+        return S_OK;
+    }
+    return E_FAIL;
+}
+
+HRESULT vboxDispKmtDestroyContext(PVBOXDISPKMT_CONTEXT pContext)
+{
+    D3DKMT_DESTROYCONTEXT DestroyContextData = {0};
+    DestroyContextData.hContext = pContext->hContext;
+    NTSTATUS Status = pContext->pDevice->pAdapter->pCallbacks->pfnD3DKMTDestroyContext(&DestroyContextData);
+    Assert(!Status);
+    if (!Status)
+    {
+#ifdef DEBUG_misha
+        memset(pContext, 0, sizeof (*pContext));
+#endif
+        return S_OK;
+    }
+    return E_FAIL;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispKmt.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispKmt.h	(revision 68261)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispKmt.h	(revision 68261)
@@ -0,0 +1,143 @@
+/* $Id$ */
+
+/** @file
+ * VBoxVideo Display D3D User mode dll
+ */
+
+/*
+ * Copyright (C) 2011-2016 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.
+ */
+
+#ifndef ___VBoxDispKmt_h__
+#define ___VBoxDispKmt_h__
+
+#include <D3dkmthk.h>
+
+#include <../../../common/wddm/VBoxMPIf.h>
+
+/* win8 release preview-specific stuff */
+typedef struct _D3DKMT_ADAPTERINFO
+{
+  D3DKMT_HANDLE hAdapter;
+  LUID          AdapterLuid;
+  ULONG         NumOfSources;
+  BOOL          bPresentMoveRegionsPreferred;
+} D3DKMT_ADAPTERINFO;
+
+#define MAX_ENUM_ADAPTERS 16
+
+typedef struct _D3DKMT_ENUMADAPTERS
+{
+  ULONG              NumAdapters;
+  D3DKMT_ADAPTERINFO Adapters[MAX_ENUM_ADAPTERS];
+} D3DKMT_ENUMADAPTERS;
+
+typedef NTSTATUS (APIENTRY *PFND3DKMT_ENUMADAPTERS)(IN OUT D3DKMT_ENUMADAPTERS*);
+
+typedef struct _D3DKMT_OPENADAPTERFROMLUID
+{
+  LUID          AdapterLuid;
+  D3DKMT_HANDLE hAdapter;
+} D3DKMT_OPENADAPTERFROMLUID;
+
+typedef NTSTATUS (APIENTRY *PFND3DKMT_OPENADAPTERFROMLUID)(IN OUT D3DKMT_OPENADAPTERFROMLUID*);
+/* END OF win8 release preview-specific stuff */
+
+typedef enum
+{
+    VBOXDISPKMT_CALLBACKS_VERSION_UNDEFINED = 0,
+    VBOXDISPKMT_CALLBACKS_VERSION_VISTA_WIN7,
+    VBOXDISPKMT_CALLBACKS_VERSION_WIN8
+} VBOXDISPKMT_CALLBACKS_VERSION;
+
+typedef struct VBOXDISPKMT_CALLBACKS
+{
+    HMODULE hGdi32;
+    VBOXDISPKMT_CALLBACKS_VERSION enmVersion;
+    /* open adapter */
+    PFND3DKMT_OPENADAPTERFROMHDC pfnD3DKMTOpenAdapterFromHdc;
+    PFND3DKMT_OPENADAPTERFROMGDIDISPLAYNAME pfnD3DKMTOpenAdapterFromGdiDisplayName;
+    /* close adapter */
+    PFND3DKMT_CLOSEADAPTER pfnD3DKMTCloseAdapter;
+    /* escape */
+    PFND3DKMT_ESCAPE pfnD3DKMTEscape;
+
+    PFND3DKMT_QUERYADAPTERINFO pfnD3DKMTQueryAdapterInfo;
+
+    PFND3DKMT_CREATEDEVICE pfnD3DKMTCreateDevice;
+    PFND3DKMT_DESTROYDEVICE pfnD3DKMTDestroyDevice;
+    PFND3DKMT_CREATECONTEXT pfnD3DKMTCreateContext;
+    PFND3DKMT_DESTROYCONTEXT pfnD3DKMTDestroyContext;
+
+    PFND3DKMT_RENDER pfnD3DKMTRender;
+
+    PFND3DKMT_CREATEALLOCATION pfnD3DKMTCreateAllocation;
+    PFND3DKMT_DESTROYALLOCATION pfnD3DKMTDestroyAllocation;
+
+    PFND3DKMT_LOCK pfnD3DKMTLock;
+    PFND3DKMT_UNLOCK pfnD3DKMTUnlock;
+
+    /* auto resize support */
+    PFND3DKMT_INVALIDATEACTIVEVIDPN pfnD3DKMTInvalidateActiveVidPn;
+    PFND3DKMT_POLLDISPLAYCHILDREN pfnD3DKMTPollDisplayChildren;
+
+    /* win8 specifics */
+    PFND3DKMT_ENUMADAPTERS pfnD3DKMTEnumAdapters;
+    PFND3DKMT_OPENADAPTERFROMLUID pfnD3DKMTOpenAdapterFromLuid;
+} VBOXDISPKMT_CALLBACKS, *PVBOXDISPKMT_CALLBACKS;
+
+typedef struct VBOXDISPKMT_ADAPTER
+{
+    D3DKMT_HANDLE hAdapter;
+    HDC hDc;
+    LUID Luid;
+    const VBOXDISPKMT_CALLBACKS *pCallbacks;
+}VBOXDISPKMT_ADAPTER, *PVBOXDISPKMT_ADAPTER;
+
+typedef struct VBOXDISPKMT_DEVICE
+{
+    struct VBOXDISPKMT_ADAPTER *pAdapter;
+    D3DKMT_HANDLE hDevice;
+    VOID *pCommandBuffer;
+    UINT CommandBufferSize;
+    D3DDDI_ALLOCATIONLIST *pAllocationList;
+    UINT AllocationListSize;
+    D3DDDI_PATCHLOCATIONLIST *pPatchLocationList;
+    UINT PatchLocationListSize;
+}VBOXDISPKMT_DEVICE, *PVBOXDISPKMT_DEVICE;
+
+typedef struct VBOXDISPKMT_CONTEXT
+{
+    struct VBOXDISPKMT_DEVICE *pDevice;
+    D3DKMT_HANDLE hContext;
+    VOID *pCommandBuffer;
+    UINT CommandBufferSize;
+    D3DDDI_ALLOCATIONLIST *pAllocationList;
+    UINT AllocationListSize;
+    D3DDDI_PATCHLOCATIONLIST *pPatchLocationList;
+    UINT PatchLocationListSize;
+} VBOXDISPKMT_CONTEXT, *PVBOXDISPKMT_CONTEXT;
+
+HRESULT vboxDispKmtCallbacksInit(PVBOXDISPKMT_CALLBACKS pCallbacks);
+HRESULT vboxDispKmtCallbacksTerm(PVBOXDISPKMT_CALLBACKS pCallbacks);
+
+HRESULT vboxDispKmtOpenAdapter(const VBOXDISPKMT_CALLBACKS *pCallbacks, PVBOXDISPKMT_ADAPTER pAdapter);
+HRESULT vboxDispKmtCloseAdapter(PVBOXDISPKMT_ADAPTER pAdapter);
+HRESULT vboxDispKmtCreateDevice(PVBOXDISPKMT_ADAPTER pAdapter, PVBOXDISPKMT_DEVICE pDevice);
+HRESULT vboxDispKmtDestroyDevice(PVBOXDISPKMT_DEVICE pDevice);
+HRESULT vboxDispKmtCreateContext(PVBOXDISPKMT_DEVICE pDevice, PVBOXDISPKMT_CONTEXT pContext,
+        VBOXWDDM_CONTEXT_TYPE enmType,
+        uint32_t crVersionMajor, uint32_t crVersionMinor,
+        HANDLE hEvent, uint64_t u64UmInfo);
+HRESULT vboxDispKmtDestroyContext(PVBOXDISPKMT_CONTEXT pContext);
+
+
+#endif /* #ifndef ___VBoxDispKmt_h__ */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispMpLogger.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispMpLogger.cpp	(revision 68261)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispMpLogger.cpp	(revision 68261)
@@ -0,0 +1,244 @@
+/* $Id$ */
+
+/** @file
+ * VBox WDDM Display backdoor logger implementation
+ */
+
+/*
+ * Copyright (C) 2012-2016 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 <iprt/win/windows.h>
+#       pragma warning(default : 4163)
+#       undef  _InterlockedExchange
+#       undef  _InterlockedExchangeAdd
+#       undef  _InterlockedCompareExchange
+#       undef  _InterlockedAddLargeStatistic
+#       undef  _interlockedbittestandset
+#       undef  _interlockedbittestandreset
+#       undef  _interlockedbittestandset64
+#       undef  _interlockedbittestandreset64
+#   else
+#       include <iprt/win/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/err.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(void)
+{
+    PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
+    if (!pLogger)
+        return VERR_NOT_SUPPORTED;
+    return VINF_SUCCESS;
+}
+
+VBOXDISPMPLOGGER_DECL(int) VBoxDispMpLoggerTerm(void)
+{
+    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(const char *pszString)
+{
+    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(pszString) + 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, pszString, 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(const char *pszString, ...)
+{
+    PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
+    if (!pLogger)
+        return;
+
+    char szBuffer[4096] = {0};
+    va_list pArgList;
+    va_start(pArgList, pszString);
+    _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), pszString, 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/shared/VBoxDispMpLogger.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispMpLogger.h	(revision 68261)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispMpLogger.h	(revision 68261)
@@ -0,0 +1,53 @@
+/* $Id$ */
+/** @file
+ * VBox WDDM Display backdoor logger API
+ */
+
+/*
+ * Copyright (C) 2012-2016 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(void);
+
+VBOXDISPMPLOGGER_DECL(int) VBoxDispMpLoggerTerm(void);
+
+VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLog(const char *pszString);
+
+VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLogF(const char *pszString, ...);
+
+RT_C_DECLS_END
+
+#endif /* #ifndef ___VBoxDispMpLogger_h__ */
+
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/Makefile.kmk	(revision 68260)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/Makefile.kmk	(revision 68261)
@@ -260,8 +260,10 @@
 endif
  wined3dwddm_INCS           = $(wined3d_INCS) \
+ 	$(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared \
  	$(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm
  wined3dwddm_SOURCES        = $(subst wined3d.def,wined3dwddm.def,$(subst wined3dxpdm.rc,wined3dwddm.rc,$(wined3d_SOURCES)))
  wined3dwddm_LIBS           = $(wined3d_LIBS) \
  	$(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger$(VBOX_SUFF_LIB) \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt$(VBOX_SUFF_LIB) \
  	$(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi$(VBOX_SUFF_LIB)
 
@@ -277,4 +279,5 @@
  	$(VBOX_LIB_VBGL_R3_X86) \
  	$(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger-x86$(VBOX_SUFF_LIB) \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt-x86$(VBOX_SUFF_LIB) \
  	$(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi-x86$(VBOX_SUFF_LIB) \
  	$(PATH_STAGE_LIB)/VBoxOGL-x86$(VBOX_SUFF_LIB)
@@ -367,4 +370,5 @@
  endif
  VBoxD3D9wddm_INCS     = $(VBoxD3D9_INCS) \
+ 	$(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared \
  	$(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm
  VBoxD3D9wddm_DEFS    += $(VBoxD3D9_DEFS) \
@@ -376,4 +380,5 @@
  	$(subst $(PATH_STAGE_LIB)/wined3d$(VBOX_SUFF_LIB),$(PATH_STAGE_LIB)/wined3dwddm$(VBOX_SUFF_LIB),$(VBoxD3D9_LIBS)) \
  	$(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger$(VBOX_SUFF_LIB) \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt$(VBOX_SUFF_LIB) \
  	$(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi$(VBOX_SUFF_LIB)
 
@@ -391,4 +396,5 @@
  VBoxD3D9wddm-x86_LIBS        += \
   	$(VBOX_PATH_ADDITIONS_LIB)/VBoxDispMpLogger-x86$(VBOX_SUFF_LIB) \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt-x86$(VBOX_SUFF_LIB) \
  	$(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi-x86$(VBOX_SUFF_LIB)
 endif # VBOX_WITH_WDDM
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk	(revision 68260)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/Makefile.kmk	(revision 68261)
@@ -29,5 +29,8 @@
 	VBOX_WITH_HGCM \
 	VBOX_BUILD_TARGET=\"$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)\"
-VBoxTray_INCS     = ../include $(VBOX_GRAPHICS_INCS)
+VBoxTray_INCS     = \
+	../include \
+	$(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared \
+	$(VBOX_GRAPHICS_INCS)
 VBoxTray_SOURCES  = \
 	VBoxTray.cpp \
@@ -69,5 +72,5 @@
  VBoxTray_DEFS   += VBOX_WITH_WDDM
  # VBoxTray_DEFS   += LOG_ENABLED
- VBoxTray_SOURCES += ../Graphics/Video/disp/wddm/VBoxDispKmt.cpp
+ VBoxTray_SOURCES += $(PATH_ROOT)/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispKmt.cpp
 endif
 
Index: /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.h	(revision 68260)
+++ /trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDispIf.h	(revision 68261)
@@ -20,5 +20,5 @@
 # define D3DKMDT_SPECIAL_MULTIPLATFORM_TOOL
 # include <d3dkmthk.h>
-# include "../Graphics/Video/disp/wddm/VBoxDispKmt.h"
+# include <VBoxDispKmt.h>
 #endif
 
Index: /trunk/src/VBox/Additions/common/crOpenGL/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/common/crOpenGL/Makefile.kmk	(revision 68260)
+++ /trunk/src/VBox/Additions/common/crOpenGL/Makefile.kmk	(revision 68261)
@@ -212,4 +212,5 @@
 VBoxOGL_LIBS.win += \
 	$(PATH_STAGE_LIB)/additions/VBoxDispMpLogger$(VBOX_SUFF_LIB) \
+	$(PATH_STAGE_LIB)/additions/VBoxWddmUmKmt$(VBOX_SUFF_LIB) \
 	$(PATH_STAGE_LIB)/additions/VBoxCrHgsmi$(VBOX_SUFF_LIB)
 
@@ -259,4 +260,5 @@
 VBoxOGL-x86_LIBS.win += \
 	$(PATH_STAGE_LIB)/additions/VBoxDispMpLogger-x86$(VBOX_SUFF_LIB) \
+	$(PATH_STAGE_LIB)/additions/VBoxWddmUmKmt-x86$(VBOX_SUFF_LIB) \
 	$(PATH_STAGE_LIB)/additions/VBoxCrHgsmi-x86$(VBOX_SUFF_LIB)
 
@@ -595,4 +597,5 @@
 VBoxOGLpackspu_LIBS.win += \
 	$(PATH_STAGE_LIB)/additions/VBoxDispMpLogger$(VBOX_SUFF_LIB) \
+	$(PATH_STAGE_LIB)/additions/VBoxWddmUmKmt$(VBOX_SUFF_LIB) \
 	$(PATH_STAGE_LIB)/additions/VBoxCrHgsmi$(VBOX_SUFF_LIB)
 
@@ -622,4 +625,5 @@
 VBoxOGLpackspu-x86_LIBS.win += \
 	$(PATH_STAGE_LIB)/additions/VBoxDispMpLogger-x86$(VBOX_SUFF_LIB) \
+	$(PATH_STAGE_LIB)/additions/VBoxWddmUmKmt-x86$(VBOX_SUFF_LIB) \
 	$(PATH_STAGE_LIB)/additions/VBoxCrHgsmi-x86$(VBOX_SUFF_LIB)
 VBoxOGLpackspu-x86_DEFS = $(VBoxOGLpackspu_DEFS) VBOX_WDDM_WOW64
Index: /trunk/src/VBox/GuestHost/OpenGL/Makefile.kmk
===================================================================
--- /trunk/src/VBox/GuestHost/OpenGL/Makefile.kmk	(revision 68260)
+++ /trunk/src/VBox/GuestHost/OpenGL/Makefile.kmk	(revision 68261)
@@ -110,5 +110,7 @@
 ifdef VBOX_WITH_CRHGSMI
 VBoxOGLcrutil_DEFS.win    += VBOX_WITH_CRHGSMI
-VBoxOGLcrutil_LIBS.win    += $(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi$(VBOX_SUFF_LIB)
+VBoxOGLcrutil_LIBS.win    += \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt$(VBOX_SUFF_LIB) \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi$(VBOX_SUFF_LIB)
 endif
 ifdef VBOX_WITH_WDDM
@@ -143,5 +145,7 @@
 ifdef VBOX_WITH_CRHGSMI
 # VBOX_WITH_CRHGSMI define is inherited from VBoxOGLcrutil
-VBoxOGLcrutil-x86_LIBS.win    += $(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi-x86$(VBOX_SUFF_LIB)
+VBoxOGLcrutil-x86_LIBS.win    += \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxWddmUmKmt-x86$(VBOX_SUFF_LIB) \
+	$(VBOX_PATH_ADDITIONS_LIB)/VBoxCrHgsmi-x86$(VBOX_SUFF_LIB)
 endif
 VBoxOGLcrutil-x86_DEFS = $(VBoxOGLcrutil_DEFS) VBOX_WDDM_WOW64
