EXTERN io_object_t iokit_lookup_connect_ref(io_object_t connectRef, ipc_space_t space) { io_object_t obj = NULL; if (connectRef && MACH_PORT_VALID(CAST_MACH_PORT_TO_NAME(connectRef))) { ipc_port_t port; kern_return_t kr; kr = ipc_object_translate(space, CAST_MACH_PORT_TO_NAME(connectRef), MACH_PORT_RIGHT_SEND, (ipc_object_t *)&port); if (kr == KERN_SUCCESS) { assert(IP_VALID(port)); ip_reference(port); ip_unlock(port); iokit_lock_port(port); if (ip_active(port) && (ip_kotype(port) == IKOT_IOKIT_CONNECT)) { obj = (io_object_t) port->ip_kobject; iokit_add_reference(obj); } iokit_unlock_port(port); ip_release(port); } } return obj; }
static void iokit_no_senders( mach_no_senders_notification_t * notification ) { ipc_port_t port; io_object_t obj = NULL; ipc_kobject_type_t type = IKOT_NONE; ipc_port_t notify; port = (ipc_port_t) notification->not_header.msgh_remote_port; // convert a port to io_object_t. if( IP_VALID(port)) { iokit_lock_port(port); if( ip_active(port)) { obj = (io_object_t) port->ip_kobject; type = ip_kotype( port ); if( (IKOT_IOKIT_OBJECT == type) || (IKOT_IOKIT_CONNECT == type)) iokit_add_reference( obj ); else obj = NULL; } iokit_unlock_port(port); if( obj ) { mach_port_mscount_t mscount = notification->not_count; if( KERN_SUCCESS != iokit_client_died( obj, port, type, &mscount )) { /* Re-request no-senders notifications on the port (if still active) */ ip_lock(port); if (ip_active(port)) { notify = ipc_port_make_sonce_locked(port); ipc_port_nsrequest( port, mscount + 1, notify, ¬ify); /* port unlocked */ if ( notify != IP_NULL) ipc_port_release_sonce(notify); } else { ip_unlock(port); } } iokit_remove_reference( obj ); } } }
/* * Lookup a device by its port. * Doesn't consume the naked send right; produces a device reference. */ MIGEXTERN io_object_t iokit_lookup_object_port( ipc_port_t port) { io_object_t obj; if (!IP_VALID(port)) return (NULL); iokit_lock_port(port); if (ip_active(port) && (ip_kotype(port) == IKOT_IOKIT_OBJECT)) { obj = (io_object_t) port->ip_kobject; iokit_add_reference( obj ); } else obj = NULL; iokit_unlock_port(port); return( obj ); }