git: 985faddcb6ed - main - rtprio*(2): add kern_ implementations

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Tue, 10 Nov 2026 12:33:04 UTC
The branch main has been updated by brooks:

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

commit 985faddcb6edf7263202bd982a9204c1db66ac91
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2026-11-10 11:49:21 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-10 11:49:21 +0000

    rtprio*(2): add kern_ implementations
    
    Effort:         CHERI upstreaming
    Sponsored by:   Innovate UK
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
---
 sys/kern/kern_resource.c | 41 +++++++++++++++++++++++++++--------------
 sys/sys/syscallsubr.h    |  5 +++++
 2 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c
index 044e95fa64a0..f7f07d4253d5 100644
--- a/sys/kern/kern_resource.c
+++ b/sys/kern/kern_resource.c
@@ -313,6 +313,13 @@ struct rtprio_thread_args {
 #endif
 int
 sys_rtprio_thread(struct thread *td, struct rtprio_thread_args *uap)
+{
+	return (kern_rtprio_thread(td, uap->function, uap->lwpid, uap->rtp));
+}
+
+int
+kern_rtprio_thread(struct thread *td, int function, lwpid_t lwpid,
+    struct rtprio *urtp)
 {
 	struct proc *p;
 	struct rtprio rtp;
@@ -320,29 +327,29 @@ sys_rtprio_thread(struct thread *td, struct rtprio_thread_args *uap)
 	int cierror, error;
 
 	/* Perform copyin before acquiring locks if needed. */
-	if (uap->function == RTP_SET)
-		cierror = copyin(uap->rtp, &rtp, sizeof(struct rtprio));
+	if (function == RTP_SET)
+		cierror = copyin(urtp, &rtp, sizeof(struct rtprio));
 	else
 		cierror = 0;
 
-	if (uap->lwpid == 0 || uap->lwpid == td->td_tid) {
+	if (lwpid == 0 || lwpid == td->td_tid) {
 		p = td->td_proc;
 		td1 = td;
 		PROC_LOCK(p);
 	} else {
-		td1 = tdfind(uap->lwpid, -1);
+		td1 = tdfind(lwpid, -1);
 		if (td1 == NULL)
 			return (ESRCH);
 		p = td1->td_proc;
 	}
 
-	switch (uap->function) {
+	switch (function) {
 	case RTP_LOOKUP:
 		if ((error = p_cansee(td, p)))
 			break;
 		pri_to_rtp(td1, &rtp);
 		PROC_UNLOCK(p);
-		return (copyout(&rtp, uap->rtp, sizeof(struct rtprio)));
+		return (copyout(&rtp, urtp, sizeof(struct rtprio)));
 	case RTP_SET:
 		if ((error = p_cansched(td, p)) || (error = cierror))
 			break;
@@ -394,6 +401,12 @@ struct rtprio_args {
 #endif
 int
 sys_rtprio(struct thread *td, struct rtprio_args *uap)
+{
+	return (kern_rtprio(td, uap->function, uap->pid, uap->rtp));
+}
+
+int
+kern_rtprio(struct thread *td, int function, pid_t pid, struct rtprio *urtp)
 {
 	struct proc *p;
 	struct thread *tdp;
@@ -401,21 +414,21 @@ sys_rtprio(struct thread *td, struct rtprio_args *uap)
 	int cierror, error;
 
 	/* Perform copyin before acquiring locks if needed. */
-	if (uap->function == RTP_SET)
-		cierror = copyin(uap->rtp, &rtp, sizeof(struct rtprio));
+	if (function == RTP_SET)
+		cierror = copyin(urtp, &rtp, sizeof(struct rtprio));
 	else
 		cierror = 0;
 
-	if (uap->pid == 0) {
+	if (pid == 0) {
 		p = td->td_proc;
 		PROC_LOCK(p);
 	} else {
-		p = pfind(uap->pid);
+		p = pfind(pid);
 		if (p == NULL)
 			return (ESRCH);
 	}
 
-	switch (uap->function) {
+	switch (function) {
 	case RTP_LOOKUP:
 		if ((error = p_cansee(td, p)))
 			break;
@@ -427,7 +440,7 @@ sys_rtprio(struct thread *td, struct rtprio_args *uap)
 		 * Note: specifying our own pid is not the same
 		 * as leaving it zero.
 		 */
-		if (uap->pid == 0) {
+		if (pid == 0) {
 			pri_to_rtp(td, &rtp);
 		} else {
 			struct rtprio rtp2;
@@ -445,7 +458,7 @@ sys_rtprio(struct thread *td, struct rtprio_args *uap)
 			}
 		}
 		PROC_UNLOCK(p);
-		return (copyout(&rtp, uap->rtp, sizeof(struct rtprio)));
+		return (copyout(&rtp, urtp, sizeof(struct rtprio)));
 	case RTP_SET:
 		if ((error = p_cansched(td, p)) || (error = cierror))
 			break;
@@ -469,7 +482,7 @@ sys_rtprio(struct thread *td, struct rtprio_args *uap)
 		 * do all the threads on that process. If we
 		 * specify our own pid we do the latter.
 		 */
-		if (uap->pid == 0) {
+		if (pid == 0) {
 			error = rtp_to_pri(&rtp, td);
 		} else {
 			FOREACH_THREAD_IN_PROC(p, td) {
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 41c1407b7ca4..95e563ccbca8 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -60,6 +60,7 @@ struct pollfd;
 struct ogetdirentries_args;
 struct rlimit;
 struct rusage;
+struct rtprio;
 struct sched_param;
 struct sembuf;
 union semun;
@@ -409,6 +410,10 @@ int	kern_recvit(struct thread *td, int s, struct msghdr *mp,
 	    enum uio_seg fromseg, struct mbuf **controlp);
 int	kern_renameat(struct thread *td, int fromfd, const char *from,
 	    int tofd, const char *to, enum uio_seg pathseg, u_int flags);
+int	kern_rtprio(struct thread *td, int function, pid_t pid,
+	    struct rtprio *urtp);
+int	kern_rtprio_thread(struct thread *td, int function, lwpid_t lwpid,
+	    struct rtprio *urtp);
 int	kern_sched_getparam(struct thread *td, struct thread *targettd,
 	    struct sched_param *param);
 int	kern_sched_getscheduler(struct thread *td, struct thread *targettd,