On Sun, 9 Jan 2022 at 17:08, Warner Losh <imp@bsdimp.com> wrote:
>
> Implement the meat of the sigaltstack(2) system call with do_sigaltstack.
>
> 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 | 1 +
> bsd-user/signal.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 67 insertions(+)
>
> diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
> index c643d6ba246..fcdea460ed2 100644
> --- a/bsd-user/qemu.h
> +++ b/bsd-user/qemu.h
> @@ -226,6 +226,7 @@ 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);
> long do_sigreturn(CPUArchState *regs, abi_ulong addr);
> +abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp);
> int do_sigaction(int sig, const struct target_sigaction *act,
> struct target_sigaction *oact);
> void QEMU_NORETURN force_sig(int target_sig);
> diff --git a/bsd-user/signal.c b/bsd-user/signal.c
> index f055d1db407..e5e5e28c60c 100644
> --- a/bsd-user/signal.c
> +++ b/bsd-user/signal.c
> @@ -528,6 +528,72 @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
> cpu_exit(thread_cpu);
> }
>
> +/* do_sigaltstack() returns target values and errnos. */
> +/* compare to kern/kern_sig.c sys_sigaltstack() and kern_sigaltstack() */
> +abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp)
> +{
> + int ret;
> + target_stack_t oss;
> +
> + if (uoss_addr) {
> + /* Save current signal stack params */
> + oss.ss_sp = tswapl(target_sigaltstack_used.ss_sp);
> + oss.ss_size = tswapl(target_sigaltstack_used.ss_size);
> + oss.ss_flags = tswapl(sas_ss_flags(sp));
> + }
This will need some minor changes to work with the sigaltstack
info being per-thread and in the TaskState struct.
Yes. Moving it into the TaskState was easy and got rid if the global.
Thanks for that suggestion earlier in the patch series.
Warrner