mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] x86: setjmp: set base pointer to zero in initjmp
Date: Mon,  9 Oct 2023 13:50:51 +0200	[thread overview]
Message-ID: <20231009115051.1931562-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20231009115051.1931562-1-a.fatoum@pengutronix.de>

Initializing the frame points to a known-bad value like zero makes it
easier for code unwinding the stack to know when to stop. Thus
initialize the stack pointer in initjmp-initialized jump buffers to
zero.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/x86/lib/setjmp_32.S | 1 +
 arch/x86/lib/setjmp_64.S | 1 +
 2 files changed, 2 insertions(+)

diff --git a/arch/x86/lib/setjmp_32.S b/arch/x86/lib/setjmp_32.S
index 30db5f989af6..5814623f9478 100644
--- a/arch/x86/lib/setjmp_32.S
+++ b/arch/x86/lib/setjmp_32.S
@@ -54,6 +54,7 @@ ENDPROC(longjmp)
 ENTRY(initjmp)
 
 	movl %edx, 20(%eax)	/* Return address */
+	movl   $0, 8(%edx)	/* Base pointer */
 	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 */
diff --git a/arch/x86/lib/setjmp_64.S b/arch/x86/lib/setjmp_64.S
index d5cf99a1557f..bfa152149975 100644
--- a/arch/x86/lib/setjmp_64.S
+++ b/arch/x86/lib/setjmp_64.S
@@ -54,6 +54,7 @@ ENDPROC(longjmp)
 ENTRY(initjmp)
 
 	movq	%rsi, (%rdi)	/* Return address */
+	movq	$0,  16(%rdi)	/* Base pointer */
 	sub	$ASM_SZPTR, %rdx	/* RSP - 8 has to be 16-byte aligned on entry */
 	movq	%rdx, 8(%rdi)	/* Stack top */
 	xorq	%rax, %rax
-- 
2.39.2




  reply	other threads:[~2023-10-09 11:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-09 11:50 [PATCH 1/2] x86: lib: setjmp: fix stack alignment Ahmad Fatoum
2023-10-09 11:50 ` Ahmad Fatoum [this message]
2023-10-12 14:27 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231009115051.1931562-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox