+/*
+ * Routine: ipc_port_bind_special_reply_port_locked
+ * Purpose:
+ * Bind the given port to current thread as a special reply port.
+ * Conditions:
+ * Port locked.
+ * Returns:
+ * None.
+ */
+
+static void
+ipc_port_bind_special_reply_port_locked(
+ ipc_port_t port)
+{
+ thread_t thread = current_thread();
+ assert(thread->ith_special_reply_port == NULL);
+ assert(port->ip_specialreply);
+ assert(port->ip_sync_link_state == PORT_SYNC_LINK_ANY);
+
+ ip_reference(port);
+ thread->ith_special_reply_port = port;
+ port->ip_messages.imq_srp_owner_thread = thread;
+
+ ipc_special_reply_port_bits_reset(port);
+}
+
+/*
+ * Routine: ipc_port_unbind_special_reply_port
+ * Purpose:
+ * Unbind the thread's special reply port.
+ * If the special port has threads waiting on turnstile,
+ * update it's inheritor.
+ * Condition:
+ * Nothing locked.
+ * Returns:
+ * None.
+ */
+static kern_return_t
+ipc_port_unbind_special_reply_port(
+ thread_t thread,
+ boolean_t unbind_active_port)
+{
+ ipc_port_t special_reply_port = thread->ith_special_reply_port;
+
+ ip_lock(special_reply_port);
+
+ /* Return error if port active and unbind_active_port set to FALSE */
+ if (unbind_active_port == FALSE && ip_active(special_reply_port)) {
+ ip_unlock(special_reply_port);
+ return KERN_FAILURE;
+ }
+
+ thread->ith_special_reply_port = NULL;
+ ipc_port_adjust_special_reply_port_locked(special_reply_port, NULL,
+ IPC_PORT_ADJUST_UNLINK_THREAD, FALSE);
+ /* port unlocked */
+
+ ip_release(special_reply_port);
+ return KERN_SUCCESS;
+}
+