Skip to content

Commit c78fcf6

Browse files
committed
[MERGE chakra-core#923] add failfast if entryExitRecord list is messed up
Merge pull request chakra-core#923 from MikeHolman:sehchange
2 parents d77265f + ac67ca2 commit c78fcf6

4 files changed

Lines changed: 32 additions & 5 deletions

File tree

lib/Common/Exceptions/ReportError.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,16 @@ __declspec(noinline) void FromDOM_NoScriptScope_fatal_error()
106106
ReportFatalException(NULL, E_UNEXPECTED, EnterScript_FromDOM_NoScriptScope, scenario);
107107
}
108108

109+
__declspec(noinline) void EntryExitRecord_Corrupted_fatal_error()
110+
{
111+
int scenario = 6;
112+
ReportFatalException(NULL, E_UNEXPECTED, Fatal_EntryExitRecordCorruption, scenario);
113+
}
114+
115+
__declspec(noinline) void UnexpectedExceptionHandling_fatal_error(EXCEPTION_POINTERS * originalException)
116+
{
117+
int scenario = 7;
118+
ReportFatalException(NULL, E_UNEXPECTED, Fatal_UnexpectedExceptionHandling, scenario);
119+
}
120+
109121
#pragma optimize("",on)

lib/Common/Exceptions/ReportError.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ enum ErrorReason
1919
MarkStack_OUTOFMEMORY = 11,
2020
EnterScript_FromDOM_NoScriptScope = 12,
2121
Fatal_FailedToBox_OUTOFMEMORY = 13,
22-
Fatal_Recycler_MemoryCorruption = 14
22+
Fatal_Recycler_MemoryCorruption = 14,
23+
Fatal_EntryExitRecordCorruption = 15,
24+
Fatal_UnexpectedExceptionHandling = 16
2325
};
2426

2527
extern "C" void ReportFatalException(
@@ -52,6 +54,8 @@ void MarkStack_OOM_fatal_error();
5254

5355
void Binary_Inconsistency_fatal_error();
5456
void Version_Inconsistency_fatal_error();
57+
void EntryExitRecord_Corrupted_fatal_error();
58+
void UnexpectedExceptionHandling_fatal_error(EXCEPTION_POINTERS * originalException);
5559

5660
#ifdef LARGEHEAPBLOCK_ENCODING
5761
void LargeHeapBlock_Metadata_Corrupted(

lib/Runtime/Base/ThreadContext.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,12 @@ ThreadContext::PushEntryExitRecord(Js::ScriptEntryExitRecord * record)
18721872
Assert(lastRecord->leaveForHost || lastRecord->leaveForAsyncHostOperation);
18731873
lastRecord->hasReentered = true;
18741874
record->next = lastRecord;
1875+
1876+
// these are on stack, which grows down. if this condition doesn't hold, then the list somehow got messed up
1877+
if (!IsOnStack(lastRecord) || (uintptr_t)record >= (uintptr_t)lastRecord)
1878+
{
1879+
EntryExitRecord_Corrupted_fatal_error();
1880+
}
18751881
}
18761882

18771883
this->entryExitRecord = record;
@@ -1881,7 +1887,14 @@ void ThreadContext::PopEntryExitRecord(Js::ScriptEntryExitRecord * record)
18811887
{
18821888
AssertMsg(record && record == this->entryExitRecord, "Mismatch script entry/exit");
18831889

1884-
this->entryExitRecord = this->entryExitRecord->next;
1890+
// these are on stack, which grows down. if this condition doesn't hold, then the list somehow got messed up
1891+
Js::ScriptEntryExitRecord * next = this->entryExitRecord->next;
1892+
if (next && (!IsOnStack(next) || (uintptr_t)this->entryExitRecord >= (uintptr_t)next))
1893+
{
1894+
EntryExitRecord_Corrupted_fatal_error();
1895+
}
1896+
1897+
this->entryExitRecord = next;
18851898
}
18861899

18871900
BOOL ThreadContext::ReserveStaticTypeIds(__in int first, __in int last)

lib/Runtime/Library/JavascriptFunction.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,8 @@ namespace Js
642642
// 0xE06D7363 is C++ exception code
643643
if (exceptionCode != 0 && !IsDebuggerPresent() && exceptionCode != 0xE06D7363 && exceptionAction != EXCEPTION_CONTINUE_EXECUTION)
644644
{
645-
exceptionInfo;
646-
647645
// ensure that hosts are not doing SEH across Chakra frames, as that can lead to bad state (e.g. destructors not being called)
648-
RaiseFailFastException(NULL, NULL, NULL);
646+
UnexpectedExceptionHandling_fatal_error(&exceptionInfo);
649647
}
650648
}
651649
//ret should never be null here

0 commit comments

Comments
 (0)