The branch main has been updated by dchagin:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=4a6c2d075da0c5105269e6edcbe57bf6aaa0a0ae

commit 4a6c2d075da0c5105269e6edcbe57bf6aaa0a0ae
Author:     Dmitry Chagin <dcha...@freebsd.org>
AuthorDate: 2022-05-30 17:03:49 +0000
Commit:     Dmitry Chagin <dcha...@freebsd.org>
CommitDate: 2022-05-30 17:03:49 +0000

    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
---
 sys/amd64/linux32/linux32_sysvec.c | 11 ++---------
 sys/i386/linux/linux_sysvec.c      | 10 ++--------
 sys/x86/linux/linux_x86_sigframe.h |  2 +-
 3 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/sys/amd64/linux32/linux32_sysvec.c 
b/sys/amd64/linux32/linux32_sysvec.c
index ff16822a352b..e9162f04d3f7 100644
--- a/sys/amd64/linux32/linux32_sysvec.c
+++ b/sys/amd64/linux32/linux32_sysvec.c
@@ -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;
diff --git a/sys/i386/linux/linux_sysvec.c b/sys/i386/linux/linux_sysvec.c
index 12f02ca22cb4..269ab3b7ab75 100644
--- a/sys/i386/linux/linux_sysvec.c
+++ b/sys/i386/linux/linux_sysvec.c
@@ -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. */
diff --git a/sys/x86/linux/linux_x86_sigframe.h 
b/sys/x86/linux/linux_x86_sigframe.h
index 56ff346ea5b7..75d9a104a345 100644
--- a/sys/x86/linux/linux_x86_sigframe.h
+++ b/sys/x86/linux/linux_x86_sigframe.h
@@ -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 {

Reply via email to