git: a81038c0dc02 - main - thr_set_name(2): add kern_ implementation

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

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

commit a81038c0dc02a7721e2a636013ae3e343966511e
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2025-11-24 15:51:26 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-10 15:54:20 +0000

    thr_set_name(2): add kern_ implementation
    
    Effort:         CHERI upstreaming
    Sponsored by:   Innovate UK
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/2284
---
 sys/kern/kern_thr.c   | 14 ++++++++++----
 sys/sys/syscallsubr.h |  1 +
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/sys/kern/kern_thr.c b/sys/kern/kern_thr.c
index 4a439eee0210..2488076940c7 100644
--- a/sys/kern/kern_thr.c
+++ b/sys/kern/kern_thr.c
@@ -605,6 +605,12 @@ sys_thr_wake(struct thread *td, struct thr_wake_args *uap)
 
 int
 sys_thr_set_name(struct thread *td, struct thr_set_name_args *uap)
+{
+	return (kern_thr_set_name(td, uap->id, uap->name));
+}
+
+int
+kern_thr_set_name(struct thread *td, lwpid_t id, const char *uname)
 {
 	struct proc *p;
 	char name[MAXCOMLEN + 1];
@@ -613,17 +619,17 @@ sys_thr_set_name(struct thread *td, struct thr_set_name_args *uap)
 
 	error = 0;
 	name[0] = '\0';
-	if (uap->name != NULL) {
-		error = copyinstr(uap->name, name, sizeof(name), NULL);
+	if (uname != NULL) {
+		error = copyinstr(uname, name, sizeof(name), NULL);
 		if (error == ENAMETOOLONG) {
-			error = copyin(uap->name, name, sizeof(name) - 1);
+			error = copyin(uname, name, sizeof(name) - 1);
 			name[sizeof(name) - 1] = '\0';
 		}
 		if (error)
 			return (error);
 	}
 	p = td->td_proc;
-	ttd = tdfind((lwpid_t)uap->id, p->p_pid);
+	ttd = tdfind(id, p->p_pid);
 	if (ttd == NULL)
 		return (ESRCH);
 	strcpy(ttd->td_name, name);
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 7267b256a2cd..3b4a0b1fa190 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -501,6 +501,7 @@ int	kern_semop(struct thread *td, int usemid, struct sembuf *usops,
 int	kern_thr_alloc(struct proc *, int pages, struct thread **);
 int	kern_thr_exit(struct thread *td);
 int	kern_thr_new(struct thread *td, struct thr_param *param);
+int	kern_thr_set_name(struct thread *td, lwpid_t id, const char *uname);
 int	kern_thr_suspend(struct thread *td, struct timespec *tsp);
 int	kern_timerfd_create(struct thread *td, int clockid, int flags);
 int	kern_timerfd_gettime(struct thread *td, int fd,