VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispMpLogger.cpp@ 46606

Last change on this file since 46606 was 41374, checked in by vboxsync, 13 years ago

wddm/3d/crogl: backdoor logging

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1/* $Id: VBoxDispMpLogger.cpp 41374 2012-05-21 18:04:03Z vboxsync $ */
2
3/** @file
4 * VBox WDDM Display backdoor logger implementation
5 */
6
7/*
8 * Copyright (C) 2012 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19/* We're unable to use standard r3 vbgl-based backdoor logging API because win8 Metro apps
20 * can not do CreateFile/Read/Write by default
21 * this is why we use miniport escape functionality to issue backdoor log string to the miniport
22 * and submit it to host via standard r0 backdoor logging api accordingly */
23# if (_MSC_VER >= 1400) && !defined(VBOX_WITH_PATCHED_DDK)
24# define _InterlockedExchange _InterlockedExchange_StupidDDKVsCompilerCrap
25# define _InterlockedExchangeAdd _InterlockedExchangeAdd_StupidDDKVsCompilerCrap
26# define _InterlockedCompareExchange _InterlockedCompareExchange_StupidDDKVsCompilerCrap
27# define _InterlockedAddLargeStatistic _InterlockedAddLargeStatistic_StupidDDKVsCompilerCrap
28# define _interlockedbittestandset _interlockedbittestandset_StupidDDKVsCompilerCrap
29# define _interlockedbittestandreset _interlockedbittestandreset_StupidDDKVsCompilerCrap
30# define _interlockedbittestandset64 _interlockedbittestandset64_StupidDDKVsCompilerCrap
31# define _interlockedbittestandreset64 _interlockedbittestandreset64_StupidDDKVsCompilerCrap
32# pragma warning(disable : 4163)
33# include <windows.h>
34# pragma warning(default : 4163)
35# undef _InterlockedExchange
36# undef _InterlockedExchangeAdd
37# undef _InterlockedCompareExchange
38# undef _InterlockedAddLargeStatistic
39# undef _interlockedbittestandset
40# undef _interlockedbittestandreset
41# undef _interlockedbittestandset64
42# undef _interlockedbittestandreset64
43# else
44# include <windows.h>
45# endif
46#include "VBoxDispMpLogger.h"
47#include <d3d9types.h>
48#include <D3dumddi.h>
49#include <d3dhal.h>
50#include "../../common/wddm/VBoxMPIf.h"
51#include "VBoxDispKmt.h"
52
53#define VBOX_VIDEO_LOG_NAME "VBoxDispMpLogger"
54#include <common/VBoxVideoLog.h>
55
56#include <iprt/asm.h>
57#include <iprt/assert.h>
58#include <iprt/mem.h>
59
60#include <stdio.h>
61
62typedef enum
63{
64 VBOXDISPMPLOGGER_STATE_UNINITIALIZED = 0,
65 VBOXDISPMPLOGGER_STATE_INITIALIZING,
66 VBOXDISPMPLOGGER_STATE_INITIALIZED,
67 VBOXDISPMPLOGGER_STATE_UNINITIALIZING
68} VBOXDISPMPLOGGER_STATE;
69
70typedef struct VBOXDISPMPLOGGER
71{
72 VBOXDISPKMT_CALLBACKS KmtCallbacks;
73 VBOXDISPMPLOGGER_STATE enmState;
74} VBOXDISPMPLOGGER, *PVBOXDISPMPLOGGER;
75
76static VBOXDISPMPLOGGER g_VBoxDispMpLogger = {0};
77
78static PVBOXDISPMPLOGGER vboxDispMpLoggerGet()
79{
80 if (ASMAtomicCmpXchgU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_INITIALIZING, VBOXDISPMPLOGGER_STATE_UNINITIALIZED))
81 {
82 HRESULT hr = vboxDispKmtCallbacksInit(&g_VBoxDispMpLogger.KmtCallbacks);
83 if (hr == S_OK)
84 {
85 /* we are on Vista+
86 * check if we can Open Adapter, i.e. WDDM driver is installed */
87 VBOXDISPKMT_ADAPTER Adapter;
88 hr = vboxDispKmtOpenAdapter(&g_VBoxDispMpLogger.KmtCallbacks, &Adapter);
89 if (hr == S_OK)
90 {
91 ASMAtomicWriteU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_INITIALIZED);
92 vboxDispKmtCloseAdapter(&Adapter);
93 return &g_VBoxDispMpLogger;
94 }
95 vboxDispKmtCallbacksTerm(&g_VBoxDispMpLogger.KmtCallbacks);
96 }
97 }
98 else if (ASMAtomicReadU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState) == VBOXDISPMPLOGGER_STATE_INITIALIZED)
99 {
100 return &g_VBoxDispMpLogger;
101 }
102 return NULL;
103}
104
105VBOXDISPMPLOGGER_DECL(int) VBoxDispMpLoggerInit()
106{
107 PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
108 if (!pLogger)
109 return VERR_NOT_SUPPORTED;
110 return VINF_SUCCESS;
111}
112
113VBOXDISPMPLOGGER_DECL(int) VBoxDispMpLoggerTerm()
114{
115 if (ASMAtomicCmpXchgU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_UNINITIALIZING, VBOXDISPMPLOGGER_STATE_INITIALIZED))
116 {
117 vboxDispKmtCallbacksTerm(&g_VBoxDispMpLogger.KmtCallbacks);
118 ASMAtomicWriteU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState, VBOXDISPMPLOGGER_STATE_UNINITIALIZED);
119 return S_OK;
120 }
121 else if (ASMAtomicReadU32((volatile uint32_t *)&g_VBoxDispMpLogger.enmState) == VBOXDISPMPLOGGER_STATE_UNINITIALIZED)
122 {
123 return S_OK;
124 }
125 return VERR_NOT_SUPPORTED;
126}
127
128VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLog(char * szString)
129{
130 PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
131 if (!pLogger)
132 return;
133
134 VBOXDISPKMT_ADAPTER Adapter;
135 HRESULT hr = vboxDispKmtOpenAdapter(&pLogger->KmtCallbacks, &Adapter);
136 if (hr == S_OK)
137 {
138 uint32_t cbString = (uint32_t)strlen(szString) + 1;
139 uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGPRINT, aStringBuf[cbString]);
140 PVBOXDISPIFESCAPE_DBGPRINT pCmd = (PVBOXDISPIFESCAPE_DBGPRINT)RTMemAllocZ(cbCmd);
141 if (pCmd)
142 {
143 pCmd->EscapeHdr.escapeCode = VBOXESC_DBGPRINT;
144 memcpy(pCmd->aStringBuf, szString, cbString);
145
146 D3DKMT_ESCAPE EscapeData = {0};
147 EscapeData.hAdapter = Adapter.hAdapter;
148 //EscapeData.hDevice = NULL;
149 EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
150 // EscapeData.Flags.HardwareAccess = 1;
151 EscapeData.pPrivateDriverData = pCmd;
152 EscapeData.PrivateDriverDataSize = cbCmd;
153 //EscapeData.hContext = NULL;
154
155 int Status = pLogger->KmtCallbacks.pfnD3DKMTEscape(&EscapeData);
156 if (Status)
157 {
158 BP_WARN();
159 }
160
161 RTMemFree(pCmd);
162 }
163 else
164 {
165 BP_WARN();
166 }
167 hr = vboxDispKmtCloseAdapter(&Adapter);
168 if(hr != S_OK)
169 {
170 BP_WARN();
171 }
172 }
173}
174
175VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLogF(char * szString, ...)
176{
177 PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
178 if (!pLogger)
179 return;
180
181 char szBuffer[4096] = {0};
182 va_list pArgList;
183 va_start(pArgList, szString);
184 _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), szString, pArgList);
185 va_end(pArgList);
186
187 VBoxDispMpLoggerLog(szBuffer);
188}
189
190static void vboxDispMpLoggerDumpBuf(void *pvBuf, uint32_t cbBuf, VBOXDISPIFESCAPE_DBGDUMPBUF_TYPE enmBuf)
191{
192 PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet();
193 if (!pLogger)
194 return;
195
196 VBOXDISPKMT_ADAPTER Adapter;
197 HRESULT hr = vboxDispKmtOpenAdapter(&pLogger->KmtCallbacks, &Adapter);
198 if (hr == S_OK)
199 {
200 uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGDUMPBUF, aBuf[cbBuf]);
201 PVBOXDISPIFESCAPE_DBGDUMPBUF pCmd = (PVBOXDISPIFESCAPE_DBGDUMPBUF)RTMemAllocZ(cbCmd);
202 if (pCmd)
203 {
204 pCmd->EscapeHdr.escapeCode = VBOXESC_DBGDUMPBUF;
205 pCmd->enmType = enmBuf;
206#ifdef VBOX_WDDM_WOW64
207 pCmd->Flags.WoW64 = 1;
208#endif
209 memcpy(pCmd->aBuf, pvBuf, cbBuf);
210
211 D3DKMT_ESCAPE EscapeData = {0};
212 EscapeData.hAdapter = Adapter.hAdapter;
213 //EscapeData.hDevice = NULL;
214 EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
215 // EscapeData.Flags.HardwareAccess = 1;
216 EscapeData.pPrivateDriverData = pCmd;
217 EscapeData.PrivateDriverDataSize = cbCmd;
218 //EscapeData.hContext = NULL;
219
220 int Status = pLogger->KmtCallbacks.pfnD3DKMTEscape(&EscapeData);
221 if (Status)
222 {
223 BP_WARN();
224 }
225
226 RTMemFree(pCmd);
227 }
228 else
229 {
230 BP_WARN();
231 }
232 hr = vboxDispKmtCloseAdapter(&Adapter);
233 if(hr != S_OK)
234 {
235 BP_WARN();
236 }
237 }
238}
239
240VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerDumpD3DCAPS9(struct _D3DCAPS9 *pCaps)
241{
242 vboxDispMpLoggerDumpBuf(pCaps, sizeof (*pCaps), VBOXDISPIFESCAPE_DBGDUMPBUF_TYPE_D3DCAPS9);
243}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette