Hi folks,

I am trying to get a test environment going to test this but in the meantime if 
any of you care to
review, here is a patch to add task_set_name() and task_get_name() RPCs to 
gnumach.

Thanks!

Barry

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 <kern/ipc_kobject.h>;  /* for null conversion */
 simport <kern/ipc_tt.h>;       /* 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 <mach/port.h>
 #include <mach/processor_info.h>
 #include <mach/task_info.h>
+#include <mach/task_name.h>
 #include <mach/task_special_ports.h>
 #include <mach/thread_info.h>
 #include <mach/thread_special_ports.h>
diff --git a/include/mach/task_name.h b/include/mach/task_name.h
new file mode 100644
index 0000000..296bd9e
--- /dev/null
+++ b/include/mach/task_name.h
@@ -0,0 +1,26 @@
+/*
+ * 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_
+
+typedef char task_name_t[32];
+
+#endif /* _TASK_NAME_H_ */
diff --git a/kern/task.c b/kern/task.c
index 114dd31..d8690c6 100644
--- a/kern/task.c
+++ b/kern/task.c
@@ -37,6 +37,7 @@
 #include <mach/vm_param.h>
 #include <mach/task_info.h>
 #include <mach/task_special_ports.h>
+#include <mach/task_name.h>
 #include <ipc/ipc_space.h>
 #include <ipc/ipc_types.h>
 #include <kern/debug.h>
@@ -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, sizeof(task->name) -1);
+       task->name[sizeof(task->name) -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, sizeof(task->name) - 1);
+       name[sizeof(name) -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 <mach/time_value.h>
 #include <mach/mach_param.h>
 #include <mach/task_info.h>
+#include <mach/task_name.h>
 #include <kern/kern_types.h>
 #include <kern/lock.h>
 #include <kern/queue.h>
@@ -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)

Reply via email to