qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Warner Losh <imp@bsdimp.com>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>,
	Laurent Vivier <laurent@vivier.eu>
Subject: Re: [PATCH v5 08/17] common-user: Adjust system call return on FreeBSD
Date: Wed, 17 Nov 2021 09:44:19 -0700	[thread overview]
Message-ID: <CANCZdfr4zOC7eSW7tEBOjz_oHJfiPo41QSfjixuPfBLBwfnKxA@mail.gmail.com> (raw)
In-Reply-To: <20211117160412.71563-9-richard.henderson@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 5512 bytes --]

On Wed, Nov 17, 2021 at 9:04 AM Richard Henderson <
richard.henderson@linaro.org> wrote:

> 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(-)
>

Reviewed by: Warner Losh <imp@bsdimp.com>


> 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
>

I believe this is OK. On FreeBSD, this will get the proper location for
errno and store
it there based on the current thread's local storage. Since the rest of the
code
extracts the errno directly, and we use that correctly w/o relying on errno
to
evaluate to the error associated with the last system call in this thread
in bsd-user,
I believe this adjustment is fine (also, a prior version seems to work,
this version
isn't yet in the github mirror, so I've not tried it).

This comment applies to all FreeBSD archs, except aarch64 which does a
similar thing,
but in a different way.

Warner

+#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..c27207492a 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. */
> +       jc      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..e3f920fa5c 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. */
> +       jc      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
>
>

[-- Attachment #2: Type: text/html, Size: 7348 bytes --]

  reply	other threads:[~2021-11-17 16:53 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-17 16:03 [PATCH v5 00/17] linux-user: simplify safe signal handling Richard Henderson
2021-11-17 16:03 ` [PATCH v5 01/17] linux-user: Add host_signal_set_pc to set pc in mcontext Richard Henderson
2021-11-17 16:23   ` Warner Losh
2021-11-17 16:37   ` Alex Bennée
2021-11-17 16:03 ` [PATCH v5 02/17] linux-user/signal.c: Create a common rewind_if_in_safe_syscall Richard Henderson
2021-11-17 16:24   ` Warner Losh
2021-11-17 16:37   ` Alex Bennée
2021-11-17 16:03 ` [PATCH v5 03/17] linux-user/safe-syscall.inc.S: Move to common-user Richard Henderson
2021-11-17 16:25   ` Warner Losh
2021-11-17 16:38   ` Alex Bennée
2021-11-17 16:03 ` [PATCH v5 04/17] common-user: Move syscall error detection into safe_syscall_base Richard Henderson
2021-11-17 16:28   ` Warner Losh
2021-11-22 11:55   ` Peter Maydell
2021-11-22 12:21     ` Richard Henderson
2021-11-22 15:07       ` Peter Maydell
2021-11-17 16:04 ` [PATCH v5 05/17] common-user/host/mips: Add safe-syscall.inc.S Richard Henderson
2021-11-17 16:31   ` Warner Losh
2021-11-17 16:04 ` [PATCH v5 06/17] common-user/host/sparc64: " Richard Henderson
2021-11-17 16:04 ` [PATCH v5 07/17] linux-user: Remove HAVE_SAFE_SYSCALL and hostdep.h Richard Henderson
2021-11-17 16:04 ` [PATCH v5 08/17] common-user: Adjust system call return on FreeBSD Richard Henderson
2021-11-17 16:44   ` Warner Losh [this message]
2021-11-17 16:04 ` [PATCH v5 09/17] *-user: Rename TARGET_ERESTARTSYS to QEMU_ERESTARTSYS Richard Henderson
2021-11-17 16:46   ` Warner Losh
2021-11-17 16:51   ` Philippe Mathieu-Daudé
2021-11-17 16:04 ` [PATCH v5 10/17] linux-user: Rename TARGET_QEMU_ESIGRETURN to QEMU_ESIGRETURN Richard Henderson
2021-11-17 17:01   ` Warner Losh
2021-11-17 16:04 ` [PATCH v5 11/17] bsd-user: Create special-errno.h Richard Henderson
2021-11-17 17:21   ` Warner Losh
2021-11-17 16:04 ` [PATCH v5 12/17] linux-user: " Richard Henderson
2021-11-17 17:21   ` Warner Losh
2021-11-17 16:04 ` [PATCH v5 13/17] meson: Add build infrastructure for common-user Richard Henderson
2021-11-17 17:22   ` Warner Losh
2021-11-17 16:04 ` [PATCH v5 14/17] common-user: Move safe-syscall.* from linux-user Richard Henderson
2021-11-17 17:23   ` Warner Losh
2021-11-17 16:04 ` [PATCH v5 15/17] linux-user: Move thunk.c from top-level Richard Henderson
2021-11-17 16:52   ` Philippe Mathieu-Daudé
2021-11-17 17:27   ` Warner Losh
2021-11-17 16:04 ` [PATCH v5 16/17] meson: Move linux_user_ss to linux-user/ Richard Henderson
2021-11-17 16:56   ` Philippe Mathieu-Daudé
2021-11-17 17:04     ` Richard Henderson
2021-11-17 17:11       ` Philippe Mathieu-Daudé
2021-11-17 17:31   ` Warner Losh
2021-11-17 16:04 ` [PATCH v5 17/17] meson: Move bsd_user_ss to bsd-user/ Richard Henderson
2021-11-17 16:56   ` Philippe Mathieu-Daudé
2021-11-17 17:29   ` Warner Losh
2021-11-17 17:42 ` [PATCH v5 00/17] 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=CANCZdfr4zOC7eSW7tEBOjz_oHJfiPo41QSfjixuPfBLBwfnKxA@mail.gmail.com \
    --to=imp@bsdimp.com \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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).