xref: /xnu-10002.61.3/osfmk/man/mach_msg.html (revision 0f4c859e951fba394238ab619495c4e1d54d0f34)
1*0f4c859eSApple OSS Distributions<h2>mach_msg</h2>
2*0f4c859eSApple OSS Distributions<hr>
3*0f4c859eSApple OSS Distributions<p>
4*0f4c859eSApple OSS Distributions<strong>System Trap</strong> / <strong>Function</strong> - Send and/or receive a message from the target port.
5*0f4c859eSApple OSS Distributions<h3>SYNOPSIS</h3>
6*0f4c859eSApple OSS Distributions<pre>
7*0f4c859eSApple OSS Distributions<strong>mach_msg_return_t   mach_msg</strong>
8*0f4c859eSApple OSS Distributions                    <strong>(mach_msg_header_t</strong>                <var>msg</var>,
9*0f4c859eSApple OSS Distributions                     <strong>mach_msg_option_t</strong>             <var>option</var>,
10*0f4c859eSApple OSS Distributions                     <strong>mach_msg_size_t</strong>            <var>send_size</var>,
11*0f4c859eSApple OSS Distributions                     <strong>mach_msg_size_t</strong>        <var>receive_limit</var>,
12*0f4c859eSApple OSS Distributions                     <strong>mach_port_t</strong>             <var>receive_name</var>,
13*0f4c859eSApple OSS Distributions                     <strong>mach_msg_timeout_t</strong>           <var>timeout</var>,
14*0f4c859eSApple OSS Distributions                     <strong>mach_port_t</strong>                   <var>notify</var><strong>);</strong>
15*0f4c859eSApple OSS Distributions
16*0f4c859eSApple OSS Distributions<strong>mach_msg_return_t   mach_msg_overwrite</strong>
17*0f4c859eSApple OSS Distributions                    <strong>(mach_msg_header_t*</strong>          <var>send_msg</var>,
18*0f4c859eSApple OSS Distributions                     <strong>mach_msg_option_t</strong>             <var>option</var>,
19*0f4c859eSApple OSS Distributions                     <strong>mach_msg_size_t</strong>            <var>send_size</var>,
20*0f4c859eSApple OSS Distributions                     <strong>mach_msg_size_t</strong>        <var>receive_limit</var>,
21*0f4c859eSApple OSS Distributions                     <strong>mach_port_t</strong>             <var>receive_name</var>,
22*0f4c859eSApple OSS Distributions                     <strong>mach_msg_timeout_t</strong>           <var>timeout</var>,
23*0f4c859eSApple OSS Distributions                     <strong>mach_port_t</strong>                   <var>notify</var>,
24*0f4c859eSApple OSS Distributions                     <strong>mach_msg_header_t</strong>       <var>*receive_msg</var>,
25*0f4c859eSApple OSS Distributions                     <strong>mach_msg_size_t</strong>     <var>receive_msg_size</var><strong>);</strong>
26*0f4c859eSApple OSS Distributions</pre>
27*0f4c859eSApple OSS Distributions<h3>PARAMETERS</h3>
28*0f4c859eSApple OSS Distributions<dl>
29*0f4c859eSApple OSS Distributions<p>
30*0f4c859eSApple OSS Distributions<dt> <var>msg</var>
31*0f4c859eSApple OSS Distributions<dd>
32*0f4c859eSApple OSS Distributions[pointer to in/out structure containing random and reply rights] A
33*0f4c859eSApple OSS Distributionsmessage buffer used by <strong>mach_msg</strong> both for send and receive. This must
34*0f4c859eSApple OSS Distributionsbe naturally aligned.
35*0f4c859eSApple OSS Distributions<p>
36*0f4c859eSApple OSS Distributions<dt> <var>send_msg</var>
37*0f4c859eSApple OSS Distributions<dd>
38*0f4c859eSApple OSS Distributions[pointer to in structure containing random and reply rights] The mes-
39*0f4c859eSApple OSS Distributionssage buffer to be sent. This must be naturally aligned.
40*0f4c859eSApple OSS Distributions<p>
41*0f4c859eSApple OSS Distributions<dt> <var>option</var>
42*0f4c859eSApple OSS Distributions<dd>
43*0f4c859eSApple OSS Distributions[in scalar] Message options are bit values, combined with bitwise-or.
44*0f4c859eSApple OSS DistributionsOne or both of MACH_SEND_MSG and MACH_RCV_MSG should be used. Other
45*0f4c859eSApple OSS Distributionsoptions act as modifiers.
46*0f4c859eSApple OSS Distributions<p>
47*0f4c859eSApple OSS Distributions<dt> <var>send_size</var>
48*0f4c859eSApple OSS Distributions<dd>
49*0f4c859eSApple OSS Distributions[in scalar] When sending a message, specifies the size of the message
50*0f4c859eSApple OSS Distributionsbuffer to be sent (the size of the header and body) in
51*0f4c859eSApple OSS Distributionsbytes. Otherwise zero should be supplied.
52*0f4c859eSApple OSS Distributions<p>
53*0f4c859eSApple OSS Distributions<dt> <var>receive_limit</var>
54*0f4c859eSApple OSS Distributions<dd>
55*0f4c859eSApple OSS Distributions[in scalar] When receiving a message, specifies the maximum size of
56*0f4c859eSApple OSS Distributionsthe msg or receive_msg buffer in bytes. Otherwise zero should be sup-
57*0f4c859eSApple OSS Distributionsplied.
58*0f4c859eSApple OSS Distributions<p>
59*0f4c859eSApple OSS Distributions<dt> <var>receive_name</var>
60*0f4c859eSApple OSS Distributions<dd>
61*0f4c859eSApple OSS Distributions[in random right] When receiving a message, specifies the port or port
62*0f4c859eSApple OSS Distributionsset. Otherwise MACH_PORT_NULL should be supplied.
63*0f4c859eSApple OSS Distributions<p>
64*0f4c859eSApple OSS Distributions<dt> <var>timeout</var>
65*0f4c859eSApple OSS Distributions<dd>
66*0f4c859eSApple OSS Distributions[in scalar] When using the MACH_SEND_TIMEOUT and MACH_RCV_TIMEOUT
67*0f4c859eSApple OSS Distributionsoptions, specifies the time in milliseconds to wait before giving
68*0f4c859eSApple OSS Distributionsup. Otherwise MACH_MSG_TIMEOUT_NONE should be supplied.
69*0f4c859eSApple OSS Distributions<p>
70*0f4c859eSApple OSS Distributions<dt> <var>notify</var>
71*0f4c859eSApple OSS Distributions<dd>
72*0f4c859eSApple OSS Distributions[in notify receive right] When using the MACH_SEND_CANCEL and
73*0f4c859eSApple OSS DistributionsMACH_RCV_NOTIFY options, specifies the port used for the
74*0f4c859eSApple OSS Distributionsnotification. Otherwise MACH_PORT_NULL should be supplied.
75*0f4c859eSApple OSS Distributions<p>
76*0f4c859eSApple OSS Distributions<dt> <var>receive_msg</var>
77*0f4c859eSApple OSS Distributions<dd>
78*0f4c859eSApple OSS Distributions[pointer to in/out structure] A message buffer into which a message
79*0f4c859eSApple OSS Distributions(header and body) will be received. This must be naturally aligned. By
80*0f4c859eSApple OSS Distributionsdefault (<strong>mach_msg</strong>), any received message will overwrite the send
81*0f4c859eSApple OSS Distributionsmessage buffer. This buffer is in/out only if the MACH_RCV_OVERWRITE
82*0f4c859eSApple OSS Distributionsoption is used; otherwise this buffer is out only.
83*0f4c859eSApple OSS Distributions<p>
84*0f4c859eSApple OSS Distributions<dt> <var>receive_msg_size</var>
85*0f4c859eSApple OSS Distributions<dd>
86*0f4c859eSApple OSS Distributions[in scalar] When using the MACH_RCV_OVERWRITE option, specifies the
87*0f4c859eSApple OSS Distributionssize (in bytes) of the receive "message" that is to be used by
88*0f4c859eSApple OSS Distributions<strong>mach_msg</strong> to indicate the disposition of received out-of-line regions.
89*0f4c859eSApple OSS Distributions</dl>
90*0f4c859eSApple OSS Distributions<h3>DESCRIPTION</h3>
91*0f4c859eSApple OSS Distributions<p>
92*0f4c859eSApple OSS DistributionsThe <strong>mach_msg</strong> system call sends and receives Mach messages. Mach
93*0f4c859eSApple OSS Distributionsmessages contain data, which can include port rights and addresses of
94*0f4c859eSApple OSS Distributionslarge regions of memory. <strong>mach_msg</strong> uses the same buffer for sending and
95*0f4c859eSApple OSS Distributionsreceiving a message; the other calls permit separate send and receive
96*0f4c859eSApple OSS Distributionsbuffers (although they may be specified to be the same).
97*0f4c859eSApple OSS DistributionsIf the option argument contains MACH_SEND_MSG, the call sends a
98*0f4c859eSApple OSS Distributionsmessage.  The <var>send_size</var> argument specifies the size of the message
99*0f4c859eSApple OSS Distributionsbuffer (header and body) to send. The msgh_remote_port field of the
100*0f4c859eSApple OSS Distributionsmessage header specifies the destination of the message.
101*0f4c859eSApple OSS DistributionsIf the option argument contains MACH_RCV_MSG, it receives a
102*0f4c859eSApple OSS Distributionsmessage. The receive_limit argument specifies the size of a buffer
103*0f4c859eSApple OSS Distributionsthat will receive the message; messages that are larger are not
104*0f4c859eSApple OSS Distributionsreceived. The receive_name argument specifies the port or port set
105*0f4c859eSApple OSS Distributionsfrom which to receive.
106*0f4c859eSApple OSS Distributions<p>
107*0f4c859eSApple OSS DistributionsIf the option argument contains both MACH_SEND_MSG and MACH_RCV_MSG,
108*0f4c859eSApple OSS Distributionsthen <strong>mach_msg</strong> does both send and receive operations (in that
109*0f4c859eSApple OSS Distributionsorder). If the send operation encounters an error (any return code
110*0f4c859eSApple OSS Distributionsother than MACH_MSG_SUCCESS), the call returns immediately
111*0f4c859eSApple OSS Distributionswithout attempting the receive operation. Semantically the combined
112*0f4c859eSApple OSS Distributionscall is equivalent to separate send and receive calls, but it saves
113*0f4c859eSApple OSS Distributionsa system call and enables other internal optimizations.
114*0f4c859eSApple OSS Distributions
115*0f4c859eSApple OSS DistributionsIf the option argument specifies neither MACH_SEND_MSG nor
116*0f4c859eSApple OSS DistributionsMACH_RCV_MSG, <strong>mach_msg</strong> does nothing.
117*0f4c859eSApple OSS DistributionsSome options, like MACH_SEND_TIMEOUT and MACH_RCV_TIMEOUT, share a
118*0f4c859eSApple OSS Distributionssupporting argument. If these options are used together, they make
119*0f4c859eSApple OSS Distributionsindependent use of the supporting argument's value.
120*0f4c859eSApple OSS Distributions<h3>NOTES</h3>
121*0f4c859eSApple OSS Distributions<p>
122*0f4c859eSApple OSS DistributionsThe Mach kernel provides message-oriented, capability-based
123*0f4c859eSApple OSS Distributionsinter-process communication. The inter-process communication (IPC)
124*0f4c859eSApple OSS Distributionsprimitives efficiently support many different styles of interaction,
125*0f4c859eSApple OSS Distributionsincluding remote procedure calls, object-oriented distributed
126*0f4c859eSApple OSS Distributionsprogramming, streaming of data, and sending very large amounts of
127*0f4c859eSApple OSS Distributionsdata.
128*0f4c859eSApple OSS Distributions<h4>Major Concepts</h4>
129*0f4c859eSApple OSS Distributions<p>
130*0f4c859eSApple OSS DistributionsThe IPC primitives operate on three abstractions: messages, ports, and
131*0f4c859eSApple OSS Distributionsport sets.  User tasks access all other kernel services and
132*0f4c859eSApple OSS Distributionsabstractions via the IPC primitives.
133*0f4c859eSApple OSS Distributions<p>
134*0f4c859eSApple OSS DistributionsThe message primitives let tasks send and receive messages. Tasks send
135*0f4c859eSApple OSS Distributionsmessages to ports. Messages sent to a port are delivered reliably
136*0f4c859eSApple OSS Distributions(messages may not be lost) and are received in the order in which they
137*0f4c859eSApple OSS Distributionswere sent via send rights by a given sending task (or a given
138*0f4c859eSApple OSS Distributionskernel). (Messages sent to send-once rights are unordered.)
139*0f4c859eSApple OSS Distributions<p>
140*0f4c859eSApple OSS DistributionsMessages
141*0f4c859eSApple OSS Distributionscontain a fixed-size header and a variable-sized message body
142*0f4c859eSApple OSS Distributionscontaining kernel and user data, and a variable-size trailer of kernel
143*0f4c859eSApple OSS Distributionsappended message attributes. The header describes the destination
144*0f4c859eSApple OSS Distributionsand the size of the message (header plus body). The message body
145*0f4c859eSApple OSS Distributionscontains descriptions of additional port rights to be transmitted,
146*0f4c859eSApple OSS Distributionsdescriptions of "out-of-line" memory regions to be sent and a
147*0f4c859eSApple OSS Distributionsvariable amount of user data, which typically includes type conversion
148*0f4c859eSApple OSS Distributionsinformation. The out-of-line memory regions (including out-of-line
149*0f4c859eSApple OSS Distributionsport arrays) are (typically) disjoint from the message body.
150*0f4c859eSApple OSS DistributionsThe IPC implementation makes use of the VM system to efficiently
151*0f4c859eSApple OSS Distributionstransfer large amounts of data. The message can contain the addresses
152*0f4c859eSApple OSS Distributionsof regions of the sender's address space which should be transferred
153*0f4c859eSApple OSS Distributionsas part of the message.
154*0f4c859eSApple OSS Distributions<p>
155*0f4c859eSApple OSS DistributionsWhen a task receives a message containing
156*0f4c859eSApple OSS Distributionssuch out-of-line regions of data, the data can appear in unused
157*0f4c859eSApple OSS Distributionsportions or overwrite an existing portion of the receiver's address
158*0f4c859eSApple OSS Distributionsspace (depending on the requested receive options). Under favorable
159*0f4c859eSApple OSS Distributionscircumstances, the transmission of out-of-line data is optimized so
160*0f4c859eSApple OSS Distributionsthat sender and receiver share the physical pages of data
161*0f4c859eSApple OSS Distributionscopy-on-write, and no actual data copy occurs unless the pages are
162*0f4c859eSApple OSS Distributionswritten. Regions of memory up to 4 gigabytes may be sent in this
163*0f4c859eSApple OSS Distributionsmanner.
164*0f4c859eSApple OSS Distributions<p>
165*0f4c859eSApple OSS DistributionsPorts hold a queue of messages. Tasks operate on a port to send and
166*0f4c859eSApple OSS Distributionsreceive messages by exercising capabilities (rights) for the
167*0f4c859eSApple OSS Distributionsport. Multiple tasks can hold send rights for a port.
168*0f4c859eSApple OSS DistributionsTasks can also
169*0f4c859eSApple OSS Distributionshold send-once rights, which grant the ability to send a single
170*0f4c859eSApple OSS Distributionsmessage. Only one task can hold the receive capability (receive
171*0f4c859eSApple OSS Distributionsright) for a port.
172*0f4c859eSApple OSS Distributions<p>
173*0f4c859eSApple OSS DistributionsPort rights can be transferred between tasks via
174*0f4c859eSApple OSS Distributionsmessages. The sender of a message can specify in the message that the
175*0f4c859eSApple OSS Distributionsmessage contains a port right. If a message contains a receive right
176*0f4c859eSApple OSS Distributionsfor a port, the receive right is removed from the sender of the
177*0f4c859eSApple OSS Distributionsmessage and transferred to the receiver of the
178*0f4c859eSApple OSS Distributionsmessage. While the receive right is in transit, tasks holding send
179*0f4c859eSApple OSS Distributionsrights can still send messages to the port, and they are queued until
180*0f4c859eSApple OSS Distributionsa task acquires the receive right and uses it to receive the messages.
181*0f4c859eSApple OSS Distributions<p>
182*0f4c859eSApple OSS DistributionsTasks can receive messages from ports and port sets. The port set
183*0f4c859eSApple OSS Distributionsabstraction allows a single thread to wait for a message from any of
184*0f4c859eSApple OSS Distributionsseveral ports. Tasks manipulate port sets with a port set name,
185*0f4c859eSApple OSS Distributionswhich is taken from the same name space as are the port rights. The
186*0f4c859eSApple OSS Distributionsport-set name may not be transferred in a message. A port set holds
187*0f4c859eSApple OSS Distributionsreceive rights, and a receive operation on a port set blocks waiting
188*0f4c859eSApple OSS Distributionsfor a message sent to any of the constituent ports. A port may not be-
189*0f4c859eSApple OSS Distributionslong to more than one port set, and if a port is a member of a port
190*0f4c859eSApple OSS Distributionsset, the holder of the receive right can't receive directly from the
191*0f4c859eSApple OSS Distributionsport.
192*0f4c859eSApple OSS Distributions<p>
193*0f4c859eSApple OSS DistributionsPort rights are a secure, location-independent way of naming
194*0f4c859eSApple OSS Distributionsports. The port queue is a protected data structure, only accessible
195*0f4c859eSApple OSS Distributionsvia the kernel's exported message primitives. Rights are also
196*0f4c859eSApple OSS Distributionsprotected by the kernel; there is no way for a malicious user task to
197*0f4c859eSApple OSS Distributionsguess a port's internal name and send a message to a port to which it
198*0f4c859eSApple OSS Distributionsshouldn't have access. Port rights do not carry any location in-
199*0f4c859eSApple OSS Distributionsformation. When a receive right for a port moves from task to task,
200*0f4c859eSApple OSS Distributionsand even between tasks on different machines, the send rights for
201*0f4c859eSApple OSS Distributionsthe port remain unchanged and continue to function.
202*0f4c859eSApple OSS Distributions<h4>Port Rights</h4>
203*0f4c859eSApple OSS Distributions<p>
204*0f4c859eSApple OSS DistributionsEach task has its own space of port rights. Port rights are named with
205*0f4c859eSApple OSS Distributionspositive (unsigned) integers. For all architectures, sizeof
206*0f4c859eSApple OSS Distributions(mach_port_t) = sizeof (mach_port_name_t) = sizeof (void*) and so user
207*0f4c859eSApple OSS Distributionsspace addresses may be used as port names, except for the reserved
208*0f4c859eSApple OSS Distributionsvalues MACH_PORT_NULL (0) and MACH_PORT_DEAD (all 1 bits). When the
209*0f4c859eSApple OSS Distributionskernel chooses a name for a new right, however, it is free to pick any
210*0f4c859eSApple OSS Distributionsunused name (one which denotes no right) in the space.
211*0f4c859eSApple OSS Distributions<p>
212*0f4c859eSApple OSS DistributionsThere are three basic kinds of rights: receive rights, send rights and
213*0f4c859eSApple OSS Distributionssend-once rights. A port name can name any of these types of rights,
214*0f4c859eSApple OSS Distributionsor name a port-set, be a dead name, or name nothing. Dead names are
215*0f4c859eSApple OSS Distributionsnot capabilities. They act as place-holders to prevent a name from
216*0f4c859eSApple OSS Distributionsbeing otherwise used.
217*0f4c859eSApple OSS Distributions<p>
218*0f4c859eSApple OSS DistributionsA port is destroyed, or dies, when its receive right is
219*0f4c859eSApple OSS Distributionsde-allocated. When a port dies, send and send-once rights for the port
220*0f4c859eSApple OSS Distributionsturn into dead names. Any messages queued at the port are destroyed,
221*0f4c859eSApple OSS Distributionswhich de-allocates the port rights and out-of-line memory in the
222*0f4c859eSApple OSS Distributionsmessages.
223*0f4c859eSApple OSS Distributions<p>
224*0f4c859eSApple OSS DistributionsEach send-once right held by a task has a different name. In contrast,
225*0f4c859eSApple OSS Distributionswhen a task holds send rights or a receive right for a port, the
226*0f4c859eSApple OSS Distributionsrights share a single name.
227*0f4c859eSApple OSS Distributions<p>
228*0f4c859eSApple OSS DistributionsTasks may hold multiple user-references for send rights. When a task
229*0f4c859eSApple OSS Distributionsreceives a send right which it already holds, the kernel increments
230*0f4c859eSApple OSS Distributionsthe right's user-reference count. When a task de-allocates a send
231*0f4c859eSApple OSS Distributionsright, the kernel decrements its user-reference count, and the task
232*0f4c859eSApple OSS Distributionsonly loses the send right when the count goes to zero.
233*0f4c859eSApple OSS Distributions<p>
234*0f4c859eSApple OSS DistributionsSend-once rights always have a user reference count of one. Tasks may
235*0f4c859eSApple OSS Distributionshold multiple user references for dead names.
236*0f4c859eSApple OSS DistributionsEach send-once right generated guarantees the receipt of a single
237*0f4c859eSApple OSS Distributionsmessage, either a message sent to that send-once right or, if the
238*0f4c859eSApple OSS Distributionssend-once right is in any way destroyed, a send-once notification.
239*0f4c859eSApple OSS Distributions<p>
240*0f4c859eSApple OSS DistributionsA message can carry port rights; the msgh_remote or msgh_local fields
241*0f4c859eSApple OSS Distributionsin the message header or the disposition field in a message body
242*0f4c859eSApple OSS Distributionsdescriptor specify the type of port right and how the port right is to
243*0f4c859eSApple OSS Distributionsbe extracted from the caller. The values MACH_PORT_NULL and
244*0f4c859eSApple OSS DistributionsMACH_PORT_DEAD are valid in place of a port right in a message body.
245*0f4c859eSApple OSS Distributions<p>
246*0f4c859eSApple OSS DistributionsIn a sent message, the following mach_msg_type_name_t values denote
247*0f4c859eSApple OSS Distributionsport rights:
248*0f4c859eSApple OSS Distributions<dl>
249*0f4c859eSApple OSS Distributions<dt> MACH_MSG_TYPE_MAKE_SEND
250*0f4c859eSApple OSS Distributions     <dd>
251*0f4c859eSApple OSS DistributionsThe message will carry a send right, but the caller must supply a
252*0f4c859eSApple OSS Distributionsreceive right. The send right is created from the receive right, and the
253*0f4c859eSApple OSS Distributionsreceive right's make-send count is incremented.
254*0f4c859eSApple OSS Distributions<dt> MACH_MSG_TYPE_COPY_SEND
255*0f4c859eSApple OSS Distributions     <dd>
256*0f4c859eSApple OSS DistributionsThe message will carry a send right, and the caller must supply a send
257*0f4c859eSApple OSS Distributionsright. The user reference count for the supplied send right is not
258*0f4c859eSApple OSS Distributionschanged. The caller may also supply a dead name and the receiving
259*0f4c859eSApple OSS Distributionstask will get MACH_PORT_DEAD.
260*0f4c859eSApple OSS Distributions<dt> MACH_MSG_TYPE_MOVE_SEND
261*0f4c859eSApple OSS Distributions     <dd>
262*0f4c859eSApple OSS DistributionsThe message will carry a send right, and the caller must supply a send
263*0f4c859eSApple OSS Distributionsright. The user reference count for the supplied send right is
264*0f4c859eSApple OSS Distributionsdecremented, and the right is destroyed if the count becomes
265*0f4c859eSApple OSS Distributionszero. Unless a receive right remains, the name becomes available for
266*0f4c859eSApple OSS Distributionsrecycling. The caller may also supply a dead name, which loses a user
267*0f4c859eSApple OSS Distributionsreference, and the receiving task will get MACH_PORT_DEAD.
268*0f4c859eSApple OSS Distributions<dt> MACH_MSG_TYPE_MAKE_SEND_ONCE
269*0f4c859eSApple OSS Distributions<dd>
270*0f4c859eSApple OSS DistributionsThe message will carry a send-once right, but the caller must supply a
271*0f4c859eSApple OSS Distributionsreceive right. The send-once right is created from the receive right.
272*0f4c859eSApple OSS DistributionsNote that send once rights can only be created from the receive right.
273*0f4c859eSApple OSS Distributions<dt> MACH_MSG_TYPE_MOVE_SEND_ONCE
274*0f4c859eSApple OSS Distributions     <dd>
275*0f4c859eSApple OSS DistributionsThe message will carry a send-once right, and the caller must supply a
276*0f4c859eSApple OSS Distributionssend-once right. The caller loses the supplied send-once right. The
277*0f4c859eSApple OSS Distributionscaller may also supply a dead name, which loses a user reference,
278*0f4c859eSApple OSS Distributionsand the receiving task will get MACH_PORT_DEAD.
279*0f4c859eSApple OSS Distributions<dt> MACH_MSG_TYPE_MOVE_RECEIVE
280*0f4c859eSApple OSS Distributions     <dd>
281*0f4c859eSApple OSS DistributionsThe message will carry a receive right, and the caller must supply a
282*0f4c859eSApple OSS Distributionsreceive right. The caller loses the supplied receive right, but
283*0f4c859eSApple OSS Distributionsretains any send rights with the same name. The make-send count and
284*0f4c859eSApple OSS Distributionssequence number of the receive right are reset to zero and
285*0f4c859eSApple OSS Distributionsno-more-senders notification requests are cancelled (with a
286*0f4c859eSApple OSS Distributionssend-once notification being sent to the no-more-senders notification
287*0f4c859eSApple OSS Distributionsright), but the port retains other attributes like queued messages
288*0f4c859eSApple OSS Distributionsand extant send and send-once rights.
289*0f4c859eSApple OSS DistributionsIf a message carries a send or send-once right, and the port dies
290*0f4c859eSApple OSS Distributionswhile the message is in transit, then the receiving task will get
291*0f4c859eSApple OSS DistributionsMACH_PORT_DEAD instead of a right.
292*0f4c859eSApple OSS Distributions	  </dl>
293*0f4c859eSApple OSS Distributions	  <p>
294*0f4c859eSApple OSS DistributionsThe following mach_msg_type_name_t values in a received message
295*0f4c859eSApple OSS Distributionsindicate that it carries port rights:
296*0f4c859eSApple OSS Distributions	  <dl>
297*0f4c859eSApple OSS Distributions<dt> MACH_MSG_TYPE_PORT_SEND
298*0f4c859eSApple OSS Distributions     <dd>
299*0f4c859eSApple OSS DistributionsThis value is an alias for MACH_MSG_TYPE_MOVE_SEND. The
300*0f4c859eSApple OSS Distributionsmessage carried a send right. If the receiving task already has send and/
301*0f4c859eSApple OSS Distributionsor receive rights for the port, then that name for the port will be reused.
302*0f4c859eSApple OSS DistributionsOtherwise, the right will have a new, previously unused, name. If the
303*0f4c859eSApple OSS Distributionstask already has send rights, it gains a user reference for the right (un-
304*0f4c859eSApple OSS Distributionsless this would cause the user-reference count to overflow). Otherwise,
305*0f4c859eSApple OSS Distributionsit acquires send rights, with a user-reference count of one.
306*0f4c859eSApple OSS Distributions<dt> MACH_MSG_TYPE_PORT_SEND_ONCE
307*0f4c859eSApple OSS Distributions     <dd>
308*0f4c859eSApple OSS DistributionsThis value is an alias for MACH_MSG_TYPE_MOVE_SEND_ONCE. The message
309*0f4c859eSApple OSS Distributionscarried a send-once right. The right will have a new, previously
310*0f4c859eSApple OSS Distributionsunused, name.
311*0f4c859eSApple OSS Distributions<dt> MACH_MSG_TYPE_PORT_RECEIVE
312*0f4c859eSApple OSS Distributions     <dd>
313*0f4c859eSApple OSS DistributionsThis value is an alias for MACH_MSG_TYPE_MOVE_RECEIVE.  The message
314*0f4c859eSApple OSS Distributionscarried a receive right. If the receiving task already has send rights
315*0f4c859eSApple OSS Distributionsfor the port, then that name for the port will be reused; otherwise,
316*0f4c859eSApple OSS Distributionsthe right will have a new, previously unused name.
317*0f4c859eSApple OSS Distributions	  </dl>
318*0f4c859eSApple OSS Distributions	  <p>
319*0f4c859eSApple OSS DistributionsIt is also possible to send a (nearly unbounded) array of port rights
320*0f4c859eSApple OSS Distributions"out-of-line". All of the rights named by the array must be of the
321*0f4c859eSApple OSS Distributionssame type. The array is physically copied with the message body
322*0f4c859eSApple OSS Distributionsproper. The array of port right (names) can be received by the
323*0f4c859eSApple OSS Distributionsreceiver using the same options available for out-of-line data
324*0f4c859eSApple OSS Distributionsreception described below.
325*0f4c859eSApple OSS Distributions<h4>Memory</h4>
326*0f4c859eSApple OSS Distributions	  <p>
327*0f4c859eSApple OSS DistributionsA message can contain one or more regions of the sender's address
328*0f4c859eSApple OSS Distributionsspace which are to be transferred as part of the message. The message
329*0f4c859eSApple OSS Distributionscarries a logical copy of the memory. For this "out-of-line" memory,
330*0f4c859eSApple OSS Distributionsthe kernel can copy the data or use virtual memory techniques to defer
331*0f4c859eSApple OSS Distributionsany actual page copies unless the sender or the receiver modifies
332*0f4c859eSApple OSS Distributionsthe data, the physical pages remain shared.
333*0f4c859eSApple OSS Distributions<p>
334*0f4c859eSApple OSS Distributions	  The sender of the message must explicitly request an out-of-line
335*0f4c859eSApple OSS Distributionstransfer. Such a region is described as an arbitrary region of the
336*0f4c859eSApple OSS Distributionssender's address space. The sender always sees this memory as being
337*0f4c859eSApple OSS Distributionscopied to the receiver.
338*0f4c859eSApple OSS Distributions<p>
339*0f4c859eSApple OSS Distributions	  For each region, the sender has a de-allocate option. If the option is
340*0f4c859eSApple OSS Distributionsset and the out-of-line memory region is not null, then the region is
341*0f4c859eSApple OSS Distributionsimplicitly de-allocated from the sender, as if by vm_deallocate. In
342*0f4c859eSApple OSS Distributionsparticular, the start address is truncated down and the end address
343*0f4c859eSApple OSS Distributionsrounded up so that every page overlapped by the memory region is
344*0f4c859eSApple OSS Distributionsde-allocated (thereby possibly de-allocating more memory than is
345*0f4c859eSApple OSS Distributionseffectively transmitted). The use of this option effectively changes
346*0f4c859eSApple OSS Distributionsthe memory copy to a memory movement. Aside from possibly optimizing
347*0f4c859eSApple OSS Distributionsthe sender's use of memory, the de-allocation option allows the kernel
348*0f4c859eSApple OSS Distributionsto more efficiently handle the transfer of memory.
349*0f4c859eSApple OSS Distributions	  <p>
350*0f4c859eSApple OSS DistributionsFor each region, the sender has the choice of permitting the kernel to
351*0f4c859eSApple OSS Distributionschoose a transmission strategy or the choice of requiring physical
352*0f4c859eSApple OSS Distributionscopy:
353*0f4c859eSApple OSS Distributions	  <dl>
354*0f4c859eSApple OSS Distributions<dt> MACH_MSG_VIRTUAL_COPY
355*0f4c859eSApple OSS Distributions     <dd>
356*0f4c859eSApple OSS DistributionsIn a sent message, this flag allows the kernel to choose any mechanism
357*0f4c859eSApple OSS Distributionsto transmit the data. For large regions, this involves constructing a
358*0f4c859eSApple OSS Distributionsvirtual copy of the pages containing the region. The portion of the
359*0f4c859eSApple OSS Distributionsfirst page preceding the data and the portion of the last page
360*0f4c859eSApple OSS Distributionsfollowing the data are not copied (and will appear as zero if the
361*0f4c859eSApple OSS Distributionsvirtual copy is dynamically allocated in the receiver).
362*0f4c859eSApple OSS Distributions	  <p>
363*0f4c859eSApple OSS DistributionsIn a received message, this flag indicates that the kernel transmitted
364*0f4c859eSApple OSS Distributionsa virtual copy. Access to the received memory may involve interactions
365*0f4c859eSApple OSS Distributionswith the memory manager managing the sender's original data. Integri-
366*0f4c859eSApple OSS Distributionsty-conscious receivers should exercise caution when dealing with out-
367*0f4c859eSApple OSS Distributionsof-line memory from un-trustworthy sources. Receivers concerned about
368*0f4c859eSApple OSS Distributionsdeterministic access time should also exercise caution. The dynamic
369*0f4c859eSApple OSS Distributionsallocation option guarantees that the virtual copy will not be di-
370*0f4c859eSApple OSS Distributionsrectly referenced during the act of receiving the message.
371*0f4c859eSApple OSS Distributions<dt> MACH_MSG_PHYSICAL_COPY
372*0f4c859eSApple OSS Distributions     <dd>
373*0f4c859eSApple OSS DistributionsIn a sent message, this flag requires that the kernel construct an
374*0f4c859eSApple OSS Distributionsactual copy of the memory (either into wired kernel memory or default
375*0f4c859eSApple OSS Distributionsmemory managed space). There is a (fairly large) limit on the amount
376*0f4c859eSApple OSS Distributionsof data that can be physically copied in a message. Port arrays always
377*0f4c859eSApple OSS Distributionsassume this option when sent.
378*0f4c859eSApple OSS Distributions	  <p>
379*0f4c859eSApple OSS DistributionsIn a received message, this flag indicates that the kernel did
380*0f4c859eSApple OSS Distributionstransmit a physical copy.
381*0f4c859eSApple OSS Distributions	  </dl>
382*0f4c859eSApple OSS Distributions	  <p>
383*0f4c859eSApple OSS DistributionsThe receiver has two options for the reception of out-of-line memory
384*0f4c859eSApple OSS Distributions(or "out-of-line" port arrays): allocation and overwrite.
385*0f4c859eSApple OSS DistributionsIn the absence of the MACH_RCV_OVERWRITE option, all out-of-line re-
386*0f4c859eSApple OSS Distributionsgions are dynamically allocated. Allocated out-of-line memory arrives
387*0f4c859eSApple OSS Distributionssomewhere in the receiver's address space as new memory. It has the
388*0f4c859eSApple OSS Distributionssame inheritance and protection attributes as newly vm_allocate'ed
389*0f4c859eSApple OSS Distributionsmemory. The receiver has the responsibility of de-allocating (with
390*0f4c859eSApple OSS Distributionsvm_deallocate) the memory when it is no longer needed. If the message
391*0f4c859eSApple OSS Distributionscontains more than one region, each will be allocated its own region,
392*0f4c859eSApple OSS Distributionsnot necessarily contiguously. If the sender's data was transmitted as
393*0f4c859eSApple OSS Distributionsa virtual copy the allocated region will have the same data alignment
394*0f4c859eSApple OSS Distributionswithin the page; otherwise, the received data will appear starting at
395*0f4c859eSApple OSS Distributionsthe beginning of a page.
396*0f4c859eSApple OSS Distributions	  <p>
397*0f4c859eSApple OSS DistributionsIf the MACH_RCV_OVERWRITE option is set, the receiver can specify how
398*0f4c859eSApple OSS Distributionseach received region is to be processed (dynamically allocated as
399*0f4c859eSApple OSS Distributionsdescribed above, or written over existing memory). With this option,
400*0f4c859eSApple OSS Distributionsthe contents of the receive buffer (receive_msg) are examined by the
401*0f4c859eSApple OSS Distributionskernel. The kernel scans the descriptors in the receive buffer
402*0f4c859eSApple OSS Distributions"message" to determine how to handle each out-of-line region. (Note:
403*0f4c859eSApple OSS Distributionswhereas receive_limit is the maximum size of the receive buffer,
404*0f4c859eSApple OSS Distributionsreceive_msg_size is the amount filled in with this "message".) The
405*0f4c859eSApple OSS Distributionskernel uses each out-of-line data descriptor (in order) to specify
406*0f4c859eSApple OSS Distributionsthe processing for each received data region in turn, each out-of-line
407*0f4c859eSApple OSS Distributionsport array descriptor is used correspondingly. (Intermingled port
408*0f4c859eSApple OSS Distributionsdescriptors are ignored when matching descriptors between the
409*0f4c859eSApple OSS Distributionsincoming message and the receive buffer list.)
410*0f4c859eSApple OSS Distributions<p>
411*0f4c859eSApple OSS DistributionsThe copy option in the
412*0f4c859eSApple OSS Distributionsmatching descriptor specifies the processing:
413*0f4c859eSApple OSS Distributions	  <dl>
414*0f4c859eSApple OSS Distributions<dt> MACH_MSG_OVERWRITE
415*0f4c859eSApple OSS Distributions     <dd>
416*0f4c859eSApple OSS DistributionsThis flag indicates that the region should write over a specified
417*0f4c859eSApple OSS Distributionsregion of the receiver's address space, as indicated by the address
418*0f4c859eSApple OSS Distributionsand size/ count fields of the descriptor. The full range overwritten
419*0f4c859eSApple OSS Distributionsmust already exist (be allocated or mapped) in the receiver's address
420*0f4c859eSApple OSS Distributionsspace. Depending on the nature of the data transmission this
421*0f4c859eSApple OSS Distributionsoverwrite may involve virtual memory manipulations or it may involve
422*0f4c859eSApple OSS Distributionsactual data copy.
423*0f4c859eSApple OSS Distributions<dt> MACH_MSG_ALLOCATE
424*0f4c859eSApple OSS Distributions     <dd>
425*0f4c859eSApple OSS DistributionsThis flag indicates that the region is to be dynamically allocated. No
426*0f4c859eSApple OSS Distributionsother descriptor values are relevant.
427*0f4c859eSApple OSS Distributions	  </dl>
428*0f4c859eSApple OSS Distributions	  <p>
429*0f4c859eSApple OSS DistributionsIf not enough descriptors appear in the receive buffer to describe all
430*0f4c859eSApple OSS Distributionsreceived regions, additional regions are dynamically allocated. If
431*0f4c859eSApple OSS Distributionsthe receiver specifies more descriptors than there are regions in the
432*0f4c859eSApple OSS Distributionsreceived message, the additional descriptors are ignored (and do not
433*0f4c859eSApple OSS Distributionsappear in the final received message).
434*0f4c859eSApple OSS Distributions	  <p>
435*0f4c859eSApple OSS DistributionsNote that the receive buffer descriptors will be overwritten:
436*0f4c859eSApple OSS DistributionsThe size fields in descriptors will be updated (when scanned, they
437*0f4c859eSApple OSS Distributionsspecified the maximum sizes of regions, when received, they specify
438*0f4c859eSApple OSS Distributionsthe actual sizes of received regions).
439*0f4c859eSApple OSS DistributionsThe copy fields in descriptors will be updated (when scanned, they
440*0f4c859eSApple OSS Distributionsspecified allocate versus overwrite, when received, they indicate
441*0f4c859eSApple OSS Distributionswhether the region was physically or virtually copied).
442*0f4c859eSApple OSS DistributionsThe descriptors may appear in different positions (given intermingled
443*0f4c859eSApple OSS Distributionsport descriptors).
444*0f4c859eSApple OSS DistributionsDescriptors that were not used (because there were not that many
445*0f4c859eSApple OSS Distributionsreceived regions) will be discarded.
446*0f4c859eSApple OSS Distributions	  <p>
447*0f4c859eSApple OSS DistributionsNull out-of-line memory is legal. If the out-of-line region size is
448*0f4c859eSApple OSS Distributionszero, then the region's specified address is ignored. A receive
449*0f4c859eSApple OSS Distributionsallocated null out-of-line memory region always has a zero address.
450*0f4c859eSApple OSS DistributionsUnaligned addresses and region sizes that are not page multiples are
451*0f4c859eSApple OSS Distributionslegal. A received message can also contain regions with unaligned
452*0f4c859eSApple OSS Distributionsaddresses and sizes which are not multiples of the page size.
453*0f4c859eSApple OSS Distributions<h4>Message Send</h4>
454*0f4c859eSApple OSS Distributions	  <p>
455*0f4c859eSApple OSS DistributionsThe send operation queues a message to a port. The message carries a
456*0f4c859eSApple OSS Distributionscopy of the caller's data. After the send, the caller can freely
457*0f4c859eSApple OSS Distributionsmodify the message buffer or the out-of-line memory regions and the
458*0f4c859eSApple OSS Distributionsmessage contents will remain unchanged.
459*0f4c859eSApple OSS Distributions	  	  <p>
460*0f4c859eSApple OSS DistributionsThe message carries with it the security ID of the sender, which the
461*0f4c859eSApple OSS Distributionsreceiver can request in the message trailer.
462*0f4c859eSApple OSS Distributions	  	  <p>
463*0f4c859eSApple OSS DistributionsMessage delivery is reliable and sequenced. Reception of a message
464*0f4c859eSApple OSS Distributionsguarantees that all messages previously sent to the port by a single
465*0f4c859eSApple OSS Distributionstask (or a single kernel) via send rights have been received and that
466*0f4c859eSApple OSS Distributionsthey are received in the order in which they were sent. Messages sent
467*0f4c859eSApple OSS Distributionsto send-once rights are unordered.
468*0f4c859eSApple OSS Distributions	  <p>
469*0f4c859eSApple OSS DistributionsIf the destination port's queue is full, several things can happen. If
470*0f4c859eSApple OSS Distributionsthe message is sent to a send-once right (msgh_remote_port carries a
471*0f4c859eSApple OSS Distributionssend-once right), then the kernel ignores the queue limit and delivers
472*0f4c859eSApple OSS Distributionsthe message. Otherwise the caller blocks until there is room in the
473*0f4c859eSApple OSS Distributionsqueue, unless the MACH_SEND_TIMEOUT option is used. If a port has
474*0f4c859eSApple OSS Distributionsseveral blocked senders, then any of them may queue the next message
475*0f4c859eSApple OSS Distributionswhen space in the queue becomes available, with the proviso that a
476*0f4c859eSApple OSS Distributionsblocked sender will not be indefinitely starved.
477*0f4c859eSApple OSS DistributionsThese options modify MACH_SEND_MSG. If MACH_SEND_MSG is not also
478*0f4c859eSApple OSS Distributionsspecified, they are ignored.
479*0f4c859eSApple OSS Distributions<dl>
480*0f4c859eSApple OSS Distributions<dt> MACH_SEND_TIMEOUT
481*0f4c859eSApple OSS Distributions     <dd>
482*0f4c859eSApple OSS DistributionsThe timeout argument should specify a maximum time (in milliseconds)
483*0f4c859eSApple OSS Distributionsfor the call to block before giving up. If the message can't be queued
484*0f4c859eSApple OSS Distributionsbefore the timeout interval elapses, then the call returns
485*0f4c859eSApple OSS DistributionsMACH_SEND_TIMED_OUT. A zero timeout is legitimate.
486*0f4c859eSApple OSS Distributions<dt> MACH_SEND_INTERRUPT
487*0f4c859eSApple OSS Distributions     <dd>
488*0f4c859eSApple OSS DistributionsIf specified, the <strong>mach_msg</strong> call will return
489*0f4c859eSApple OSS DistributionsMACH_SEND_INTERRUPTED if a software interrupt aborts the call.
490*0f4c859eSApple OSS DistributionsOtherwise, the send operation will be retried.
491*0f4c859eSApple OSS Distributions<dt> MACH_SEND_TRAILER
492*0f4c859eSApple OSS Distributions     <dd>
493*0f4c859eSApple OSS DistributionsIf set, the kernel, instead of determining the message attributes
494*0f4c859eSApple OSS Distributionsitself, will accept a formatted message trailer from the sender. The
495*0f4c859eSApple OSS Distributionssupplied trailer must be of the latest version supported by the
496*0f4c859eSApple OSS Distributionskernel, and must contain all message attributes defined by the
497*0f4c859eSApple OSS Distributionskernel. Only tasks with a security ID of KERNEL_SECURITY_ID can use
498*0f4c859eSApple OSS Distributionsthis option; the intended use of this option is in support of the
499*0f4c859eSApple OSS DistributionsNet Message server. The trailer must follow the message in memory as
500*0f4c859eSApple OSS Distributionsit would appear in a received message. (The send_size argument to
501*0f4c859eSApple OSS Distributions<strong>mach_msg</strong> still indicates the size of the message proper, not including
502*0f4c859eSApple OSS Distributionsthis trailer.)
503*0f4c859eSApple OSS Distributions	  </dl>
504*0f4c859eSApple OSS Distributions	  <p>
505*0f4c859eSApple OSS DistributionsThe queueing of a message carrying receive rights may create a
506*0f4c859eSApple OSS Distributionscircular loop of receive rights and messages, which can never be
507*0f4c859eSApple OSS Distributionsreceived. For example, a message carrying a receive right can be
508*0f4c859eSApple OSS Distributionssent to that receive right. This situation is not an error, but the
509*0f4c859eSApple OSS Distributionskernel will garbage-collect such loops, destroying the messages.
510*0f4c859eSApple OSS DistributionsSome return codes, like MACH_SEND_TIMED_OUT, imply that the message
511*0f4c859eSApple OSS Distributionswas almost sent, but could not be queued. In these situations, the
512*0f4c859eSApple OSS Distributionskernel tries to return the message contents to the caller with a
513*0f4c859eSApple OSS Distributionspseudo-receive operation. This prevents the loss of port rights or
514*0f4c859eSApple OSS Distributionsmemory which only exist in the message, for example, a receive right
515*0f4c859eSApple OSS Distributionswhich was moved into the message, or out-of-line memory sent with
516*0f4c859eSApple OSS Distributionsthe de-allocate option.
517*0f4c859eSApple OSS Distributions	  <p>
518*0f4c859eSApple OSS DistributionsThe intent of the pseudo-receive operation is to restore, as best as
519*0f4c859eSApple OSS Distributionspossible, the state prior to attempting the send. This involves
520*0f4c859eSApple OSS Distributionsrestoring the port rights and out-of-line memory regions contained in
521*0f4c859eSApple OSS Distributionsthe message. The port right names and out-of-line addresses in the
522*0f4c859eSApple OSS Distributionsmessage send buffer are updated to reflect the new values resulting
523*0f4c859eSApple OSS Distributionsfrom their effective reception. The pseudo-receive handles the des-
524*0f4c859eSApple OSS Distributionstination and reply rights as any other rights; they are not reversed
525*0f4c859eSApple OSS Distributionsas is the appearance in a normal received message. Also, no trailer is
526*0f4c859eSApple OSS Distributionsappended to the message. After the pseudo-receive, the message is
527*0f4c859eSApple OSS Distributionsready to be resent. If the message is not resent, note that
528*0f4c859eSApple OSS Distributionsout-of-line memory regions may have moved and some port rights may
529*0f4c859eSApple OSS Distributionshave changed names.
530*0f4c859eSApple OSS Distributions	  <p>
531*0f4c859eSApple OSS DistributionsAlthough unlikely, the pseudo-receive operation may encounter resource
532*0f4c859eSApple OSS Distributionsshortages. This is similar to a MACH_RCV_BODY_ERROR return code from
533*0f4c859eSApple OSS Distributionsa receive operation. When this happens, the normal send return codes
534*0f4c859eSApple OSS Distributionsare augmented with the MACH_MSG_IPC_SPACE, MACH_MSG_VM_SPACE,
535*0f4c859eSApple OSS DistributionsMACH_MSG_IPC_KERNEL and MACH_MSG_VM_KERNEL bits to indicate the
536*0f4c859eSApple OSS Distributionsnature of the resource shortage.
537*0f4c859eSApple OSS Distributions<h4>Message Receive</h4>
538*0f4c859eSApple OSS Distributions	  <p>
539*0f4c859eSApple OSS DistributionsThe receive operation de-queues a message from a port. The receiving
540*0f4c859eSApple OSS Distributionstask acquires the port rights and out-of-line memory regions carried
541*0f4c859eSApple OSS Distributionsin the message.
542*0f4c859eSApple OSS DistributionsThe receive_name argument specifies a port or port set from which to
543*0f4c859eSApple OSS Distributionsreceive. If a port is specified, the caller must possess the receive
544*0f4c859eSApple OSS Distributionsright for the port and the port must not be a member of a port set. If
545*0f4c859eSApple OSS Distributionsno message is present, the call blocks, subject to the
546*0f4c859eSApple OSS DistributionsMACH_RCV_TIMEOUT option.
547*0f4c859eSApple OSS Distributions<p>
548*0f4c859eSApple OSS DistributionsIf a port set is specified, the call will receive a message sent to
549*0f4c859eSApple OSS Distributionsany of the member ports. It is permissible for the port set to have
550*0f4c859eSApple OSS Distributionsno member ports, and ports may be added and removed while a receive
551*0f4c859eSApple OSS Distributionsfrom the port set is in progress. The received message can come from
552*0f4c859eSApple OSS Distributionsany of the member ports which have messages, with the proviso that a
553*0f4c859eSApple OSS Distributionsmember port with messages will not be indefinitely starved. The
554*0f4c859eSApple OSS Distributionsmsgh_local_port field in the received message header specifies from
555*0f4c859eSApple OSS Distributionswhich port in the port set the message came.
556*0f4c859eSApple OSS Distributions<p>
557*0f4c859eSApple OSS DistributionsThe receive_limit argument specifies the size of the caller's message
558*0f4c859eSApple OSS Distributionsbuffer (which must be big enough for the message header, body and
559*0f4c859eSApple OSS Distributionstrailer); the msgh_size field of the received message indicates the
560*0f4c859eSApple OSS Distributionsactual size of the received message header and body. The <strong>mach_msg</strong> call
561*0f4c859eSApple OSS Distributionswill not receive a message larger than receive_limit. Messages that
562*0f4c859eSApple OSS Distributionsare too large are destroyed, unless the MACH_RCV_LARGE option is used.
563*0f4c859eSApple OSS DistributionsFollowing the received data, at the next natural boundary, is a
564*0f4c859eSApple OSS Distributionsmessage trailer.  The msgh_size field of the received message does not
565*0f4c859eSApple OSS Distributionsinclude the length of this trailer; the trailer's length is given by
566*0f4c859eSApple OSS Distributionsthe msgh_trailer_size field within the trailer. The receiver of a
567*0f4c859eSApple OSS Distributionsmessage is given a choice as to what trailer format is desired, and,
568*0f4c859eSApple OSS Distributionswithin that format, which of the leading trailer attributes are
569*0f4c859eSApple OSS Distributionsdesired (that is, to get trailer element three, the receiver must also
570*0f4c859eSApple OSS Distributionsaccept elements one and two). For any given trailer format (of which
571*0f4c859eSApple OSS Distributionsthere is currently only one), the trailer is compatibly extended by
572*0f4c859eSApple OSS Distributionsadding additional elements to the end.
573*0f4c859eSApple OSS Distributions<p>
574*0f4c859eSApple OSS DistributionsReceived messages are stamped (in the trailer) with a sequence number,
575*0f4c859eSApple OSS Distributionstaken from the port from which the message was received. (Messages
576*0f4c859eSApple OSS Distributionsreceived from a port set are stamped with a sequence number from the
577*0f4c859eSApple OSS Distributionsappropriate member port.) Newly created ports start with a zero
578*0f4c859eSApple OSS Distributionssequence number, and the sequence number is reset to zero whenever the
579*0f4c859eSApple OSS Distributionsport's receive right moves between tasks.  When a message is de-queued
580*0f4c859eSApple OSS Distributionsfrom the port, it is stamped with the port's sequence number and the
581*0f4c859eSApple OSS Distributionsport's sequence number is then incremented. (Note that this occurs
582*0f4c859eSApple OSS Distributionswhether or not the receiver requests the sequence number in the trail-
583*0f4c859eSApple OSS Distributionser.) The de-queue and increment operations are atomic, so that
584*0f4c859eSApple OSS Distributionsmultiple threads receiving messages from a port can use the msgh_seqno
585*0f4c859eSApple OSS Distributionsfield to reconstruct the original order of the messages.
586*0f4c859eSApple OSS Distributions<p>
587*0f4c859eSApple OSS DistributionsThe destination and reply ports are reversed in a received message
588*0f4c859eSApple OSS Distributionsheader. The msgh_local_port field carries the name of the destination
589*0f4c859eSApple OSS Distributionsport, from which the message was received, and the msgh_remote_port
590*0f4c859eSApple OSS Distributionsfield carries the reply port right. The bits in msgh_bits are also
591*0f4c859eSApple OSS Distributionsreversed. The MACH_MSGH_BITS_LOCAL bits have a value of
592*0f4c859eSApple OSS DistributionsMACH_MSG_TYPE_PORT_SEND_ONCE or MACH_MSG_TYPE_PORT_SEND depending on
593*0f4c859eSApple OSS Distributionsthe type of right to which the message was sent. The
594*0f4c859eSApple OSS DistributionsMACH_MSGH_BITS_REMOTE bits describe the reply port right.
595*0f4c859eSApple OSS Distributions<p>
596*0f4c859eSApple OSS DistributionsA received message can contain port rights and out-of-line memory. The
597*0f4c859eSApple OSS Distributionsmsgh_local_port field does not carry a port right; the act of
598*0f4c859eSApple OSS Distributionsreceiving the message consumes the send or send-once right for the
599*0f4c859eSApple OSS Distributionsdestination port. The msgh_remote_port field does carry a port right,
600*0f4c859eSApple OSS Distributionsand the message can carry additional port rights and memory if the
601*0f4c859eSApple OSS DistributionsMACH_MSGH_BITS_COMPLEX bit is set. Received port rights and memory
602*0f4c859eSApple OSS Distributionsshould be consumed or de-allocated in some fashion.
603*0f4c859eSApple OSS DistributionsIn almost all cases, msgh_local_port will specify the name of a
604*0f4c859eSApple OSS Distributionsreceive right, either receive_name, or, if receive_name is a port
605*0f4c859eSApple OSS Distributionsset, a member of receive_name.
606*0f4c859eSApple OSS Distributions<p>
607*0f4c859eSApple OSS DistributionsIf other threads are concurrently
608*0f4c859eSApple OSS Distributionsmanipulating the receive right, the situation is more complicated. If
609*0f4c859eSApple OSS Distributionsthe receive right is renamed during the call, then msgh_local_port
610*0f4c859eSApple OSS Distributionsspecifies the right's new name. If the caller loses the receive right
611*0f4c859eSApple OSS Distributionsafter the message was de-queued from it, then <strong>mach_msg</strong> will proceed
612*0f4c859eSApple OSS Distributionsinstead of returning MACH_RCV_PORT_DIED. If the receive right was
613*0f4c859eSApple OSS Distributionsdestroyed, then msgh_local_port specifies MACH_PORT_DEAD. If the
614*0f4c859eSApple OSS Distributionsreceive right still exists, but isn't held by the caller, then
615*0f4c859eSApple OSS Distributionsmsgh_local_port specifies MACH_PORT_NULL.
616*0f4c859eSApple OSS Distributions<p>
617*0f4c859eSApple OSS DistributionsThe following options modify MACH_RCV_MSG. If MACH_RCV_MSG is not also
618*0f4c859eSApple OSS Distributionsspecified, they are ignored.
619*0f4c859eSApple OSS Distributions<dl>
620*0f4c859eSApple OSS Distributions<dt> MACH_RCV_TIMEOUT
621*0f4c859eSApple OSS Distributions     <dd>
622*0f4c859eSApple OSS DistributionsThe timeout argument should specify a maximum time (in milliseconds)
623*0f4c859eSApple OSS Distributionsfor the call to block before giving up. If no message arrives before
624*0f4c859eSApple OSS Distributionsthe timeout interval elapses, then the call returns
625*0f4c859eSApple OSS DistributionsMACH_RCV_TIMED_OUT. A zero timeout is legitimate.
626*0f4c859eSApple OSS Distributions<dt> MACH_RCV_NOTIFY
627*0f4c859eSApple OSS Distributions     <dd>
628*0f4c859eSApple OSS DistributionsThe notify argument should specify a receive right for a notify
629*0f4c859eSApple OSS Distributionsport. If receiving the reply port creates a new port right in the
630*0f4c859eSApple OSS Distributionscaller, then the notify port is used to request a dead-name
631*0f4c859eSApple OSS Distributionsnotification for the new port right.
632*0f4c859eSApple OSS Distributions<dt> MACH_RCV_INTERRUPT
633*0f4c859eSApple OSS Distributions     <dd>
634*0f4c859eSApple OSS DistributionsIf specified, the <strong>mach_msg</strong> call will return MACH_RCV_INTERRUPTED if a
635*0f4c859eSApple OSS Distributionssoftware interrupt aborts the call.  Otherwise, the receive operation
636*0f4c859eSApple OSS Distributionswill be retried.
637*0f4c859eSApple OSS Distributions<dt> MACH_RCV_OVERWRITE
638*0f4c859eSApple OSS Distributions     <dd>
639*0f4c859eSApple OSS DistributionsIf specified, the message buffer specified by receive_msg (or msg), of
640*0f4c859eSApple OSS Distributionslength receive_msg_size, will be scanned for out-of-line descriptors to
641*0f4c859eSApple OSS Distributionsspecify the processing to be done when receiving out-of-line regions.
642*0f4c859eSApple OSS DistributionsThis option is only allowed for <strong>mach_msg_overwrite</strong>.
643*0f4c859eSApple OSS Distributions<dt> MACH_RCV_LARGE
644*0f4c859eSApple OSS Distributions     <dd>
645*0f4c859eSApple OSS DistributionsIf the message is larger than receive_limit or an out-of-line region
646*0f4c859eSApple OSS Distributionsis larger than the size allowed by a corresponding receive descriptor
647*0f4c859eSApple OSS Distributions(MACH_RCV_OVERWRITE), the message remains queued instead of being
648*0f4c859eSApple OSS Distributionsdestroyed. If the header, trailer and body would not fit into
649*0f4c859eSApple OSS Distributionsreceive_limit, only the message header (mach_msg_header) and trailer
650*0f4c859eSApple OSS Distributionsheader (mach_msg_trailer) are returned with the actual size of the
651*0f4c859eSApple OSS Distributionsmessage returned in the msgh_size field, the actual size of the
652*0f4c859eSApple OSS Distributionstrailer returned in the msgh_trailer_size field and an error return
653*0f4c859eSApple OSS Distributionsvalue of MACH_RCV_TOO_LARGE. If receive_limit is sufficient but an
654*0f4c859eSApple OSS Distributionsout-of-line descriptor is not, the message header, trailer and body
655*0f4c859eSApple OSS Distributionsare received, with out-of-line descriptors set to indicate the
656*0f4c859eSApple OSS Distributionsnature and size of the out-of-line regions, with an error return of
657*0f4c859eSApple OSS DistributionsMACH_RCV_SCATTER_SMALL. No out-of-line regions or port rights
658*0f4c859eSApple OSS Distributions(including the reply right) will be received. If this option is not
659*0f4c859eSApple OSS Distributionsspecified, messages too large will be de-queued and then destroyed;
660*0f4c859eSApple OSS Distributionsthe caller receives the message header, with all fields correct,
661*0f4c859eSApple OSS Distributionsincluding the destination port but excepting the reply port, which is
662*0f4c859eSApple OSS DistributionsMACH_PORT_NULL and an empty (no additional element) message trailer.
663*0f4c859eSApple OSS Distributions<dt> MACH_RCV_TRAILER_TYPE(value)
664*0f4c859eSApple OSS Distributions     <dd>
665*0f4c859eSApple OSS DistributionsThis macro encodes the type of trailer the kernel must return with the
666*0f4c859eSApple OSS Distributionsmessage. If the kernel does not recognize this type, it returns
667*0f4c859eSApple OSS DistributionsMACH_RCV_INVALID_TRAILER. Currently, only MACH_MSG_TRAILER_FORMAT_0 is
668*0f4c859eSApple OSS Distributionssupported.
669*0f4c859eSApple OSS Distributions<dt> MACH_RCV_TRAILER_ELEMENTS(value)
670*0f4c859eSApple OSS Distributions     <dd>
671*0f4c859eSApple OSS DistributionsThis macro encodes the number of trailer elements desired. If the ker-
672*0f4c859eSApple OSS Distributionsnel does not support this number for the requested trailer type, the
673*0f4c859eSApple OSS Distributionskernel returns MACH_RCV_INVALID_TRAILER. Zero is a legal value.
674*0f4c859eSApple OSS Distributions	  </dl>
675*0f4c859eSApple OSS Distributions	  <p>
676*0f4c859eSApple OSS Distributions	  The following trailer elements are supported:
677*0f4c859eSApple OSS Distributions	  <dl>
678*0f4c859eSApple OSS Distributions<dt> MACH_RCV_TRAILER_SEQNO
679*0f4c859eSApple OSS Distributions     <dd>
680*0f4c859eSApple OSS DistributionsReturns the sequence number of the message relative to its port. This
681*0f4c859eSApple OSS Distributionsvalue is of type mach_port_seqno_t.
682*0f4c859eSApple OSS Distributions<dt> MACH_RCV_TRAILER_SENDER
683*0f4c859eSApple OSS Distributions     <dd>
684*0f4c859eSApple OSS DistributionsReturns the security ID of the task that sent the message. This value
685*0f4c859eSApple OSS Distributionsis of type security_id_t.
686*0f4c859eSApple OSS Distributions	  </dl>
687*0f4c859eSApple OSS Distributions	  <p>
688*0f4c859eSApple OSS DistributionsIf a resource shortage prevents the reception of a port right, the
689*0f4c859eSApple OSS Distributionsport right is destroyed and the caller sees the name
690*0f4c859eSApple OSS DistributionsMACH_PORT_NULL. If a resource shortage prevents the reception of an
691*0f4c859eSApple OSS Distributionsout-of-line memory region, the region is destroyed and the caller sees
692*0f4c859eSApple OSS Distributionsa zero address. In addition, the corresponding element in the size
693*0f4c859eSApple OSS Distributionsarray is set to zero. A task never receives port rights or memory for
694*0f4c859eSApple OSS Distributionswhich it is not told.
695*0f4c859eSApple OSS Distributions	  <p>
696*0f4c859eSApple OSS DistributionsThe MACH_RCV_HEADER_ERROR return code indicates a resource shortage
697*0f4c859eSApple OSS Distributionsin the reception of the message header. The reply port and all port
698*0f4c859eSApple OSS Distributionsrights and memory in the message are destroyed. The caller receives
699*0f4c859eSApple OSS Distributionsthe message header with all fields correct except for the reply
700*0f4c859eSApple OSS Distributionsport.
701*0f4c859eSApple OSS Distributions	  <p>
702*0f4c859eSApple OSS DistributionsThe MACH_RCV_BODY_ERROR return code indicates a resource shortage in
703*0f4c859eSApple OSS Distributionsthe reception of the message body. The message header, including the
704*0f4c859eSApple OSS Distributionsreply port, is correct. The kernel attempts to transfer all port
705*0f4c859eSApple OSS Distributionsrights and memory regions in the body, and only destroys those that
706*0f4c859eSApple OSS Distributionscan't be transferred.
707*0f4c859eSApple OSS Distributions<h4>Atomicity</h4>
708*0f4c859eSApple OSS Distributions	  <p>
709*0f4c859eSApple OSS DistributionsThe <strong>mach_msg</strong> call handles port rights in the message header
710*0f4c859eSApple OSS Distributionsatomically. Out-of-line memory and port rights in the message body do
711*0f4c859eSApple OSS Distributionsnot enjoy this atomicity guarantee. These elements may be processed
712*0f4c859eSApple OSS Distributionsfront-to-back, back-to-front, in some random order, or even
713*0f4c859eSApple OSS Distributionsatomically.
714*0f4c859eSApple OSS Distributions	  <p>
715*0f4c859eSApple OSS DistributionsFor example, consider sending a message with the destination port
716*0f4c859eSApple OSS Distributionsspecified as MACH_MSG_TYPE_MOVE_SEND and the reply port specified as
717*0f4c859eSApple OSS DistributionsMACH_MSG_TYPE_COPY_SEND. The same send right, with one user-refer-
718*0f4c859eSApple OSS Distributionsence, is supplied for both the msgh_remote_port and msgh_local_port
719*0f4c859eSApple OSS Distributionsfields.  Because <strong>mach_msg</strong> processes the port rights atomically, this
720*0f4c859eSApple OSS Distributionssucceeds. If msgh_remote_port were processed before msgh_local_port,
721*0f4c859eSApple OSS Distributionsthen <strong>mach_msg</strong> would return MACH_SEND_INVALID_REPLY in this situation.
722*0f4c859eSApple OSS Distributions	  <p>
723*0f4c859eSApple OSS DistributionsOn the other hand, suppose the destination and reply port are both
724*0f4c859eSApple OSS Distributionsspecified as MACH_MSG_TYPE_MOVE_SEND, and again the same send right
725*0f4c859eSApple OSS Distributionswith one user-reference is supplied for both. Now the send operation
726*0f4c859eSApple OSS Distributionsfails, but because it processes the rights atomically, <strong>mach_msg</strong> can
727*0f4c859eSApple OSS Distributionsreturn either MACH_SEND_INVALID_DEST or MACH_SEND_INVALID_REPLY.
728*0f4c859eSApple OSS Distributions<p>
729*0f4c859eSApple OSS DistributionsFor example, consider receiving a message at the same time another
730*0f4c859eSApple OSS Distributionsthread is deallocating the destination receive right. Suppose the
731*0f4c859eSApple OSS Distributionsreply port field carries a send right for the destination port. If the
732*0f4c859eSApple OSS Distributionsde-allocation happens before the dequeuing, the receiver gets
733*0f4c859eSApple OSS DistributionsMACH_RCV_PORT_DIED. If the de-allocation happens after the receive,
734*0f4c859eSApple OSS Distributionsthe msgh_local_port and the msgh_remote_port fields both specify
735*0f4c859eSApple OSS Distributionsthe same right, which becomes a dead name when the receive right is
736*0f4c859eSApple OSS Distributionsde-allocated. If the de-allocation happens between the de-queue and
737*0f4c859eSApple OSS Distributionsthe receive, the msgh_local_port and msgh_remote_port fields both
738*0f4c859eSApple OSS Distributionsspecify MACH_PORT_DEAD. Because the rights are processed atomically,
739*0f4c859eSApple OSS Distributionsit is not possible for just one of the two fields to hold
740*0f4c859eSApple OSS DistributionsMACH_PORT_DEAD.
741*0f4c859eSApple OSS Distributions<p>
742*0f4c859eSApple OSS DistributionsThe MACH_RCV_NOTIFY option provides a more likely example. Suppose a
743*0f4c859eSApple OSS Distributionsmessage carrying a send-once right reply port is received with
744*0f4c859eSApple OSS DistributionsMACH_RCV_NOTIFY at the same time the reply port is destroyed. If the
745*0f4c859eSApple OSS Distributionsreply port is destroyed first, then msgh_remote_port specifies
746*0f4c859eSApple OSS DistributionsMACH_PORT_DEAD and the kernel does not generate a dead-name
747*0f4c859eSApple OSS Distributionsnotification. If the reply port is destroyed after it is received,
748*0f4c859eSApple OSS Distributionsthen msgh_remote_port specifies a dead name for which the kernel
749*0f4c859eSApple OSS Distributionsgenerates a dead-name notification. Either the reply port is dead on
750*0f4c859eSApple OSS Distributionsarrival or notification is requested.
751*0f4c859eSApple OSS Distributions<h4>Implementation</h4>
752*0f4c859eSApple OSS Distributions<p>
753*0f4c859eSApple OSS Distributions<strong>mach_msg</strong> and <strong>mach_msg_overwrite</strong> are wrappers for a system call. They
754*0f4c859eSApple OSS Distributionshave the responsibility for repeating the interrupted system call.
755*0f4c859eSApple OSS Distributions<h3>CAUTIONS</h3>
756*0f4c859eSApple OSS Distributions<p>
757*0f4c859eSApple OSS DistributionsIf MACH_RCV_TIMEOUT is used without MACH_RCV_INTERRUPT, then the
758*0f4c859eSApple OSS Distributionstimeout duration might not be accurate. When the call is interrupted
759*0f4c859eSApple OSS Distributionsand automatically retried, the original timeout is used. If
760*0f4c859eSApple OSS Distributionsinterrupts occur frequently enough, the timeout interval might never
761*0f4c859eSApple OSS Distributionsexpire. MACH_SEND_TIMEOUT without MACH_SEND_INTERRUPT suffers from the
762*0f4c859eSApple OSS Distributionssame problem.
763*0f4c859eSApple OSS Distributions<h3>RETURN VALUES</h3>
764*0f4c859eSApple OSS Distributions<p>
765*0f4c859eSApple OSS DistributionsThe send operation can generate the following return codes. These
766*0f4c859eSApple OSS Distributionsreturn codes imply that the call did nothing:
767*0f4c859eSApple OSS Distributions<dl>
768*0f4c859eSApple OSS Distributions<p>
769*0f4c859eSApple OSS Distributions<dt> MACH_SEND_MSG_TOO_SMALL
770*0f4c859eSApple OSS Distributions     <dd>
771*0f4c859eSApple OSS DistributionsThe specified send_size was smaller than the minimum size for a
772*0f4c859eSApple OSS Distributionsmessage.
773*0f4c859eSApple OSS Distributions<p>
774*0f4c859eSApple OSS Distributions<dt> MACH_SEND_NO_BUFFER
775*0f4c859eSApple OSS Distributions     <dd>
776*0f4c859eSApple OSS DistributionsA resource shortage prevented the kernel from allocating a message
777*0f4c859eSApple OSS Distributionsbuffer.
778*0f4c859eSApple OSS Distributions<p>
779*0f4c859eSApple OSS Distributions<dt> MACH_SEND_INVALID_DATA
780*0f4c859eSApple OSS Distributions     <dd>
781*0f4c859eSApple OSS DistributionsThe supplied message buffer was not readable.
782*0f4c859eSApple OSS Distributions<p>
783*0f4c859eSApple OSS Distributions<dt> MACH_SEND_INVALID_HEADER
784*0f4c859eSApple OSS Distributions     <dd>
785*0f4c859eSApple OSS DistributionsThe msgh_bits value was invalid.
786*0f4c859eSApple OSS Distributions<p>
787*0f4c859eSApple OSS Distributions<dt> MACH_SEND_INVALID_DEST
788*0f4c859eSApple OSS Distributions     <dd>
789*0f4c859eSApple OSS DistributionsThe msgh_remote_port value was invalid.
790*0f4c859eSApple OSS Distributions<p>
791*0f4c859eSApple OSS Distributions<dt> MACH_SEND_INVALID_NOTIFY
792*0f4c859eSApple OSS Distributions     <dd>
793*0f4c859eSApple OSS DistributionsWhen using MACH_SEND_CANCEL, the notify argument did not
794*0f4c859eSApple OSS Distributionsdenote a valid receive right.
795*0f4c859eSApple OSS Distributions<p>
796*0f4c859eSApple OSS Distributions<dt> MACH_SEND_INVALID_REPLY
797*0f4c859eSApple OSS Distributions     <dd>
798*0f4c859eSApple OSS DistributionsThe msgh_local_port value was invalid.
799*0f4c859eSApple OSS Distributions<p>
800*0f4c859eSApple OSS Distributions<dt> MACH_SEND_INVALID_TRAILER
801*0f4c859eSApple OSS Distributions     <dd>
802*0f4c859eSApple OSS DistributionsThe trailer to be sent does not correspond to the current kernel format,
803*0f4c859eSApple OSS Distributionsor the sending task does not have the privilege to supply the message
804*0f4c859eSApple OSS Distributionsattributes.
805*0f4c859eSApple OSS Distributions	  </dl>
806*0f4c859eSApple OSS Distributions	  <p>
807*0f4c859eSApple OSS DistributionsThese return codes imply that some or all of the message was destroyed:
808*0f4c859eSApple OSS Distributions	  <dl>
809*0f4c859eSApple OSS Distributions<p>
810*0f4c859eSApple OSS Distributions<dt> MACH_SEND_INVALID_MEMORY
811*0f4c859eSApple OSS Distributions     <dd>
812*0f4c859eSApple OSS DistributionsThe message body specified out-of-line data that was not readable.
813*0f4c859eSApple OSS Distributions<p>
814*0f4c859eSApple OSS Distributions<dt> MACH_SEND_INVALID_RIGHT
815*0f4c859eSApple OSS Distributions     <dd>
816*0f4c859eSApple OSS DistributionsThe message body specified a port right which the caller didn't possess.
817*0f4c859eSApple OSS Distributions<p>
818*0f4c859eSApple OSS Distributions<dt> MACH_SEND_INVALID_TYPE
819*0f4c859eSApple OSS Distributions     <dd>
820*0f4c859eSApple OSS DistributionsA kernel processed descriptor was invalid.
821*0f4c859eSApple OSS Distributions<p>
822*0f4c859eSApple OSS Distributions<dt> MACH_SEND_MSG_TOO_SMALL
823*0f4c859eSApple OSS Distributions     <dd>
824*0f4c859eSApple OSS DistributionsThe last data item in the message ran over the end of the message.
825*0f4c859eSApple OSS Distributions	  </dl>
826*0f4c859eSApple OSS Distributions	  <p>
827*0f4c859eSApple OSS DistributionsThese return codes imply that the message was returned to the caller with a
828*0f4c859eSApple OSS Distributionspseudo-receive operation:
829*0f4c859eSApple OSS Distributions	  <dl>
830*0f4c859eSApple OSS Distributions<p>
831*0f4c859eSApple OSS Distributions<dt> MACH_SEND_TIMED_OUT
832*0f4c859eSApple OSS Distributions     <dd>
833*0f4c859eSApple OSS DistributionsThe timeout interval expired.
834*0f4c859eSApple OSS Distributions<p>
835*0f4c859eSApple OSS Distributions<dt> MACH_SEND_INTERRUPTED
836*0f4c859eSApple OSS Distributions     <dd>
837*0f4c859eSApple OSS DistributionsA software interrupt occurred.
838*0f4c859eSApple OSS Distributions	  </dl>
839*0f4c859eSApple OSS Distributions	  <p>
840*0f4c859eSApple OSS DistributionsThis return code implies that the message was queued:
841*0f4c859eSApple OSS Distributions	  <dl>
842*0f4c859eSApple OSS Distributions<p>
843*0f4c859eSApple OSS Distributions<dt> MACH_MSG_SUCCESS
844*0f4c859eSApple OSS Distributions     <dd>
845*0f4c859eSApple OSS DistributionsThe message was queued.
846*0f4c859eSApple OSS Distributions	  </dl>
847*0f4c859eSApple OSS Distributions	  <p>
848*0f4c859eSApple OSS DistributionsThe receive operation can generate the following return codes. These return
849*0f4c859eSApple OSS Distributionscodes imply that the call did not de-queue a message:
850*0f4c859eSApple OSS Distributions	  <dl>
851*0f4c859eSApple OSS Distributions<p>
852*0f4c859eSApple OSS Distributions<dt> MACH_RCV_INVALID_NAME
853*0f4c859eSApple OSS Distributions     <dd>
854*0f4c859eSApple OSS DistributionsThe specified receive_name was invalid.
855*0f4c859eSApple OSS Distributions<p>
856*0f4c859eSApple OSS Distributions<dt> MACH_RCV_IN_SET
857*0f4c859eSApple OSS Distributions     <dd>
858*0f4c859eSApple OSS DistributionsThe specified port was a member of a port set.
859*0f4c859eSApple OSS Distributions<p>
860*0f4c859eSApple OSS Distributions<dt> MACH_RCV_TIMED_OUT
861*0f4c859eSApple OSS Distributions     <dd>
862*0f4c859eSApple OSS DistributionsThe timeout interval expired.
863*0f4c859eSApple OSS Distributions<p>
864*0f4c859eSApple OSS Distributions<dt> MACH_RCV_INTERRUPTED
865*0f4c859eSApple OSS Distributions     <dd>
866*0f4c859eSApple OSS DistributionsA software interrupt occurred.
867*0f4c859eSApple OSS Distributions<p>
868*0f4c859eSApple OSS Distributions<dt> MACH_RCV_PORT_DIED
869*0f4c859eSApple OSS Distributions     <dd>
870*0f4c859eSApple OSS DistributionsThe caller lost the rights specified by receive_name.
871*0f4c859eSApple OSS Distributions<p>
872*0f4c859eSApple OSS Distributions<dt> MACH_RCV_PORT_CHANGED
873*0f4c859eSApple OSS Distributions     <dd>
874*0f4c859eSApple OSS Distributionsreceive_name specified a receive right which was moved into a port set
875*0f4c859eSApple OSS Distributionsduring the call.
876*0f4c859eSApple OSS Distributions<p>
877*0f4c859eSApple OSS Distributions<dt> MACH_RCV_TOO_LARGE
878*0f4c859eSApple OSS Distributions     <dd>
879*0f4c859eSApple OSS DistributionsWhen using MACH_RCV_LARGE, the message was larger than
880*0f4c859eSApple OSS Distributionsreceive_limit. The message is left queued, and its actual size is
881*0f4c859eSApple OSS Distributionsreturned in the message header/message body.
882*0f4c859eSApple OSS Distributions<p>
883*0f4c859eSApple OSS Distributions<dt> MACH_RCV_SCATTER_SMALL
884*0f4c859eSApple OSS Distributions     <dd>
885*0f4c859eSApple OSS DistributionsWhen using MACH_RCV_LARGE with MACH_RCV_OVERWRITE, one or more scatter
886*0f4c859eSApple OSS Distributionslist descriptors specified an overwrite region smaller than the
887*0f4c859eSApple OSS Distributionscorresponding incoming region. The message is left queued, and the
888*0f4c859eSApple OSS Distributionsproper descriptors are returned in the message header/message body.
889*0f4c859eSApple OSS Distributions<p>
890*0f4c859eSApple OSS Distributions<dt> MACH_RCV_INVALID_TRAILER
891*0f4c859eSApple OSS Distributions     <dd>
892*0f4c859eSApple OSS DistributionsThe trailer type desired, or the number of trailer elements desired, is
893*0f4c859eSApple OSS Distributionsnot supported by the kernel.
894*0f4c859eSApple OSS Distributions	  </dl>
895*0f4c859eSApple OSS Distributions	  <p>
896*0f4c859eSApple OSS DistributionsThese return codes imply that a message was de-queued and destroyed:
897*0f4c859eSApple OSS Distributions	  <dl>
898*0f4c859eSApple OSS Distributions<p>
899*0f4c859eSApple OSS Distributions<dt> MACH_RCV_HEADER_ERROR
900*0f4c859eSApple OSS Distributions     <dd>
901*0f4c859eSApple OSS DistributionsA resource shortage prevented the reception of the port rights in the
902*0f4c859eSApple OSS Distributionsmessage header.
903*0f4c859eSApple OSS Distributions<p>
904*0f4c859eSApple OSS Distributions<dt> MACH_RCV_INVALID_NOTIFY
905*0f4c859eSApple OSS Distributions     <dd>
906*0f4c859eSApple OSS DistributionsWhen using MACH_RCV_NOTIFY, the notify argument did not denote a
907*0f4c859eSApple OSS Distributionsvalid receive right.
908*0f4c859eSApple OSS Distributions<p>
909*0f4c859eSApple OSS Distributions<dt> MACH_RCV_INVALID_DATA
910*0f4c859eSApple OSS Distributions     <dd>
911*0f4c859eSApple OSS DistributionsThe specified message buffer was not writable.
912*0f4c859eSApple OSS Distributions<p>
913*0f4c859eSApple OSS Distributions<dt> MACH_RCV_TOO_LARGE
914*0f4c859eSApple OSS Distributions     <dd>
915*0f4c859eSApple OSS DistributionsWhen not using MACH_RCV_LARGE, a message larger than
916*0f4c859eSApple OSS Distributionsreceive_limit was de-queued and destroyed.
917*0f4c859eSApple OSS Distributions<p>
918*0f4c859eSApple OSS Distributions<dt> MACH_RCV_SCATTER_SMALL
919*0f4c859eSApple OSS Distributions     <dd>
920*0f4c859eSApple OSS DistributionsWhen not using MACH_RCV_LARGE with MACH_RCV_OVERWRITE, one or more
921*0f4c859eSApple OSS Distributionsscatter list descriptors specified an overwrite region smaller than
922*0f4c859eSApple OSS Distributionsthe corresponding incoming region. The message was de-queued and
923*0f4c859eSApple OSS Distributionsdestroyed.
924*0f4c859eSApple OSS Distributions<p>
925*0f4c859eSApple OSS Distributions<dt> MACH_RCV_OVERWRITE_ERROR
926*0f4c859eSApple OSS Distributions     <dd>
927*0f4c859eSApple OSS DistributionsA region specified by a receive overwrite descriptor
928*0f4c859eSApple OSS Distributions(MACH_RCV_OVERWRITE) was not allocated or could not be written.
929*0f4c859eSApple OSS Distributions<p>
930*0f4c859eSApple OSS Distributions<dt> MACH_RCV_INVALID_TYPE
931*0f4c859eSApple OSS Distributions     <dd>
932*0f4c859eSApple OSS DistributionsWhen using MACH_RCV_OVERWRITE, one or more scatter list descriptors
933*0f4c859eSApple OSS Distributionsdid not have the type matching the corresponding incoming message
934*0f4c859eSApple OSS Distributionsdescriptor or had an invalid copy (disposition) field.
935*0f4c859eSApple OSS Distributions<p>
936*0f4c859eSApple OSS Distributions<dt> MACH_RCV_LIMITS
937*0f4c859eSApple OSS Distributions     <dd>
938*0f4c859eSApple OSS DistributionsThe combined size of all out-of-line memory regions or the total num-
939*0f4c859eSApple OSS Distributionsber of port rights in the message exceeds the limit set for the port.
940*0f4c859eSApple OSS DistributionsThese return codes imply that a message was received:
941*0f4c859eSApple OSS Distributions<p>
942*0f4c859eSApple OSS Distributions<dt> MACH_RCV_BODY_ERROR
943*0f4c859eSApple OSS Distributions     <dd>
944*0f4c859eSApple OSS DistributionsA resource shortage prevented the reception of a port right or out-of-
945*0f4c859eSApple OSS Distributionsline memory region in the message body.
946*0f4c859eSApple OSS Distributions<p>
947*0f4c859eSApple OSS Distributions<dt> MACH_MSG_SUCCESS
948*0f4c859eSApple OSS Distributions     <dd>
949*0f4c859eSApple OSS DistributionsA message was received.
950*0f4c859eSApple OSS Distributions	  </dl>
951*0f4c859eSApple OSS Distributions	  <p>
952*0f4c859eSApple OSS DistributionsResource shortages can occur after a message is de-queued, while
953*0f4c859eSApple OSS Distributionstransferring port rights and out-of-line memory regions to the
954*0f4c859eSApple OSS Distributionsreceiving task. The <strong>mach_msg</strong> call returns MACH_RCV_HEADER_ERROR or
955*0f4c859eSApple OSS DistributionsMACH_RCV_BODY_ERROR in this situation. These return codes always carry
956*0f4c859eSApple OSS Distributions	  extra bits (bitwise-or'ed) that indicate the nature of the resource
957*0f4c859eSApple OSS Distributionsshortage:
958*0f4c859eSApple OSS Distributions	  <dl>
959*0f4c859eSApple OSS Distributions<p>
960*0f4c859eSApple OSS Distributions<dt> MACH_MSG_IPC_SPACE
961*0f4c859eSApple OSS Distributions     <dd>
962*0f4c859eSApple OSS DistributionsThere was no room in the task's IPC name space for another port name.
963*0f4c859eSApple OSS Distributions<p>
964*0f4c859eSApple OSS Distributions<dt> MACH_MSG_VM_SPACE
965*0f4c859eSApple OSS Distributions     <dd>
966*0f4c859eSApple OSS DistributionsThere was no room in the task's VM address space for an out-of-line
967*0f4c859eSApple OSS Distributionsmemory region.
968*0f4c859eSApple OSS Distributions<p>
969*0f4c859eSApple OSS Distributions<dt> MACH_MSG_IPC_KERNEL
970*0f4c859eSApple OSS Distributions     <dd>
971*0f4c859eSApple OSS DistributionsA kernel resource shortage prevented the reception of a port right.
972*0f4c859eSApple OSS Distributions<p>
973*0f4c859eSApple OSS Distributions<dt> MACH_MSG_VM_KERNEL
974*0f4c859eSApple OSS Distributions     <dd>
975*0f4c859eSApple OSS DistributionsA kernel resource shortage prevented the reception of an out-of-line
976*0f4c859eSApple OSS Distributionsmemory region.
977*0f4c859eSApple OSS Distributions</dl>
978*0f4c859eSApple OSS Distributions<h3>RELATED INFORMATION</h3>
979*0f4c859eSApple OSS Distributions<p>
980*0f4c859eSApple OSS DistributionsFunctions:
981*0f4c859eSApple OSS Distributions<a href="vm_allocate.html"><strong>vm_allocate</strong></a>,
982*0f4c859eSApple OSS Distributions<a href="vm_deallocate.html"><strong>vm_deallocate</strong></a>,
983*0f4c859eSApple OSS Distributions<a href="vm_write.html"><strong>vm_write</strong></a>,
984*0f4c859eSApple OSS Distributions<a href="MP_request_notification.html"><strong>mach_port_request_notification</strong></a>,
985*0f4c859eSApple OSS Distributions<p>
986*0f4c859eSApple OSS DistributionsData Structures:
987*0f4c859eSApple OSS Distributionsmach_msg_header.
988