+/*
+ * Routine: convert_task_suspend_token_to_port
+ * Purpose:
+ * Convert from a task suspension token to a port.
+ * Consumes a task suspension token ref; produces a naked send-once right
+ * which may be invalid.
+ * Conditions:
+ * Nothing locked.
+ */
+ipc_port_t
+convert_task_suspension_token_to_port(
+ task_suspension_token_t task)
+{
+ ipc_port_t port;
+
+ task_lock(task);
+ if (task->active) {
+ if (task->itk_resume == IP_NULL) {
+ task->itk_resume = ipc_port_alloc_kernel();
+ if (!IP_VALID(task->itk_resume)) {
+ panic("failed to create resume port");
+ }
+
+ ipc_kobject_set(task->itk_resume, (ipc_kobject_t) task, IKOT_TASK_RESUME);
+ }
+
+ /*
+ * Create a send-once right for each instance of a direct user-called
+ * task_suspend2 call. Each time one of these send-once rights is abandoned,
+ * the notification handler will resume the target task.
+ */
+ port = ipc_port_make_sonce(task->itk_resume);
+ assert(IP_VALID(port));
+ } else {
+ port = IP_NULL;
+ }
+
+ task_unlock(task);
+ task_suspension_token_deallocate(task);
+
+ return port;
+}
+
+