]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/message.h
xnu-2422.90.20.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
83 /*
84 * The timeout mechanism uses mach_msg_timeout_t values,
85 * passed by value. The timeout units are milliseconds.
86 * It is controlled with the MACH_SEND_TIMEOUT
87 * and MACH_RCV_TIMEOUT options.
88 */
89
90 typedef natural_t mach_msg_timeout_t;
91
92 /*
93 * The value to be used when there is no timeout.
94 * (No MACH_SEND_TIMEOUT/MACH_RCV_TIMEOUT option.)
95 */
96
97 #define MACH_MSG_TIMEOUT_NONE ((mach_msg_timeout_t) 0)
98
99 /*
100 * The kernel uses MACH_MSGH_BITS_COMPLEX as a hint. If it isn't on, it
101 * assumes the body of the message doesn't contain port rights or OOL
102 * data. The field is set in received messages. A user task must
103 * use caution in interpreting the body of a message if the bit isn't
104 * on, because the mach_msg_type's in the body might "lie" about the
105 * contents. If the bit isn't on, but the mach_msg_types
106 * in the body specify rights or OOL data, the behavior is undefined.
107 * (Ie, an error may or may not be produced.)
108 *
109 * The value of MACH_MSGH_BITS_REMOTE determines the interpretation
110 * of the msgh_remote_port field. It is handled like a msgt_name.
111 *
112 * The value of MACH_MSGH_BITS_LOCAL determines the interpretation
113 * of the msgh_local_port field. It is handled like a msgt_name.
114 *
115 * MACH_MSGH_BITS() combines two MACH_MSG_TYPE_* values, for the remote
116 * and local fields, into a single value suitable for msgh_bits.
117 *
118 * MACH_MSGH_BITS_CIRCULAR should be zero; is is used internally.
119 *
120 * The unused bits should be zero and are reserved for the kernel
121 * or for future interface expansion.
122 */
123
124 #define MACH_MSGH_BITS_ZERO 0x00000000
125 #define MACH_MSGH_BITS_REMOTE_MASK 0x000000ff
126 #define MACH_MSGH_BITS_LOCAL_MASK 0x0000ff00
127 #define MACH_MSGH_BITS_COMPLEX 0x80000000U
128 #define MACH_MSGH_BITS_USER 0x8000ffffU
129
130 #define MACH_MSGH_BITS_CIRCULAR 0x40000000 /* internal use only */
131 #define MACH_MSGH_BITS_RAISEIMP 0x20000000 /* importance raise, internal use only */
132 #define MACH_MSGH_BITS_IMPHOLDASRT 0x10000000 /* holds assertion alredy, in userland */
133 #define MACH_MSGH_BITS_USED 0xf000ffffU
134
135 #define MACH_MSGH_BITS_PORTS_MASK \
136 (MACH_MSGH_BITS_REMOTE_MASK|MACH_MSGH_BITS_LOCAL_MASK)
137
138 #define MACH_MSGH_BITS(remote, local) \
139 ((remote) | ((local) << 8))
140 #define MACH_MSGH_BITS_REMOTE(bits) \
141 ((bits) & MACH_MSGH_BITS_REMOTE_MASK)
142 #define MACH_MSGH_BITS_LOCAL(bits) \
143 (((bits) & MACH_MSGH_BITS_LOCAL_MASK) >> 8)
144 #define MACH_MSGH_BITS_PORTS(bits) \
145 ((bits) & MACH_MSGH_BITS_PORTS_MASK)
146 #define MACH_MSGH_BITS_OTHER(bits) \
147 ((bits) &~ MACH_MSGH_BITS_PORTS_MASK)
148
149 /*
150 * Every message starts with a message header.
151 * Following the message header, if the message is complex, are a count
152 * of type descriptors and the type descriptors themselves
153 * (mach_msg_descriptor_t). The size of the message must be specified in
154 * bytes, and includes the message header, descriptor count, descriptors,
155 * and inline data.
156 *
157 * The msgh_remote_port field specifies the destination of the message.
158 * It must specify a valid send or send-once right for a port.
159 *
160 * The msgh_local_port field specifies a "reply port". Normally,
161 * This field carries a send-once right that the receiver will use
162 * to reply to the message. It may carry the values MACH_PORT_NULL,
163 * MACH_PORT_DEAD, a send-once right, or a send right.
164 *
165 * The msgh_seqno field carries a sequence number associated with the
166 * received-from port. A port's sequence number is incremented every
167 * time a message is received from it. In sent messages, the field's
168 * value is ignored.
169 *
170 * The msgh_id field is uninterpreted by the message primitives.
171 * It normally carries information specifying the format
172 * or meaning of the message.
173 */
174
175 typedef unsigned int mach_msg_bits_t;
176 typedef natural_t mach_msg_size_t;
177 typedef integer_t mach_msg_id_t;
178
179
180 #define MACH_MSG_SIZE_NULL (mach_msg_size_t *) 0
181
182 typedef unsigned int mach_msg_type_name_t;
183
184 #define MACH_MSG_TYPE_MOVE_RECEIVE 16 /* Must hold receive rights */
185 #define MACH_MSG_TYPE_MOVE_SEND 17 /* Must hold send rights */
186 #define MACH_MSG_TYPE_MOVE_SEND_ONCE 18 /* Must hold sendonce rights */
187 #define MACH_MSG_TYPE_COPY_SEND 19 /* Must hold send rights */
188 #define MACH_MSG_TYPE_MAKE_SEND 20 /* Must hold receive rights */
189 #define MACH_MSG_TYPE_MAKE_SEND_ONCE 21 /* Must hold receive rights */
190 #define MACH_MSG_TYPE_COPY_RECEIVE 22 /* Must hold receive rights */
191
192 typedef unsigned int mach_msg_copy_options_t;
193
194 #define MACH_MSG_PHYSICAL_COPY 0
195 #define MACH_MSG_VIRTUAL_COPY 1
196 #define MACH_MSG_ALLOCATE 2
197 #define MACH_MSG_OVERWRITE 3
198 #ifdef MACH_KERNEL
199 #define MACH_MSG_KALLOC_COPY_T 4
200 #endif /* MACH_KERNEL */
201
202 /*
203 * In a complex mach message, the mach_msg_header_t is followed by
204 * a descriptor count, then an array of that number of descriptors
205 * (mach_msg_*_descriptor_t). The type field of mach_msg_type_descriptor_t
206 * (which any descriptor can be cast to) indicates the flavor of the
207 * descriptor.
208 *
209 * Note that in LP64, the various types of descriptors are no longer all
210 * the same size as mach_msg_descriptor_t, so the array cannot be indexed
211 * as expected.
212 */
213
214 typedef unsigned int mach_msg_descriptor_type_t;
215
216 #define MACH_MSG_PORT_DESCRIPTOR 0
217 #define MACH_MSG_OOL_DESCRIPTOR 1
218 #define MACH_MSG_OOL_PORTS_DESCRIPTOR 2
219 #define MACH_MSG_OOL_VOLATILE_DESCRIPTOR 3
220
221 #pragma pack(4)
222
223 typedef struct
224 {
225 natural_t pad1;
226 mach_msg_size_t pad2;
227 unsigned int pad3 : 24;
228 mach_msg_descriptor_type_t type : 8;
229 } mach_msg_type_descriptor_t;
230
231 typedef struct
232 {
233 mach_port_t name;
234 #if !(defined(KERNEL) && defined(__LP64__))
235 // Pad to 8 bytes everywhere except the K64 kernel where mach_port_t is 8 bytes
236 mach_msg_size_t pad1;
237 #endif
238 unsigned int pad2 : 16;
239 mach_msg_type_name_t disposition : 8;
240 mach_msg_descriptor_type_t type : 8;
241 #if defined(KERNEL)
242 uint32_t pad_end;
243 #endif
244 } mach_msg_port_descriptor_t;
245
246 typedef struct
247 {
248 uint32_t address;
249 mach_msg_size_t size;
250 boolean_t deallocate: 8;
251 mach_msg_copy_options_t copy: 8;
252 unsigned int pad1: 8;
253 mach_msg_descriptor_type_t type: 8;
254 } mach_msg_ool_descriptor32_t;
255
256 typedef struct
257 {
258 uint64_t address;
259 boolean_t deallocate: 8;
260 mach_msg_copy_options_t copy: 8;
261 unsigned int pad1: 8;
262 mach_msg_descriptor_type_t type: 8;
263 mach_msg_size_t size;
264 } mach_msg_ool_descriptor64_t;
265
266 typedef struct
267 {
268 void* address;
269 #if !defined(__LP64__)
270 mach_msg_size_t size;
271 #endif
272 boolean_t deallocate: 8;
273 mach_msg_copy_options_t copy: 8;
274 unsigned int pad1: 8;
275 mach_msg_descriptor_type_t type: 8;
276 #if defined(__LP64__)
277 mach_msg_size_t size;
278 #endif
279 #if defined(KERNEL) && !defined(__LP64__)
280 uint32_t pad_end;
281 #endif
282 } mach_msg_ool_descriptor_t;
283
284 typedef struct
285 {
286 uint32_t address;
287 mach_msg_size_t count;
288 boolean_t deallocate: 8;
289 mach_msg_copy_options_t copy: 8;
290 mach_msg_type_name_t disposition : 8;
291 mach_msg_descriptor_type_t type : 8;
292 } mach_msg_ool_ports_descriptor32_t;
293
294 typedef struct
295 {
296 uint64_t address;
297 boolean_t deallocate: 8;
298 mach_msg_copy_options_t copy: 8;
299 mach_msg_type_name_t disposition : 8;
300 mach_msg_descriptor_type_t type : 8;
301 mach_msg_size_t count;
302 } mach_msg_ool_ports_descriptor64_t;
303
304 typedef struct
305 {
306 void* address;
307 #if !defined(__LP64__)
308 mach_msg_size_t count;
309 #endif
310 boolean_t deallocate: 8;
311 mach_msg_copy_options_t copy: 8;
312 mach_msg_type_name_t disposition : 8;
313 mach_msg_descriptor_type_t type : 8;
314 #if defined(__LP64__)
315 mach_msg_size_t count;
316 #endif
317 #if defined(KERNEL) && !defined(__LP64__)
318 uint32_t pad_end;
319 #endif
320 } mach_msg_ool_ports_descriptor_t;
321
322 /*
323 * LP64support - This union definition is not really
324 * appropriate in LP64 mode because not all descriptors
325 * are of the same size in that environment.
326 */
327 #if defined(__LP64__) && defined(KERNEL)
328 typedef union
329 {
330 mach_msg_port_descriptor_t port;
331 mach_msg_ool_descriptor32_t out_of_line;
332 mach_msg_ool_ports_descriptor32_t ool_ports;
333 mach_msg_type_descriptor_t type;
334 } mach_msg_descriptor_t;
335 #else
336 typedef union
337 {
338 mach_msg_port_descriptor_t port;
339 mach_msg_ool_descriptor_t out_of_line;
340 mach_msg_ool_ports_descriptor_t ool_ports;
341 mach_msg_type_descriptor_t type;
342 } mach_msg_descriptor_t;
343 #endif
344
345 typedef struct
346 {
347 mach_msg_size_t msgh_descriptor_count;
348 } mach_msg_body_t;
349
350 #define MACH_MSG_BODY_NULL (mach_msg_body_t *) 0
351 #define MACH_MSG_DESCRIPTOR_NULL (mach_msg_descriptor_t *) 0
352
353 typedef struct
354 {
355 mach_msg_bits_t msgh_bits;
356 mach_msg_size_t msgh_size;
357 mach_port_t msgh_remote_port;
358 mach_port_t msgh_local_port;
359 mach_msg_size_t msgh_reserved;
360 mach_msg_id_t msgh_id;
361 } mach_msg_header_t;
362
363 #define MACH_MSG_NULL (mach_msg_header_t *) 0
364
365 typedef struct
366 {
367 mach_msg_header_t header;
368 mach_msg_body_t body;
369 } mach_msg_base_t;
370
371 typedef unsigned int mach_msg_trailer_type_t;
372
373 #define MACH_MSG_TRAILER_FORMAT_0 0
374
375 typedef unsigned int mach_msg_trailer_size_t;
376 typedef char *mach_msg_trailer_info_t;
377
378 typedef struct
379 {
380 mach_msg_trailer_type_t msgh_trailer_type;
381 mach_msg_trailer_size_t msgh_trailer_size;
382 } mach_msg_trailer_t;
383
384 typedef struct
385 {
386 mach_msg_trailer_type_t msgh_trailer_type;
387 mach_msg_trailer_size_t msgh_trailer_size;
388 mach_port_seqno_t msgh_seqno;
389 } mach_msg_seqno_trailer_t;
390
391 typedef struct
392 {
393 unsigned int val[2];
394 } security_token_t;
395
396 typedef struct
397 {
398 mach_msg_trailer_type_t msgh_trailer_type;
399 mach_msg_trailer_size_t msgh_trailer_size;
400 mach_port_seqno_t msgh_seqno;
401 security_token_t msgh_sender;
402 } mach_msg_security_trailer_t;
403
404 /*
405 * The audit token is an opaque token which identifies
406 * Mach tasks and senders of Mach messages as subjects
407 * to the BSM audit system. Only the appropriate BSM
408 * library routines should be used to interpret the
409 * contents of the audit token as the representation
410 * of the subject identity within the token may change
411 * over time.
412 */
413 typedef struct
414 {
415 unsigned int val[8];
416 } audit_token_t;
417
418 typedef struct
419 {
420 mach_msg_trailer_type_t msgh_trailer_type;
421 mach_msg_trailer_size_t msgh_trailer_size;
422 mach_port_seqno_t msgh_seqno;
423 security_token_t msgh_sender;
424 audit_token_t msgh_audit;
425 } mach_msg_audit_trailer_t;
426
427 typedef struct
428 {
429 mach_msg_trailer_type_t msgh_trailer_type;
430 mach_msg_trailer_size_t msgh_trailer_size;
431 mach_port_seqno_t msgh_seqno;
432 security_token_t msgh_sender;
433 audit_token_t msgh_audit;
434 mach_port_context_t msgh_context;
435 } mach_msg_context_trailer_t;
436
437 typedef struct
438 {
439 mach_port_name_t sender;
440 } msg_labels_t;
441
442 /*
443 Trailer type to pass MAC policy label info as a mach message trailer.
444
445 */
446
447 typedef struct
448 {
449 mach_msg_trailer_type_t msgh_trailer_type;
450 mach_msg_trailer_size_t msgh_trailer_size;
451 mach_port_seqno_t msgh_seqno;
452 security_token_t msgh_sender;
453 audit_token_t msgh_audit;
454 mach_port_context_t msgh_context;
455 int msgh_ad;
456 msg_labels_t msgh_labels;
457 } mach_msg_mac_trailer_t;
458
459 #define MACH_MSG_TRAILER_MINIMUM_SIZE sizeof(mach_msg_trailer_t)
460
461 /*
462 * These values can change from release to release - but clearly
463 * code cannot request additional trailer elements one was not
464 * compiled to understand. Therefore, it is safe to use this
465 * constant when the same module specified the receive options.
466 * Otherwise, you run the risk that the options requested by
467 * another module may exceed the local modules notion of
468 * MAX_TRAILER_SIZE.
469 */
470
471 typedef mach_msg_mac_trailer_t mach_msg_max_trailer_t;
472 #define MAX_TRAILER_SIZE ((mach_msg_size_t)sizeof(mach_msg_max_trailer_t))
473
474 /*
475 * Legacy requirements keep us from ever updating these defines (even
476 * when the format_0 trailers gain new option data fields in the future).
477 * Therefore, they shouldn't be used going forward. Instead, the sizes
478 * should be compared against the specific element size requested using
479 * REQUESTED_TRAILER_SIZE.
480 */
481 typedef mach_msg_security_trailer_t mach_msg_format_0_trailer_t;
482
483 /*typedef mach_msg_mac_trailer_t mach_msg_format_0_trailer_t;
484 */
485
486 #define MACH_MSG_TRAILER_FORMAT_0_SIZE sizeof(mach_msg_format_0_trailer_t)
487
488 #define KERNEL_SECURITY_TOKEN_VALUE { {0, 1} }
489 extern security_token_t KERNEL_SECURITY_TOKEN;
490
491 #define KERNEL_AUDIT_TOKEN_VALUE { {0, 0, 0, 0, 0, 0, 0, 0} }
492 extern audit_token_t KERNEL_AUDIT_TOKEN;
493
494 typedef integer_t mach_msg_options_t;
495
496 typedef struct
497 {
498 mach_msg_header_t header;
499 } mach_msg_empty_send_t;
500
501 typedef struct
502 {
503 mach_msg_header_t header;
504 mach_msg_trailer_t trailer;
505 } mach_msg_empty_rcv_t;
506
507 typedef union
508 {
509 mach_msg_empty_send_t send;
510 mach_msg_empty_rcv_t rcv;
511 } mach_msg_empty_t;
512
513 #pragma pack()
514
515 /* utility to round the message size - will become machine dependent */
516 #define round_msg(x) (((mach_msg_size_t)(x) + sizeof (natural_t) - 1) & \
517 ~(sizeof (natural_t) - 1))
518
519 /*
520 * There is no fixed upper bound to the size of Mach messages.
521 */
522 #define MACH_MSG_SIZE_MAX ((mach_msg_size_t) ~0)
523
524 #if defined(__APPLE_API_PRIVATE)
525 /*
526 * But architectural limits of a given implementation, or
527 * temporal conditions may cause unpredictable send failures
528 * for messages larger than MACH_MSG_SIZE_RELIABLE.
529 *
530 * In either case, waiting for memory is [currently] outside
531 * the scope of send timeout values provided to IPC.
532 */
533 #define MACH_MSG_SIZE_RELIABLE ((mach_msg_size_t) 256 * 1024)
534 #endif
535 /*
536 * Compatibility definitions, for code written
537 * when there was a msgh_kind instead of msgh_seqno.
538 */
539 #define MACH_MSGH_KIND_NORMAL 0x00000000
540 #define MACH_MSGH_KIND_NOTIFICATION 0x00000001
541 #define msgh_kind msgh_seqno
542 #define mach_msg_kind_t mach_port_seqno_t
543
544 typedef natural_t mach_msg_type_size_t;
545 typedef natural_t mach_msg_type_number_t;
546
547 /*
548 * Values received/carried in messages. Tells the receiver what
549 * sort of port right he now has.
550 *
551 * MACH_MSG_TYPE_PORT_NAME is used to transfer a port name
552 * which should remain uninterpreted by the kernel. (Port rights
553 * are not transferred, just the port name.)
554 */
555
556 #define MACH_MSG_TYPE_PORT_NONE 0
557
558 #define MACH_MSG_TYPE_PORT_NAME 15
559 #define MACH_MSG_TYPE_PORT_RECEIVE MACH_MSG_TYPE_MOVE_RECEIVE
560 #define MACH_MSG_TYPE_PORT_SEND MACH_MSG_TYPE_MOVE_SEND
561 #define MACH_MSG_TYPE_PORT_SEND_ONCE MACH_MSG_TYPE_MOVE_SEND_ONCE
562
563 #define MACH_MSG_TYPE_LAST 22 /* Last assigned */
564
565 /*
566 * A dummy value. Mostly used to indicate that the actual value
567 * will be filled in later, dynamically.
568 */
569
570 #define MACH_MSG_TYPE_POLYMORPHIC ((mach_msg_type_name_t) -1)
571
572 /*
573 * Is a given item a port type?
574 */
575
576 #define MACH_MSG_TYPE_PORT_ANY(x) \
577 (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
578 ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
579
580 #define MACH_MSG_TYPE_PORT_ANY_SEND(x) \
581 (((x) >= MACH_MSG_TYPE_MOVE_SEND) && \
582 ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
583
584 #define MACH_MSG_TYPE_PORT_ANY_RIGHT(x) \
585 (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
586 ((x) <= MACH_MSG_TYPE_MOVE_SEND_ONCE))
587
588 typedef integer_t mach_msg_option_t;
589
590 #define MACH_MSG_OPTION_NONE 0x00000000
591
592 #define MACH_SEND_MSG 0x00000001
593 #define MACH_RCV_MSG 0x00000002
594
595 #define MACH_RCV_LARGE 0x00000004 /* report large message sizes */
596 #define MACH_RCV_LARGE_IDENTITY 0x00000008 /* identify source of large messages */
597
598 #define MACH_SEND_TIMEOUT 0x00000010 /* timeout value applies to send */
599 #define MACH_SEND_INTERRUPT 0x00000040 /* don't restart interrupted sends */
600 #define MACH_SEND_NOTIFY 0x00000080 /* arm send-possible notify */
601 #define MACH_SEND_ALWAYS 0x00010000 /* ignore qlimits - kernel only */
602 #define MACH_SEND_TRAILER 0x00020000 /* sender-provided trailer */
603 #define MACH_SEND_NOIMPORTANCE 0x00040000 /* msg won't carry importance */
604 #define MACH_SEND_IMPORTANCE 0x00080000 /* msg carries importance - kernel only */
605
606
607 #define MACH_RCV_TIMEOUT 0x00000100 /* timeout value applies to receive */
608 #define MACH_RCV_NOTIFY 0x00000200 /* reserved - legacy */
609 #define MACH_RCV_INTERRUPT 0x00000400 /* don't restart interrupted receive */
610 #define MACH_RCV_OVERWRITE 0x00001000 /* scatter receive */
611
612 /*
613 * NOTE: a 0x00------ RCV mask implies to ask for
614 * a MACH_MSG_TRAILER_FORMAT_0 with 0 Elements,
615 * which is equivalent to a mach_msg_trailer_t.
616 *
617 * XXXMAC: unlike the rest of the MACH_RCV_* flags, MACH_RCV_TRAILER_LABELS
618 * needs its own private bit since we only calculate its fields when absolutely
619 * required.
620 */
621 #define MACH_RCV_TRAILER_NULL 0
622 #define MACH_RCV_TRAILER_SEQNO 1
623 #define MACH_RCV_TRAILER_SENDER 2
624 #define MACH_RCV_TRAILER_AUDIT 3
625 #define MACH_RCV_TRAILER_CTX 4
626 #define MACH_RCV_TRAILER_AV 7
627 #define MACH_RCV_TRAILER_LABELS 8
628
629 #define MACH_RCV_TRAILER_TYPE(x) (((x) & 0xf) << 28)
630 #define MACH_RCV_TRAILER_ELEMENTS(x) (((x) & 0xf) << 24)
631 #define MACH_RCV_TRAILER_MASK ((0xf << 24))
632
633 #define GET_RCV_ELEMENTS(y) (((y) >> 24) & 0xf)
634
635 #ifdef MACH_KERNEL_PRIVATE
636 /* The options that the kernel honors when passed from user space */
637 #define MACH_SEND_USER (MACH_SEND_MSG | \
638 MACH_SEND_TIMEOUT | MACH_SEND_NOTIFY | \
639 MACH_SEND_TRAILER | MACH_SEND_NOIMPORTANCE )
640
641 #define MACH_RCV_USER (MACH_RCV_MSG | \
642 MACH_RCV_TIMEOUT | MACH_RCV_OVERWRITE | \
643 MACH_RCV_LARGE | MACH_RCV_LARGE_IDENTITY | \
644 MACH_RCV_TRAILER_MASK)
645
646 #define MACH_MSG_OPTION_USER (MACH_SEND_USER | MACH_RCV_USER)
647
648 /* The options implemented by the library interface to mach_msg et. al. */
649 #define MACH_MSG_OPTION_LIB (MACH_SEND_INTERRUPT | MACH_RCV_INTERRUPT)
650
651 /* Default options to use when sending from the kernel */
652 #if 11938665
653 /*
654 * Until we are sure of its effects, we are disabling
655 * importance donation from the kernel-side of user
656 * threads in importance-donating tasks.
657 */
658 #define MACH_SEND_KERNEL_DEFAULT (MACH_SEND_MSG | \
659 MACH_SEND_ALWAYS | MACH_SEND_NOIMPORTANCE)
660 #else
661 #define MACH_SEND_KERNEL_DEFAULT (MACH_SEND_MSG | MACH_SEND_ALWAYS)
662 #endif
663
664 #endif /* MACH_KERNEL_PRIVATE */
665
666 /*
667 * XXXMAC: note that in the case of MACH_RCV_TRAILER_LABELS,
668 * we just fall through to mach_msg_max_trailer_t.
669 * This is correct behavior since mach_msg_max_trailer_t is defined as
670 * mac_msg_mac_trailer_t which is used for the LABELS trailer.
671 * It also makes things work properly if MACH_RCV_TRAILER_LABELS is ORed
672 * with one of the other options.
673 */
674
675 #define REQUESTED_TRAILER_SIZE_NATIVE(y) \
676 ((mach_msg_trailer_size_t) \
677 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_NULL) ? \
678 sizeof(mach_msg_trailer_t) : \
679 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SEQNO) ? \
680 sizeof(mach_msg_seqno_trailer_t) : \
681 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SENDER) ? \
682 sizeof(mach_msg_security_trailer_t) : \
683 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AUDIT) ? \
684 sizeof(mach_msg_audit_trailer_t) : \
685 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_CTX) ? \
686 sizeof(mach_msg_context_trailer_t) : \
687 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AV) ? \
688 sizeof(mach_msg_mac_trailer_t) : \
689 sizeof(mach_msg_max_trailer_t))))))))
690
691
692 #ifdef XNU_KERNEL_PRIVATE
693
694 #define REQUESTED_TRAILER_SIZE(is64, y) REQUESTED_TRAILER_SIZE_NATIVE(y)
695
696 #else /* XNU_KERNEL_PRIVATE */
697 #define REQUESTED_TRAILER_SIZE(y) REQUESTED_TRAILER_SIZE_NATIVE(y)
698 #endif /* XNU_KERNEL_PRIVATE */
699
700 /*
701 * Much code assumes that mach_msg_return_t == kern_return_t.
702 * This definition is useful for descriptive purposes.
703 *
704 * See <mach/error.h> for the format of error codes.
705 * IPC errors are system 4. Send errors are subsystem 0;
706 * receive errors are subsystem 1. The code field is always non-zero.
707 * The high bits of the code field communicate extra information
708 * for some error codes. MACH_MSG_MASK masks off these special bits.
709 */
710
711 typedef kern_return_t mach_msg_return_t;
712
713 #define MACH_MSG_SUCCESS 0x00000000
714
715
716 #define MACH_MSG_MASK 0x00003e00
717 /* All special error code bits defined below. */
718 #define MACH_MSG_IPC_SPACE 0x00002000
719 /* No room in IPC name space for another capability name. */
720 #define MACH_MSG_VM_SPACE 0x00001000
721 /* No room in VM address space for out-of-line memory. */
722 #define MACH_MSG_IPC_KERNEL 0x00000800
723 /* Kernel resource shortage handling an IPC capability. */
724 #define MACH_MSG_VM_KERNEL 0x00000400
725 /* Kernel resource shortage handling out-of-line memory. */
726
727 #define MACH_SEND_IN_PROGRESS 0x10000001
728 /* Thread is waiting to send. (Internal use only.) */
729 #define MACH_SEND_INVALID_DATA 0x10000002
730 /* Bogus in-line data. */
731 #define MACH_SEND_INVALID_DEST 0x10000003
732 /* Bogus destination port. */
733 #define MACH_SEND_TIMED_OUT 0x10000004
734 /* Message not sent before timeout expired. */
735 #define MACH_SEND_INTERRUPTED 0x10000007
736 /* Software interrupt. */
737 #define MACH_SEND_MSG_TOO_SMALL 0x10000008
738 /* Data doesn't contain a complete message. */
739 #define MACH_SEND_INVALID_REPLY 0x10000009
740 /* Bogus reply port. */
741 #define MACH_SEND_INVALID_RIGHT 0x1000000a
742 /* Bogus port rights in the message body. */
743 #define MACH_SEND_INVALID_NOTIFY 0x1000000b
744 /* Bogus notify port argument. */
745 #define MACH_SEND_INVALID_MEMORY 0x1000000c
746 /* Invalid out-of-line memory pointer. */
747 #define MACH_SEND_NO_BUFFER 0x1000000d
748 /* No message buffer is available. */
749 #define MACH_SEND_TOO_LARGE 0x1000000e
750 /* Send is too large for port */
751 #define MACH_SEND_INVALID_TYPE 0x1000000f
752 /* Invalid msg-type specification. */
753 #define MACH_SEND_INVALID_HEADER 0x10000010
754 /* A field in the header had a bad value. */
755 #define MACH_SEND_INVALID_TRAILER 0x10000011
756 /* The trailer to be sent does not match kernel format. */
757 #define MACH_SEND_INVALID_RT_OOL_SIZE 0x10000015
758 /* compatibility: no longer a returned error */
759
760 #define MACH_RCV_IN_PROGRESS 0x10004001
761 /* Thread is waiting for receive. (Internal use only.) */
762 #define MACH_RCV_INVALID_NAME 0x10004002
763 /* Bogus name for receive port/port-set. */
764 #define MACH_RCV_TIMED_OUT 0x10004003
765 /* Didn't get a message within the timeout value. */
766 #define MACH_RCV_TOO_LARGE 0x10004004
767 /* Message buffer is not large enough for inline data. */
768 #define MACH_RCV_INTERRUPTED 0x10004005
769 /* Software interrupt. */
770 #define MACH_RCV_PORT_CHANGED 0x10004006
771 /* compatibility: no longer a returned error */
772 #define MACH_RCV_INVALID_NOTIFY 0x10004007
773 /* Bogus notify port argument. */
774 #define MACH_RCV_INVALID_DATA 0x10004008
775 /* Bogus message buffer for inline data. */
776 #define MACH_RCV_PORT_DIED 0x10004009
777 /* Port/set was sent away/died during receive. */
778 #define MACH_RCV_IN_SET 0x1000400a
779 /* compatibility: no longer a returned error */
780 #define MACH_RCV_HEADER_ERROR 0x1000400b
781 /* Error receiving message header. See special bits. */
782 #define MACH_RCV_BODY_ERROR 0x1000400c
783 /* Error receiving message body. See special bits. */
784 #define MACH_RCV_INVALID_TYPE 0x1000400d
785 /* Invalid msg-type specification in scatter list. */
786 #define MACH_RCV_SCATTER_SMALL 0x1000400e
787 /* Out-of-line overwrite region is not large enough */
788 #define MACH_RCV_INVALID_TRAILER 0x1000400f
789 /* trailer type or number of trailer elements not supported */
790 #define MACH_RCV_IN_PROGRESS_TIMED 0x10004011
791 /* Waiting for receive with timeout. (Internal use only.) */
792
793
794 __BEGIN_DECLS
795
796 /*
797 * Routine: mach_msg_overwrite
798 * Purpose:
799 * Send and/or receive a message. If the message operation
800 * is interrupted, and the user did not request an indication
801 * of that fact, then restart the appropriate parts of the
802 * operation silently (trap version does not restart).
803 *
804 * Distinct send and receive buffers may be specified. If
805 * no separate receive buffer is specified, the msg parameter
806 * will be used for both send and receive operations.
807 *
808 * In addition to a distinct receive buffer, that buffer may
809 * already contain scatter control information to direct the
810 * receiving of the message.
811 */
812
813 extern mach_msg_return_t mach_msg_overwrite(
814 mach_msg_header_t *msg,
815 mach_msg_option_t option,
816 mach_msg_size_t send_size,
817 mach_msg_size_t rcv_size,
818 mach_port_name_t rcv_name,
819 mach_msg_timeout_t timeout,
820 mach_port_name_t notify,
821 mach_msg_header_t *rcv_msg,
822 mach_msg_size_t rcv_limit);
823
824 #ifndef KERNEL
825
826 /*
827 * Routine: mach_msg
828 * Purpose:
829 * Send and/or receive a message. If the message operation
830 * is interrupted, and the user did not request an indication
831 * of that fact, then restart the appropriate parts of the
832 * operation silently (trap version does not restart).
833 */
834 extern mach_msg_return_t mach_msg(
835 mach_msg_header_t *msg,
836 mach_msg_option_t option,
837 mach_msg_size_t send_size,
838 mach_msg_size_t rcv_size,
839 mach_port_name_t rcv_name,
840 mach_msg_timeout_t timeout,
841 mach_port_name_t notify);
842
843 #elif defined(MACH_KERNEL_PRIVATE)
844
845 extern mach_msg_return_t mach_msg_receive_results(void);
846
847 #endif /* KERNEL */
848
849 __END_DECLS
850
851 #endif /* _MACH_MESSAGE_H_ */
852