qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC 4/4] common-user: Allow return codes to be adjusted after sytsem ca


From: Warner Losh
Subject: [RFC 4/4] common-user: Allow return codes to be adjusted after sytsem call
Date: Sun, 7 Nov 2021 19:37:38 -0700

All the *-users generally use the Linux style of negative return codes
for errno. However, other systems, like FreeBSD, have a different
convention. Allow those systems to insert code after the syscall that
adjusts the return value of the system call to match the native linux
format.

Signed-off-by: Warner Losh <imp@bsdimp.com>
---
 common-user/host/aarch64/safe-syscall.inc.S | 1 +
 common-user/host/arm/safe-syscall.inc.S     | 1 +
 common-user/host/i386/safe-syscall.inc.S    | 1 +
 common-user/host/ppc64/safe-syscall.inc.S   | 1 +
 common-user/host/riscv/safe-syscall.inc.S   | 1 +
 common-user/host/s390x/safe-syscall.inc.S   | 1 +
 common-user/host/x86_64/safe-syscall.inc.S  | 1 +
 linux-user/safe-syscall.S                   | 1 +
 8 files changed, 8 insertions(+)

diff --git a/common-user/host/aarch64/safe-syscall.inc.S 
b/common-user/host/aarch64/safe-syscall.inc.S
index bc1f5a9792..81d83e8e79 100644
--- a/common-user/host/aarch64/safe-syscall.inc.S
+++ b/common-user/host/aarch64/safe-syscall.inc.S
@@ -64,6 +64,7 @@ safe_syscall_start:
        svc     0x0
 safe_syscall_end:
        /* code path for having successfully executed the syscall */
+       ADJUST_SYSCALL_RETCODE
        ret
 
 0:
diff --git a/common-user/host/arm/safe-syscall.inc.S 
b/common-user/host/arm/safe-syscall.inc.S
index 88c4958504..40e9a5e28d 100644
--- a/common-user/host/arm/safe-syscall.inc.S
+++ b/common-user/host/arm/safe-syscall.inc.S
@@ -78,6 +78,7 @@ safe_syscall_start:
        swi     0
 safe_syscall_end:
        /* code path for having successfully executed the syscall */
+       ADJUST_SYSCALL_RETCODE
        pop     { r4, r5, r6, r7, r8, pc }
 
 1:
diff --git a/common-user/host/i386/safe-syscall.inc.S 
b/common-user/host/i386/safe-syscall.inc.S
index 9e58fc6504..eb6b43bd81 100644
--- a/common-user/host/i386/safe-syscall.inc.S
+++ b/common-user/host/i386/safe-syscall.inc.S
@@ -75,6 +75,7 @@ safe_syscall_start:
        int     $0x80
 safe_syscall_end:
        /* code path for having successfully executed the syscall */
+       ADJUST_SYSCALL_RETCODE
        pop     %ebx
        .cfi_remember_state
        .cfi_adjust_cfa_offset -4
diff --git a/common-user/host/ppc64/safe-syscall.inc.S 
b/common-user/host/ppc64/safe-syscall.inc.S
index 875133173b..974bd03f8d 100644
--- a/common-user/host/ppc64/safe-syscall.inc.S
+++ b/common-user/host/ppc64/safe-syscall.inc.S
@@ -75,6 +75,7 @@ safe_syscall_start:
        sc
 safe_syscall_end:
        /* code path when we did execute the syscall */
+       ADJUST_SYSCALL_RETCODE
        ld 14, 16(1) /* restore r14 to its original value */
        bnslr+
 
diff --git a/common-user/host/riscv/safe-syscall.inc.S 
b/common-user/host/riscv/safe-syscall.inc.S
index 9ca3fbfd1e..a4bd5c5c72 100644
--- a/common-user/host/riscv/safe-syscall.inc.S
+++ b/common-user/host/riscv/safe-syscall.inc.S
@@ -66,6 +66,7 @@ safe_syscall_start:
        scall
 safe_syscall_end:
        /* code path for having successfully executed the syscall */
+       ADJUST_SYSCALL_RETCODE
        ret
 
 0:
diff --git a/common-user/host/s390x/safe-syscall.inc.S 
b/common-user/host/s390x/safe-syscall.inc.S
index 414b44ad38..4ba60fbed0 100644
--- a/common-user/host/s390x/safe-syscall.inc.S
+++ b/common-user/host/s390x/safe-syscall.inc.S
@@ -76,6 +76,7 @@ safe_syscall_start:
        jne     2f
        svc     0
 safe_syscall_end:
+       ADJUST_SYSCALL_RETCODE
 
 1:     lg      %r15,0(%r15)            /* load back chain */
        .cfi_remember_state
diff --git a/common-user/host/x86_64/safe-syscall.inc.S 
b/common-user/host/x86_64/safe-syscall.inc.S
index f36992daa3..e1ae6f83e6 100644
--- a/common-user/host/x86_64/safe-syscall.inc.S
+++ b/common-user/host/x86_64/safe-syscall.inc.S
@@ -72,6 +72,7 @@ safe_syscall_start:
         syscall
 safe_syscall_end:
         /* code path for having successfully executed the syscall */
+       ADJUST_SYSCALL_RETCODE
         pop     %rbp
         .cfi_remember_state
         .cfi_def_cfa_offset 8
diff --git a/linux-user/safe-syscall.S b/linux-user/safe-syscall.S
index 42ea7c40ba..0d6dd19398 100644
--- a/linux-user/safe-syscall.S
+++ b/linux-user/safe-syscall.S
@@ -17,6 +17,7 @@
  * so that this will pull in the right fragment for the architecture.
  */
 #ifdef HAVE_SAFE_SYSCALL
+#define ADJUST_SYSCALL_RETCODE         /* No adjustment for linux */
 #include "safe-syscall.inc.S"
 #endif
 
-- 
2.33.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]