git: 23abe1880071 - main - __sysctl(2): add kern_ implementation

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

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

commit 23abe1880071fed7f422af9b556db87afe426070
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2025-11-24 15:40:30 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-10 15:54:20 +0000

    __sysctl(2): add kern_ implementation
    
    The flags argument will be used by compat impelementations.
    
    Effort:         CHERI upstreaming
    Sponsored by:   Innovate UK
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
---
 sys/kern/kern_sysctl.c | 24 ++++++++++++++++--------
 sys/sys/syscallsubr.h  |  3 +++
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 8c63f8073cb4..50632cc16988 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -58,6 +58,7 @@
 #include <sys/rmlock.h>
 #include <sys/sbuf.h>
 #include <sys/sx.h>
+#include <sys/syscallsubr.h>
 #include <sys/sysproto.h>
 #include <sys/uio.h>
 #ifdef KTRACE
@@ -2443,24 +2444,31 @@ struct __sysctl_args {
 #endif
 int
 sys___sysctl(struct thread *td, struct __sysctl_args *uap)
+{
+	return (kern_sysctl(td, uap->name, uap->namelen, uap->old,
+	    uap->oldlenp, uap->new, uap->newlen, 0));
+}
+
+int
+kern_sysctl(struct thread *td, const int *uname, u_int namelen, void *old,
+    size_t *oldlenp, const void *new, size_t newlen, int flags)
 {
 	int error, i, name[CTL_MAXNAME];
 	size_t j;
 
-	if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
+	if (namelen > CTL_MAXNAME || namelen < 2)
 		return (EINVAL);
 
- 	error = copyin(uap->name, &name, uap->namelen * sizeof(int));
- 	if (error)
+	error = copyin(uname, &name, namelen * sizeof(int));
+	if (error)
 		return (error);
 
-	error = userland_sysctl(td, name, uap->namelen,
-		uap->old, uap->oldlenp, 0,
-		uap->new, uap->newlen, &j, 0);
+	error = userland_sysctl(td, name, namelen, old, oldlenp, 0,
+	    new, newlen, &j, flags);
 	if (error && error != ENOMEM)
 		return (error);
-	if (uap->oldlenp) {
-		i = copyout(&j, uap->oldlenp, sizeof(j));
+	if (oldlenp) {
+		i = copyout(&j, oldlenp, sizeof(j));
 		if (i)
 			return (i);
 	}
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 199c2039c7b3..7267b256a2cd 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -485,6 +485,9 @@ int	kern_statfs(struct thread *td, const char *path, enum uio_seg pathseg,
 int	kern_symlinkat(struct thread *td, const char *path1, int fd,
 	    const char *path2, enum uio_seg segflg);
 int	kern_sync(struct thread *td);
+int	kern_sysctl(struct thread *td, const int *uname, u_int namelen,
+	    void *old, size_t *oldlenp, const void *new, size_t newlen,
+	    int flags);
 int	kern_ktimer_create(struct thread *td, clockid_t clock_id,
 	    struct sigevent *evp, int *timerid, int preset_id);
 int	kern_ktimer_delete(struct thread *, int);