summaryrefslogtreecommitdiff
path: root/kern
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2013-11-24 11:17:54 +0100
committerRichard Braun <rbraun@sceen.net>2013-11-24 11:17:54 +0100
commit22495036a354e209a7f2085bdd2e1fc82895208b (patch)
tree3feed22ad96e1309f8188cfcef8547eb4ac734fa /kern
parent167804f7e91c8dfc8321299aacd82f831e01ef21 (diff)
New RPC for thread destruction
A new call, thread_terminate_release, is added to support self destruction in threading libraries. * include/mach/gnumach.defs (thread_terminate_release): New simpleroutine declaration. * kern/thread.c: Include vm/vm_user.h and ipc/mach_port.h. (thread_terminate_release): New function. * kern/thread.h (thread_terminate_release): New prototype.
Diffstat (limited to 'kern')
-rw-r--r--kern/thread.c24
-rw-r--r--kern/thread.h7
2 files changed, 31 insertions, 0 deletions
diff --git a/kern/thread.c b/kern/thread.c
index eb8a8bb..67fd41e 100644
--- a/kern/thread.c
+++ b/kern/thread.c
@@ -57,9 +57,11 @@
#include <kern/slab.h>
#include <kern/mach_clock.h>
#include <vm/vm_kern.h>
+#include <vm/vm_user.h>
#include <ipc/ipc_kmsg.h>
#include <ipc/ipc_port.h>
#include <ipc/mach_msg.h>
+#include <ipc/mach_port.h>
#include <machine/machspl.h> /* for splsched */
#include <machine/pcb.h>
#include <machine/thread.h> /* for MACHINE_STACK */
@@ -850,6 +852,28 @@ kern_return_t thread_terminate(
return KERN_SUCCESS;
}
+kern_return_t thread_terminate_release(
+ thread_t thread,
+ task_t task,
+ mach_port_t thread_name,
+ mach_port_t reply_port,
+ vm_offset_t address,
+ vm_size_t size)
+{
+ if (task == NULL)
+ return KERN_INVALID_ARGUMENT;
+
+ mach_port_deallocate(task->itk_space, thread_name);
+
+ if (reply_port != MACH_PORT_NULL)
+ mach_port_destroy(task->itk_space, reply_port);
+
+ if ((address != 0) || (size != 0))
+ vm_deallocate(task->map, address, size);
+
+ return thread_terminate(thread);
+}
+
/*
* thread_force_terminate:
*
diff --git a/kern/thread.h b/kern/thread.h
index 3959dfc..beb2dbc 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -259,6 +259,13 @@ extern kern_return_t thread_create(
thread_t *child_thread);
extern kern_return_t thread_terminate(
thread_t thread);
+extern kern_return_t thread_terminate_release(
+ thread_t thread,
+ task_t task,
+ mach_port_t thread_name,
+ mach_port_t reply_port,
+ vm_offset_t address,
+ vm_size_t size);
extern kern_return_t thread_suspend(
thread_t thread);
extern kern_return_t thread_resume(