summaryrefslogtreecommitdiff
path: root/src/utilcode
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2017-10-16 15:00:33 -0700
committerGitHub <noreply@github.com>2017-10-16 15:00:33 -0700
commit479b1e654cd5a13bb1ce47288cf78776b858bced (patch)
tree79c8e6e8b34b1870a3e090ecaf4c3710a539439b /src/utilcode
parenta1142be0e2cfc8b98168761beeb5f97e4f865b63 (diff)
downloadcoreclr-479b1e654cd5a13bb1ce47288cf78776b858bced.tar.gz
coreclr-479b1e654cd5a13bb1ce47288cf78776b858bced.tar.bz2
coreclr-479b1e654cd5a13bb1ce47288cf78776b858bced.zip
Delete dead code (#14521)
Diffstat (limited to 'src/utilcode')
-rw-r--r--src/utilcode/util.cpp344
1 files changed, 1 insertions, 343 deletions
diff --git a/src/utilcode/util.cpp b/src/utilcode/util.cpp
index 8b2ee6f8ca..97b90ed06f 100644
--- a/src/utilcode/util.cpp
+++ b/src/utilcode/util.cpp
@@ -3035,348 +3035,7 @@ LPWSTR *SegmentCommandLine(LPCWSTR lpCmdLine, DWORD *pNumArgs)
Volatile<PVOID> ForbidCallsIntoHostOnThisThread::s_pvOwningFiber = NULL;
-#ifdef ENABLE_CONTRACTS_IMPL
-
-enum SOViolationType {
- SO_Violation_Intolerant = 0,
- SO_Violation_NotMainline = 1,
- SO_Violation_Backout = 2,
-};
-
-struct HashedSOViolations {
- ULONG m_hash;
- HashedSOViolations* m_pNext;
- HashedSOViolations(ULONG hash, HashedSOViolations *pNext) : m_hash(hash), m_pNext(pNext) {}
-};
-
-static HashedSOViolations *s_pHashedSOViolations = NULL;
-
-void SOViolation(const char *szFunction, const char *szFile, int lineNum, SOViolationType violation);
-
-
-//
-// SOTolerantViolation is used to report an SO-intolerant function that is not running behind a probe.
-//
-void SOTolerantViolation(const char *szFunction, const char *szFile, int lineNum)
-{
- return SOViolation(szFunction, szFile, lineNum, SO_Violation_Intolerant);
-}
-
-//
-// SONotMainlineViolation is used to report any code with SO_NOT_MAINLINE being run in a test environment
-// with COMPlus_NO_SO_NOT_MAINLINE enabled
-//
-void SONotMainlineViolation(const char *szFunction, const char *szFile, int lineNum)
-{
- return SOViolation(szFunction, szFile, lineNum, SO_Violation_NotMainline);
-}
-
-//
-// SONotMainlineViolation is used to report any code with SO_NOT_MAINLINE being run in a test environment
-// with COMPlus_NO_SO_NOT_MAINLINE enabled
-//
-void SOBackoutViolation(const char *szFunction, const char *szFile, int lineNum)
-{
- return SOViolation(szFunction, szFile, lineNum, SO_Violation_Backout);
-}
-
-//
-// Code common to SO violations
-//
-// The default is to throw up an ASSERT. But the function can also dump violations to a file and
-// ensure that only unique violations are tracked.
-//
-void SOViolation(const char *szFunction, const char *szFile, int lineNum, SOViolationType violationType)
-{
- // This function is called from places that don't allow a throw. But this is debug-only
- // code that should eventually never be called once all the violations are gone.
- CONTRACT_VIOLATION(ThrowsViolation|FaultViolation|TakesLockViolation);
-
- static BOOL fDumpToFileInitialized = FALSE;
- static BOOL fDumpToFile = FALSE;
-
-#pragma warning(disable:4640) // Suppress warning: construction of local static object is not thread-safe
- static SString hashFN;
- static SString fnameFN;
- static SString detailsFN;
-#pragma warning(default:4640)
-
- static int dumpLock = -1;
-
- static CHAR szExprWithStack[10480];
- static DWORD stackTraceLength = 20;
-
- if (fDumpToFileInitialized == FALSE)
- {
- stackTraceLength = REGUTIL::GetConfigDWORD_DontUse_(CLRConfig::INTERNAL_SODumpViolationsStackTraceLength, stackTraceLength);
- // Limit the length or we'll overflow our buffer
- if (stackTraceLength > cfrMaxAssertStackLevels)
- {
- stackTraceLength = cfrMaxAssertStackLevels;
- }
- NewArrayHolder<WCHAR> dumpDir(CLRConfig::GetConfigValue(CLRConfig::INTERNAL_SODumpViolationsDir));
- if (dumpDir == NULL)
- {
- fDumpToFileInitialized = TRUE;
- }
- else
- {
- fDumpToFile = TRUE;
- hashFN.Append(SString(dumpDir.GetValue()));
- hashFN.Append(W("\\SOViolationHashes.txt"));
- fnameFN.Append(SString(dumpDir.GetValue()));
- fnameFN.Append(W("\\SOViolationFunctionNames.txt"));
- detailsFN.Append(SString(dumpDir.GetValue()));
- detailsFN.Append(W("\\SOViolationDetails.txt"));
- }
- }
-
- char buff[1024];
-
- if (violationType == SO_Violation_NotMainline)
- {
- sprintf_s(buff,
- _countof(buff),
- "CONTRACT VIOLATION by %s at \"%s\" @ %d\n\n"
- "SO-not-mainline function being called with not-mainline checking enabled.\n"
- "\nPlease open a bug against the feature owner.\n"
- "\nNOTE: You can disable this ASSERT by setting COMPlus_SOEnableDefaultRWValidation=0.\n"
- " or by turning of not-mainline checking by by setting COMPlus_NO_SO_NOT_MAINLINE=0.\n"
- "\nFor details about this feature, see, in a CLR enlistment,\n"
- "src\\ndp\\clr\\doc\\OtherDevDocs\\untriaged\\clrdev_web\\SO Guide for CLR Developers.doc\n",
- szFunction, szFile, lineNum);
- }
- else if (violationType == SO_Violation_Backout)
- {
- sprintf_s(buff,
- _countof(buff),
- "SO Backout Marker overrun.\n\n"
- "A dtor or handler path exceeded the backout code stack consumption limit.\n"
- "\nPlease open a bug against the feature owner.\n"
- "\nNOTE: You can disable this ASSERT by setting COMPlus_SOEnableBackoutStackValidation=0.\n"
- "\nFor details about this feature, see, in a CLR enlistment,\n"
- "src\\ndp\\clr\\doc\\OtherDevDocs\\untriaged\\clrdev_web\\SO Guide for CLR Developers.doc\n");
- }
- else
- {
- sprintf_s(buff,
- _countof(buff),
- "CONTRACT VIOLATION by %s at \"%s\" @ %d\n\n"
- "SO-intolerant function called outside an SO probe.\n"
- "\nPlease open a bug against the feature owner.\n"
- "\nNOTE: You can disable this ASSERT by setting COMPlus_SOEnableDefaultRWValidation=0.\n"
- "\nFor details about this feature, see, in a CLR enlistment,\n"
- "src\\ndp\\clr\\doc\\OtherDevDocs\\untriaged\\clrdev_web\\SO Guide for CLR Developers.doc\n",
- szFunction, szFile, lineNum);
- }
-
- // At this point, we've checked if we should dump to file or not and so can either
- // do the assert or fall through and dump to a file.
- if (! fDumpToFile)
- {
- DbgAssertDialog((char *)szFile, lineNum, buff);
- return;
- }
-
- // If we are dumping violations to a file, we want to avoid duplicates so that we can run multiple tests
- // and find unique violations and not end up with massively long files.
- // We keep three files:
- // 1) a list of the hashed strings for each unique filename/function
- // 2) a list of the actual filename/function for unique violations and
- // 3) a detailed assert dump for the violation itself
- //
- // First thing to do is read in the hashes file if this is our first violation. We read the filenames into a linked
- // list with their hashes.
- //
- // Then we want to search through the list for that violation
-
- // If it's new, then we insert the violation at the front of our list and append it to the violation files
- // Otherwise, if we've already seen this violation, we can ignore it.
-
-
- HANDLE hashesDumpFileHandle = INVALID_HANDLE_VALUE;
-
- StackScratchBuffer buffer;
- // First see if we've initialized yet
- if (fDumpToFileInitialized == FALSE)
- {
- LONG lAlreadyOwned = InterlockedExchange((LPLONG)&dumpLock, 1);
- if (lAlreadyOwned == 1)
- {
- // somebody else has gotten here first. So just skip this violation.
- return;
- }
-
- // This is our first time through, so read in the existing file and create a linked list of hashed names from it.
- hashesDumpFileHandle = CreateFileA(
- hashFN.GetANSI(buffer),
- GENERIC_READ,
- FILE_SHARE_READ,
- NULL,
- OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_WRITE_THROUGH,
- NULL);
-
- // If we successfully opened the file, pull out each hash number and add it to a linked list of known violations.
- // Otherwise, if we couldn't open the file, assume that there were no preexisting violations. The worse thing
- // that will happen in this case is that we might report some dups.
- if (hashesDumpFileHandle != INVALID_HANDLE_VALUE)
- {
- DWORD dwFileSize = GetFileSize( hashesDumpFileHandle, NULL );
-
- NewArrayHolder<char> pBuffer(new char[dwFileSize]);
- DWORD cbBuffer = dwFileSize;
- DWORD cbRead;
- DWORD result = ReadFile( hashesDumpFileHandle, pBuffer.GetValue(), cbBuffer, &cbRead, NULL );
-
- CloseHandle( hashesDumpFileHandle );
- hashesDumpFileHandle = INVALID_HANDLE_VALUE;
-
- // If we couldn't read the file, assume that there were no preexisting violations. Worse thing
- // that will happen is we might report some dups.
- if (result && cbRead == cbBuffer)
- {
- char *pBuf = pBuffer.GetValue();
- COUNT_T count = 0;
- LOG((LF_EH, LL_INFO100000, "SOTolerantViolation: Reading known violations\n"));
- while (count < cbRead)
- {
- char *pHashStart = pBuf + count;
- char *pHashEnd = strstr(pHashStart, "\r\n");
- COUNT_T len = static_cast<COUNT_T>(pHashEnd-pHashStart);
- SString hashString(SString::Ascii, pHashStart, len);
- ULONG hashValue = wcstoul(hashString.GetUnicode(), NULL, 16);
- HashedSOViolations *pHashedSOViolations = new HashedSOViolations(hashValue, s_pHashedSOViolations);
- s_pHashedSOViolations = pHashedSOViolations;
- count += (len + 2);
- LOG((LF_ALWAYS, LL_ALWAYS, " %8.8x\n", pHashedSOViolations->m_hash));
- }
- }
- }
- fDumpToFileInitialized = TRUE;
- dumpLock = -1;
- }
-
-
- SString violation;
- violation.Append(SString(SString::Ascii, szFile));
- violation.Append(W(" "));
- violation.Append(SString(SString::Ascii, szFunction));
- HashedSOViolations *cur = s_pHashedSOViolations;
-
- // look for the violation in the list
- while (cur != NULL)
- {
- if (cur->m_hash == violation.Hash())
- {
- return;
- }
- cur = cur->m_pNext;
- }
-
- LONG lAlreadyOwned = InterlockedExchange((LPLONG)&dumpLock, 1);
- if (lAlreadyOwned == 1)
- {
- // somebody else has gotten here first. So just skip this violation.
- return;
- }
-
- HANDLE functionsDumpFileHandle = INVALID_HANDLE_VALUE;
- HANDLE detailsDumpFileHandle = INVALID_HANDLE_VALUE;
-
- // This is a new violation
- // Append new violations to the output files
- functionsDumpFileHandle = CreateFileA(
- fnameFN.GetANSI(buffer), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_WRITE_THROUGH, NULL);
-
- if (functionsDumpFileHandle != INVALID_HANDLE_VALUE)
- {
- // First write it to the filename dump
- SetFilePointer(functionsDumpFileHandle, NULL, NULL, FILE_END);
-
- DWORD written;
- char *szExpr = &szExprWithStack[0];
- sprintf_s(szExpr, _countof(szExprWithStack), "%s %8.8x\r\n", violation.GetANSI(buffer), violation.Hash());
- WriteFile(functionsDumpFileHandle, szExpr, static_cast<DWORD>(strlen(szExpr)), &written, NULL);
- CloseHandle(functionsDumpFileHandle);
-
- // Now write it to the hashes dump. Once we've got it in the filename dump, we don't
- // care if these others fail. We can live w/o detailed info or with dups.
- hashesDumpFileHandle = CreateFileA(
- hashFN.GetANSI(buffer), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_WRITE_THROUGH, NULL);
-
- if (hashesDumpFileHandle != INVALID_HANDLE_VALUE)
- {
- SetFilePointer(hashesDumpFileHandle, NULL, NULL, FILE_END);
-
- DWORD written;
- sprintf_s(szExpr, _countof(szExprWithStack), "%8.8x", violation.Hash());
- strcat_s(szExpr, _countof(szExprWithStack), "\r\n");
- WriteFile(hashesDumpFileHandle, szExpr, static_cast<DWORD>(strlen(szExpr)), &written, NULL);
- CloseHandle(hashesDumpFileHandle);
- hashesDumpFileHandle = INVALID_HANDLE_VALUE;
- }
-
- // Now write it to the details dump
- strcpy_s(szExpr, _countof(szExprWithStack), buff);
- strcat_s(szExpr, _countof(szExprWithStack), "\n\n");
-#ifndef FEATURE_PAL
- GetStringFromStackLevels(1, stackTraceLength, szExprWithStack + strlen(szExprWithStack));
- strcat_s(szExpr, _countof(szExprWithStack), "\n\n");
-#endif // FEATURE_PAL
- char exeName[300];
- GetModuleFileNameA(NULL, exeName, sizeof(exeName)/sizeof(WCHAR));
- strcat_s(szExpr, _countof(szExprWithStack), exeName);
- strcat_s(szExpr, _countof(szExprWithStack), "\n\n\n");
-
- detailsDumpFileHandle = CreateFileA(
- detailsFN.GetANSI(buffer), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS,
- FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_WRITE_THROUGH, NULL);
-
- if (detailsDumpFileHandle != INVALID_HANDLE_VALUE)
- {
- SetFilePointer(detailsDumpFileHandle, NULL, NULL, FILE_END);
- WriteFile(detailsDumpFileHandle, szExpr, static_cast<DWORD>(strlen(szExpr)), &written, NULL);
- CloseHandle(detailsDumpFileHandle);
- detailsDumpFileHandle = INVALID_HANDLE_VALUE;
- }
-
- // add the new violation to our list
- HashedSOViolations *pHashedSOViolations = new HashedSOViolations(violation.Hash(), s_pHashedSOViolations);
- s_pHashedSOViolations = pHashedSOViolations;
- LOG((LF_ALWAYS, LL_ALWAYS, "SOTolerantViolation: Adding new violation %8.8x %s\n", pHashedSOViolations->m_hash, violation.GetANSI(buffer)));
- dumpLock = -1;
- }
-}
-
-void SoTolerantViolationHelper(const char *szFunction,
- const char *szFile,
- int lineNum)
-{
- // Keep this function separate to avoid overhead of EH in the normal case where we don't assert
- // Enter SO-tolerant mode for scope of this call so that we don't get contract asserts
- // in anything called downstream of CONTRACT_ASSERT. If we unwind out of here, our dtor
- // will reset our state to what it was on entry.
- CONTRACT_VIOLATION(SOToleranceViolation);
-
- SOTolerantViolation(szFunction, szFile, lineNum);
-
-}
-
-void CloseSOTolerantViolationFile()
-{
- // We used to have a file to close. Now we just cleanup the memory.
- HashedSOViolations *ptr = s_pHashedSOViolations;
- while (ptr != NULL)
- {
- s_pHashedSOViolations = s_pHashedSOViolations->m_pNext;
- delete ptr;
- ptr = s_pHashedSOViolations;
- }
-}
-#endif //ENABLE_CONTRACTS_IMPL
+//======================================================================
BOOL FileExists(LPCWSTR filename)
{
@@ -3392,7 +3051,6 @@ BOOL FileExists(LPCWSTR filename)
return TRUE;
}
-
//======================================================================
// This function returns true, if it can determine that the instruction pointer
// refers to a code address that belongs in the range of the given image.