Skip to content

Commit ab50399

Browse files
committed
change how we do our seh failfast
1 parent 7bfaf94 commit ab50399

5 files changed

Lines changed: 18 additions & 5 deletions

File tree

lib/Common/Exceptions/ReportError.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ _NOINLINE void EntryExitRecord_Corrupted_fatal_error()
126126
ReportFatalException(NULL, E_UNEXPECTED, Fatal_EntryExitRecordCorruption, scenario);
127127
}
128128

129-
_NOINLINE void UnexpectedExceptionHandling_fatal_error(EXCEPTION_POINTERS * originalException)
129+
_NOINLINE void UnexpectedExceptionHandling_fatal_error()
130130
{
131131
int scenario = 7;
132132
ReportFatalException(NULL, E_UNEXPECTED, Fatal_UnexpectedExceptionHandling, scenario);

lib/Common/Exceptions/ReportError.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void MarkStack_OOM_fatal_error();
5959
void Binary_Inconsistency_fatal_error();
6060
void Version_Inconsistency_fatal_error();
6161
void EntryExitRecord_Corrupted_fatal_error();
62-
void UnexpectedExceptionHandling_fatal_error(EXCEPTION_POINTERS * originalException);
62+
void UnexpectedExceptionHandling_fatal_error();
6363

6464
#ifdef LARGEHEAPBLOCK_ENCODING
6565
void LargeHeapBlock_Metadata_Corrupted(

lib/Runtime/Base/ThreadContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ ThreadContext::ThreadContext(AllocationPolicyManager * allocationPolicyManager,
186186
jsrtRuntime(nullptr),
187187
propertyMap(nullptr),
188188
rootPendingClose(nullptr),
189+
exceptionCode(0),
189190
isProfilingUserCode(true),
190191
loopDepth(0),
191192
redeferralState(InitialRedeferralState),

lib/Runtime/Base/ThreadContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ class ThreadContext sealed :
710710
int stackProbeCount;
711711
// Count stack probes and poll for continuation every n probes
712712
static const int StackProbePollThreshold = 1000;
713+
EXCEPTION_POINTERS exceptionInfo;
714+
uint32 exceptionCode;
713715

714716
ArenaAllocator inlineCacheThreadInfoAllocator;
715717
ArenaAllocator isInstInlineCacheThreadInfoAllocator;
@@ -866,6 +868,10 @@ class ThreadContext sealed :
866868
#endif
867869
#endif
868870

871+
void SetAbnormalExceptionRecord(EXCEPTION_POINTERS *exceptionInfo) { this->exceptionInfo = *exceptionInfo; }
872+
void SetAbnormalExceptionCode(uint32 exceptionInfo) { this->exceptionCode = exceptionInfo; }
873+
uint32 GetAbnormalExceptionCode() const { return this->exceptionCode; }
874+
869875
#ifdef ENABLE_BASIC_TELEMETRY
870876
GUID activityId;
871877
#endif

lib/Runtime/Library/JavascriptFunction.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,12 @@ namespace Js
670670
// SEH and ResumeForOutOfBoundsArrayRefs are not needed.
671671
ret = CallRootFunctionInternal(args, scriptContext, inScript);
672672
#else
673+
if (scriptContext->GetThreadContext()->GetAbnormalExceptionCode() != 0)
674+
{
675+
// ensure that hosts are not doing SEH across Chakra frames, as that can lead to bad state (e.g. destructors not being called)
676+
UnexpectedExceptionHandling_fatal_error();
677+
}
678+
673679
// mark volatile, because otherwise VC will incorrectly optimize away load in the finally block
674680
volatile uint32 exceptionCode = 0;
675681
volatile int exceptionAction = EXCEPTION_CONTINUE_SEARCH;
@@ -691,10 +697,10 @@ namespace Js
691697
__finally
692698
{
693699
// 0xE06D7363 is C++ exception code
694-
if (exceptionCode != 0 && !IsDebuggerPresent() && exceptionCode != 0xE06D7363 && exceptionAction != EXCEPTION_CONTINUE_EXECUTION)
700+
if (AbnormalTermination() && exceptionCode != 0 && !IsDebuggerPresent() && exceptionCode != 0xE06D7363)
695701
{
696-
// ensure that hosts are not doing SEH across Chakra frames, as that can lead to bad state (e.g. destructors not being called)
697-
UnexpectedExceptionHandling_fatal_error(&exceptionInfo);
702+
scriptContext->GetThreadContext()->SetAbnormalExceptionCode(exceptionCode);
703+
scriptContext->GetThreadContext()->SetAbnormalExceptionRecord(&exceptionInfo);
698704
}
699705
}
700706
#endif

0 commit comments

Comments
 (0)