Fix assert on unhandled SIGSEGV (#47538)
authorJan Vorlicek <jan.vorlicek@volny.cz>
Thu, 28 Jan 2021 13:12:40 +0000 (14:12 +0100)
committerGitHub <noreply@github.com>
Thu, 28 Jan 2021 13:12:40 +0000 (14:12 +0100)
commit2e67553cfa38eee56ca6adc4b9d1e7e11b9f7bc3
tree6d6bad8e0262fdd97128bacf1205555f234eedf9
parent9dd7bf432dfa40cc0651d74bec8a57f3f2084e0c
Fix assert on unhandled SIGSEGV (#47538)

When SIGSEGV is not handled by .NET runtime (e.g. when it occurs in code
out of its control), the SIGSEGV handler ends up calling
DiagnosticServer::Shutdown in the runtime via a registered shutdown callback.
That method ends up calling Thread::GetFrame, which asserts if the
current SP is out of a valid range for the regular stack. The problem is
that SIGSEGV handler is called on an alternate stack and so this
callback ends up being called on that stack too. That causes this
assertion to fail, because the current thread is not marked as executing
on alternate stack, which would skip that assert.

This change fixes it by passing through a bool flag indicating whether
the callback was called on an alternate stack or not. And in that
callback, we set the flag on the thread accordingly.
src/coreclr/pal/inc/pal.h
src/coreclr/pal/src/exception/signal.cpp
src/coreclr/pal/src/include/pal/process.h
src/coreclr/pal/src/thread/process.cpp
src/coreclr/vm/ceemain.cpp