Skip to content

Commit f03bda5

Browse files
committed
[MERGE chakra-core#761] handle stack overflow in case OS is in low resource state
Merge pull request chakra-core#761 from leirocks:faultinjection_OOS
2 parents 49f5d95 + c97f8d1 commit f03bda5

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

lib/Common/Core/FaultInjection.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ namespace Js
856856
{
857857
faultInjectionDebug = true;
858858
}
859-
if (globalFlags.FaultInjection >= 0 && !IsDebuggerPresent())
859+
if (globalFlags.FaultInjection >= 0)
860860
{
861861
// initialize symbol system here instead of inside the exception filter
862862
// because some hard stack overflow can happen in SymInitialize
@@ -1385,24 +1385,40 @@ namespace Js
13851385
static volatile bool inExceptionHandler = false;
13861386
LONG WINAPI FaultInjection::FaultInjectionExceptionFilter(_In_ struct _EXCEPTION_POINTERS *ExceptionInfo)
13871387
{
1388+
if (inExceptionHandler)
1389+
{
1390+
// re-entering, this can happen if RemoveExceptionFilters() failed because of stack overflow
1391+
// Let it crash and the postmortem debugger can catch it.
1392+
DebugBreak();
1393+
}
1394+
1395+
inExceptionHandler = true;
1396+
13881397
RemoveExceptionFilters();
1398+
13891399
// for debugging, can't hit here in windbg because of using vectored exception handling
13901400
if (faultInjectionDebug)
13911401
{
13921402
DebugBreak();
13931403
}
13941404

1395-
if (inExceptionHandler)
1405+
if (ExceptionInfo->ExceptionRecord->ExceptionCode == STATUS_STACK_OVERFLOW) // hard stack overflow
13961406
{
1397-
// Let it crash and the postmorterm debugger can catch it.
1398-
return EXCEPTION_CONTINUE_EXECUTION;
1407+
DebugBreak(); // let the postmortem debugger to create the dump, make sure they are filing bug with same bucket
1408+
}
1409+
1410+
__try
1411+
{
1412+
// sometimes the OS is really low memory and can't commit page for stack expanding
1413+
// even stack is not deep yet
1414+
FaultInjection::Global.FaultInjectionAnalyzeException(ExceptionInfo);
1415+
}
1416+
__except (EXCEPTION_EXECUTE_HANDLER)
1417+
{
1418+
DebugBreak();
13991419
}
1420+
inExceptionHandler = false;
14001421

1401-
struct AutoValue {
1402-
AutoValue() { inExceptionHandler = true; }
1403-
~AutoValue() { inExceptionHandler = false; }
1404-
} autoVal;
1405-
FaultInjection::Global.FaultInjectionAnalyzeException(ExceptionInfo);
14061422
return EXCEPTION_EXECUTE_HANDLER;
14071423
}
14081424

0 commit comments

Comments
 (0)