]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
0a7de745 | 31 | /* |
1c79356b A |
32 | * Mach Operating System |
33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
0a7de745 | 35 | * |
1c79356b A |
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. | |
0a7de745 | 41 | * |
1c79356b A |
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. | |
0a7de745 | 45 | * |
1c79356b | 46 | * Carnegie Mellon requests users of this software to return to |
0a7de745 | 47 | * |
1c79356b A |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
0a7de745 | 52 | * |
1c79356b A |
53 | * any improvements or extensions that they make and grant Carnegie Mellon |
54 | * the rights to redistribute these changes. | |
55 | */ | |
2d21ac55 A |
56 | /* |
57 | * NOTICE: This file was modified by McAfee Research in 2004 to introduce | |
58 | * support for mandatory and extensible security protections. This notice | |
59 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
60 | * Version 2.0. | |
61 | * Copyright (c) 2005 SPARTA, Inc. | |
62 | */ | |
1c79356b A |
63 | /* |
64 | */ | |
65 | /* | |
66 | * File: mach/message.h | |
67 | * | |
68 | * Mach IPC message and primitive function definitions. | |
69 | */ | |
70 | ||
0a7de745 | 71 | #ifndef _MACH_MESSAGE_H_ |
1c79356b A |
72 | #define _MACH_MESSAGE_H_ |
73 | ||
9bccf70c A |
74 | #include <stdint.h> |
75 | #include <mach/port.h> | |
76 | #include <mach/boolean.h> | |
77 | #include <mach/kern_return.h> | |
78 | #include <mach/machine/vm_types.h> | |
1c79356b | 79 | |
91447636 | 80 | #include <sys/cdefs.h> |
316670eb | 81 | #include <sys/appleapiopts.h> |
3e170ce0 | 82 | #include <Availability.h> |
f427ee49 A |
83 | #if !KERNEL && PRIVATE |
84 | #include <TargetConditionals.h> | |
85 | #endif | |
91447636 | 86 | |
1c79356b A |
87 | /* |
88 | * The timeout mechanism uses mach_msg_timeout_t values, | |
89 | * passed by value. The timeout units are milliseconds. | |
90 | * It is controlled with the MACH_SEND_TIMEOUT | |
91 | * and MACH_RCV_TIMEOUT options. | |
92 | */ | |
93 | ||
94 | typedef natural_t mach_msg_timeout_t; | |
95 | ||
96 | /* | |
97 | * The value to be used when there is no timeout. | |
98 | * (No MACH_SEND_TIMEOUT/MACH_RCV_TIMEOUT option.) | |
99 | */ | |
100 | ||
0a7de745 | 101 | #define MACH_MSG_TIMEOUT_NONE ((mach_msg_timeout_t) 0) |
1c79356b A |
102 | |
103 | /* | |
b0d623f7 | 104 | * The kernel uses MACH_MSGH_BITS_COMPLEX as a hint. If it isn't on, it |
1c79356b A |
105 | * assumes the body of the message doesn't contain port rights or OOL |
106 | * data. The field is set in received messages. A user task must | |
107 | * use caution in interpreting the body of a message if the bit isn't | |
108 | * on, because the mach_msg_type's in the body might "lie" about the | |
109 | * contents. If the bit isn't on, but the mach_msg_types | |
110 | * in the body specify rights or OOL data, the behavior is undefined. | |
111 | * (Ie, an error may or may not be produced.) | |
112 | * | |
113 | * The value of MACH_MSGH_BITS_REMOTE determines the interpretation | |
fe8ab488 A |
114 | * of the msgh_remote_port field. It is handled like a msgt_name, |
115 | * but must result in a send or send-once type right. | |
1c79356b A |
116 | * |
117 | * The value of MACH_MSGH_BITS_LOCAL determines the interpretation | |
fe8ab488 A |
118 | * of the msgh_local_port field. It is handled like a msgt_name, |
119 | * and also must result in a send or send-once type right. | |
120 | * | |
121 | * The value of MACH_MSGH_BITS_VOUCHER determines the interpretation | |
122 | * of the msgh_voucher_port field. It is handled like a msgt_name, | |
123 | * but must result in a send right (and the msgh_voucher_port field | |
124 | * must be the name of a send right to a Mach voucher kernel object. | |
1c79356b A |
125 | * |
126 | * MACH_MSGH_BITS() combines two MACH_MSG_TYPE_* values, for the remote | |
127 | * and local fields, into a single value suitable for msgh_bits. | |
128 | * | |
129 | * MACH_MSGH_BITS_CIRCULAR should be zero; is is used internally. | |
130 | * | |
131 | * The unused bits should be zero and are reserved for the kernel | |
132 | * or for future interface expansion. | |
133 | */ | |
134 | ||
0a7de745 | 135 | #define MACH_MSGH_BITS_ZERO 0x00000000 |
1c79356b | 136 | |
0a7de745 A |
137 | #define MACH_MSGH_BITS_REMOTE_MASK 0x0000001f |
138 | #define MACH_MSGH_BITS_LOCAL_MASK 0x00001f00 | |
139 | #define MACH_MSGH_BITS_VOUCHER_MASK 0x001f0000 | |
fe8ab488 | 140 | |
0a7de745 A |
141 | #define MACH_MSGH_BITS_PORTS_MASK \ |
142 | (MACH_MSGH_BITS_REMOTE_MASK | \ | |
143 | MACH_MSGH_BITS_LOCAL_MASK | \ | |
144 | MACH_MSGH_BITS_VOUCHER_MASK) | |
fe8ab488 | 145 | |
0a7de745 | 146 | #define MACH_MSGH_BITS_COMPLEX 0x80000000U /* message is complex */ |
fe8ab488 | 147 | |
0a7de745 | 148 | #define MACH_MSGH_BITS_USER 0x801f1f1fU /* allowed bits user->kernel */ |
fe8ab488 | 149 | |
0a7de745 A |
150 | #define MACH_MSGH_BITS_RAISEIMP 0x20000000U /* importance raised due to msg */ |
151 | #define MACH_MSGH_BITS_DENAP MACH_MSGH_BITS_RAISEIMP | |
1c79356b | 152 | |
0a7de745 A |
153 | #define MACH_MSGH_BITS_IMPHOLDASRT 0x10000000U /* assertion help, userland private */ |
154 | #define MACH_MSGH_BITS_DENAPHOLDASRT MACH_MSGH_BITS_IMPHOLDASRT | |
1c79356b | 155 | |
0a7de745 | 156 | #define MACH_MSGH_BITS_CIRCULAR 0x10000000U /* message circular, kernel private */ |
fe8ab488 | 157 | |
0a7de745 | 158 | #define MACH_MSGH_BITS_USED 0xb01f1f1fU |
fe8ab488 A |
159 | |
160 | /* setter macros for the bits */ | |
0a7de745 A |
161 | #define MACH_MSGH_BITS(remote, local) /* legacy */ \ |
162 | ((remote) | ((local) << 8)) | |
163 | #define MACH_MSGH_BITS_SET_PORTS(remote, local, voucher) \ | |
164 | (((remote) & MACH_MSGH_BITS_REMOTE_MASK) | \ | |
165 | (((local) << 8) & MACH_MSGH_BITS_LOCAL_MASK) | \ | |
fe8ab488 | 166 | (((voucher) << 16) & MACH_MSGH_BITS_VOUCHER_MASK)) |
0a7de745 | 167 | #define MACH_MSGH_BITS_SET(remote, local, voucher, other) \ |
fe8ab488 A |
168 | (MACH_MSGH_BITS_SET_PORTS((remote), (local), (voucher)) \ |
169 | | ((other) &~ MACH_MSGH_BITS_PORTS_MASK)) | |
170 | ||
171 | /* getter macros for pulling values out of the bits field */ | |
0a7de745 A |
172 | #define MACH_MSGH_BITS_REMOTE(bits) \ |
173 | ((bits) & MACH_MSGH_BITS_REMOTE_MASK) | |
174 | #define MACH_MSGH_BITS_LOCAL(bits) \ | |
175 | (((bits) & MACH_MSGH_BITS_LOCAL_MASK) >> 8) | |
176 | #define MACH_MSGH_BITS_VOUCHER(bits) \ | |
177 | (((bits) & MACH_MSGH_BITS_VOUCHER_MASK) >> 16) | |
178 | #define MACH_MSGH_BITS_PORTS(bits) \ | |
fe8ab488 | 179 | ((bits) & MACH_MSGH_BITS_PORTS_MASK) |
0a7de745 A |
180 | #define MACH_MSGH_BITS_OTHER(bits) \ |
181 | ((bits) &~ MACH_MSGH_BITS_PORTS_MASK) | |
1c79356b | 182 | |
fe8ab488 | 183 | /* checking macros */ |
0a7de745 | 184 | #define MACH_MSGH_BITS_HAS_REMOTE(bits) \ |
fe8ab488 | 185 | (MACH_MSGH_BITS_REMOTE(bits) != MACH_MSGH_BITS_ZERO) |
0a7de745 | 186 | #define MACH_MSGH_BITS_HAS_LOCAL(bits) \ |
fe8ab488 | 187 | (MACH_MSGH_BITS_LOCAL(bits) != MACH_MSGH_BITS_ZERO) |
0a7de745 | 188 | #define MACH_MSGH_BITS_HAS_VOUCHER(bits) \ |
fe8ab488 | 189 | (MACH_MSGH_BITS_VOUCHER(bits) != MACH_MSGH_BITS_ZERO) |
0a7de745 | 190 | #define MACH_MSGH_BITS_IS_COMPLEX(bits) \ |
fe8ab488 A |
191 | (((bits) & MACH_MSGH_BITS_COMPLEX) != MACH_MSGH_BITS_ZERO) |
192 | ||
193 | /* importance checking macros */ | |
0a7de745 | 194 | #define MACH_MSGH_BITS_RAISED_IMPORTANCE(bits) \ |
fe8ab488 | 195 | (((bits) & MACH_MSGH_BITS_RAISEIMP) != MACH_MSGH_BITS_ZERO) |
0a7de745 | 196 | #define MACH_MSGH_BITS_HOLDS_IMPORTANCE_ASSERTION(bits) \ |
fe8ab488 A |
197 | (((bits) & MACH_MSGH_BITS_IMPHOLDASRT) != MACH_MSGH_BITS_ZERO) |
198 | ||
1c79356b A |
199 | /* |
200 | * Every message starts with a message header. | |
b0d623f7 | 201 | * Following the message header, if the message is complex, are a count |
0a7de745 A |
202 | * of type descriptors and the type descriptors themselves |
203 | * (mach_msg_descriptor_t). The size of the message must be specified in | |
204 | * bytes, and includes the message header, descriptor count, descriptors, | |
b0d623f7 | 205 | * and inline data. |
1c79356b A |
206 | * |
207 | * The msgh_remote_port field specifies the destination of the message. | |
208 | * It must specify a valid send or send-once right for a port. | |
209 | * | |
210 | * The msgh_local_port field specifies a "reply port". Normally, | |
211 | * This field carries a send-once right that the receiver will use | |
212 | * to reply to the message. It may carry the values MACH_PORT_NULL, | |
213 | * MACH_PORT_DEAD, a send-once right, or a send right. | |
214 | * | |
fe8ab488 A |
215 | * The msgh_voucher_port field specifies a Mach voucher port. Only |
216 | * send rights to kernel-implemented Mach Voucher kernel objects in | |
217 | * addition to MACH_PORT_NULL or MACH_PORT_DEAD may be passed. | |
1c79356b A |
218 | * |
219 | * The msgh_id field is uninterpreted by the message primitives. | |
220 | * It normally carries information specifying the format | |
221 | * or meaning of the message. | |
222 | */ | |
223 | ||
224 | typedef unsigned int mach_msg_bits_t; | |
0a7de745 | 225 | typedef natural_t mach_msg_size_t; |
1c79356b A |
226 | typedef integer_t mach_msg_id_t; |
227 | ||
1c79356b A |
228 | #define MACH_MSG_SIZE_NULL (mach_msg_size_t *) 0 |
229 | ||
39037602 A |
230 | typedef unsigned int mach_msg_priority_t; |
231 | ||
232 | #define MACH_MSG_PRIORITY_UNSPECIFIED (mach_msg_priority_t) 0 | |
233 | ||
f427ee49 A |
234 | #if PRIVATE |
235 | typedef uint8_t mach_msg_qos_t; // same as thread_qos_t | |
236 | #define MACH_MSG_QOS_UNSPECIFIED 0 | |
237 | #define MACH_MSG_QOS_MAINTENANCE 1 | |
238 | #define MACH_MSG_QOS_BACKGROUND 2 | |
239 | #define MACH_MSG_QOS_UTILITY 3 | |
240 | #define MACH_MSG_QOS_DEFAULT 4 | |
241 | #define MACH_MSG_QOS_USER_INITIATED 5 | |
242 | #define MACH_MSG_QOS_USER_INTERACTIVE 6 | |
243 | #define MACH_MSG_QOS_LAST 6 | |
244 | ||
245 | extern int mach_msg_priority_is_pthread_priority(mach_msg_priority_t pri); | |
246 | extern mach_msg_priority_t mach_msg_priority_encode( | |
247 | mach_msg_qos_t override_qos, | |
248 | mach_msg_qos_t qos, | |
249 | int relpri); | |
250 | extern mach_msg_qos_t mach_msg_priority_overide_qos(mach_msg_priority_t pri); | |
251 | extern mach_msg_qos_t mach_msg_priority_qos(mach_msg_priority_t pri); | |
252 | extern int mach_msg_priority_relpri(mach_msg_priority_t pri); | |
253 | ||
254 | #if KERNEL || !TARGET_OS_SIMULATOR | |
255 | static inline int | |
256 | mach_msg_priority_is_pthread_priority_inline(mach_msg_priority_t pri) | |
257 | { | |
258 | return (pri & 0xff) == 0xff; | |
259 | } | |
260 | ||
261 | #define MACH_MSG_PRIORITY_RELPRI_SHIFT 8 | |
262 | #define MACH_MSG_PRIORITY_RELPRI_MASK (0xff << MACH_MSG_PRIORITY_RELPRI_SHIFT) | |
263 | #define MACH_MSG_PRIORITY_QOS_SHIFT 16 | |
264 | #define MACH_MSG_PRIORITY_QOS_MASK (0xf << MACH_MSG_PRIORITY_QOS_SHIFT) | |
265 | #define MACH_MSG_PRIORITY_OVERRIDE_SHIFT 20 | |
266 | #define MACH_MSG_PRIORITY_OVERRIDE_MASK (0xf << MACH_MSG_PRIORITY_OVERRIDE_SHIFT) | |
267 | ||
268 | static inline mach_msg_priority_t | |
269 | mach_msg_priority_encode_inline(mach_msg_qos_t override_qos, mach_msg_qos_t qos, int relpri) | |
270 | { | |
271 | mach_msg_priority_t pri = 0; | |
272 | if (qos > 0 && qos <= MACH_MSG_QOS_LAST) { | |
273 | pri |= (uint32_t)(qos << MACH_MSG_PRIORITY_QOS_SHIFT); | |
274 | pri |= (uint32_t)((uint8_t)(relpri - 1) << MACH_MSG_PRIORITY_RELPRI_SHIFT); | |
275 | } | |
276 | if (override_qos > 0 && override_qos <= MACH_MSG_QOS_LAST) { | |
277 | pri |= (uint32_t)(override_qos << MACH_MSG_PRIORITY_OVERRIDE_SHIFT); | |
278 | } | |
279 | return pri; | |
280 | } | |
281 | ||
282 | static inline mach_msg_qos_t | |
283 | mach_msg_priority_overide_qos_inline(mach_msg_priority_t pri) | |
284 | { | |
285 | pri &= MACH_MSG_PRIORITY_OVERRIDE_MASK; | |
286 | pri >>= MACH_MSG_PRIORITY_OVERRIDE_SHIFT; | |
287 | return (mach_msg_qos_t)(pri <= MACH_MSG_QOS_LAST ? pri : 0); | |
288 | } | |
289 | ||
290 | static inline mach_msg_qos_t | |
291 | mach_msg_priority_qos_inline(mach_msg_priority_t pri) | |
292 | { | |
293 | pri &= MACH_MSG_PRIORITY_QOS_MASK; | |
294 | pri >>= MACH_MSG_PRIORITY_QOS_SHIFT; | |
295 | return (mach_msg_qos_t)(pri <= MACH_MSG_QOS_LAST ? pri : 0); | |
296 | } | |
297 | ||
298 | static inline int | |
299 | mach_msg_priority_relpri_inline(mach_msg_priority_t pri) | |
300 | { | |
301 | if (mach_msg_priority_qos_inline(pri)) { | |
302 | return (int8_t)(pri >> MACH_MSG_PRIORITY_RELPRI_SHIFT) + 1; | |
303 | } | |
304 | return 0; | |
305 | } | |
306 | ||
307 | #define mach_msg_priority_is_pthread_priority(...) \ | |
308 | mach_msg_priority_is_pthread_priority_inline(__VA_ARGS__) | |
309 | #define mach_msg_priority_encode(...) \ | |
310 | mach_msg_priority_encode_inline(__VA_ARGS__) | |
311 | #define mach_msg_priority_overide_qos(...) \ | |
312 | mach_msg_priority_overide_qos_inline(__VA_ARGS__) | |
313 | #define mach_msg_priority_qos(...) \ | |
314 | mach_msg_priority_qos_inline(__VA_ARGS__) | |
315 | #define mach_msg_priority_relpri(...) \ | |
316 | mach_msg_priority_relpri_inline(__VA_ARGS__) | |
317 | #endif | |
318 | ||
319 | #endif // PRIVATE | |
320 | ||
1c79356b A |
321 | typedef unsigned int mach_msg_type_name_t; |
322 | ||
0a7de745 A |
323 | #define MACH_MSG_TYPE_MOVE_RECEIVE 16 /* Must hold receive right */ |
324 | #define MACH_MSG_TYPE_MOVE_SEND 17 /* Must hold send right(s) */ | |
325 | #define MACH_MSG_TYPE_MOVE_SEND_ONCE 18 /* Must hold sendonce right */ | |
326 | #define MACH_MSG_TYPE_COPY_SEND 19 /* Must hold send right(s) */ | |
327 | #define MACH_MSG_TYPE_MAKE_SEND 20 /* Must hold receive right */ | |
328 | #define MACH_MSG_TYPE_MAKE_SEND_ONCE 21 /* Must hold receive right */ | |
329 | #define MACH_MSG_TYPE_COPY_RECEIVE 22 /* NOT VALID */ | |
330 | #define MACH_MSG_TYPE_DISPOSE_RECEIVE 24 /* must hold receive right */ | |
331 | #define MACH_MSG_TYPE_DISPOSE_SEND 25 /* must hold send right(s) */ | |
332 | #define MACH_MSG_TYPE_DISPOSE_SEND_ONCE 26 /* must hold sendonce right */ | |
1c79356b A |
333 | |
334 | typedef unsigned int mach_msg_copy_options_t; | |
335 | ||
0a7de745 A |
336 | #define MACH_MSG_PHYSICAL_COPY 0 |
337 | #define MACH_MSG_VIRTUAL_COPY 1 | |
338 | #define MACH_MSG_ALLOCATE 2 | |
339 | #define MACH_MSG_OVERWRITE 3 /* deprecated */ | |
1c79356b | 340 | #ifdef MACH_KERNEL |
0a7de745 | 341 | #define MACH_MSG_KALLOC_COPY_T 4 |
1c79356b A |
342 | #endif /* MACH_KERNEL */ |
343 | ||
cb323159 A |
344 | #define MACH_MSG_GUARD_FLAGS_NONE 0x0000 |
345 | #define MACH_MSG_GUARD_FLAGS_IMMOVABLE_RECEIVE 0x0001 /* Move the receive right and mark it as immovable */ | |
346 | #define MACH_MSG_GUARD_FLAGS_UNGUARDED_ON_SEND 0x0002 /* Verify that the port is unguarded */ | |
347 | #define MACH_MSG_GUARD_FLAGS_MASK 0x0003 /* Valid flag bits */ | |
348 | typedef unsigned int mach_msg_guard_flags_t; | |
349 | ||
b0d623f7 | 350 | /* |
0a7de745 A |
351 | * In a complex mach message, the mach_msg_header_t is followed by |
352 | * a descriptor count, then an array of that number of descriptors | |
b0d623f7 A |
353 | * (mach_msg_*_descriptor_t). The type field of mach_msg_type_descriptor_t |
354 | * (which any descriptor can be cast to) indicates the flavor of the | |
355 | * descriptor. | |
356 | * | |
357 | * Note that in LP64, the various types of descriptors are no longer all | |
0a7de745 | 358 | * the same size as mach_msg_descriptor_t, so the array cannot be indexed |
b0d623f7 A |
359 | * as expected. |
360 | */ | |
361 | ||
1c79356b A |
362 | typedef unsigned int mach_msg_descriptor_type_t; |
363 | ||
0a7de745 A |
364 | #define MACH_MSG_PORT_DESCRIPTOR 0 |
365 | #define MACH_MSG_OOL_DESCRIPTOR 1 | |
366 | #define MACH_MSG_OOL_PORTS_DESCRIPTOR 2 | |
367 | #define MACH_MSG_OOL_VOLATILE_DESCRIPTOR 3 | |
cb323159 | 368 | #define MACH_MSG_GUARDED_PORT_DESCRIPTOR 4 |
1c79356b | 369 | |
cb323159 | 370 | #pragma pack(push, 4) |
1c79356b | 371 | |
0a7de745 A |
372 | typedef struct{ |
373 | natural_t pad1; | |
374 | mach_msg_size_t pad2; | |
375 | unsigned int pad3 : 24; | |
376 | mach_msg_descriptor_type_t type : 8; | |
1c79356b A |
377 | } mach_msg_type_descriptor_t; |
378 | ||
0a7de745 A |
379 | typedef struct{ |
380 | mach_port_t name; | |
b0d623f7 A |
381 | #if !(defined(KERNEL) && defined(__LP64__)) |
382 | // Pad to 8 bytes everywhere except the K64 kernel where mach_port_t is 8 bytes | |
0a7de745 | 383 | mach_msg_size_t pad1; |
b0d623f7 | 384 | #endif |
0a7de745 A |
385 | unsigned int pad2 : 16; |
386 | mach_msg_type_name_t disposition : 8; | |
387 | mach_msg_descriptor_type_t type : 8; | |
b0d623f7 | 388 | #if defined(KERNEL) |
0a7de745 | 389 | uint32_t pad_end; |
b0d623f7 | 390 | #endif |
1c79356b A |
391 | } mach_msg_port_descriptor_t; |
392 | ||
0a7de745 A |
393 | typedef struct{ |
394 | uint32_t address; | |
395 | mach_msg_size_t size; | |
396 | boolean_t deallocate: 8; | |
397 | mach_msg_copy_options_t copy: 8; | |
398 | unsigned int pad1: 8; | |
399 | mach_msg_descriptor_type_t type: 8; | |
91447636 A |
400 | } mach_msg_ool_descriptor32_t; |
401 | ||
0a7de745 A |
402 | typedef struct{ |
403 | uint64_t address; | |
404 | boolean_t deallocate: 8; | |
405 | mach_msg_copy_options_t copy: 8; | |
406 | unsigned int pad1: 8; | |
407 | mach_msg_descriptor_type_t type: 8; | |
408 | mach_msg_size_t size; | |
91447636 A |
409 | } mach_msg_ool_descriptor64_t; |
410 | ||
0a7de745 A |
411 | typedef struct{ |
412 | void* address; | |
91447636 | 413 | #if !defined(__LP64__) |
0a7de745 | 414 | mach_msg_size_t size; |
91447636 | 415 | #endif |
0a7de745 A |
416 | boolean_t deallocate: 8; |
417 | mach_msg_copy_options_t copy: 8; | |
418 | unsigned int pad1: 8; | |
419 | mach_msg_descriptor_type_t type: 8; | |
91447636 | 420 | #if defined(__LP64__) |
0a7de745 | 421 | mach_msg_size_t size; |
91447636 | 422 | #endif |
b0d623f7 | 423 | #if defined(KERNEL) && !defined(__LP64__) |
0a7de745 | 424 | uint32_t pad_end; |
b0d623f7 | 425 | #endif |
1c79356b A |
426 | } mach_msg_ool_descriptor_t; |
427 | ||
0a7de745 A |
428 | typedef struct{ |
429 | uint32_t address; | |
430 | mach_msg_size_t count; | |
431 | boolean_t deallocate: 8; | |
432 | mach_msg_copy_options_t copy: 8; | |
433 | mach_msg_type_name_t disposition : 8; | |
434 | mach_msg_descriptor_type_t type : 8; | |
91447636 A |
435 | } mach_msg_ool_ports_descriptor32_t; |
436 | ||
0a7de745 A |
437 | typedef struct{ |
438 | uint64_t address; | |
439 | boolean_t deallocate: 8; | |
440 | mach_msg_copy_options_t copy: 8; | |
441 | mach_msg_type_name_t disposition : 8; | |
442 | mach_msg_descriptor_type_t type : 8; | |
443 | mach_msg_size_t count; | |
91447636 A |
444 | } mach_msg_ool_ports_descriptor64_t; |
445 | ||
0a7de745 A |
446 | typedef struct{ |
447 | void* address; | |
91447636 | 448 | #if !defined(__LP64__) |
0a7de745 | 449 | mach_msg_size_t count; |
91447636 | 450 | #endif |
0a7de745 A |
451 | boolean_t deallocate: 8; |
452 | mach_msg_copy_options_t copy: 8; | |
453 | mach_msg_type_name_t disposition : 8; | |
454 | mach_msg_descriptor_type_t type : 8; | |
91447636 | 455 | #if defined(__LP64__) |
0a7de745 | 456 | mach_msg_size_t count; |
91447636 | 457 | #endif |
b0d623f7 | 458 | #if defined(KERNEL) && !defined(__LP64__) |
0a7de745 | 459 | uint32_t pad_end; |
b0d623f7 | 460 | #endif |
1c79356b A |
461 | } mach_msg_ool_ports_descriptor_t; |
462 | ||
cb323159 A |
463 | typedef struct{ |
464 | uint32_t context; | |
465 | mach_port_name_t name; | |
466 | mach_msg_guard_flags_t flags : 16; | |
467 | mach_msg_type_name_t disposition : 8; | |
468 | mach_msg_descriptor_type_t type : 8; | |
469 | } mach_msg_guarded_port_descriptor32_t; | |
470 | ||
471 | typedef struct{ | |
472 | uint64_t context; | |
473 | mach_msg_guard_flags_t flags : 16; | |
474 | mach_msg_type_name_t disposition : 8; | |
475 | mach_msg_descriptor_type_t type : 8; | |
476 | mach_port_name_t name; | |
477 | } mach_msg_guarded_port_descriptor64_t; | |
478 | ||
479 | typedef struct{ | |
480 | #if defined(KERNEL) | |
481 | mach_port_t name; | |
482 | #if !defined(__LP64__) | |
483 | uint32_t pad1; | |
484 | #endif | |
485 | mach_msg_guard_flags_t flags : 16; | |
486 | mach_msg_type_name_t disposition : 8; | |
487 | mach_msg_descriptor_type_t type : 8; | |
488 | #if defined(__LP64__) | |
489 | uint32_t pad_end; | |
490 | #endif /* defined(__LP64__) */ | |
491 | #else | |
492 | mach_port_context_t context; | |
493 | #if !defined(__LP64__) | |
494 | mach_port_name_t name; | |
495 | #endif | |
496 | mach_msg_guard_flags_t flags : 16; | |
497 | mach_msg_type_name_t disposition : 8; | |
498 | mach_msg_descriptor_type_t type : 8; | |
499 | #if defined(__LP64__) | |
500 | mach_port_name_t name; | |
501 | #endif /* defined(__LP64__) */ | |
502 | #endif /* defined(KERNEL) */ | |
503 | } mach_msg_guarded_port_descriptor_t; | |
504 | ||
91447636 A |
505 | /* |
506 | * LP64support - This union definition is not really | |
507 | * appropriate in LP64 mode because not all descriptors | |
508 | * are of the same size in that environment. | |
509 | */ | |
b0d623f7 | 510 | #if defined(__LP64__) && defined(KERNEL) |
0a7de745 A |
511 | typedef union{ |
512 | mach_msg_port_descriptor_t port; | |
513 | mach_msg_ool_descriptor32_t out_of_line; | |
514 | mach_msg_ool_ports_descriptor32_t ool_ports; | |
515 | mach_msg_type_descriptor_t type; | |
cb323159 | 516 | mach_msg_guarded_port_descriptor32_t guarded_port; |
b0d623f7 A |
517 | } mach_msg_descriptor_t; |
518 | #else | |
0a7de745 A |
519 | typedef union{ |
520 | mach_msg_port_descriptor_t port; | |
521 | mach_msg_ool_descriptor_t out_of_line; | |
522 | mach_msg_ool_ports_descriptor_t ool_ports; | |
523 | mach_msg_type_descriptor_t type; | |
cb323159 | 524 | mach_msg_guarded_port_descriptor_t guarded_port; |
1c79356b | 525 | } mach_msg_descriptor_t; |
b0d623f7 | 526 | #endif |
1c79356b | 527 | |
0a7de745 A |
528 | typedef struct{ |
529 | mach_msg_size_t msgh_descriptor_count; | |
1c79356b A |
530 | } mach_msg_body_t; |
531 | ||
532 | #define MACH_MSG_BODY_NULL (mach_msg_body_t *) 0 | |
533 | #define MACH_MSG_DESCRIPTOR_NULL (mach_msg_descriptor_t *) 0 | |
534 | ||
0a7de745 A |
535 | typedef struct{ |
536 | mach_msg_bits_t msgh_bits; | |
537 | mach_msg_size_t msgh_size; | |
538 | mach_port_t msgh_remote_port; | |
539 | mach_port_t msgh_local_port; | |
540 | mach_port_name_t msgh_voucher_port; | |
541 | mach_msg_id_t msgh_id; | |
1c79356b A |
542 | } mach_msg_header_t; |
543 | ||
0a7de745 A |
544 | #define msgh_reserved msgh_voucher_port |
545 | #define MACH_MSG_NULL (mach_msg_header_t *) 0 | |
1c79356b | 546 | |
0a7de745 A |
547 | typedef struct{ |
548 | mach_msg_header_t header; | |
549 | mach_msg_body_t body; | |
1c79356b A |
550 | } mach_msg_base_t; |
551 | ||
0a7de745 | 552 | typedef unsigned int mach_msg_trailer_type_t; |
1c79356b | 553 | |
0a7de745 | 554 | #define MACH_MSG_TRAILER_FORMAT_0 0 |
1c79356b | 555 | |
0a7de745 | 556 | typedef unsigned int mach_msg_trailer_size_t; |
39236c6e | 557 | typedef char *mach_msg_trailer_info_t; |
1c79356b | 558 | |
0a7de745 A |
559 | typedef struct{ |
560 | mach_msg_trailer_type_t msgh_trailer_type; | |
561 | mach_msg_trailer_size_t msgh_trailer_size; | |
1c79356b A |
562 | } mach_msg_trailer_t; |
563 | ||
fe8ab488 A |
564 | /* |
565 | * The msgh_seqno field carries a sequence number | |
566 | * associated with the received-from port. A port's | |
567 | * sequence number is incremented every time a message | |
568 | * is received from it and included in the received | |
569 | * trailer to help put messages back in sequence if | |
570 | * multiple threads receive and/or process received | |
571 | * messages. | |
572 | */ | |
0a7de745 A |
573 | typedef struct{ |
574 | mach_msg_trailer_type_t msgh_trailer_type; | |
575 | mach_msg_trailer_size_t msgh_trailer_size; | |
576 | mach_port_seqno_t msgh_seqno; | |
1c79356b A |
577 | } mach_msg_seqno_trailer_t; |
578 | ||
0a7de745 A |
579 | typedef struct{ |
580 | unsigned int val[2]; | |
1c79356b A |
581 | } security_token_t; |
582 | ||
0a7de745 A |
583 | typedef struct{ |
584 | mach_msg_trailer_type_t msgh_trailer_type; | |
585 | mach_msg_trailer_size_t msgh_trailer_size; | |
586 | mach_port_seqno_t msgh_seqno; | |
587 | security_token_t msgh_sender; | |
1c79356b A |
588 | } mach_msg_security_trailer_t; |
589 | ||
e5568f75 A |
590 | /* |
591 | * The audit token is an opaque token which identifies | |
592 | * Mach tasks and senders of Mach messages as subjects | |
593 | * to the BSM audit system. Only the appropriate BSM | |
594 | * library routines should be used to interpret the | |
595 | * contents of the audit token as the representation | |
596 | * of the subject identity within the token may change | |
597 | * over time. | |
598 | */ | |
0a7de745 A |
599 | typedef struct{ |
600 | unsigned int val[8]; | |
55e303ae A |
601 | } audit_token_t; |
602 | ||
0a7de745 A |
603 | typedef struct{ |
604 | mach_msg_trailer_type_t msgh_trailer_type; | |
605 | mach_msg_trailer_size_t msgh_trailer_size; | |
606 | mach_port_seqno_t msgh_seqno; | |
607 | security_token_t msgh_sender; | |
608 | audit_token_t msgh_audit; | |
55e303ae | 609 | } mach_msg_audit_trailer_t; |
1c79356b | 610 | |
0a7de745 A |
611 | typedef struct{ |
612 | mach_msg_trailer_type_t msgh_trailer_type; | |
613 | mach_msg_trailer_size_t msgh_trailer_size; | |
614 | mach_port_seqno_t msgh_seqno; | |
615 | security_token_t msgh_sender; | |
616 | audit_token_t msgh_audit; | |
617 | mach_port_context_t msgh_context; | |
b0d623f7 A |
618 | } mach_msg_context_trailer_t; |
619 | ||
5ba3f43e | 620 | #if defined(MACH_KERNEL_PRIVATE) && defined(__arm64__) |
0a7de745 A |
621 | typedef struct{ |
622 | mach_msg_trailer_type_t msgh_trailer_type; | |
623 | mach_msg_trailer_size_t msgh_trailer_size; | |
624 | mach_port_seqno_t msgh_seqno; | |
625 | security_token_t msgh_sender; | |
626 | audit_token_t msgh_audit; | |
627 | mach_port_context32_t msgh_context; | |
5ba3f43e A |
628 | } mach_msg_context_trailer32_t; |
629 | ||
0a7de745 A |
630 | typedef struct{ |
631 | mach_msg_trailer_type_t msgh_trailer_type; | |
632 | mach_msg_trailer_size_t msgh_trailer_size; | |
633 | mach_port_seqno_t msgh_seqno; | |
634 | security_token_t msgh_sender; | |
635 | audit_token_t msgh_audit; | |
636 | mach_port_context64_t msgh_context; | |
5ba3f43e A |
637 | } mach_msg_context_trailer64_t; |
638 | #endif | |
fe8ab488 A |
639 | |
640 | ||
0a7de745 A |
641 | typedef struct{ |
642 | mach_port_name_t sender; | |
2d21ac55 A |
643 | } msg_labels_t; |
644 | ||
f427ee49 A |
645 | typedef int mach_msg_filter_id; |
646 | #define MACH_MSG_FILTER_POLICY_ALLOW (mach_msg_filter_id)0 | |
647 | ||
0a7de745 A |
648 | /* |
649 | * Trailer type to pass MAC policy label info as a mach message trailer. | |
650 | * | |
651 | */ | |
652 | ||
653 | typedef struct{ | |
654 | mach_msg_trailer_type_t msgh_trailer_type; | |
655 | mach_msg_trailer_size_t msgh_trailer_size; | |
656 | mach_port_seqno_t msgh_seqno; | |
657 | security_token_t msgh_sender; | |
658 | audit_token_t msgh_audit; | |
659 | mach_port_context_t msgh_context; | |
f427ee49 | 660 | mach_msg_filter_id msgh_ad; |
0a7de745 | 661 | msg_labels_t msgh_labels; |
2d21ac55 A |
662 | } mach_msg_mac_trailer_t; |
663 | ||
5ba3f43e | 664 | #if defined(MACH_KERNEL_PRIVATE) && defined(__arm64__) |
0a7de745 A |
665 | typedef struct{ |
666 | mach_msg_trailer_type_t msgh_trailer_type; | |
667 | mach_msg_trailer_size_t msgh_trailer_size; | |
668 | mach_port_seqno_t msgh_seqno; | |
669 | security_token_t msgh_sender; | |
670 | audit_token_t msgh_audit; | |
671 | mach_port_context32_t msgh_context; | |
f427ee49 | 672 | mach_msg_filter_id msgh_ad; |
0a7de745 | 673 | msg_labels_t msgh_labels; |
5ba3f43e A |
674 | } mach_msg_mac_trailer32_t; |
675 | ||
0a7de745 A |
676 | typedef struct{ |
677 | mach_msg_trailer_type_t msgh_trailer_type; | |
678 | mach_msg_trailer_size_t msgh_trailer_size; | |
679 | mach_port_seqno_t msgh_seqno; | |
680 | security_token_t msgh_sender; | |
681 | audit_token_t msgh_audit; | |
682 | mach_port_context64_t msgh_context; | |
f427ee49 | 683 | mach_msg_filter_id msgh_ad; |
0a7de745 | 684 | msg_labels_t msgh_labels; |
5ba3f43e A |
685 | } mach_msg_mac_trailer64_t; |
686 | ||
687 | #endif | |
fe8ab488 | 688 | |
1c79356b | 689 | #define MACH_MSG_TRAILER_MINIMUM_SIZE sizeof(mach_msg_trailer_t) |
55e303ae A |
690 | |
691 | /* | |
692 | * These values can change from release to release - but clearly | |
693 | * code cannot request additional trailer elements one was not | |
694 | * compiled to understand. Therefore, it is safe to use this | |
695 | * constant when the same module specified the receive options. | |
696 | * Otherwise, you run the risk that the options requested by | |
697 | * another module may exceed the local modules notion of | |
698 | * MAX_TRAILER_SIZE. | |
699 | */ | |
5ba3f43e A |
700 | #if defined(MACH_KERNEL_PRIVATE) && defined(__arm64__) |
701 | typedef mach_msg_mac_trailer64_t mach_msg_max_trailer64_t; | |
702 | typedef mach_msg_mac_trailer32_t mach_msg_max_trailer32_t; | |
703 | #endif | |
39236c6e | 704 | |
2d21ac55 | 705 | typedef mach_msg_mac_trailer_t mach_msg_max_trailer_t; |
b0d623f7 | 706 | #define MAX_TRAILER_SIZE ((mach_msg_size_t)sizeof(mach_msg_max_trailer_t)) |
55e303ae A |
707 | |
708 | /* | |
709 | * Legacy requirements keep us from ever updating these defines (even | |
710 | * when the format_0 trailers gain new option data fields in the future). | |
711 | * Therefore, they shouldn't be used going forward. Instead, the sizes | |
712 | * should be compared against the specific element size requested using | |
713 | * REQUESTED_TRAILER_SIZE. | |
714 | */ | |
715 | typedef mach_msg_security_trailer_t mach_msg_format_0_trailer_t; | |
2d21ac55 A |
716 | |
717 | /*typedef mach_msg_mac_trailer_t mach_msg_format_0_trailer_t; | |
0a7de745 | 718 | */ |
2d21ac55 | 719 | |
55e303ae | 720 | #define MACH_MSG_TRAILER_FORMAT_0_SIZE sizeof(mach_msg_format_0_trailer_t) |
1c79356b A |
721 | |
722 | #define KERNEL_SECURITY_TOKEN_VALUE { {0, 1} } | |
cb323159 | 723 | extern const security_token_t KERNEL_SECURITY_TOKEN; |
1c79356b | 724 | |
55e303ae | 725 | #define KERNEL_AUDIT_TOKEN_VALUE { {0, 0, 0, 0, 0, 0, 0, 0} } |
cb323159 | 726 | extern const audit_token_t KERNEL_AUDIT_TOKEN; |
55e303ae | 727 | |
0a7de745 | 728 | typedef integer_t mach_msg_options_t; |
1c79356b | 729 | |
0a7de745 A |
730 | typedef struct{ |
731 | mach_msg_header_t header; | |
1c79356b A |
732 | } mach_msg_empty_send_t; |
733 | ||
0a7de745 A |
734 | typedef struct{ |
735 | mach_msg_header_t header; | |
736 | mach_msg_trailer_t trailer; | |
1c79356b A |
737 | } mach_msg_empty_rcv_t; |
738 | ||
0a7de745 A |
739 | typedef union{ |
740 | mach_msg_empty_send_t send; | |
741 | mach_msg_empty_rcv_t rcv; | |
1c79356b A |
742 | } mach_msg_empty_t; |
743 | ||
cb323159 | 744 | #pragma pack(pop) |
91447636 | 745 | |
1c79356b | 746 | /* utility to round the message size - will become machine dependent */ |
0a7de745 A |
747 | #define round_msg(x) (((mach_msg_size_t)(x) + sizeof (natural_t) - 1) & \ |
748 | ~(sizeof (natural_t) - 1)) | |
1c79356b | 749 | |
eb6b6ca3 A |
750 | #ifdef XNU_KERNEL_PRIVATE |
751 | ||
752 | #include <os/base.h> | |
753 | #include <os/overflow.h> | |
754 | #include <kern/debug.h> | |
755 | ||
756 | #define round_msg_overflow(in, out) __os_warn_unused(({ \ | |
757 | bool __ovr = os_add_overflow(in, (__typeof__(*out))(sizeof(natural_t) - 1), out); \ | |
758 | *out &= ~((__typeof__(*out))(sizeof(natural_t) - 1)); \ | |
759 | __ovr; \ | |
760 | })) | |
761 | ||
762 | static inline mach_msg_size_t | |
763 | mach_round_msg(mach_msg_size_t x) | |
764 | { | |
765 | if (round_msg_overflow(x, &x)) { | |
766 | panic("round msg overflow"); | |
767 | } | |
768 | return x; | |
769 | } | |
770 | #endif /* XNU_KERNEL_PRIVATE */ | |
771 | ||
1c79356b A |
772 | /* |
773 | * There is no fixed upper bound to the size of Mach messages. | |
774 | */ | |
0a7de745 | 775 | #define MACH_MSG_SIZE_MAX ((mach_msg_size_t) ~0) |
1c79356b | 776 | |
316670eb A |
777 | #if defined(__APPLE_API_PRIVATE) |
778 | /* | |
779 | * But architectural limits of a given implementation, or | |
780 | * temporal conditions may cause unpredictable send failures | |
781 | * for messages larger than MACH_MSG_SIZE_RELIABLE. | |
782 | * | |
783 | * In either case, waiting for memory is [currently] outside | |
784 | * the scope of send timeout values provided to IPC. | |
785 | */ | |
0a7de745 | 786 | #define MACH_MSG_SIZE_RELIABLE ((mach_msg_size_t) 256 * 1024) |
316670eb | 787 | #endif |
1c79356b A |
788 | /* |
789 | * Compatibility definitions, for code written | |
790 | * when there was a msgh_kind instead of msgh_seqno. | |
791 | */ | |
0a7de745 A |
792 | #define MACH_MSGH_KIND_NORMAL 0x00000000 |
793 | #define MACH_MSGH_KIND_NOTIFICATION 0x00000001 | |
794 | #define msgh_kind msgh_seqno | |
795 | #define mach_msg_kind_t mach_port_seqno_t | |
1c79356b | 796 | |
1c79356b A |
797 | typedef natural_t mach_msg_type_size_t; |
798 | typedef natural_t mach_msg_type_number_t; | |
799 | ||
800 | /* | |
801 | * Values received/carried in messages. Tells the receiver what | |
802 | * sort of port right he now has. | |
803 | * | |
804 | * MACH_MSG_TYPE_PORT_NAME is used to transfer a port name | |
805 | * which should remain uninterpreted by the kernel. (Port rights | |
806 | * are not transferred, just the port name.) | |
807 | */ | |
808 | ||
0a7de745 | 809 | #define MACH_MSG_TYPE_PORT_NONE 0 |
1c79356b | 810 | |
0a7de745 A |
811 | #define MACH_MSG_TYPE_PORT_NAME 15 |
812 | #define MACH_MSG_TYPE_PORT_RECEIVE MACH_MSG_TYPE_MOVE_RECEIVE | |
813 | #define MACH_MSG_TYPE_PORT_SEND MACH_MSG_TYPE_MOVE_SEND | |
814 | #define MACH_MSG_TYPE_PORT_SEND_ONCE MACH_MSG_TYPE_MOVE_SEND_ONCE | |
1c79356b | 815 | |
0a7de745 | 816 | #define MACH_MSG_TYPE_LAST 22 /* Last assigned */ |
1c79356b A |
817 | |
818 | /* | |
819 | * A dummy value. Mostly used to indicate that the actual value | |
820 | * will be filled in later, dynamically. | |
821 | */ | |
822 | ||
0a7de745 | 823 | #define MACH_MSG_TYPE_POLYMORPHIC ((mach_msg_type_name_t) -1) |
1c79356b A |
824 | |
825 | /* | |
826 | * Is a given item a port type? | |
827 | */ | |
828 | ||
0a7de745 A |
829 | #define MACH_MSG_TYPE_PORT_ANY(x) \ |
830 | (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \ | |
1c79356b A |
831 | ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE)) |
832 | ||
0a7de745 A |
833 | #define MACH_MSG_TYPE_PORT_ANY_SEND(x) \ |
834 | (((x) >= MACH_MSG_TYPE_MOVE_SEND) && \ | |
1c79356b A |
835 | ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE)) |
836 | ||
0a7de745 A |
837 | #define MACH_MSG_TYPE_PORT_ANY_RIGHT(x) \ |
838 | (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \ | |
1c79356b A |
839 | ((x) <= MACH_MSG_TYPE_MOVE_SEND_ONCE)) |
840 | ||
841 | typedef integer_t mach_msg_option_t; | |
842 | ||
0a7de745 | 843 | #define MACH_MSG_OPTION_NONE 0x00000000 |
1c79356b | 844 | |
0a7de745 A |
845 | #define MACH_SEND_MSG 0x00000001 |
846 | #define MACH_RCV_MSG 0x00000002 | |
1c79356b | 847 | |
0a7de745 A |
848 | #define MACH_RCV_LARGE 0x00000004 /* report large message sizes */ |
849 | #define MACH_RCV_LARGE_IDENTITY 0x00000008 /* identify source of large messages */ | |
39236c6e | 850 | |
0a7de745 | 851 | #define MACH_SEND_TIMEOUT 0x00000010 /* timeout value applies to send */ |
cb323159 | 852 | #define MACH_SEND_OVERRIDE 0x00000020 /* priority override for send */ |
0a7de745 A |
853 | #define MACH_SEND_INTERRUPT 0x00000040 /* don't restart interrupted sends */ |
854 | #define MACH_SEND_NOTIFY 0x00000080 /* arm send-possible notify */ | |
855 | #define MACH_SEND_ALWAYS 0x00010000 /* ignore qlimits - kernel only */ | |
856 | #define MACH_SEND_TRAILER 0x00020000 /* sender-provided trailer */ | |
39236c6e | 857 | #define MACH_SEND_NOIMPORTANCE 0x00040000 /* msg won't carry importance */ |
0a7de745 A |
858 | #define MACH_SEND_NODENAP MACH_SEND_NOIMPORTANCE |
859 | #define MACH_SEND_IMPORTANCE 0x00080000 /* msg carries importance - kernel only */ | |
860 | #define MACH_SEND_SYNC_OVERRIDE 0x00100000 /* msg should do sync ipc override */ | |
cb323159 | 861 | #define MACH_SEND_PROPAGATE_QOS 0x00200000 /* IPC should propagate the caller's QoS */ |
0a7de745 | 862 | #define MACH_SEND_SYNC_USE_THRPRI MACH_SEND_PROPAGATE_QOS /* obsolete name */ |
cb323159 A |
863 | #define MACH_SEND_KERNEL 0x00400000 /* full send from kernel space - kernel only */ |
864 | #define MACH_SEND_SYNC_BOOTSTRAP_CHECKIN 0x00800000 /* special reply port should boost thread doing sync bootstrap checkin */ | |
39236c6e | 865 | |
0a7de745 | 866 | #define MACH_RCV_TIMEOUT 0x00000100 /* timeout value applies to receive */ |
cb323159 | 867 | #define MACH_RCV_NOTIFY 0x00000000 /* legacy name (value was: 0x00000200) */ |
0a7de745 A |
868 | #define MACH_RCV_INTERRUPT 0x00000400 /* don't restart interrupted receive */ |
869 | #define MACH_RCV_VOUCHER 0x00000800 /* willing to receive voucher port */ | |
cb323159 A |
870 | #define MACH_RCV_OVERWRITE 0x00000000 /* scatter receive (deprecated) */ |
871 | #define MACH_RCV_GUARDED_DESC 0x00001000 /* Can receive new guarded descriptor */ | |
0a7de745 | 872 | #define MACH_RCV_SYNC_WAIT 0x00004000 /* sync waiter waiting for rcv */ |
cb323159 A |
873 | #define MACH_RCV_SYNC_PEEK 0x00008000 /* sync waiter waiting to peek */ |
874 | ||
875 | #define MACH_MSG_STRICT_REPLY 0x00000200 /* Enforce specific properties about the reply port, and | |
876 | * the context in which a thread replies to a message. | |
877 | * This flag must be passed on both the SEND and RCV */ | |
1c79356b | 878 | |
39037602 A |
879 | #ifdef XNU_KERNEL_PRIVATE |
880 | ||
0a7de745 | 881 | #define MACH_RCV_STACK 0x00002000 /* receive into highest addr of buffer */ |
39037602 A |
882 | |
883 | /* | |
884 | * NOTE: | |
885 | * This internal-only flag is intended for use by a single thread per-port/set! | |
886 | * If more than one thread attempts to MACH_PEEK_MSG on a port or set, one of | |
887 | * the threads may miss messages (in fact, it may never wake up). | |
888 | */ | |
0a7de745 | 889 | #define MACH_PEEK_MSG 0x80000000 /* receive, but leave msgs queued */ |
39037602 A |
890 | |
891 | #endif | |
892 | ||
0a7de745 | 893 | /* |
1c79356b | 894 | * NOTE: a 0x00------ RCV mask implies to ask for |
0a7de745 | 895 | * a MACH_MSG_TRAILER_FORMAT_0 with 0 Elements, |
1c79356b | 896 | * which is equivalent to a mach_msg_trailer_t. |
2d21ac55 A |
897 | * |
898 | * XXXMAC: unlike the rest of the MACH_RCV_* flags, MACH_RCV_TRAILER_LABELS | |
0a7de745 | 899 | * needs its own private bit since we only calculate its fields when absolutely |
b0d623f7 | 900 | * required. |
1c79356b A |
901 | */ |
902 | #define MACH_RCV_TRAILER_NULL 0 | |
903 | #define MACH_RCV_TRAILER_SEQNO 1 | |
904 | #define MACH_RCV_TRAILER_SENDER 2 | |
55e303ae | 905 | #define MACH_RCV_TRAILER_AUDIT 3 |
b0d623f7 A |
906 | #define MACH_RCV_TRAILER_CTX 4 |
907 | #define MACH_RCV_TRAILER_AV 7 | |
908 | #define MACH_RCV_TRAILER_LABELS 8 | |
1c79356b | 909 | |
0a7de745 A |
910 | #define MACH_RCV_TRAILER_TYPE(x) (((x) & 0xf) << 28) |
911 | #define MACH_RCV_TRAILER_ELEMENTS(x) (((x) & 0xf) << 24) | |
912 | #define MACH_RCV_TRAILER_MASK ((0xf << 24)) | |
1c79356b | 913 | |
1c79356b | 914 | #define GET_RCV_ELEMENTS(y) (((y) >> 24) & 0xf) |
2d21ac55 | 915 | |
39236c6e A |
916 | #ifdef MACH_KERNEL_PRIVATE |
917 | /* The options that the kernel honors when passed from user space */ | |
39037602 | 918 | #define MACH_SEND_USER (MACH_SEND_MSG | MACH_SEND_TIMEOUT | \ |
0a7de745 A |
919 | MACH_SEND_NOTIFY | MACH_SEND_OVERRIDE | \ |
920 | MACH_SEND_TRAILER | MACH_SEND_NOIMPORTANCE | \ | |
cb323159 A |
921 | MACH_SEND_SYNC_OVERRIDE | MACH_SEND_PROPAGATE_QOS | \ |
922 | MACH_SEND_SYNC_BOOTSTRAP_CHECKIN | \ | |
923 | MACH_MSG_STRICT_REPLY | MACH_RCV_GUARDED_DESC) | |
39236c6e | 924 | |
39037602 | 925 | #define MACH_RCV_USER (MACH_RCV_MSG | MACH_RCV_TIMEOUT | \ |
0a7de745 A |
926 | MACH_RCV_LARGE | MACH_RCV_LARGE_IDENTITY | \ |
927 | MACH_RCV_VOUCHER | MACH_RCV_TRAILER_MASK | \ | |
cb323159 A |
928 | MACH_RCV_SYNC_WAIT | MACH_RCV_SYNC_PEEK | \ |
929 | MACH_RCV_GUARDED_DESC | MACH_MSG_STRICT_REPLY) | |
39236c6e | 930 | |
0a7de745 | 931 | #define MACH_MSG_OPTION_USER (MACH_SEND_USER | MACH_RCV_USER) |
39236c6e A |
932 | |
933 | /* The options implemented by the library interface to mach_msg et. al. */ | |
0a7de745 | 934 | #define MACH_MSG_OPTION_LIB (MACH_SEND_INTERRUPT | MACH_RCV_INTERRUPT) |
39236c6e | 935 | |
490019cf A |
936 | /* |
937 | * Default options to use when sending from the kernel. | |
938 | * | |
939 | * Until we are sure of its effects, we are disabling | |
940 | * importance donation from the kernel-side of user | |
941 | * threads in importance-donating tasks. | |
942 | * (11938665 & 23925818) | |
943 | */ | |
39236c6e | 944 | #define MACH_SEND_KERNEL_DEFAULT (MACH_SEND_MSG | \ |
0a7de745 | 945 | MACH_SEND_ALWAYS | MACH_SEND_NOIMPORTANCE) |
39236c6e | 946 | |
cb323159 A |
947 | #define MACH_SEND_WITH_STRICT_REPLY(_opts) (((_opts) & (MACH_MSG_STRICT_REPLY | MACH_SEND_MSG)) == \ |
948 | (MACH_MSG_STRICT_REPLY | MACH_SEND_MSG)) | |
949 | ||
950 | #define MACH_SEND_REPLY_IS_IMMOVABLE(_opts) (((_opts) & (MACH_MSG_STRICT_REPLY | \ | |
951 | MACH_SEND_MSG | MACH_RCV_MSG | \ | |
952 | MACH_RCV_GUARDED_DESC)) == \ | |
953 | (MACH_MSG_STRICT_REPLY | MACH_SEND_MSG | MACH_RCV_GUARDED_DESC)) | |
954 | ||
955 | #define MACH_RCV_WITH_STRICT_REPLY(_opts) (((_opts) & (MACH_MSG_STRICT_REPLY | MACH_RCV_MSG)) == \ | |
956 | (MACH_MSG_STRICT_REPLY | MACH_RCV_MSG)) | |
957 | ||
958 | #define MACH_RCV_WITH_IMMOVABLE_REPLY(_opts) (((_opts) & (MACH_MSG_STRICT_REPLY | \ | |
959 | MACH_RCV_MSG | MACH_RCV_GUARDED_DESC)) == \ | |
960 | (MACH_MSG_STRICT_REPLY | MACH_RCV_MSG | MACH_RCV_GUARDED_DESC)) | |
961 | ||
39236c6e A |
962 | #endif /* MACH_KERNEL_PRIVATE */ |
963 | ||
0a7de745 A |
964 | /* |
965 | * XXXMAC: note that in the case of MACH_RCV_TRAILER_LABELS, | |
b0d623f7 | 966 | * we just fall through to mach_msg_max_trailer_t. |
2d21ac55 | 967 | * This is correct behavior since mach_msg_max_trailer_t is defined as |
b0d623f7 | 968 | * mac_msg_mac_trailer_t which is used for the LABELS trailer. |
0a7de745 | 969 | * It also makes things work properly if MACH_RCV_TRAILER_LABELS is ORed |
b0d623f7 | 970 | * with one of the other options. |
2d21ac55 | 971 | */ |
316670eb | 972 | |
0a7de745 A |
973 | #define REQUESTED_TRAILER_SIZE_NATIVE(y) \ |
974 | ((mach_msg_trailer_size_t) \ | |
975 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_NULL) ? \ | |
976 | sizeof(mach_msg_trailer_t) : \ | |
977 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SEQNO) ? \ | |
978 | sizeof(mach_msg_seqno_trailer_t) : \ | |
979 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SENDER) ? \ | |
980 | sizeof(mach_msg_security_trailer_t) : \ | |
981 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AUDIT) ? \ | |
982 | sizeof(mach_msg_audit_trailer_t) : \ | |
983 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_CTX) ? \ | |
984 | sizeof(mach_msg_context_trailer_t) : \ | |
985 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AV) ? \ | |
986 | sizeof(mach_msg_mac_trailer_t) : \ | |
b0d623f7 | 987 | sizeof(mach_msg_max_trailer_t)))))))) |
2d21ac55 | 988 | |
316670eb A |
989 | |
990 | #ifdef XNU_KERNEL_PRIVATE | |
991 | ||
5ba3f43e | 992 | #if defined(__arm64__) |
0a7de745 A |
993 | #define REQUESTED_TRAILER_SIZE(is64, y) \ |
994 | ((mach_msg_trailer_size_t) \ | |
995 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_NULL) ? \ | |
996 | sizeof(mach_msg_trailer_t) : \ | |
997 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SEQNO) ? \ | |
998 | sizeof(mach_msg_seqno_trailer_t) : \ | |
999 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SENDER) ? \ | |
1000 | sizeof(mach_msg_security_trailer_t) : \ | |
1001 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AUDIT) ? \ | |
1002 | sizeof(mach_msg_audit_trailer_t) : \ | |
1003 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_CTX) ? \ | |
5ba3f43e | 1004 | ((is64) ? sizeof(mach_msg_context_trailer64_t) : sizeof(mach_msg_context_trailer32_t)) : \ |
0a7de745 | 1005 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_AV) ? \ |
5ba3f43e A |
1006 | ((is64) ? sizeof(mach_msg_mac_trailer64_t) : sizeof(mach_msg_mac_trailer32_t)) : \ |
1007 | sizeof(mach_msg_max_trailer_t)))))))) | |
1008 | #else | |
316670eb | 1009 | #define REQUESTED_TRAILER_SIZE(is64, y) REQUESTED_TRAILER_SIZE_NATIVE(y) |
5ba3f43e | 1010 | #endif |
316670eb A |
1011 | |
1012 | #else /* XNU_KERNEL_PRIVATE */ | |
1013 | #define REQUESTED_TRAILER_SIZE(y) REQUESTED_TRAILER_SIZE_NATIVE(y) | |
1014 | #endif /* XNU_KERNEL_PRIVATE */ | |
1015 | ||
1c79356b A |
1016 | /* |
1017 | * Much code assumes that mach_msg_return_t == kern_return_t. | |
1018 | * This definition is useful for descriptive purposes. | |
1019 | * | |
1020 | * See <mach/error.h> for the format of error codes. | |
1021 | * IPC errors are system 4. Send errors are subsystem 0; | |
1022 | * receive errors are subsystem 1. The code field is always non-zero. | |
1023 | * The high bits of the code field communicate extra information | |
1024 | * for some error codes. MACH_MSG_MASK masks off these special bits. | |
1025 | */ | |
1026 | ||
1027 | typedef kern_return_t mach_msg_return_t; | |
1028 | ||
0a7de745 A |
1029 | #define MACH_MSG_SUCCESS 0x00000000 |
1030 | ||
1031 | ||
1032 | #define MACH_MSG_MASK 0x00003e00 | |
1033 | /* All special error code bits defined below. */ | |
1034 | #define MACH_MSG_IPC_SPACE 0x00002000 | |
1035 | /* No room in IPC name space for another capability name. */ | |
1036 | #define MACH_MSG_VM_SPACE 0x00001000 | |
1037 | /* No room in VM address space for out-of-line memory. */ | |
1038 | #define MACH_MSG_IPC_KERNEL 0x00000800 | |
1039 | /* Kernel resource shortage handling an IPC capability. */ | |
1040 | #define MACH_MSG_VM_KERNEL 0x00000400 | |
1041 | /* Kernel resource shortage handling out-of-line memory. */ | |
1042 | ||
1043 | #define MACH_SEND_IN_PROGRESS 0x10000001 | |
1044 | /* Thread is waiting to send. (Internal use only.) */ | |
1045 | #define MACH_SEND_INVALID_DATA 0x10000002 | |
1046 | /* Bogus in-line data. */ | |
1047 | #define MACH_SEND_INVALID_DEST 0x10000003 | |
1048 | /* Bogus destination port. */ | |
1049 | #define MACH_SEND_TIMED_OUT 0x10000004 | |
1050 | /* Message not sent before timeout expired. */ | |
1051 | #define MACH_SEND_INVALID_VOUCHER 0x10000005 | |
1052 | /* Bogus voucher port. */ | |
1053 | #define MACH_SEND_INTERRUPTED 0x10000007 | |
1054 | /* Software interrupt. */ | |
1055 | #define MACH_SEND_MSG_TOO_SMALL 0x10000008 | |
1056 | /* Data doesn't contain a complete message. */ | |
1057 | #define MACH_SEND_INVALID_REPLY 0x10000009 | |
1058 | /* Bogus reply port. */ | |
1059 | #define MACH_SEND_INVALID_RIGHT 0x1000000a | |
1060 | /* Bogus port rights in the message body. */ | |
1061 | #define MACH_SEND_INVALID_NOTIFY 0x1000000b | |
1062 | /* Bogus notify port argument. */ | |
1063 | #define MACH_SEND_INVALID_MEMORY 0x1000000c | |
1064 | /* Invalid out-of-line memory pointer. */ | |
1065 | #define MACH_SEND_NO_BUFFER 0x1000000d | |
1066 | /* No message buffer is available. */ | |
1067 | #define MACH_SEND_TOO_LARGE 0x1000000e | |
1068 | /* Send is too large for port */ | |
1069 | #define MACH_SEND_INVALID_TYPE 0x1000000f | |
1070 | /* Invalid msg-type specification. */ | |
1071 | #define MACH_SEND_INVALID_HEADER 0x10000010 | |
1072 | /* A field in the header had a bad value. */ | |
1073 | #define MACH_SEND_INVALID_TRAILER 0x10000011 | |
1074 | /* The trailer to be sent does not match kernel format. */ | |
cb323159 A |
1075 | #define MACH_SEND_INVALID_CONTEXT 0x10000012 |
1076 | /* The sending thread context did not match the context on the dest port */ | |
0a7de745 A |
1077 | #define MACH_SEND_INVALID_RT_OOL_SIZE 0x10000015 |
1078 | /* compatibility: no longer a returned error */ | |
cb323159 A |
1079 | #define MACH_SEND_NO_GRANT_DEST 0x10000016 |
1080 | /* The destination port doesn't accept ports in body */ | |
f427ee49 A |
1081 | #define MACH_SEND_MSG_FILTERED 0x10000017 |
1082 | /* Message send was rejected by message filter */ | |
0a7de745 A |
1083 | |
1084 | #define MACH_RCV_IN_PROGRESS 0x10004001 | |
1085 | /* Thread is waiting for receive. (Internal use only.) */ | |
1086 | #define MACH_RCV_INVALID_NAME 0x10004002 | |
1087 | /* Bogus name for receive port/port-set. */ | |
1088 | #define MACH_RCV_TIMED_OUT 0x10004003 | |
1089 | /* Didn't get a message within the timeout value. */ | |
1090 | #define MACH_RCV_TOO_LARGE 0x10004004 | |
1091 | /* Message buffer is not large enough for inline data. */ | |
1092 | #define MACH_RCV_INTERRUPTED 0x10004005 | |
1093 | /* Software interrupt. */ | |
1094 | #define MACH_RCV_PORT_CHANGED 0x10004006 | |
1095 | /* compatibility: no longer a returned error */ | |
1096 | #define MACH_RCV_INVALID_NOTIFY 0x10004007 | |
1097 | /* Bogus notify port argument. */ | |
1098 | #define MACH_RCV_INVALID_DATA 0x10004008 | |
1099 | /* Bogus message buffer for inline data. */ | |
1100 | #define MACH_RCV_PORT_DIED 0x10004009 | |
1101 | /* Port/set was sent away/died during receive. */ | |
1102 | #define MACH_RCV_IN_SET 0x1000400a | |
1103 | /* compatibility: no longer a returned error */ | |
1104 | #define MACH_RCV_HEADER_ERROR 0x1000400b | |
1105 | /* Error receiving message header. See special bits. */ | |
1106 | #define MACH_RCV_BODY_ERROR 0x1000400c | |
1107 | /* Error receiving message body. See special bits. */ | |
1108 | #define MACH_RCV_INVALID_TYPE 0x1000400d | |
1109 | /* Invalid msg-type specification in scatter list. */ | |
1110 | #define MACH_RCV_SCATTER_SMALL 0x1000400e | |
1111 | /* Out-of-line overwrite region is not large enough */ | |
1112 | #define MACH_RCV_INVALID_TRAILER 0x1000400f | |
1113 | /* trailer type or number of trailer elements not supported */ | |
1c79356b | 1114 | #define MACH_RCV_IN_PROGRESS_TIMED 0x10004011 |
0a7de745 | 1115 | /* Waiting for receive with timeout. (Internal use only.) */ |
cb323159 A |
1116 | #define MACH_RCV_INVALID_REPLY 0x10004012 |
1117 | /* invalid reply port used in a STRICT_REPLY message */ | |
1c79356b | 1118 | |
39037602 | 1119 | #ifdef XNU_KERNEL_PRIVATE |
0a7de745 A |
1120 | #define MACH_PEEK_IN_PROGRESS 0x10008001 |
1121 | /* Waiting for a peek. (Internal use only.) */ | |
1122 | #define MACH_PEEK_READY 0x10008002 | |
1123 | /* Waiting for a peek. (Internal use only.) */ | |
39037602 A |
1124 | #endif |
1125 | ||
91447636 A |
1126 | |
1127 | __BEGIN_DECLS | |
1128 | ||
9bccf70c A |
1129 | /* |
1130 | * Routine: mach_msg_overwrite | |
1131 | * Purpose: | |
1132 | * Send and/or receive a message. If the message operation | |
1133 | * is interrupted, and the user did not request an indication | |
1134 | * of that fact, then restart the appropriate parts of the | |
1135 | * operation silently (trap version does not restart). | |
1136 | * | |
1137 | * Distinct send and receive buffers may be specified. If | |
1138 | * no separate receive buffer is specified, the msg parameter | |
1139 | * will be used for both send and receive operations. | |
1140 | * | |
1141 | * In addition to a distinct receive buffer, that buffer may | |
1142 | * already contain scatter control information to direct the | |
1143 | * receiving of the message. | |
1144 | */ | |
3e170ce0 | 1145 | __WATCHOS_PROHIBITED __TVOS_PROHIBITED |
0a7de745 A |
1146 | extern mach_msg_return_t mach_msg_overwrite( |
1147 | mach_msg_header_t *msg, | |
1148 | mach_msg_option_t option, | |
1149 | mach_msg_size_t send_size, | |
1150 | mach_msg_size_t rcv_size, | |
1151 | mach_port_name_t rcv_name, | |
1152 | mach_msg_timeout_t timeout, | |
1153 | mach_port_name_t notify, | |
1154 | mach_msg_header_t *rcv_msg, | |
1155 | mach_msg_size_t rcv_limit); | |
1156 | ||
1157 | #ifndef KERNEL | |
91447636 | 1158 | |
9bccf70c A |
1159 | /* |
1160 | * Routine: mach_msg | |
1161 | * Purpose: | |
1162 | * Send and/or receive a message. If the message operation | |
1163 | * is interrupted, and the user did not request an indication | |
1164 | * of that fact, then restart the appropriate parts of the | |
1165 | * operation silently (trap version does not restart). | |
1166 | */ | |
3e170ce0 | 1167 | __WATCHOS_PROHIBITED __TVOS_PROHIBITED |
0a7de745 A |
1168 | extern mach_msg_return_t mach_msg( |
1169 | mach_msg_header_t *msg, | |
1170 | mach_msg_option_t option, | |
1171 | mach_msg_size_t send_size, | |
1172 | mach_msg_size_t rcv_size, | |
1173 | mach_port_name_t rcv_name, | |
1174 | mach_msg_timeout_t timeout, | |
1175 | mach_port_name_t notify); | |
1c79356b | 1176 | |
fe8ab488 A |
1177 | /* |
1178 | * Routine: mach_voucher_deallocate | |
1179 | * Purpose: | |
1180 | * Deallocate a mach voucher created or received in a message. Drops | |
1181 | * one (send right) reference to the voucher. | |
1182 | */ | |
3e170ce0 | 1183 | __WATCHOS_PROHIBITED __TVOS_PROHIBITED |
0a7de745 A |
1184 | extern kern_return_t mach_voucher_deallocate( |
1185 | mach_port_name_t voucher); | |
fe8ab488 | 1186 | |
b0d623f7 A |
1187 | #elif defined(MACH_KERNEL_PRIVATE) |
1188 | ||
0a7de745 | 1189 | extern mach_msg_return_t mach_msg_receive_results(mach_msg_size_t *size); |
b0d623f7 | 1190 | |
0a7de745 | 1191 | #endif /* KERNEL */ |
91447636 A |
1192 | |
1193 | __END_DECLS | |
1194 | ||
0a7de745 | 1195 | #endif /* _MACH_MESSAGE_H_ */ |