[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 34/40] bsd-user/signal.c: process_pending_signals
From: |
Warner Losh |
Subject: |
[PATCH v3 34/40] bsd-user/signal.c: process_pending_signals |
Date: |
Fri, 28 Jan 2022 16:27:59 -0700 |
Process the currently queued signals.
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.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 55 insertions(+), 1 deletion(-)
diff --git a/bsd-user/signal.c b/bsd-user/signal.c
index 34e8c811ad6..4b398745f45 100644
--- a/bsd-user/signal.c
+++ b/bsd-user/signal.c
@@ -756,8 +756,62 @@ static void handle_pending_signal(CPUArchState *env, int
sig,
}
}
-void process_pending_signals(CPUArchState *cpu_env)
+void process_pending_signals(CPUArchState *env)
{
+ CPUState *cpu = env_cpu(env);
+ int sig;
+ sigset_t *blocked_set, set;
+ struct emulated_sigtable *k;
+ TaskState *ts = cpu->opaque;
+
+ while (qatomic_read(&ts->signal_pending)) {
+ sigfillset(&set);
+ sigprocmask(SIG_SETMASK, &set, 0);
+
+ restart_scan:
+ sig = ts->sync_signal.pending;
+ if (sig) {
+ /*
+ * Synchronous signals are forced by the emulated CPU in some way.
+ * If they are set to ignore, restore the default handler (see
+ * sys/kern_sig.c trapsignal() and execsigs() for this behavior)
+ * though maybe this is done only when forcing exit for non
SIGCHLD.
+ */
+ if (sigismember(&ts->signal_mask, target_to_host_signal(sig)) ||
+ sigact_table[sig - 1]._sa_handler == TARGET_SIG_IGN) {
+ sigdelset(&ts->signal_mask, target_to_host_signal(sig));
+ sigact_table[sig - 1]._sa_handler = TARGET_SIG_DFL;
+ }
+ handle_pending_signal(env, sig, &ts->sync_signal);
+ }
+
+ k = ts->sigtab;
+ for (sig = 1; sig <= TARGET_NSIG; sig++, k++) {
+ blocked_set = ts->in_sigsuspend ?
+ &ts->sigsuspend_mask : &ts->signal_mask;
+ if (k->pending &&
+ !sigismember(blocked_set, target_to_host_signal(sig))) {
+ handle_pending_signal(env, sig, k);
+ /*
+ * Restart scan from the beginning, as handle_pending_signal
+ * might have resulted in a new synchronous signal (eg
SIGSEGV).
+ */
+ goto restart_scan;
+ }
+ }
+
+ /*
+ * Unblock signals and check one more time. Unblocking signals may
cause
+ * us to take another host signal, which will set signal_pending again.
+ */
+ qatomic_set(&ts->signal_pending, 0);
+ ts->in_sigsuspend = false;
+ set = ts->signal_mask;
+ sigdelset(&set, SIGSEGV);
+ sigdelset(&set, SIGBUS);
+ sigprocmask(SIG_SETMASK, &set, 0);
+ }
+ ts->in_sigsuspend = false;
}
void cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr,
--
2.33.1
- [PATCH v3 32/40] bsd-user/signal.c: handle_pending_signal, (continued)
- [PATCH v3 32/40] bsd-user/signal.c: handle_pending_signal, Warner Losh, 2022/01/28
- [PATCH v3 40/40] bsd-user/freebsd/target_os_ucontext.h: Prefer env as arg name for CPUArchState args, Warner Losh, 2022/01/28
- [PATCH v3 39/40] bsd-user: Rename arg name for target_cpu_reset to env, Warner Losh, 2022/01/28
- [PATCH v3 30/40] bsd-user/signal.c: sigset manipulation routines., Warner Losh, 2022/01/28
- [PATCH v3 37/40] bsd-user/signal.c: do_sigaltstack, Warner Losh, 2022/01/28
- [PATCH v3 19/40] bsd-user/host/arm/host-signal.h: Implement host_signal_*, Warner Losh, 2022/01/28
- [PATCH v3 29/40] bsd-user/signal.c: Fill in queue_signal, Warner Losh, 2022/01/28
- [PATCH v3 31/40] bsd-user/signal.c: setup_frame, Warner Losh, 2022/01/28
- [PATCH v3 27/40] bsd-user/strace.c: print_taken_signal, Warner Losh, 2022/01/28
- [PATCH v3 33/40] bsd-user/signal.c: tswap_siginfo, Warner Losh, 2022/01/28
- [PATCH v3 34/40] bsd-user/signal.c: process_pending_signals,
Warner Losh <=
- [PATCH v3 38/40] MAINTAINERS: Add tests/vm/*bsd to the list to get reviews on, Warner Losh, 2022/01/28