diff --git a/src/coreclr/inc/clrconfigvalues.h b/src/coreclr/inc/clrconfigvalues.h index ddc7c79506ad4e..98cb2fc5a013dc 100644 --- a/src/coreclr/inc/clrconfigvalues.h +++ b/src/coreclr/inc/clrconfigvalues.h @@ -817,7 +817,6 @@ CONFIG_STRING_INFO(INTERNAL_DumpOnClassLoad, W("DumpOnClassLoad"), "Dumps inform CONFIG_DWORD_INFO(INTERNAL_ExpandAllOnLoad, W("ExpandAllOnLoad"), 0, "") CONFIG_DWORD_INFO(INTERNAL_ForceRelocs, W("ForceRelocs"), 0, "") CONFIG_DWORD_INFO(INTERNAL_GenerateLongJumpDispatchStubRatio, W("GenerateLongJumpDispatchStubRatio"), 0, "Useful for testing VSD on AMD64") -CONFIG_DWORD_INFO(INTERNAL_HashStack, W("HashStack"), 0, "") CONFIG_DWORD_INFO(INTERNAL_HostManagerConfig, W("HostManagerConfig"), (DWORD)-1, "") CONFIG_DWORD_INFO(INTERNAL_HostTestThreadAbort, W("HostTestThreadAbort"), 0, "") CONFIG_STRING_INFO(INTERNAL_InvokeHalt, W("InvokeHalt"), "Throws an assert when the given method is invoked through reflection.") diff --git a/src/coreclr/inc/clrhost.h b/src/coreclr/inc/clrhost.h index 9b8b41f291c0d7..a9376a0a422ab4 100644 --- a/src/coreclr/inc/clrhost.h +++ b/src/coreclr/inc/clrhost.h @@ -65,10 +65,6 @@ BOOL ClrVirtualProtect(LPVOID lpAddress, SIZE_T dwSize, DWORD flNewProtect, PDWO HANDLE ClrGetProcessExecutableHeap(); #endif -#ifdef FAILPOINTS_ENABLED -extern int RFS_HashStack(); -#endif - // Critical section support for CLR DLLs other than the EE. // Include the header defining each Crst type and its corresponding level (relative rank). This is // auto-generated from a tool that takes a high-level description of each Crst type and its dependencies. diff --git a/src/coreclr/inc/holder.h b/src/coreclr/inc/holder.h index 360be1d19ea3f6..eb537804daa928 100644 --- a/src/coreclr/inc/holder.h +++ b/src/coreclr/inc/holder.h @@ -997,19 +997,6 @@ FORCEINLINE void Delete(TYPE *value) template using NewHolder = SpecializedWrapper<_TYPE, Delete<_TYPE>>; - //----------------------------------------------------------------------------- -// NewExecutableHolder : New'ed memory holder for executable memory. -// -// { -// NewExecutableHolder foo = (Foo*) new (executable) Byte[num]; -// } // delete foo on out of scope -//----------------------------------------------------------------------------- -// IJW -template void DeleteExecutable(T *p); - -template -using NewExecutableHolder = SpecializedWrapper<_TYPE, DeleteExecutable<_TYPE>>; - //----------------------------------------------------------------------------- // NewArrayHolder : New []'ed pointer holder // { diff --git a/src/coreclr/inc/switches.h b/src/coreclr/inc/switches.h index e19627fac1efad..06fdaa5f397510 100644 --- a/src/coreclr/inc/switches.h +++ b/src/coreclr/inc/switches.h @@ -33,13 +33,6 @@ #define LOGGING #endif -#if !defined(FEATURE_UTILCODE_NO_DEPENDENCIES) -// Failpoint support -#if defined(_DEBUG) && !defined(DACCESS_COMPILE) && !defined(TARGET_UNIX) -#define FAILPOINTS_ENABLED -#endif -#endif //!defined(FEATURE_UTILCODE_NO_DEPENDENCIES) - #if 0 // Enable to track details of EESuspension #define TIME_SUSPEND diff --git a/src/coreclr/inc/utilcode.h b/src/coreclr/inc/utilcode.h index d4416a36919bd6..aee6e75713c49e 100644 --- a/src/coreclr/inc/utilcode.h +++ b/src/coreclr/inc/utilcode.h @@ -3716,37 +3716,6 @@ namespace util } } - -/* ------------------------------------------------------------------------ * - * Overloaded operators for the executable heap - * ------------------------------------------------------------------------ */ - -#ifdef HOST_WINDOWS - -struct CExecutable { int x; }; -extern const CExecutable executable; - -void * __cdecl operator new(size_t n, const CExecutable&); -void * __cdecl operator new[](size_t n, const CExecutable&); -void * __cdecl operator new(size_t n, const CExecutable&, const std::nothrow_t&) noexcept; -void * __cdecl operator new[](size_t n, const CExecutable&, const std::nothrow_t&) noexcept; - - -// -// Executable heap delete to match the executable heap new above. -// -template void DeleteExecutable(T *p) -{ - if (p != NULL) - { - p->T::~T(); - - HeapFree(ClrGetProcessExecutableHeap(), 0, p); - } -} - -#endif // HOST_WINDOWS - INDEBUG(BOOL DbgIsExecutable(LPVOID lpMem, SIZE_T length);) BOOL ThreadWillCreateGuardPage(SIZE_T sizeReservedStack, SIZE_T sizeCommittedStack); diff --git a/src/coreclr/utilcode/clrhost.cpp b/src/coreclr/utilcode/clrhost.cpp index 0bf016eb883490..05291cabea3826 100644 --- a/src/coreclr/utilcode/clrhost.cpp +++ b/src/coreclr/utilcode/clrhost.cpp @@ -39,79 +39,6 @@ void* GetClrModuleBase() thread_local int t_CantAllocCount; -#ifdef FAILPOINTS_ENABLED -typedef int (*FHashStack) (); - -static FHashStack fHashStack = 0; -static _TEB *HashStackSetupThread = NULL; -static _TEB *RFSCustomDataSetupThread = NULL; - -static void SetupHashStack () -{ - CANNOT_HAVE_CONTRACT; - - FHashStack oldValue = InterlockedCompareExchangeT(&fHashStack, - reinterpret_cast(1), reinterpret_cast(0)); - if ((size_t) oldValue >= 2) { - return; - } - else if ((size_t) oldValue == 0) { - // We are the first thread to initialize - HashStackSetupThread = NtCurrentTeb(); - - if (CLRConfig::GetConfigValue(CLRConfig::INTERNAL_HashStack) == 0) { - fHashStack = (FHashStack) 2; - return; - } - - PAL_TRY(void *, unused, NULL) { - FHashStack func; - HMODULE hmod = WszLoadLibrary(W("mscorrfs.dll"), NULL, 0); - if (hmod) { - func = (FHashStack)GetProcAddress (hmod, "HashStack"); - if (func == 0) { - func = (FHashStack)2; - } - } - else - func = (FHashStack)2; - fHashStack = func; - } - PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) - { - fHashStack = (FHashStack) 2; - } - PAL_ENDTRY; - } - else if (NtCurrentTeb() == HashStackSetupThread) { - // We get here while initializing - return; - } - else { - // All other threads will wait - while (fHashStack == (FHashStack) 1) { - ClrSleepEx (100, FALSE); - } - } -} - -int RFS_HashStack () -{ - CANNOT_HAVE_CONTRACT; - - if ((size_t)fHashStack < 2) { - SetupHashStack (); - } - - if ((size_t)fHashStack <= 2) { - return 0; - } - else - return fHashStack (); -} - -#endif // FAILPOINTS_ENABLED - DWORD GetClrModulePathName(SString& buffer) { #ifdef HOST_WINDOWS diff --git a/src/coreclr/utilcode/clrhost_nodependencies.cpp b/src/coreclr/utilcode/clrhost_nodependencies.cpp index 3cc4badd9e3aa3..a3d1cfb3e12f65 100644 --- a/src/coreclr/utilcode/clrhost_nodependencies.cpp +++ b/src/coreclr/utilcode/clrhost_nodependencies.cpp @@ -204,96 +204,31 @@ ClrDebugState *CLRInitDebugState() // use standard heap functions for AddressSanitizer and for the DAC build. #if !defined(HAS_ADDRESS_SANITIZER) && !defined(DACCESS_COMPILE) -#ifdef _DEBUG -#ifdef TARGET_X86 -#define OS_HEAP_ALIGN 8 -#else -#define OS_HEAP_ALIGN 16 -#endif -#define CLRALLOC_TAG 0x2ce145f1 -#endif - -#ifdef HOST_WINDOWS -static HANDLE g_hProcessHeap; -#endif -static FORCEINLINE void* ClrMalloc(size_t size) +#if defined(SELF_NO_HOST) +namespace { - STATIC_CONTRACT_NOTHROW; - -#ifdef FAILPOINTS_ENABLED - if (RFS_HashStack()) - return NULL; -#endif - - void* p; - -#ifdef _DEBUG - size += OS_HEAP_ALIGN; -#endif - -#ifdef HOST_WINDOWS - HANDLE hHeap = g_hProcessHeap; - if (hHeap == NULL) + void ReportOOM(size_t size) { - InterlockedCompareExchangeT(&g_hProcessHeap, ::GetProcessHeap(), NULL); - hHeap = g_hProcessHeap; + // With no host, we have nowhere to report the OOM. } - - p = HeapAlloc(hHeap, 0, size); +} #else - if (size == 0) - { - // Allocate at least one byte. - size = 1; - } - p = malloc(size); -#endif - -#ifdef _DEBUG - // Store the tag to detect heap contamination - if (p != NULL) +// If we have the CLR host, we should report OOMs to the StressLog. +namespace +{ + FORCEINLINE void ReportOOM(size_t size) { - *((DWORD*)p) = CLRALLOC_TAG; - p = (BYTE*)p + OS_HEAP_ALIGN; - } -#endif - -#ifndef SELF_NO_HOST - if (p == NULL + STATIC_CONTRACT_NOTHROW; // If we have not created StressLog ring buffer, we should not try to use it. // StressLog is going to do a memory allocation. We may enter an endless loop. - && StressLog::t_pCurrentThreadLog != NULL) - { - STRESS_LOG_OOM_STACK(size); + if (StressLog::t_pCurrentThreadLog != NULL) + { + STRESS_LOG_OOM_STACK(size); + } } -#endif - - return p; } - -FORCEINLINE void ClrFree(void* p) -{ - STATIC_CONTRACT_NOTHROW; - -#ifdef _DEBUG - if (p != NULL) - { - // Check the heap handle to detect heap contamination - p = (BYTE*)p - OS_HEAP_ALIGN; - if (*((DWORD*)p) != CLRALLOC_TAG) - _ASSERTE(!"Heap contamination detected! HeapFree was called on a heap other than the one that memory was allocated from.\n" - "Possible cause: you used new (executable) to allocate the memory, but didn't use DeleteExecutable() to free it."); - } -#endif - -#ifdef HOST_WINDOWS - if (p != NULL) - HeapFree(g_hProcessHeap, 0, p); -#else - free(p); #endif -} void * __cdecl operator new(size_t n) @@ -307,8 +242,9 @@ operator new(size_t n) STATIC_CONTRACT_FAULT; STATIC_CONTRACT_SUPPORTS_DAC_HOST_ONLY; - void* result = ClrMalloc(n); + void* result = malloc(n == 0 ? 1 : n); if (result == NULL) { + ReportOOM(n); ThrowOutOfMemory(); } TRASH_LASTERROR; @@ -318,39 +254,10 @@ operator new(size_t n) void * __cdecl operator new[](size_t n) { -#ifdef _DEBUG_IMPL - CLRThrowsExceptionWorker(); -#endif - - STATIC_CONTRACT_THROWS; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FAULT; - STATIC_CONTRACT_SUPPORTS_DAC_HOST_ONLY; - - void* result = ClrMalloc(n); - if (result == NULL) { - ThrowOutOfMemory(); - } - TRASH_LASTERROR; - return result; -}; - - -void * __cdecl operator new(size_t n, const std::nothrow_t&) noexcept -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FAULT; - STATIC_CONTRACT_SUPPORTS_DAC_HOST_ONLY; - - INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN())); - - void* result = ClrMalloc(n); - TRASH_LASTERROR; - return result; + return ::operator new(n); } -void * __cdecl operator new[](size_t n, const std::nothrow_t&) noexcept +void* __cdecl operator new(size_t size, const std::nothrow_t&) noexcept { STATIC_CONTRACT_NOTHROW; STATIC_CONTRACT_GC_NOTRIGGER; @@ -359,158 +266,37 @@ void * __cdecl operator new[](size_t n, const std::nothrow_t&) noexcept INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN())); - void* result = ClrMalloc(n); - TRASH_LASTERROR; - return result; -} - -void __cdecl -operator delete(void *p) noexcept -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_SUPPORTS_DAC_HOST_ONLY; - - ClrFree(p); - - TRASH_LASTERROR; -} - -void __cdecl -operator delete[](void *p) noexcept -{ - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_SUPPORTS_DAC_HOST_ONLY; - - ClrFree(p); - TRASH_LASTERROR; -} - -#endif // !HAS_ADDRESS_SANITIZER && !DACCESS_COMPILE - -/* ------------------------------------------------------------------------ * - * New operator overloading for the executable heap - * ------------------------------------------------------------------------ */ - -#ifdef HOST_WINDOWS - -HANDLE ClrGetProcessExecutableHeap() -{ - // Note: this can be called a little early for real contracts, so we use static contracts instead. - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - - static HANDLE g_ExecutableHeapHandle; - - // - // Create the executable heap lazily - // - if (g_ExecutableHeapHandle == NULL) + void* result = malloc(size == 0 ? 1 : size); + if (result == nullptr) { - - HANDLE ExecutableHeapHandle = HeapCreate( - HEAP_CREATE_ENABLE_EXECUTE, // heap allocation attributes - 0, // initial heap size - 0 // maximum heap size; 0 == growable - ); - - if (ExecutableHeapHandle == NULL) - return NULL; - - HANDLE ExistingValue = InterlockedCompareExchangeT(&g_ExecutableHeapHandle, ExecutableHeapHandle, NULL); - if (ExistingValue != NULL) - { - HeapDestroy(ExecutableHeapHandle); - } - } - - return g_ExecutableHeapHandle; -} - -const CExecutable executable = { 0 }; - -void * __cdecl operator new(size_t n, const CExecutable&) -{ -#if defined(_DEBUG_IMPL) - CLRThrowsExceptionWorker(); -#endif - - STATIC_CONTRACT_THROWS; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FAULT; - - HANDLE hExecutableHeap = ClrGetProcessExecutableHeap(); - if (hExecutableHeap == NULL) { - ThrowOutOfMemory(); - } - - void * result = HeapAlloc(hExecutableHeap, 0, n); - if (result == NULL) { - ThrowOutOfMemory(); + ReportOOM(size); } TRASH_LASTERROR; return result; } -void * __cdecl operator new[](size_t n, const CExecutable&) +void* __cdecl operator new[](size_t size, const std::nothrow_t&) noexcept { -#if defined(_DEBUG_IMPL) - CLRThrowsExceptionWorker(); -#endif - - STATIC_CONTRACT_THROWS; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FAULT; - - HANDLE hExecutableHeap = ClrGetProcessExecutableHeap(); - if (hExecutableHeap == NULL) { - ThrowOutOfMemory(); - } - - void * result = HeapAlloc(hExecutableHeap, 0, n); - if (result == NULL) { - ThrowOutOfMemory(); - } - TRASH_LASTERROR; - return result; + return ::operator new(size, std::nothrow); } -void * __cdecl operator new(size_t n, const CExecutable&, const std::nothrow_t&) noexcept +void __cdecl operator delete(void* p) noexcept { STATIC_CONTRACT_NOTHROW; STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FAULT; - - INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN())); + STATIC_CONTRACT_SUPPORTS_DAC_HOST_ONLY; - HANDLE hExecutableHeap = ClrGetProcessExecutableHeap(); - if (hExecutableHeap == NULL) - return NULL; + free(p); - void * result = HeapAlloc(hExecutableHeap, 0, n); TRASH_LASTERROR; - return result; } -void * __cdecl operator new[](size_t n, const CExecutable&, const std::nothrow_t&) noexcept +void __cdecl operator delete[](void* p) noexcept { - STATIC_CONTRACT_NOTHROW; - STATIC_CONTRACT_GC_NOTRIGGER; - STATIC_CONTRACT_FAULT; - - INCONTRACT(_ASSERTE(!ARE_FAULTS_FORBIDDEN())); - - HANDLE hExecutableHeap = ClrGetProcessExecutableHeap(); - if (hExecutableHeap == NULL) - return NULL; - - void * result = HeapAlloc(hExecutableHeap, 0, n); - TRASH_LASTERROR; - return result; + ::operator delete(p); } -#endif // HOST_WINDOWS +#endif // !HAS_ADDRESS_SANITIZER && !DACCESS_COMPILE #ifdef _DEBUG @@ -518,7 +304,7 @@ void * __cdecl operator new[](size_t n, const CExecutable&, const std::nothrow_t BOOL DbgIsExecutable(LPVOID lpMem, SIZE_T length) { #if defined(TARGET_UNIX) - // No NX support on PAL or for crossgen compilations. + // No NX support on PAL return TRUE; #else // !(TARGET_UNIX) BYTE *regionStart = (BYTE*) ALIGN_DOWN((BYTE*)lpMem, GetOsPageSize()); diff --git a/src/coreclr/utilcode/hostimpl.cpp b/src/coreclr/utilcode/hostimpl.cpp index c1e4b53b065a55..4ba20554c824c8 100644 --- a/src/coreclr/utilcode/hostimpl.cpp +++ b/src/coreclr/utilcode/hostimpl.cpp @@ -43,10 +43,6 @@ DWORD ClrSleepEx(DWORD dwMilliseconds, BOOL bAlertable) LPVOID ClrVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect) { -#ifdef FAILPOINTS_ENABLED - if (RFS_HashStack ()) - return NULL; -#endif return VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect); } diff --git a/src/coreclr/vm/hosting.cpp b/src/coreclr/vm/hosting.cpp index 3482781620be80..065b254dee4047 100644 --- a/src/coreclr/vm/hosting.cpp +++ b/src/coreclr/vm/hosting.cpp @@ -16,12 +16,6 @@ LPVOID ClrVirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, } CONTRACTL_END; -#ifdef FAILPOINTS_ENABLED - if (RFS_HashStack ()) - return NULL; -#endif - - #ifdef _DEBUG if (g_fEEStarted) { // On Debug build we make sure that a thread is not going to do memory allocation