• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.5.8/xnu-1228.15.4/osfmk/ipc/

Lines Matching refs:port

77 #include <mach/port.h>
111 ipc_port_t port);
145 * The port is locked and active.
153 ipc_port_t port,
161 assert(ip_active(port));
165 table = port->ip_dnrequests;
187 * Grow a port's table of dead-name requests.
189 * The port must be locked and active.
191 * Upon return the port is unlocked.
195 * KERN_SUCCESS The port died.
202 ipc_port_t port,
208 assert(ip_active(port));
210 otable = port->ip_dnrequests;
219 ip_unlock(port);
226 ip_unlock(port);
231 ip_reference(port);
232 ip_unlock(port);
236 ipc_port_release(port);
240 ip_lock(port);
241 ip_release(port);
244 * Check that port is still active and that nobody else
246 * just checking port->ip_dnrequests == otable isn't
250 if (ip_active(port) &&
251 (port->ip_dnrequests == otable) &&
288 port->ip_dnrequests = ntable;
289 ip_unlock(port);
295 ip_check_unlock(port);
307 * The port must locked and active.
312 ipc_port_t port,
319 assert(ip_active(port));
323 table = port->ip_dnrequests;
342 * Make a port-deleted request, returning the
346 * The port is locked and active. It is unlocked.
353 ipc_port_t port,
359 assert(ip_active(port));
361 previous = port->ip_pdrequest;
362 port->ip_pdrequest = notify;
363 ip_unlock(port);
375 * The port is locked and active. It is unlocked.
382 ipc_port_t port,
390 assert(ip_active(port));
392 previous = port->ip_nsrequest;
393 mscount = port->ip_mscount;
395 if ((port->ip_srights == 0) && (sync <= mscount) &&
397 port->ip_nsrequest = IP_NULL;
398 ip_unlock(port);
401 port->ip_nsrequest = notify;
402 ip_unlock(port);
414 * The port is locked and active.
419 ipc_port_t port)
423 assert(ip_active(port));
428 if (port->ip_pset_count != 0) {
429 ipc_pset_remove_from_all(port);
430 assert(port->ip_pset_count == 0);
434 * Send anyone waiting on the port's queue directly away.
438 imq_lock(&port->ip_messages);
439 ipc_mqueue_changed(&port->ip_messages);
440 ipc_port_set_mscount(port, 0);
441 port->ip_messages.imq_seqno = 0;
442 imq_unlock(&port->ip_messages);
449 * Initializes a newly-allocated port.
455 ipc_port_t port,
459 /* port->ip_kobject doesn't have to be initialized */
461 port->ip_receiver = space;
462 port->ip_receiver_name = name;
464 port->ip_mscount = 0;
465 port->ip_srights = 0;
466 port->ip_sorights = 0;
468 port->ip_nsrequest = IP_NULL;
469 port->ip_pdrequest = IP_NULL;
470 port->ip_dnrequests = IPR_NULL;
472 port->ip_pset_count = 0;
473 port->ip_premsg = IKM_NULL;
476 ipc_port_init_debug(port);
479 ipc_mqueue_init(&port->ip_messages, FALSE /* set */);
485 * Allocate a port.
487 * Nothing locked. If successful, the port is returned
490 * KERN_SUCCESS The port is allocated.
502 ipc_port_t port;
508 &name, (ipc_object_t *) &port);
512 /* port is locked */
514 ipc_port_init(port, space, name);
520 &port->ip_label);
525 *portp = port;
533 * Allocate a port, with a specific name.
535 * Nothing locked. If successful, the port is returned
538 * KERN_SUCCESS The port is allocated.
550 ipc_port_t port;
555 name, (ipc_object_t *) &port);
559 /* port is locked */
561 ipc_port_init(port, space, name);
567 &port->ip_label);
571 *portp = port;
579 * dnrequests was taken from port while the port
580 * was locked but the port now has port->ip_dnrequests set to IPR_NULL.
584 __unused ipc_port_t port,
611 * Destroys a port. Cleans up queued messages.
613 * If the port has a backup, it doesn't get destroyed,
614 * but is sent in a port-destroyed notification to the backup.
616 * The port is locked and alive; nothing else locked.
618 * Afterwards, the port is unlocked and dead.
623 ipc_port_t port)
630 assert(ip_active(port));
631 /* port->ip_receiver_name is garbage */
632 /* port->ip_receiver/port->ip_destination is garbage */
633 assert(port->ip_pset_count == 0);
634 assert(port->ip_mscount == 0);
636 /* first check for a backup port */
638 pdrequest = port->ip_pdrequest;
641 port->ip_pdrequest = IP_NULL;
643 /* make port be in limbo */
644 port->ip_receiver_name = MACH_PORT_NULL;
645 port->ip_destination = IP_NULL;
646 ip_unlock(port);
648 /* consumes our refs for port and pdrequest */
649 ipc_notify_port_destroyed(pdrequest, port);
653 /* once port is dead, we don't need to keep it locked */
655 port->ip_object.io_bits &= ~IO_BITS_ACTIVE;
656 port->ip_timestamp = ipc_port_timestamp();
659 dnrequests = port->ip_dnrequests;
660 port->ip_dnrequests = IPR_NULL;
663 * If the port has a preallocated message buffer and that buffer
668 if (IP_PREALLOC(port)) {
669 kmsg = port->ip_premsg;
671 IP_CLEAR_PREALLOC(port, kmsg);
675 ip_unlock(port);
679 nsrequest = port->ip_nsrequest;
684 mqueue = &port->ip_messages;
689 ipc_port_dnnotify(port, dnrequests);
692 ipc_kobject_destroy(port);
694 ipc_port_release(port); /* consume caller's ref */
700 * Check if queueing "port" in a message for "dest"
703 * If no circularity (FALSE returned), then "port"
706 * That is, we want to set port->ip_destination == dest,
708 * port->ip_destination->ip_destination->... == port
710 * No ports locked. References held for "port" and "dest".
715 ipc_port_t port,
720 assert(port != IP_NULL);
723 if (port == dest)
732 ip_lock(port);
743 ip_unlock(port);
748 * Search for the end of the chain (a port not in transit),
765 if (port == base) {
770 /* port (== base) is in limbo */
772 assert(ip_active(port));
773 assert(port->ip_receiver_name == MACH_PORT_NULL);
774 assert(port->ip_destination == IP_NULL);
793 * The guarantee: lock port while the entire chain is locked.
794 * Once port is locked, we can take a reference to dest,
795 * add port to the chain, and unlock everything.
798 ip_lock(port);
803 /* port is in limbo */
805 assert(ip_active(port));
806 assert(port->ip_receiver_name == MACH_PORT_NULL);
807 assert(port->ip_destination == IP_NULL);
810 port->ip_destination = dest;
814 while (port != base) {
817 /* port is in transit */
819 assert(ip_active(port));
820 assert(port->ip_receiver_name == MACH_PORT_NULL);
821 assert(port->ip_destination != IP_NULL);
823 next = port->ip_destination;
824 ip_unlock(port);
825 port = next;
841 * Make a send-once notify port from a receive right.
855 ipc_port_t port;
866 port = (ipc_port_t) entry->ie_object;
867 assert(port != IP_NULL);
869 ip_lock(port);
870 assert(ip_active(port));
871 assert(port->ip_receiver_name == name);
872 assert(port->ip_receiver == space);
874 ip_reference(port);
875 port->ip_sorights++;
876 ip_unlock(port);
878 return port;
887 * port locked and active.
891 ipc_port_t port)
893 assert(ip_active(port));
894 port->ip_mscount++;
895 port->ip_srights++;
896 ip_reference(port);
897 ip_unlock(port);
898 return port;
909 ipc_port_t port)
912 if (!IP_VALID(port))
913 return port;
915 ip_lock(port);
916 if (ip_active(port)) {
917 port->ip_mscount++;
918 port->ip_srights++;
919 ip_reference(port);
920 ip_unlock(port);
921 return port;
923 ip_unlock(port);
933 * dead port -> IP_DEAD
934 * live port -> port + ref
941 ipc_port_t port)
945 if (!IP_VALID(port))
946 return port;
948 ip_lock(port);
949 if (ip_active(port)) {
950 assert(port->ip_srights > 0);
952 ip_reference(port);
953 port->ip_srights++;
954 sright = port;
957 ip_unlock(port);
1001 * Consumes a ref for the port.
1008 ipc_port_t port)
1013 assert(IP_VALID(port));
1015 ip_lock(port);
1016 ip_release(port);
1018 if (!ip_active(port)) {
1019 ip_check_unlock(port);
1023 assert(port->ip_srights > 0);
1025 if (--port->ip_srights == 0 &&
1026 port->ip_nsrequest != IP_NULL) {
1027 nsrequest = port->ip_nsrequest;
1028 port->ip_nsrequest = IP_NULL;
1029 mscount = port->ip_mscount;
1030 ip_unlock(port);
1033 ip_unlock(port);
1041 * The port is not locked but it is active.
1046 ipc_port_t port)
1048 assert(IP_VALID(port));
1050 ip_lock(port);
1051 assert(ip_active(port));
1052 port->ip_sorights++;
1053 ip_reference(port);
1054 ip_unlock(port);
1056 return port;
1063 * Consumes a ref for the port.
1075 ipc_port_t port)
1077 assert(IP_VALID(port));
1079 ip_lock(port);
1081 assert(port->ip_sorights > 0);
1083 port->ip_sorights--;
1085 ip_release(port);
1087 if (!ip_active(port)) {
1088 ip_check_unlock(port);
1092 ip_unlock(port);
1099 * Consumes a ref for the port; destroys the port.
1106 ipc_port_t port)
1110 assert(IP_VALID(port));
1112 ip_lock(port);
1113 assert(ip_active(port));
1114 assert(port->ip_receiver_name == MACH_PORT_NULL);
1115 dest = port->ip_destination;
1117 ipc_port_destroy(port); /* consumes ref, unlocks */
1126 * Allocate a port in a special space.
1127 * The new port is returned with one ref.
1137 ipc_port_t port;
1139 port = (ipc_port_t) io_alloc(IOT_PORT);
1140 if (port == IP_NULL)
1143 bzero((char *)port, sizeof(*port));
1144 io_lock_init(&port->ip_object);
1145 port->ip_references = 1;
1146 port->ip_object.io_bits = io_makebits(TRUE, IOT_PORT, 0);
1148 ipc_port_init(port, space, 1);
1158 mac_port_label_init(&port->ip_label);
1159 mac_port_label_associate_kernel(&port->ip_label, space == ipc_space_reply);
1162 return port;
1168 * Deallocate a port in a special space.
1169 * Consumes one ref for the port.
1176 ipc_port_t port,
1179 ip_lock(port);
1180 assert(ip_active(port));
1181 // assert(port->ip_receiver_name != MACH_PORT_NULL);
1182 assert(port->ip_receiver == space);
1189 port->ip_receiver_name = MACH_PORT_NULL;
1190 port->ip_receiver = IS_NULL;
1193 ipc_port_set_mscount(port, 0);
1194 port->ip_messages.imq_seqno = 0;
1196 ipc_port_destroy(port);
1216 ipc_port_t port);
1227 * port debugging.
1238 * Initialize all of the debugging state in a port.
1239 * Insert the port into a global list of all allocated ports.
1243 ipc_port_t port)
1247 port->ip_thread = current_thread();
1248 port->ip_timetrack = port_timestamp++;
1250 port->ip_callstack[i] = 0;
1252 port->ip_spares[i] = 0;
1259 machine_callstack(&port->ip_callstack[0], IP_CALLSTACK_MAX);
1266 queue_enter(&port_alloc_queue, port, ipc_port_t, ip_port_links);
1273 * Remove a port from the queue of allocated ports.
1275 * deallocating the actual memory occupied by the port.
1280 __unused ipc_port_t port)
1286 ipc_port_t port)
1291 queue_remove(&port_alloc_queue, port, ipc_port_t, ip_port_links);
1308 ipc_port_t port);
1313 * Pretty-print a port for kdb.
1319 ipc_port_t port,
1335 printf("port 0x%x\n", port);
1339 ipc_object_print(&port->ip_object);
1345 if (!ip_active(port)) {
1346 iprintf("timestamp=0x%x", port->ip_timestamp);
1347 } else if (port->ip_receiver_name == MACH_PORT_NULL) {
1348 iprintf("destination=0x%x (", port->ip_destination);
1349 if (port->ip_destination != MACH_PORT_NULL &&
1350 (task = db_task_from_space(port->ip_destination->
1357 iprintf("receiver=0x%x (", port->ip_receiver);
1358 if (port->ip_receiver == ipc_space_kernel)
1360 else if (port->ip_receiver == ipc_space_reply)
1362 else if (port->ip_receiver == default_pager_space)
1364 else if ((task = db_task_from_space(port->ip_receiver, &task_id)) != (db_addr_t)0)
1370 printf(", receiver_name=0x%x\n", port->ip_receiver_name);
1372 iprintf("mscount=%d", port->ip_mscount);
1373 printf(", srights=%d", port->ip_srights);
1374 printf(", sorights=%d\n", port->ip_sorights);
1376 iprintf("nsrequest=0x%x", port->ip_nsrequest);
1377 printf(", pdrequest=0x%x", port->ip_pdrequest);
1378 printf(", dnrequests=0x%x\n", port->ip_dnrequests);
1380 iprintf("pset_count=0x%x", port->ip_pset_count);
1381 printf(", seqno=%d", port->ip_messages.imq_seqno);
1382 printf(", msgcount=%d", port->ip_messages.imq_msgcount);
1383 printf(", qlimit=%d\n", port->ip_messages.imq_qlimit);
1385 iprintf("kmsgs=0x%x", port->ip_messages.imq_messages.ikmq_base);
1386 printf(", rcvrs queue=0x%x", port->ip_messages.imq_wait_queue);
1387 printf(", kobj=0x%x\n", port->ip_kobject);
1389 iprintf("premsg=0x%x", port->ip_premsg);
1394 port->ip_thread, port->ip_timetrack);
1398 if (port->ip_spares[i] != 0) {
1405 port->ip_spares[i]);
1418 nmsgs = db_port_queue_print(port);
1459 ipc_port_t port;
1463 for (port = (ipc_port_t)first_element(ipc_object_zones[IOT_PORT]);
1464 port;
1465 port = (ipc_port_t)next_element(ipc_object_zones[IOT_PORT],
1466 port))
1467 if (ip_kotype(port) == type &&
1468 (!dead || !ip_active(port))) {
1470 printf("0x%x\t", port);
1472 printf("0x%x\n", port);
1481 ipc_port_t port;
1503 for (port = (ipc_port_t)first_element(ipc_object_zones[IOT_PORT]);
1504 port;
1505 port = (ipc_port_t)next_element(ipc_object_zones[IOT_PORT],
1506 port)) {
1508 if (ip_kotype(port) >= IKOT_MAX_TYPE) {
1510 if (!io_active(&port->ip_object))
1513 port_types[ip_kotype(port)].total_count++;
1514 if (!io_active(&port->ip_object))
1515 port_types[ip_kotype(port)].dead_count++;
1518 if (!port->ip_receiver)
1520 else if (port->ip_receiver == ipc_space_kernel)
1522 else if (port->ip_receiver == ipc_space_reply)
1524 else if (port->ip_receiver == default_pager_space)
1641 * Process all of the messages on a port - prints out the
1647 ipc_port_t port)
1651 if (ipc_kmsg_queue_empty(&port->ip_messages.imq_messages))
1653 kmsg = ipc_kmsg_queue_first(&port->ip_messages.imq_messages);
1666 * Translate port's cache of call stack pointers
1671 ipc_port_t port)
1676 iprintf("[%d] 0x%x\t", i, port->ip_callstack[i]);
1677 if (port->ip_callstack[i] != 0 &&
1678 DB_VALID_KERN_ADDR(port->ip_callstack[i]))
1679 db_printsym(port->ip_callstack[i], DB_STGY_PROC);
1824 * display print out each port encountered
1836 ipc_port_t port;
1843 iprintf("Allocated port count is %d\n", port_count);
1850 port_track_init(&port_callers, "port callers");
1851 port_track_init(&port_threads, "port threads");
1852 port_track_init(&port_spaces, "port spaces");
1858 queue_iterate(&port_alloc_queue, port, ipc_port_t, ip_port_links) {
1861 port_type = " IPC port";
1862 if (ip_active(port))
1865 refs = port->ip_references;
1870 if (ip_active(port))
1877 port_type, port);
1878 if (ip_active(port))
1883 port_item_add(&port_threads, (unsigned long) port->ip_thread);
1885 if (port->ip_callstack[i] != 0 &&
1886 DB_VALID_KERN_ADDR(port->ip_callstack[i]))
1888 port->ip_callstack[i]);
1890 if (!ip_active(port)) {
1893 port_type, port, refs);
1897 if (port->ip_receiver_name == MACH_PORT_NULL) {
1899 port, refs);
1903 if (port->ip_receiver == ipc_space_kernel ||
1904 port->ip_receiver == ipc_space_reply ||
1905 ipc_entry_lookup(port->ip_receiver,
1906 port->ip_receiver_name)
1909 (unsigned long)port->ip_receiver);
1912 port_type, port,
1913 port->ip_timetrack, refs);
1918 port_type, port, port->ip_receiver,
1919 port->ip_receiver_name, refs);
1922 iprintf("Active port type summary:\n");