Next: Exchanging Port Rights, Previous: Mach Message Call, Up: Messaging Interface
A Mach message consists of a fixed size message header, a
mach_msg_header_t, followed by zero or more data items. Data
items are typed. Each item has a type descriptor followed by the actual
data (or the address of the data, for out-of-line memory regions).
The following data types are related to Mach ports:
The
mach_port_tdata type is an unsigned integer type which represents a port name in the task's port name space. In GNU Mach, this is anunsigned int.
The following data types are related to Mach messages:
The
mach_msg_bits_tdata type is anunsigned intused to store various flags for a message.
The
mach_msg_size_tdata type is anunsigned intused to store the size of a message.
The
mach_msg_id_tdata type is aninteger_ttypically used to convey a function or operation id for the receiver.
This structure is the start of every message in the Mach IPC system. It has the following members:
mach_msg_bits_t msgh_bits- The
msgh_bitsfield has the following bits defined, all other bits should be zero:
MACH_MSGH_BITS_REMOTE_MASKMACH_MSGH_BITS_LOCAL_MASK- The remote and local bits encode
mach_msg_type_name_tvalues that specify the port rights in themsgh_remote_portandmsgh_local_portfields. The remote value must specify a send or send-once right for the destination of the message. If the local value doesn't specify a send or send-once right for the message's reply port, it must be zero and msgh_local_port must beMACH_PORT_NULL.MACH_MSGH_BITS_COMPLEX- The complex bit must be specified if the message body contains port rights or out-of-line memory regions. If it is not specified, then the message body carries no port rights or memory, no matter what the type descriptors may seem to indicate.
MACH_MSGH_BITS_REMOTEandMACH_MSGH_BITS_LOCALmacros return the appropriatemach_msg_type_name_tvalues, given amsgh_bitsvalue. TheMACH_MSGH_BITSmacro constructs a value formsgh_bits, given twomach_msg_type_name_tvalues.mach_msg_size_t msgh_size- The
msgh_sizefield in the header of a received message contains the message's size. The message size, a byte quantity, includes the message header, type descriptors, and in-line data. For out-of-line memory regions, the message size includes the size of the in-line address, not the size of the actual memory region. There are no arbitrary limits on the size of a Mach message, the number of data items in a message, or the size of the data items.mach_port_t msgh_remote_port- The
msgh_remote_portfield specifies the destination port of the message. The field must carry a legitimate send or send-once right for a port.mach_port_t msgh_local_port- The
msgh_local_portfield specifies an auxiliary port right, which is conventionally used as a reply port by the recipient of the message. The field must carry a send right, a send-once right,MACH_PORT_NULL, orMACH_PORT_DEAD.mach_port_seqno_t msgh_seqno- The
msgh_seqnofield provides a sequence number for the message. It is only valid in received messages; its value in sent messages is overwritten.mach_msg_id_t msgh_id- The
mach_msgcall doesn't use themsgh_idfield, but it conventionally conveys an operation or function id.
This macro composes two
mach_msg_type_name_tvalues that specify the port rights in themsgh_remote_portandmsgh_local_portfields of amach_msgcall into an appropriatemach_msg_bits_tvalue.
This macro extracts the
mach_msg_type_name_tvalue for the remote port right in amach_msg_bits_tvalue.
This macro extracts the
mach_msg_type_name_tvalue for the local port right in amach_msg_bits_tvalue.
This macro extracts the
mach_msg_bits_tcomponent consisting of themach_msg_type_name_tvalues for the remote and local port right in amach_msg_bits_tvalue.
This macro extracts the
mach_msg_bits_tcomponent consisting of everything except themach_msg_type_name_tvalues for the remote and local port right in amach_msg_bits_tvalue.
Each data item has a type descriptor, a mach_msg_type_t or a
mach_msg_type_long_t. The mach_msg_type_long_t type
descriptor allows larger values for some fields. The
msgtl_header field in the long descriptor is only used for its
inline, longform, and deallocate bits.
This is an
unsigned intand can be used to hold themsgt_namecomponent of themach_msg_type_tandmach_msg_type_long_tstructure.
This is an
unsigned intand can be used to hold themsgt_sizecomponent of themach_msg_type_tandmach_msg_type_long_tstructure.
This is an
natural_tand can be used to hold themsgt_numbercomponent of themach_msg_type_tandmach_msg_type_long_tstructure.
This structure has the following members:
unsigned int msgt_name : 8- The
msgt_namefield specifies the data's type. The following types are predefined:
MACH_MSG_TYPE_UNSTRUCTUREDMACH_MSG_TYPE_BITMACH_MSG_TYPE_BOOLEANMACH_MSG_TYPE_INTEGER_16MACH_MSG_TYPE_INTEGER_32MACH_MSG_TYPE_CHARMACH_MSG_TYPE_BYTEMACH_MSG_TYPE_INTEGER_8MACH_MSG_TYPE_REALMACH_MSG_TYPE_STRINGMACH_MSG_TYPE_STRING_CMACH_MSG_TYPE_PORT_NAMEThe following predefined types specify port rights, and receive special treatment. The next section discusses these types in detail. The type
MACH_MSG_TYPE_PORT_NAMEdescribes port right names, when no rights are being transferred, but just names. For this purpose, it should be used in preference toMACH_MSG_TYPE_INTEGER_32.
MACH_MSG_TYPE_MOVE_RECEIVEMACH_MSG_TYPE_MOVE_SENDMACH_MSG_TYPE_MOVE_SEND_ONCEMACH_MSG_TYPE_COPY_SENDMACH_MSG_TYPE_MAKE_SENDMACH_MSG_TYPE_MAKE_SEND_ONCEmsgt_size : 8- The
msgt_sizefield specifies the size of each datum, in bits. For example, the msgt_size ofMACH_MSG_TYPE_INTEGER_32data is 32.msgt_number : 12- The
msgt_numberfield specifies how many data elements comprise the data item. Zero is a legitimate number.The total length specified by a type descriptor is
(msgt_size * msgt_number), rounded up to an integral number of bytes. In-line data is then padded to an integral number of long-words. This ensures that type descriptors always start on long-word boundaries. It implies that message sizes are always an integral multiple of a long-word's size.msgt_inline : 1- The
msgt_inlinebit specifies, whenFALSE, that the data actually resides in an out-of-line region. The address of the memory region (avm_offset_torvm_address_t) follows the type descriptor in the message body. Themsgt_name,msgt_size, andmsgt_numberfields describe the memory region, not the address.msgt_longform : 1- The
msgt_longformbit specifies, whenTRUE, that this type descriptor is amach_msg_type_long_tinstead of amach_msg_type_t. Themsgt_name,msgt_size, andmsgt_numberfields should be zero. Instead,mach_msguses the followingmsgtl_name,msgtl_size, andmsgtl_numberfields.msgt_deallocate : 1- The
msgt_deallocatebit is used with out-of-line regions. WhenTRUE, it specifies that the memory region should be deallocated from the sender's address space (as if withvm_deallocate) when the message is sent.msgt_unused : 1- The
msgt_unusedbit should be zero.
This macro returns
TRUEif the given type name specifies a port type, otherwise it returnsFALSE.
This macro returns
TRUEif the given type name specifies a port type with a send or send-once right, otherwise it returnsFALSE.