}
}
-
-EPolicyAction EEPolicy::DetermineResourceConstraintAction(Thread *pThread)
-{
- CONTRACTL
- {
- NOTHROW;
- GC_NOTRIGGER;
- MODE_ANY;
- }
- CONTRACTL_END;
-
- EPolicyAction action = GetEEPolicy()->GetActionOnFailure(FAIL_CriticalResource);
-
- AppDomain *pDomain = GetAppDomain();
- // If it is default domain, we can not unload the appdomain
- if (pDomain == SystemDomain::System()->DefaultDomain() &&
- (action == eUnloadAppDomain || action == eRudeUnloadAppDomain))
- {
- action = eThrowException;
- }
- return action;
-}
-
-void EEPolicy::PerformResourceConstraintAction(Thread *pThread, EPolicyAction action, UINT exitCode, BOOL haveStack)
- {
- WRAPPER_NO_CONTRACT;
-
- _ASSERTE(GetAppDomain() != NULL);
-
- switch (action) {
- case eThrowException:
- // Caller is going to rethrow.
- return;
- break;
- case eAbortThread:
- pThread->UserAbort(Thread::TAR_Thread, TA_Safe, GetEEPolicy()->GetTimeout(OPR_ThreadAbort), Thread::UAC_Normal);
- break;
- case eRudeAbortThread:
- pThread->UserAbort(Thread::TAR_Thread, TA_Rude, GetEEPolicy()->GetTimeout(OPR_ThreadAbort), Thread::UAC_Normal);
- break;
- case eExitProcess:
- case eFastExitProcess:
- case eRudeExitProcess:
- HandleExitProcessFromEscalation(action, exitCode);
- break;
- default:
- _ASSERTE (!"Invalid policy");
- break;
- }
-}
-
-void EEPolicy::HandleOutOfMemory()
-{
- WRAPPER_NO_CONTRACT;
-
- _ASSERTE (g_pOutOfMemoryExceptionClass);
-
- Thread *pThread = GetThread();
- _ASSERTE (pThread);
-
- EPolicyAction action = DetermineResourceConstraintAction(pThread);
-
- // Check if we are executing in the context of a Constrained Execution Region.
- if (action != eThrowException && Thread::IsExecutingWithinCer())
- {
- // Hitting OOM in a CER region should throw the OOM without regard to the escalation policy
- // since the CER author has declared they are hardened against such failures. That's
- // the whole point of CERs, to denote regions where code knows exactly how to deal with
- // failures in an attempt to minimize the need for rollback or recycling.
- return;
- }
-
- PerformResourceConstraintAction(pThread, action, HOST_E_EXITPROCESS_OUTOFMEMORY, TRUE);
-}
-
//---------------------------------------------------------------------------------------
//
// EEPolicy::HandleStackOverflow - Handle stack overflow according to policy
EPolicyAction GetActionOnFailure(EClrFailure failure);
- static EPolicyAction DetermineResourceConstraintAction(Thread *pThread);
-
- static void PerformResourceConstraintAction(Thread *pThread, EPolicyAction action, UINT exitCode, BOOL haveStack);
-
- static void HandleOutOfMemory();
-
static void HandleStackOverflow();
static void HandleExitProcess(ShutdownCompleteAction sca = SCA_ExitProcessWhenShutdownComplete);