]> git.saurik.com Git - apple/xnu.git/blame_incremental - osfmk/mach/message.h
xnu-3248.40.184.tar.gz
[apple/xnu.git] / osfmk / mach / message.h
... / ...
CommitLineData
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
91typedef natural_t mach_msg_timeout_t;
92
93/*
94 * The value to be used when there is no timeout.
95 * (No MACH_SEND_TIMEOUT/MACH_RCV_TIMEOUT option.)
96 */
97
98#define MACH_MSG_TIMEOUT_NONE ((mach_msg_timeout_t) 0)
99
100/*
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
221typedef unsigned int mach_msg_bits_t;
222typedef natural_t mach_msg_size_t;
223typedef integer_t mach_msg_id_t;
224
225
226#define MACH_MSG_SIZE_NULL (mach_msg_size_t *) 0
227
228typedef 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
241typedef 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
263typedef 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
272typedef 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
280typedef 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
295typedef 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
305typedef 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
315typedef 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
333typedef 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
343typedef 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
353typedef 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)
377typedef 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
385typedef 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
394typedef 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
402typedef 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
415typedef struct
416{
417 mach_msg_header_t header;
418 mach_msg_body_t body;
419} mach_msg_base_t;
420
421typedef unsigned int mach_msg_trailer_type_t;
422
423#define MACH_MSG_TRAILER_FORMAT_0 0
424
425typedef unsigned int mach_msg_trailer_size_t;
426typedef char *mach_msg_trailer_info_t;
427
428typedef 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 */
443typedef 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
450typedef struct
451{
452 unsigned int val[2];
453} security_token_t;
454
455typedef 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 */
472typedef struct
473{
474 unsigned int val[8];
475} audit_token_t;
476
477typedef 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
486typedef 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
498typedef 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
508typedef 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
533typedef 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 */
543typedef 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} }
551extern security_token_t KERNEL_SECURITY_TOKEN;
552
553#define KERNEL_AUDIT_TOKEN_VALUE { {0, 0, 0, 0, 0, 0, 0, 0} }
554extern audit_token_t KERNEL_AUDIT_TOKEN;
555
556typedef integer_t mach_msg_options_t;
557
558typedef struct
559{
560 mach_msg_header_t header;
561} mach_msg_empty_send_t;
562
563typedef struct
564{
565 mach_msg_header_t header;
566 mach_msg_trailer_t trailer;
567} mach_msg_empty_rcv_t;
568
569typedef 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
606typedef natural_t mach_msg_type_size_t;
607typedef 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
650typedef 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/*
715 * Default options to use when sending from the kernel.
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 * (11938665 & 23925818)
721 */
722#define MACH_SEND_KERNEL_DEFAULT (MACH_SEND_MSG | \
723 MACH_SEND_ALWAYS | MACH_SEND_NOIMPORTANCE)
724
725#endif /* MACH_KERNEL_PRIVATE */
726
727/*
728 * XXXMAC: note that in the case of MACH_RCV_TRAILER_LABELS,
729 * we just fall through to mach_msg_max_trailer_t.
730 * This is correct behavior since mach_msg_max_trailer_t is defined as
731 * mac_msg_mac_trailer_t which is used for the LABELS trailer.
732 * It also makes things work properly if MACH_RCV_TRAILER_LABELS is ORed
733 * with one of the other options.
734 */
735
736#define REQUESTED_TRAILER_SIZE_NATIVE(y) \
737 ((mach_msg_trailer_size_t) \
738 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_NULL) ? \
739 sizeof(mach_msg_trailer_t) : \
740 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SEQNO) ? \
741 sizeof(mach_msg_seqno_trailer_t) : \
742 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SENDER) ? \
743 sizeof(mach_msg_security_trailer_t) : \
744 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AUDIT) ? \
745 sizeof(mach_msg_audit_trailer_t) : \
746 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_CTX) ? \
747 sizeof(mach_msg_context_trailer_t) : \
748 ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AV) ? \
749 sizeof(mach_msg_mac_trailer_t) : \
750 sizeof(mach_msg_max_trailer_t))))))))
751
752
753#ifdef XNU_KERNEL_PRIVATE
754
755#define REQUESTED_TRAILER_SIZE(is64, y) REQUESTED_TRAILER_SIZE_NATIVE(y)
756
757#else /* XNU_KERNEL_PRIVATE */
758#define REQUESTED_TRAILER_SIZE(y) REQUESTED_TRAILER_SIZE_NATIVE(y)
759#endif /* XNU_KERNEL_PRIVATE */
760
761/*
762 * Much code assumes that mach_msg_return_t == kern_return_t.
763 * This definition is useful for descriptive purposes.
764 *
765 * See <mach/error.h> for the format of error codes.
766 * IPC errors are system 4. Send errors are subsystem 0;
767 * receive errors are subsystem 1. The code field is always non-zero.
768 * The high bits of the code field communicate extra information
769 * for some error codes. MACH_MSG_MASK masks off these special bits.
770 */
771
772typedef kern_return_t mach_msg_return_t;
773
774#define MACH_MSG_SUCCESS 0x00000000
775
776
777#define MACH_MSG_MASK 0x00003e00
778 /* All special error code bits defined below. */
779#define MACH_MSG_IPC_SPACE 0x00002000
780 /* No room in IPC name space for another capability name. */
781#define MACH_MSG_VM_SPACE 0x00001000
782 /* No room in VM address space for out-of-line memory. */
783#define MACH_MSG_IPC_KERNEL 0x00000800
784 /* Kernel resource shortage handling an IPC capability. */
785#define MACH_MSG_VM_KERNEL 0x00000400
786 /* Kernel resource shortage handling out-of-line memory. */
787
788#define MACH_SEND_IN_PROGRESS 0x10000001
789 /* Thread is waiting to send. (Internal use only.) */
790#define MACH_SEND_INVALID_DATA 0x10000002
791 /* Bogus in-line data. */
792#define MACH_SEND_INVALID_DEST 0x10000003
793 /* Bogus destination port. */
794#define MACH_SEND_TIMED_OUT 0x10000004
795 /* Message not sent before timeout expired. */
796#define MACH_SEND_INVALID_VOUCHER 0x10000005
797 /* Bogus voucher port. */
798#define MACH_SEND_INTERRUPTED 0x10000007
799 /* Software interrupt. */
800#define MACH_SEND_MSG_TOO_SMALL 0x10000008
801 /* Data doesn't contain a complete message. */
802#define MACH_SEND_INVALID_REPLY 0x10000009
803 /* Bogus reply port. */
804#define MACH_SEND_INVALID_RIGHT 0x1000000a
805 /* Bogus port rights in the message body. */
806#define MACH_SEND_INVALID_NOTIFY 0x1000000b
807 /* Bogus notify port argument. */
808#define MACH_SEND_INVALID_MEMORY 0x1000000c
809 /* Invalid out-of-line memory pointer. */
810#define MACH_SEND_NO_BUFFER 0x1000000d
811 /* No message buffer is available. */
812#define MACH_SEND_TOO_LARGE 0x1000000e
813 /* Send is too large for port */
814#define MACH_SEND_INVALID_TYPE 0x1000000f
815 /* Invalid msg-type specification. */
816#define MACH_SEND_INVALID_HEADER 0x10000010
817 /* A field in the header had a bad value. */
818#define MACH_SEND_INVALID_TRAILER 0x10000011
819 /* The trailer to be sent does not match kernel format. */
820#define MACH_SEND_INVALID_RT_OOL_SIZE 0x10000015
821 /* compatibility: no longer a returned error */
822
823#define MACH_RCV_IN_PROGRESS 0x10004001
824 /* Thread is waiting for receive. (Internal use only.) */
825#define MACH_RCV_INVALID_NAME 0x10004002
826 /* Bogus name for receive port/port-set. */
827#define MACH_RCV_TIMED_OUT 0x10004003
828 /* Didn't get a message within the timeout value. */
829#define MACH_RCV_TOO_LARGE 0x10004004
830 /* Message buffer is not large enough for inline data. */
831#define MACH_RCV_INTERRUPTED 0x10004005
832 /* Software interrupt. */
833#define MACH_RCV_PORT_CHANGED 0x10004006
834 /* compatibility: no longer a returned error */
835#define MACH_RCV_INVALID_NOTIFY 0x10004007
836 /* Bogus notify port argument. */
837#define MACH_RCV_INVALID_DATA 0x10004008
838 /* Bogus message buffer for inline data. */
839#define MACH_RCV_PORT_DIED 0x10004009
840 /* Port/set was sent away/died during receive. */
841#define MACH_RCV_IN_SET 0x1000400a
842 /* compatibility: no longer a returned error */
843#define MACH_RCV_HEADER_ERROR 0x1000400b
844 /* Error receiving message header. See special bits. */
845#define MACH_RCV_BODY_ERROR 0x1000400c
846 /* Error receiving message body. See special bits. */
847#define MACH_RCV_INVALID_TYPE 0x1000400d
848 /* Invalid msg-type specification in scatter list. */
849#define MACH_RCV_SCATTER_SMALL 0x1000400e
850 /* Out-of-line overwrite region is not large enough */
851#define MACH_RCV_INVALID_TRAILER 0x1000400f
852 /* trailer type or number of trailer elements not supported */
853#define MACH_RCV_IN_PROGRESS_TIMED 0x10004011
854 /* Waiting for receive with timeout. (Internal use only.) */
855
856
857__BEGIN_DECLS
858
859/*
860 * Routine: mach_msg_overwrite
861 * Purpose:
862 * Send and/or receive a message. If the message operation
863 * is interrupted, and the user did not request an indication
864 * of that fact, then restart the appropriate parts of the
865 * operation silently (trap version does not restart).
866 *
867 * Distinct send and receive buffers may be specified. If
868 * no separate receive buffer is specified, the msg parameter
869 * will be used for both send and receive operations.
870 *
871 * In addition to a distinct receive buffer, that buffer may
872 * already contain scatter control information to direct the
873 * receiving of the message.
874 */
875__WATCHOS_PROHIBITED __TVOS_PROHIBITED
876extern mach_msg_return_t mach_msg_overwrite(
877 mach_msg_header_t *msg,
878 mach_msg_option_t option,
879 mach_msg_size_t send_size,
880 mach_msg_size_t rcv_size,
881 mach_port_name_t rcv_name,
882 mach_msg_timeout_t timeout,
883 mach_port_name_t notify,
884 mach_msg_header_t *rcv_msg,
885 mach_msg_size_t rcv_limit);
886
887#ifndef KERNEL
888
889/*
890 * Routine: mach_msg
891 * Purpose:
892 * Send and/or receive a message. If the message operation
893 * is interrupted, and the user did not request an indication
894 * of that fact, then restart the appropriate parts of the
895 * operation silently (trap version does not restart).
896 */
897__WATCHOS_PROHIBITED __TVOS_PROHIBITED
898extern mach_msg_return_t mach_msg(
899 mach_msg_header_t *msg,
900 mach_msg_option_t option,
901 mach_msg_size_t send_size,
902 mach_msg_size_t rcv_size,
903 mach_port_name_t rcv_name,
904 mach_msg_timeout_t timeout,
905 mach_port_name_t notify);
906
907/*
908 * Routine: mach_voucher_deallocate
909 * Purpose:
910 * Deallocate a mach voucher created or received in a message. Drops
911 * one (send right) reference to the voucher.
912 */
913__WATCHOS_PROHIBITED __TVOS_PROHIBITED
914extern kern_return_t mach_voucher_deallocate(
915 mach_port_name_t voucher);
916
917#elif defined(MACH_KERNEL_PRIVATE)
918
919extern mach_msg_return_t mach_msg_receive_results(void);
920
921#endif /* KERNEL */
922
923__END_DECLS
924
925#endif /* _MACH_MESSAGE_H_ */
926