Lines Matching refs:thread

68  *	Task and thread related IPC functions.
92 #include <kern/thread.h>
283 * (Or the current thread must be in the task.)
365 * (Or the current thread must be in the task.)
432 * Initialize a thread's IPC state.
439 thread_t thread)
447 thread->ith_self = kport;
448 thread->ith_sself = ipc_port_make_send(kport);
449 thread->exc_actions = NULL;
451 ipc_kobject_set(kport, (ipc_kobject_t)thread, IKOT_THREAD);
454 thread->ith_assertions = 0;
457 ipc_kmsg_queue_init(&thread->ith_messages);
459 thread->ith_rpc_reply = IP_NULL;
464 thread_t thread)
466 assert(thread->exc_actions == NULL);
468 thread->exc_actions = kalloc(sizeof(struct exception_action) * EXC_TYPES_COUNT);
469 bzero(thread->exc_actions, sizeof(struct exception_action) * EXC_TYPES_COUNT);
474 thread_t thread)
476 if (thread->exc_actions != NULL) {
477 kfree(thread->exc_actions,
479 thread->exc_actions = NULL;
485 thread_t thread)
487 ipc_port_t kport = thread->ith_self;
496 * Clean up and destroy a thread's IPC state.
503 thread_t thread)
505 ipc_port_t kport = thread->ith_self;
510 if (IP_VALID(thread->ith_sself))
511 ipc_port_release_send(thread->ith_sself);
513 thread->ith_sself = thread->ith_self = IP_NULL;
515 if (thread->exc_actions != NULL) {
517 if (IP_VALID(thread->exc_actions[i].port))
518 ipc_port_release_send(thread->exc_actions[i].port);
520 ipc_thread_destroy_exc_actions(thread);
527 assert(thread->ith_assertions == 0);
530 assert(ipc_kmsg_queue_empty(&thread->ith_messages));
532 if (thread->ith_rpc_reply != IP_NULL)
533 ipc_port_dealloc_reply(thread->ith_rpc_reply);
535 thread->ith_rpc_reply = IP_NULL;
541 * Reset the IPC state for a given Mach thread when
543 * Both the thread port and its exception ports have
552 thread_t thread)
564 thread_mtx_lock(thread);
566 old_kport = thread->ith_self;
570 thread_mtx_unlock(thread);
575 thread->ith_self = new_kport;
576 old_sself = thread->ith_sself;
577 thread->ith_sself = ipc_port_make_send(new_kport);
579 ipc_kobject_set(new_kport, (ipc_kobject_t) thread, IKOT_THREAD);
585 if (thread->exc_actions != NULL) {
588 if (thread->exc_actions[i].privileged) {
591 old_exc_actions[i] = thread->exc_actions[i].port;
592 thread->exc_actions[i].port = IP_NULL;
597 thread_mtx_unlock(thread);
656 * for the thread's user-visible self port.
658 * Only works for the current thread.
666 thread_t thread)
670 assert(thread == current_thread());
672 thread_mtx_lock(thread);
674 assert(thread->ith_self != IP_NULL);
676 if ((port = thread->ith_sself) == thread->ith_self) {
688 thread_mtx_unlock(thread);
720 * Give the caller send rights for his own thread port.
732 thread_t thread = current_thread();
733 task_t task = thread->task;
737 sright = retrieve_thread_self_fast(thread);
773 * Clones a send right for one of the thread's
779 * KERN_INVALID_ARGUMENT The thread is null.
780 * KERN_FAILURE The thread is dead.
786 thread_t thread,
793 if (thread == THREAD_NULL)
799 whichp = &thread->ith_sself;
806 thread_mtx_lock(thread);
808 if (thread->active)
813 thread_mtx_unlock(thread);
821 * Changes one of the thread's special ports,
828 * KERN_INVALID_ARGUMENT The thread is null.
829 * KERN_FAILURE The thread is dead.
835 thread_t thread,
842 if (thread == THREAD_NULL)
848 whichp = &thread->ith_sself;
855 thread_mtx_lock(thread);
857 if (thread->active) {
864 thread_mtx_unlock(thread);
1369 * Convert from a port to a thread.
1370 * Doesn't consume the port ref; produces an thread ref,
1380 thread_t thread = THREAD_NULL;
1387 thread = (thread_t)port->ip_kobject;
1388 assert(thread != THREAD_NULL);
1390 thread_reference_internal(thread);
1396 return (thread);
1402 * Convert from a port name to an thread reference
1403 * A name of MACH_PORT_NULL is valid for the null thread.
1411 thread_t thread = THREAD_NULL;
1420 thread = convert_port_to_thread(kport);
1426 return (thread);
1553 * Convert from a thread to a port.
1554 * Consumes an thread ref; produces a naked send right
1562 thread_t thread)
1566 thread_mtx_lock(thread);
1568 if (thread->ith_self != IP_NULL)
1569 port = ipc_port_make_send(thread->ith_self);
1573 thread_mtx_unlock(thread);
1575 thread_deallocate(thread);
1597 * Routine: thread/task_set_exception_ports [kernel call]
1599 * Sets the thread/task exception port, flavor and
1608 * KERN_INVALID_ARGUMENT The thread is null,
1611 * KERN_FAILURE The thread is dead.
1616 thread_t thread,
1626 if (thread == THREAD_NULL)
1653 thread_mtx_lock(thread);
1655 if (!thread->active) {
1656 thread_mtx_unlock(thread);
1661 if (thread->exc_actions == NULL) {
1662 ipc_thread_init_exc_actions(thread);
1666 old_port[i] = thread->exc_actions[i].port;
1667 thread->exc_actions[i].port = ipc_port_copy_send(new_port);
1668 thread->exc_actions[i].behavior = new_behavior;
1669 thread->exc_actions[i].flavor = new_flavor;
1670 thread->exc_actions[i].privileged = privileged;
1676 thread_mtx_unlock(thread);
1761 * Routine: thread/task_swap_exception_ports [kernel call]
1763 * Sets the thread/task exception port, flavor and
1781 * KERN_INVALID_ARGUMENT The thread is null,
1784 * KERN_FAILURE The thread is dead.
1789 thread_t thread,
1804 if (thread == THREAD_NULL)
1826 thread_mtx_lock(thread);
1828 if (!thread->active) {
1829 thread_mtx_unlock(thread);
1834 if (thread->exc_actions == NULL) {
1835 ipc_thread_init_exc_actions(thread);
1846 if ( thread->exc_actions[i].port == ports[j] &&
1847 thread->exc_actions[i].behavior == behaviors[j] &&
1848 thread->exc_actions[i].flavor == flavors[j] ) {
1856 ports[j] = ipc_port_copy_send(thread->exc_actions[i].port);
1858 behaviors[j] = thread->exc_actions[i].behavior;
1859 flavors[j] = thread->exc_actions[i].flavor;
1863 old_port[i] = thread->exc_actions[i].port;
1864 thread->exc_actions[i].port = ipc_port_copy_send(new_port);
1865 thread->exc_actions[i].behavior = new_behavior;
1866 thread->exc_actions[i].flavor = new_flavor;
1867 thread->exc_actions[i].privileged = privileged;
1873 thread_mtx_unlock(thread);
1986 * Routine: thread/task_get_exception_ports [kernel call]
1988 * Clones a send right for each of the thread/task's exception
1998 * KERN_INVALID_ARGUMENT The thread is null,
2001 * KERN_FAILURE The thread is dead.
2006 thread_t thread,
2016 if (thread == THREAD_NULL)
2022 thread_mtx_lock(thread);
2024 if (!thread->active) {
2025 thread_mtx_unlock(thread);
2032 if (thread->exc_actions == NULL) {
2043 if ( thread->exc_actions[i].port == ports[j] &&
2044 thread->exc_actions[i].behavior ==behaviors[j] &&
2045 thread->exc_actions[i].flavor == flavors[j] ) {
2053 ports[j] = ipc_port_copy_send(thread->exc_actions[i].port);
2054 behaviors[j] = thread->exc_actions[i].behavior;
2055 flavors[j] = thread->exc_actions[i].flavor;
2064 thread_mtx_unlock(thread);