From d71a42b6b0672d605e466845c3538fac8a0763a4 Mon Sep 17 00:00:00 2001 From: Jonghyun Park Date: Mon, 6 Mar 2017 20:31:37 +0900 Subject: [PATCH] [x86/Linux] Stack align aware unwinder (dotnet/coreclr#9928) Commit migrated from https://github.com/dotnet/coreclr/commit/ccf4cb343f6b9f47fc4b08d8811ead1caa3c706c --- src/coreclr/src/unwinder/i386/unwinder_i386.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/unwinder/i386/unwinder_i386.cpp b/src/coreclr/src/unwinder/i386/unwinder_i386.cpp index 4de2379..2c184d1 100644 --- a/src/coreclr/src/unwinder/i386/unwinder_i386.cpp +++ b/src/coreclr/src/unwinder/i386/unwinder_i386.cpp @@ -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 -- 2.7.4