qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu, imp@bsdimp.com
Subject: [PATCH v4 8/9] common-user: Adjust system call return on FreeBSD
Date: Tue, 16 Nov 2021 12:02:55 +0100	[thread overview]
Message-ID: <20211116110256.365484-9-richard.henderson@linaro.org> (raw)
In-Reply-To: <20211116110256.365484-1-richard.henderson@linaro.org>

From: Warner Losh <imp@bsdimp.com>

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.

Signed-off-by: Warner Losh <imp@bsdimp.com>
[rth: Rebase on new safe_syscall_base api; add #error check.]
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 common-user/host/aarch64/safe-syscall.inc.S | 12 +++++++++++-
 common-user/host/arm/safe-syscall.inc.S     | 11 +++++++++++
 common-user/host/i386/safe-syscall.inc.S    | 10 ++++++++++
 common-user/host/x86_64/safe-syscall.inc.S  | 10 ++++++++++
 4 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/common-user/host/aarch64/safe-syscall.inc.S b/common-user/host/aarch64/safe-syscall.inc.S
index 95c60d8609..d3f065cdef 100644
--- a/common-user/host/aarch64/safe-syscall.inc.S
+++ b/common-user/host/aarch64/safe-syscall.inc.S
@@ -65,12 +65,22 @@ safe_syscall_start:
 safe_syscall_end:
 
 	/* code path for having successfully executed the syscall */
-	cmn	x0, #4095
+#if defined(__linux__)
+	/* Linux kernel returns (small) negative errno. */
+	cmn	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
 
 	/* code path setting errno */
+#ifdef __linux__
 0:	neg	w0, w0			/* create positive errno */
+#endif
 1:	str	w0, [x11]		/* store errno */
 	mov	x0, #-1
 	ret
diff --git a/common-user/host/arm/safe-syscall.inc.S b/common-user/host/arm/safe-syscall.inc.S
index 17839c6486..328299021d 100644
--- a/common-user/host/arm/safe-syscall.inc.S
+++ b/common-user/host/arm/safe-syscall.inc.S
@@ -82,12 +82,23 @@ safe_syscall_start:
 safe_syscall_end:
 
 	/* code path for having successfully executed the syscall */
+#if defined(__linux__)
+	/* Linux kernel returns (small) negative errno. */
 	cmp	r0, #-4096
 	bhi	0f
+#elif defined(__FreeBSD__)
+	/* FreeBSD kernel returns positive errno and C bit set. */
+	bcs	1f
+#else
+#error "unsupported os"
+#endif
+
 9:	pop	{ r4, r5, r6, r7, r8, r9, r10, pc }
 
 	/* code path setting errno */
+#ifdef __linux__
 0:	neg	r0, r0		/* create positive errno */
+#endif
 1:	str	r0, [r9]	/* store errno */
 	mov	r0, #-1
 	b	9b
diff --git a/common-user/host/i386/safe-syscall.inc.S b/common-user/host/i386/safe-syscall.inc.S
index ad89521783..a9382f777e 100644
--- a/common-user/host/i386/safe-syscall.inc.S
+++ b/common-user/host/i386/safe-syscall.inc.S
@@ -76,8 +76,16 @@ safe_syscall_start:
 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. */
+	jcs	1f
+#else
+#error "unsupported os"
+#endif
 
 9:	pop	%ebx
 	.cfi_remember_state
@@ -97,7 +105,9 @@ safe_syscall_end:
 	.cfi_restore_state
 
 	/* code path setting errno */
+#ifdef __linux__
 0:	neg	%eax			/* create positive errno */
+#endif
 1:	mov	8+16(%esp), %ebx	/* load errno pointer */
 	mov	%eax, (%ebx)		/* store errno */
 	mov	$-1, %eax
diff --git a/common-user/host/x86_64/safe-syscall.inc.S b/common-user/host/x86_64/safe-syscall.inc.S
index 9a0c4c93b4..36b7efe2ca 100644
--- a/common-user/host/x86_64/safe-syscall.inc.S
+++ b/common-user/host/x86_64/safe-syscall.inc.S
@@ -75,8 +75,16 @@ safe_syscall_start:
 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. */
+	jcs	1f
+#else
+#error "unsupported os"
+#endif
 
 9:      pop     %rbp
         .cfi_remember_state
@@ -86,7 +94,9 @@ safe_syscall_end:
         .cfi_restore_state
 
         /* code path setting errno */
+#ifdef __linux__
 0:      neg	%eax			/* create positive errno */
+#endif
 1:      mov	%eax, (%rbp)		/* store errno */
         mov	$-1, %rax
         jmp	9b
-- 
2.25.1



  parent reply	other threads:[~2021-11-16 11:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16 11:02 [PATCH v4 0/9] linux-user: simplify safe signal handling Richard Henderson
2021-11-16 11:02 ` [PATCH v4 1/9] linux-user: Add host_signal_set_pc to set pc in mcontext Richard Henderson
2021-11-16 11:02 ` [PATCH v4 2/9] linux-user/signal.c: Create a common rewind_if_in_safe_syscall Richard Henderson
2021-11-16 11:02 ` [PATCH v4 3/9] linux-user/safe-syscall.inc.S: Move to common-user Richard Henderson
2021-11-16 21:03   ` Warner Losh
2021-11-17  8:11     ` Philippe Mathieu-Daudé
2021-11-17 12:49     ` Richard Henderson
2021-11-17 16:09       ` Warner Losh
2021-11-17 16:20       ` Philippe Mathieu-Daudé
2021-11-16 11:02 ` [PATCH v4 4/9] common-user: Move syscall error detection into safe_syscall_base Richard Henderson
2021-11-16 11:02 ` [PATCH v4 5/9] common-user/host/mips: Add safe-syscall.inc.S Richard Henderson
2021-11-16 11:02 ` [PATCH v4 6/9] common-user/host/sparc64: " Richard Henderson
2021-11-16 11:02 ` [PATCH v4 7/9] linux-user: Remove HAVE_SAFE_SYSCALL and hostdep.h Richard Henderson
2021-11-17  8:22   ` Philippe Mathieu-Daudé
2021-11-17 15:58   ` Warner Losh
2021-11-16 11:02 ` Richard Henderson [this message]
2021-11-16 20:58   ` [PATCH v4 8/9] common-user: Adjust system call return on FreeBSD Warner Losh
2021-11-16 21:43     ` Richard Henderson
2021-11-17  8:23   ` Philippe Mathieu-Daudé
2021-11-17  8:32     ` Richard Henderson
2021-11-17  8:38       ` Philippe Mathieu-Daudé
2021-11-16 11:02 ` [PATCH v4 9/9] common-user: Move safe-syscall.* from *-user Richard Henderson
2021-11-16 21:10 ` [PATCH v4 0/9] linux-user: simplify safe signal handling Warner Losh

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=20211116110256.365484-9-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=imp@bsdimp.com \
    --cc=laurent@vivier.eu \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).