git: e5100cd50a05 - main - sched_*(2): add user_ implementations

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Wed, 11 Nov 2026 09:58:13 UTC
The branch main has been updated by brooks:

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

commit e5100cd50a051dce571444ab4b8a821580f3dda4
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-11-11 09:40:40 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-11 09:40:40 +0000

    sched_*(2): add user_ implementations
    
    Effort:         CHERI upstreaming
    Sponsored by:   Innovate UK
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
---
 sys/kern/p1003_1b.c   | 52 ++++++++++++++++++++++++++++++++++++++-------------
 sys/sys/syscallsubr.h |  8 ++++++++
 2 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/sys/kern/p1003_1b.c b/sys/kern/p1003_1b.c
index 6259f7092487..96730f22596c 100644
--- a/sys/kern/p1003_1b.c
+++ b/sys/kern/p1003_1b.c
@@ -108,22 +108,29 @@ sched_attach(void)
 
 int
 sys_sched_setparam(struct thread *td, struct sched_setparam_args *uap)
+{
+	return (user_sched_setparam(td, uap->pid, uap->param));
+}
+
+int
+user_sched_setparam(struct thread *td, pid_t pid,
+    const struct sched_param *param)
 {
 	struct thread *targettd;
 	struct proc *targetp;
 	int e;
 	struct sched_param sched_param;
 
-	e = copyin(uap->param, &sched_param, sizeof(sched_param));
+	e = copyin(param, &sched_param, sizeof(sched_param));
 	if (e)
 		return (e);
 
-	if (uap->pid == 0) {
+	if (pid == 0) {
 		targetp = td->td_proc;
 		targettd = td;
 		PROC_LOCK(targetp);
 	} else {
-		targetp = pfind(uap->pid);
+		targetp = pfind(pid);
 		if (targetp == NULL)
 			return (ESRCH);
 		targettd = FIRST_THREAD_IN_PROC(targetp);
@@ -153,18 +160,24 @@ kern_sched_setparam(struct thread *td, struct thread *targettd,
 
 int
 sys_sched_getparam(struct thread *td, struct sched_getparam_args *uap)
+{
+	return (user_sched_getparam(td, uap->pid, uap->param));
+}
+
+int
+user_sched_getparam(struct thread *td, pid_t pid, struct sched_param *param)
 {
 	int e;
 	struct sched_param sched_param;
 	struct thread *targettd;
 	struct proc *targetp;
 
-	if (uap->pid == 0) {
+	if (pid == 0) {
 		targetp = td->td_proc;
 		targettd = td;
 		PROC_LOCK(targetp);
 	} else {
-		targetp = pfind(uap->pid);
+		targetp = pfind(pid);
 		if (targetp == NULL) {
 			return (ESRCH);
 		}
@@ -174,7 +187,7 @@ sys_sched_getparam(struct thread *td, struct sched_getparam_args *uap)
 	e = kern_sched_getparam(td, targettd, &sched_param);
 	PROC_UNLOCK(targetp);
 	if (e == 0)
-		e = copyout(&sched_param, uap->param, sizeof(sched_param));
+		e = copyout(&sched_param, param, sizeof(sched_param));
 	return (e);
 }
 
@@ -196,29 +209,35 @@ kern_sched_getparam(struct thread *td, struct thread *targettd,
 
 int
 sys_sched_setscheduler(struct thread *td, struct sched_setscheduler_args *uap)
+{
+	return (user_sched_setscheduler(td, uap->pid, uap->policy, uap->param));
+}
+
+int
+user_sched_setscheduler(struct thread *td, pid_t pid, int policy,
+    const struct sched_param *param)
 {
 	int e;
 	struct sched_param sched_param;
 	struct thread *targettd;
 	struct proc *targetp;
 
-	e = copyin(uap->param, &sched_param, sizeof(sched_param));
+	e = copyin(param, &sched_param, sizeof(sched_param));
 	if (e)
 		return (e);
 
-	if (uap->pid == 0) {
+	if (pid == 0) {
 		targetp = td->td_proc;
 		targettd = td;
 		PROC_LOCK(targetp);
 	} else {
-		targetp = pfind(uap->pid);
+		targetp = pfind(pid);
 		if (targetp == NULL)
 			return (ESRCH);
 		targettd = FIRST_THREAD_IN_PROC(targetp);
 	}
 
-	e = kern_sched_setscheduler(td, targettd, uap->policy,
-	    &sched_param);
+	e = kern_sched_setscheduler(td, targettd, policy, &sched_param);
 	PROC_UNLOCK(targetp);
 	return (e);
 }
@@ -320,13 +339,20 @@ sys_sched_get_priority_min(struct thread *td,
 int
 sys_sched_rr_get_interval(struct thread *td,
     struct sched_rr_get_interval_args *uap)
+{
+	return (user_sched_rr_get_interval(td, uap->pid, uap->interval));
+}
+
+int
+user_sched_rr_get_interval(struct thread *td, pid_t pid,
+    struct timespec *interval)
 {
 	struct timespec timespec;
 	int error;
 
-	error = kern_sched_rr_get_interval(td, uap->pid, &timespec);
+	error = kern_sched_rr_get_interval(td, pid, &timespec);
 	if (error == 0)
-		error = copyout(&timespec, uap->interval, sizeof(timespec));
+		error = copyout(&timespec, interval, sizeof(timespec));
 	return (error);
 }
 
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 4b9000c6d39a..ea9667f0cf3d 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -549,6 +549,14 @@ int	user_jail_get(struct thread *td, struct iovec *iovp,
 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_sched_getparam(struct thread *td, pid_t pid,
+	    struct sched_param *param);
+int	user_sched_rr_get_interval(struct thread *td, pid_t pid,
+	    struct timespec *interval);
+int	user_sched_setparam(struct thread *td, pid_t pid,
+	    const struct sched_param *param);
+int	user_sched_setscheduler(struct thread *td, pid_t pid, int policy,
+	    const struct sched_param *param);
 int	user_setgroups(struct thread *td, int gidsetsize, const gid_t *gidset);
 int	user_settimeofday(struct thread *td, const struct timeval *tv,
 	    const struct timezone *tz);