]> git.saurik.com Git - apple/xnu.git/blame - osfmk/mach/message.h
xnu-3789.51.2.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@
1c79356b 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.
8f6c56a5 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.
17 *
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
31/*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
35 *
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.
41 *
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.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
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
71#ifndef _MACH_MESSAGE_H_
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
98#define MACH_MSG_TIMEOUT_NONE ((mach_msg_timeout_t) 0)
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
132#define MACH_MSGH_BITS_ZERO 0x00000000
1c79356b 133
fe8ab488
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
137
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)
142
143#define MACH_MSGH_BITS_COMPLEX 0x80000000U /* message is complex */
144
145#define MACH_MSGH_BITS_USER 0x801f1f1fU /* allowed bits user->kernel */
146
147#define MACH_MSGH_BITS_RAISEIMP 0x20000000U /* importance raised due to msg */
148#define MACH_MSGH_BITS_DENAP MACH_MSGH_BITS_RAISEIMP
1c79356b 149
fe8ab488
A
150#define MACH_MSGH_BITS_IMPHOLDASRT 0x10000000U /* assertion help, userland private */
151#define MACH_MSGH_BITS_DENAPHOLDASRT MACH_MSGH_BITS_IMPHOLDASRT
1c79356b 152
fe8ab488
A
153#define MACH_MSGH_BITS_CIRCULAR 0x10000000U /* message circular, kernel private */
154
155#define MACH_MSGH_BITS_USED 0xb01f1f1fU
156
157/* setter macros for the bits */
158#define MACH_MSGH_BITS(remote, local) /* legacy */ \
1c79356b 159 ((remote) | ((local) << 8))
fe8ab488
A
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) | \
163 (((voucher) << 16) & MACH_MSGH_BITS_VOUCHER_MASK))
164#define MACH_MSGH_BITS_SET(remote, local, voucher, other) \
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 */
1c79356b
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)
fe8ab488
A
173#define MACH_MSGH_BITS_VOUCHER(bits) \
174 (((bits) & MACH_MSGH_BITS_VOUCHER_MASK) >> 16)
1c79356b 175#define MACH_MSGH_BITS_PORTS(bits) \
fe8ab488 176 ((bits) & MACH_MSGH_BITS_PORTS_MASK)
1c79356b
A
177#define MACH_MSGH_BITS_OTHER(bits) \
178 ((bits) &~ MACH_MSGH_BITS_PORTS_MASK)
179
fe8ab488
A
180/* checking macros */
181#define MACH_MSGH_BITS_HAS_REMOTE(bits) \
182 (MACH_MSGH_BITS_REMOTE(bits) != MACH_MSGH_BITS_ZERO)
183#define MACH_MSGH_BITS_HAS_LOCAL(bits) \
184 (MACH_MSGH_BITS_LOCAL(bits) != MACH_MSGH_BITS_ZERO)
185#define MACH_MSGH_BITS_HAS_VOUCHER(bits) \
186 (MACH_MSGH_BITS_VOUCHER(bits) != MACH_MSGH_BITS_ZERO)
187#define MACH_MSGH_BITS_IS_COMPLEX(bits) \
188 (((bits) & MACH_MSGH_BITS_COMPLEX) != MACH_MSGH_BITS_ZERO)
189
190/* importance checking macros */
191#define MACH_MSGH_BITS_RAISED_IMPORTANCE(bits) \
192 (((bits) & MACH_MSGH_BITS_RAISEIMP) != MACH_MSGH_BITS_ZERO)
193#define MACH_MSGH_BITS_HOLDS_IMPORTANCE_ASSERTION(bits) \
194 (((bits) & MACH_MSGH_BITS_IMPHOLDASRT) != MACH_MSGH_BITS_ZERO)
195
1c79356b
A
196/*
197 * Every message starts with a message header.
b0d623f7
A
198 * Following the message header, if the message is complex, are a count
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,
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;
222typedef natural_t mach_msg_size_t;
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
39037602
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) */
fe8ab488 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
246#define MACH_MSG_PHYSICAL_COPY 0
247#define MACH_MSG_VIRTUAL_COPY 1
248#define MACH_MSG_ALLOCATE 2
3e170ce0 249#define MACH_MSG_OVERWRITE 3 /* deprecated */
1c79356b
A
250#ifdef MACH_KERNEL
251#define MACH_MSG_KALLOC_COPY_T 4
1c79356b
A
252#endif /* MACH_KERNEL */
253
b0d623f7
A
254/*
255 * In a complex mach message, the mach_msg_header_t is followed by
256 * a descriptor count, then an array of that number of descriptors
257 * (mach_msg_*_descriptor_t). The type field of mach_msg_type_descriptor_t
258 * (which any descriptor can be cast to) indicates the flavor of the
259 * descriptor.
260 *
261 * Note that in LP64, the various types of descriptors are no longer all
262 * the same size as mach_msg_descriptor_t, so the array cannot be indexed
263 * as expected.
264 */
265
1c79356b
A
266typedef unsigned int mach_msg_descriptor_type_t;
267
268#define MACH_MSG_PORT_DESCRIPTOR 0
269#define MACH_MSG_OOL_DESCRIPTOR 1
270#define MACH_MSG_OOL_PORTS_DESCRIPTOR 2
271#define MACH_MSG_OOL_VOLATILE_DESCRIPTOR 3
272
91447636 273#pragma pack(4)
1c79356b
A
274
275typedef struct
276{
91447636 277 natural_t pad1;
1c79356b
A
278 mach_msg_size_t pad2;
279 unsigned int pad3 : 24;
280 mach_msg_descriptor_type_t type : 8;
281} mach_msg_type_descriptor_t;
282
283typedef struct
284{
285 mach_port_t name;
b0d623f7
A
286#if !(defined(KERNEL) && defined(__LP64__))
287// Pad to 8 bytes everywhere except the K64 kernel where mach_port_t is 8 bytes
1c79356b 288 mach_msg_size_t pad1;
b0d623f7 289#endif
1c79356b
A
290 unsigned int pad2 : 16;
291 mach_msg_type_name_t disposition : 8;
292 mach_msg_descriptor_type_t type : 8;
b0d623f7
A
293#if defined(KERNEL)
294 uint32_t pad_end;
295#endif
1c79356b
A
296} mach_msg_port_descriptor_t;
297
298typedef struct
299{
91447636
A
300 uint32_t address;
301 mach_msg_size_t size;
302 boolean_t deallocate: 8;
303 mach_msg_copy_options_t copy: 8;
304 unsigned int pad1: 8;
305 mach_msg_descriptor_type_t type: 8;
306} mach_msg_ool_descriptor32_t;
307
308typedef struct
309{
310 uint64_t address;
311 boolean_t deallocate: 8;
312 mach_msg_copy_options_t copy: 8;
313 unsigned int pad1: 8;
314 mach_msg_descriptor_type_t type: 8;
315 mach_msg_size_t size;
316} mach_msg_ool_descriptor64_t;
317
318typedef struct
319{
320 void* address;
321#if !defined(__LP64__)
1c79356b 322 mach_msg_size_t size;
91447636 323#endif
1c79356b
A
324 boolean_t deallocate: 8;
325 mach_msg_copy_options_t copy: 8;
326 unsigned int pad1: 8;
327 mach_msg_descriptor_type_t type: 8;
91447636
A
328#if defined(__LP64__)
329 mach_msg_size_t size;
330#endif
b0d623f7
A
331#if defined(KERNEL) && !defined(__LP64__)
332 uint32_t pad_end;
333#endif
1c79356b
A
334} mach_msg_ool_descriptor_t;
335
91447636
A
336typedef struct
337{
338 uint32_t address;
339 mach_msg_size_t count;
340 boolean_t deallocate: 8;
341 mach_msg_copy_options_t copy: 8;
342 mach_msg_type_name_t disposition : 8;
343 mach_msg_descriptor_type_t type : 8;
344} mach_msg_ool_ports_descriptor32_t;
345
346typedef struct
347{
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;
354} mach_msg_ool_ports_descriptor64_t;
355
1c79356b
A
356typedef struct
357{
358 void* address;
91447636 359#if !defined(__LP64__)
1c79356b 360 mach_msg_size_t count;
91447636 361#endif
1c79356b
A
362 boolean_t deallocate: 8;
363 mach_msg_copy_options_t copy: 8;
364 mach_msg_type_name_t disposition : 8;
365 mach_msg_descriptor_type_t type : 8;
91447636
A
366#if defined(__LP64__)
367 mach_msg_size_t count;
368#endif
b0d623f7
A
369#if defined(KERNEL) && !defined(__LP64__)
370 uint32_t pad_end;
371#endif
1c79356b
A
372} mach_msg_ool_ports_descriptor_t;
373
91447636
A
374/*
375 * LP64support - This union definition is not really
376 * appropriate in LP64 mode because not all descriptors
377 * are of the same size in that environment.
378 */
b0d623f7
A
379#if defined(__LP64__) && defined(KERNEL)
380typedef union
381{
382 mach_msg_port_descriptor_t port;
383 mach_msg_ool_descriptor32_t out_of_line;
384 mach_msg_ool_ports_descriptor32_t ool_ports;
385 mach_msg_type_descriptor_t type;
386} mach_msg_descriptor_t;
387#else
1c79356b
A
388typedef union
389{
390 mach_msg_port_descriptor_t port;
391 mach_msg_ool_descriptor_t out_of_line;
392 mach_msg_ool_ports_descriptor_t ool_ports;
393 mach_msg_type_descriptor_t type;
394} mach_msg_descriptor_t;
b0d623f7 395#endif
1c79356b
A
396
397typedef struct
398{
399 mach_msg_size_t msgh_descriptor_count;
400} mach_msg_body_t;
401
402#define MACH_MSG_BODY_NULL (mach_msg_body_t *) 0
403#define MACH_MSG_DESCRIPTOR_NULL (mach_msg_descriptor_t *) 0
404
405typedef struct
406{
407 mach_msg_bits_t msgh_bits;
408 mach_msg_size_t msgh_size;
409 mach_port_t msgh_remote_port;
410 mach_port_t msgh_local_port;
fe8ab488 411 mach_port_name_t msgh_voucher_port;
1c79356b
A
412 mach_msg_id_t msgh_id;
413} mach_msg_header_t;
414
fe8ab488
A
415#define msgh_reserved msgh_voucher_port
416#define MACH_MSG_NULL (mach_msg_header_t *) 0
1c79356b
A
417
418typedef struct
419{
420 mach_msg_header_t header;
421 mach_msg_body_t body;
422} mach_msg_base_t;
423
424typedef unsigned int mach_msg_trailer_type_t;
425
426#define MACH_MSG_TRAILER_FORMAT_0 0
427
428typedef unsigned int mach_msg_trailer_size_t;
39236c6e 429typedef char *mach_msg_trailer_info_t;
1c79356b
A
430
431typedef struct
432{
433 mach_msg_trailer_type_t msgh_trailer_type;
434 mach_msg_trailer_size_t msgh_trailer_size;
435} mach_msg_trailer_t;
436
fe8ab488
A
437/*
438 * The msgh_seqno field carries a sequence number
439 * associated with the received-from port. A port's
440 * sequence number is incremented every time a message
441 * is received from it and included in the received
442 * trailer to help put messages back in sequence if
443 * multiple threads receive and/or process received
444 * messages.
445 */
1c79356b
A
446typedef struct
447{
448 mach_msg_trailer_type_t msgh_trailer_type;
449 mach_msg_trailer_size_t msgh_trailer_size;
450 mach_port_seqno_t msgh_seqno;
451} mach_msg_seqno_trailer_t;
452
453typedef struct
454{
455 unsigned int val[2];
456} security_token_t;
457
458typedef struct
459{
460 mach_msg_trailer_type_t msgh_trailer_type;
461 mach_msg_trailer_size_t msgh_trailer_size;
462 mach_port_seqno_t msgh_seqno;
463 security_token_t msgh_sender;
464} mach_msg_security_trailer_t;
465
e5568f75
A
466/*
467 * The audit token is an opaque token which identifies
468 * Mach tasks and senders of Mach messages as subjects
469 * to the BSM audit system. Only the appropriate BSM
470 * library routines should be used to interpret the
471 * contents of the audit token as the representation
472 * of the subject identity within the token may change
473 * over time.
474 */
55e303ae
A
475typedef struct
476{
477 unsigned int val[8];
478} audit_token_t;
479
480typedef struct
481{
482 mach_msg_trailer_type_t msgh_trailer_type;
483 mach_msg_trailer_size_t msgh_trailer_size;
484 mach_port_seqno_t msgh_seqno;
485 security_token_t msgh_sender;
486 audit_token_t msgh_audit;
487} mach_msg_audit_trailer_t;
1c79356b 488
b0d623f7
A
489typedef struct
490{
491 mach_msg_trailer_type_t msgh_trailer_type;
492 mach_msg_trailer_size_t msgh_trailer_size;
493 mach_port_seqno_t msgh_seqno;
494 security_token_t msgh_sender;
495 audit_token_t msgh_audit;
316670eb 496 mach_port_context_t msgh_context;
b0d623f7
A
497} mach_msg_context_trailer_t;
498
fe8ab488
A
499
500
2d21ac55
A
501typedef struct
502{
503 mach_port_name_t sender;
504} msg_labels_t;
505
506/*
507 Trailer type to pass MAC policy label info as a mach message trailer.
508
509*/
510
511typedef struct
512{
513 mach_msg_trailer_type_t msgh_trailer_type;
514 mach_msg_trailer_size_t msgh_trailer_size;
515 mach_port_seqno_t msgh_seqno;
516 security_token_t msgh_sender;
b0d623f7 517 audit_token_t msgh_audit;
316670eb 518 mach_port_context_t msgh_context;
2d21ac55 519 int msgh_ad;
b0d623f7 520 msg_labels_t msgh_labels;
2d21ac55
A
521} mach_msg_mac_trailer_t;
522
fe8ab488 523
1c79356b 524#define MACH_MSG_TRAILER_MINIMUM_SIZE sizeof(mach_msg_trailer_t)
55e303ae
A
525
526/*
527 * These values can change from release to release - but clearly
528 * code cannot request additional trailer elements one was not
529 * compiled to understand. Therefore, it is safe to use this
530 * constant when the same module specified the receive options.
531 * Otherwise, you run the risk that the options requested by
532 * another module may exceed the local modules notion of
533 * MAX_TRAILER_SIZE.
534 */
39236c6e 535
2d21ac55 536typedef mach_msg_mac_trailer_t mach_msg_max_trailer_t;
b0d623f7 537#define MAX_TRAILER_SIZE ((mach_msg_size_t)sizeof(mach_msg_max_trailer_t))
55e303ae
A
538
539/*
540 * Legacy requirements keep us from ever updating these defines (even
541 * when the format_0 trailers gain new option data fields in the future).
542 * Therefore, they shouldn't be used going forward. Instead, the sizes
543 * should be compared against the specific element size requested using
544 * REQUESTED_TRAILER_SIZE.
545 */
546typedef mach_msg_security_trailer_t mach_msg_format_0_trailer_t;
2d21ac55
A
547
548/*typedef mach_msg_mac_trailer_t mach_msg_format_0_trailer_t;
549*/
550
55e303ae 551#define MACH_MSG_TRAILER_FORMAT_0_SIZE sizeof(mach_msg_format_0_trailer_t)
1c79356b
A
552
553#define KERNEL_SECURITY_TOKEN_VALUE { {0, 1} }
554extern security_token_t KERNEL_SECURITY_TOKEN;
555
55e303ae
A
556#define KERNEL_AUDIT_TOKEN_VALUE { {0, 0, 0, 0, 0, 0, 0, 0} }
557extern audit_token_t KERNEL_AUDIT_TOKEN;
558
1c79356b
A
559typedef integer_t mach_msg_options_t;
560
561typedef struct
562{
563 mach_msg_header_t header;
564} mach_msg_empty_send_t;
565
566typedef struct
567{
568 mach_msg_header_t header;
569 mach_msg_trailer_t trailer;
570} mach_msg_empty_rcv_t;
571
572typedef union
573{
574 mach_msg_empty_send_t send;
575 mach_msg_empty_rcv_t rcv;
576} mach_msg_empty_t;
577
91447636
A
578#pragma pack()
579
1c79356b
A
580/* utility to round the message size - will become machine dependent */
581#define round_msg(x) (((mach_msg_size_t)(x) + sizeof (natural_t) - 1) & \
582 ~(sizeof (natural_t) - 1))
583
584/*
585 * There is no fixed upper bound to the size of Mach messages.
586 */
1c79356b
A
587#define MACH_MSG_SIZE_MAX ((mach_msg_size_t) ~0)
588
316670eb
A
589#if defined(__APPLE_API_PRIVATE)
590/*
591 * But architectural limits of a given implementation, or
592 * temporal conditions may cause unpredictable send failures
593 * for messages larger than MACH_MSG_SIZE_RELIABLE.
594 *
595 * In either case, waiting for memory is [currently] outside
596 * the scope of send timeout values provided to IPC.
597 */
598#define MACH_MSG_SIZE_RELIABLE ((mach_msg_size_t) 256 * 1024)
599#endif
1c79356b
A
600/*
601 * Compatibility definitions, for code written
602 * when there was a msgh_kind instead of msgh_seqno.
603 */
1c79356b 604#define MACH_MSGH_KIND_NORMAL 0x00000000
1c79356b 605#define MACH_MSGH_KIND_NOTIFICATION 0x00000001
1c79356b
A
606#define msgh_kind msgh_seqno
607#define mach_msg_kind_t mach_port_seqno_t
608
1c79356b
A
609typedef natural_t mach_msg_type_size_t;
610typedef natural_t mach_msg_type_number_t;
611
612/*
613 * Values received/carried in messages. Tells the receiver what
614 * sort of port right he now has.
615 *
616 * MACH_MSG_TYPE_PORT_NAME is used to transfer a port name
617 * which should remain uninterpreted by the kernel. (Port rights
618 * are not transferred, just the port name.)
619 */
620
621#define MACH_MSG_TYPE_PORT_NONE 0
622
623#define MACH_MSG_TYPE_PORT_NAME 15
624#define MACH_MSG_TYPE_PORT_RECEIVE MACH_MSG_TYPE_MOVE_RECEIVE
625#define MACH_MSG_TYPE_PORT_SEND MACH_MSG_TYPE_MOVE_SEND
626#define MACH_MSG_TYPE_PORT_SEND_ONCE MACH_MSG_TYPE_MOVE_SEND_ONCE
627
628#define MACH_MSG_TYPE_LAST 22 /* Last assigned */
629
630/*
631 * A dummy value. Mostly used to indicate that the actual value
632 * will be filled in later, dynamically.
633 */
634
635#define MACH_MSG_TYPE_POLYMORPHIC ((mach_msg_type_name_t) -1)
636
637/*
638 * Is a given item a port type?
639 */
640
641#define MACH_MSG_TYPE_PORT_ANY(x) \
642 (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
643 ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
644
645#define MACH_MSG_TYPE_PORT_ANY_SEND(x) \
646 (((x) >= MACH_MSG_TYPE_MOVE_SEND) && \
647 ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
648
649#define MACH_MSG_TYPE_PORT_ANY_RIGHT(x) \
650 (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
651 ((x) <= MACH_MSG_TYPE_MOVE_SEND_ONCE))
652
653typedef integer_t mach_msg_option_t;
654
655#define MACH_MSG_OPTION_NONE 0x00000000
656
657#define MACH_SEND_MSG 0x00000001
658#define MACH_RCV_MSG 0x00000002
1c79356b 659
39236c6e
A
660#define MACH_RCV_LARGE 0x00000004 /* report large message sizes */
661#define MACH_RCV_LARGE_IDENTITY 0x00000008 /* identify source of large messages */
662
663#define MACH_SEND_TIMEOUT 0x00000010 /* timeout value applies to send */
39037602 664#define MACH_SEND_OVERRIDE 0x00000020 /* priority override for send */
39236c6e 665#define MACH_SEND_INTERRUPT 0x00000040 /* don't restart interrupted sends */
6d2010ae 666#define MACH_SEND_NOTIFY 0x00000080 /* arm send-possible notify */
39236c6e
A
667#define MACH_SEND_ALWAYS 0x00010000 /* ignore qlimits - kernel only */
668#define MACH_SEND_TRAILER 0x00020000 /* sender-provided trailer */
669#define MACH_SEND_NOIMPORTANCE 0x00040000 /* msg won't carry importance */
fe8ab488 670#define MACH_SEND_NODENAP MACH_SEND_NOIMPORTANCE
39236c6e 671#define MACH_SEND_IMPORTANCE 0x00080000 /* msg carries importance - kernel only */
1c79356b 672
39236c6e
A
673
674#define MACH_RCV_TIMEOUT 0x00000100 /* timeout value applies to receive */
6d2010ae 675#define MACH_RCV_NOTIFY 0x00000200 /* reserved - legacy */
39236c6e 676#define MACH_RCV_INTERRUPT 0x00000400 /* don't restart interrupted receive */
fe8ab488 677#define MACH_RCV_VOUCHER 0x00000800 /* willing to receive voucher port */
3e170ce0 678#define MACH_RCV_OVERWRITE 0x00001000 /* scatter receive (deprecated) */
1c79356b 679
39037602
A
680#ifdef XNU_KERNEL_PRIVATE
681
682#define MACH_RCV_STACK 0x00002000 /* receive into highest addr of buffer */
683
684/*
685 * NOTE:
686 * This internal-only flag is intended for use by a single thread per-port/set!
687 * If more than one thread attempts to MACH_PEEK_MSG on a port or set, one of
688 * the threads may miss messages (in fact, it may never wake up).
689 */
690#define MACH_PEEK_MSG 0x00100000 /* receive, but leave msgs queued */
691
692#endif
693
1c79356b
A
694/*
695 * NOTE: a 0x00------ RCV mask implies to ask for
696 * a MACH_MSG_TRAILER_FORMAT_0 with 0 Elements,
697 * which is equivalent to a mach_msg_trailer_t.
2d21ac55
A
698 *
699 * XXXMAC: unlike the rest of the MACH_RCV_* flags, MACH_RCV_TRAILER_LABELS
b0d623f7
A
700 * needs its own private bit since we only calculate its fields when absolutely
701 * required.
1c79356b
A
702 */
703#define MACH_RCV_TRAILER_NULL 0
704#define MACH_RCV_TRAILER_SEQNO 1
705#define MACH_RCV_TRAILER_SENDER 2
55e303ae 706#define MACH_RCV_TRAILER_AUDIT 3
b0d623f7
A
707#define MACH_RCV_TRAILER_CTX 4
708#define MACH_RCV_TRAILER_AV 7
709#define MACH_RCV_TRAILER_LABELS 8
1c79356b
A
710
711#define MACH_RCV_TRAILER_TYPE(x) (((x) & 0xf) << 28)
712#define MACH_RCV_TRAILER_ELEMENTS(x) (((x) & 0xf) << 24)
39236c6e 713#define MACH_RCV_TRAILER_MASK ((0xf << 24))
1c79356b 714
1c79356b 715#define GET_RCV_ELEMENTS(y) (((y) >> 24) & 0xf)
2d21ac55 716
39236c6e
A
717#ifdef MACH_KERNEL_PRIVATE
718/* The options that the kernel honors when passed from user space */
39037602
A
719#define MACH_SEND_USER (MACH_SEND_MSG | MACH_SEND_TIMEOUT | \
720 MACH_SEND_NOTIFY | MACH_SEND_OVERRIDE | \
721 MACH_SEND_TRAILER | MACH_SEND_NOIMPORTANCE )
39236c6e 722
39037602
A
723#define MACH_RCV_USER (MACH_RCV_MSG | MACH_RCV_TIMEOUT | \
724 MACH_RCV_LARGE | MACH_RCV_LARGE_IDENTITY | \
725 MACH_RCV_VOUCHER | MACH_RCV_TRAILER_MASK)
39236c6e
A
726
727#define MACH_MSG_OPTION_USER (MACH_SEND_USER | MACH_RCV_USER)
728
729/* The options implemented by the library interface to mach_msg et. al. */
730#define MACH_MSG_OPTION_LIB (MACH_SEND_INTERRUPT | MACH_RCV_INTERRUPT)
731
490019cf
A
732/*
733 * Default options to use when sending from the kernel.
734 *
735 * Until we are sure of its effects, we are disabling
736 * importance donation from the kernel-side of user
737 * threads in importance-donating tasks.
738 * (11938665 & 23925818)
739 */
39236c6e
A
740#define MACH_SEND_KERNEL_DEFAULT (MACH_SEND_MSG | \
741 MACH_SEND_ALWAYS | MACH_SEND_NOIMPORTANCE)
39236c6e
A
742
743#endif /* MACH_KERNEL_PRIVATE */
744
2d21ac55 745/*
b0d623f7
A
746 * XXXMAC: note that in the case of MACH_RCV_TRAILER_LABELS,
747 * we just fall through to mach_msg_max_trailer_t.
2d21ac55 748 * This is correct behavior since mach_msg_max_trailer_t is defined as
b0d623f7
A
749 * mac_msg_mac_trailer_t which is used for the LABELS trailer.
750 * It also makes things work properly if MACH_RCV_TRAILER_LABELS is ORed
751 * with one of the other options.
2d21ac55 752 */
316670eb
A
753
754#define REQUESTED_TRAILER_SIZE_NATIVE(y) \
9bccf70c
A
755 ((mach_msg_trailer_size_t) \
756 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_NULL) ? \
757 sizeof(mach_msg_trailer_t) : \
758 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SEQNO) ? \
759 sizeof(mach_msg_seqno_trailer_t) : \
55e303ae
A
760 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SENDER) ? \
761 sizeof(mach_msg_security_trailer_t) : \
2d21ac55
A
762 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AUDIT) ? \
763 sizeof(mach_msg_audit_trailer_t) : \
b0d623f7
A
764 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_CTX) ? \
765 sizeof(mach_msg_context_trailer_t) : \
766 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AV) ? \
767 sizeof(mach_msg_mac_trailer_t) : \
768 sizeof(mach_msg_max_trailer_t))))))))
2d21ac55 769
316670eb
A
770
771#ifdef XNU_KERNEL_PRIVATE
772
773#define REQUESTED_TRAILER_SIZE(is64, y) REQUESTED_TRAILER_SIZE_NATIVE(y)
774
775#else /* XNU_KERNEL_PRIVATE */
776#define REQUESTED_TRAILER_SIZE(y) REQUESTED_TRAILER_SIZE_NATIVE(y)
777#endif /* XNU_KERNEL_PRIVATE */
778
1c79356b
A
779/*
780 * Much code assumes that mach_msg_return_t == kern_return_t.
781 * This definition is useful for descriptive purposes.
782 *
783 * See <mach/error.h> for the format of error codes.
784 * IPC errors are system 4. Send errors are subsystem 0;
785 * receive errors are subsystem 1. The code field is always non-zero.
786 * The high bits of the code field communicate extra information
787 * for some error codes. MACH_MSG_MASK masks off these special bits.
788 */
789
790typedef kern_return_t mach_msg_return_t;
791
792#define MACH_MSG_SUCCESS 0x00000000
793
794
795#define MACH_MSG_MASK 0x00003e00
796 /* All special error code bits defined below. */
797#define MACH_MSG_IPC_SPACE 0x00002000
798 /* No room in IPC name space for another capability name. */
799#define MACH_MSG_VM_SPACE 0x00001000
800 /* No room in VM address space for out-of-line memory. */
801#define MACH_MSG_IPC_KERNEL 0x00000800
802 /* Kernel resource shortage handling an IPC capability. */
803#define MACH_MSG_VM_KERNEL 0x00000400
804 /* Kernel resource shortage handling out-of-line memory. */
805
806#define MACH_SEND_IN_PROGRESS 0x10000001
807 /* Thread is waiting to send. (Internal use only.) */
808#define MACH_SEND_INVALID_DATA 0x10000002
809 /* Bogus in-line data. */
810#define MACH_SEND_INVALID_DEST 0x10000003
811 /* Bogus destination port. */
812#define MACH_SEND_TIMED_OUT 0x10000004
813 /* Message not sent before timeout expired. */
fe8ab488
A
814#define MACH_SEND_INVALID_VOUCHER 0x10000005
815 /* Bogus voucher port. */
1c79356b
A
816#define MACH_SEND_INTERRUPTED 0x10000007
817 /* Software interrupt. */
818#define MACH_SEND_MSG_TOO_SMALL 0x10000008
819 /* Data doesn't contain a complete message. */
820#define MACH_SEND_INVALID_REPLY 0x10000009
821 /* Bogus reply port. */
822#define MACH_SEND_INVALID_RIGHT 0x1000000a
823 /* Bogus port rights in the message body. */
824#define MACH_SEND_INVALID_NOTIFY 0x1000000b
825 /* Bogus notify port argument. */
826#define MACH_SEND_INVALID_MEMORY 0x1000000c
827 /* Invalid out-of-line memory pointer. */
828#define MACH_SEND_NO_BUFFER 0x1000000d
829 /* No message buffer is available. */
830#define MACH_SEND_TOO_LARGE 0x1000000e
831 /* Send is too large for port */
832#define MACH_SEND_INVALID_TYPE 0x1000000f
833 /* Invalid msg-type specification. */
834#define MACH_SEND_INVALID_HEADER 0x10000010
835 /* A field in the header had a bad value. */
836#define MACH_SEND_INVALID_TRAILER 0x10000011
837 /* The trailer to be sent does not match kernel format. */
838#define MACH_SEND_INVALID_RT_OOL_SIZE 0x10000015
9bccf70c 839 /* compatibility: no longer a returned error */
1c79356b
A
840
841#define MACH_RCV_IN_PROGRESS 0x10004001
842 /* Thread is waiting for receive. (Internal use only.) */
843#define MACH_RCV_INVALID_NAME 0x10004002
844 /* Bogus name for receive port/port-set. */
845#define MACH_RCV_TIMED_OUT 0x10004003
846 /* Didn't get a message within the timeout value. */
847#define MACH_RCV_TOO_LARGE 0x10004004
848 /* Message buffer is not large enough for inline data. */
849#define MACH_RCV_INTERRUPTED 0x10004005
850 /* Software interrupt. */
851#define MACH_RCV_PORT_CHANGED 0x10004006
9bccf70c 852 /* compatibility: no longer a returned error */
1c79356b
A
853#define MACH_RCV_INVALID_NOTIFY 0x10004007
854 /* Bogus notify port argument. */
855#define MACH_RCV_INVALID_DATA 0x10004008
856 /* Bogus message buffer for inline data. */
857#define MACH_RCV_PORT_DIED 0x10004009
858 /* Port/set was sent away/died during receive. */
859#define MACH_RCV_IN_SET 0x1000400a
9bccf70c 860 /* compatibility: no longer a returned error */
1c79356b
A
861#define MACH_RCV_HEADER_ERROR 0x1000400b
862 /* Error receiving message header. See special bits. */
863#define MACH_RCV_BODY_ERROR 0x1000400c
864 /* Error receiving message body. See special bits. */
865#define MACH_RCV_INVALID_TYPE 0x1000400d
866 /* Invalid msg-type specification in scatter list. */
867#define MACH_RCV_SCATTER_SMALL 0x1000400e
868 /* Out-of-line overwrite region is not large enough */
869#define MACH_RCV_INVALID_TRAILER 0x1000400f
870 /* trailer type or number of trailer elements not supported */
871#define MACH_RCV_IN_PROGRESS_TIMED 0x10004011
872 /* Waiting for receive with timeout. (Internal use only.) */
873
39037602
A
874#ifdef XNU_KERNEL_PRIVATE
875#define MACH_PEEK_IN_PROGRESS 0x10008001
876 /* Waiting for a peek. (Internal use only.) */
877#define MACH_PEEK_READY 0x10008002
878 /* Waiting for a peek. (Internal use only.) */
879#endif
880
91447636
A
881
882__BEGIN_DECLS
883
9bccf70c
A
884/*
885 * Routine: mach_msg_overwrite
886 * Purpose:
887 * Send and/or receive a message. If the message operation
888 * is interrupted, and the user did not request an indication
889 * of that fact, then restart the appropriate parts of the
890 * operation silently (trap version does not restart).
891 *
892 * Distinct send and receive buffers may be specified. If
893 * no separate receive buffer is specified, the msg parameter
894 * will be used for both send and receive operations.
895 *
896 * In addition to a distinct receive buffer, that buffer may
897 * already contain scatter control information to direct the
898 * receiving of the message.
899 */
3e170ce0 900__WATCHOS_PROHIBITED __TVOS_PROHIBITED
1c79356b
A
901extern mach_msg_return_t mach_msg_overwrite(
902 mach_msg_header_t *msg,
903 mach_msg_option_t option,
904 mach_msg_size_t send_size,
905 mach_msg_size_t rcv_size,
906 mach_port_name_t rcv_name,
907 mach_msg_timeout_t timeout,
908 mach_port_name_t notify,
909 mach_msg_header_t *rcv_msg,
910 mach_msg_size_t rcv_limit);
911
91447636
A
912#ifndef KERNEL
913
9bccf70c
A
914/*
915 * Routine: mach_msg
916 * Purpose:
917 * Send and/or receive a message. If the message operation
918 * is interrupted, and the user did not request an indication
919 * of that fact, then restart the appropriate parts of the
920 * operation silently (trap version does not restart).
921 */
3e170ce0 922__WATCHOS_PROHIBITED __TVOS_PROHIBITED
1c79356b
A
923extern mach_msg_return_t mach_msg(
924 mach_msg_header_t *msg,
925 mach_msg_option_t option,
926 mach_msg_size_t send_size,
927 mach_msg_size_t rcv_size,
928 mach_port_name_t rcv_name,
929 mach_msg_timeout_t timeout,
930 mach_port_name_t notify);
931
fe8ab488
A
932/*
933 * Routine: mach_voucher_deallocate
934 * Purpose:
935 * Deallocate a mach voucher created or received in a message. Drops
936 * one (send right) reference to the voucher.
937 */
3e170ce0 938__WATCHOS_PROHIBITED __TVOS_PROHIBITED
fe8ab488
A
939extern kern_return_t mach_voucher_deallocate(
940 mach_port_name_t voucher);
941
b0d623f7
A
942#elif defined(MACH_KERNEL_PRIVATE)
943
39037602 944extern mach_msg_return_t mach_msg_receive_results(mach_msg_size_t *size);
b0d623f7 945
39037602
A
946extern mach_msg_priority_t mach_msg_priority_combine(mach_msg_priority_t msg_qos,
947 mach_msg_priority_t recv_qos);
91447636
A
948#endif /* KERNEL */
949
950__END_DECLS
951
1c79356b 952#endif /* _MACH_MESSAGE_H_ */
2d21ac55 953