Next: , Up: Host Interface


8.1 Host Ports

— Data type: host_t

This is a mach_port_t and used to hold the port name of a host name port (or short: host port). Any task can get a send right to the name port of the host running the task using the mach_host_self system call. The name port can be used query information about the host, for example the current time.

— Function: host_t mach_host_self ()

The mach_host_self system call returns the calling thread's host name port. It has an effect equivalent to receiving a send right for the host port. mach_host_self returns the name of the send right. In particular, successive calls will increase the calling task's user-reference count for the send right.

As a special exception, the kernel will overrun the user reference count of the host name port, so that this function can not fail for that reason. Because of this, the user should not deallocate the port right if an overrun might have happened. Otherwise the reference count could drop to zero and the send right be destroyed while the user still expects to be able to use it. As the kernel does not make use of the number of extant send rights anyway, this is safe to do (the host port itself is never destroyed).

The function returns MACH_PORT_NULL if a resource shortage prevented the reception of the send right.

This function is also available in mach/mach_traps.h.

— Data type: host_priv_t

This is a mach_port_t and used to hold the port name of a privileged host control port. A send right to the host control port is inserted into the first task at bootstrap (see Modules). This is the only way to get access to the host control port in Mach, so the initial task has to preserve the send right carefully, moving a copy of it to other privileged tasks if necessary and denying access to unprivileged tasks.