From 82bd51f001c8df3def3b327bb31fc7611539cbd8 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Thu, 30 May 2019 18:38:33 -0700 Subject: Remove unused code in vm/util.* (#24863) * Remove unused code in vm/util.* --- src/vm/peimagelayout.cpp | 2 +- src/vm/threads.h | 6 +- src/vm/util.cpp | 317 +---------------------------------------------- src/vm/util.hpp | 114 +---------------- 4 files changed, 8 insertions(+), 431 deletions(-) diff --git a/src/vm/peimagelayout.cpp b/src/vm/peimagelayout.cpp index b689236af9..906e443af7 100644 --- a/src/vm/peimagelayout.cpp +++ b/src/vm/peimagelayout.cpp @@ -390,7 +390,7 @@ ConvertedImageLayout::ConvertedImageLayout(PEImageLayout* source) ThrowLastError(); - m_FileView.Assign(CLRMapViewOfFileEx(m_FileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0, + m_FileView.Assign(CLRMapViewOfFile(m_FileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0, (void *) source->GetPreferredBase())); if (m_FileView == NULL) m_FileView.Assign(CLRMapViewOfFile(m_FileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0)); diff --git a/src/vm/threads.h b/src/vm/threads.h index 7dac8017de..6abbc381e6 100644 --- a/src/vm/threads.h +++ b/src/vm/threads.h @@ -376,9 +376,6 @@ public: { TSNC_OwnsSpinLock = 0x00000400, // The thread owns a spinlock. - TSNC_DisableOleaut32Check = 0x00040000, // Disable oleaut32 delay load check. Oleaut32 has - // been loaded - TSNC_LoadsTypeViolation = 0x40000000, // Use by type loader to break deadlocks caused by type load level ordering violations }; @@ -1209,8 +1206,7 @@ public: TSNC_InRestoringSyncBlock = 0x00020000, // The thread is restoring its SyncBlock for Object.Wait. // After the thread is interrupted once, we turn off interruption // at the beginning of wait. - TSNC_DisableOleaut32Check = 0x00040000, // Disable oleaut32 delay load check. Oleaut32 has - // been loaded + // unused = 0x00040000, TSNC_CannotRecycle = 0x00080000, // A host can not recycle this Thread object. When a thread // has orphaned lock, we will apply this. TSNC_RaiseUnloadEvent = 0x00100000, // Finalize thread is raising managed unload event which diff --git a/src/vm/util.cpp b/src/vm/util.cpp index 077b40926f..2e2648e909 100644 --- a/src/vm/util.cpp +++ b/src/vm/util.cpp @@ -545,70 +545,6 @@ void NPrintToStdErrW(const WCHAR *pwzString, size_t nchars) } //---------------------------------------------------------------------------- - - - - -//+-------------------------------------------------------------------------- -// -// Function: VMDebugOutputA( . . . . ) -// VMDebugOutputW( . . . . ) -// -// Synopsis: Output a message formatted in printf fashion to the debugger. -// ANSI and wide character versions are both provided. Only -// present in debug builds (i.e. when _DEBUG is defined). -// -// Arguments: [format] --- ANSI or Wide character format string -// in printf/OutputDebugString-style format. -// -// [ ... ] --- Variable length argument list compatible -// with the format string. -// -// Returns: Nothing. -// -// Notes: Has internal static sized character buffer of -// width specified by the preprocessor constant DEBUGOUT_BUFSIZE. -// -//--------------------------------------------------------------------------- -#ifdef _DEBUG - -#define DEBUGOUT_BUFSIZE 1024 - -void __cdecl VMDebugOutputA(__in LPSTR format, ...) -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FORBID_FAULT; - - va_list argPtr; - va_start(argPtr, format); - - char szBuffer[DEBUGOUT_BUFSIZE]; - - if(vsprintf_s(szBuffer, DEBUGOUT_BUFSIZE-1, format, argPtr) > 0) - OutputDebugStringA(szBuffer); - va_end(argPtr); -} - -void __cdecl VMDebugOutputW(__in LPWSTR format, ...) -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FORBID_FAULT; - STATIC_CONTRACT_DEBUG_ONLY; - - va_list argPtr; - va_start(argPtr, format); - - WCHAR wszBuffer[DEBUGOUT_BUFSIZE]; - - if(vswprintf_s(wszBuffer, DEBUGOUT_BUFSIZE-2, format, argPtr) > 0) - WszOutputDebugString(wszBuffer); - va_end(argPtr); -} - -#endif // #ifdef DACCESS_COMPILE - //***************************************************************************** // Compare VarLoc's //***************************************************************************** @@ -1254,153 +1190,10 @@ HRESULT VMPostError( // Returned error. } #ifndef CROSSGEN_COMPILE -void VMDumpCOMErrors(HRESULT hrErr) -{ - CONTRACTL - { - NOTHROW; - GC_TRIGGERS; - MODE_PREEMPTIVE; - PRECONDITION(FAILED(hrErr)); - } - CONTRACTL_END; - - SafeComHolderPreemp pIErr(NULL);// Error interface. - BSTRHolder bstrDesc(NULL); // Description text. - - // Try to get an error info object and display the message. - if (SafeGetErrorInfo(&pIErr) == S_OK && pIErr->GetDescription(&bstrDesc) == S_OK) - { - EEMessageBoxCatastrophic(IDS_EE_GENERIC, IDS_FATAL_ERROR, (BSTR)bstrDesc); - } - else - { - // Just give out the failed hr return code. - EEMessageBoxCatastrophic(IDS_COMPLUS_ERROR, IDS_FATAL_ERROR, hrErr); - } -} //----------------------------------------------------------------------------- #ifndef FEATURE_PAL -// Wrap registry functions to use CQuickWSTR to allocate space. This does it -// in a stack friendly manner. -//----------------------------------------------------------------------------- -LONG UtilRegEnumKey(HKEY hKey, // handle to key to query - DWORD dwIndex, // index of subkey to query - CQuickWSTR* lpName) // buffer for subkey name -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - INJECT_FAULT(return ERROR_NOT_ENOUGH_MEMORY;); - } - CONTRACTL_END; - - DWORD size = (DWORD)lpName->MaxSize(); - LONG result = WszRegEnumKeyEx(hKey, - dwIndex, - lpName->Ptr(), - &size, - NULL, - NULL, - NULL, - NULL); - - if (result == ERROR_SUCCESS || result == ERROR_MORE_DATA) { - - // Grow or shrink buffer to correct size - if (lpName->ReSizeNoThrow(size+1) != NOERROR) - result = ERROR_NOT_ENOUGH_MEMORY; - - if (result == ERROR_MORE_DATA) { - size = (DWORD)lpName->MaxSize(); - result = WszRegEnumKeyEx(hKey, - dwIndex, - lpName->Ptr(), - &size, - NULL, - NULL, - NULL, - NULL); - } - } - - return result; -} - -LONG UtilRegQueryStringValueEx(HKEY hKey, // handle to key to query - LPCWSTR lpValueName, // address of name of value to query - LPDWORD lpReserved, // reserved - LPDWORD lpType, // address of buffer for value type - CQuickWSTR* lpData)// data buffer -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - INJECT_FAULT(return ERROR_NOT_ENOUGH_MEMORY;); - } - CONTRACTL_END; - - DWORD size = (DWORD)lpData->MaxSize(); - LONG result = WszRegQueryValueEx(hKey, - lpValueName, - lpReserved, - lpType, - (LPBYTE) lpData->Ptr(), - &size); - - if (result == ERROR_SUCCESS || result == ERROR_MORE_DATA) { - - // Grow or shrink buffer to correct size - if (lpData->ReSizeNoThrow(size+1) != NOERROR) - result = ERROR_NOT_ENOUGH_MEMORY; - - if (result == ERROR_MORE_DATA) { - size = (DWORD)lpData->MaxSize(); - result = WszRegQueryValueEx(hKey, - lpValueName, - lpReserved, - lpType, - (LPBYTE) lpData->Ptr(), - &size); - } - } - - return result; -} - -BOOL ReportEventCLR( - WORD wType, - WORD wCategory, - DWORD dwEventID, - PSID lpUserSid, - SString * message) -{ - CONTRACTL { - THROWS; - GC_TRIGGERS; - MODE_ANY; - } CONTRACTL_END; - - GCX_PREEMP(); - - SString buff; - buff.Printf(W(".NET Runtime version %s - %s"), VER_FILEVERSION_STR_L, message->GetUnicode()); - - DWORD dwRetVal = ClrReportEvent(W(".NET Runtime"), - wType, // event type - wCategory, // category - dwEventID, // event identifier - lpUserSid, // user security identifier - buff.GetUnicode()); // one substitution string - - // Return BOOLEAN based upon return code - return (dwRetVal == ERROR_SUCCESS)?TRUE:FALSE; -} - // This function checks to see if GetLogicalProcessorInformation API is supported. // On success, this function allocates a SLPI array, sets nEntries to number // of elements in the SLPI array and returns a pointer to the SLPI array after filling it with information. @@ -2091,7 +1884,7 @@ void *GetCLRFunction(LPCSTR FunctionName) #endif // CROSSGEN_COMPILE LPVOID -CLRMapViewOfFileEx( +CLRMapViewOfFile( IN HANDLE hFileMappingObject, IN DWORD dwDesiredAccess, IN DWORD dwFileOffsetHigh, @@ -2151,20 +1944,6 @@ CLRMapViewOfFileEx( return pv; } -LPVOID -CLRMapViewOfFile( - IN HANDLE hFileMappingObject, - IN DWORD dwDesiredAccess, - IN DWORD dwFileOffsetHigh, - IN DWORD dwFileOffsetLow, - IN SIZE_T dwNumberOfBytesToMap - ) -{ - WRAPPER_NO_CONTRACT; - return CLRMapViewOfFileEx(hFileMappingObject,dwDesiredAccess,dwFileOffsetHigh,dwFileOffsetLow,dwNumberOfBytesToMap,NULL); -} - - BOOL CLRUnmapViewOfFile( IN LPVOID lpBaseAddress @@ -2278,17 +2057,6 @@ BOOL CLRFreeLibrary(HMODULE hModule) return FreeLibrary(hModule); } -VOID CLRFreeLibraryAndExitThread(HMODULE hModule,DWORD dwExitCode) -{ - // Don't use dynamic contract: will override GetLastError value - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_TRIGGERS; - STATIC_CONTRACT_FORBID_FAULT; - - // This is no-return - FreeLibraryAndExitThread(hModule,dwExitCode); -} - #endif // CROSSGEN_COMPILE #endif // #ifndef DACCESS_COMPILE @@ -3069,83 +2837,6 @@ BOOL DACNotify::ParseExceptionCatcherEnterNotification(TADDR Args[], TADDR& Meth return TRUE; } - -#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) - - -#if defined(_DEBUG) && !defined(FEATURE_PAL) - -typedef USHORT -(__stdcall *PFNRtlCaptureStackBackTrace)( - IN ULONG FramesToSkip, - IN ULONG FramesToCapture, - OUT PVOID * BackTrace, - OUT PULONG BackTraceHash); - -static PFNRtlCaptureStackBackTrace s_RtlCaptureStackBackTrace = NULL; - -WORD UtilCaptureStackBackTrace( - ULONG FramesToSkip, - ULONG FramesToCapture, - PVOID * BackTrace, - OUT PULONG BackTraceHash) -{ - WRAPPER_NO_CONTRACT; - -#ifdef _DEBUG - Thread* t = GetThread(); - if (t != NULL) { - // the thread should not have a hijack set up or we can't walk the stack. - _ASSERTE(!(t->m_State & Thread::TS_Hijacked)); - } -#endif - - if(!s_RtlCaptureStackBackTrace) - { - // Don't need to worry about race conditions here since it will be the same value - HMODULE hModNtdll = GetModuleHandleA("ntdll.dll"); - s_RtlCaptureStackBackTrace = reinterpret_cast( - GetProcAddress(hModNtdll, "RtlCaptureStackBackTrace")); - } - if (!s_RtlCaptureStackBackTrace) { - return 0; - } - ULONG hash; - if (BackTraceHash == NULL) { - BackTraceHash = &hash; - } - return s_RtlCaptureStackBackTrace(FramesToSkip, FramesToCapture, BackTrace, BackTraceHash); -} - -#endif // #if _DEBUG && !FEATURE_PAL - - -#ifdef _DEBUG -DisableDelayLoadCheckForOleaut32::DisableDelayLoadCheckForOleaut32() -{ - GetThread()->SetThreadStateNC(Thread::TSNC_DisableOleaut32Check); -} - -DisableDelayLoadCheckForOleaut32::~DisableDelayLoadCheckForOleaut32() -{ - GetThread()->ResetThreadStateNC(Thread::TSNC_DisableOleaut32Check); -} - -BOOL DelayLoadOleaut32CheckDisabled() -{ - Thread *pThread = GetThread(); - if (pThread && pThread->HasThreadStateNC(Thread::TSNC_DisableOleaut32Check)) - { - return TRUE; - } - - return FALSE; -} -#endif - -#endif // !DACCESS_COMPILE && !CROSSGEN_COMPILE - - static BOOL TrustMeIAmSafe(void *pLock) { LIMITED_METHOD_CONTRACT; @@ -3154,10 +2845,8 @@ static BOOL TrustMeIAmSafe(void *pLock) LockOwner g_lockTrustMeIAmThreadSafe = { NULL, TrustMeIAmSafe }; - -DangerousNonHostedSpinLock g_randomLock; -CLRRandom g_random; - +static DangerousNonHostedSpinLock g_randomLock; +static CLRRandom g_random; int GetRandomInt(int maxVal) { diff --git a/src/vm/util.hpp b/src/vm/util.hpp index 5d484f2ee4..61fe9ab367 100644 --- a/src/vm/util.hpp +++ b/src/vm/util.hpp @@ -12,9 +12,6 @@ #ifndef _H_UTIL #define _H_UTIL -#define MAX_UINT32_HEX_CHAR_LEN 8 // max number of chars representing an unsigned int32, not including terminating null char. -#define MAX_INT32_DECIMAL_CHAR_LEN 11 // max number of chars representing an int32, including sign, not including terminating null char. - #include "utilcode.h" #include "metadata.h" #include "holderinst.h" @@ -72,27 +69,6 @@ typedef double R8; // using compiler intrinsics so they are as fast as they can possibly be. // -// -// these don't have corresponding compiler intrinsics -// - -#ifdef FEATURE_SINGLE_THREADED -#define FastInterlockIncrement(a) (++(*a)) -#define FastInterlockDecrement(a) (--(*a)) -#define FastInterlockOr(a, b) (*a |= (DWORD)b) -#define FastInterlockAnd(a, b) (*a &= (DWORD)b) -#define FastInterlockIncrementLong(a) (++(*a)) -#define FastInterlockDecrementLong(a) (--(*a)) -#define FastInterlockOrLong(a, b) (*a |= (UINT64)b) -#define FastInterlockAndLong(a, b) (*a &= (UINT64)b) -#define FastInterlockCompareExchange InterlockedCompareExchange -#define FastInterlockCompareExchangePointer InterlockedCompareExchangeT - -#else - -// -// these DO have corresponding compiler intrinsics -// #define FastInterlockIncrement InterlockedIncrement #define FastInterlockDecrement InterlockedDecrement #define FastInterlockExchange InterlockedExchange @@ -123,8 +99,6 @@ FORCEINLINE void FastInterlockAnd(DWORD RAW_KEYWORD(volatile) *p, const int msk) InterlockedAnd((LONG *)p, msk); } -#endif - #ifndef FEATURE_PAL // Copied from malloc.h: don't want to bring in the whole header file. void * __cdecl _alloca(size_t); @@ -325,17 +299,8 @@ class CQuickHeap // Linked list of big QuickBlock's QuickBlock *m_pFirstBigQuickBlock; - }; -//====================================================================== -// String Helpers -// -// -// -ULONG StringHashValueW(__in LPWSTR wzString); -ULONG StringHashValueA(LPCSTR szString); - void PrintToStdOutA(const char *pszString); void PrintToStdOutW(const WCHAR *pwzString); void PrintToStdErrA(const char *pszString); @@ -345,50 +310,15 @@ void NPrintToStdOutW(const WCHAR *pwzString, size_t nchars); void NPrintToStdErrA(const char *pszString, size_t nbytes); void NPrintToStdErrW(const WCHAR *pwzString, size_t nchars); - -//===================================================================== -// Function for formatted text output to the debugger -// -// -void __cdecl VMDebugOutputA(__in LPSTR format, ...); -void __cdecl VMDebugOutputW(__in LPWSTR format, ...); - //===================================================================== // VM-safe wrapper for PostError. // HRESULT VMPostError( // Returned error. HRESULT hrRpt, // Reported error. ...); // Error arguments. - -//===================================================================== -// Displays the messaage box or logs the message, corresponding to the last COM+ error occurred -void VMDumpCOMErrors(HRESULT hrErr); -#include "nativevaraccessors.h" -//====================================================================== -// Stack friendly registry helpers -// -LONG UtilRegEnumKey(HKEY hKey, // handle to key to query - DWORD dwIndex, // index of subkey to query - CQuickWSTR* lpName);// buffer for subkey name - -LONG UtilRegQueryStringValueEx(HKEY hKey, // handle to key to query - LPCWSTR lpValueName, // address of name of value to query - LPDWORD lpReserved, // reserved - LPDWORD lpType, // address of buffer for value type - CQuickWSTR* lpData);// data buffer - -//====================================================================== -// Event logging - -BOOL ReportEventCLR ( - IN WORD wType, // Event type - warning, error, success, etc - IN WORD wCategory, // Event category - IN DWORD dwEventID, // Event identifier (defined in shimr\msg.mc) - IN PSID lpUserSid, // user's security identifier - IN SString * message // message to log - ); +#include "nativevaraccessors.h" // -------------------------------------------------------------------------------- // GCX macros @@ -687,17 +617,6 @@ HMODULE CLRLoadLibraryEx(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags); HMODULE CLRLoadLibrary(LPCWSTR lpLibFileName); BOOL CLRFreeLibrary(HMODULE hModule); -VOID CLRFreeLibraryAndExitThread(HMODULE hModule, DWORD dwExitCode); - -LPVOID -CLRMapViewOfFileEx( - IN HANDLE hFileMappingObject, - IN DWORD dwDesiredAccess, - IN DWORD dwFileOffsetHigh, - IN DWORD dwFileOffsetLow, - IN SIZE_T dwNumberOfBytesToMap, - IN LPVOID lpBaseAddress - ); LPVOID CLRMapViewOfFile( @@ -705,9 +624,8 @@ CLRMapViewOfFile( IN DWORD dwDesiredAccess, IN DWORD dwFileOffsetHigh, IN DWORD dwFileOffsetLow, - IN SIZE_T dwNumberOfBytesToMap - ); - + IN SIZE_T dwNumberOfBytesToMap, + IN LPVOID lpBaseAddress = NULL); BOOL CLRUnmapViewOfFile( @@ -1026,19 +944,6 @@ public: }; void DACNotifyCompilationFinished(MethodDesc *pMethodDesc); - -#ifdef _DEBUG -#ifndef FEATURE_PAL -// NOTE: Windows Vista RTM SDK defines CaptureStackBackTrace as RtlCaptureStackBackTrace (in winbase.h) -// Renamed CaptureStackBackTrace to UtilCaptureBackTrace in order to avoid conflicts with the Windows definition -USHORT UtilCaptureStackBackTrace( - ULONG FramesToSkip, - ULONG FramesToCapture, - PVOID * BackTrace, - OUT PULONG BackTraceHash); -#endif // !FEATURE_PAL -#endif //_DEBUG - // These wrap the SString:L:CompareCaseInsenstive function in a way that makes it // easy to fix code that uses _stricmp. _stricmp should be avoided as it uses the current @@ -1049,19 +954,6 @@ USHORT UtilCaptureStackBackTrace( // you've got a problem. int __cdecl stricmpUTF8(const char* szStr1, const char* szStr2); -#ifdef _DEBUG -class DisableDelayLoadCheckForOleaut32 -{ -public: - DisableDelayLoadCheckForOleaut32(); - ~DisableDelayLoadCheckForOleaut32(); -}; -#endif - -extern LONG g_OLEAUT32_Loaded; - -#define ENSURE_OLEAUT32_LOADED() - BOOL DbgIsExecutable(LPVOID lpMem, SIZE_T length); int GetRandomInt(int maxVal); -- cgit v1.2.3