summaryrefslogtreecommitdiff
path: root/src/vm
diff options
context:
space:
mode:
authorJonghyun Park <parjong@gmail.com>2016-12-14 11:15:21 +0900
committerJan Kotas <jkotas@microsoft.com>2016-12-13 18:15:21 -0800
commitdb529508a0623def4da3baa7175f4c654d3d6fbd (patch)
tree3fb1e63b6e8cb52c18ab1bb2c87ca2ad262d2c43 /src/vm
parent24c23c2649a0eec7621466626a5a637daca10337 (diff)
downloadcoreclr-db529508a0623def4da3baa7175f4c654d3d6fbd.tar.gz
coreclr-db529508a0623def4da3baa7175f4c654d3d6fbd.tar.bz2
coreclr-db529508a0623def4da3baa7175f4c654d3d6fbd.zip
[x86/Linux] Enforce 16-byte stack alignment (#8587)
Clang (and GCC) requires 16-byte stack alignment, but the current implementation of CallDescrInternal and ThePreStub does not provide any guarantee on stack alignment. This commit adds 16-byte stack alignment adjust code inside these functions.
Diffstat (limited to 'src/vm')
-rw-r--r--src/vm/i386/asmhelpers.S23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/vm/i386/asmhelpers.S b/src/vm/i386/asmhelpers.S
index 4a44c2c84f..1c6f0a36f6 100644
--- a/src/vm/i386/asmhelpers.S
+++ b/src/vm/i386/asmhelpers.S
@@ -405,6 +405,15 @@ NESTED_ENTRY CallDescrWorkerInternal, _TEXT, NoHandler
mov ebx, [esp + ((2 + 1) * 4)]
+ // compute padding size
+ mov eax, esp
+ mov ecx, [ebx + CallDescrData__numStackSlots]
+ shl ecx, 2
+ sub eax, ecx
+ and eax, 15
+ // adjust stack offset
+ sub esp, eax
+
// copy the stack
mov ecx, [ebx +CallDescrData__numStackSlots]
mov eax, [ebx +CallDescrData__pSrc]
@@ -431,6 +440,7 @@ LOCAL_LABEL(donestack):
mov edx, DWORD PTR [eax]
mov ecx, DWORD PTR [eax + 4]
+ CHECK_STACK_ALIGNMENT
call [ebx + CallDescrData__pTarget]
#ifdef _DEBUG
nop // This is a tag that we use in an assert. Fcalls expect to
@@ -455,6 +465,9 @@ LOCAL_LABEL(ReturnsInt):
mov [ebx + CallDescrData__returnValue + 4], edx
LOCAL_LABEL(Epilog):
+ // restore the stake pointer
+ lea esp, [ebp - 4]
+
EPILOG_BEG
EPILOG_POP ebx
EPILOG_END
@@ -996,12 +1009,19 @@ NESTED_ENTRY ThePreStub, _TEXT, NoHandler
mov esi, esp
+ // Compute padding size
+ lea ebx, [esp - 8]
+ and ebx, 15
+ // Adjust stack offset
+ sub esp, ebx
+
// EAX contains MethodDesc* from the precode. Push it here as argument
// for PreStubWorker
push eax
push esi
+ CHECK_STACK_ALIGNMENT
call C_FUNC(PreStubWorker)
// eax now contains replacement stub. PreStubWorker will never return
@@ -1009,6 +1029,9 @@ NESTED_ENTRY ThePreStub, _TEXT, NoHandler
// From here on, mustn't trash eax
+ // Restore stack pointer
+ mov esp, esi
+
STUB_EPILOG
// Tailcall target