On Sun, 9 Jan 2022 at 16:56, Warner Losh <i...@bsdimp.com> wrote: > > Convert siginfo from targer to host. > > 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/signal.c | 34 ++++++++++++++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > > diff --git a/bsd-user/signal.c b/bsd-user/signal.c > index 934528d5fb0..c954d0f4f37 100644 > --- a/bsd-user/signal.c > +++ b/bsd-user/signal.c > @@ -197,6 +197,40 @@ static inline void > host_to_target_siginfo_noswap(target_siginfo_t *tinfo, > } > } > > +static void tswap_siginfo(target_siginfo_t *tinfo, const target_siginfo_t > *info) > +{ > + int sig, code; > + > + sig = info->si_signo; > + code = info->si_code; > + tinfo->si_signo = tswap32(sig); > + tinfo->si_errno = tswap32(info->si_errno); > + tinfo->si_code = tswap32(info->si_code); > + tinfo->si_pid = tswap32(info->si_pid); > + tinfo->si_uid = tswap32(info->si_uid); > + tinfo->si_status = tswap32(info->si_status); > + tinfo->si_addr = tswapal(info->si_addr);
This implicitly assumes FreeBSD target_siginfo_t, because (a) all the field names are different on eg NetBSD (b) if, like NetBSD, the pid and uid fields are inside the same union as the addr, you can't just swap all of them unconditionally but need different logic to handle them as part of the "which bit of the union is valid" code. FreeBSD-only is fine for now, but you might want to add a comment. > + /* > + * Unswapped, because we passed it through mostly untouched. si_value is > + * opaque to the kernel, so we didn't bother with potentially wasting > cycles > + * to swap it into host byte order. > + */ > + tinfo->si_value.sival_ptr = info->si_value.sival_ptr; > + if (SIGILL == sig || SIGFPE == sig || SIGSEGV == sig || SIGBUS == sig || > + SIGTRAP == sig) { > + tinfo->_reason._fault._trapno = > tswap32(info->_reason._fault._trapno); > + } > +#ifdef SIGPOLL > + if (SIGPOLL == sig) { > + tinfo->_reason._poll._band = tswap32(info->_reason._poll._band); > + } > +#endif > + if (SI_TIMER == code) { > + tinfo->_reason._timer._timerid = > tswap32(info->_reason._timer._timerid); > + tinfo->_reason._timer._overrun = > tswap32(info->_reason._timer._overrun); > + } > +} You had a call to this already in the previous patch, which presumably means that it didn't compile at that point in the series, so this patch should be moved earlier. My reply to patch 2 has the higher-level commentary about handling of target_siginfo_t. thanks -- PMM