From 10b25803ce879ee6ac832b884bfdabc79769486a Mon Sep 17 00:00:00 2001 From: Flavio Cruz Date: Mon, 12 Feb 2024 01:26:34 -0500 Subject: Add thread_set_name RPC. Like task_set_name, we use the same size as the task name and will inherit the task name, whenever it exists. This will be used to implement pthread_setname_np. Message-ID: <20240212062634.1082207-2-flaviocruz@gmail.com> --- kern/thread.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'kern/thread.c') diff --git a/kern/thread.c b/kern/thread.c index 23ee8b09..2eab1ca4 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -551,6 +552,10 @@ kern_return_t thread_create( #endif /* MACH_PCSAMPLE */ new_thread->pc_sample.buffer = 0; + + /* Inherit the task name as the thread name. */ + memcpy (new_thread->name, parent_task->name, THREAD_NAME_SIZE); + /* * Add the thread to the task`s list of threads. * The new thread holds another reference to the task. @@ -2624,3 +2629,18 @@ thread_stats(void) printf("%d using rpc_reply.\n", rpcreply); } #endif /* MACH_DEBUG */ + +/* + * thread_set_name + * + * Set the name of thread THREAD to NAME. + */ +kern_return_t +thread_set_name( + thread_t thread, + const_kernel_debug_name_t name) +{ + strncpy(thread->name, name, sizeof thread->name - 1); + thread->name[sizeof thread->name - 1] = '\0'; + return KERN_SUCCESS; +} -- cgit v1.2.3