diff --git a/include/mach/gnumach.defs b/include/mach/gnumach.defs index 7331334..b26be96 100644 --- a/include/mach/gnumach.defs +++ b/include/mach/gnumach.defs @@ -37,3 +37,17 @@ type vm_cache_statistics_data_t = struct[11] of integer_t; routine vm_cache_statistics( target_task : vm_task_t; out vm_cache_stats : vm_cache_statistics_data_t); + +/* + * Set the name of a task. + */ +routine task_set_name( + task : task_t; + name : task_name_t); + +/* + * Get the name of a task. + */ +routine task_get_name( + task : task_t; + out name : task_name_t); diff --git a/include/mach/mach_types.defs b/include/mach/mach_types.defs index 607d5d9..c913cbb 100644 --- a/include/mach/mach_types.defs +++ b/include/mach/mach_types.defs @@ -230,6 +230,8 @@ type emulation_vector_t = ^array[] of vm_offset_t; type rpc_signature_info_t = array[*:1024] of int; +type task_name_t = (MACH_MSG_TYPE_STRING, 8*32); + #if KERNEL_SERVER simport ; /* for null conversion */ simport ; /* for task/thread conversion */ diff --git a/include/mach/mach_types.h b/include/mach/mach_types.h index 8768482..5bb3a7b 100644 --- a/include/mach/mach_types.h +++ b/include/mach/mach_types.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include diff --git a/include/mach/task_name.h b/include/mach/task_name.h new file mode 100644 index 0000000..d6306e2 --- /dev/null +++ b/include/mach/task_name.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2013 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + * Author: Barry deFreese. + */ + +#ifndef _TASK_NAME_H_ +#define _TASK_NAME_H_ + +#define TASK_NAME_SIZE 32 + +typedef char task_name_t[TASK_NAME_SIZE]; + +#endif /* _TASK_NAME_H_ */ diff --git a/kern/task.c b/kern/task.c index 114dd31..438037b 100644 --- a/kern/task.c +++ b/kern/task.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1212,3 +1213,33 @@ task_ras_control( #endif return ret; } + +kern_return_t +task_set_name ( + task_t task, + task_name_t name) +{ + + if (task == TASK_NULL) + return KERN_INVALID_ARGUMENT; + + strncpy(task->name, name, TASK_NAME_SIZE - 1); + task->name[TASK_NAME_SIZE - 1] = '\0'; + + return KERN_SUCCESS; +} + +kern_return_t +task_get_name ( + task_t task, + task_name_t name) +{ + + if (task == TASK_NULL) + return KERN_INVALID_ARGUMENT; + + strncpy(name, task->name, TASK_NAME_SIZE - 1); + name[TASK_NAME_SIZE - 1] = '\0'; + + return KERN_SUCCESS; +} diff --git a/kern/task.h b/kern/task.h index 9bfea57..842979a 100644 --- a/kern/task.h +++ b/kern/task.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -111,6 +112,8 @@ struct task { natural_t cow_faults; /* copy-on-write faults counter */ natural_t messages_sent; /* messages sent counter */ natural_t messages_received; /* messages received counter */ + + task_name_t name; /* Task name */ }; #define task_lock(task) simple_lock(&(task)->lock)