diff mbox series

[1/2] x86: fix longjmp() implementation

Message ID 20221001130022.161518-2-heinrich.schuchardt@canonical.com
State Accepted
Delegated to: Simon Glass
Headers show
Series x86: fix longjmp() implementation | expand

Commit Message

Heinrich Schuchardt Oct. 1, 2022, 1 p.m. UTC
If longjmp(jmp_buf env, int val) is called with val = 0, the setjmp()
macro must return 1.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---
 arch/x86/cpu/i386/setjmp.S | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Simon Glass Oct. 3, 2022, 1:10 a.m. UTC | #1
On Sat, 1 Oct 2022 at 07:05, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> If longjmp(jmp_buf env, int val) is called with val = 0, the setjmp()
> macro must return 1.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  arch/x86/cpu/i386/setjmp.S | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/arch/x86/cpu/i386/setjmp.S b/arch/x86/cpu/i386/setjmp.S
> index 40b10dc8df..eceeafa7c8 100644
> --- a/arch/x86/cpu/i386/setjmp.S
> +++ b/arch/x86/cpu/i386/setjmp.S
> @@ -49,12 +49,17 @@ longjmp:
>         xchgl %eax, %edx
>  #else
>         movl 4(%esp), %edx      /* jmp_ptr address */
> +       movl 8(%esp), %eax      /* Return value */
>  #endif
>         movl (%edx), %ebx
>         movl 4(%edx), %esp
>         movl 8(%edx), %ebp
>         movl 12(%edx), %esi
>         movl 16(%edx), %edi
> +       test %eax, %eax
> +       jnz nz
> +       inc %eax
> +nz:
>         jmp *20(%edx)
>
>         .size longjmp, .-longjmp
> --
> 2.37.2
>

Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass Oct. 22, 2022, 1:06 a.m. UTC | #2
On Sat, 1 Oct 2022 at 07:05, Heinrich Schuchardt
<heinrich.schuchardt@canonical.com> wrote:
>
> If longjmp(jmp_buf env, int val) is called with val = 0, the setjmp()
> macro must return 1.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>  arch/x86/cpu/i386/setjmp.S | 5 +++++
>  1 file changed, 5 insertions(+)
>
Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/arch/x86/cpu/i386/setjmp.S b/arch/x86/cpu/i386/setjmp.S
index 40b10dc8df..eceeafa7c8 100644
--- a/arch/x86/cpu/i386/setjmp.S
+++ b/arch/x86/cpu/i386/setjmp.S
@@ -49,12 +49,17 @@  longjmp:
 	xchgl %eax, %edx
 #else
 	movl 4(%esp), %edx	/* jmp_ptr address */
+	movl 8(%esp), %eax	/* Return value */
 #endif
 	movl (%edx), %ebx
 	movl 4(%edx), %esp
 	movl 8(%edx), %ebp
 	movl 12(%edx), %esi
 	movl 16(%edx), %edi
+	test %eax, %eax
+	jnz nz
+	inc %eax
+nz:
 	jmp *20(%edx)
 
 	.size longjmp, .-longjmp