On Sun, 9 Jan 2022 at 16:29, Warner Losh <i...@bsdimp.com> wrote: > > Initialize the signal state for the emulator. Setup a set of sane > default signal handlers, mirroring the host's signals. For fatal signals > (those that exit by default), establish our own set of signal > handlers. Stub out the actual signal handler we use for the moment. > > Signed-off-by: Stacey Son <s...@freebsd.org> > Signed-off-by: Kyle Evans <kev...@freebsd.org> > Signed-off-by: Warner Losh <i...@bsdimp.com> > --- > bsd-user/qemu.h | 1 + > bsd-user/signal.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 69 insertions(+)
> +static struct target_sigaction sigact_table[TARGET_NSIG]; > void signal_init(void) > { > + TaskState *ts = (TaskState *)thread_cpu->opaque; > + struct sigaction act; > + struct sigaction oact; > + int i; > + int host_sig; > + > + /* Set the signal mask from the host mask. */ > + sigprocmask(0, 0, &ts->signal_mask); > + > + /* > + * Set all host signal handlers. ALL signals are blocked during the > + * handlers to serialize them. > + */ > + memset(sigact_table, 0, sizeof(sigact_table)); Do you need this memset()? sigact_table is a global, so it's zero-initialized on startup, and this function is only called once. The (otherwise basically identical) Linux version of this function doesn't have it. > + > + sigfillset(&act.sa_mask); > + act.sa_sigaction = host_signal_handler; > + act.sa_flags = SA_SIGINFO; > + > + for (i = 1; i <= TARGET_NSIG; i++) { > + host_sig = target_to_host_signal(i); > + sigaction(host_sig, NULL, &oact); > + if (oact.sa_sigaction == (void *)SIG_IGN) { > + sigact_table[i - 1]._sa_handler = TARGET_SIG_IGN; > + } else if (oact.sa_sigaction == (void *)SIG_DFL) { > + sigact_table[i - 1]._sa_handler = TARGET_SIG_DFL; > + } > + /* > + * If there's already a handler installed then something has > + * gone horribly wrong, so don't even try to handle that case. > + * Install some handlers for our own use. We need at least > + * SIGSEGV and SIGBUS, to detect exceptions. We can not just > + * trap all signals because it affects syscall interrupt > + * behavior. But do trap all default-fatal signals. > + */ > + if (fatal_signal(i)) { > + sigaction(host_sig, &act, NULL); > + } > + } > } Otherwise Reviewed-by: Peter Maydell <peter.mayd...@linaro.org> thanks -- PMM