Fiber-friendly Vectored Exception Handling (dotnet/coreclr#20746)
authorTobias Loew <tobias-loew@users.noreply.github.com>
Mon, 5 Nov 2018 19:28:01 +0000 (20:28 +0100)
committerJan Vorlicek <janvorli@microsoft.com>
Mon, 5 Nov 2018 19:28:01 +0000 (20:28 +0100)
* Fiber-friendly Vectored Exception Handling

Check during exception handling if the cached and the current stack-base match to detect Fibers.

Commit migrated from https://github.com/dotnet/coreclr/commit/9f5aabc89487eeb2b1621cfb3b9ed8f5db243d9e

src/coreclr/src/vm/excep.cpp

index 6eb9105..013c8fe 100644 (file)
@@ -8172,6 +8172,24 @@ LONG WINAPI CLRVectoredExceptionHandlerShim(PEXCEPTION_POINTERS pExceptionInfo)
     // this thread will bypass all our locks.
     Thread *pThread = GetThread();
 
+    if (pThread)
+    {
+        // Fiber-friendly Vectored Exception Handling:
+        // Check if the current and the cached stack-base match.
+        // If they don't match then probably the thread is running on a different Fiber
+        // than during the initialization of the Thread-object.
+        void* stopPoint = pThread->GetCachedStackBase();
+        void* currentStackBase = Thread::GetStackUpperBound();
+        if (currentStackBase != stopPoint)
+        {
+            CantAllocHolder caHolder;
+            STRESS_LOG2(LF_EH, LL_INFO100, "In CLRVectoredExceptionHandler: mismatch of cached and current stack-base indicating use of Fibers, return with EXCEPTION_CONTINUE_SEARCH: current = %p; cache = %p\n",
+                currentStackBase, stopPoint);
+            return EXCEPTION_CONTINUE_SEARCH;
+        }
+    }
+    
+    
     // Also check if the exception was in the EE or not
     BOOL fExceptionInEE = FALSE;
     if (!pThread)