From bcfa8e7425de615e6755620a0ffea89588b8d64c Mon Sep 17 00:00:00 2001 From: Sean Gillespie Date: Thu, 23 Mar 2017 18:40:56 -0700 Subject: [PATCH] [Local GC] Redirect fatal errors to the EE (dotnet/coreclr#10436) * [Local GC] Redirect fatal errors to the EE * Address code review feedback: don't fetch the IP when reporting a fatal error Commit migrated from https://github.com/dotnet/coreclr/commit/b04644c55ae003bd1c6c8fefe33d5dfe6ef240f0 --- src/coreclr/src/gc/env/gcenv.ee.h | 2 ++ src/coreclr/src/gc/gc.cpp | 4 ++-- src/coreclr/src/gc/gcenv.ee.standalone.inl | 6 ++++++ src/coreclr/src/gc/gcinterface.ee.h | 4 ++++ src/coreclr/src/gc/sample/gcenv.ee.cpp | 5 +++++ src/coreclr/src/vm/gcenv.ee.cpp | 4 ++++ src/coreclr/src/vm/gcenv.ee.h | 1 + 7 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/gc/env/gcenv.ee.h b/src/coreclr/src/gc/env/gcenv.ee.h index 9f7f266..689b1cc 100644 --- a/src/coreclr/src/gc/env/gcenv.ee.h +++ b/src/coreclr/src/gc/env/gcenv.ee.h @@ -68,6 +68,8 @@ public: static void StompWriteBarrier(WriteBarrierParameters* args); static void EnableFinalization(bool foundFinalizers); + + static void HandleFatalError(unsigned int exitCode); }; #endif // __GCENV_EE_H__ diff --git a/src/coreclr/src/gc/gc.cpp b/src/coreclr/src/gc/gc.cpp index 1a5072e..a1a691e 100644 --- a/src/coreclr/src/gc/gc.cpp +++ b/src/coreclr/src/gc/gc.cpp @@ -17496,7 +17496,7 @@ void gc_heap::enque_pinned_plug (uint8_t* plug, // risks. This happens very rarely and fixing it in the // way so that we can continue is a bit involved and will // not be done in Dev10. - EEPOLICY_HANDLE_FATAL_ERROR(CORINFO_EXCEPTION_GC); + GCToEEInterface::HandleFatalError(CORINFO_EXCEPTION_GC); } } @@ -25002,7 +25002,7 @@ void gc_heap::gc_thread_stub (void* arg) #else STRESS_LOG0(LF_GC, LL_ALWAYS, "Thread::CommitThreadStack failed."); _ASSERTE(!"Thread::CommitThreadStack failed."); - EEPOLICY_HANDLE_FATAL_ERROR(COR_E_STACKOVERFLOW); + GCToEEInterface::HandleFatalError(COR_E_STACKOVERFLOW); #endif //BACKGROUND_GC } #endif // FEATURE_REDHAWK diff --git a/src/coreclr/src/gc/gcenv.ee.standalone.inl b/src/coreclr/src/gc/gcenv.ee.standalone.inl index 31f3d1d..c391ef8 100644 --- a/src/coreclr/src/gc/gcenv.ee.standalone.inl +++ b/src/coreclr/src/gc/gcenv.ee.standalone.inl @@ -207,6 +207,12 @@ ALWAYS_INLINE void GCToEEInterface::EnableFinalization(bool foundFinalizers) g_theGCToCLR->EnableFinalization(foundFinalizers); } +ALWAYS_INLINE void GCToEEInterface::HandleFatalError(unsigned int exitCode) +{ + assert(g_theGCToCLR != nullptr); + g_theGCToCLR->HandleFatalError(exitCode); +} + #undef ALWAYS_INLINE #endif // __GCTOENV_EE_STANDALONE_INL__ diff --git a/src/coreclr/src/gc/gcinterface.ee.h b/src/coreclr/src/gc/gcinterface.ee.h index 7c0eea2..da74665 100644 --- a/src/coreclr/src/gc/gcinterface.ee.h +++ b/src/coreclr/src/gc/gcinterface.ee.h @@ -133,6 +133,10 @@ public: // be finalized. virtual void EnableFinalization(bool foundFinalizers) = 0; + + // Signals to the EE that the GC encountered a fatal error and can't recover. + virtual + void HandleFatalError(unsigned int exitCode) = 0; }; #endif // _GCINTERFACE_EE_H_ diff --git a/src/coreclr/src/gc/sample/gcenv.ee.cpp b/src/coreclr/src/gc/sample/gcenv.ee.cpp index 8403bba..b339fcc 100644 --- a/src/coreclr/src/gc/sample/gcenv.ee.cpp +++ b/src/coreclr/src/gc/sample/gcenv.ee.cpp @@ -265,6 +265,11 @@ void GCToEEInterface::EnableFinalization(bool foundFinalizers) // TODO: Implement for finalization } +void GCToEEInterface::HandleFatalError(unsigned int exitCode) +{ + abort(); +} + bool IsGCSpecialThread() { // TODO: Implement for background GC diff --git a/src/coreclr/src/vm/gcenv.ee.cpp b/src/coreclr/src/vm/gcenv.ee.cpp index 380c31a..bf2ce2c 100644 --- a/src/coreclr/src/vm/gcenv.ee.cpp +++ b/src/coreclr/src/vm/gcenv.ee.cpp @@ -1340,3 +1340,7 @@ void GCToEEInterface::EnableFinalization(bool foundFinalizers) } } +void GCToEEInterface::HandleFatalError(unsigned int exitCode) +{ + EEPOLICY_HANDLE_FATAL_ERROR(exitCode); +} diff --git a/src/coreclr/src/vm/gcenv.ee.h b/src/coreclr/src/vm/gcenv.ee.h index a7ab0b5..e3ced6c 100644 --- a/src/coreclr/src/vm/gcenv.ee.h +++ b/src/coreclr/src/vm/gcenv.ee.h @@ -44,6 +44,7 @@ public: void StompWriteBarrier(WriteBarrierParameters* args); void EnableFinalization(bool foundFinalizers); + void HandleFatalError(unsigned int exitCode); }; #endif // FEATURE_STANDALONE_GC -- 2.7.4