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