Message ID | 20220109161923.85683-28-imp@bsdimp.com |
---|---|
State | New |
Headers | show |
Series | bsd-user: upstream our signal implementation | expand |
On Sun, 9 Jan 2022 at 16:57, Warner Losh <imp@bsdimp.com> wrote: > > 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> > --- > bsd-user/signal.c | 34 ++++++++++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > > diff --git a/bsd-user/signal.c b/bsd-user/signal.c > index c954d0f4f37..1dd6dbb4ee1 100644 > --- a/bsd-user/signal.c > +++ b/bsd-user/signal.c > @@ -781,6 +781,40 @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig, > > void process_pending_signals(CPUArchState *cpu_env) I won't review this, because I favour using the logic that linux-user does here. -- PMM
On Fri, Jan 14, 2022 at 4:55 AM Peter Maydell <peter.maydell@linaro.org> wrote: > On Sun, 9 Jan 2022 at 16:57, Warner Losh <imp@bsdimp.com> wrote: > > > > 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> > > --- > > bsd-user/signal.c | 34 ++++++++++++++++++++++++++++++++++ > > 1 file changed, 34 insertions(+) > > > > diff --git a/bsd-user/signal.c b/bsd-user/signal.c > > index c954d0f4f37..1dd6dbb4ee1 100644 > > --- a/bsd-user/signal.c > > +++ b/bsd-user/signal.c > > @@ -781,6 +781,40 @@ static void handle_pending_signal(CPUArchState > *cpu_env, int sig, > > > > void process_pending_signals(CPUArchState *cpu_env) > > I won't review this, because I favour using the logic that > linux-user does here. > I've rewritten it to use that, I believe (I'll check that belief before v2), so likely a good call. Warner
diff --git a/bsd-user/signal.c b/bsd-user/signal.c index c954d0f4f37..1dd6dbb4ee1 100644 --- a/bsd-user/signal.c +++ b/bsd-user/signal.c @@ -781,6 +781,40 @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig, void process_pending_signals(CPUArchState *cpu_env) { + CPUState *cpu = env_cpu(cpu_env); + int sig; + sigset_t *blocked_set, set; + struct emulated_sigtable *k; + TaskState *ts = cpu->opaque; + + while (qatomic_read(&ts->signal_pending)) { + /* FIXME: This is not threadsafe. */ + + sigfillset(&set); + sigprocmask(SIG_SETMASK, &set, 0); + + k = ts->sigtab; + blocked_set = ts->in_sigsuspend ? + &ts->sigsuspend_mask : &ts->signal_mask; + for (sig = 1; sig <= TARGET_NSIG; sig++, k++) { + if (k->pending && + !sigismember(blocked_set, target_to_host_signal(sig))) { + handle_pending_signal(cpu_env, sig, k); + } + } + + /* + * unblock signals and check one more time. Unblocking signals may cause + * us to take anothe rhost 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,