All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Warner Losh <imp@bsdimp.com>
Cc: Kyle Evans <kevans@freebsd.org>, Stacey Son <sson@freebsd.org>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH 23/30] bsd-user/signal.c: sigset manipulation routines.
Date: Fri, 14 Jan 2022 11:13:59 +0000	[thread overview]
Message-ID: <CAFEAcA_fc_-qXoY07uZuMpT6kAUT+oT8RD_G=8vGgSQqDmH-WA@mail.gmail.com> (raw)
In-Reply-To: <20220109161923.85683-24-imp@bsdimp.com>

On Sun, 9 Jan 2022 at 16:53, Warner Losh <imp@bsdimp.com> wrote:
>
> target_sigemptyset: resets a set to having no bits set
> qemu_sigorset:      computes the or of two sets
> target_sigaddset:   adds a signal to a set
> target_sigismember: returns true when signal is a member
> host_to_target_sigset_internal: convert host sigset to target
> host_to_target_sigset: convert host sigset to target
> target_to_host_sigset_internal: convert target sigset to host
> target_to_host_sigset: convert target sigset to host
>
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Kyle Evans <kevans@freebsd.org>
> Signed-off-by: Warner Losh <imp@bsdimp.com>
> ---
>  bsd-user/qemu.h   |  3 ++
>  bsd-user/signal.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 92 insertions(+)
>
> diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
> index e12617f5d69..e8c417c7c33 100644
> --- a/bsd-user/qemu.h
> +++ b/bsd-user/qemu.h
> @@ -223,7 +223,10 @@ void queue_signal(CPUArchState *env, int sig, target_siginfo_t *info);
>  abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp);
>  int target_to_host_signal(int sig);
>  int host_to_target_signal(int sig);
> +void host_to_target_sigset(target_sigset_t *d, const sigset_t *s);
> +void target_to_host_sigset(sigset_t *d, const target_sigset_t *s);
>  void QEMU_NORETURN force_sig(int target_sig);
> +int qemu_sigorset(sigset_t *dest, const sigset_t *left, const sigset_t *right);
>
>  /* mmap.c */
>  int target_mprotect(abi_ulong start, abi_ulong len, int prot);
> diff --git a/bsd-user/signal.c b/bsd-user/signal.c
> index 93c3b3c5033..8dadc9a39a7 100644
> --- a/bsd-user/signal.c
> +++ b/bsd-user/signal.c
> @@ -32,6 +32,9 @@
>
>  static struct target_sigaction sigact_table[TARGET_NSIG];
>  static void host_signal_handler(int host_sig, siginfo_t *info, void *puc);
> +static void target_to_host_sigset_internal(sigset_t *d,
> +        const target_sigset_t *s);
> +
>
>  int host_to_target_signal(int sig)
>  {
> @@ -43,6 +46,44 @@ int target_to_host_signal(int sig)
>      return sig;
>  }
>
> +static inline void target_sigemptyset(target_sigset_t *set)
> +{
> +    memset(set, 0, sizeof(*set));
> +}
> +
> +#include <signal.h>

Don't include system headers halfway through the file like this,
please : put the #include at the top of the file with the others.

> +
> +int
> +qemu_sigorset(sigset_t *dest, const sigset_t *left, const sigset_t *right)
> +{
> +    sigset_t work;
> +    int i;
> +
> +    sigemptyset(&work);
> +    for (i = 1; i < NSIG; ++i) {
> +        if (sigismember(left, i) || sigismember(right, i)) {
> +            sigaddset(&work, i);
> +        }
> +    }
> +
> +    *dest = work;
> +    return 0;
> +}

FreeBSD's manpage says it has a native sigorset() --
https://www.freebsd.org/cgi/man.cgi?query=sigemptyset&sektion=3&apropos=0&manpath=freebsd
can you just use that ?

> +
> +static inline void target_sigaddset(target_sigset_t *set, int signum)
> +{
> +    signum--;
> +    uint32_t mask = (uint32_t)1 << (signum % TARGET_NSIG_BPW);
> +    set->__bits[signum / TARGET_NSIG_BPW] |= mask;
> +}
> +
> +static inline int target_sigismember(const target_sigset_t *set, int signum)
> +{
> +    signum--;
> +    abi_ulong mask = (abi_ulong)1 << (signum % TARGET_NSIG_BPW);
> +    return (set->__bits[signum / TARGET_NSIG_BPW] & mask) != 0;
> +}
> +
>  /* Adjust the signal context to rewind out of safe-syscall if we're in it */
>  static inline void rewind_if_in_safe_syscall(void *puc)
>  {
> @@ -55,6 +96,54 @@ static inline void rewind_if_in_safe_syscall(void *puc)
>      }
>  }
>
> +static void host_to_target_sigset_internal(target_sigset_t *d,
> +        const sigset_t *s)
> +{
> +    int i;
> +
> +    target_sigemptyset(d);
> +    for (i = 1; i <= TARGET_NSIG; i++) {

i here is iterating through host signal numbers, not target
numbers, so TARGET_NSIG isn't the right upper bound.
On Linux we iterate from 1 to _NSIG-1; on BSD I think
you may want (i = 0; i < NSIG; i++), but you should check that.

> +        if (sigismember(s, i)) {
> +            target_sigaddset(d, host_to_target_signal(i));
> +        }
> +    }
> +}

These functions are a little odd when you compare them to their
linux-user equivalents, because they're both written
with a sort of abstraction between host and target signal
numbers (they call host_to_target_signal() and
target_to_host_signal()) but also written with baked-in
assumptions that the mapping is basically 1:1 (they don't
have the code that handles the possibility that the
target signal isn't representable as a host signal or
vice-versa). But assuming the BSDs don't change their
signal numbering across architectures, this is fine.

thanks
-- PMM


  reply	other threads:[~2022-01-14 11:19 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-09 16:18 [PATCH 00/30] bsd-user: upstream our signal implementation Warner Losh
2022-01-09 16:18 ` [PATCH 01/30] bsd-user/arm/target_arch_cpu.h: Move EXCP_ATOMIC to match linux-user Warner Losh
2022-01-13 15:47   ` Peter Maydell
2022-01-23 21:30   ` Richard Henderson
2022-01-09 16:18 ` [PATCH 02/30] bsd-user/signal.c: implement force_sig_fault Warner Losh
2022-01-13 16:43   ` Peter Maydell
2022-01-23 21:36   ` Richard Henderson
2022-01-09 16:18 ` [PATCH 03/30] bsd-user/signal.c: Implement cpu_loop_exit_sigsegv Warner Losh
2022-01-13 17:00   ` Peter Maydell
2022-01-23 21:38   ` Richard Henderson
2022-01-09 16:18 ` [PATCH 04/30] bsd-user/signal.c: implement cpu_loop_exit_sigbus Warner Losh
2022-01-13 17:00   ` Peter Maydell
2022-01-23 21:38   ` Richard Henderson
2022-01-09 16:18 ` [PATCH 05/30] bsd-user/arm/arget_arch_cpu.h: Move EXCP_DEBUG and EXCP_BKPT together Warner Losh
2022-01-13 17:13   ` Peter Maydell
2022-01-14  6:33     ` Warner Losh
2022-01-23 21:40   ` Richard Henderson
2022-01-09 16:18 ` [PATCH 06/30] bsd-user/arm/target_arch_cpu.h: Correct code pointer Warner Losh
2022-01-13 17:15   ` Peter Maydell
2022-01-14  6:38     ` Warner Losh
2022-01-14 10:22       ` Peter Maydell
2022-01-17  4:12         ` Warner Losh
2022-01-23 21:43   ` Richard Henderson
2022-01-09 16:19 ` [PATCH 07/30] bsd-user/arm/target_arch_cpu.h: Use force_sig_fault for EXCP_UDEF Warner Losh
2022-01-13 17:19   ` Peter Maydell
2022-01-23 22:07     ` Richard Henderson
2022-01-09 16:19 ` [PATCH 08/30] bsd-user/arm/target_arch_cpu.h: Implement data faults Warner Losh
2022-01-13 17:40   ` Peter Maydell
2022-01-14 18:13     ` Warner Losh
2022-01-14 18:21       ` Peter Maydell
2022-01-24  1:12   ` Richard Henderson
2022-01-09 16:19 ` [PATCH 09/30] bsd-user/signal.c: implement abstract target / host signal translation Warner Losh
2022-01-13 17:44   ` Peter Maydell
2022-01-14 18:27     ` Warner Losh
2022-01-09 16:19 ` [PATCH 10/30] bsd-user/signal.c: Implement signal_init() Warner Losh
2022-01-13 19:28   ` Peter Maydell
2022-01-14 18:51     ` Warner Losh
2022-01-24  1:38   ` Richard Henderson
2022-01-24 21:35     ` Warner Losh
2022-01-09 16:19 ` [PATCH 11/30] bsd-user/host/arm/host-signal.h: Implement host_signal_* Warner Losh
2022-01-13 19:32   ` Peter Maydell
2022-01-17  3:53     ` Warner Losh
2022-01-09 16:19 ` [PATCH 12/30] bsd-user/host/i386/host-signal.h: " Warner Losh
2022-01-13 19:33   ` Peter Maydell
2022-01-24  1:49   ` Richard Henderson
2022-01-09 16:19 ` [PATCH 13/30] bsd-user/host/x86_64/host-signal.h: " Warner Losh
2022-01-13 19:33   ` Peter Maydell
2022-01-24  1:52   ` Richard Henderson
2022-01-09 16:19 ` [PATCH 14/30] bsd-user: Add host signals to the build Warner Losh
2022-01-13 19:35   ` Peter Maydell
2022-01-24  1:56   ` Richard Henderson
2022-01-09 16:19 ` [PATCH 15/30] bsd-user: Add trace events for bsd-usr Warner Losh
2022-01-13 19:37   ` Peter Maydell
2022-01-24  1:57   ` Richard Henderson
2022-01-09 16:19 ` [PATCH 16/30] bsd-user/signal.c: host_to_target_siginfo_noswap Warner Losh
2022-01-13 19:43   ` Peter Maydell
2022-01-15  6:19     ` Warner Losh
2022-01-15 11:08       ` Peter Maydell
2022-01-24  2:05   ` Richard Henderson
2022-01-24 21:45     ` Warner Losh
2022-01-09 16:19 ` [PATCH 17/30] bsd-user/signal.c: Implement rewind_if_in_safe_syscall Warner Losh
2022-01-13 19:44   ` Peter Maydell
2022-01-24  2:09   ` Richard Henderson
2022-01-09 16:19 ` [PATCH 18/30] bsd-user/signal.c: Implement host_signal_handler Warner Losh
2022-01-13 20:17   ` Peter Maydell
2022-01-16 20:52     ` Warner Losh
2022-01-09 16:19 ` [PATCH 19/30] bsd-user/strace.c: print_taken_signal Warner Losh
2022-01-13 20:20   ` Peter Maydell
2022-01-24  2:45   ` Richard Henderson
2022-01-09 16:19 ` [PATCH 20/30] bsd-user/signal.c: core_dump_signal Warner Losh
2022-01-13 20:22   ` Peter Maydell
2022-01-13 20:28     ` Warner Losh
2022-01-13 20:40       ` Peter Maydell
2022-01-24  3:01   ` Richard Henderson
2022-01-09 16:19 ` [PATCH 21/30] bsd-user/signal.c: force_sig Warner Losh
2022-01-13 20:29   ` Peter Maydell
2022-01-13 20:53     ` Peter Maydell
2022-01-13 23:04       ` Kyle Evans
2022-01-18 22:27         ` Warner Losh
2022-01-09 16:19 ` [PATCH 22/30] bsd-user/signal.c: Fill in queue_signal Warner Losh
2022-01-13 20:37   ` Peter Maydell
2022-01-17 16:22     ` Warner Losh
2022-01-17 16:33       ` Peter Maydell
2022-01-09 16:19 ` [PATCH 23/30] bsd-user/signal.c: sigset manipulation routines Warner Losh
2022-01-14 11:13   ` Peter Maydell [this message]
2022-01-22 16:44     ` Warner Losh
2022-01-22 18:00       ` Kyle Evans
2022-01-09 16:19 ` [PATCH 24/30] bsd-user/signal.c: setup_frame Warner Losh
2022-01-14 11:40   ` Peter Maydell
2022-01-17  6:58     ` Warner Losh
2022-01-17  7:24       ` Warner Losh
2022-01-09 16:19 ` [PATCH 25/30] bsd-user/signal.c: handle_pending_signal Warner Losh
2022-01-14 11:50   ` Peter Maydell
2022-01-09 16:19 ` [PATCH 26/30] bsd-user/signal.c: tswap_siginfo Warner Losh
2022-01-14 11:54   ` Peter Maydell
2022-01-09 16:19 ` [PATCH 27/30] bsd-user/signal.c: process_pending_signals Warner Losh
2022-01-14 11:55   ` Peter Maydell
2022-01-17  2:09     ` Warner Losh
2022-01-09 16:19 ` [PATCH 28/30] bsd-user/signal.c: implement do_sigreturn Warner Losh
2022-01-14 12:12   ` Peter Maydell
2022-01-09 16:19 ` [PATCH 29/30] bsd-user/signal.c: implement do_sigaction Warner Losh
2022-01-14 13:13   ` Peter Maydell
2022-01-09 16:19 ` [PATCH 30/30] bsd-user/signal.c: do_sigaltstack Warner Losh
2022-01-14 13:18   ` Peter Maydell
2022-01-22 22:20     ` 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='CAFEAcA_fc_-qXoY07uZuMpT6kAUT+oT8RD_G=8vGgSQqDmH-WA@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=imp@bsdimp.com \
    --cc=kevans@freebsd.org \
    --cc=qemu-devel@nongnu.org \
    --cc=sson@freebsd.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.