Preserve last error in call-counting stubs (#60886)
authorJan Kotas <jkotas@microsoft.com>
Tue, 26 Oct 2021 22:04:24 +0000 (15:04 -0700)
committerGitHub <noreply@github.com>
Tue, 26 Oct 2021 22:04:24 +0000 (15:04 -0700)
Fixes #60819

src/coreclr/vm/callcounting.cpp

index bdc4bc8..5a3561c 100644 (file)
@@ -715,14 +715,13 @@ extern "C" PCODE STDCALL OnCallCountThresholdReached(TransitionBlock *transition
 
 PCODE CallCountingManager::OnCallCountThresholdReached(TransitionBlock *transitionBlock, TADDR stubIdentifyingToken)
 {
-    CONTRACTL
-    {
-        THROWS;
-        GC_TRIGGERS;
-        MODE_COOPERATIVE;
-        PRECONDITION(CheckPointer(transitionBlock));
-    }
-    CONTRACTL_END;
+    STATIC_CONTRACT_THROWS;
+    STATIC_CONTRACT_GC_TRIGGERS;
+    STATIC_CONTRACT_MODE_COOPERATIVE;
+
+    PCODE codeEntryPoint;
+
+    BEGIN_PRESERVE_LAST_ERROR;
 
     MAKE_CURRENT_THREAD_AVAILABLE();
 
@@ -740,8 +739,6 @@ PCODE CallCountingManager::OnCallCountThresholdReached(TransitionBlock *transiti
     CallCountingHelperFrame *frame = &frameWithCookie;
     frame->Push(CURRENT_THREAD);
 
-    PCODE codeEntryPoint;
-
     INSTALL_MANAGED_EXCEPTION_DISPATCHER;
     INSTALL_UNWIND_AND_CONTINUE_HANDLER;
 
@@ -786,6 +783,9 @@ PCODE CallCountingManager::OnCallCountThresholdReached(TransitionBlock *transiti
     UNINSTALL_MANAGED_EXCEPTION_DISPATCHER;
 
     frame->Pop(CURRENT_THREAD);
+
+    END_PRESERVE_LAST_ERROR;
+
     return codeEntryPoint;
 }