NAME
thread_get_special_port-returns a special port of a thread
thread_set_special_port-set a special port of a thread
thread_self -returns calling thread’s kernel port
thread_reply -returns calling thread’s reply port

SYNOPSIS
#include <mach.h>

kern_return_t thread_get_special_port(thread, which_port, special_port)
thread_t thread;
int which_port;
port_t *special_port;

kern_return_t thread_set_special_port(thread, which_port, special_port)
thread_t thread;
int which_port;
port_t special_port;

thread_t thread_self()

port_t thread_reply()

ARGUMENTS
thread The thread for which to get the port

which_port The port that is requested. Is one of
THREAD_REPLY_PORT or THREAD_EXCEPTION_PORT.

special_port The value of the port that is being requested or
being set.

DESCRIPTION
get_special_port returns send rights to one of a set of special
ports for the thread specified by thread. In the case of getting
the thread’s own thread_reply_port, receive and ownership rights
are also given to the thread.

set_special_port sets one of a set of special ports for the thread
specified by thread.

thread_self returns the port to which kernel calls for the
currently executing thread should be directed. Currently,
thread_self returns the thread kernel port which is a port for
which the kernel has receive rights and which it uses to identify a
thread. In the future it may be possible for one thread to
interpose a port as another’s thread’s kernel port. At that time,
thread_self will still return the port to which the executing
thread should direct kernel calls, but it may no longer be a port
on which the kernel has receive rights.

If one thread, the controller, has send access to the kernel port
of another thread, the subject thread, then the controller thread
can perform kernel operations for the subject thread. Normally only
the thread itself and its parent task will have access to the
thread kernel port, but any thread may pass rights to its kernel
port to any other thread.

thread_reply returns receive, ownership and send rights to the
reply port of the calling thread. The reply port is a port to which
the thread has receive rights. It is used to receive any
initialization messages and as a reply port for early remote
procedure calls.

The following macros to call thread_get/set_special_port for a
specific port are defined in <sys/thread_special_ports.h>:
thread_get_reply_port, thread_set_reply_port,
thread_get_exception_port and thread_set_exception_port.

A thread also has access to its task’s special ports.

DIAGNOSTICS
KERN_SUCCESS The port was returned or set.

KERN_INVALID_ARGUMENT thread is not a thread or which_port
is an invalid port selector.

SEE ALSO
task_special_ports(2), thread_create(2)

BUGS
THREAD_KERNEL_PORT may be added to the set of ports that
thread_set_special_port accepts.