linux(4): Properly restore the thread signal mask after signal delivery on i386

Replace sigframe sf_extramask by native sigset_t and use it to
store/restore the thread signal mask without conversion to/from
Linux signal mask.

Pointy hat to:		dchagin
MFC after:		2 weeks
This commit is contained in:
Dmitry Chagin 2022-05-30 20:03:49 +03:00
parent 2722e515ac
commit 4a6c2d075d
3 changed files with 5 additions and 18 deletions

View File

@ -373,7 +373,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
bzero(&frame, sizeof(frame));
frame.sf_sig = sig;
frame.sf_sigmask = *mask;
bsd_to_linux_sigset(mask, &lmask);
/* Build the signal context to be used by sigreturn. */
@ -399,8 +399,6 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
frame.sf_sc.sc_cr2 = (u_int32_t)(uintptr_t)ksi->ksi_addr;
frame.sf_sc.sc_trapno = bsd_to_linux_trapcode(code);
frame.sf_extramask[0] = lmask.__mask;
if (copyout(&frame, fp, sizeof(frame)) != 0) {
/*
* Process has trashed its stack; give it an illegal
@ -442,8 +440,6 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
{
struct l_sigframe frame;
struct trapframe *regs;
sigset_t bmask;
l_sigset_t lmask;
int eflags;
ksiginfo_t ksi;
@ -477,10 +473,7 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
return(EINVAL);
}
lmask.__mask = frame.sf_sc.sc_mask;
lmask.__mask = frame.sf_extramask[0];
linux_to_bsd_sigset(&lmask, &bmask);
kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0);
kern_sigprocmask(td, SIG_SETMASK, &frame.sf_sigmask, NULL, 0);
/* Restore signal context. */
regs->tf_rdi = frame.sf_sc.sc_edi;

View File

@ -474,7 +474,7 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
bzero(&frame, sizeof(frame));
frame.sf_sig = sig;
frame.sf_sigmask = *mask;
bsd_to_linux_sigset(mask, &lmask);
/* Build the signal context to be used by sigreturn. */
@ -500,8 +500,6 @@ linux_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
frame.sf_sc.sc_cr2 = (register_t)ksi->ksi_addr;
frame.sf_sc.sc_trapno = bsd_to_linux_trapcode(ksi->ksi_trapno);
frame.sf_extramask[0] = lmask.__mask;
if (copyout(&frame, fp, sizeof(frame)) != 0) {
/*
* Process has trashed its stack; give it an illegal
@ -540,8 +538,6 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
{
struct l_sigframe frame;
struct trapframe *regs;
l_sigset_t lmask;
sigset_t bmask;
int eflags;
ksiginfo_t ksi;
@ -577,9 +573,7 @@ linux_sigreturn(struct thread *td, struct linux_sigreturn_args *args)
return (EINVAL);
}
lmask.__mask = frame.sf_sc.sc_mask;
linux_to_bsd_sigset(&lmask, &bmask);
kern_sigprocmask(td, SIG_SETMASK, &bmask, NULL, 0);
kern_sigprocmask(td, SIG_SETMASK, &frame.sf_sigmask, NULL, 0);
/* Restore signal context. */
/* %gs was restored by the trampoline. */

View File

@ -116,7 +116,7 @@ struct l_sigframe {
l_int sf_sig;
struct l_sigcontext sf_sc;
struct l_fpstate sf_fpstate;
l_uint sf_extramask[1];
sigset_t sf_sigmask;
};
struct l_rt_sigframe {