git: cab31f5633c1 - main - kern: add a TDA_PSELECT for early restoration of sigmask

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Tue, 26 Nov 2024 04:05:18 UTC
The branch main has been updated by kevans:

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

commit cab31f5633c1ffdd8b24749a3c9dd22c59568503
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2024-11-26 04:04:48 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2024-11-26 04:04:48 +0000

    kern: add a TDA_PSELECT for early restoration of sigmask
    
    It may be the case that we want to avoid delivering signals that are
    normally blocked by the thread's signal mask, in which case the syscall
    should schedule this one instead to restore the mask prior to delivery.
    
    This will be used by pselect/ppoll to avoid delivering signals that were
    supposed to be blocked after the timeout has elapsed.  The name was
    chosen as this is the expected behavior of pselect/ppoll, while late
    restoration of the mask is exceptional behavior for these specific
    calls.
    
    __FreeBSD_version bump as later TDA_* values have changed, third-party
    modules that may be using MOD3/MOD4 need to be rebuilt.
    
    Reviewed by:    kib
    Sponsored by:   Klara, Inc.
    Sponsored by:   NetApp, Inc.
    Differential Revision:  https://reviews.freebsd.org/D47741
---
 sys/kern/kern_sig.c | 10 ++++++++++
 sys/sys/param.h     |  2 +-
 sys/sys/proc.h      |  1 +
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index cded24450ca1..96dc5e356ae9 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -365,6 +365,16 @@ sigqueue_start(void)
 	SIGFILLSET(fastblock_mask);
 	SIG_CANTMASK(fastblock_mask);
 	ast_register(TDA_SIG, ASTR_UNCOND, 0, ast_sig);
+
+	/*
+	 * TDA_PSELECT is for the case where the signal mask should be restored
+	 * before delivering any signals so that we do not deliver any that are
+	 * blocked by the normal thread mask.  It is mutually exclusive with
+	 * TDA_SIGSUSPEND, which should be used if we *do* want to deliver
+	 * signals that are normally blocked, e.g., if it interrupted our sleep.
+	 */
+	ast_register(TDA_PSELECT, ASTR_ASTF_REQUIRED | ASTR_TDP,
+	    TDP_OLDMASK, ast_sigsuspend);
 	ast_register(TDA_SIGSUSPEND, ASTR_ASTF_REQUIRED | ASTR_TDP,
 	    TDP_OLDMASK, ast_sigsuspend);
 }
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 79ecd58569a3..550ea1fc61f6 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -73,7 +73,7 @@
  * cannot include sys/param.h and should only be updated here.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1500027
+#define __FreeBSD_version 1500028
 
 /*
  * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
index c5ef4f849eab..3422f75172f0 100644
--- a/sys/sys/proc.h
+++ b/sys/sys/proc.h
@@ -494,6 +494,7 @@ enum {
 	TDA_RACCT,
 	TDA_MOD1,		/* For third party use, before signals are */
 	TAD_MOD2,		/* processed .. */
+	TDA_PSELECT,		/* For discarding temporary signal mask */
 	TDA_SIG,
 	TDA_KTRACE,
 	TDA_SUSPEND,