--- include/mach/gnumach.defs | 8 ++++++++ kern/thread.c | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+)
diff --git a/include/mach/gnumach.defs b/include/mach/gnumach.defs index 7ecf74d..f13e866 100644 --- a/include/mach/gnumach.defs +++ b/include/mach/gnumach.defs @@ -215,3 +215,11 @@ routine vm_pages_phys( simpleroutine thread_set_name( thread : thread_t; name : kernel_debug_name_t); + +/* + * Get the name of thread THREAD as set by thread_set_name. Will return + * the name of the task if no THREAD name is set. + */ +routine thread_get_name( + thread : thread_t; + out name : kernel_debug_name_t); diff --git a/kern/thread.c b/kern/thread.c index 68cc667..a656c07 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -2647,3 +2647,24 @@ thread_set_name( thread->name[sizeof thread->name - 1] = '\0'; return KERN_SUCCESS; } + +/* + * thread_get_name + * + * Return the name of the thread THREAD. + * Will use the name of the thread as set by thread_set_name. + * If thread_set_name was not used, this will return the name of the task + * copied when the thread was created. + */ +kern_return_t +thread_get_name( + thread_t thread, + kernel_debug_name_t name) +{ + if (thread == THREAD_NULL) + return KERN_INVALID_ARGUMENT; + + strncpy(name, thread->name, sizeof thread->name); + + return KERN_SUCCESS; +} -- 2.45.2