Changeset 95955 in vbox for trunk/src/VBox/Additions/WINNT
- Timestamp:
- Jul 29, 2022 8:52:37 PM (3 years ago)
- Location:
- trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.cpp
r93115 r95955 19 19 20 20 #ifdef VBOXWDDMDISP_DEBUG_VEHANDLER 21 #include <Psapi.h> 22 #endif 23 24 #include <stdio.h> 25 #include <stdarg.h> 21 # include <Psapi.h> 22 #endif 26 23 27 24 #include <iprt/asm.h> 28 25 #include <iprt/assert.h> 29 30 static DWORD g_VBoxVDbgFIsModuleNameInited = 0; 31 static char g_VBoxVDbgModuleName[MAX_PATH]; 32 33 char *vboxVDbgDoGetModuleName() 34 { 35 if (!g_VBoxVDbgFIsModuleNameInited) 36 { 37 DWORD cName = GetModuleFileNameA(NULL, g_VBoxVDbgModuleName, RT_ELEMENTS(g_VBoxVDbgModuleName)); 26 #include <iprt/process.h> 27 #include <iprt/string.h> 28 29 #ifndef IPRT_NO_CRT 30 # include <stdio.h> 31 #endif 32 33 34 #if defined(VBOXWDDMDISP_DEBUG) || defined(LOG_TO_BACKDOOR_DRV) 35 static const char *vboxVDbgDoGetExeName(void) 36 { 37 # ifdef IPRT_NO_CRT 38 /** @todo use RTProcShortName instead? */ 39 return RTProcExecutablePath(); /* should've been initialized by nocrt-startup-dll-win.cpp already */ 40 # else 41 static bool volatile s_fInitialized = false; 42 static char s_szExePath[MAX_PATH]; 43 if (!s_fInitialized) 44 { 45 DWORD cName = GetModuleFileNameA(NULL, s_szExePath, RT_ELEMENTS(s_szExePath)); 38 46 if (!cName) 39 47 { 40 # ifdef LOG_ENABLED48 # ifdef LOG_ENABLED 41 49 DWORD winEr = GetLastError(); 42 # endif50 # endif 43 51 WARN(("GetModuleFileNameA failed, winEr %d", winEr)); 44 52 return NULL; 45 53 } 46 g_VBoxVDbgFIsModuleNameInited = TRUE; 47 } 48 return g_VBoxVDbgModuleName; 49 } 50 51 static void vboxDispLogDbgFormatStringV(char * szBuffer, uint32_t cbBuffer, const char * szString, va_list pArgList) 52 { 53 uint32_t cbWritten = sprintf(szBuffer, "['%s' 0x%lx.0x%lx] Disp: ", vboxVDbgDoGetModuleName(), GetCurrentProcessId(), GetCurrentThreadId()); 54 if (cbWritten > cbBuffer) 55 { 56 AssertReleaseFailed(); 57 return; 58 } 59 60 _vsnprintf(szBuffer + cbWritten, cbBuffer - cbWritten, szString, pArgList); 61 } 62 54 s_fInitialized = TRUE; 55 } 56 return s_szExePath; 57 #endif /* !IPRT_NO_CRT */ 58 } 59 60 static void vboxDispLogDbgFormatStringV(char *pszBuffer, uint32_t cbBuffer, const char *pszFormat, va_list va) 61 { 62 # ifdef IPRT_NO_CRT 63 va_list vaCopy; 64 va_copy(vaCopy, va); /* The &va for a %N must not be taken from an parameter list, so copy it onto the stack. */ 65 RTStrPrintf(pszBuffer, cbBuffer, "['%s' 0x%lx.0x%lx] Disp: %N", 66 vboxVDbgDoGetExeName(), GetCurrentProcessId(), GetCurrentThreadId(), pszFormat, &vaCopy); 67 va_end(vaCopy); 68 # else 69 int cch = _snprintf(pszBuffer, cbBuffer, "['%s' 0x%lx.0x%lx] Disp: ", 70 vboxVDbgDoGetExeName(), GetCurrentProcessId(), GetCurrentThreadId()); 71 AssertReturnVoid(cch > 0); 72 AssertReturnVoid((unsigned)cch + 2 <= cbBuffer); 73 cbBuffer -= (unsigned)cch; 74 pszBuffer += (unsigned)cch; 75 76 cch = _vsnprintf(pszBuffer, cbBuffer, pszFormat, va); 77 pszBuffer[cbBuffer - 1] = '\0'; /* Don't trust _vsnprintf to terminate the output. */ 78 # endif 79 } 80 81 #endif /* VBOXWDDMDISP_DEBUG || LOG_TO_BACKDOOR_DRV */ 63 82 #if defined(VBOXWDDMDISP_DEBUG) 64 83 LONG g_VBoxVDbgFIsDwm = -1; … … 108 127 PVBOXWDDMDISP_RESOURCE g_VBoxVDbgInternalRc = NULL; 109 128 110 VOID vboxVDbgDoPrintDmlCmd(const char* pszDesc, const char* pszCmd) 111 { 129 VOID vboxVDbgDoPrintDmlCmd(const char *pszDesc, const char *pszCmd) 130 { 131 #ifdef IPRT_NO_CRT 132 /* DML isn't exactly following XML rules, docs + examples are not consistent 133 about escaping sequences even. But assume it groks the typical XML 134 escape sequences for now. */ 135 vboxVDbgPrint(("<?dml?><exec cmd=\"%RMas\">%RMes</exec>, ( %s )\n", pszCmd, pszDesc, pszCmd)); /** @todo escape the last pszCmd too? */ 136 #else 112 137 vboxVDbgPrint(("<?dml?><exec cmd=\"%s\">%s</exec>, ( %s )\n", pszCmd, pszDesc, pszCmd)); 138 #endif 113 139 } 114 140 115 141 VOID vboxVDbgDoPrintDumpCmd(const char* pszDesc, const void *pvData, uint32_t width, uint32_t height, uint32_t bpp, uint32_t pitch) 116 142 { 117 char Cmd[1024]; 118 sprintf(Cmd, "!vbvdbg.ms 0x%p 0n%d 0n%d 0n%d 0n%d", pvData, width, height, bpp, pitch); 119 vboxVDbgDoPrintDmlCmd(pszDesc, Cmd); 143 char szCmd[1024]; 144 #ifdef IPRT_NO_CRT 145 RTStrPrintf(szCmd, sizeof(szCmd), "!vbvdbg.ms 0x%p 0n%d 0n%d 0n%d 0n%d", pvData, width, height, bpp, pitch); 146 #else 147 _snprintf(szCmd, sizeof(szCmd), "!vbvdbg.ms 0x%p 0n%d 0n%d 0n%d 0n%d", pvData, width, height, bpp, pitch); 148 szCmd[sizeof(szCmd) - 1] = '\0'; 149 #endif 150 vboxVDbgDoPrintDmlCmd(pszDesc, szCmd); 120 151 } 121 152 … … 140 171 const VBOXWDDMDISP_ALLOCATION *pAlloc = pInfo->pAlloc; 141 172 IDirect3DResource9 *pD3DRc = pInfo->pD3DRc; 142 char rectBuf[24]; 143 if (pInfo->pRect) 144 _snprintf(rectBuf, sizeof(rectBuf) / sizeof(rectBuf[0]), "(%ld:%ld);(%ld:%ld)", 145 pInfo->pRect->left, pInfo->pRect->top, 146 pInfo->pRect->right, pInfo->pRect->bottom); 173 const RECT * const pRect = pInfo->pRect; 174 char szRectBuf[24]; 175 if (pRect) 176 #ifdef IPRT_NO_CRT 177 RTStrPrintf(szRectBuf, sizeof(szRectBuf), "(%ld:%ld);(%ld:%ld)", pRect->left, pRect->top, pRect->right, pRect->bottom); 178 #else 179 _snprintf(szRectBuf, sizeof(szRectBuf), "(%ld:%ld);(%ld:%ld)", pRect->left, pRect->top, pRect->right, pRect->bottom); 180 #endif 147 181 else 148 strcpy( rectBuf, "n/a");182 strcpy(szRectBuf, "n/a"); 149 183 150 184 vboxVDbgPrint(("%s Sh(0x%p), Rc(0x%p), pAlloc(0x%x), pD3DIf(0x%p), Type(%s), Rect(%s), Locks(%d) %s", … … 155 189 pD3DRc, 156 190 pD3DRc ? vboxDispLogD3DRcType(pD3DRc->GetType()) : "n/a", 157 rectBuf,191 szRectBuf, 158 192 pAlloc ? pAlloc->LockInfo.cLocks : 0, 159 193 pSuffix ? pSuffix : "")); … … 624 658 BOOL vboxVDbgDoCheckExe(const char * pszName) 625 659 { 626 char *pszModule = vboxVDbgDoGetModuleName();660 char const *pszModule = vboxVDbgDoGetExeName(); 627 661 if (!pszModule) 628 662 return FALSE; 629 size_t cbModule, cbName; 630 cbModule = strlen(pszModule); 631 cbName = strlen(pszName); 632 if (cbName > cbModule) 633 return FALSE; 634 if (_stricmp(pszName, pszModule + (cbModule - cbName))) 663 size_t cchModule = strlen(pszModule); 664 size_t cchName = strlen(pszName); 665 if (cchName > cchModule) 666 return FALSE; 667 # ifdef IPRT_NO_CRT 668 if (RTStrICmp(pszName, &pszModule[cchModule - cchName])) 669 # else 670 if (_stricmp(pszName, &pszModule[cchModule - cchName])) 671 # endif 635 672 return FALSE; 636 673 return TRUE; … … 741 778 742 779 #endif /* VBOXWDDMDISP_DEBUG_VEHANDLER */ 743 744 780 #if defined(VBOXWDDMDISP_DEBUG) || defined(LOG_TO_BACKDOOR_DRV) 745 void vboxDispLogDrvF(char * szString, ...) 746 { 747 char szBuffer[4096] = {0}; 748 va_list pArgList; 749 va_start(pArgList, szString); 750 vboxDispLogDbgFormatStringV(szBuffer, sizeof (szBuffer), szString, pArgList); 751 va_end(pArgList); 781 782 void vboxDispLogDrvF(char const *pszFormat, ...) 783 { 784 char szBuffer[4096]; 785 va_list va; 786 va_start(va, pszFormat); 787 vboxDispLogDbgFormatStringV(szBuffer, sizeof(szBuffer), pszFormat, va); 788 va_end(va); 752 789 753 790 VBoxDispMpLoggerLog(szBuffer); 754 791 } 755 792 756 void vboxDispLogDbgPrintF(c har * szString, ...)757 { 758 char szBuffer[4096] = { 0 };759 va_list pArgList;760 va_start( pArgList, szString);761 vboxDispLogDbgFormatStringV(szBuffer, sizeof(szBuffer), szString, pArgList);762 va_end( pArgList);793 void vboxDispLogDbgPrintF(const char *pszFormat, ...) 794 { 795 char szBuffer[4096]; 796 va_list va; 797 va_start(va, pszFormat); 798 vboxDispLogDbgFormatStringV(szBuffer, sizeof(szBuffer), pszFormat, va); 799 va_end(va); 763 800 764 801 OutputDebugStringA(szBuffer); 765 802 } 766 #endif 803 804 #endif -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/VBoxDispDbg.h
r93115 r95955 188 188 VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerDumpD3DCAPS9(struct _D3DCAPS9 *pCaps); 189 189 190 void vboxDispLogDrvF(c har * szString, ...);190 void vboxDispLogDrvF(const char *pszFormat, ...); 191 191 192 192 # define vboxDispDumpD3DCAPS9(_pCaps) do { VBoxDispMpLoggerDumpD3DCAPS9(_pCaps); } while (0) … … 197 197 #ifdef VBOXWDDMDISP_DEBUG 198 198 199 void vboxDispLogDbgPrintF(c har * szString, ...);199 void vboxDispLogDbgPrintF(const char *pszFormat, ...); 200 200 201 201 typedef struct VBOXWDDMDISP_ALLOCATION *PVBOXWDDMDISP_ALLOCATION; -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispMpLogger.cpp
r93299 r95955 2 2 /** @file 3 3 * VBox WDDM Display backdoor logger implementation 4 * 5 * We're unable to use standard r3 vbgl-based backdoor logging API because win8 6 * Metro apps can not do CreateFile/Read/Write by default. This is why we use 7 * miniport escape functionality to issue backdoor log string to the miniport 8 * and submit it to host via standard r0 backdoor logging api accordingly. 4 9 */ 5 10 … … 16 21 */ 17 22 18 /* We're unable to use standard r3 vbgl-based backdoor logging API because win8 Metro apps19 * can not do CreateFile/Read/Write by default20 * this is why we use miniport escape functionality to issue backdoor log string to the miniport21 * and submit it to host via standard r0 backdoor logging api accordingly */22 23 23 #include <VBoxDispMpLogger.h> 24 24 #include <iprt/win/windows.h> … … 35 35 #include <iprt/errcore.h> 36 36 #include <iprt/mem.h> 37 38 #include <stdio.h> 37 #include <iprt/process.h> 38 39 #ifndef IPRT_NO_CRT 40 # include <stdio.h> 41 #endif 42 39 43 40 44 typedef enum … … 151 155 } 152 156 153 VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLogF(const char *psz String, ...)157 VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLogF(const char *pszFormat, ...) 154 158 { 155 159 PVBOXDISPMPLOGGER pLogger = vboxDispMpLoggerGet(); … … 157 161 return; 158 162 159 char szBuffer[4096] = {0}; 160 va_list pArgList; 161 va_start(pArgList, pszString); 162 _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), pszString, pArgList); 163 va_end(pArgList); 163 char szBuffer[4096]; 164 va_list va; 165 va_start(va, pszFormat); 166 #ifdef IPRT_NO_CRT 167 RTStrPrintfV(szBuffer, sizeof(szBuffer), pszFormat, va); 168 #else 169 int cch = _vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, va); 170 AssertReturnVoid(cch >= 0); /* unlikely that we'll have string encoding problems, but just in case. */ 171 szBuffer[sizeof(szBuffer) - 1] = '\0'; /* doesn't necessarily terminate the buffer on overflow */ 172 #endif 173 va_end(va); 164 174 165 175 VBoxDispMpLoggerLog(szBuffer); … … 222 232 223 233 /* 224 * Prefix the output string with module name and pid/tid.234 * Prefix the output string with exe name and pid/tid. 225 235 */ 226 static const char *vboxUmLogGetModuleName(void) 227 { 236 static const char *vboxUmLogGetExeName(void) 237 { 238 #ifdef IPRT_NO_CRT 239 /** @todo use RTProcShortName instead? */ 240 return RTProcExecutablePath(); /* should've been initialized by nocrt-startup-dll-win.cpp already */ 241 #else 228 242 static int s_fModuleNameInited = 0; 229 243 static char s_szModuleName[MAX_PATH]; 230 231 244 if (!s_fModuleNameInited) 232 245 { 233 246 const DWORD cchName = GetModuleFileNameA(NULL, s_szModuleName, RT_ELEMENTS(s_szModuleName)); 234 247 if (cchName == 0) 235 {236 248 return "<no module>"; 237 }238 249 s_fModuleNameInited = 1; 239 250 } 240 251 return &s_szModuleName[0]; 252 #endif 241 253 } 242 254 … … 244 256 { 245 257 char szBuffer[4096]; 246 const int cbBuffer = sizeof(szBuffer); 247 char *pszBuffer = &szBuffer[0]; 248 249 int cbWritten = _snprintf(pszBuffer, cbBuffer, "['%s' 0x%lx.0x%lx]: ", 250 vboxUmLogGetModuleName(), GetCurrentProcessId(), GetCurrentThreadId()); 251 if (cbWritten < 0 || cbWritten >= cbBuffer) 252 { 253 AssertFailed(); 254 pszBuffer[0] = 0; 255 cbWritten = 0; 256 } 257 258 const size_t cbLeft = cbBuffer - cbWritten; 259 const size_t cbString = strlen(pszString) + 1; 260 if (cbString <= cbLeft) 261 { 262 memcpy(pszBuffer + cbWritten, pszString, cbString); 263 } 264 else 265 { 266 memcpy(pszBuffer + cbWritten, pszString, cbLeft - 1); 267 pszBuffer[cbWritten + cbLeft - 1] = 0; 268 } 258 #ifdef IPRT_NO_CRT 259 RTStrPrintf(szBuffer, sizeof(szBuffer), "['%s' 0x%lx.0x%lx]: %s", 260 vboxUmLogGetExeName(), GetCurrentProcessId(), GetCurrentThreadId(), pszString); 261 #else 262 int cch = _snprintf(szBuffer, sizeof(szBuffer), "['%s' 0x%lx.0x%lx]: %s", 263 vboxUmLogGetExeName(), GetCurrentProcessId(), GetCurrentThreadId(), pszString); 264 AssertReturnVoid(cch > 0); /* unlikely that we'll have string encoding problems, but just in case. */ 265 szBuffer[sizeof(szBuffer) - 1] = '\0'; /* the function doesn't necessarily terminate the buffer on overflow. */ 266 #endif 269 267 270 268 VBoxDispMpLoggerLog(szBuffer); -
trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/wddm/shared/VBoxDispMpLogger.h
r93115 r95955 40 40 VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLog(const char *pszString); 41 41 42 VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLogF(const char *psz String, ...);42 VBOXDISPMPLOGGER_DECL(void) VBoxDispMpLoggerLogF(const char *pszFormat, ...); 43 43 44 44 DECLCALLBACK(void) VBoxWddmUmLog(const char *pszString);
Note:
See TracChangeset
for help on using the changeset viewer.