#include <mach/mach_port.h> also included by
<mach/mach.h>mach/mach_port.h
macro_mach_port_user_
#define _mach_port_user_
macromach_port_MSG_COUNT
#define mach_port_MSG_COUNT 43
functionmach_port_names
extern kern_return_t mach_port_names( ipc_space_t task, mach_port_name_array_t *names, /* out */ mach_msg_type_number_t *namesCnt, mach_port_type_array_t *types, /* out */ mach_msg_type_number_t *typesCnt )
Returns the set of port and port set names
to which the target task has access, along with
the type (set or port) for each name.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return information about a task's port name space.
The mach_port_names returns information about task 's port name space. It returns task's currently active names, which represent some port, port set, or dead name right. For each name, it also returns what type of rights task holds (the same information returned by mach_port_type).
Note that when a call to mach_port_names returns, the number of entries in the two output arrays (names and types) are equal (namesCnt equals typesCnt). The fact that this interface returns two separate counts is an artifact of the Mach Interface Generator.
Notes. This interface is machine word length specific because of the port name parameter and the returned port names.
functionmach_port_type
extern kern_return_t mach_port_type( ipc_space_t task, mach_port_name_t name, mach_port_type_t *ptype /* out */ )
Returns the type (set or port) for the port name
within the target task. Also indicates whether
there is a dead-name request for the name.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return the characteristics of the target port name.
The mach_port_type function returns information about task 's rights for a specific name in its port name space. The returned ptype is a bit-mask indicating what rights task holds with this name. The bit-mask is composed of the following bits: MACH_PORT_TYPE_SEND The name denotes send rights.
MACH_PORT_TYPE_RECEIVE The name denotes a receive right.
MACH_PORT_TYPE_SEND_ONCE The name denotes a send-once right.
MACH_PORT_TYPE_PORT_SET The name denotes a port set.
MACH_PORT_TYPE_DEAD_NAME The name is a dead name.
MACH_PORT_TYPE_DNREQUEST A dead-name request has been registered for the right.
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_INVALID_NAME | name did not denote a right. |
functionmach_port_rename
extern kern_return_t mach_port_rename( ipc_space_t task, mach_port_name_t old_name, mach_port_name_t new_name )
OBSOLETE interface, removed from kernel
functionmach_port_allocate_name
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t mach_port_allocate_name( ipc_space_t task, mach_port_right_t right, mach_port_name_t name )
Allocates the specified kind of object, with the given name.
The right must be one of
MACH_PORT_RIGHT_RECEIVE
MACH_PORT_RIGHT_PORT_SET
MACH_PORT_RIGHT_DEAD_NAME
New port sets are empty. New ports don't have any
send/send-once rights or queued messages. The make-send
count is zero and their queue limit is MACH_PORT_QLIMIT_DEFAULT.
New sets, ports, and dead names have one user reference.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Create a port right with the caller-specified name.
The mach_port_allocate_name function creates a new right in the specified task, with a specified name for the new right.
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_NAME_EXISTS | name was already in use for a port right. |
functionmach_port_allocate
extern kern_return_t mach_port_allocate( ipc_space_t task, mach_port_right_t right, mach_port_name_t *name /* out */ )
Allocates the specified kind of object.
The right must be one of
MACH_PORT_RIGHT_RECEIVE
MACH_PORT_RIGHT_PORT_SET
MACH_PORT_RIGHT_DEAD_NAME
Like port_allocate_name, but the kernel picks a name.
It can use any name not associated with a right.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Create caller-specified type of port right.
The mach_port_allocate function creates a new right in the specified task. The new right's name is returned in name.
Ports that are allocated via this call do not support the full set of Mach port semantics; in particular, the kernel will not provide no-more-senders notification service requests on such ports. Any attempt to request no-more-senders notification service will generate an error. Use the mach_port_allocate_full interface to allocate ports that support the full set of Mach port semantics.
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_NO_SPACE | There was no room in task's IPC name space for another right. |
functionmach_port_destroy
extern __API_DEPRECATED("Inherently unsafe API: instead manage rights with " "mach_port_destruct(), mach_port_deallocate() or mach_port_mod_refs()", macos(10.0, 12.0), ios(2.0, 15.0), tvos(9.0, 15.0), watchos(2.0, 8.0)) kern_return_t mach_port_destroy(
ipc_space_t task,
mach_port_name_t name
)deprecated
Destroys all rights associated with the name and makes it
available for recycling immediately. The name can be a
port (possibly with multiple user refs), a port set, or
a dead name (again, with multiple user refs).
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Deallocate all port rights associated with specified name.
The mach_port_destroy function de-allocates all rights denoted by a name. The name becomes immediately available for reuse.
For most purposes, mach_port_mod_refs and mach_port_deallocate are preferable.
If name denotes a port set, then all members of the port set are implicitly removed from the port set.
If name denotes a receive right that is a member of a port set, the receive right is implicitly removed from the port set. Remaining messages queued to the port are destroyed and extant send and send-once rights turn into dead names. If those send and send-once rights have dead-name requests registered, then dead-name notifications are generated for them.
If name denotes a send-once right, then the destruction of the send-once right produces a send-once notification for the port.
If name denotes a send-once, send, and/or receive right, and it has a dead-name request registered, then a port-deleted notification is generated (as opposed to a dead-name notification).
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_INVALID_NAME | The name parameter did not denote a right. |
functionmach_port_deallocate
extern kern_return_t mach_port_deallocate(ipc_space_t task, mach_port_name_t name)
Releases one send/send-once/dead-name user ref.
Just like mach_port_mod_refs -1, but deduces the
correct type of right. This allows a user task
to release a ref for a port without worrying
about whether the port has died or not.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Decrement the target port right's user reference count.
The mach_port_deallocate function releases a user reference for a right. It is an alternate form of mach_port_mod_refs that allows a task to release a user reference for a send or send-once right without failing if the port has died and the right is now actually a dead name.
If name denotes a dead name, send right, or send-once right, then the right loses one user reference. If it only had one user reference, then the right is destroyed. If name does not denote an element in the port name space, the function returns success.
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_INVALID_RIGHT | The name parameter denoted an invalid right. |
functionmach_port_get_refs
extern kern_return_t mach_port_get_refs( ipc_space_t task, mach_port_name_t name, mach_port_right_t right, mach_port_urefs_t *refs /* out */ )
A port set always has one user ref.
A send-once right always has one user ref.
A dead name always has one or more user refs.
A send right always has one or more user refs.
A receive right always has one user ref.
The right must be one of
MACH_PORT_RIGHT_RECEIVE
MACH_PORT_RIGHT_PORT_SET
MACH_PORT_RIGHT_DEAD_NAME
MACH_PORT_RIGHT_SEND
MACH_PORT_RIGHT_SEND_ONCE
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return the current count of user references on the target port right.
The mach_port_get_refs function returns the number of user references a task has for a right.
If name denotes a right, but not the type of right specified, then zero is returned. Otherwise a positive number of user references is returned. Note a name may simultaneously denote send and receive rights. The number of references for send-once rights is always one.
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_INVALID_NAME | name did not denote a right. |
functionmach_port_mod_refs
extern kern_return_t mach_port_mod_refs( ipc_space_t task, mach_port_name_t name, mach_port_right_t right, mach_port_delta_t delta )
The delta is a signed change to the task's
user ref count for the right. Only dead names
and send rights can have a positive delta.
The resulting user ref count can't be negative.
If it is zero, the right is deallocated.
If the name isn't a composite right, it becomes
available for recycling. The right must be one of
MACH_PORT_RIGHT_RECEIVE
MACH_PORT_RIGHT_PORT_SET
MACH_PORT_RIGHT_DEAD_NAME
MACH_PORT_RIGHT_SEND
MACH_PORT_RIGHT_SEND_ONCE
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Modify the specified port right's count of user references.
The mach_port_mod_refs function requests that the number of user references a task has for a right be changed. This results in the right being destroyed, if the number of user references is changed to zero.
The name parameter should denote the specified right. The number of user references for the right is changed by the amount delta, subject to the following restrictions: port sets, receive rights, and send-once rights may only have one user reference. The resulting number of user references can't be negative. If the resulting number of user references is zero, the effect is to de-allocate the right. For dead names and send rights, there is an implementation-defined maximum number of user references.
If the call destroys the right, then the effect is as described for mach_port_destroy, with the exception that mach_port_destroy simultaneously destroys all the rights denoted by a name, while mach_port_mod_refs can only destroy one right. The name will be available for reuse if it only denoted the one right.
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_INVALID_NAME | name did not denote a right. |
| KERN_INVALID_RIGHT | name denoted a right, but not the specified right. |
| KERN_INVALID_VALUE | The user-reference count would become negative. |
| KERN_UREFS_OVERFLOW | The user-reference count would overflow. |
functionmach_port_peek
extern kern_return_t mach_port_peek( ipc_space_t task, mach_port_name_t name, mach_msg_trailer_type_t trailer_type, mach_port_seqno_t *request_seqnop, /* inout */ mach_msg_size_t *msg_sizep, /* out */ mach_msg_id_t *msg_idp, /* out */ mach_msg_trailer_info_t trailer_infop, /* out */ mach_msg_type_number_t *trailer_infopCnt )
Peek at the message queue for the specified receive
right and return info about the message with the
sequence number matching the input. If zero is
specified as the seqno, the first message in the
queue will be peeked.
Only the following trailer types are currently supported:
MACH_RCV_TRAILER_TYPE(MACH_MSG_TRAILER_FORMAT_0)
or'ed with one of these element types:
MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_NULL)
MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_SEQNO)
MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_SENDER)
MACH_RCV_TRAILER_ELEMENTS(MACH_RCV_TRAILER_AUDIT)
functionmach_port_set_mscount
extern kern_return_t mach_port_set_mscount( ipc_space_t task, mach_port_name_t name, mach_port_mscount_t mscount )
Only valid for receive rights.
Sets the make-send count for the port.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Change the target port's make-send count.
The mach_port_set_mscount function changes the make-send count of task 's receive right named name. A port's make-send count specifies the number of send rights that have been generated via the port's receive right. A port's make-send count is set to zero when the port is first allocated; the count is reset to zero each time the port's receive right is transferred via a Mach message.
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_INVALID_NAME | name did not denote a right. |
| KERN_INVALID_RIGHT | name denoted a right, but not a receive right. |
functionmach_port_get_set_status
extern kern_return_t mach_port_get_set_status( ipc_space_read_t task, mach_port_name_t name, mach_port_name_array_t *members, /* out */ mach_msg_type_number_t *membersCnt )
Only valid for port sets. Returns a list of
the members.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return the port right names contained in the target port set.
The mach_port_get_set_status function returns the individual port right names for all port rights contained in the specified port set. The members parameter is an array that is automatically allocated when the reply message is received. Note that vm_deallocate should be used to free the array.
Note that this interface, unlike others such as task_threads, returns a collection of port right names, NOT a collection of port rights themselves. In other words, this function does not insert port rights into the caller's port right name space; consequently, a call to mach_port_get_set_status does not affect the reference count of each port right within the target port set.
Notes. This interface is machine word length specific because of the port name parameter and the returned port names.
| KERN_INVALID_NAME | name did not denote a right. |
| KERN_INVALID_RIGHT | name denoted a right, but not a port set. |
functionmach_port_move_member
extern kern_return_t mach_port_move_member( ipc_space_t task, mach_port_name_t member, mach_port_name_t after )
Puts the member port (the task must have receive rights)
into the after port set. If the port is already a member
of any set(s), it is atomically removed from those sets as
part of this operation. (If after is MACH_PORT_NULL, the
port is still removed from all current sets).
CMU/MIT Mach reference · manual page · © Carnegie Mellon
The mach_port_move_member function moves a receive right into a port set. If the receive right is already a member of any other port sets, it is removed from those sets first. If the port set is MACH_PORT_NULL, then the receive right is not put into a port set, but removed from all its current port sets.
Notes. This interface is machine word length specific because of the port name parameter.
functionmach_port_request_notification
extern kern_return_t mach_port_request_notification( ipc_space_t task, mach_port_name_t name, mach_msg_id_t msgid, mach_port_mscount_t sync, mach_port_t notify, mach_msg_type_name_t notifyPoly, mach_port_t *previous /* out */ )
Requests a notification from the kernel. The request
must supply the send-once right which is used for
the notification. If a send-once right was previously
registered, it is returned. The msgid must be one of:
MACH_NOTIFY_PORT_DESTROYED (receive rights)
MACH_NOTIFY_DEAD_NAME (send/receive/send-once rights)
MACH_NOTIFY_SEND_POSSIBLE (send/receive/send-once rights)
MACH_NOTIFY_NO_SENDERS (receive rights)
The sync value specifies whether a notification should
get sent immediately, if appropriate. The exact meaning
depends on the notification:
MACH_NOTIFY_PORT_DESTROYED: must be zero.
MACH_NOTIFY_DEAD_NAME: if non-zero, then name can be dead,
and the notification gets sent immediately.
If zero, then name can't be dead.
MACH_NOTIFY_SEND_POSSIBLE: if non-zero, will generate a send-
possible notification as soon as it is possible to send
to the port. If zero, will generate a send-possible
notification only after a subsequent failed send
(with MACH_SEND_NOTIFY option to mach_msg call). Can
generate a dead-name notification if name is already dead
or becomes dead before a send-possible notification fires.
MACH_NOTIFY_NO_SENDERS: the notification gets sent
immediately if the current mscount is greater
than or equal to the sync value and there are no
extant send rights.
If the name is deleted before a successfully registered notification
is delivered, it is replaced with a port-deleted notification.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Request notification of the specified port event type.
The mach_port_request_notification function registers a request for a notification and supplies a send-once right that the notification will use. It is an atomic swap, returning the previously registered send-once right (or MACH_PORT_NULL for none). A notification request may be cancelled by providing MACH_PORT_NULL.
The variant argument takes the following values: MACH_NOTIFY_PORT_DESTROYED sync must be zero. The name must specify a receive right, and the call requests a port-destroyed notification for the receive right. If the receive right were to have been destroyed, for instance by mach_port_destroy, then instead the receive right will be sent in a port-destroyed notification to the registered send-once right.
MACH_NOTIFY_DEAD_NAME The call requests a dead-name notification. name specifies send, receive, or send-once rights for a port. If the port is destroyed (and the right remains, becoming a dead name), then a dead-name notification which carries the name of the right will be sent to the registered send-once right. If sync is non-zero, the name may specify a dead name, and a dead-name notification is immediately generated.
Whenever a dead-name notification is generated, the user reference count of the dead name is incremented. For example, a send right with two user refs has a registered dead-name request. If the port is destroyed, the send right turns into a dead name with three user refs (instead of two), and a dead-name notification is generated.
If the name is made available for reuse, perhaps because of mach_port_destroy or mach_port_mod_refs, or the name denotes a send-once right which has a message sent to it, then the registered send-once right is used to generate a port-deleted notification instead.
MACH_NOTIFY_NO_SENDERS The call requests a no-senders notification. name must specify a receive right. If the receive right's make-send count is greater than or equal to the sync value, and it has no extant send rights, than an immediate no-senders notification is generated. Otherwise the notification is generated when the receive right next loses its last extant send right. In either case, any previously registered send-once right is returned.
The no-senders notification carries the value the port's make-send count had when it was generated. The make-send count is incremented whenever a send right is made directly from a receive right. The make-send count is reset to zero when the receive right is carried in a message.
When moving a receive right, no-senders notifications are canceled, with a send-once notification sent to indicate the cancelation.
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_INVALID_NAME | name did not denote a right. |
| KERN_INVALID_RIGHT | name denoted an invalid right. |
| KERN_INVALID_CAPABILITY | notify was invalid. |
| KERN_UREFS_OVERFLOW | name denotes a dead name, but generating an immediate dead-name notification would overflow the name's user-reference count. |
functionmach_port_insert_right
extern kern_return_t mach_port_insert_right( ipc_space_t task, mach_port_name_t name, mach_port_t poly, mach_msg_type_name_t polyPoly )
Inserts the specified rights into the target task,
using the specified name. If inserting send/receive
rights and the task already has send/receive rights
for the port, then the names must agree. In any case,
the task gains a user ref for the port.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Insert the specified port right into the target task.
The mach_port_insert_right function inserts into task the caller's right for a port, using a specified name for the right in the target task.
The specified name can't be one of the reserved values MACH_PORT_NULL or MACH_PORT_DEAD. The right can't be MACH_PORT_NULL or MACH_PORT_DEAD.
The argument right_type specifies a right to be inserted and how that right should be extracted from the caller. It should be a value appropriate for mach_msg.
If right_type is MACH_MSG_TYPE_MAKE_SEND, MACH_MSG_TYPE_MOVE_SEND, or MACH_MSG_TYPE_COPY_SEND, then a send right is inserted. If the target already holds send or receive rights for the port, then name should denote those rights in the target. Otherwise, name should be unused in the target. If the target already has send rights, then those send rights gain an additional user reference. Otherwise, the target gains a send right, with a user reference count of one.
If right_type is MACH_MSG_TYPE_MAKE_SEND_ONCE or MACH_MSG_TYPE_MOVE_SEND_ONCE, then a send-once right is inserted. The name should be unused in the target. The target gains a send-once right.
If right_type is MACH_MSG_TYPE_MOVE_RECEIVE, then a receive right is inserted. If the target already holds send rights for the port, then name should denote those rights in the target. Otherwise, name should be unused in the target. The receive right is moved into the target task.
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_NAME_EXISTS | name already denoted a right. |
| KERN_INVALID_CAPABILITY | right was null or dead. |
| KERN_UREFS_OVERFLOW | Inserting the right would overflow name 's user-reference count. |
| KERN_RIGHT_EXISTS | task already had rights for the port, with a different name. |
functionmach_port_extract_right
extern kern_return_t mach_port_extract_right( ipc_space_t task, mach_port_name_t name, mach_msg_type_name_t msgt_name, mach_port_t *poly, /* out */ mach_msg_type_name_t *polyPoly )
Returns the specified right for the named port
in the target task, extracting that right from
the target task. The target task loses a user
ref and the name may be available for recycling.
msgt_name must be one of
MACH_MSG_TYPE_MOVE_RECEIVE
MACH_MSG_TYPE_COPY_SEND
MACH_MSG_TYPE_MAKE_SEND
MACH_MSG_TYPE_MOVE_SEND
MACH_MSG_TYPE_MAKE_SEND_ONCE
MACH_MSG_TYPE_MOVE_SEND_ONCE
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Remove the specified right from the target task and return it to the caller.
The mach_port_extract_right function extracts a port right from the target task and returns it to the caller as if the task sent the right voluntarily, using desired_type as the disposition for the right. See mach_msg.
The returned value of acquired_type will be MACH_MSG_TYPE_PORT_SEND if a send right is extracted, MACH_MSG_TYPE_PORT_RECEIVE if a receive right is extracted, and MACH_MSG_TYPE_PORT_SEND_ONCE if a send-once right is extracted.
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_INVALID_NAME | name did not denote a right. |
| KERN_INVALID_RIGHT | name denoted an invalid right. |
functionmach_port_set_seqno
extern kern_return_t mach_port_set_seqno( ipc_space_t task, mach_port_name_t name, mach_port_seqno_t seqno )
Only valid for receive rights.
Sets the sequence number for the port.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Change the current value of the target port's sequence number.
The mach_port_set_seqno function changes the sequence number of task 's receive right named name.
(Each port is associated with a sequence number attribute that can be used to track the order in which messages sent to the port are received. A port's sequence number is initially set to zero and is incremented each time a message is received from the port. A port's sequence number is automatically reset to zero each time the port's receive right migrates.)
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_INVALID_NAME | name did not denote a right. |
| KERN_INVALID_RIGHT | name denoted a right, but not a receive right. |
functionmach_port_get_attributes
extern kern_return_t mach_port_get_attributes( ipc_space_read_t task, mach_port_name_t name, mach_port_flavor_t flavor, mach_port_info_t port_info_out, /* out */ mach_msg_type_number_t *port_info_outCnt )
Returns information about a port.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Return information about target port as specified by the caller.
The mach_port_get_attributes function returns an information structure of type flavor.
Notes. This interface is machine word length specific because of the port name parameter in the MACH_PORT_RECEIVE_STATUS structure return.
| KERN_INVALID_NAME | name did not denote a right. |
| KERN_INVALID_RIGHT | name denoted a right, but not a receive right. |
functionmach_port_set_attributes
extern kern_return_t mach_port_set_attributes( ipc_space_t task, mach_port_name_t name, mach_port_flavor_t flavor, mach_port_info_t port_info, mach_msg_type_number_t port_infoCnt )
Set attributes of a port
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Set the target port's attributes.
The mach_port_set_attributes function sets attributes of type flavor.
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_INVALID_NAME | name did not denote a right. |
| KERN_INVALID_RIGHT | name denoted a right, but not a receive right. |
functionmach_port_allocate_qos
extern kern_return_t mach_port_allocate_qos( ipc_space_t task, mach_port_right_t right, mach_port_qos_t *qos, /* inout */ mach_port_name_t *name /* out */ )
Allocates the specified kind of object, qos version.
The right must be
MACH_PORT_RIGHT_RECEIVE
Like port_allocate_name, but the kernel picks a name.
It can use any name not associated with a right.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Allocate a port with specified "quality of service."
The mach_port_allocate_qos function allocates a port with caller-specified "quality of service" characteristics with or without a caller-specified name; in other words, the caller may specify a desired name or it may let the kernel generate the name. The new port is capable of supporting full Mach port semantics (i.e no-more-senders notification can be requested on the port).
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_NO_SPACE | There was no room in task's IPC name space for another right. |
| KERN_INVALID_VALUE | The type of right specified by right is either invalid or conflicts with the requested "quality of service" as specified via qos. |
functionmach_port_allocate_full
extern kern_return_t mach_port_allocate_full( ipc_space_t task, mach_port_right_t right, mach_port_t proto, mach_port_qos_t *qos, /* inout */ mach_port_name_t *name /* inout */ )
Generic interface to allocation various kinds of ports.
Should never be called directly by users (at least not
unless they are exceedingly masochistic).
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Create a port right with full Mach port semantics.
The mach_port_allocate_full function creates a new right in the specified task. The new right's name is returned via the name parameter. The new port supports the full set of Mach port semantics (i.e. no_more_senders detection will work, if requested).
Notes. This interface is machine word length specific because of the port name parameter.
| KERN_NO_SPACE | There was no room in task's IPC name space for another right. |
functiontask_set_port_space
extern __TVOS_PROHIBITED __WATCHOS_PROHIBITED kern_return_t task_set_port_space( ipc_space_t task, int table_entries )
Pre-expand task port name space.
OBSOLETE. Do nothing and return success.
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Set the size of the target task's port name space table.
The task_set_port_space function preallocates the specified number of entries in the specified task's IPC name space.
| KERN_NO_SPACE | The requested table size exceeds the maximum allowable table size. |
functionmach_port_get_srights
extern kern_return_t mach_port_get_srights( ipc_space_t task, mach_port_name_t name, mach_port_rights_t *srights /* out */ )
Returns the exact number of extant send rights
for the given receive right.
functionmach_port_space_info
extern kern_return_t mach_port_space_info( ipc_space_read_t space, ipc_info_space_t *space_info, /* out */ ipc_info_name_array_t *table_info, /* out */ mach_msg_type_number_t *table_infoCnt, ipc_info_tree_name_array_t *tree_info, /* out */ mach_msg_type_number_t *tree_infoCnt )
Returns information about an IPC space.
functionmach_port_dnrequest_info
extern kern_return_t mach_port_dnrequest_info( ipc_space_t task, mach_port_name_t name, unsigned *dnr_total, /* out */ /* total size of table */ unsigned *dnr_used /* out */ )
Returns information about the dead-name requests
registered with the named receive right.
functionmach_port_kernel_object
extern kern_return_t mach_port_kernel_object( ipc_space_read_t task, mach_port_name_t name, unsigned *object_type, /* out */ unsigned *object_addr /* out */ )
amount used
OBSOLETE interface, removed from kernel.
functionmach_port_insert_member
extern kern_return_t mach_port_insert_member( ipc_space_t task, mach_port_name_t name, mach_port_name_t pset )
Inserts the specified rights into the portset identified
by the <task, pset> pair. The results of passing in the
Poly argument via the supplied disposition must yield a
receive right.
If the <task,pset> pair does not represent a valid portset
KERN_INVALID_RIGHT is returned.
If the passed in name argument does not represent a receive
right, KERN_INVALID_CAPABILITY will be returned.
If the port represented by the receive right is already in
the portset, KERN_ALREADY_IN_SET is returned.
functionmach_port_extract_member
extern kern_return_t mach_port_extract_member( ipc_space_t task, mach_port_name_t name, mach_port_name_t pset )
Extracts the specified right from the named portset
in the target task.
the target task. The target task loses a user
ref and the name may be available for recycling.
msgt_name must be one of
MACH_MSG_TYPE_MOVE_RECEIVE
MACH_MSG_TYPE_COPY_SEND
MACH_MSG_TYPE_MAKE_SEND
MACH_MSG_TYPE_MOVE_SEND
MACH_MSG_TYPE_MAKE_SEND_ONCE
MACH_MSG_TYPE_MOVE_SEND_ONCE
functionmach_port_get_context
extern kern_return_t mach_port_get_context( ipc_space_read_t task, mach_port_name_t name, mach_port_context_t *context /* out */ )
Only valid for receive rights.
Gets the context pointer for the port.
functionmach_port_set_context
extern kern_return_t mach_port_set_context( ipc_space_t task, mach_port_name_t name, mach_port_context_t context )
Only valid for receive rights.
Sets the context pointer for the port.
functionmach_port_kobject
extern kern_return_t mach_port_kobject( ipc_space_read_t task, mach_port_name_t name, ipc_info_object_type_t *object_type, /* out */ mach_vm_address_t *object_addr /* out */ )
Return the type and address of the kernel object
that the given send/receive right represents.
functionmach_port_construct
extern kern_return_t mach_port_construct( ipc_space_t task, mach_port_options_ptr_t options, mach_port_context_t context, mach_port_name_t *name /* out */ )
Constructs a right based on the options passed
in. Also allows guarding the port as one of the
options if the requested right is a receive
right.
functionmach_port_destruct
extern kern_return_t mach_port_destruct( ipc_space_t task, mach_port_name_t name, mach_port_delta_t srdelta, mach_port_context_t guard )
Destroys a mach port using the guard provided
for guarded ports. Also reduces the user ref
count for send rights as specified by srdelta.
functionmach_port_guard
extern kern_return_t mach_port_guard( ipc_space_t task, mach_port_name_t name, mach_port_context_t guard, boolean_t strict )
Guard an already existing port. Allows guarding
receive rights only. Uses the context field in the
port structure to store the guard.
functionmach_port_unguard
extern kern_return_t mach_port_unguard( ipc_space_t task, mach_port_name_t name, mach_port_context_t guard )
Unguard a port guarded previously. For unguarded ports
or incorrect guards passed in it raises an exception
indicating guarding misbehavior.
functionmach_port_space_basic_info
extern kern_return_t mach_port_space_basic_info( ipc_space_inspect_t task, ipc_info_space_basic_t *basic_info /* out */ )
Returns basic information about an IPC space.
functionmach_port_guard_with_flags
extern kern_return_t mach_port_guard_with_flags( ipc_space_t task, mach_port_name_t name, mach_port_context_t guard, uint64_t flags )
Guard an already existing port. Allows guarding
receive rights only. Uses the context field in the
port structure to store the guard.
functionmach_port_swap_guard
extern kern_return_t mach_port_swap_guard( ipc_space_t task, mach_port_name_t name, mach_port_context_t old_guard, mach_port_context_t new_guard )
Swap guard value of an existing guarded port. Works
only if it is not a strict guard.
functionmach_port_kobject_description
extern kern_return_t mach_port_kobject_description( ipc_space_read_t task, mach_port_name_t name, ipc_info_object_type_t *object_type, /* out */ mach_vm_address_t *object_addr, /* out */ kobject_description_t description /* out */ )
Return the type and address of the kernel object
that the given send/receive right represents.
functionmach_port_is_connection_for_service
extern kern_return_t mach_port_is_connection_for_service( ipc_space_t task, mach_port_name_t connection_port, mach_port_name_t service_port, uint64_t *filter_policy_id /* out */ )
Verifies that connection port was created for this
service port and returns the filter policy id
for that connection port
functionmach_port_get_service_port_info
extern kern_return_t mach_port_get_service_port_info( ipc_space_read_t task, mach_port_name_t name, mach_service_port_info_data_t *sp_info_out /* out */ )
Get information about service ports. Supported only
on development/debug builds
functionmach_port_assert_attributes
extern kern_return_t mach_port_assert_attributes( ipc_space_t task, mach_port_name_t name, mach_port_flavor_t flavor, mach_port_info_t info, mach_msg_type_number_t infoCnt )
▾
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/ipc/mach_port.c
Asserts that a port's attributes match the caller's expectation, killing the caller if they do not. The only flavor is MACH_PORT_GUARD_INFO: info points to a mach_port_guard_info_t holding the guard value the caller believes protects the receive right name. If the port is unguarded, or is not strictly guarded with exactly that value, the kernel raises a fatal EXC_GUARD mach-port exception (kGUARD_EXC_UNGUARDED or kGUARD_EXC_INCORRECT_GUARD) and returns KERN_INVALID_ARGUMENT. Returns KERN_FAILURE if infoCnt is less than MACH_PORT_GUARD_INFO_COUNT, KERN_INVALID_RIGHT/KERN_INVALID_NAME if name does not denote a receive right.
macrosubsystem_to_name_map_mach_port
#define subsystem_to_name_map_mach_port { "mach_port_names", 3200 },
{ "mach_port_type", 3201 },
{ "mach_port_rename", 3202 },
{ "mach_port_allocate_name", 3203 },
{ "mach_port_allocate", 3204 },
{ "mach_port_destroy", 3205 },
{ "mach_port_deallocate", 3206 },
{ "mach_port_get_refs", 3207 },
{ "mach_port_mod_refs", 3208 },
{ "mach_port_peek", 3209 },
{ "mach_port_set_mscount", 3210 },
{ "mach_port_get_set_status", 3211 },
{ "mach_port_move_member", 3212 },
{ "mach_port_request_notification", 3213 },
{ "mach_port_insert_right", 3214 },
{ "mach_port_extract_right", 3215 },
{ "mach_port_set_seqno", 3216 },
{ "mach_port_get_attributes", 3217 },
{ "mach_port_set_attributes", 3218 },
{ "mach_port_allocate_qos", 3219 },
{ "mach_port_allocate_full", 3220 },
{ "task_set_port_space", 3221 },
{ "mach_port_get_srights", 3222 },
{ "mach_port_space_info", 3223 },
{ "mach_port_dnrequest_info", 3224 },
{ "mach_port_kernel_object", 3225 },
{ "mach_port_insert_member", 3226 },
{ "mach_port_extract_member", 3227 },
{ "mach_port_get_context", 3228 },
{ "mach_port_set_context", 3229 },
{ "mach_port_kobject", 3230 },
{ "mach_port_construct", 3231 },
{ "mach_port_destruct", 3232 },
{ "mach_port_guard", 3233 },
{ "mach_port_unguard", 3234 },
{ "mach_port_space_basic_info", 3235 },
{ "mach_port_guard_with_flags", 3237 },
{ "mach_port_swap_guard", 3238 },
{ "mach_port_kobject_description", 3239 },
{ "mach_port_is_connection_for_service", 3240 },
{ "mach_port_get_service_port_info", 3241 },
{ "mach_port_assert_attributes", 3242 }