[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 30/40] bsd-user/signal.c: sigset manipulation routines.
From: |
Warner Losh |
Subject: |
[PULL 30/40] bsd-user/signal.c: sigset manipulation routines. |
Date: |
Mon, 31 Jan 2022 12:56:26 -0700 |
target_sigemptyset: resets a set to having no bits set
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>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
bsd-user/signal-common.h | 2 ++
bsd-user/signal.c | 74 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+)
diff --git a/bsd-user/signal-common.h b/bsd-user/signal-common.h
index 80e9503238a..ee819266f54 100644
--- a/bsd-user/signal-common.h
+++ b/bsd-user/signal-common.h
@@ -14,11 +14,13 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong
uoss_addr, abi_ulong sp);
long do_sigreturn(CPUArchState *env);
void force_sig_fault(int sig, int code, abi_ulong addr);
int host_to_target_signal(int sig);
+void host_to_target_sigset(target_sigset_t *d, const sigset_t *s);
void process_pending_signals(CPUArchState *env);
void queue_signal(CPUArchState *env, int sig, int si_type,
target_siginfo_t *info);
void signal_init(void);
int target_to_host_signal(int sig);
+void target_to_host_sigset(sigset_t *d, const target_sigset_t *s);
/*
* Within QEMU the top 8 bits of si_code indicate which of the parts of the
diff --git a/bsd-user/signal.c b/bsd-user/signal.c
index 34663f7a28a..84dafa4e9fe 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);
+
/*
* The BSD ABIs use the same singal numbers across all the CPU architectures,
so
@@ -48,6 +51,25 @@ int target_to_host_signal(int sig)
return sig;
}
+static inline void target_sigemptyset(target_sigset_t *set)
+{
+ memset(set, 0, sizeof(*set));
+}
+
+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)
{
@@ -60,6 +82,58 @@ static inline void rewind_if_in_safe_syscall(void *puc)
}
}
+/*
+ * Note: The following take advantage of the BSD signal property that all
+ * signals are available on all architectures.
+ */
+static void host_to_target_sigset_internal(target_sigset_t *d,
+ const sigset_t *s)
+{
+ int i;
+
+ target_sigemptyset(d);
+ for (i = 1; i <= NSIG; i++) {
+ if (sigismember(s, i)) {
+ target_sigaddset(d, host_to_target_signal(i));
+ }
+ }
+}
+
+void host_to_target_sigset(target_sigset_t *d, const sigset_t *s)
+{
+ target_sigset_t d1;
+ int i;
+
+ host_to_target_sigset_internal(&d1, s);
+ for (i = 0; i < _SIG_WORDS; i++) {
+ d->__bits[i] = tswap32(d1.__bits[i]);
+ }
+}
+
+static void target_to_host_sigset_internal(sigset_t *d,
+ const target_sigset_t *s)
+{
+ int i;
+
+ sigemptyset(d);
+ for (i = 1; i <= TARGET_NSIG; i++) {
+ if (target_sigismember(s, i)) {
+ sigaddset(d, target_to_host_signal(i));
+ }
+ }
+}
+
+void target_to_host_sigset(sigset_t *d, const target_sigset_t *s)
+{
+ target_sigset_t s1;
+ int i;
+
+ for (i = 0; i < TARGET_NSIG_WORDS; i++) {
+ s1.__bits[i] = tswap32(s->__bits[i]);
+ }
+ target_to_host_sigset_internal(d, &s1);
+}
+
static bool has_trapno(int tsig)
{
return tsig == TARGET_SIGILL ||
--
2.33.1
- [PULL 37/40] bsd-user/signal.c: do_sigaltstack, (continued)
- [PULL 37/40] bsd-user/signal.c: do_sigaltstack, Warner Losh, 2022/01/31
- [PULL 29/40] bsd-user/signal.c: Fill in queue_signal, Warner Losh, 2022/01/31
- [PULL 35/40] bsd-user/signal.c: implement do_sigreturn, Warner Losh, 2022/01/31
- [PULL 04/40] bsd-user/arm/signal.c: get_mcontext should zero vfp data, Warner Losh, 2022/01/31
- [PULL 19/40] bsd-user/host/arm/host-signal.h: Implement host_signal_*, Warner Losh, 2022/01/31
- [PULL 11/40] bsd-user/signal.c: implement cpu_loop_exit_sigbus, Warner Losh, 2022/01/31
- [PULL 05/40] bsd-user: Remove vestiges of signal queueing code, Warner Losh, 2022/01/31
- [PULL 12/40] bsd-user/arm/arget_arch_cpu.h: Move EXCP_DEBUG and EXCP_BKPT together, Warner Losh, 2022/01/31
- [PULL 14/40] bsd-user/arm/target_arch_cpu.h: Use force_sig_fault for EXCP_UDEF, Warner Losh, 2022/01/31
- [PULL 21/40] bsd-user/host/x86_64/host-signal.h: Implement host_signal_*, Warner Losh, 2022/01/31
- [PULL 30/40] bsd-user/signal.c: sigset manipulation routines.,
Warner Losh <=
- [PULL 39/40] bsd-user: Rename arg name for target_cpu_reset to env, Warner Losh, 2022/01/31
- [PULL 26/40] bsd-user/signal.c: Implement host_signal_handler, Warner Losh, 2022/01/31
- [PULL 23/40] bsd-user: Add trace events for bsd-user, Warner Losh, 2022/01/31
- [PULL 31/40] bsd-user/signal.c: setup_frame, Warner Losh, 2022/01/31
- [PULL 17/40] bsd-user/signal.c: Implement signal_init(), Warner Losh, 2022/01/31
- [PULL 20/40] bsd-user/host/i386/host-signal.h: Implement host_signal_*, Warner Losh, 2022/01/31
- [PULL 02/40] bsd-user: Create setup_sigframe_arch to setup sigframe context, Warner Losh, 2022/01/31
- [PULL 15/40] bsd-user/arm/target_arch_cpu.h: Implement data faults, Warner Losh, 2022/01/31
- [PULL 27/40] bsd-user/strace.c: print_taken_signal, Warner Losh, 2022/01/31
- [PULL 28/40] bsd-user/signal.c: Implement dump_core_and_abort, Warner Losh, 2022/01/31