[PATCH] common-user: Fix tail calls to safe_syscall_set_errno_tail

Richard Henderson posted 1 patch 2 years, 3 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220104190454.542225-1-richard.henderson@linaro.org
Maintainers: Riku Voipio <riku.voipio@iki.fi>
common-user/host/i386/safe-syscall.inc.S   | 1 +
common-user/host/mips/safe-syscall.inc.S   | 1 +
common-user/host/x86_64/safe-syscall.inc.S | 1 +
3 files changed, 3 insertions(+)
[PATCH] common-user: Fix tail calls to safe_syscall_set_errno_tail
Posted by Richard Henderson 2 years, 3 months ago
For the ABIs in which the syscall return register is not
also the first function argument register, move the errno
value into the correct place.

Fixes: a3310c0397e2
Reported-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 common-user/host/i386/safe-syscall.inc.S   | 1 +
 common-user/host/mips/safe-syscall.inc.S   | 1 +
 common-user/host/x86_64/safe-syscall.inc.S | 1 +
 3 files changed, 3 insertions(+)

diff --git a/common-user/host/i386/safe-syscall.inc.S b/common-user/host/i386/safe-syscall.inc.S
index baf5400a29..9c45e56e48 100644
--- a/common-user/host/i386/safe-syscall.inc.S
+++ b/common-user/host/i386/safe-syscall.inc.S
@@ -120,6 +120,7 @@ safe_syscall_end:
         pop     %ebp
         .cfi_adjust_cfa_offset -4
         .cfi_restore ebp
+        mov     %eax, (%esp)
         jmp     safe_syscall_set_errno_tail
 
         .cfi_endproc
diff --git a/common-user/host/mips/safe-syscall.inc.S b/common-user/host/mips/safe-syscall.inc.S
index fc75a337d1..6a44614970 100644
--- a/common-user/host/mips/safe-syscall.inc.S
+++ b/common-user/host/mips/safe-syscall.inc.S
@@ -141,6 +141,7 @@ safe_syscall_end:
 1:      USE_ALT_CP(t0)
         SETUP_GPX(t1)
         SETUP_GPX64(t0, t1)
+        move    a0, v0
         PTR_LA  t9, safe_syscall_set_errno_tail
         jr      t9
 
diff --git a/common-user/host/x86_64/safe-syscall.inc.S b/common-user/host/x86_64/safe-syscall.inc.S
index a20927a783..d1a67a303a 100644
--- a/common-user/host/x86_64/safe-syscall.inc.S
+++ b/common-user/host/x86_64/safe-syscall.inc.S
@@ -99,6 +99,7 @@ safe_syscall_end:
 1:      pop     %rbp
         .cfi_def_cfa_offset 8
         .cfi_restore rbp
+        mov     %eax, %edi
         jmp     safe_syscall_set_errno_tail
         .cfi_endproc
 
-- 
2.25.1


Re: [PATCH] common-user: Fix tail calls to safe_syscall_set_errno_tail
Posted by Philippe Mathieu-Daudé 2 years, 3 months ago
On Tue, Jan 4, 2022 at 8:05 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> For the ABIs in which the syscall return register is not
> also the first function argument register, move the errno
> value into the correct place.
>
> Fixes: a3310c0397e2

Using Laurent alias [*]:
Fixes: a3310c0397e ("linux-user: Move syscall error detection into
safe_syscall_base")

[*] https://lore.kernel.org/qemu-devel/6c69b3b6-f1f0-da38-d47a-dba01e33bd6a@redhat.com/

> Reported-by: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>  common-user/host/i386/safe-syscall.inc.S   | 1 +
>  common-user/host/mips/safe-syscall.inc.S   | 1 +
>  common-user/host/x86_64/safe-syscall.inc.S | 1 +
>  3 files changed, 3 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>

Re: [PATCH] common-user: Fix tail calls to safe_syscall_set_errno_tail
Posted by Laurent Vivier 2 years, 3 months ago
Le 04/01/2022 à 20:04, Richard Henderson a écrit :
> For the ABIs in which the syscall return register is not
> also the first function argument register, move the errno
> value into the correct place.
> 
> Fixes: a3310c0397e2
> Reported-by: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   common-user/host/i386/safe-syscall.inc.S   | 1 +
>   common-user/host/mips/safe-syscall.inc.S   | 1 +
>   common-user/host/x86_64/safe-syscall.inc.S | 1 +
>   3 files changed, 3 insertions(+)
> 

Tested-by: Laurent Vivier <laurent@vivier.eu>


Re: [PATCH] common-user: Fix tail calls to safe_syscall_set_errno_tail
Posted by Richard Henderson 2 years, 3 months ago
On 1/4/22 11:04 AM, Richard Henderson wrote:
> For the ABIs in which the syscall return register is not
> also the first function argument register, move the errno
> value into the correct place.
> 
> Fixes: a3310c0397e2
> Reported-by: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   common-user/host/i386/safe-syscall.inc.S   | 1 +
>   common-user/host/mips/safe-syscall.inc.S   | 1 +
>   common-user/host/x86_64/safe-syscall.inc.S | 1 +
>   3 files changed, 3 insertions(+)

Queued to tcg-next.

r~