mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-18 13:04:36 +03:00
Make alignment of a stack required by a function call proper.
This commit is contained in:
@@ -53,7 +53,7 @@ uint32_t HostRuntime::getStackAlignment() {
|
||||
// not sure about all other UNIX operating systems, because 16-byte alignment
|
||||
// is addition to an older specification.
|
||||
#if (ASMJIT_ARCH_X64) || \
|
||||
(ASMJIT_ARCH_X86 && (ASMJIT_OS_LINUX || ASMJIT_OS_BSD || ASMJIT_OS_MAC))
|
||||
(ASMJIT_ARCH_X86 && (ASMJIT_OS_LINUX || ASMJIT_OS_BSD || ASMJIT_OS_MAC || ASMJIT_OS_ANDROID))
|
||||
alignment = 16;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -4856,6 +4856,7 @@ static Error X86Context_initFunc(X86Context* self, X86FuncNode* func) {
|
||||
// Adjust stack pointer if function is caller.
|
||||
if (func->isCaller()) {
|
||||
func->addFuncFlags(kFuncFlagIsStackAdjusted);
|
||||
func->_callStackSize = Utils::alignTo<uint32_t>(func->getCallStackSize(), func->getRequiredStackAlignment());
|
||||
}
|
||||
|
||||
// Adjust stack pointer if manual stack alignment is needed.
|
||||
@@ -4962,13 +4963,19 @@ static Error X86Context_initFunc(X86Context* self, X86FuncNode* func) {
|
||||
// Count push/pop sequence.
|
||||
v += func->getPushPopStackSize();
|
||||
|
||||
// Count save/restore sequence for XMM registers (should be already aligned).
|
||||
v += func->getMoveStackSize();
|
||||
|
||||
// Maximum memory required to call all functions within this function.
|
||||
v += func->getCallStackSize();
|
||||
|
||||
// Calculate the final offset to keep stack alignment.
|
||||
func->_alignStackSize = Utils::alignDiff<uint32_t>(v, func->getRequiredStackAlignment());
|
||||
}
|
||||
|
||||
// Memory stack size.
|
||||
func->_memStackSize = self->_memAllTotal;
|
||||
func->_alignedMemStackSize = Utils::alignTo<uint32_t>(func->_memStackSize, func->_requiredStackAlignment);
|
||||
func->_alignedMemStackSize = Utils::alignTo<uint32_t>(func->_memStackSize, func->getRequiredStackAlignment());
|
||||
|
||||
if (func->isNaked()) {
|
||||
self->_argBaseReg = kX86RegIndexSp;
|
||||
|
||||
Reference in New Issue
Block a user