summaryrefslogtreecommitdiffstats
path: root/arch/x86/lib
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2023-10-09 13:50:50 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2023-10-12 16:27:03 +0200
commit5155dc05760174ab7b2d5ff931e3c9dea079b847 (patch)
tree8dc606fb0975385f8c9ca0d108d92d1a4d17e746 /arch/x86/lib
parentf42e0ad1f85e060906a350ffd1fa502595229e2c (diff)
downloadbarebox-5155dc05760174ab7b2d5ff931e3c9dea079b847.tar.gz
barebox-5155dc05760174ab7b2d5ff931e3c9dea079b847.tar.xz
x86: lib: setjmp: fix stack alignment
x86 stack is expected to be 16-byte aligned to allow for instructions like movaps that involve xmm operands to directly use the stack. However the 16-byte alignment is what's expected at startup time. All later functions will have the stack misaligned by a pointer size's worth because call pushes the return address to the call stack. Add the missing (mis)alignment. This fixes a segmentation fault observed using initjmp on x86_64. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20231009115051.1931562-1-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/x86/lib')
-rw-r--r--arch/x86/lib/setjmp_32.S4
-rw-r--r--arch/x86/lib/setjmp_64.S2
2 files changed, 5 insertions, 1 deletions
diff --git a/arch/x86/lib/setjmp_32.S b/arch/x86/lib/setjmp_32.S
index 38dcb68c1b..30db5f989a 100644
--- a/arch/x86/lib/setjmp_32.S
+++ b/arch/x86/lib/setjmp_32.S
@@ -8,6 +8,7 @@
#define _REGPARM
#include <linux/linkage.h>
+#include <asm-generic/pointer.h>
.text
.align 8
@@ -53,7 +54,8 @@ ENDPROC(longjmp)
ENTRY(initjmp)
movl %edx, 20(%eax) /* Return address */
- movl %ecx, 4(%eax) /* Post-return %esp! */
+ sub $ASM_SZPTR, %ecx /* ESP - 4 has to be 16-byte aligned on entry */
+ movl %ecx, 4(%eax) /* Stack top */
xorl %eax, %eax /* Return value */
ret
diff --git a/arch/x86/lib/setjmp_64.S b/arch/x86/lib/setjmp_64.S
index 28ea576cd2..d5cf99a155 100644
--- a/arch/x86/lib/setjmp_64.S
+++ b/arch/x86/lib/setjmp_64.S
@@ -6,6 +6,7 @@
*/
#include <linux/linkage.h>
+#include <asm-generic/pointer.h>
.text
.align 8
@@ -53,6 +54,7 @@ ENDPROC(longjmp)
ENTRY(initjmp)
movq %rsi, (%rdi) /* Return address */
+ sub $ASM_SZPTR, %rdx /* RSP - 8 has to be 16-byte aligned on entry */
movq %rdx, 8(%rdi) /* Stack top */
xorq %rax, %rax
ret