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