git: 1c17a0983ac3 - main - profil(2): add kern_ implemenation

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

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

commit 1c17a0983ac329f053af69640e8844f4f58b80ac
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

    profil(2): add kern_ implemenation
    
    Effort:         CHERI upstreaming
    Sponsored by:   Innovate, UK
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
---
 sys/kern/subr_prof.c  | 21 +++++++++++++++------
 sys/sys/syscallsubr.h |  2 ++
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/sys/kern/subr_prof.c b/sys/kern/subr_prof.c
index c95416de8cfe..6032b9c7e912 100644
--- a/sys/kern/subr_prof.c
+++ b/sys/kern/subr_prof.c
@@ -37,6 +37,7 @@
 #include <sys/mutex.h>
 #include <sys/proc.h>
 #include <sys/resourcevar.h>
+#include <sys/syscallsubr.h>
 #include <sys/sysctl.h>
 
 #include <machine/cpu.h>
@@ -58,15 +59,23 @@ struct profil_args {
 /* ARGSUSED */
 int
 sys_profil(struct thread *td, struct profil_args *uap)
+{
+	return (kern_profil(td, uap->samples, uap->size, uap->offset,
+	    uap->scale));
+}
+
+int
+kern_profil(struct thread *td, char *samples, size_t size, size_t offset,
+    u_int scale)
 {
 	struct uprof *upp;
 	struct proc *p;
 
-	if (uap->scale > (1 << 16))
+	if (scale > (1 << 16))
 		return (EINVAL);
 
 	p = td->td_proc;
-	if (uap->scale == 0) {
+	if (scale == 0) {
 		PROC_LOCK(p);
 		stopprofclock(p);
 		PROC_UNLOCK(p);
@@ -75,10 +84,10 @@ sys_profil(struct thread *td, struct profil_args *uap)
 	PROC_LOCK(p);
 	upp = &td->td_proc->p_stats->p_prof;
 	PROC_PROFLOCK(p);
-	upp->pr_off = uap->offset;
-	upp->pr_scale = uap->scale;
-	upp->pr_base = uap->samples;
-	upp->pr_size = uap->size;
+	upp->pr_off = offset;
+	upp->pr_scale = scale;
+	upp->pr_base = samples;
+	upp->pr_size = size;
 	PROC_PROFUNLOCK(p);
 	startprofclock(p);
 	PROC_UNLOCK(p);
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index ea9667f0cf3d..7dbba4b28b95 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -386,6 +386,8 @@ int	kern_pdwait(struct thread *td, int fd, int *status,
 	    int options, struct __wrusage *wrusage, siginfo_t *sip);
 int	kern_procctl(struct thread *td, enum idtype idtype, id_t id, int com,
 	    void *data);
+int	kern_profil(struct thread *td, char *samples, size_t size,
+	    size_t offset, u_int scale);
 int	kern_pread(struct thread *td, int fd, void *buf, size_t nbyte,
 	    off_t offset);
 int	kern_preadv(struct thread *td, int fd, struct uio *auio, off_t offset);