]> git.saurik.com Git - apple/xnu.git/blame - osfmk/mach/message.h
xnu-6153.141.1.tar.gz
[apple/xnu.git] / osfmk / mach / message.h
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
0a7de745 31/*
1c79356b
A
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
0a7de745 35 *
1c79356b
A
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
0a7de745 41 *
1c79356b
A
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
0a7de745 45 *
1c79356b 46 * Carnegie Mellon requests users of this software to return to
0a7de745 47 *
1c79356b
A
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
0a7de745 52 *
1c79356b
A
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
2d21ac55
A
56/*
57 * NOTICE: This file was modified by McAfee Research in 2004 to introduce
58 * support for mandatory and extensible security protections. This notice
59 * is included in support of clause 2.2 (b) of the Apple Public License,
60 * Version 2.0.
61 * Copyright (c) 2005 SPARTA, Inc.
62 */
1c79356b
A
63/*
64 */
65/*
66 * File: mach/message.h
67 *
68 * Mach IPC message and primitive function definitions.
69 */
70
0a7de745 71#ifndef _MACH_MESSAGE_H_
1c79356b
A
72#define _MACH_MESSAGE_H_
73
9bccf70c
A
74#include <stdint.h>
75#include <mach/port.h>
76#include <mach/boolean.h>
77#include <mach/kern_return.h>
78#include <mach/machine/vm_types.h>
1c79356b 79
91447636 80#include <sys/cdefs.h>
316670eb 81#include <sys/appleapiopts.h>
3e170ce0 82#include <Availability.h>
91447636 83
1c79356b
A
84/*
85 * The timeout mechanism uses mach_msg_timeout_t values,
86 * passed by value. The timeout units are milliseconds.
87 * It is controlled with the MACH_SEND_TIMEOUT
88 * and MACH_RCV_TIMEOUT options.
89 */
90
91typedef natural_t mach_msg_timeout_t;
92
93/*
94 * The value to be used when there is no timeout.
95 * (No MACH_SEND_TIMEOUT/MACH_RCV_TIMEOUT option.)
96 */
97
0a7de745 98#define MACH_MSG_TIMEOUT_NONE ((mach_msg_timeout_t) 0)
1c79356b
A
99
100/*
b0d623f7 101 * The kernel uses MACH_MSGH_BITS_COMPLEX as a hint. If it isn't on, it
1c79356b
A
102 * assumes the body of the message doesn't contain port rights or OOL
103 * data. The field is set in received messages. A user task must
104 * use caution in interpreting the body of a message if the bit isn't
105 * on, because the mach_msg_type's in the body might "lie" about the
106 * contents. If the bit isn't on, but the mach_msg_types
107 * in the body specify rights or OOL data, the behavior is undefined.
108 * (Ie, an error may or may not be produced.)
109 *
110 * The value of MACH_MSGH_BITS_REMOTE determines the interpretation
fe8ab488
A
111 * of the msgh_remote_port field. It is handled like a msgt_name,
112 * but must result in a send or send-once type right.
1c79356b
A
113 *
114 * The value of MACH_MSGH_BITS_LOCAL determines the interpretation
fe8ab488
A
115 * of the msgh_local_port field. It is handled like a msgt_name,
116 * and also must result in a send or send-once type right.
117 *
118 * The value of MACH_MSGH_BITS_VOUCHER determines the interpretation
119 * of the msgh_voucher_port field. It is handled like a msgt_name,
120 * but must result in a send right (and the msgh_voucher_port field
121 * must be the name of a send right to a Mach voucher kernel object.
1c79356b
A
122 *
123 * MACH_MSGH_BITS() combines two MACH_MSG_TYPE_* values, for the remote
124 * and local fields, into a single value suitable for msgh_bits.
125 *
126 * MACH_MSGH_BITS_CIRCULAR should be zero; is is used internally.
127 *
128 * The unused bits should be zero and are reserved for the kernel
129 * or for future interface expansion.
130 */
131
0a7de745 132#define MACH_MSGH_BITS_ZERO 0x00000000
1c79356b 133
0a7de745
A
134#define MACH_MSGH_BITS_REMOTE_MASK 0x0000001f
135#define MACH_MSGH_BITS_LOCAL_MASK 0x00001f00
136#define MACH_MSGH_BITS_VOUCHER_MASK 0x001f0000
fe8ab488 137
0a7de745
A
138#define MACH_MSGH_BITS_PORTS_MASK \
139 (MACH_MSGH_BITS_REMOTE_MASK | \
140 MACH_MSGH_BITS_LOCAL_MASK | \
141 MACH_MSGH_BITS_VOUCHER_MASK)
fe8ab488 142
0a7de745 143#define MACH_MSGH_BITS_COMPLEX 0x80000000U /* message is complex */
fe8ab488 144
0a7de745 145#define MACH_MSGH_BITS_USER 0x801f1f1fU /* allowed bits user->kernel */
fe8ab488 146
0a7de745
A
147#define MACH_MSGH_BITS_RAISEIMP 0x20000000U /* importance raised due to msg */
148#define MACH_MSGH_BITS_DENAP MACH_MSGH_BITS_RAISEIMP
1c79356b 149
0a7de745
A
150#define MACH_MSGH_BITS_IMPHOLDASRT 0x10000000U /* assertion help, userland private */
151#define MACH_MSGH_BITS_DENAPHOLDASRT MACH_MSGH_BITS_IMPHOLDASRT
1c79356b 152
0a7de745 153#define MACH_MSGH_BITS_CIRCULAR 0x10000000U /* message circular, kernel private */
fe8ab488 154
0a7de745 155#define MACH_MSGH_BITS_USED 0xb01f1f1fU
fe8ab488
A
156
157/* setter macros for the bits */
0a7de745
A
158#define MACH_MSGH_BITS(remote, local) /* legacy */ \
159 ((remote) | ((local) << 8))
160#define MACH_MSGH_BITS_SET_PORTS(remote, local, voucher) \
161 (((remote) & MACH_MSGH_BITS_REMOTE_MASK) | \
162 (((local) << 8) & MACH_MSGH_BITS_LOCAL_MASK) | \
fe8ab488 163 (((voucher) << 16) & MACH_MSGH_BITS_VOUCHER_MASK))
0a7de745 164#define MACH_MSGH_BITS_SET(remote, local, voucher, other) \
fe8ab488
A
165 (MACH_MSGH_BITS_SET_PORTS((remote), (local), (voucher)) \
166 | ((other) &~ MACH_MSGH_BITS_PORTS_MASK))
167
168/* getter macros for pulling values out of the bits field */
0a7de745
A
169#define MACH_MSGH_BITS_REMOTE(bits) \
170 ((bits) & MACH_MSGH_BITS_REMOTE_MASK)
171#define MACH_MSGH_BITS_LOCAL(bits) \
172 (((bits) & MACH_MSGH_BITS_LOCAL_MASK) >> 8)
173#define MACH_MSGH_BITS_VOUCHER(bits) \
174 (((bits) & MACH_MSGH_BITS_VOUCHER_MASK) >> 16)
175#define MACH_MSGH_BITS_PORTS(bits) \
fe8ab488 176 ((bits) & MACH_MSGH_BITS_PORTS_MASK)
0a7de745
A
177#define MACH_MSGH_BITS_OTHER(bits) \
178 ((bits) &~ MACH_MSGH_BITS_PORTS_MASK)
1c79356b 179
fe8ab488 180/* checking macros */
0a7de745 181#define MACH_MSGH_BITS_HAS_REMOTE(bits) \
fe8ab488 182 (MACH_MSGH_BITS_REMOTE(bits) != MACH_MSGH_BITS_ZERO)
0a7de745 183#define MACH_MSGH_BITS_HAS_LOCAL(bits) \
fe8ab488 184 (MACH_MSGH_BITS_LOCAL(bits) != MACH_MSGH_BITS_ZERO)
0a7de745 185#define MACH_MSGH_BITS_HAS_VOUCHER(bits) \
fe8ab488 186 (MACH_MSGH_BITS_VOUCHER(bits) != MACH_MSGH_BITS_ZERO)
0a7de745 187#define MACH_MSGH_BITS_IS_COMPLEX(bits) \
fe8ab488
A
188 (((bits) & MACH_MSGH_BITS_COMPLEX) != MACH_MSGH_BITS_ZERO)
189
190/* importance checking macros */
0a7de745 191#define MACH_MSGH_BITS_RAISED_IMPORTANCE(bits) \
fe8ab488 192 (((bits) & MACH_MSGH_BITS_RAISEIMP) != MACH_MSGH_BITS_ZERO)
0a7de745 193#define MACH_MSGH_BITS_HOLDS_IMPORTANCE_ASSERTION(bits) \
fe8ab488
A
194 (((bits) & MACH_MSGH_BITS_IMPHOLDASRT) != MACH_MSGH_BITS_ZERO)
195
1c79356b
A
196/*
197 * Every message starts with a message header.
b0d623f7 198 * Following the message header, if the message is complex, are a count
0a7de745
A
199 * of type descriptors and the type descriptors themselves
200 * (mach_msg_descriptor_t). The size of the message must be specified in
201 * bytes, and includes the message header, descriptor count, descriptors,
b0d623f7 202 * and inline data.
1c79356b
A
203 *
204 * The msgh_remote_port field specifies the destination of the message.
205 * It must specify a valid send or send-once right for a port.
206 *
207 * The msgh_local_port field specifies a "reply port". Normally,
208 * This field carries a send-once right that the receiver will use
209 * to reply to the message. It may carry the values MACH_PORT_NULL,
210 * MACH_PORT_DEAD, a send-once right, or a send right.
211 *
fe8ab488
A
212 * The msgh_voucher_port field specifies a Mach voucher port. Only
213 * send rights to kernel-implemented Mach Voucher kernel objects in
214 * addition to MACH_PORT_NULL or MACH_PORT_DEAD may be passed.
1c79356b
A
215 *
216 * The msgh_id field is uninterpreted by the message primitives.
217 * It normally carries information specifying the format
218 * or meaning of the message.
219 */
220
221typedef unsigned int mach_msg_bits_t;
0a7de745 222typedef natural_t mach_msg_size_t;
1c79356b
A
223typedef integer_t mach_msg_id_t;
224
1c79356b
A
225#define MACH_MSG_SIZE_NULL (mach_msg_size_t *) 0
226
39037602
A
227typedef unsigned int mach_msg_priority_t;
228
229#define MACH_MSG_PRIORITY_UNSPECIFIED (mach_msg_priority_t) 0
230
1c79356b
A
231typedef unsigned int mach_msg_type_name_t;
232
0a7de745
A
233#define MACH_MSG_TYPE_MOVE_RECEIVE 16 /* Must hold receive right */
234#define MACH_MSG_TYPE_MOVE_SEND 17 /* Must hold send right(s) */
235#define MACH_MSG_TYPE_MOVE_SEND_ONCE 18 /* Must hold sendonce right */
236#define MACH_MSG_TYPE_COPY_SEND 19 /* Must hold send right(s) */
237#define MACH_MSG_TYPE_MAKE_SEND 20 /* Must hold receive right */
238#define MACH_MSG_TYPE_MAKE_SEND_ONCE 21 /* Must hold receive right */
239#define MACH_MSG_TYPE_COPY_RECEIVE 22 /* NOT VALID */
240#define MACH_MSG_TYPE_DISPOSE_RECEIVE 24 /* must hold receive right */
241#define MACH_MSG_TYPE_DISPOSE_SEND 25 /* must hold send right(s) */
242#define MACH_MSG_TYPE_DISPOSE_SEND_ONCE 26 /* must hold sendonce right */
1c79356b
A
243
244typedef unsigned int mach_msg_copy_options_t;
245
0a7de745
A
246#define MACH_MSG_PHYSICAL_COPY 0
247#define MACH_MSG_VIRTUAL_COPY 1
248#define MACH_MSG_ALLOCATE 2
249#define MACH_MSG_OVERWRITE 3 /* deprecated */
1c79356b 250#ifdef MACH_KERNEL
0a7de745 251#define MACH_MSG_KALLOC_COPY_T 4
1c79356b
A
252#endif /* MACH_KERNEL */
253
cb323159
A
254#define MACH_MSG_GUARD_FLAGS_NONE 0x0000
255#define MACH_MSG_GUARD_FLAGS_IMMOVABLE_RECEIVE 0x0001 /* Move the receive right and mark it as immovable */
256#define MACH_MSG_GUARD_FLAGS_UNGUARDED_ON_SEND 0x0002 /* Verify that the port is unguarded */
257#define MACH_MSG_GUARD_FLAGS_MASK 0x0003 /* Valid flag bits */
258typedef unsigned int mach_msg_guard_flags_t;
259
b0d623f7 260/*
0a7de745
A
261 * In a complex mach message, the mach_msg_header_t is followed by
262 * a descriptor count, then an array of that number of descriptors
b0d623f7
A
263 * (mach_msg_*_descriptor_t). The type field of mach_msg_type_descriptor_t
264 * (which any descriptor can be cast to) indicates the flavor of the
265 * descriptor.
266 *
267 * Note that in LP64, the various types of descriptors are no longer all
0a7de745 268 * the same size as mach_msg_descriptor_t, so the array cannot be indexed
b0d623f7
A
269 * as expected.
270 */
271
1c79356b
A
272typedef unsigned int mach_msg_descriptor_type_t;
273
0a7de745
A
274#define MACH_MSG_PORT_DESCRIPTOR 0
275#define MACH_MSG_OOL_DESCRIPTOR 1
276#define MACH_MSG_OOL_PORTS_DESCRIPTOR 2
277#define MACH_MSG_OOL_VOLATILE_DESCRIPTOR 3
cb323159 278#define MACH_MSG_GUARDED_PORT_DESCRIPTOR 4
1c79356b 279
cb323159 280#pragma pack(push, 4)
1c79356b 281
0a7de745
A
282typedef struct{
283 natural_t pad1;
284 mach_msg_size_t pad2;
285 unsigned int pad3 : 24;
286 mach_msg_descriptor_type_t type : 8;
1c79356b
A
287} mach_msg_type_descriptor_t;
288
0a7de745
A
289typedef struct{
290 mach_port_t name;
b0d623f7
A
291#if !(defined(KERNEL) && defined(__LP64__))
292// Pad to 8 bytes everywhere except the K64 kernel where mach_port_t is 8 bytes
0a7de745 293 mach_msg_size_t pad1;
b0d623f7 294#endif
0a7de745
A
295 unsigned int pad2 : 16;
296 mach_msg_type_name_t disposition : 8;
297 mach_msg_descriptor_type_t type : 8;
b0d623f7 298#if defined(KERNEL)
0a7de745 299 uint32_t pad_end;
b0d623f7 300#endif
1c79356b
A
301} mach_msg_port_descriptor_t;
302
0a7de745
A
303typedef struct{
304 uint32_t address;
305 mach_msg_size_t size;
306 boolean_t deallocate: 8;
307 mach_msg_copy_options_t copy: 8;
308 unsigned int pad1: 8;
309 mach_msg_descriptor_type_t type: 8;
91447636
A
310} mach_msg_ool_descriptor32_t;
311
0a7de745
A
312typedef struct{
313 uint64_t address;
314 boolean_t deallocate: 8;
315 mach_msg_copy_options_t copy: 8;
316 unsigned int pad1: 8;
317 mach_msg_descriptor_type_t type: 8;
318 mach_msg_size_t size;
91447636
A
319} mach_msg_ool_descriptor64_t;
320
0a7de745
A
321typedef struct{
322 void* address;
91447636 323#if !defined(__LP64__)
0a7de745 324 mach_msg_size_t size;
91447636 325#endif
0a7de745
A
326 boolean_t deallocate: 8;
327 mach_msg_copy_options_t copy: 8;
328 unsigned int pad1: 8;
329 mach_msg_descriptor_type_t type: 8;
91447636 330#if defined(__LP64__)
0a7de745 331 mach_msg_size_t size;
91447636 332#endif
b0d623f7 333#if defined(KERNEL) && !defined(__LP64__)
0a7de745 334 uint32_t pad_end;
b0d623f7 335#endif
1c79356b
A
336} mach_msg_ool_descriptor_t;
337
0a7de745
A
338typedef struct{
339 uint32_t address;
340 mach_msg_size_t count;
341 boolean_t deallocate: 8;
342 mach_msg_copy_options_t copy: 8;
343 mach_msg_type_name_t disposition : 8;
344 mach_msg_descriptor_type_t type : 8;
91447636
A
345} mach_msg_ool_ports_descriptor32_t;
346
0a7de745
A
347typedef struct{
348 uint64_t address;
349 boolean_t deallocate: 8;
350 mach_msg_copy_options_t copy: 8;
351 mach_msg_type_name_t disposition : 8;
352 mach_msg_descriptor_type_t type : 8;
353 mach_msg_size_t count;
91447636
A
354} mach_msg_ool_ports_descriptor64_t;
355
0a7de745
A
356typedef struct{
357 void* address;
91447636 358#if !defined(__LP64__)
0a7de745 359 mach_msg_size_t count;
91447636 360#endif
0a7de745
A
361 boolean_t deallocate: 8;
362 mach_msg_copy_options_t copy: 8;
363 mach_msg_type_name_t disposition : 8;
364 mach_msg_descriptor_type_t type : 8;
91447636 365#if defined(__LP64__)
0a7de745 366 mach_msg_size_t count;
91447636 367#endif
b0d623f7 368#if defined(KERNEL) && !defined(__LP64__)
0a7de745 369 uint32_t pad_end;
b0d623f7 370#endif
1c79356b
A
371} mach_msg_ool_ports_descriptor_t;
372
cb323159
A
373typedef struct{
374 uint32_t context;
375 mach_port_name_t name;
376 mach_msg_guard_flags_t flags : 16;
377 mach_msg_type_name_t disposition : 8;
378 mach_msg_descriptor_type_t type : 8;
379} mach_msg_guarded_port_descriptor32_t;
380
381typedef struct{
382 uint64_t context;
383 mach_msg_guard_flags_t flags : 16;
384 mach_msg_type_name_t disposition : 8;
385 mach_msg_descriptor_type_t type : 8;
386 mach_port_name_t name;
387} mach_msg_guarded_port_descriptor64_t;
388
389typedef struct{
390#if defined(KERNEL)
391 mach_port_t name;
392#if !defined(__LP64__)
393 uint32_t pad1;
394#endif
395 mach_msg_guard_flags_t flags : 16;
396 mach_msg_type_name_t disposition : 8;
397 mach_msg_descriptor_type_t type : 8;
398#if defined(__LP64__)
399 uint32_t pad_end;
400#endif /* defined(__LP64__) */
401#else
402 mach_port_context_t context;
403#if !defined(__LP64__)
404 mach_port_name_t name;
405#endif
406 mach_msg_guard_flags_t flags : 16;
407 mach_msg_type_name_t disposition : 8;
408 mach_msg_descriptor_type_t type : 8;
409#if defined(__LP64__)
410 mach_port_name_t name;
411#endif /* defined(__LP64__) */
412#endif /* defined(KERNEL) */
413} mach_msg_guarded_port_descriptor_t;
414
91447636
A
415/*
416 * LP64support - This union definition is not really
417 * appropriate in LP64 mode because not all descriptors
418 * are of the same size in that environment.
419 */
b0d623f7 420#if defined(__LP64__) && defined(KERNEL)
0a7de745
A
421typedef union{
422 mach_msg_port_descriptor_t port;
423 mach_msg_ool_descriptor32_t out_of_line;
424 mach_msg_ool_ports_descriptor32_t ool_ports;
425 mach_msg_type_descriptor_t type;
cb323159 426 mach_msg_guarded_port_descriptor32_t guarded_port;
b0d623f7
A
427} mach_msg_descriptor_t;
428#else
0a7de745
A
429typedef union{
430 mach_msg_port_descriptor_t port;
431 mach_msg_ool_descriptor_t out_of_line;
432 mach_msg_ool_ports_descriptor_t ool_ports;
433 mach_msg_type_descriptor_t type;
cb323159 434 mach_msg_guarded_port_descriptor_t guarded_port;
1c79356b 435} mach_msg_descriptor_t;
b0d623f7 436#endif
1c79356b 437
0a7de745
A
438typedef struct{
439 mach_msg_size_t msgh_descriptor_count;
1c79356b
A
440} mach_msg_body_t;
441
442#define MACH_MSG_BODY_NULL (mach_msg_body_t *) 0
443#define MACH_MSG_DESCRIPTOR_NULL (mach_msg_descriptor_t *) 0
444
0a7de745
A
445typedef struct{
446 mach_msg_bits_t msgh_bits;
447 mach_msg_size_t msgh_size;
448 mach_port_t msgh_remote_port;
449 mach_port_t msgh_local_port;
450 mach_port_name_t msgh_voucher_port;
451 mach_msg_id_t msgh_id;
1c79356b
A
452} mach_msg_header_t;
453
0a7de745
A
454#define msgh_reserved msgh_voucher_port
455#define MACH_MSG_NULL (mach_msg_header_t *) 0
1c79356b 456
0a7de745
A
457typedef struct{
458 mach_msg_header_t header;
459 mach_msg_body_t body;
1c79356b
A
460} mach_msg_base_t;
461
0a7de745 462typedef unsigned int mach_msg_trailer_type_t;
1c79356b 463
0a7de745 464#define MACH_MSG_TRAILER_FORMAT_0 0
1c79356b 465
0a7de745 466typedef unsigned int mach_msg_trailer_size_t;
39236c6e 467typedef char *mach_msg_trailer_info_t;
1c79356b 468
0a7de745
A
469typedef struct{
470 mach_msg_trailer_type_t msgh_trailer_type;
471 mach_msg_trailer_size_t msgh_trailer_size;
1c79356b
A
472} mach_msg_trailer_t;
473
fe8ab488
A
474/*
475 * The msgh_seqno field carries a sequence number
476 * associated with the received-from port. A port's
477 * sequence number is incremented every time a message
478 * is received from it and included in the received
479 * trailer to help put messages back in sequence if
480 * multiple threads receive and/or process received
481 * messages.
482 */
0a7de745
A
483typedef struct{
484 mach_msg_trailer_type_t msgh_trailer_type;
485 mach_msg_trailer_size_t msgh_trailer_size;
486 mach_port_seqno_t msgh_seqno;
1c79356b
A
487} mach_msg_seqno_trailer_t;
488
0a7de745
A
489typedef struct{
490 unsigned int val[2];
1c79356b
A
491} security_token_t;
492
0a7de745
A
493typedef struct{
494 mach_msg_trailer_type_t msgh_trailer_type;
495 mach_msg_trailer_size_t msgh_trailer_size;
496 mach_port_seqno_t msgh_seqno;
497 security_token_t msgh_sender;
1c79356b
A
498} mach_msg_security_trailer_t;
499
e5568f75
A
500/*
501 * The audit token is an opaque token which identifies
502 * Mach tasks and senders of Mach messages as subjects
503 * to the BSM audit system. Only the appropriate BSM
504 * library routines should be used to interpret the
505 * contents of the audit token as the representation
506 * of the subject identity within the token may change
507 * over time.
508 */
0a7de745
A
509typedef struct{
510 unsigned int val[8];
55e303ae
A
511} audit_token_t;
512
0a7de745
A
513typedef struct{
514 mach_msg_trailer_type_t msgh_trailer_type;
515 mach_msg_trailer_size_t msgh_trailer_size;
516 mach_port_seqno_t msgh_seqno;
517 security_token_t msgh_sender;
518 audit_token_t msgh_audit;
55e303ae 519} mach_msg_audit_trailer_t;
1c79356b 520
0a7de745
A
521typedef struct{
522 mach_msg_trailer_type_t msgh_trailer_type;
523 mach_msg_trailer_size_t msgh_trailer_size;
524 mach_port_seqno_t msgh_seqno;
525 security_token_t msgh_sender;
526 audit_token_t msgh_audit;
527 mach_port_context_t msgh_context;
b0d623f7
A
528} mach_msg_context_trailer_t;
529
5ba3f43e 530#if defined(MACH_KERNEL_PRIVATE) && defined(__arm64__)
0a7de745
A
531typedef struct{
532 mach_msg_trailer_type_t msgh_trailer_type;
533 mach_msg_trailer_size_t msgh_trailer_size;
534 mach_port_seqno_t msgh_seqno;
535 security_token_t msgh_sender;
536 audit_token_t msgh_audit;
537 mach_port_context32_t msgh_context;
5ba3f43e
A
538} mach_msg_context_trailer32_t;
539
0a7de745
A
540typedef struct{
541 mach_msg_trailer_type_t msgh_trailer_type;
542 mach_msg_trailer_size_t msgh_trailer_size;
543 mach_port_seqno_t msgh_seqno;
544 security_token_t msgh_sender;
545 audit_token_t msgh_audit;
546 mach_port_context64_t msgh_context;
5ba3f43e
A
547} mach_msg_context_trailer64_t;
548#endif
fe8ab488
A
549
550
0a7de745
A
551typedef struct{
552 mach_port_name_t sender;
2d21ac55
A
553} msg_labels_t;
554
0a7de745
A
555/*
556 * Trailer type to pass MAC policy label info as a mach message trailer.
557 *
558 */
559
560typedef struct{
561 mach_msg_trailer_type_t msgh_trailer_type;
562 mach_msg_trailer_size_t msgh_trailer_size;
563 mach_port_seqno_t msgh_seqno;
564 security_token_t msgh_sender;
565 audit_token_t msgh_audit;
566 mach_port_context_t msgh_context;
567 int msgh_ad;
568 msg_labels_t msgh_labels;
2d21ac55
A
569} mach_msg_mac_trailer_t;
570
5ba3f43e 571#if defined(MACH_KERNEL_PRIVATE) && defined(__arm64__)
0a7de745
A
572typedef struct{
573 mach_msg_trailer_type_t msgh_trailer_type;
574 mach_msg_trailer_size_t msgh_trailer_size;
575 mach_port_seqno_t msgh_seqno;
576 security_token_t msgh_sender;
577 audit_token_t msgh_audit;
578 mach_port_context32_t msgh_context;
579 int msgh_ad;
580 msg_labels_t msgh_labels;
5ba3f43e
A
581} mach_msg_mac_trailer32_t;
582
0a7de745
A
583typedef struct{
584 mach_msg_trailer_type_t msgh_trailer_type;
585 mach_msg_trailer_size_t msgh_trailer_size;
586 mach_port_seqno_t msgh_seqno;
587 security_token_t msgh_sender;
588 audit_token_t msgh_audit;
589 mach_port_context64_t msgh_context;
590 int msgh_ad;
591 msg_labels_t msgh_labels;
5ba3f43e
A
592} mach_msg_mac_trailer64_t;
593
594#endif
fe8ab488 595
1c79356b 596#define MACH_MSG_TRAILER_MINIMUM_SIZE sizeof(mach_msg_trailer_t)
55e303ae
A
597
598/*
599 * These values can change from release to release - but clearly
600 * code cannot request additional trailer elements one was not
601 * compiled to understand. Therefore, it is safe to use this
602 * constant when the same module specified the receive options.
603 * Otherwise, you run the risk that the options requested by
604 * another module may exceed the local modules notion of
605 * MAX_TRAILER_SIZE.
606 */
5ba3f43e
A
607#if defined(MACH_KERNEL_PRIVATE) && defined(__arm64__)
608typedef mach_msg_mac_trailer64_t mach_msg_max_trailer64_t;
609typedef mach_msg_mac_trailer32_t mach_msg_max_trailer32_t;
610#endif
39236c6e 611
2d21ac55 612typedef mach_msg_mac_trailer_t mach_msg_max_trailer_t;
b0d623f7 613#define MAX_TRAILER_SIZE ((mach_msg_size_t)sizeof(mach_msg_max_trailer_t))
55e303ae
A
614
615/*
616 * Legacy requirements keep us from ever updating these defines (even
617 * when the format_0 trailers gain new option data fields in the future).
618 * Therefore, they shouldn't be used going forward. Instead, the sizes
619 * should be compared against the specific element size requested using
620 * REQUESTED_TRAILER_SIZE.
621 */
622typedef mach_msg_security_trailer_t mach_msg_format_0_trailer_t;
2d21ac55
A
623
624/*typedef mach_msg_mac_trailer_t mach_msg_format_0_trailer_t;
0a7de745 625 */
2d21ac55 626
55e303ae 627#define MACH_MSG_TRAILER_FORMAT_0_SIZE sizeof(mach_msg_format_0_trailer_t)
1c79356b
A
628
629#define KERNEL_SECURITY_TOKEN_VALUE { {0, 1} }
cb323159 630extern const security_token_t KERNEL_SECURITY_TOKEN;
1c79356b 631
55e303ae 632#define KERNEL_AUDIT_TOKEN_VALUE { {0, 0, 0, 0, 0, 0, 0, 0} }
cb323159 633extern const audit_token_t KERNEL_AUDIT_TOKEN;
55e303ae 634
0a7de745 635typedef integer_t mach_msg_options_t;
1c79356b 636
0a7de745
A
637typedef struct{
638 mach_msg_header_t header;
1c79356b
A
639} mach_msg_empty_send_t;
640
0a7de745
A
641typedef struct{
642 mach_msg_header_t header;
643 mach_msg_trailer_t trailer;
1c79356b
A
644} mach_msg_empty_rcv_t;
645
0a7de745
A
646typedef union{
647 mach_msg_empty_send_t send;
648 mach_msg_empty_rcv_t rcv;
1c79356b
A
649} mach_msg_empty_t;
650
cb323159 651#pragma pack(pop)
91447636 652
1c79356b 653/* utility to round the message size - will become machine dependent */
0a7de745
A
654#define round_msg(x) (((mach_msg_size_t)(x) + sizeof (natural_t) - 1) & \
655 ~(sizeof (natural_t) - 1))
1c79356b 656
eb6b6ca3
A
657#ifdef XNU_KERNEL_PRIVATE
658
659#include <os/base.h>
660#include <os/overflow.h>
661#include <kern/debug.h>
662
663#define round_msg_overflow(in, out) __os_warn_unused(({ \
664 bool __ovr = os_add_overflow(in, (__typeof__(*out))(sizeof(natural_t) - 1), out); \
665 *out &= ~((__typeof__(*out))(sizeof(natural_t) - 1)); \
666 __ovr; \
667 }))
668
669static inline mach_msg_size_t
670mach_round_msg(mach_msg_size_t x)
671{
672 if (round_msg_overflow(x, &x)) {
673 panic("round msg overflow");
674 }
675 return x;
676}
677#endif /* XNU_KERNEL_PRIVATE */
678
1c79356b
A
679/*
680 * There is no fixed upper bound to the size of Mach messages.
681 */
0a7de745 682#define MACH_MSG_SIZE_MAX ((mach_msg_size_t) ~0)
1c79356b 683
316670eb
A
684#if defined(__APPLE_API_PRIVATE)
685/*
686 * But architectural limits of a given implementation, or
687 * temporal conditions may cause unpredictable send failures
688 * for messages larger than MACH_MSG_SIZE_RELIABLE.
689 *
690 * In either case, waiting for memory is [currently] outside
691 * the scope of send timeout values provided to IPC.
692 */
0a7de745 693#define MACH_MSG_SIZE_RELIABLE ((mach_msg_size_t) 256 * 1024)
316670eb 694#endif
1c79356b
A
695/*
696 * Compatibility definitions, for code written
697 * when there was a msgh_kind instead of msgh_seqno.
698 */
0a7de745
A
699#define MACH_MSGH_KIND_NORMAL 0x00000000
700#define MACH_MSGH_KIND_NOTIFICATION 0x00000001
701#define msgh_kind msgh_seqno
702#define mach_msg_kind_t mach_port_seqno_t
1c79356b 703
1c79356b
A
704typedef natural_t mach_msg_type_size_t;
705typedef natural_t mach_msg_type_number_t;
706
707/*
708 * Values received/carried in messages. Tells the receiver what
709 * sort of port right he now has.
710 *
711 * MACH_MSG_TYPE_PORT_NAME is used to transfer a port name
712 * which should remain uninterpreted by the kernel. (Port rights
713 * are not transferred, just the port name.)
714 */
715
0a7de745 716#define MACH_MSG_TYPE_PORT_NONE 0
1c79356b 717
0a7de745
A
718#define MACH_MSG_TYPE_PORT_NAME 15
719#define MACH_MSG_TYPE_PORT_RECEIVE MACH_MSG_TYPE_MOVE_RECEIVE
720#define MACH_MSG_TYPE_PORT_SEND MACH_MSG_TYPE_MOVE_SEND
721#define MACH_MSG_TYPE_PORT_SEND_ONCE MACH_MSG_TYPE_MOVE_SEND_ONCE
1c79356b 722
0a7de745 723#define MACH_MSG_TYPE_LAST 22 /* Last assigned */
1c79356b
A
724
725/*
726 * A dummy value. Mostly used to indicate that the actual value
727 * will be filled in later, dynamically.
728 */
729
0a7de745 730#define MACH_MSG_TYPE_POLYMORPHIC ((mach_msg_type_name_t) -1)
1c79356b
A
731
732/*
733 * Is a given item a port type?
734 */
735
0a7de745
A
736#define MACH_MSG_TYPE_PORT_ANY(x) \
737 (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
1c79356b
A
738 ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
739
0a7de745
A
740#define MACH_MSG_TYPE_PORT_ANY_SEND(x) \
741 (((x) >= MACH_MSG_TYPE_MOVE_SEND) && \
1c79356b
A
742 ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
743
0a7de745
A
744#define MACH_MSG_TYPE_PORT_ANY_RIGHT(x) \
745 (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
1c79356b
A
746 ((x) <= MACH_MSG_TYPE_MOVE_SEND_ONCE))
747
748typedef integer_t mach_msg_option_t;
749
0a7de745 750#define MACH_MSG_OPTION_NONE 0x00000000
1c79356b 751
0a7de745
A
752#define MACH_SEND_MSG 0x00000001
753#define MACH_RCV_MSG 0x00000002
1c79356b 754
0a7de745
A
755#define MACH_RCV_LARGE 0x00000004 /* report large message sizes */
756#define MACH_RCV_LARGE_IDENTITY 0x00000008 /* identify source of large messages */
39236c6e 757
0a7de745 758#define MACH_SEND_TIMEOUT 0x00000010 /* timeout value applies to send */
cb323159 759#define MACH_SEND_OVERRIDE 0x00000020 /* priority override for send */
0a7de745
A
760#define MACH_SEND_INTERRUPT 0x00000040 /* don't restart interrupted sends */
761#define MACH_SEND_NOTIFY 0x00000080 /* arm send-possible notify */
762#define MACH_SEND_ALWAYS 0x00010000 /* ignore qlimits - kernel only */
763#define MACH_SEND_TRAILER 0x00020000 /* sender-provided trailer */
39236c6e 764#define MACH_SEND_NOIMPORTANCE 0x00040000 /* msg won't carry importance */
0a7de745
A
765#define MACH_SEND_NODENAP MACH_SEND_NOIMPORTANCE
766#define MACH_SEND_IMPORTANCE 0x00080000 /* msg carries importance - kernel only */
767#define MACH_SEND_SYNC_OVERRIDE 0x00100000 /* msg should do sync ipc override */
cb323159 768#define MACH_SEND_PROPAGATE_QOS 0x00200000 /* IPC should propagate the caller's QoS */
0a7de745 769#define MACH_SEND_SYNC_USE_THRPRI MACH_SEND_PROPAGATE_QOS /* obsolete name */
cb323159
A
770#define MACH_SEND_KERNEL 0x00400000 /* full send from kernel space - kernel only */
771#define MACH_SEND_SYNC_BOOTSTRAP_CHECKIN 0x00800000 /* special reply port should boost thread doing sync bootstrap checkin */
39236c6e 772
0a7de745 773#define MACH_RCV_TIMEOUT 0x00000100 /* timeout value applies to receive */
cb323159 774#define MACH_RCV_NOTIFY 0x00000000 /* legacy name (value was: 0x00000200) */
0a7de745
A
775#define MACH_RCV_INTERRUPT 0x00000400 /* don't restart interrupted receive */
776#define MACH_RCV_VOUCHER 0x00000800 /* willing to receive voucher port */
cb323159
A
777#define MACH_RCV_OVERWRITE 0x00000000 /* scatter receive (deprecated) */
778#define MACH_RCV_GUARDED_DESC 0x00001000 /* Can receive new guarded descriptor */
0a7de745 779#define MACH_RCV_SYNC_WAIT 0x00004000 /* sync waiter waiting for rcv */
cb323159
A
780#define MACH_RCV_SYNC_PEEK 0x00008000 /* sync waiter waiting to peek */
781
782#define MACH_MSG_STRICT_REPLY 0x00000200 /* Enforce specific properties about the reply port, and
783 * the context in which a thread replies to a message.
784 * This flag must be passed on both the SEND and RCV */
1c79356b 785
39037602
A
786#ifdef XNU_KERNEL_PRIVATE
787
0a7de745 788#define MACH_RCV_STACK 0x00002000 /* receive into highest addr of buffer */
39037602
A
789
790/*
791 * NOTE:
792 * This internal-only flag is intended for use by a single thread per-port/set!
793 * If more than one thread attempts to MACH_PEEK_MSG on a port or set, one of
794 * the threads may miss messages (in fact, it may never wake up).
795 */
0a7de745 796#define MACH_PEEK_MSG 0x80000000 /* receive, but leave msgs queued */
39037602
A
797
798#endif
799
0a7de745 800/*
1c79356b 801 * NOTE: a 0x00------ RCV mask implies to ask for
0a7de745 802 * a MACH_MSG_TRAILER_FORMAT_0 with 0 Elements,
1c79356b 803 * which is equivalent to a mach_msg_trailer_t.
2d21ac55
A
804 *
805 * XXXMAC: unlike the rest of the MACH_RCV_* flags, MACH_RCV_TRAILER_LABELS
0a7de745 806 * needs its own private bit since we only calculate its fields when absolutely
b0d623f7 807 * required.
1c79356b
A
808 */
809#define MACH_RCV_TRAILER_NULL 0
810#define MACH_RCV_TRAILER_SEQNO 1
811#define MACH_RCV_TRAILER_SENDER 2
55e303ae 812#define MACH_RCV_TRAILER_AUDIT 3
b0d623f7
A
813#define MACH_RCV_TRAILER_CTX 4
814#define MACH_RCV_TRAILER_AV 7
815#define MACH_RCV_TRAILER_LABELS 8
1c79356b 816
0a7de745
A
817#define MACH_RCV_TRAILER_TYPE(x) (((x) & 0xf) << 28)
818#define MACH_RCV_TRAILER_ELEMENTS(x) (((x) & 0xf) << 24)
819#define MACH_RCV_TRAILER_MASK ((0xf << 24))
1c79356b 820
1c79356b 821#define GET_RCV_ELEMENTS(y) (((y) >> 24) & 0xf)
2d21ac55 822
39236c6e
A
823#ifdef MACH_KERNEL_PRIVATE
824/* The options that the kernel honors when passed from user space */
39037602 825#define MACH_SEND_USER (MACH_SEND_MSG | MACH_SEND_TIMEOUT | \
0a7de745
A
826 MACH_SEND_NOTIFY | MACH_SEND_OVERRIDE | \
827 MACH_SEND_TRAILER | MACH_SEND_NOIMPORTANCE | \
cb323159
A
828 MACH_SEND_SYNC_OVERRIDE | MACH_SEND_PROPAGATE_QOS | \
829 MACH_SEND_SYNC_BOOTSTRAP_CHECKIN | \
830 MACH_MSG_STRICT_REPLY | MACH_RCV_GUARDED_DESC)
39236c6e 831
39037602 832#define MACH_RCV_USER (MACH_RCV_MSG | MACH_RCV_TIMEOUT | \
0a7de745
A
833 MACH_RCV_LARGE | MACH_RCV_LARGE_IDENTITY | \
834 MACH_RCV_VOUCHER | MACH_RCV_TRAILER_MASK | \
cb323159
A
835 MACH_RCV_SYNC_WAIT | MACH_RCV_SYNC_PEEK | \
836 MACH_RCV_GUARDED_DESC | MACH_MSG_STRICT_REPLY)
39236c6e 837
0a7de745 838#define MACH_MSG_OPTION_USER (MACH_SEND_USER | MACH_RCV_USER)
39236c6e
A
839
840/* The options implemented by the library interface to mach_msg et. al. */
0a7de745 841#define MACH_MSG_OPTION_LIB (MACH_SEND_INTERRUPT | MACH_RCV_INTERRUPT)
39236c6e 842
490019cf
A
843/*
844 * Default options to use when sending from the kernel.
845 *
846 * Until we are sure of its effects, we are disabling
847 * importance donation from the kernel-side of user
848 * threads in importance-donating tasks.
849 * (11938665 & 23925818)
850 */
39236c6e 851#define MACH_SEND_KERNEL_DEFAULT (MACH_SEND_MSG | \
0a7de745 852 MACH_SEND_ALWAYS | MACH_SEND_NOIMPORTANCE)
39236c6e 853
cb323159
A
854#define MACH_SEND_WITH_STRICT_REPLY(_opts) (((_opts) & (MACH_MSG_STRICT_REPLY | MACH_SEND_MSG)) == \
855 (MACH_MSG_STRICT_REPLY | MACH_SEND_MSG))
856
857#define MACH_SEND_REPLY_IS_IMMOVABLE(_opts) (((_opts) & (MACH_MSG_STRICT_REPLY | \
858 MACH_SEND_MSG | MACH_RCV_MSG | \
859 MACH_RCV_GUARDED_DESC)) == \
860 (MACH_MSG_STRICT_REPLY | MACH_SEND_MSG | MACH_RCV_GUARDED_DESC))
861
862#define MACH_RCV_WITH_STRICT_REPLY(_opts) (((_opts) & (MACH_MSG_STRICT_REPLY | MACH_RCV_MSG)) == \
863 (MACH_MSG_STRICT_REPLY | MACH_RCV_MSG))
864
865#define MACH_RCV_WITH_IMMOVABLE_REPLY(_opts) (((_opts) & (MACH_MSG_STRICT_REPLY | \
866 MACH_RCV_MSG | MACH_RCV_GUARDED_DESC)) == \
867 (MACH_MSG_STRICT_REPLY | MACH_RCV_MSG | MACH_RCV_GUARDED_DESC))
868
39236c6e
A
869#endif /* MACH_KERNEL_PRIVATE */
870
0a7de745
A
871/*
872 * XXXMAC: note that in the case of MACH_RCV_TRAILER_LABELS,
b0d623f7 873 * we just fall through to mach_msg_max_trailer_t.
2d21ac55 874 * This is correct behavior since mach_msg_max_trailer_t is defined as
b0d623f7 875 * mac_msg_mac_trailer_t which is used for the LABELS trailer.
0a7de745 876 * It also makes things work properly if MACH_RCV_TRAILER_LABELS is ORed
b0d623f7 877 * with one of the other options.
2d21ac55 878 */
316670eb 879
0a7de745
A
880#define REQUESTED_TRAILER_SIZE_NATIVE(y) \
881 ((mach_msg_trailer_size_t) \
882 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_NULL) ? \
883 sizeof(mach_msg_trailer_t) : \
884 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SEQNO) ? \
885 sizeof(mach_msg_seqno_trailer_t) : \
886 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SENDER) ? \
887 sizeof(mach_msg_security_trailer_t) : \
888 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AUDIT) ? \
889 sizeof(mach_msg_audit_trailer_t) : \
890 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_CTX) ? \
891 sizeof(mach_msg_context_trailer_t) : \
892 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AV) ? \
893 sizeof(mach_msg_mac_trailer_t) : \
b0d623f7 894 sizeof(mach_msg_max_trailer_t))))))))
2d21ac55 895
316670eb
A
896
897#ifdef XNU_KERNEL_PRIVATE
898
5ba3f43e 899#if defined(__arm64__)
0a7de745
A
900#define REQUESTED_TRAILER_SIZE(is64, y) \
901 ((mach_msg_trailer_size_t) \
902 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_NULL) ? \
903 sizeof(mach_msg_trailer_t) : \
904 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SEQNO) ? \
905 sizeof(mach_msg_seqno_trailer_t) : \
906 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SENDER) ? \
907 sizeof(mach_msg_security_trailer_t) : \
908 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AUDIT) ? \
909 sizeof(mach_msg_audit_trailer_t) : \
910 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_CTX) ? \
5ba3f43e 911 ((is64) ? sizeof(mach_msg_context_trailer64_t) : sizeof(mach_msg_context_trailer32_t)) : \
0a7de745 912 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AV) ? \
5ba3f43e
A
913 ((is64) ? sizeof(mach_msg_mac_trailer64_t) : sizeof(mach_msg_mac_trailer32_t)) : \
914 sizeof(mach_msg_max_trailer_t))))))))
915#else
316670eb 916#define REQUESTED_TRAILER_SIZE(is64, y) REQUESTED_TRAILER_SIZE_NATIVE(y)
5ba3f43e 917#endif
316670eb
A
918
919#else /* XNU_KERNEL_PRIVATE */
920#define REQUESTED_TRAILER_SIZE(y) REQUESTED_TRAILER_SIZE_NATIVE(y)
921#endif /* XNU_KERNEL_PRIVATE */
922
1c79356b
A
923/*
924 * Much code assumes that mach_msg_return_t == kern_return_t.
925 * This definition is useful for descriptive purposes.
926 *
927 * See <mach/error.h> for the format of error codes.
928 * IPC errors are system 4. Send errors are subsystem 0;
929 * receive errors are subsystem 1. The code field is always non-zero.
930 * The high bits of the code field communicate extra information
931 * for some error codes. MACH_MSG_MASK masks off these special bits.
932 */
933
934typedef kern_return_t mach_msg_return_t;
935
0a7de745
A
936#define MACH_MSG_SUCCESS 0x00000000
937
938
939#define MACH_MSG_MASK 0x00003e00
940/* All special error code bits defined below. */
941#define MACH_MSG_IPC_SPACE 0x00002000
942/* No room in IPC name space for another capability name. */
943#define MACH_MSG_VM_SPACE 0x00001000
944/* No room in VM address space for out-of-line memory. */
945#define MACH_MSG_IPC_KERNEL 0x00000800
946/* Kernel resource shortage handling an IPC capability. */
947#define MACH_MSG_VM_KERNEL 0x00000400
948/* Kernel resource shortage handling out-of-line memory. */
949
950#define MACH_SEND_IN_PROGRESS 0x10000001
951/* Thread is waiting to send. (Internal use only.) */
952#define MACH_SEND_INVALID_DATA 0x10000002
953/* Bogus in-line data. */
954#define MACH_SEND_INVALID_DEST 0x10000003
955/* Bogus destination port. */
956#define MACH_SEND_TIMED_OUT 0x10000004
957/* Message not sent before timeout expired. */
958#define MACH_SEND_INVALID_VOUCHER 0x10000005
959/* Bogus voucher port. */
960#define MACH_SEND_INTERRUPTED 0x10000007
961/* Software interrupt. */
962#define MACH_SEND_MSG_TOO_SMALL 0x10000008
963/* Data doesn't contain a complete message. */
964#define MACH_SEND_INVALID_REPLY 0x10000009
965/* Bogus reply port. */
966#define MACH_SEND_INVALID_RIGHT 0x1000000a
967/* Bogus port rights in the message body. */
968#define MACH_SEND_INVALID_NOTIFY 0x1000000b
969/* Bogus notify port argument. */
970#define MACH_SEND_INVALID_MEMORY 0x1000000c
971/* Invalid out-of-line memory pointer. */
972#define MACH_SEND_NO_BUFFER 0x1000000d
973/* No message buffer is available. */
974#define MACH_SEND_TOO_LARGE 0x1000000e
975/* Send is too large for port */
976#define MACH_SEND_INVALID_TYPE 0x1000000f
977/* Invalid msg-type specification. */
978#define MACH_SEND_INVALID_HEADER 0x10000010
979/* A field in the header had a bad value. */
980#define MACH_SEND_INVALID_TRAILER 0x10000011
981/* The trailer to be sent does not match kernel format. */
cb323159
A
982#define MACH_SEND_INVALID_CONTEXT 0x10000012
983/* The sending thread context did not match the context on the dest port */
0a7de745
A
984#define MACH_SEND_INVALID_RT_OOL_SIZE 0x10000015
985/* compatibility: no longer a returned error */
cb323159
A
986#define MACH_SEND_NO_GRANT_DEST 0x10000016
987/* The destination port doesn't accept ports in body */
0a7de745
A
988
989#define MACH_RCV_IN_PROGRESS 0x10004001
990/* Thread is waiting for receive. (Internal use only.) */
991#define MACH_RCV_INVALID_NAME 0x10004002
992/* Bogus name for receive port/port-set. */
993#define MACH_RCV_TIMED_OUT 0x10004003
994/* Didn't get a message within the timeout value. */
995#define MACH_RCV_TOO_LARGE 0x10004004
996/* Message buffer is not large enough for inline data. */
997#define MACH_RCV_INTERRUPTED 0x10004005
998/* Software interrupt. */
999#define MACH_RCV_PORT_CHANGED 0x10004006
1000/* compatibility: no longer a returned error */
1001#define MACH_RCV_INVALID_NOTIFY 0x10004007
1002/* Bogus notify port argument. */
1003#define MACH_RCV_INVALID_DATA 0x10004008
1004/* Bogus message buffer for inline data. */
1005#define MACH_RCV_PORT_DIED 0x10004009
1006/* Port/set was sent away/died during receive. */
1007#define MACH_RCV_IN_SET 0x1000400a
1008/* compatibility: no longer a returned error */
1009#define MACH_RCV_HEADER_ERROR 0x1000400b
1010/* Error receiving message header. See special bits. */
1011#define MACH_RCV_BODY_ERROR 0x1000400c
1012/* Error receiving message body. See special bits. */
1013#define MACH_RCV_INVALID_TYPE 0x1000400d
1014/* Invalid msg-type specification in scatter list. */
1015#define MACH_RCV_SCATTER_SMALL 0x1000400e
1016/* Out-of-line overwrite region is not large enough */
1017#define MACH_RCV_INVALID_TRAILER 0x1000400f
1018/* trailer type or number of trailer elements not supported */
1c79356b 1019#define MACH_RCV_IN_PROGRESS_TIMED 0x10004011
0a7de745 1020/* Waiting for receive with timeout. (Internal use only.) */
cb323159
A
1021#define MACH_RCV_INVALID_REPLY 0x10004012
1022/* invalid reply port used in a STRICT_REPLY message */
1c79356b 1023
39037602 1024#ifdef XNU_KERNEL_PRIVATE
0a7de745
A
1025#define MACH_PEEK_IN_PROGRESS 0x10008001
1026/* Waiting for a peek. (Internal use only.) */
1027#define MACH_PEEK_READY 0x10008002
1028/* Waiting for a peek. (Internal use only.) */
39037602
A
1029#endif
1030
91447636
A
1031
1032__BEGIN_DECLS
1033
9bccf70c
A
1034/*
1035 * Routine: mach_msg_overwrite
1036 * Purpose:
1037 * Send and/or receive a message. If the message operation
1038 * is interrupted, and the user did not request an indication
1039 * of that fact, then restart the appropriate parts of the
1040 * operation silently (trap version does not restart).
1041 *
1042 * Distinct send and receive buffers may be specified. If
1043 * no separate receive buffer is specified, the msg parameter
1044 * will be used for both send and receive operations.
1045 *
1046 * In addition to a distinct receive buffer, that buffer may
1047 * already contain scatter control information to direct the
1048 * receiving of the message.
1049 */
3e170ce0 1050__WATCHOS_PROHIBITED __TVOS_PROHIBITED
0a7de745
A
1051extern mach_msg_return_t mach_msg_overwrite(
1052 mach_msg_header_t *msg,
1053 mach_msg_option_t option,
1054 mach_msg_size_t send_size,
1055 mach_msg_size_t rcv_size,
1056 mach_port_name_t rcv_name,
1057 mach_msg_timeout_t timeout,
1058 mach_port_name_t notify,
1059 mach_msg_header_t *rcv_msg,
1060 mach_msg_size_t rcv_limit);
1061
1062#ifndef KERNEL
91447636 1063
9bccf70c
A
1064/*
1065 * Routine: mach_msg
1066 * Purpose:
1067 * Send and/or receive a message. If the message operation
1068 * is interrupted, and the user did not request an indication
1069 * of that fact, then restart the appropriate parts of the
1070 * operation silently (trap version does not restart).
1071 */
3e170ce0 1072__WATCHOS_PROHIBITED __TVOS_PROHIBITED
0a7de745
A
1073extern mach_msg_return_t mach_msg(
1074 mach_msg_header_t *msg,
1075 mach_msg_option_t option,
1076 mach_msg_size_t send_size,
1077 mach_msg_size_t rcv_size,
1078 mach_port_name_t rcv_name,
1079 mach_msg_timeout_t timeout,
1080 mach_port_name_t notify);
1c79356b 1081
fe8ab488
A
1082/*
1083 * Routine: mach_voucher_deallocate
1084 * Purpose:
1085 * Deallocate a mach voucher created or received in a message. Drops
1086 * one (send right) reference to the voucher.
1087 */
3e170ce0 1088__WATCHOS_PROHIBITED __TVOS_PROHIBITED
0a7de745
A
1089extern kern_return_t mach_voucher_deallocate(
1090 mach_port_name_t voucher);
fe8ab488 1091
b0d623f7
A
1092#elif defined(MACH_KERNEL_PRIVATE)
1093
0a7de745 1094extern mach_msg_return_t mach_msg_receive_results(mach_msg_size_t *size);
b0d623f7 1095
0a7de745 1096#endif /* KERNEL */
91447636
A
1097
1098__END_DECLS
1099
0a7de745 1100#endif /* _MACH_MESSAGE_H_ */