[x86/Linux] Fix incorrect FP values (dotnet/coreclr#9975)
authorHanjoung Lee <waterets@gmail.com>
Tue, 7 Mar 2017 08:57:29 +0000 (17:57 +0900)
committerJan Vorlicek <janvorli@microsoft.com>
Tue, 7 Mar 2017 08:57:29 +0000 (09:57 +0100)
* [x86/Linux] Fix incorrect FP values

Restoring FP by CallerSP could be incorrect for nested EH.
Now that we have dotnet/coreclr#9820, we can use current context for 1st pass of EH.

Fix dotnet/coreclr#9848

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

src/coreclr/src/vm/eetwain.cpp
src/coreclr/src/vm/exceptionhandling.cpp

index 19253c0..18bc24a 100644 (file)
@@ -5190,11 +5190,7 @@ OBJECTREF EECodeManager::GetInstance( PREGDISPLAY    pContext,
     if (info.ebpFrame)
     {
         _ASSERTE(stackDepth == 0);
-#if defined(WIN64EXCEPTIONS)
-        taArgBase = GetCallerSp(pContext) - 2 * sizeof(TADDR);
-#else
-        taArgBase = *pContext->pEbp;
-#endif
+        taArgBase = GetRegdisplayFP(pContext);
     }
     else
     {
@@ -5365,11 +5361,7 @@ PTR_VOID EECodeManager::GetParamTypeArg(PREGDISPLAY     pContext,
         return NULL;
     }
 
-#if defined(WIN64EXCEPTIONS)
-    TADDR fp = GetCallerSp(pContext) - 2 * sizeof(TADDR);
-#else
     TADDR fp = GetRegdisplayFP(pContext);
-#endif
     TADDR taParamTypeArg = *PTR_TADDR(fp - GetParamTypeArgOffset(&info));
     return PTR_VOID(taParamTypeArg);
 
@@ -5497,13 +5489,7 @@ void * EECodeManager::GetGSCookieAddr(PREGDISPLAY     pContext,
     
     if  (info->ebpFrame)
     {
-        DWORD curEBP;
-
-#ifdef WIN64EXCEPTIONS
-        curEBP = GetCallerSp(pContext) - 2 * 4;
-#else
-        curEBP = *pContext->pEbp;
-#endif
+        DWORD curEBP = GetRegdisplayFP(pContext);
 
         return PVOID(SIZE_T(curEBP - info->gsCookieOffset));
     }
index 74a456d..8419442 100644 (file)
@@ -47,6 +47,13 @@ inline void RestoreNonvolatileRegisters(PCONTEXT pContext, PKNONVOLATILE_CONTEXT
     ENUM_CALLEE_SAVED_REGISTERS();
 #undef CALLEE_SAVED_REGISTER
 }
+
+inline void RestoreNonvolatileRegisterPointers(PT_KNONVOLATILE_CONTEXT_POINTERS pContextPointers, PKNONVOLATILE_CONTEXT pNonvolatileContext)
+{
+#define CALLEE_SAVED_REGISTER(reg) pContextPointers->reg = &pNonvolatileContext->reg;
+    ENUM_CALLEE_SAVED_REGISTERS();
+#undef CALLEE_SAVED_REGISTER
+}
 #endif
 #ifndef DACCESS_COMPILE
 
@@ -1312,6 +1319,7 @@ void ExceptionTracker::InitializeCurrentContextForCrawlFrame(CrawlFrame* pcfThis
         SetIP(pRD->pCurrentContext, 0);
 #else // !USE_CURRENT_CONTEXT_IN_FILTER
         RestoreNonvolatileRegisters(pRD->pCurrentContext, pDispatcherContext->CurrentNonVolatileContextRecord);
+        RestoreNonvolatileRegisterPointers(pRD->pCurrentContextPointers, pDispatcherContext->CurrentNonVolatileContextRecord);
 #endif // USE_CURRENT_CONTEXT_IN_FILTER
 
         *(pRD->pCallerContext)      = *(pDispatcherContext->ContextRecord);