- ipc_port_t port;
- io_object_t obj = NULL;
- ipc_kobject_type_t type;
- 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)) {
- ip_lock(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;
+ ipc_port_t port;
+ io_object_t obj = NULL;
+ ipc_kobject_type_t type = IKOT_NONE;
+ ipc_port_t notify;
+
+ port = 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)
+ || (IKOT_IOKIT_IDENT == type)
+ || (IKOT_UEXT_OBJECT == type)) {
+ iokit_add_reference( obj, IKOT_IOKIT_OBJECT );
+ } 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 );
+ }