From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: Warner Losh <imp@bsdimp.com>
Subject: [PULL 12/15] common-user: Adjust system call return on FreeBSD
Date: Mon, 20 Dec 2021 12:24:57 -0800 [thread overview]
Message-ID: <20211220202500.111897-13-richard.henderson@linaro.org> (raw)
In-Reply-To: <20211220202500.111897-1-richard.henderson@linaro.org>
FreeBSD system calls return positive errno. On the 4 hosts for
which we have support, error is indicated by the C bit set or clear.
Reviewed-by: Warner Losh <imp@bsdimp.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
common-user/host/aarch64/safe-syscall.inc.S | 14 +++++++++++++-
common-user/host/arm/safe-syscall.inc.S | 9 +++++++++
common-user/host/i386/safe-syscall.inc.S | 11 +++++++++++
common-user/host/x86_64/safe-syscall.inc.S | 11 +++++++++++
4 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/common-user/host/aarch64/safe-syscall.inc.S b/common-user/host/aarch64/safe-syscall.inc.S
index 73a04b73b3..b8fd5b553e 100644
--- a/common-user/host/aarch64/safe-syscall.inc.S
+++ b/common-user/host/aarch64/safe-syscall.inc.S
@@ -60,17 +60,29 @@ safe_syscall_start:
cbnz w10, 2f
svc 0x0
safe_syscall_end:
+
/* code path for having successfully executed the syscall */
+#if defined(__linux__)
+ /* Linux kernel returns (small) negative errno. */
cmp x0, #-4096
b.hi 0f
+#elif defined(__FreeBSD__)
+ /* FreeBSD kernel returns positive errno and C bit set. */
+ b.cs 1f
+#else
+#error "unsupported os"
+#endif
ret
+#if defined(__linux__)
/* code path setting errno */
0: neg w0, w0
b safe_syscall_set_errno_tail
+#endif
/* code path when we didn't execute the syscall */
2: mov w0, #QEMU_ERESTARTSYS
- b safe_syscall_set_errno_tail
+1: b safe_syscall_set_errno_tail
+
.cfi_endproc
.size safe_syscall_base, .-safe_syscall_base
diff --git a/common-user/host/arm/safe-syscall.inc.S b/common-user/host/arm/safe-syscall.inc.S
index 66176a902c..bbfb89634e 100644
--- a/common-user/host/arm/safe-syscall.inc.S
+++ b/common-user/host/arm/safe-syscall.inc.S
@@ -74,10 +74,19 @@ safe_syscall_start:
bne 2f
swi 0
safe_syscall_end:
+
/* code path for having successfully executed the syscall */
+#if defined(__linux__)
+ /* Linux kernel returns (small) negative errno. */
cmp r0, #-4096
neghi r0, r0
bhi 1f
+#elif defined(__FreeBSD__)
+ /* FreeBSD kernel returns positive errno and C bit set. */
+ bcs 1f
+#else
+#error "unsupported os"
+#endif
pop { r4, r5, r6, r7, r8, pc }
/* code path when we didn't execute the syscall */
diff --git a/common-user/host/i386/safe-syscall.inc.S b/common-user/host/i386/safe-syscall.inc.S
index aced8c5141..baf5400a29 100644
--- a/common-user/host/i386/safe-syscall.inc.S
+++ b/common-user/host/i386/safe-syscall.inc.S
@@ -71,9 +71,18 @@ safe_syscall_start:
mov 8+16(%esp), %eax /* syscall number */
int $0x80
safe_syscall_end:
+
/* code path for having successfully executed the syscall */
+#if defined(__linux__)
+ /* Linux kernel returns (small) negative errno. */
cmp $-4095, %eax
jae 0f
+#elif defined(__FreeBSD__)
+ /* FreeBSD kernel returns positive errno and C bit set. */
+ jc 1f
+#else
+#error "unsupported os"
+#endif
pop %ebx
.cfi_remember_state
.cfi_adjust_cfa_offset -4
@@ -90,8 +99,10 @@ safe_syscall_end:
ret
.cfi_restore_state
+#if defined(__linux__)
0: neg %eax
jmp 1f
+#endif
/* code path when we didn't execute the syscall */
2: mov $QEMU_ERESTARTSYS, %eax
diff --git a/common-user/host/x86_64/safe-syscall.inc.S b/common-user/host/x86_64/safe-syscall.inc.S
index 84fed206f9..a20927a783 100644
--- a/common-user/host/x86_64/safe-syscall.inc.S
+++ b/common-user/host/x86_64/safe-syscall.inc.S
@@ -68,9 +68,18 @@ safe_syscall_start:
jnz 2f
syscall
safe_syscall_end:
+
/* code path for having successfully executed the syscall */
+#if defined(__linux__)
+ /* Linux kernel returns (small) negative errno. */
cmp $-4095, %rax
jae 0f
+#elif defined(__FreeBSD__)
+ /* FreeBSD kernel returns positive errno and C bit set. */
+ jc 1f
+#else
+#error "unsupported os"
+#endif
pop %rbp
.cfi_remember_state
.cfi_def_cfa_offset 8
@@ -78,8 +87,10 @@ safe_syscall_end:
ret
.cfi_restore_state
+#if defined(__linux__)
0: neg %eax
jmp 1f
+#endif
/* code path when we didn't execute the syscall */
2: mov $QEMU_ERESTARTSYS, %eax
--
2.25.1
next prev parent reply other threads:[~2021-12-20 20:34 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-20 20:24 [PULL 00/15] *-user: simplify safe signal handling Richard Henderson
2021-12-20 20:24 ` [PULL 01/15] linux-user: Untabify all safe-syscall.inc.S Richard Henderson
2021-12-20 20:24 ` [PULL 02/15] linux-user: Move syscall error detection into safe_syscall_base Richard Henderson
2022-01-04 13:51 ` Laurent Vivier
2022-01-04 18:12 ` Richard Henderson
2021-12-20 20:24 ` [PULL 03/15] linux-user/host/mips: Add safe-syscall.inc.S Richard Henderson
2021-12-20 20:24 ` [PULL 04/15] linux-user/host/sparc64: " Richard Henderson
2021-12-20 20:24 ` [PULL 05/15] linux-user: Remove HAVE_SAFE_SYSCALL and hostdep.h Richard Henderson
2021-12-20 20:24 ` [PULL 06/15] linux-user: Rename TARGET_ERESTARTSYS to QEMU_ERESTARTSYS Richard Henderson
2021-12-20 20:24 ` [PULL 07/15] bsd-user: " Richard Henderson
2021-12-20 20:24 ` [PULL 08/15] linux-user: Rename TARGET_QEMU_ESIGRETURN to QEMU_ESIGRETURN Richard Henderson
2021-12-20 20:24 ` [PULL 09/15] linux-user: Create special-errno.h Richard Henderson
2021-12-20 20:24 ` [PULL 10/15] bsd-user: " Richard Henderson
2021-12-20 20:24 ` [PULL 11/15] common-user: Move safe-syscall.* from linux-user Richard Henderson
2021-12-20 20:24 ` Richard Henderson [this message]
2021-12-20 20:24 ` [PULL 13/15] linux-user: Move thunk.c from top-level Richard Henderson
2021-12-20 20:24 ` [PULL 14/15] meson: Move linux_user_ss to linux-user/ Richard Henderson
2021-12-20 20:25 ` [PULL 15/15] meson: Move bsd_user_ss to bsd-user/ Richard Henderson
2021-12-20 23:54 ` [PULL 00/15] *-user: simplify safe signal handling Richard Henderson
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=20211220202500.111897-13-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=imp@bsdimp.com \
--cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.