Skip to content

Commit d01ebfe

Browse files
authored
Remove ThreadNative_GetProcessDefaultStackSize (#102003)
* Remove ThreadNative_GetProcessDefaultStackSize * Remove PEDecoder::CheckWillCreateGuardPage
1 parent c5301c4 commit d01ebfe

9 files changed

+1
-214
lines changed

src/coreclr/inc/pedecoder.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,6 @@ class PEDecoder
309309
BOOL HasReadyToRunHeader() const;
310310
READYTORUN_HEADER *GetReadyToRunHeader() const;
311311

312-
void GetEXEStackSizes(SIZE_T *PE_SizeOfStackReserve, SIZE_T *PE_SizeOfStackCommit) const;
313-
314-
CHECK CheckWillCreateGuardPage() const;
315-
316312
// Native DLLMain Entrypoint
317313
BOOL HasNativeEntryPoint() const;
318314
void *GetNativeEntryPoint() const;

src/coreclr/inc/pedecoder.inl

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -411,42 +411,6 @@ inline WORD PEDecoder::GetCharacteristics() const
411411
return VAL16(FindNTHeaders()->FileHeader.Characteristics);
412412
}
413413

414-
inline SIZE_T PEDecoder::GetSizeOfStackReserve() const
415-
{
416-
CONTRACTL
417-
{
418-
INSTANCE_CHECK;
419-
PRECONDITION(CheckNTHeaders());
420-
NOTHROW;
421-
GC_NOTRIGGER;
422-
}
423-
CONTRACTL_END;
424-
425-
if (Has32BitNTHeaders())
426-
return (SIZE_T) VAL32(GetNTHeaders32()->OptionalHeader.SizeOfStackReserve);
427-
else
428-
return (SIZE_T) VAL64(GetNTHeaders64()->OptionalHeader.SizeOfStackReserve);
429-
}
430-
431-
432-
inline SIZE_T PEDecoder::GetSizeOfStackCommit() const
433-
{
434-
CONTRACTL
435-
{
436-
INSTANCE_CHECK;
437-
PRECONDITION(CheckNTHeaders());
438-
NOTHROW;
439-
GC_NOTRIGGER;
440-
}
441-
CONTRACTL_END;
442-
443-
if (Has32BitNTHeaders())
444-
return (SIZE_T) VAL32(GetNTHeaders32()->OptionalHeader.SizeOfStackCommit);
445-
else
446-
return (SIZE_T) VAL64(GetNTHeaders64()->OptionalHeader.SizeOfStackCommit);
447-
}
448-
449-
450414
inline SIZE_T PEDecoder::GetSizeOfHeapReserve() const
451415
{
452416
CONTRACTL

src/coreclr/inc/utilcode.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3718,8 +3718,6 @@ namespace util
37183718

37193719
INDEBUG(BOOL DbgIsExecutable(LPVOID lpMem, SIZE_T length);)
37203720

3721-
BOOL ThreadWillCreateGuardPage(SIZE_T sizeReservedStack, SIZE_T sizeCommittedStack);
3722-
37233721
#ifdef FEATURE_COMINTEROP
37243722
FORCEINLINE void HolderSysFreeString(BSTR str) { CONTRACT_VIOLATION(ThrowsViolation); SysFreeString(str); }
37253723

src/coreclr/utilcode/pedecoder.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ CHECK PEDecoder::CheckFormat() const
3535

3636
if (IsILOnly())
3737
CHECK(CheckILOnly());
38-
39-
CHECK(CheckWillCreateGuardPage());
4038
}
4139
}
4240

@@ -2435,44 +2433,6 @@ PTR_CVOID PEDecoder::GetNativeManifestMetadata(COUNT_T *pSize) const
24352433
RETURN dac_cast<PTR_VOID>(GetDirectoryData(pDir));
24362434
}
24372435

2438-
// Get the SizeOfStackReserve and SizeOfStackCommit from the PE file that was used to create
2439-
// the calling process (.exe file).
2440-
void PEDecoder::GetEXEStackSizes(SIZE_T *PE_SizeOfStackReserve, SIZE_T *PE_SizeOfStackCommit) const
2441-
{
2442-
CONTRACTL {
2443-
PRECONDITION(!IsDll()); // This routine should only be called for EXE files.
2444-
NOTHROW;
2445-
GC_NOTRIGGER;
2446-
} CONTRACTL_END;
2447-
2448-
* PE_SizeOfStackReserve = GetSizeOfStackReserve();
2449-
* PE_SizeOfStackCommit = GetSizeOfStackCommit();
2450-
}
2451-
2452-
CHECK PEDecoder::CheckWillCreateGuardPage() const
2453-
{
2454-
CONTRACT_CHECK
2455-
{
2456-
PRECONDITION(CheckNTHeaders());
2457-
NOTHROW;
2458-
GC_NOTRIGGER;
2459-
}
2460-
CONTRACT_CHECK_END;
2461-
2462-
if (!IsDll())
2463-
{
2464-
SIZE_T sizeReservedStack = 0;
2465-
SIZE_T sizeCommittedStack = 0;
2466-
2467-
GetEXEStackSizes(&sizeReservedStack, &sizeCommittedStack);
2468-
2469-
CHECK(ThreadWillCreateGuardPage(sizeReservedStack, sizeCommittedStack));
2470-
2471-
}
2472-
2473-
CHECK_OK;
2474-
}
2475-
24762436
BOOL PEDecoder::HasNativeEntryPoint() const
24772437
{
24782438
CONTRACTL {

src/coreclr/utilcode/util_nodependencies.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -730,45 +730,3 @@ void OutputDebugStringUtf8(LPCUTF8 utf8DebugMsg)
730730
OutputDebugStringW(wideDebugMsg);
731731
#endif // !TARGET_UNIX
732732
}
733-
734-
BOOL ThreadWillCreateGuardPage(SIZE_T sizeReservedStack, SIZE_T sizeCommittedStack)
735-
{
736-
// We need to make sure there will be a reserved but never committed page at the end
737-
// of the stack. We do here the check NT does when it creates the user stack to decide
738-
// if there is going to be a guard page. However, that is not enough, as if we only
739-
// have a guard page, we have nothing to protect us from going pass it. Well, in
740-
// fact, there is something that we will protect you, there are certain places
741-
// (RTLUnwind) in NT that will check that the current frame is within stack limits.
742-
// If we are not it will bomb out. We will also bomb out if we touch the hard guard
743-
// page.
744-
//
745-
// For situation B, teb->StackLimit is at the beginning of the user stack (ie
746-
// before updating StackLimit it checks if it was able to create a new guard page,
747-
// in this case, it can't), which makes the check fail in RtlUnwind.
748-
//
749-
// Situation A [ Hard guard page | Guard page | user stack]
750-
//
751-
// Situation B [ Guard page | User stack ]
752-
//
753-
// Situation C [ User stack ( no room for guard page) ]
754-
//
755-
// Situation D (W9x) : Guard page or not, w9x has a 64k reserved region below
756-
// the stack, we don't need any checks at all
757-
//
758-
// We really want to be in situation A all the time, so we add one more page
759-
// to our requirements (we require guard page + hard guard)
760-
761-
SYSTEM_INFO sysInfo;
762-
::GetSystemInfo(&sysInfo);
763-
764-
// OS rounds up sizes the following way to decide if it marks a guard page
765-
sizeReservedStack = ALIGN(sizeReservedStack, ((size_t)sysInfo.dwAllocationGranularity)); // Allocation granularity
766-
sizeCommittedStack = ALIGN(sizeCommittedStack, ((size_t)sysInfo.dwPageSize)); // Page Size
767-
768-
// OS wont create guard page, we can't execute managed code safely.
769-
// We also have to make sure we have a 'hard' guard, thus we add another
770-
// page to the memory we would need comitted.
771-
// That is, the following code will check if sizeReservedStack is at least 2 pages
772-
// more than sizeCommittedStack.
773-
return (sizeReservedStack > sizeCommittedStack + ((size_t)sysInfo.dwPageSize));
774-
} // ThreadWillCreateGuardPage

src/coreclr/vm/comsynchronizable.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -913,25 +913,6 @@ void ThreadNative::InformThreadNameChange(Thread* pThread, LPCWSTR name, INT32 l
913913
#endif // DEBUGGING_SUPPORTED
914914
}
915915

916-
extern "C" UINT64 QCALLTYPE ThreadNative_GetProcessDefaultStackSize()
917-
{
918-
QCALL_CONTRACT;
919-
920-
SIZE_T reserve = 0;
921-
SIZE_T commit = 0;
922-
923-
BEGIN_QCALL;
924-
925-
if (!Thread::GetProcessDefaultStackSize(&reserve, &commit))
926-
reserve = 1024 * 1024;
927-
928-
END_QCALL;
929-
930-
return (UINT64)reserve;
931-
}
932-
933-
934-
935916
FCIMPL1(FC_BOOL_RET, ThreadNative::IsThreadpoolThread, ThreadBaseObject* thread)
936917
{
937918
FCALL_CONTRACT;

src/coreclr/vm/comsynchronizable.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ friend class ThreadBaseObject;
9090
extern "C" void QCALLTYPE ThreadNative_Start(QCall::ThreadHandle thread, int threadStackSize, int priority, PCWSTR pThreadName);
9191
extern "C" void QCALLTYPE ThreadNative_SetIsBackground(QCall::ThreadHandle thread, BOOL value);
9292
extern "C" void QCALLTYPE ThreadNative_InformThreadNameChange(QCall::ThreadHandle thread, LPCWSTR name, INT32 len);
93-
extern "C" UINT64 QCALLTYPE ThreadNative_GetProcessDefaultStackSize();
9493
extern "C" BOOL QCALLTYPE ThreadNative_YieldThread();
9594
extern "C" UINT64 QCALLTYPE ThreadNative_GetCurrentOSThreadId();
9695
extern "C" void QCALLTYPE ThreadNative_Abort(QCall::ThreadHandle thread);

src/coreclr/vm/threads.cpp

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,66 +2179,6 @@ SIZE_T GetDefaultStackSizeSetting()
21792179
return (SIZE_T) value;
21802180
}
21812181

2182-
BOOL Thread::GetProcessDefaultStackSize(SIZE_T* reserveSize, SIZE_T* commitSize)
2183-
{
2184-
CONTRACTL
2185-
{
2186-
NOTHROW;
2187-
GC_NOTRIGGER;
2188-
}
2189-
CONTRACTL_END;
2190-
2191-
//
2192-
// Let's get the stack sizes from the PE file that started process.
2193-
//
2194-
static SIZE_T ExeSizeOfStackReserve = 0;
2195-
static SIZE_T ExeSizeOfStackCommit = 0;
2196-
2197-
static BOOL fSizesGot = FALSE;
2198-
2199-
if (!fSizesGot)
2200-
{
2201-
SIZE_T defaultStackSizeSetting = GetDefaultStackSizeSetting();
2202-
2203-
if (defaultStackSizeSetting != 0)
2204-
{
2205-
ExeSizeOfStackReserve = defaultStackSizeSetting;
2206-
ExeSizeOfStackCommit = defaultStackSizeSetting;
2207-
fSizesGot = TRUE;
2208-
}
2209-
}
2210-
2211-
#ifndef TARGET_UNIX
2212-
if (!fSizesGot)
2213-
{
2214-
HINSTANCE hInst = WszGetModuleHandle(NULL);
2215-
_ASSERTE(hInst); // WszGetModuleHandle should never fail on the module that started the process.
2216-
EX_TRY
2217-
{
2218-
PEDecoder pe(hInst);
2219-
pe.GetEXEStackSizes(&ExeSizeOfStackReserve, &ExeSizeOfStackCommit);
2220-
fSizesGot = TRUE;
2221-
}
2222-
EX_CATCH
2223-
{
2224-
fSizesGot = FALSE;
2225-
}
2226-
EX_END_CATCH(SwallowAllExceptions);
2227-
}
2228-
#endif // !TARGET_UNIX
2229-
2230-
if (!fSizesGot) {
2231-
//return some somewhat-reasonable numbers
2232-
if (NULL != reserveSize) *reserveSize = 256*1024;
2233-
if (NULL != commitSize) *commitSize = 256*1024;
2234-
return FALSE;
2235-
}
2236-
2237-
if (NULL != reserveSize) *reserveSize = ExeSizeOfStackReserve;
2238-
if (NULL != commitSize) *commitSize = ExeSizeOfStackCommit;
2239-
return TRUE;
2240-
}
2241-
22422182
BOOL Thread::CreateNewOSThread(SIZE_T sizeToCommitOrReserve, LPTHREAD_START_ROUTINE start, void *args)
22432183
{
22442184
CONTRACTL {

src/coreclr/vm/threads.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,7 +2867,6 @@ class Thread
28672867

28682868
DWORD m_Priority; // initialized to INVALID_THREAD_PRIORITY, set to actual priority when a
28692869
// thread does a busy wait for GC, reset to INVALID_THREAD_PRIORITY after wait is over
2870-
friend class NDirect; // Quick access to thread stub creation
28712870

28722871
#ifdef HAVE_GCCOVER
28732872
friend void DoGcStress (PT_CONTEXT regs, NativeCodeVersion nativeCodeVersion); // Needs to call UnhijackThread
@@ -3663,14 +3662,6 @@ class Thread
36633662
#endif // defined(GCCOVER_TOLERATE_SPURIOUS_AV)
36643663
#endif // HAVE_GCCOVER
36653664

3666-
public:
3667-
static BOOL CheckThreadStackSize(SIZE_T *SizeToCommitOrReserve,
3668-
BOOL isSizeToReserve // When TRUE, the previous argument is the stack size to reserve.
3669-
// Otherwise, it is the size to commit.
3670-
);
3671-
3672-
static BOOL GetProcessDefaultStackSize(SIZE_T* reserveSize, SIZE_T* commitSize);
3673-
36743665
private:
36753666

36763667
// Although this is a pointer, it is used as a flag to indicate the current context is unsafe
@@ -4072,7 +4063,7 @@ struct cdac_offsets<Thread>
40724063
static constexpr size_t ExposedObject = offsetof(Thread, m_ExposedObject);
40734064
static constexpr size_t Link = offsetof(Thread, m_Link);
40744065
};
4075-
4066+
40764067
// End of class Thread
40774068

40784069
typedef Thread::ForbidSuspendThreadHolder ForbidSuspendThreadHolder;

0 commit comments

Comments
 (0)