Lines Matching defs:thread
68 * Task and thread related IPC functions.
92 #include <kern/thread.h>
276 * (Or the current thread must be in the task.)
353 * (Or the current thread must be in the task.)
415 * Initialize a thread's IPC state.
422 thread_t thread)
431 thread->ith_self = kport;
432 thread->ith_sself = ipc_port_make_send(kport);
435 thread->exc_actions[i].port = IP_NULL;
437 ipc_kobject_set(kport, (ipc_kobject_t)thread, IKOT_THREAD);
439 ipc_kmsg_queue_init(&thread->ith_messages);
441 thread->ith_rpc_reply = IP_NULL;
446 thread_t thread)
448 ipc_port_t kport = thread->ith_self;
457 * Clean up and destroy a thread's IPC state.
464 thread_t thread)
466 ipc_port_t kport = thread->ith_self;
471 if (IP_VALID(thread->ith_sself))
472 ipc_port_release_send(thread->ith_sself);
474 thread->ith_sself = thread->ith_self = IP_NULL;
477 if (IP_VALID(thread->exc_actions[i].port))
478 ipc_port_release_send(thread->exc_actions[i].port);
484 assert(ipc_kmsg_queue_empty(&thread->ith_messages));
486 if (thread->ith_rpc_reply != IP_NULL)
487 ipc_port_dealloc_reply(thread->ith_rpc_reply);
489 thread->ith_rpc_reply = IP_NULL;
495 * Reset the IPC state for a given Mach thread when
497 * Both the thread port and its exception ports have
506 thread_t thread)
517 thread_mtx_lock(thread);
519 old_kport = thread->ith_self;
523 thread_mtx_unlock(thread);
528 thread->ith_self = new_kport;
529 old_sself = thread->ith_sself;
530 thread->ith_sself = ipc_port_make_send(new_kport);
532 ipc_kobject_set(new_kport, (ipc_kobject_t) thread, IKOT_THREAD);
535 if (!thread->exc_actions[i].privileged) {
536 old_exc_actions[i] = thread->exc_actions[i].port;
537 thread->exc_actions[i].port = IP_NULL;
543 thread_mtx_unlock(thread);
602 * for the thread's user-visible self port.
604 * Only works for the current thread.
612 thread_t thread)
616 assert(thread == current_thread());
618 thread_mtx_lock(thread);
620 assert(thread->ith_self != IP_NULL);
622 if ((port = thread->ith_sself) == thread->ith_self) {
634 thread_mtx_unlock(thread);
666 * Give the caller send rights for his own thread port.
678 thread_t thread = current_thread();
679 task_t task = thread->task;
683 sright = retrieve_thread_self_fast(thread);
719 * Clones a send right for one of the thread's
725 * KERN_INVALID_ARGUMENT The thread is null.
726 * KERN_FAILURE The thread is dead.
732 thread_t thread,
739 if (thread == THREAD_NULL)
745 whichp = &thread->ith_sself;
752 thread_mtx_lock(thread);
754 if (thread->active)
759 thread_mtx_unlock(thread);
767 * Changes one of the thread's special ports,
774 * KERN_INVALID_ARGUMENT The thread is null.
775 * KERN_FAILURE The thread is dead.
781 thread_t thread,
788 if (thread == THREAD_NULL)
794 whichp = &thread->ith_sself;
801 thread_mtx_lock(thread);
803 if (thread->active) {
810 thread_mtx_unlock(thread);
1311 * Convert from a port to a thread.
1312 * Doesn't consume the port ref; produces an thread ref,
1322 thread_t thread = THREAD_NULL;
1329 thread = (thread_t)port->ip_kobject;
1330 assert(thread != THREAD_NULL);
1332 thread_reference_internal(thread);
1338 return (thread);
1344 * Convert from a port name to an thread reference
1345 * A name of MACH_PORT_NULL is valid for the null thread.
1353 thread_t thread = THREAD_NULL;
1362 thread = convert_port_to_thread(kport);
1368 return (thread);
1451 * Convert from a thread to a port.
1452 * Consumes an thread ref; produces a naked send right
1460 thread_t thread)
1464 thread_mtx_lock(thread);
1466 if (thread->ith_self != IP_NULL)
1467 port = ipc_port_make_send(thread->ith_self);
1471 thread_mtx_unlock(thread);
1473 thread_deallocate(thread);
1495 * Routine: thread/task_set_exception_ports [kernel call]
1497 * Sets the thread/task exception port, flavor and
1506 * KERN_INVALID_ARGUMENT The thread is null,
1509 * KERN_FAILURE The thread is dead.
1514 thread_t thread,
1524 if (thread == THREAD_NULL)
1551 thread_mtx_lock(thread);
1553 if (!thread->active) {
1554 thread_mtx_unlock(thread);
1561 old_port[i] = thread->exc_actions[i].port;
1562 thread->exc_actions[i].port = ipc_port_copy_send(new_port);
1563 thread->exc_actions[i].behavior = new_behavior;
1564 thread->exc_actions[i].flavor = new_flavor;
1565 thread->exc_actions[i].privileged = privileged;
1571 thread_mtx_unlock(thread);
1648 * Routine: thread/task_swap_exception_ports [kernel call]
1650 * Sets the thread/task exception port, flavor and
1668 * KERN_INVALID_ARGUMENT The thread is null,
1671 * KERN_FAILURE The thread is dead.
1676 thread_t thread,
1691 if (thread == THREAD_NULL)
1710 thread_mtx_lock(thread);
1712 if (!thread->active) {
1713 thread_mtx_unlock(thread);
1727 if ( thread->exc_actions[i].port == ports[j] &&
1728 thread->exc_actions[i].behavior == behaviors[j] &&
1729 thread->exc_actions[i].flavor == flavors[j] ) {
1737 ports[j] = ipc_port_copy_send(thread->exc_actions[i].port);
1739 behaviors[j] = thread->exc_actions[i].behavior;
1740 flavors[j] = thread->exc_actions[i].flavor;
1744 old_port[i] = thread->exc_actions[i].port;
1745 thread->exc_actions[i].port = ipc_port_copy_send(new_port);
1746 thread->exc_actions[i].behavior = new_behavior;
1747 thread->exc_actions[i].flavor = new_flavor;
1748 thread->exc_actions[i].privileged = privileged;
1756 thread_mtx_unlock(thread);
1866 * Routine: thread/task_get_exception_ports [kernel call]
1868 * Clones a send right for each of the thread/task's exception
1878 * KERN_INVALID_ARGUMENT The thread is null,
1881 * KERN_FAILURE The thread is dead.
1886 thread_t thread,
1896 if (thread == THREAD_NULL)
1902 thread_mtx_lock(thread);
1904 if (!thread->active) {
1905 thread_mtx_unlock(thread);
1919 if ( thread->exc_actions[i].port == ports[j] &&
1920 thread->exc_actions[i].behavior ==behaviors[j] &&
1921 thread->exc_actions[i].flavor == flavors[j] ) {
1929 ports[j] = ipc_port_copy_send(thread->exc_actions[i].port);
1930 behaviors[j] = thread->exc_actions[i].behavior;
1931 flavors[j] = thread->exc_actions[i].flavor;
1939 thread_mtx_unlock(thread);