git: 698ba43e0ec7 - main - sig*(2): add kern_ and user_ implementations
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 10 Nov 2026 15:54:39 UTC
The branch main has been updated by brooks:
URL: https://cgit.FreeBSD.org/src/commit/?id=698ba43e0ec7a3cb107a4b14be6f781965b1d3c4
commit 698ba43e0ec7a3cb107a4b14be6f781965b1d3c4
Author: Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2025-11-24 15:33:34 +0000
Commit: Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-10 15:54:20 +0000
sig*(2): add kern_ and user_ implementations
Effort: CHERI upstreaming
Sponsored by: Innovate UK
Pull Request: https://github.com/freebsd/freebsd-src/pull/2284
---
sys/kern/kern_sig.c | 92 ++++++++++++++++++++++++++++++++++++++++-----------
sys/sys/signal.h | 4 +++
sys/sys/syscallsubr.h | 11 ++++++
3 files changed, 87 insertions(+), 20 deletions(-)
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 629ce1c3c40a..10ddc61ea184 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1194,21 +1194,28 @@ struct sigprocmask_args {
#endif
int
sys_sigprocmask(struct thread *td, struct sigprocmask_args *uap)
+{
+ return (user_sigprocmask(td, uap->how, uap->set, uap->oset));
+}
+
+int
+user_sigprocmask(struct thread *td, int how, const sigset_t *uset,
+ sigset_t *uoset)
{
sigset_t set, oset;
sigset_t *setp, *osetp;
int error;
- setp = (uap->set != NULL) ? &set : NULL;
- osetp = (uap->oset != NULL) ? &oset : NULL;
+ setp = (uset != NULL) ? &set : NULL;
+ osetp = (uoset != NULL) ? &oset : NULL;
if (setp) {
- error = copyin(uap->set, setp, sizeof(set));
+ error = copyin(uset, setp, sizeof(set));
if (error)
return (error);
}
- error = kern_sigprocmask(td, uap->how, setp, osetp, 0);
+ error = kern_sigprocmask(td, how, setp, osetp, 0);
if (osetp && !error) {
- error = copyout(osetp, uap->oset, sizeof(oset));
+ error = copyout(osetp, uoset, sizeof(oset));
}
return (error);
}
@@ -1235,12 +1242,18 @@ osigprocmask(struct thread *td, struct osigprocmask_args *uap)
int
sys_sigwait(struct thread *td, struct sigwait_args *uap)
+{
+ return (user_sigwait(td, uap->set, uap->sig));
+}
+
+int
+user_sigwait(struct thread *td, const sigset_t *uset, int *usig)
{
ksiginfo_t ksi;
sigset_t set;
int error;
- error = copyin(uap->set, &set, sizeof(set));
+ error = copyin(uset, &set, sizeof(set));
if (error) {
td->td_retval[0] = error;
return (0);
@@ -1261,13 +1274,27 @@ sys_sigwait(struct thread *td, struct sigwait_args *uap)
return (0);
}
- error = copyout(&ksi.ksi_signo, uap->sig, sizeof(ksi.ksi_signo));
+ error = copyout(&ksi.ksi_signo, usig, sizeof(ksi.ksi_signo));
td->td_retval[0] = error;
return (0);
}
+static int
+copyout_siginfo(const siginfo_t *si, void *info)
+{
+ return (copyout(si, info, sizeof(*si)));
+}
+
int
sys_sigtimedwait(struct thread *td, struct sigtimedwait_args *uap)
+{
+ return (user_sigtimedwait(td, uap->set, uap->info, uap->timeout,
+ copyout_siginfo));
+}
+
+int
+user_sigtimedwait(struct thread *td, const sigset_t *uset, void *info,
+ const struct timespec *utimeout, copyout_siginfo_t *copyout_siginfop)
{
struct timespec ts;
struct timespec *timeout;
@@ -1275,8 +1302,8 @@ sys_sigtimedwait(struct thread *td, struct sigtimedwait_args *uap)
ksiginfo_t ksi;
int error;
- if (uap->timeout) {
- error = copyin(uap->timeout, &ts, sizeof(ts));
+ if (utimeout) {
+ error = copyin(utimeout, &ts, sizeof(ts));
if (error)
return (error);
@@ -1284,7 +1311,7 @@ sys_sigtimedwait(struct thread *td, struct sigtimedwait_args *uap)
} else
timeout = NULL;
- error = copyin(uap->set, &set, sizeof(set));
+ error = copyin(uset, &set, sizeof(set));
if (error)
return (error);
@@ -1292,8 +1319,8 @@ sys_sigtimedwait(struct thread *td, struct sigtimedwait_args *uap)
if (error)
return (error);
- if (uap->info)
- error = copyout(&ksi.ksi_info, uap->info, sizeof(siginfo_t));
+ if (info)
+ error = copyout_siginfop(&ksi.ksi_info, info);
if (error == 0)
td->td_retval[0] = ksi.ksi_signo;
@@ -1302,12 +1329,19 @@ sys_sigtimedwait(struct thread *td, struct sigtimedwait_args *uap)
int
sys_sigwaitinfo(struct thread *td, struct sigwaitinfo_args *uap)
+{
+ return (user_sigwaitinfo(td, uap->set, uap->info, copyout_siginfo));
+}
+
+int
+user_sigwaitinfo(struct thread *td, const sigset_t *uset, void *info,
+ copyout_siginfo_t *copyout_siginfop)
{
ksiginfo_t ksi;
sigset_t set;
int error;
- error = copyin(uap->set, &set, sizeof(set));
+ error = copyin(uset, &set, sizeof(set));
if (error)
return (error);
@@ -1315,8 +1349,8 @@ sys_sigwaitinfo(struct thread *td, struct sigwaitinfo_args *uap)
if (error)
return (error);
- if (uap->info)
- error = copyout(&ksi.ksi_info, uap->info, sizeof(siginfo_t));
+ if (info)
+ error = copyout_siginfop(&ksi.ksi_info, info);
if (error == 0)
td->td_retval[0] = ksi.ksi_signo;
@@ -1477,6 +1511,12 @@ struct sigpending_args {
#endif
int
sys_sigpending(struct thread *td, struct sigpending_args *uap)
+{
+ return (kern_sigpending(td, uap->set));
+}
+
+int
+kern_sigpending(struct thread *td, sigset_t *set)
{
struct proc *p = td->td_proc;
sigset_t pending;
@@ -1485,7 +1525,7 @@ sys_sigpending(struct thread *td, struct sigpending_args *uap)
pending = p->p_sigqueue.sq_signals;
SIGSETOR(pending, td->td_sigqueue.sq_signals);
PROC_UNLOCK(p);
- return (copyout(&pending, uap->set, sizeof(sigset_t)));
+ return (copyout(&pending, set, sizeof(sigset_t)));
}
#ifdef COMPAT_43 /* XXX - COMPAT_FBSD3 */
@@ -1599,11 +1639,17 @@ struct sigsuspend_args {
/* ARGSUSED */
int
sys_sigsuspend(struct thread *td, struct sigsuspend_args *uap)
+{
+ return (user_sigsuspend(td, uap->sigmask));
+}
+
+int
+user_sigsuspend(struct thread *td, const sigset_t *sigmask)
{
sigset_t mask;
int error;
- error = copyin(uap->sigmask, &mask, sizeof(mask));
+ error = copyin(sigmask, &mask, sizeof(mask));
if (error)
return (error);
return (kern_sigsuspend(td, mask));
@@ -3973,6 +4019,12 @@ sigfastblock_resched(struct thread *td, bool resched)
int
sys_sigfastblock(struct thread *td, struct sigfastblock_args *uap)
+{
+ return (kern_sigfastblock(td, uap->cmd, uap->ptr));
+}
+
+int
+kern_sigfastblock(struct thread *td, int cmd, uint32_t *ptr)
{
struct proc *p;
int error, res;
@@ -3980,18 +4032,18 @@ sys_sigfastblock(struct thread *td, struct sigfastblock_args *uap)
error = 0;
p = td->td_proc;
- switch (uap->cmd) {
+ switch (cmd) {
case SIGFASTBLOCK_SETPTR:
if ((td->td_pflags & TDP_SIGFASTBLOCK) != 0) {
error = EBUSY;
break;
}
- if (((uintptr_t)(uap->ptr) & (sizeof(uint32_t) - 1)) != 0) {
+ if (((uintptr_t)(ptr) & (sizeof(uint32_t) - 1)) != 0) {
error = EINVAL;
break;
}
td->td_pflags |= TDP_SIGFASTBLOCK;
- td->td_sigblock_ptr = uap->ptr;
+ td->td_sigblock_ptr = ptr;
break;
case SIGFASTBLOCK_UNBLOCK:
diff --git a/sys/sys/signal.h b/sys/sys/signal.h
index 792087f735a1..7f987969a847 100644
--- a/sys/sys/signal.h
+++ b/sys/sys/signal.h
@@ -246,6 +246,10 @@ typedef struct __siginfo {
} _reason;
} siginfo_t;
+#ifdef _KERNEL
+typedef int (copyout_siginfo_t)(const siginfo_t *si, void *info);
+#endif
+
#define si_trapno _reason._fault._trapno
#define si_timerid _reason._timer._timerid
#define si_overrun _reason._timer._overrun
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 4ecdc70fd3ba..199c2039c7b3 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -467,6 +467,8 @@ int kern_shutdown(struct thread *td, int s, int how);
int kern_sigaction(struct thread *td, int sig, const struct sigaction *act,
struct sigaction *oact, int flags);
int kern_sigaltstack(struct thread *td, stack_t *ss, stack_t *oss);
+int kern_sigfastblock(struct thread *td, int cmd, uint32_t *ptr);
+int kern_sigpending(struct thread *td, sigset_t *set);
int kern_sigprocmask(struct thread *td, int how,
sigset_t *set, sigset_t *oset, int flags);
int kern_sigsuspend(struct thread *td, sigset_t mask);
@@ -538,6 +540,15 @@ int user_jail_set(struct thread *td, struct iovec *iovp,
unsigned int iovcnt, int flags, copyinuio_t *copyinuio_f);
int user_kldload(struct thread *td, const char *file);
int user_setgroups(struct thread *td, int gidsetsize, const gid_t *gidset);
+int user_sigprocmask(struct thread *td, int how, const sigset_t *uset,
+ sigset_t *uoset);
+int user_sigsuspend(struct thread *td, const sigset_t *sigmask);
+int user_sigtimedwait(struct thread *td, const sigset_t *uset, void *info,
+ const struct timespec *utimeout,
+ copyout_siginfo_t *copyout_siginfop);
+int user_sigwait(struct thread *td, const sigset_t *uset, int *usig);
+int user_sigwaitinfo(struct thread *td, const sigset_t *uset, void *info,
+ copyout_siginfo_t *copyout_siginfop);
int user_wait6(struct thread *td, enum idtype idtype, id_t id,
int *statusp, int options, struct __wrusage *wrusage,
siginfo_t *sip);