VBoxDispMpLogger.cpp revision 384478d3896257fbce9ceb8c01e74040b969e6d7
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * VBox WDDM Display backdoor logger implementation
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * Copyright (C) 2012 Oracle Corporation
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * available from http://www.virtualbox.org. This file is free software;
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * General Public License (GPL) as published by the Free Software
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync/* We're unable to use standard r3 vbgl-based backdoor logging API because win8 Metro apps
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * can not do CreateFile/Read/Write by default
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * this is why we use miniport escape functionality to issue backdoor log string to the miniport
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * and submit it to host via standard r0 backdoor logging api accordingly */
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync# if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync# define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync# define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync# define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync# define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync# define _interlockedbittestandset _interlockedbittestandset_StupidDDKVsCompilerCrap
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync# define _interlockedbittestandreset _interlockedbittestandreset_StupidDDKVsCompilerCrap
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync# define _interlockedbittestandset64 _interlockedbittestandset64_StupidDDKVsCompilerCrap
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync# define _interlockedbittestandreset64 _interlockedbittestandreset64_StupidDDKVsCompilerCrap
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync#include "../../common/wddm/VBoxMPIf.h"
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsynctypedef enum
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync if (ASMAtomicCmpXchgU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_INITIALIZING, VBOXDISPMPLOGGER_STATE_UNINITIALIZED))
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync HRESULT hr = vboxDispKmtCallbacksInit(&g_VBoxDispMpLogger.KmtCallbacks);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync /* we are on Vista+
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync * check if we can Open Adapter, i.e. WDDM driver is installed */
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync hr = vboxDispKmtOpenAdapter(&g_VBoxDispMpLogger.KmtCallbacks, &Adapter);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync ASMAtomicWriteU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_INITIALIZED);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync vboxDispKmtCallbacksTerm(&g_VBoxDispMpLogger.KmtCallbacks);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync else if (ASMAtomicReadU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState) == VBOXDISPMPLOGGER_STATE_INITIALIZED)
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync if (ASMAtomicCmpXchgU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_UNINITIALIZING, VBOXDISPMPLOGGER_STATE_INITIALIZED))
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync vboxDispKmtCallbacksTerm(&g_VBoxDispMpLogger.KmtCallbacks);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync ASMAtomicWriteU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_UNINITIALIZED);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync else if (ASMAtomicReadU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState) == VBOXDISPMPLOGGER_STATE_UNINITIALIZED)
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsyncVBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLog(char * szString)
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync HRESULT hr = vboxDispKmtOpenAdapter(&pLogger->KmtCallbacks, &Adapter);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync uint32_t cbString = (uint32_t)strlen(szString) + 1;
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGPRINT, aStringBuf[cbString]);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync PVBOXDISPIFESCAPE_DBGPRINT pCmd = (PVBOXDISPIFESCAPE_DBGPRINT)RTMemAllocZ(cbCmd);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync //EscapeData.hDevice = NULL;
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync // EscapeData.Flags.HardwareAccess = 1;
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync //EscapeData.hContext = NULL;
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync int Status = pLogger->KmtCallbacks.pfnD3DKMTEscape(&EscapeData);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsyncVBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLogF(char * szString, ...)
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), szString, pArgList);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsyncstatic void vboxDispMpLoggerDumpBuf(void *pvBuf, uint32_t cbBuf, VBOXDISPIFESCAPE_DBGDUMPBUF_TYPE enmBuf)
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync HRESULT hr = vboxDispKmtOpenAdapter(&pLogger->KmtCallbacks, &Adapter);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGDUMPBUF, aBuf[cbBuf]);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync PVBOXDISPIFESCAPE_DBGDUMPBUF pCmd = (PVBOXDISPIFESCAPE_DBGDUMPBUF)RTMemAllocZ(cbCmd);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync //EscapeData.hDevice = NULL;
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync // EscapeData.Flags.HardwareAccess = 1;
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync //EscapeData.hContext = NULL;
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsync int Status = pLogger->KmtCallbacks.pfnD3DKMTEscape(&EscapeData);
384478d3896257fbce9ceb8c01e74040b969e6d7vboxsyncVBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerDumpD3DCAPS9(struct _D3DCAPS9 *pCaps)