diff --git a/src/coreclr/inc/pedecoder.h b/src/coreclr/inc/pedecoder.h index efd0555a4f7b9f..057dfa9a25de61 100644 --- a/src/coreclr/inc/pedecoder.h +++ b/src/coreclr/inc/pedecoder.h @@ -309,10 +309,6 @@ class PEDecoder BOOL HasReadyToRunHeader() const; READYTORUN_HEADER *GetReadyToRunHeader() const; - void GetEXEStackSizes(SIZE_T *PE_SizeOfStackReserve, SIZE_T *PE_SizeOfStackCommit) const; - - CHECK CheckWillCreateGuardPage() const; - // Native DLLMain Entrypoint BOOL HasNativeEntryPoint() const; void *GetNativeEntryPoint() const; diff --git a/src/coreclr/inc/pedecoder.inl b/src/coreclr/inc/pedecoder.inl index 4e8d9c1b645a94..7257bd9a78a529 100644 --- a/src/coreclr/inc/pedecoder.inl +++ b/src/coreclr/inc/pedecoder.inl @@ -411,42 +411,6 @@ inline WORD PEDecoder::GetCharacteristics() const return VAL16(FindNTHeaders()->FileHeader.Characteristics); } -inline SIZE_T PEDecoder::GetSizeOfStackReserve() const -{ - CONTRACTL - { - INSTANCE_CHECK; - PRECONDITION(CheckNTHeaders()); - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - if (Has32BitNTHeaders()) - return (SIZE_T) VAL32(GetNTHeaders32()->OptionalHeader.SizeOfStackReserve); - else - return (SIZE_T) VAL64(GetNTHeaders64()->OptionalHeader.SizeOfStackReserve); -} - - -inline SIZE_T PEDecoder::GetSizeOfStackCommit() const -{ - CONTRACTL - { - INSTANCE_CHECK; - PRECONDITION(CheckNTHeaders()); - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - if (Has32BitNTHeaders()) - return (SIZE_T) VAL32(GetNTHeaders32()->OptionalHeader.SizeOfStackCommit); - else - return (SIZE_T) VAL64(GetNTHeaders64()->OptionalHeader.SizeOfStackCommit); -} - - inline SIZE_T PEDecoder::GetSizeOfHeapReserve() const { CONTRACTL diff --git a/src/coreclr/inc/utilcode.h b/src/coreclr/inc/utilcode.h index aee6e75713c49e..01f4da28d47939 100644 --- a/src/coreclr/inc/utilcode.h +++ b/src/coreclr/inc/utilcode.h @@ -3718,8 +3718,6 @@ namespace util INDEBUG(BOOL DbgIsExecutable(LPVOID lpMem, SIZE_T length);) -BOOL ThreadWillCreateGuardPage(SIZE_T sizeReservedStack, SIZE_T sizeCommittedStack); - #ifdef FEATURE_COMINTEROP FORCEINLINE void HolderSysFreeString(BSTR str) { CONTRACT_VIOLATION(ThrowsViolation); SysFreeString(str); } diff --git a/src/coreclr/utilcode/pedecoder.cpp b/src/coreclr/utilcode/pedecoder.cpp index d8f2ff2fe98acb..8aae56853d3a6f 100644 --- a/src/coreclr/utilcode/pedecoder.cpp +++ b/src/coreclr/utilcode/pedecoder.cpp @@ -35,8 +35,6 @@ CHECK PEDecoder::CheckFormat() const if (IsILOnly()) CHECK(CheckILOnly()); - - CHECK(CheckWillCreateGuardPage()); } } @@ -2435,44 +2433,6 @@ PTR_CVOID PEDecoder::GetNativeManifestMetadata(COUNT_T *pSize) const RETURN dac_cast(GetDirectoryData(pDir)); } -// Get the SizeOfStackReserve and SizeOfStackCommit from the PE file that was used to create -// the calling process (.exe file). -void PEDecoder::GetEXEStackSizes(SIZE_T *PE_SizeOfStackReserve, SIZE_T *PE_SizeOfStackCommit) const -{ - CONTRACTL { - PRECONDITION(!IsDll()); // This routine should only be called for EXE files. - NOTHROW; - GC_NOTRIGGER; - } CONTRACTL_END; - - * PE_SizeOfStackReserve = GetSizeOfStackReserve(); - * PE_SizeOfStackCommit = GetSizeOfStackCommit(); -} - -CHECK PEDecoder::CheckWillCreateGuardPage() const -{ - CONTRACT_CHECK - { - PRECONDITION(CheckNTHeaders()); - NOTHROW; - GC_NOTRIGGER; - } - CONTRACT_CHECK_END; - - if (!IsDll()) - { - SIZE_T sizeReservedStack = 0; - SIZE_T sizeCommittedStack = 0; - - GetEXEStackSizes(&sizeReservedStack, &sizeCommittedStack); - - CHECK(ThreadWillCreateGuardPage(sizeReservedStack, sizeCommittedStack)); - - } - - CHECK_OK; -} - BOOL PEDecoder::HasNativeEntryPoint() const { CONTRACTL { diff --git a/src/coreclr/utilcode/util_nodependencies.cpp b/src/coreclr/utilcode/util_nodependencies.cpp index 39bf51a02a4a63..c4b79ec832a41e 100644 --- a/src/coreclr/utilcode/util_nodependencies.cpp +++ b/src/coreclr/utilcode/util_nodependencies.cpp @@ -730,45 +730,3 @@ void OutputDebugStringUtf8(LPCUTF8 utf8DebugMsg) OutputDebugStringW(wideDebugMsg); #endif // !TARGET_UNIX } - -BOOL ThreadWillCreateGuardPage(SIZE_T sizeReservedStack, SIZE_T sizeCommittedStack) -{ - // We need to make sure there will be a reserved but never committed page at the end - // of the stack. We do here the check NT does when it creates the user stack to decide - // if there is going to be a guard page. However, that is not enough, as if we only - // have a guard page, we have nothing to protect us from going pass it. Well, in - // fact, there is something that we will protect you, there are certain places - // (RTLUnwind) in NT that will check that the current frame is within stack limits. - // If we are not it will bomb out. We will also bomb out if we touch the hard guard - // page. - // - // For situation B, teb->StackLimit is at the beginning of the user stack (ie - // before updating StackLimit it checks if it was able to create a new guard page, - // in this case, it can't), which makes the check fail in RtlUnwind. - // - // Situation A [ Hard guard page | Guard page | user stack] - // - // Situation B [ Guard page | User stack ] - // - // Situation C [ User stack ( no room for guard page) ] - // - // Situation D (W9x) : Guard page or not, w9x has a 64k reserved region below - // the stack, we don't need any checks at all - // - // We really want to be in situation A all the time, so we add one more page - // to our requirements (we require guard page + hard guard) - - SYSTEM_INFO sysInfo; - ::GetSystemInfo(&sysInfo); - - // OS rounds up sizes the following way to decide if it marks a guard page - sizeReservedStack = ALIGN(sizeReservedStack, ((size_t)sysInfo.dwAllocationGranularity)); // Allocation granularity - sizeCommittedStack = ALIGN(sizeCommittedStack, ((size_t)sysInfo.dwPageSize)); // Page Size - - // OS wont create guard page, we can't execute managed code safely. - // We also have to make sure we have a 'hard' guard, thus we add another - // page to the memory we would need comitted. - // That is, the following code will check if sizeReservedStack is at least 2 pages - // more than sizeCommittedStack. - return (sizeReservedStack > sizeCommittedStack + ((size_t)sysInfo.dwPageSize)); -} // ThreadWillCreateGuardPage diff --git a/src/coreclr/vm/comsynchronizable.cpp b/src/coreclr/vm/comsynchronizable.cpp index ff09cb362daef3..7cfee71b92c9ed 100644 --- a/src/coreclr/vm/comsynchronizable.cpp +++ b/src/coreclr/vm/comsynchronizable.cpp @@ -913,25 +913,6 @@ void ThreadNative::InformThreadNameChange(Thread* pThread, LPCWSTR name, INT32 l #endif // DEBUGGING_SUPPORTED } -extern "C" UINT64 QCALLTYPE ThreadNative_GetProcessDefaultStackSize() -{ - QCALL_CONTRACT; - - SIZE_T reserve = 0; - SIZE_T commit = 0; - - BEGIN_QCALL; - - if (!Thread::GetProcessDefaultStackSize(&reserve, &commit)) - reserve = 1024 * 1024; - - END_QCALL; - - return (UINT64)reserve; -} - - - FCIMPL1(FC_BOOL_RET, ThreadNative::IsThreadpoolThread, ThreadBaseObject* thread) { FCALL_CONTRACT; diff --git a/src/coreclr/vm/comsynchronizable.h b/src/coreclr/vm/comsynchronizable.h index 4d14461602d55f..b0f5b72295a155 100644 --- a/src/coreclr/vm/comsynchronizable.h +++ b/src/coreclr/vm/comsynchronizable.h @@ -90,7 +90,6 @@ friend class ThreadBaseObject; extern "C" void QCALLTYPE ThreadNative_Start(QCall::ThreadHandle thread, int threadStackSize, int priority, PCWSTR pThreadName); extern "C" void QCALLTYPE ThreadNative_SetIsBackground(QCall::ThreadHandle thread, BOOL value); extern "C" void QCALLTYPE ThreadNative_InformThreadNameChange(QCall::ThreadHandle thread, LPCWSTR name, INT32 len); -extern "C" UINT64 QCALLTYPE ThreadNative_GetProcessDefaultStackSize(); extern "C" BOOL QCALLTYPE ThreadNative_YieldThread(); extern "C" UINT64 QCALLTYPE ThreadNative_GetCurrentOSThreadId(); extern "C" void QCALLTYPE ThreadNative_Abort(QCall::ThreadHandle thread); diff --git a/src/coreclr/vm/threads.cpp b/src/coreclr/vm/threads.cpp index cbe820f7088a47..747dfa7e68954d 100644 --- a/src/coreclr/vm/threads.cpp +++ b/src/coreclr/vm/threads.cpp @@ -2179,66 +2179,6 @@ SIZE_T GetDefaultStackSizeSetting() return (SIZE_T) value; } -BOOL Thread::GetProcessDefaultStackSize(SIZE_T* reserveSize, SIZE_T* commitSize) -{ - CONTRACTL - { - NOTHROW; - GC_NOTRIGGER; - } - CONTRACTL_END; - - // - // Let's get the stack sizes from the PE file that started process. - // - static SIZE_T ExeSizeOfStackReserve = 0; - static SIZE_T ExeSizeOfStackCommit = 0; - - static BOOL fSizesGot = FALSE; - - if (!fSizesGot) - { - SIZE_T defaultStackSizeSetting = GetDefaultStackSizeSetting(); - - if (defaultStackSizeSetting != 0) - { - ExeSizeOfStackReserve = defaultStackSizeSetting; - ExeSizeOfStackCommit = defaultStackSizeSetting; - fSizesGot = TRUE; - } - } - -#ifndef TARGET_UNIX - if (!fSizesGot) - { - HINSTANCE hInst = WszGetModuleHandle(NULL); - _ASSERTE(hInst); // WszGetModuleHandle should never fail on the module that started the process. - EX_TRY - { - PEDecoder pe(hInst); - pe.GetEXEStackSizes(&ExeSizeOfStackReserve, &ExeSizeOfStackCommit); - fSizesGot = TRUE; - } - EX_CATCH - { - fSizesGot = FALSE; - } - EX_END_CATCH(SwallowAllExceptions); - } -#endif // !TARGET_UNIX - - if (!fSizesGot) { - //return some somewhat-reasonable numbers - if (NULL != reserveSize) *reserveSize = 256*1024; - if (NULL != commitSize) *commitSize = 256*1024; - return FALSE; - } - - if (NULL != reserveSize) *reserveSize = ExeSizeOfStackReserve; - if (NULL != commitSize) *commitSize = ExeSizeOfStackCommit; - return TRUE; -} - BOOL Thread::CreateNewOSThread(SIZE_T sizeToCommitOrReserve, LPTHREAD_START_ROUTINE start, void *args) { CONTRACTL { diff --git a/src/coreclr/vm/threads.h b/src/coreclr/vm/threads.h index 2bee7d56ff1d5a..3fb398e07b577a 100644 --- a/src/coreclr/vm/threads.h +++ b/src/coreclr/vm/threads.h @@ -2867,7 +2867,6 @@ class Thread DWORD m_Priority; // initialized to INVALID_THREAD_PRIORITY, set to actual priority when a // thread does a busy wait for GC, reset to INVALID_THREAD_PRIORITY after wait is over - friend class NDirect; // Quick access to thread stub creation #ifdef HAVE_GCCOVER friend void DoGcStress (PT_CONTEXT regs, NativeCodeVersion nativeCodeVersion); // Needs to call UnhijackThread @@ -3663,14 +3662,6 @@ class Thread #endif // defined(GCCOVER_TOLERATE_SPURIOUS_AV) #endif // HAVE_GCCOVER -public: - static BOOL CheckThreadStackSize(SIZE_T *SizeToCommitOrReserve, - BOOL isSizeToReserve // When TRUE, the previous argument is the stack size to reserve. - // Otherwise, it is the size to commit. - ); - - static BOOL GetProcessDefaultStackSize(SIZE_T* reserveSize, SIZE_T* commitSize); - private: // Although this is a pointer, it is used as a flag to indicate the current context is unsafe @@ -4067,7 +4058,7 @@ struct cdac_offsets static constexpr size_t ExposedObject = offsetof(Thread, m_ExposedObject); static constexpr size_t Link = offsetof(Thread, m_Link); }; - + // End of class Thread typedef Thread::ForbidSuspendThreadHolder ForbidSuspendThreadHolder;