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