10ef59989SWarner Losh /* 20ef59989SWarner Losh * Emulation of BSD signals 30ef59989SWarner Losh * 40ef59989SWarner Losh * Copyright (c) 2013 Stacey Son 50ef59989SWarner Losh * 60ef59989SWarner Losh * SPDX-License-Identifier: GPL-2.0-or-later 70ef59989SWarner Losh */ 80ef59989SWarner Losh 90ef59989SWarner Losh #ifndef SIGNAL_COMMON_H 100ef59989SWarner Losh #define SIGNAL_COMMON_H 110ef59989SWarner Losh 12394cf694SWarner Losh /** 13394cf694SWarner Losh * block_signals: block all signals while handling this guest syscall 14394cf694SWarner Losh * 15394cf694SWarner Losh * Block all signals, and arrange that the signal mask is returned to 16394cf694SWarner Losh * its correct value for the guest before we resume execution of guest code. 17394cf694SWarner Losh * If this function returns non-zero, then the caller should immediately 18394cf694SWarner Losh * return -TARGET_ERESTARTSYS to the main loop, which will take the pending 19394cf694SWarner Losh * signal and restart execution of the syscall. 20394cf694SWarner Losh * If block_signals() returns zero, then the caller can continue with 21394cf694SWarner Losh * emulation of the system call knowing that no signals can be taken 22394cf694SWarner Losh * (and therefore that no race conditions will result). 23394cf694SWarner Losh * This should only be called once, because if it is called a second time 24394cf694SWarner Losh * it will always return non-zero. (Think of it like a mutex that can't 25394cf694SWarner Losh * be recursively locked.) 26394cf694SWarner Losh * Signals will be unblocked again by process_pending_signals(). 27394cf694SWarner Losh * 28394cf694SWarner Losh * Return value: non-zero if there was a pending signal, zero if not. 29394cf694SWarner Losh */ 30394cf694SWarner Losh int block_signals(void); /* Returns non zero if signal pending */ 31394cf694SWarner Losh 322bd010c4SWarner Losh long do_rt_sigreturn(CPUArchState *env); 33394cf694SWarner Losh int do_sigaction(int sig, const struct target_sigaction *act, 34394cf694SWarner Losh struct target_sigaction *oact); 352bd010c4SWarner Losh abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp); 36c885ae0eSWarner Losh long do_sigreturn(CPUArchState *env, abi_ulong addr); 370ef59989SWarner Losh void force_sig_fault(int sig, int code, abi_ulong addr); 383f254cf2SStacey Son void host_to_target_siginfo(target_siginfo_t *tinfo, const siginfo_t *info); 391366ef81SWarner Losh int host_to_target_signal(int sig); 40c93cbac1SWarner Losh void host_to_target_sigset(target_sigset_t *d, const sigset_t *s); 412bd010c4SWarner Losh void process_pending_signals(CPUArchState *env); 42e32a6301SWarner Losh void queue_signal(CPUArchState *env, int sig, int si_type, 43e32a6301SWarner Losh target_siginfo_t *info); 442bd010c4SWarner Losh void signal_init(void); 451366ef81SWarner Losh int target_to_host_signal(int sig); 46c93cbac1SWarner Losh void target_to_host_sigset(sigset_t *d, const target_sigset_t *s); 470ef59989SWarner Losh 48e32a6301SWarner Losh /* 49e32a6301SWarner Losh * Within QEMU the top 8 bits of si_code indicate which of the parts of the 50e32a6301SWarner Losh * union in target_siginfo is valid. This only applies between 51e32a6301SWarner Losh * host_to_target_siginfo_noswap() and tswap_siginfo(); it does not appear 52e32a6301SWarner Losh * either within host siginfo_t or in target_siginfo structures which we get 53944399ffSMichael Tokarev * from the guest userspace program. Linux kernels use this internally, but BSD 54e32a6301SWarner Losh * kernels don't do this, but its a useful abstraction. 55e32a6301SWarner Losh * 56e32a6301SWarner Losh * The linux-user version of this uses the top 16 bits, but FreeBSD's SI_USER 57944399ffSMichael Tokarev * and other signal independent SI_ codes have bit 16 set, so we only use the top 58e32a6301SWarner Losh * byte instead. 59e32a6301SWarner Losh * 60e32a6301SWarner Losh * For FreeBSD, we have si_pid, si_uid, si_status, and si_addr always. Linux and 61e32a6301SWarner Losh * {Open,Net}BSD have a different approach (where their reason field is larger, 62e32a6301SWarner Losh * but whose siginfo has fewer fields always). 63eb9d35f6SWarner Losh * 64eb9d35f6SWarner Losh * QEMU_SI_CAPSICUM is currently only FreeBSD 14 current only, so only define 65eb9d35f6SWarner Losh * it where _capsicum is available. 66e32a6301SWarner Losh */ 67e32a6301SWarner Losh #define QEMU_SI_NOINFO 0 /* nothing other than si_signo valid */ 68e32a6301SWarner Losh #define QEMU_SI_FAULT 1 /* _fault is valid in _reason */ 69e32a6301SWarner Losh #define QEMU_SI_TIMER 2 /* _timer is valid in _reason */ 70e32a6301SWarner Losh #define QEMU_SI_MESGQ 3 /* _mesgq is valid in _reason */ 71e32a6301SWarner Losh #define QEMU_SI_POLL 4 /* _poll is valid in _reason */ 72eb9d35f6SWarner Losh #if defined(__FreeBSD_version) && __FreeBSD_version >= 1400026 73e32a6301SWarner Losh #define QEMU_SI_CAPSICUM 5 /* _capsicum is valid in _reason */ 74eb9d35f6SWarner Losh #endif 75e32a6301SWarner Losh 760ef59989SWarner Losh #endif 77