#ifdef FEATURE_PAL
//---------------------------------------------------------------------------------------
//
-// This functions return True if the given stack address is
-// within the specified stack boundaries.
-//
-// Arguments:
-// sp - a stack pointer that needs to be verified
-// stackLowAddress, stackHighAddress - these values specify stack boundaries
-//
-bool IsSpInStackLimits(ULONG64 sp, ULONG64 stackLowAddress, ULONG64 stackHighAddress)
-{
- return ((sp > stackLowAddress) && (sp < stackHighAddress));
-}
-
-//---------------------------------------------------------------------------------------
-//
// This function initiates unwinding of native frames during the unwinding of a managed
// exception. The managed exception can be propagated over several managed / native ranges
// until it is finally handled by a managed handler or leaves the stack unhandled and
EECodeInfo codeInfo;
UINT_PTR establisherFrame = NULL;
PVOID handlerData;
- ULONG64 stackHighAddress = (ULONG64)PAL_GetStackBase();
- ULONG64 stackLowAddress = (ULONG64)PAL_GetStackLimit();
// Indicate that we are performing second pass.
ex.ExceptionRecord.ExceptionFlags = EXCEPTION_UNWINDING;
// Make sure that the establisher frame pointer is within stack boundaries
// and we did not go below that target frame.
// TODO: make sure the establisher frame is properly aligned.
- if (!IsSpInStackLimits(establisherFrame, stackLowAddress, stackHighAddress) ||
- establisherFrame > ex.TargetFrameSp)
+ if (!Thread::IsAddressInCurrentStack((void*)establisherFrame) || establisherFrame > ex.TargetFrameSp)
{
// TODO: add better error handling
UNREACHABLE();
UNREACHABLE();
}
- } while (IsSpInStackLimits(GetSP(currentFrameContext), stackLowAddress, stackHighAddress) &&
- (establisherFrame != ex.TargetFrameSp));
+ } while (Thread::IsAddressInCurrentStack((void*)GetSP(currentFrameContext)) && (establisherFrame != ex.TargetFrameSp));
_ASSERTE(!"UnwindManagedExceptionPass2: Unwinding failed. Reached the end of the stack");
EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE);
UINT_PTR controlPc;
UINT_PTR establisherFrame = NULL;
PVOID handlerData;
- ULONG64 stackHighAddress = (ULONG64)PAL_GetStackBase();
- ULONG64 stackLowAddress = (ULONG64)PAL_GetStackLimit();
#ifdef FEATURE_HIJACK
GetThread()->UnhijackThread();
// Make sure that the establisher frame pointer is within stack boundaries.
// TODO: make sure the establisher frame is properly aligned.
- if (!IsSpInStackLimits(establisherFrame, stackLowAddress, stackHighAddress))
+ if (!Thread::IsAddressInCurrentStack((void*)establisherFrame))
{
// TODO: add better error handling
UNREACHABLE();
}
}
- } while (IsSpInStackLimits(GetSP(&frameContext), stackLowAddress, stackHighAddress));
+ } while (Thread::IsAddressInCurrentStack((void*)GetSP(&frameContext)));
_ASSERTE(!"UnwindManagedExceptionPass1: Failed to find a handler. Reached the end of the stack");
EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE);
public:
BOOL IsAddressInStack (PTR_VOID addr) const { return TRUE; }
+ static BOOL IsAddressInCurrentStack (PTR_VOID addr) { return TRUE; }
Frame *IsRunningIn(AppDomain* pDomain, int *count) { return NULL; }
return m_CacheStackLimit < addr && addr <= m_CacheStackBase;
}
+ static BOOL IsAddressInCurrentStack (PTR_VOID addr)
+ {
+ LIMITED_METHOD_DAC_CONTRACT;
+ Thread* currentThread = GetThread();
+ if (currentThread == NULL)
+ {
+ return FALSE;
+ }
+
+ PTR_VOID sp = dac_cast<PTR_VOID>(GetCurrentSP());
+ _ASSERTE(currentThread->m_CacheStackBase != NULL);
+ _ASSERTE(sp < currentThread->m_CacheStackBase);
+ return sp < addr && addr <= currentThread->m_CacheStackBase;
+ }
+
// DetermineIfGuardPagePresent returns TRUE if the thread's stack contains a proper guard page. This function
// makes a physical check of the stack, rather than relying on whether or not the CLR is currently processing a
// stack overflow exception.
// CanResetStackTo will return TRUE if the given stack pointer is far enough away from the guard page to proper
// restore the guard page with RestoreGuardPage.
BOOL CanResetStackTo(LPCVOID stackPointer);
-#endif
// IsStackSpaceAvailable will return true if there are the given number of stack pages available on the stack.
BOOL IsStackSpaceAvailable(float numPages);
+
+#endif
// Returns the amount of stack available after an SO but before the OS rips the process.
static UINT_PTR GetStackGuarantee();