This is an automated email from the ASF dual-hosted git repository. jerpelea pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 0ed64e4ef0639119522567ac40db310124f0fef0 Author: Marco Casaroli <[email protected]> AuthorDate: Sun Nov 1 11:45:39 2026 +0100 arch/x86_64: Align the kernel stack at the call of x86_64_syscall(). With CONFIG_ARCH_KERNEL_STACK, x86_64_syscall_entry() moves RSP to the register area, which is 64 byte aligned, and pushes the previous kernel stack pointer before it calls x86_64_syscall(). RSP is then 8 modulo 16 at the call, but the SysV ABI wants it 16 byte aligned there, so every system call runs on a misaligned stack. Code that uses aligned SSE moves on the stack (optimized code for 16 byte locals, the vector register save area of variadic functions) then faults with a general protection fault. Take 8 more bytes after the push, and give them back before the pop. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- arch/x86_64/src/intel64/intel64_head.S | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86_64/src/intel64/intel64_head.S b/arch/x86_64/src/intel64/intel64_head.S index 0403f7ccd95..d3cef4b99d0 100644 --- a/arch/x86_64/src/intel64/intel64_head.S +++ b/arch/x86_64/src/intel64/intel64_head.S @@ -645,8 +645,12 @@ no_kstack_switch: /* Update stored kernel stack */ movq %rsp, %gs:X86_64_CPUPRIV_KTOPSTK_OFFSET - /* Store original kernel stack on stack which is now in RDI */ + /* Store original kernel stack on stack which is now in RDI. The + * SysV ABI wants RSP 16 byte aligned at the call: the push took 8 + * bytes of the aligned register area address, so take 8 more. + */ pushq %rdi + subq $8, %rsp #endif /* Return value from syscall stored in rax */ @@ -665,6 +669,7 @@ no_kstack_switch: #ifdef CONFIG_ARCH_KERNEL_STACK /* Restore original kernel stack */ + addq $8, %rsp popq %gs:X86_64_CPUPRIV_KTOPSTK_OFFSET #endif
