Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/coreclr/classlibnative/bcltype/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ static StackWalkAction FindFailFastCallerCallback(CrawlFrame* frame, VOID* data)
return SWA_ABORT;
}

static thread_local int8_t alreadyFailing = 0;

extern "C" void QCALLTYPE Environment_FailFast(QCall::StackCrawlMarkHandle mark, PCWSTR message, QCall::ObjectHandleOnStack exception, PCWSTR errorSource)
{
QCALL_CONTRACT;
Expand All @@ -143,7 +145,14 @@ extern "C" void QCALLTYPE Environment_FailFast(QCall::StackCrawlMarkHandle mark,

LPCWSTR argExceptionString = NULL;
StackSString msg;
if (exception.Get() != NULL)
// Because Environment_FailFast should kill the process, any subsequent calls are likely nested call from managed while formatting the exception message or the stack trace.
// Only collect exception string if this is the first attempt to fail fast on this thread.
alreadyFailing++;
if (alreadyFailing != 1)
{
argExceptionString = W("Environment.FailFast called recursively.");
}
else if (exception.Get() != NULL)
{
GetExceptionMessage(exception.Get(), msg);
argExceptionString = msg.GetUnicode();
Expand Down
Loading