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