bsd-user/signal.c: Only copy the _capsicum for FreeBSD_version > 1400026

The capsicum signal stuff is new with FreeBSD 14, rev 1400026, so only
define QEMU_SI_CAPSICUM there. Only copy _capsicum when QEMU_SI_CAPSICUM
is defined. Default to no info being passed for signals we make no guess
about.

Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Warner Losh 2022-02-01 13:30:30 -07:00
parent 3bbe296c1c
commit eb9d35f686
2 changed files with 10 additions and 0 deletions

View File

@ -59,12 +59,17 @@ void target_to_host_sigset(sigset_t *d, const target_sigset_t *s);
* For FreeBSD, we have si_pid, si_uid, si_status, and si_addr always. Linux and * For FreeBSD, we have si_pid, si_uid, si_status, and si_addr always. Linux and
* {Open,Net}BSD have a different approach (where their reason field is larger, * {Open,Net}BSD have a different approach (where their reason field is larger,
* but whose siginfo has fewer fields always). * but whose siginfo has fewer fields always).
*
* QEMU_SI_CAPSICUM is currently only FreeBSD 14 current only, so only define
* it where _capsicum is available.
*/ */
#define QEMU_SI_NOINFO 0 /* nothing other than si_signo valid */ #define QEMU_SI_NOINFO 0 /* nothing other than si_signo valid */
#define QEMU_SI_FAULT 1 /* _fault is valid in _reason */ #define QEMU_SI_FAULT 1 /* _fault is valid in _reason */
#define QEMU_SI_TIMER 2 /* _timer is valid in _reason */ #define QEMU_SI_TIMER 2 /* _timer is valid in _reason */
#define QEMU_SI_MESGQ 3 /* _mesgq is valid in _reason */ #define QEMU_SI_MESGQ 3 /* _mesgq is valid in _reason */
#define QEMU_SI_POLL 4 /* _poll is valid in _reason */ #define QEMU_SI_POLL 4 /* _poll is valid in _reason */
#if defined(__FreeBSD_version) && __FreeBSD_version >= 1400026
#define QEMU_SI_CAPSICUM 5 /* _capsicum is valid in _reason */ #define QEMU_SI_CAPSICUM 5 /* _capsicum is valid in _reason */
#endif
#endif #endif

View File

@ -222,6 +222,7 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
* We have to go based on the signal number now to figure out * We have to go based on the signal number now to figure out
* what's valid. * what's valid.
*/ */
si_type = QEMU_SI_NOINFO;
if (has_trapno(sig)) { if (has_trapno(sig)) {
tinfo->_reason._fault._trapno = info->_reason._fault._trapno; tinfo->_reason._fault._trapno = info->_reason._fault._trapno;
si_type = QEMU_SI_FAULT; si_type = QEMU_SI_FAULT;
@ -241,11 +242,13 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
* capsicum is somewhere between weak and non-existant, but if we get * capsicum is somewhere between weak and non-existant, but if we get
* one, then we know what to save. * one, then we know what to save.
*/ */
#ifdef QEMU_SI_CAPSICUM
if (sig == TARGET_SIGTRAP) { if (sig == TARGET_SIGTRAP) {
tinfo->_reason._capsicum._syscall = tinfo->_reason._capsicum._syscall =
info->_reason._capsicum._syscall; info->_reason._capsicum._syscall;
si_type = QEMU_SI_CAPSICUM; si_type = QEMU_SI_CAPSICUM;
} }
#endif
break; break;
} }
tinfo->si_code = deposit32(si_code, 24, 8, si_type); tinfo->si_code = deposit32(si_code, 24, 8, si_type);
@ -295,10 +298,12 @@ static void tswap_siginfo(target_siginfo_t *tinfo, const target_siginfo_t *info)
/* Note: Not generated on FreeBSD */ /* Note: Not generated on FreeBSD */
__put_user(info->_reason._poll._band, &tinfo->_reason._poll._band); __put_user(info->_reason._poll._band, &tinfo->_reason._poll._band);
break; break;
#ifdef QEMU_SI_CAPSICUM
case QEMU_SI_CAPSICUM: case QEMU_SI_CAPSICUM:
__put_user(info->_reason._capsicum._syscall, __put_user(info->_reason._capsicum._syscall,
&tinfo->_reason._capsicum._syscall); &tinfo->_reason._capsicum._syscall);
break; break;
#endif
default: default:
g_assert_not_reached(); g_assert_not_reached();
} }