[x86/Linux] Stack align aware unwinder (dotnet/coreclr#9928)
authorJonghyun Park <parjong@gmail.com>
Mon, 6 Mar 2017 11:31:37 +0000 (20:31 +0900)
committerJan Vorlicek <janvorli@microsoft.com>
Mon, 6 Mar 2017 11:31:37 +0000 (12:31 +0100)
Commit migrated from https://github.com/dotnet/coreclr/commit/ccf4cb343f6b9f47fc4b08d8811ead1caa3c706c

src/coreclr/src/unwinder/i386/unwinder_i386.cpp

index 4de2379..2c184d1 100644 (file)
@@ -105,8 +105,19 @@ OOPStackUnwinderX86::VirtualUnwind(
     ENUM_CALLEE_SAVED_REGISTERS();
 #undef CALLEE_SAVED_REGISTER
 
-    ContextRecord->Esp = rd.SP - codeInfo.GetCodeManager()->GetStackParameterSize(&codeInfo);
-    ContextRecord->ResumeEsp = rd.SP;
+    SIZE_T paramSize = codeInfo.GetCodeManager()->GetStackParameterSize(&codeInfo);
+    SIZE_T paddingSize = 0;
+
+#ifdef UNIX_X86_ABI
+    // On UNIX_X86_ABI, function call may have stack alignment padding.
+    if (paramSize % 16 != 0)
+    {
+        paddingSize += 16 - (paramSize % 16);
+    }
+#endif // UNIX_X86_ABI
+
+    ContextRecord->Esp = rd.SP - paramSize;
+    ContextRecord->ResumeEsp = rd.SP + paddingSize;
     ContextRecord->Eip = rd.ControlPC;
 
     // For x86, the value of Establisher Frame Pointer is Caller SP