This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new a7e0bdb0d8f arch/x86_64: align the user stack pointer when entering
user space
a7e0bdb0d8f is described below
commit a7e0bdb0d8f0362f5e89c18601543a2416427a75
Author: raiden00pl <[email protected]>
AuthorDate: Fri Aug 7 11:57:44 2026 +0200
arch/x86_64: align the user stack pointer when entering user space
The task and pthread entry points were entered with the stack pointer
left by the kernel side of the startup path, not aligned to the 16
bytes the ABI requires: applications calling a variadic function with
floating point arguments crashed with a general protection exception
on the first SSE store of the argument save area. Align the stack
pointer when returning to user space, where the value is known.
Signed-off-by: raiden00pl <[email protected]>
Assisted-by: Claude Code
---
arch/x86_64/src/common/x86_64_syscall.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/arch/x86_64/src/common/x86_64_syscall.c
b/arch/x86_64/src/common/x86_64_syscall.c
index 4e92a686410..848f625c3ce 100644
--- a/arch/x86_64/src/common/x86_64_syscall.c
+++ b/arch/x86_64/src/common/x86_64_syscall.c
@@ -151,6 +151,14 @@ uint64_t *x86_64_syscall(uint64_t *regs)
regs[REG_RSI] = arg3;
regs[REG_RCX] = arg1;
+ /* Align the user stack pointer: the entry point is entered as
+ * if it was called, so the stack must be 16 byte aligned with
+ * the return address slot accounted for. Otherwise the SSE
+ * accesses generated for variadic functions fault.
+ */
+
+ regs[REG_RSP] = (regs[REG_RSP] & ~0x0f) - 8;
+
break;
}
@@ -181,6 +189,10 @@ uint64_t *x86_64_syscall(uint64_t *regs)
regs[REG_RSI] = arg3;
regs[REG_RCX] = arg1;
+ /* Align the user stack pointer, see SYS_task_start */
+
+ regs[REG_RSP] = (regs[REG_RSP] & ~0x0f) - 8;
+
break;
}