Changeset 95955 in vbox for trunk/src/VBox/Additions/3D/win
- Timestamp:
- Jul 29, 2022 8:52:37 PM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 152711
- Location:
- trunk/src/VBox/Additions/3D/win/VBoxWddmUmHlp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/3D/win/VBoxWddmUmHlp/VBoxMpLogger.cpp
r93115 r95955 22 22 */ 23 23 24 #define IPRT_NO_CRT_FOR_3RD_PARTY /* To get malloc and free wrappers in IPRT_NO_CRT mode. Doesn't link with IPRT in non-no-CRT mode. */ 24 25 #include "UmHlpInternal.h" 25 26 26 27 #include <../../../common/wddm/VBoxMPIf.h> 27 28 #include <stdio.h> 28 #include <stdlib.h> 29 #ifdef IPRT_NO_CRT 30 # include <iprt/process.h> 31 # include <iprt/string.h> 32 #else 33 # include <stdio.h> 34 #endif 29 35 30 36 DECLCALLBACK(void) VBoxDispMpLoggerLog(const char *pszString) … … 70 76 } 71 77 72 DECLCALLBACK(void) VBoxDispMpLoggerLogF(const char *psz String, ...)78 DECLCALLBACK(void) VBoxDispMpLoggerLogF(const char *pszFormat, ...) 73 79 { 74 char szBuffer[4096] = {0}; 75 va_list pArgList; 76 va_start(pArgList, pszString); 77 _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), pszString, pArgList); 78 va_end(pArgList); 80 /** @todo would make a whole lot more sense to just allocate 81 * VBOXDISPIFESCAPE_DBGPRINT here and printf into it's buffer than 82 * double buffering it like this */ 83 char szBuffer[4096]; 84 va_list va; 85 va_start(va, pszFormat); 86 #ifdef IPRT_NO_CRT 87 RTStrPrintf(szBuffer, sizeof(szBuffer), pszFormat, va); 88 #else 89 _vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, va); 90 szBuffer[sizeof(szBuffer) - 1] = '\0'; /* Don't trust the _vsnprintf function terminate the string! */ 91 #endif 92 va_end(va); 79 93 80 94 VBoxDispMpLoggerLog(szBuffer); 81 95 } 82 96 83 /* 84 * Prefix the output string with module name and pid/tid.97 /** 98 * Prefix the output string with exe name and pid/tid. 85 99 */ 86 static const char *vboxUmLogGetModuleName(void) 100 #ifndef IPRT_NO_CRT 101 static const char *vboxUmLogGetExeName(void) 87 102 { 88 103 static int s_fModuleNameInited = 0; … … 93 108 const DWORD cchName = GetModuleFileNameA(NULL, s_szModuleName, RT_ELEMENTS(s_szModuleName)); 94 109 if (cchName == 0) 95 {96 110 return "<no module>"; 97 }98 111 s_fModuleNameInited = 1; 99 112 } 100 113 return &s_szModuleName[0]; 101 114 } 115 #endif 102 116 103 117 DECLCALLBACK(void) VBoxWddmUmLog(const char *pszString) 104 118 { 119 /** @todo Allocate VBOXDISPIFESCAPE_DBGPRINT here and format right into it 120 * instead? That would be a lot more flexible and a little faster. */ 105 121 char szBuffer[4096]; 106 const int cbBuffer = sizeof(szBuffer); 107 char *pszBuffer = &szBuffer[0]; 108 109 int cbWritten = _snprintf(pszBuffer, cbBuffer, "['%s' 0x%lx.0x%lx]: ", 110 vboxUmLogGetModuleName(), GetCurrentProcessId(), GetCurrentThreadId()); 111 if (cbWritten < 0 || cbWritten >= cbBuffer) 112 { 113 Assert(0); 114 pszBuffer[0] = 0; 115 cbWritten = 0; 116 } 117 118 const size_t cbLeft = cbBuffer - cbWritten; 119 const size_t cbString = strlen(pszString) + 1; 120 if (cbString <= cbLeft) 121 { 122 memcpy(pszBuffer + cbWritten, pszString, cbString); 123 } 124 else 125 { 126 memcpy(pszBuffer + cbWritten, pszString, cbLeft - 1); 127 pszBuffer[cbWritten + cbLeft - 1] = 0; 128 } 122 #ifdef IPRT_NO_CRT 123 /** @todo use RTProcShortName instead of RTProcExecutablePath? Will avoid 124 * chopping off log text if the executable path is too long. */ 125 RTStrPrintf(szBuffer, sizeof(szBuffer), "['%s' 0x%lx.0x%lx]: %s", 126 RTProcExecutablePath() /* should've been initialized by nocrt-startup-dll-win.cpp already */, 127 GetCurrentProcessId(), GetCurrentThreadId(), pszString); 128 #else 129 int cch = _snprintf(szBuffer, sizeof(szBuffer), "['%s' 0x%lx.0x%lx]: %s", 130 vboxUmLogGetExeName(), GetCurrentProcessId(), GetCurrentThreadId(), pszString); 131 AssertReturnVoid(cch > 0); /* unlikely that we'll have string encoding problems, but just in case. */ 132 szBuffer[sizeof(szBuffer) - 1] = '\0'; /* the function doesn't necessarily terminate the buffer on overflow. */ 133 #endif 129 134 130 135 VBoxDispMpLoggerLog(szBuffer); -
trunk/src/VBox/Additions/3D/win/VBoxWddmUmHlp/VBoxWddmUmHlp.h
r93115 r95955 30 30 31 31 /* Do not require IPRT library. */ 32 #if defined(Assert) 33 #undef Assert 34 #endif 35 #ifdef RT_STRICT 36 #define Assert(_e) (void)( (!!(_e)) || (ASMBreakpoint(), 0) ) 37 #else 38 #define Assert(_e) (void)( 0 ) 32 /** @todo r=bird: It is *NOT* okay to redefine Assert* (or Log*) macros! It 33 * causes confusing as the code no longer behaves in the way one expect. Thus, 34 * it is strictly forbidden. */ 35 #ifndef IPRT_NO_CRT 36 # undef Assert 37 # undef AssertReturnVoid 38 # ifdef RT_STRICT 39 # define Assert(_e) (void)( (!!(_e)) || (ASMBreakpoint(), 0) ) 40 # define AssertReturnVoid(a_Expr) do { if (RT_LIKELY(a_Expr)) {} else { ASMBreakpoint(); return; } } while (0) 41 # else 42 # define Assert(_e) (void)( 0 ) 43 # define AssertReturnVoid(a_Expr) do { if (RT_LIKELY(a_Expr)) {} else return; } while (0) 44 # endif 39 45 #endif 40 46 … … 88 94 DECLCALLBACK(D3DKMTFUNCTIONS const *) D3DKMTFunctions(void); 89 95 90 DECLCALLBACK(void) VBoxDispMpLoggerLogF(const char *psz String, ...);96 DECLCALLBACK(void) VBoxDispMpLoggerLogF(const char *pszFormat, ...); 91 97 DECLCALLBACK(void) VBoxWddmUmLog(const char *pszString); 92 98
Note:
See TracChangeset
for help on using the changeset viewer.