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