]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
1c79356b | 11 | * |
37839358 A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
25 | /* | |
26 | * Mach Operating System | |
27 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University | |
28 | * All Rights Reserved. | |
29 | * | |
30 | * Permission to use, copy, modify and distribute this software and its | |
31 | * documentation is hereby granted, provided that both the copyright | |
32 | * notice and this permission notice appear in all copies of the | |
33 | * software, derivative works or modified versions, and any portions | |
34 | * thereof, and that both notices appear in supporting documentation. | |
35 | * | |
36 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
37 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
38 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
39 | * | |
40 | * Carnegie Mellon requests users of this software to return to | |
41 | * | |
42 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
43 | * School of Computer Science | |
44 | * Carnegie Mellon University | |
45 | * Pittsburgh PA 15213-3890 | |
46 | * | |
47 | * any improvements or extensions that they make and grant Carnegie Mellon | |
48 | * the rights to redistribute these changes. | |
49 | */ | |
50 | /* | |
51 | */ | |
52 | /* | |
53 | * File: mach/message.h | |
54 | * | |
55 | * Mach IPC message and primitive function definitions. | |
56 | */ | |
57 | ||
58 | #ifndef _MACH_MESSAGE_H_ | |
59 | #define _MACH_MESSAGE_H_ | |
60 | ||
9bccf70c A |
61 | #include <stdint.h> |
62 | #include <mach/port.h> | |
63 | #include <mach/boolean.h> | |
64 | #include <mach/kern_return.h> | |
65 | #include <mach/machine/vm_types.h> | |
1c79356b | 66 | |
91447636 A |
67 | #include <sys/cdefs.h> |
68 | ||
1c79356b A |
69 | /* |
70 | * The timeout mechanism uses mach_msg_timeout_t values, | |
71 | * passed by value. The timeout units are milliseconds. | |
72 | * It is controlled with the MACH_SEND_TIMEOUT | |
73 | * and MACH_RCV_TIMEOUT options. | |
74 | */ | |
75 | ||
76 | typedef natural_t mach_msg_timeout_t; | |
77 | ||
78 | /* | |
79 | * The value to be used when there is no timeout. | |
80 | * (No MACH_SEND_TIMEOUT/MACH_RCV_TIMEOUT option.) | |
81 | */ | |
82 | ||
83 | #define MACH_MSG_TIMEOUT_NONE ((mach_msg_timeout_t) 0) | |
84 | ||
85 | /* | |
86 | * The kernel uses MACH_MSGH_BITS_COMPLEX as a hint. It it isn't on, it | |
87 | * assumes the body of the message doesn't contain port rights or OOL | |
88 | * data. The field is set in received messages. A user task must | |
89 | * use caution in interpreting the body of a message if the bit isn't | |
90 | * on, because the mach_msg_type's in the body might "lie" about the | |
91 | * contents. If the bit isn't on, but the mach_msg_types | |
92 | * in the body specify rights or OOL data, the behavior is undefined. | |
93 | * (Ie, an error may or may not be produced.) | |
94 | * | |
95 | * The value of MACH_MSGH_BITS_REMOTE determines the interpretation | |
96 | * of the msgh_remote_port field. It is handled like a msgt_name. | |
97 | * | |
98 | * The value of MACH_MSGH_BITS_LOCAL determines the interpretation | |
99 | * of the msgh_local_port field. It is handled like a msgt_name. | |
100 | * | |
101 | * MACH_MSGH_BITS() combines two MACH_MSG_TYPE_* values, for the remote | |
102 | * and local fields, into a single value suitable for msgh_bits. | |
103 | * | |
104 | * MACH_MSGH_BITS_CIRCULAR should be zero; is is used internally. | |
105 | * | |
106 | * The unused bits should be zero and are reserved for the kernel | |
107 | * or for future interface expansion. | |
108 | */ | |
109 | ||
110 | #define MACH_MSGH_BITS_ZERO 0x00000000 | |
111 | #define MACH_MSGH_BITS_REMOTE_MASK 0x000000ff | |
112 | #define MACH_MSGH_BITS_LOCAL_MASK 0x0000ff00 | |
113 | #define MACH_MSGH_BITS_COMPLEX 0x80000000U | |
114 | #define MACH_MSGH_BITS_USER 0x8000ffffU | |
115 | ||
116 | #define MACH_MSGH_BITS_CIRCULAR 0x40000000 /* internal use only */ | |
117 | #define MACH_MSGH_BITS_USED 0xc000ffffU | |
118 | ||
119 | #define MACH_MSGH_BITS_PORTS_MASK \ | |
120 | (MACH_MSGH_BITS_REMOTE_MASK|MACH_MSGH_BITS_LOCAL_MASK) | |
121 | ||
122 | #define MACH_MSGH_BITS(remote, local) \ | |
123 | ((remote) | ((local) << 8)) | |
124 | #define MACH_MSGH_BITS_REMOTE(bits) \ | |
125 | ((bits) & MACH_MSGH_BITS_REMOTE_MASK) | |
126 | #define MACH_MSGH_BITS_LOCAL(bits) \ | |
127 | (((bits) & MACH_MSGH_BITS_LOCAL_MASK) >> 8) | |
128 | #define MACH_MSGH_BITS_PORTS(bits) \ | |
129 | ((bits) & MACH_MSGH_BITS_PORTS_MASK) | |
130 | #define MACH_MSGH_BITS_OTHER(bits) \ | |
131 | ((bits) &~ MACH_MSGH_BITS_PORTS_MASK) | |
132 | ||
133 | /* | |
134 | * Every message starts with a message header. | |
135 | * Following the message header are zero or more pairs of | |
136 | * type descriptors (mach_msg_type_t/mach_msg_type_long_t) and | |
137 | * data values. The size of the message must be specified in bytes, | |
138 | * and includes the message header, type descriptors, inline | |
139 | * data, and inline pointer for out-of-line data. | |
140 | * | |
141 | * The msgh_remote_port field specifies the destination of the message. | |
142 | * It must specify a valid send or send-once right for a port. | |
143 | * | |
144 | * The msgh_local_port field specifies a "reply port". Normally, | |
145 | * This field carries a send-once right that the receiver will use | |
146 | * to reply to the message. It may carry the values MACH_PORT_NULL, | |
147 | * MACH_PORT_DEAD, a send-once right, or a send right. | |
148 | * | |
149 | * The msgh_seqno field carries a sequence number associated with the | |
150 | * received-from port. A port's sequence number is incremented every | |
151 | * time a message is received from it. In sent messages, the field's | |
152 | * value is ignored. | |
153 | * | |
154 | * The msgh_id field is uninterpreted by the message primitives. | |
155 | * It normally carries information specifying the format | |
156 | * or meaning of the message. | |
157 | */ | |
158 | ||
159 | typedef unsigned int mach_msg_bits_t; | |
160 | typedef natural_t mach_msg_size_t; | |
161 | typedef integer_t mach_msg_id_t; | |
162 | ||
163 | ||
164 | #define MACH_MSG_SIZE_NULL (mach_msg_size_t *) 0 | |
165 | ||
166 | typedef unsigned int mach_msg_type_name_t; | |
167 | ||
168 | #define MACH_MSG_TYPE_MOVE_RECEIVE 16 /* Must hold receive rights */ | |
169 | #define MACH_MSG_TYPE_MOVE_SEND 17 /* Must hold send rights */ | |
170 | #define MACH_MSG_TYPE_MOVE_SEND_ONCE 18 /* Must hold sendonce rights */ | |
171 | #define MACH_MSG_TYPE_COPY_SEND 19 /* Must hold send rights */ | |
172 | #define MACH_MSG_TYPE_MAKE_SEND 20 /* Must hold receive rights */ | |
173 | #define MACH_MSG_TYPE_MAKE_SEND_ONCE 21 /* Must hold receive rights */ | |
174 | #define MACH_MSG_TYPE_COPY_RECEIVE 22 /* Must hold receive rights */ | |
175 | ||
176 | typedef unsigned int mach_msg_copy_options_t; | |
177 | ||
178 | #define MACH_MSG_PHYSICAL_COPY 0 | |
179 | #define MACH_MSG_VIRTUAL_COPY 1 | |
180 | #define MACH_MSG_ALLOCATE 2 | |
181 | #define MACH_MSG_OVERWRITE 3 | |
182 | #ifdef MACH_KERNEL | |
183 | #define MACH_MSG_KALLOC_COPY_T 4 | |
1c79356b A |
184 | #endif /* MACH_KERNEL */ |
185 | ||
186 | typedef unsigned int mach_msg_descriptor_type_t; | |
187 | ||
188 | #define MACH_MSG_PORT_DESCRIPTOR 0 | |
189 | #define MACH_MSG_OOL_DESCRIPTOR 1 | |
190 | #define MACH_MSG_OOL_PORTS_DESCRIPTOR 2 | |
191 | #define MACH_MSG_OOL_VOLATILE_DESCRIPTOR 3 | |
192 | ||
91447636 | 193 | #pragma pack(4) |
1c79356b A |
194 | |
195 | typedef struct | |
196 | { | |
91447636 | 197 | natural_t pad1; |
1c79356b A |
198 | mach_msg_size_t pad2; |
199 | unsigned int pad3 : 24; | |
200 | mach_msg_descriptor_type_t type : 8; | |
201 | } mach_msg_type_descriptor_t; | |
202 | ||
203 | typedef struct | |
204 | { | |
205 | mach_port_t name; | |
206 | mach_msg_size_t pad1; | |
207 | unsigned int pad2 : 16; | |
208 | mach_msg_type_name_t disposition : 8; | |
209 | mach_msg_descriptor_type_t type : 8; | |
210 | } mach_msg_port_descriptor_t; | |
211 | ||
212 | typedef struct | |
213 | { | |
91447636 A |
214 | uint32_t address; |
215 | mach_msg_size_t size; | |
216 | boolean_t deallocate: 8; | |
217 | mach_msg_copy_options_t copy: 8; | |
218 | unsigned int pad1: 8; | |
219 | mach_msg_descriptor_type_t type: 8; | |
220 | } mach_msg_ool_descriptor32_t; | |
221 | ||
222 | typedef struct | |
223 | { | |
224 | uint64_t address; | |
225 | boolean_t deallocate: 8; | |
226 | mach_msg_copy_options_t copy: 8; | |
227 | unsigned int pad1: 8; | |
228 | mach_msg_descriptor_type_t type: 8; | |
229 | mach_msg_size_t size; | |
230 | } mach_msg_ool_descriptor64_t; | |
231 | ||
232 | typedef struct | |
233 | { | |
234 | void* address; | |
235 | #if !defined(__LP64__) | |
1c79356b | 236 | mach_msg_size_t size; |
91447636 | 237 | #endif |
1c79356b A |
238 | boolean_t deallocate: 8; |
239 | mach_msg_copy_options_t copy: 8; | |
240 | unsigned int pad1: 8; | |
241 | mach_msg_descriptor_type_t type: 8; | |
91447636 A |
242 | #if defined(__LP64__) |
243 | mach_msg_size_t size; | |
244 | #endif | |
1c79356b A |
245 | } mach_msg_ool_descriptor_t; |
246 | ||
91447636 A |
247 | typedef struct |
248 | { | |
249 | uint32_t address; | |
250 | mach_msg_size_t count; | |
251 | boolean_t deallocate: 8; | |
252 | mach_msg_copy_options_t copy: 8; | |
253 | mach_msg_type_name_t disposition : 8; | |
254 | mach_msg_descriptor_type_t type : 8; | |
255 | } mach_msg_ool_ports_descriptor32_t; | |
256 | ||
257 | typedef struct | |
258 | { | |
259 | uint64_t address; | |
260 | boolean_t deallocate: 8; | |
261 | mach_msg_copy_options_t copy: 8; | |
262 | mach_msg_type_name_t disposition : 8; | |
263 | mach_msg_descriptor_type_t type : 8; | |
264 | mach_msg_size_t count; | |
265 | } mach_msg_ool_ports_descriptor64_t; | |
266 | ||
1c79356b A |
267 | typedef struct |
268 | { | |
269 | void* address; | |
91447636 | 270 | #if !defined(__LP64__) |
1c79356b | 271 | mach_msg_size_t count; |
91447636 | 272 | #endif |
1c79356b A |
273 | boolean_t deallocate: 8; |
274 | mach_msg_copy_options_t copy: 8; | |
275 | mach_msg_type_name_t disposition : 8; | |
276 | mach_msg_descriptor_type_t type : 8; | |
91447636 A |
277 | #if defined(__LP64__) |
278 | mach_msg_size_t count; | |
279 | #endif | |
1c79356b A |
280 | } mach_msg_ool_ports_descriptor_t; |
281 | ||
91447636 A |
282 | /* |
283 | * LP64support - This union definition is not really | |
284 | * appropriate in LP64 mode because not all descriptors | |
285 | * are of the same size in that environment. | |
286 | */ | |
1c79356b A |
287 | typedef union |
288 | { | |
289 | mach_msg_port_descriptor_t port; | |
290 | mach_msg_ool_descriptor_t out_of_line; | |
291 | mach_msg_ool_ports_descriptor_t ool_ports; | |
292 | mach_msg_type_descriptor_t type; | |
293 | } mach_msg_descriptor_t; | |
294 | ||
295 | typedef struct | |
296 | { | |
297 | mach_msg_size_t msgh_descriptor_count; | |
298 | } mach_msg_body_t; | |
299 | ||
300 | #define MACH_MSG_BODY_NULL (mach_msg_body_t *) 0 | |
301 | #define MACH_MSG_DESCRIPTOR_NULL (mach_msg_descriptor_t *) 0 | |
302 | ||
303 | typedef struct | |
304 | { | |
305 | mach_msg_bits_t msgh_bits; | |
306 | mach_msg_size_t msgh_size; | |
307 | mach_port_t msgh_remote_port; | |
308 | mach_port_t msgh_local_port; | |
309 | mach_msg_size_t msgh_reserved; | |
310 | mach_msg_id_t msgh_id; | |
311 | } mach_msg_header_t; | |
312 | ||
313 | #define MACH_MSG_NULL (mach_msg_header_t *) 0 | |
314 | ||
315 | typedef struct | |
316 | { | |
317 | mach_msg_header_t header; | |
318 | mach_msg_body_t body; | |
319 | } mach_msg_base_t; | |
320 | ||
321 | typedef unsigned int mach_msg_trailer_type_t; | |
322 | ||
323 | #define MACH_MSG_TRAILER_FORMAT_0 0 | |
324 | ||
325 | typedef unsigned int mach_msg_trailer_size_t; | |
326 | ||
327 | typedef struct | |
328 | { | |
329 | mach_msg_trailer_type_t msgh_trailer_type; | |
330 | mach_msg_trailer_size_t msgh_trailer_size; | |
331 | } mach_msg_trailer_t; | |
332 | ||
333 | typedef struct | |
334 | { | |
335 | mach_msg_trailer_type_t msgh_trailer_type; | |
336 | mach_msg_trailer_size_t msgh_trailer_size; | |
337 | mach_port_seqno_t msgh_seqno; | |
338 | } mach_msg_seqno_trailer_t; | |
339 | ||
340 | typedef struct | |
341 | { | |
342 | unsigned int val[2]; | |
343 | } security_token_t; | |
344 | ||
345 | typedef struct | |
346 | { | |
347 | mach_msg_trailer_type_t msgh_trailer_type; | |
348 | mach_msg_trailer_size_t msgh_trailer_size; | |
349 | mach_port_seqno_t msgh_seqno; | |
350 | security_token_t msgh_sender; | |
351 | } mach_msg_security_trailer_t; | |
352 | ||
e5568f75 A |
353 | /* |
354 | * The audit token is an opaque token which identifies | |
355 | * Mach tasks and senders of Mach messages as subjects | |
356 | * to the BSM audit system. Only the appropriate BSM | |
357 | * library routines should be used to interpret the | |
358 | * contents of the audit token as the representation | |
359 | * of the subject identity within the token may change | |
360 | * over time. | |
361 | */ | |
55e303ae A |
362 | typedef struct |
363 | { | |
364 | unsigned int val[8]; | |
365 | } audit_token_t; | |
366 | ||
367 | typedef struct | |
368 | { | |
369 | mach_msg_trailer_type_t msgh_trailer_type; | |
370 | mach_msg_trailer_size_t msgh_trailer_size; | |
371 | mach_port_seqno_t msgh_seqno; | |
372 | security_token_t msgh_sender; | |
373 | audit_token_t msgh_audit; | |
374 | } mach_msg_audit_trailer_t; | |
1c79356b | 375 | |
1c79356b | 376 | #define MACH_MSG_TRAILER_MINIMUM_SIZE sizeof(mach_msg_trailer_t) |
55e303ae A |
377 | |
378 | /* | |
379 | * These values can change from release to release - but clearly | |
380 | * code cannot request additional trailer elements one was not | |
381 | * compiled to understand. Therefore, it is safe to use this | |
382 | * constant when the same module specified the receive options. | |
383 | * Otherwise, you run the risk that the options requested by | |
384 | * another module may exceed the local modules notion of | |
385 | * MAX_TRAILER_SIZE. | |
386 | */ | |
387 | typedef mach_msg_audit_trailer_t mach_msg_max_trailer_t; | |
388 | #define MAX_TRAILER_SIZE sizeof(mach_msg_max_trailer_t) | |
389 | ||
390 | /* | |
391 | * Legacy requirements keep us from ever updating these defines (even | |
392 | * when the format_0 trailers gain new option data fields in the future). | |
393 | * Therefore, they shouldn't be used going forward. Instead, the sizes | |
394 | * should be compared against the specific element size requested using | |
395 | * REQUESTED_TRAILER_SIZE. | |
396 | */ | |
397 | typedef mach_msg_security_trailer_t mach_msg_format_0_trailer_t; | |
398 | #define MACH_MSG_TRAILER_FORMAT_0_SIZE sizeof(mach_msg_format_0_trailer_t) | |
1c79356b A |
399 | |
400 | #define KERNEL_SECURITY_TOKEN_VALUE { {0, 1} } | |
401 | extern security_token_t KERNEL_SECURITY_TOKEN; | |
402 | ||
55e303ae A |
403 | #define KERNEL_AUDIT_TOKEN_VALUE { {0, 0, 0, 0, 0, 0, 0, 0} } |
404 | extern audit_token_t KERNEL_AUDIT_TOKEN; | |
405 | ||
1c79356b A |
406 | typedef integer_t mach_msg_options_t; |
407 | ||
408 | typedef struct | |
409 | { | |
410 | mach_msg_header_t header; | |
411 | } mach_msg_empty_send_t; | |
412 | ||
413 | typedef struct | |
414 | { | |
415 | mach_msg_header_t header; | |
416 | mach_msg_trailer_t trailer; | |
417 | } mach_msg_empty_rcv_t; | |
418 | ||
419 | typedef union | |
420 | { | |
421 | mach_msg_empty_send_t send; | |
422 | mach_msg_empty_rcv_t rcv; | |
423 | } mach_msg_empty_t; | |
424 | ||
91447636 A |
425 | #pragma pack() |
426 | ||
1c79356b A |
427 | /* utility to round the message size - will become machine dependent */ |
428 | #define round_msg(x) (((mach_msg_size_t)(x) + sizeof (natural_t) - 1) & \ | |
429 | ~(sizeof (natural_t) - 1)) | |
430 | ||
431 | /* | |
432 | * There is no fixed upper bound to the size of Mach messages. | |
433 | */ | |
434 | ||
435 | #define MACH_MSG_SIZE_MAX ((mach_msg_size_t) ~0) | |
436 | ||
437 | /* | |
438 | * Compatibility definitions, for code written | |
439 | * when there was a msgh_kind instead of msgh_seqno. | |
440 | */ | |
1c79356b | 441 | #define MACH_MSGH_KIND_NORMAL 0x00000000 |
1c79356b | 442 | #define MACH_MSGH_KIND_NOTIFICATION 0x00000001 |
1c79356b A |
443 | #define msgh_kind msgh_seqno |
444 | #define mach_msg_kind_t mach_port_seqno_t | |
445 | ||
446 | /* | |
447 | * The msgt_number field specifies the number of data elements. | |
448 | * The msgt_size field specifies the size of each data element, in bits. | |
449 | * The msgt_name field specifies the type of each data element. | |
450 | * If msgt_inline is TRUE, the data follows the type descriptor | |
451 | * in the body of the message. If msgt_inline is FALSE, then a pointer | |
452 | * to the data should follow the type descriptor, and the data is | |
453 | * sent out-of-line. In this case, if msgt_deallocate is TRUE, | |
454 | * then the out-of-line data is moved (instead of copied) into the message. | |
455 | * If msgt_longform is TRUE, then the type descriptor is actually | |
456 | * a mach_msg_type_long_t. | |
457 | * | |
458 | * The actual amount of inline data following the descriptor must | |
459 | * a multiple of the word size. For out-of-line data, this is a | |
460 | * pointer. For inline data, the supplied data size (calculated | |
461 | * from msgt_number/msgt_size) is rounded up. This guarantees | |
462 | * that type descriptors always fall on word boundaries. | |
463 | * | |
464 | * For port rights, msgt_size must be 8*sizeof(mach_port_t). | |
465 | * If the data is inline, msgt_deallocate should be FALSE. | |
466 | * The msgt_unused bit should be zero. | |
467 | * The msgt_name, msgt_size, msgt_number fields in | |
468 | * a mach_msg_type_long_t should be zero. | |
469 | */ | |
470 | ||
471 | typedef natural_t mach_msg_type_size_t; | |
472 | typedef natural_t mach_msg_type_number_t; | |
473 | ||
474 | /* | |
475 | * Values received/carried in messages. Tells the receiver what | |
476 | * sort of port right he now has. | |
477 | * | |
478 | * MACH_MSG_TYPE_PORT_NAME is used to transfer a port name | |
479 | * which should remain uninterpreted by the kernel. (Port rights | |
480 | * are not transferred, just the port name.) | |
481 | */ | |
482 | ||
483 | #define MACH_MSG_TYPE_PORT_NONE 0 | |
484 | ||
485 | #define MACH_MSG_TYPE_PORT_NAME 15 | |
486 | #define MACH_MSG_TYPE_PORT_RECEIVE MACH_MSG_TYPE_MOVE_RECEIVE | |
487 | #define MACH_MSG_TYPE_PORT_SEND MACH_MSG_TYPE_MOVE_SEND | |
488 | #define MACH_MSG_TYPE_PORT_SEND_ONCE MACH_MSG_TYPE_MOVE_SEND_ONCE | |
489 | ||
490 | #define MACH_MSG_TYPE_LAST 22 /* Last assigned */ | |
491 | ||
492 | /* | |
493 | * A dummy value. Mostly used to indicate that the actual value | |
494 | * will be filled in later, dynamically. | |
495 | */ | |
496 | ||
497 | #define MACH_MSG_TYPE_POLYMORPHIC ((mach_msg_type_name_t) -1) | |
498 | ||
499 | /* | |
500 | * Is a given item a port type? | |
501 | */ | |
502 | ||
503 | #define MACH_MSG_TYPE_PORT_ANY(x) \ | |
504 | (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \ | |
505 | ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE)) | |
506 | ||
507 | #define MACH_MSG_TYPE_PORT_ANY_SEND(x) \ | |
508 | (((x) >= MACH_MSG_TYPE_MOVE_SEND) && \ | |
509 | ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE)) | |
510 | ||
511 | #define MACH_MSG_TYPE_PORT_ANY_RIGHT(x) \ | |
512 | (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \ | |
513 | ((x) <= MACH_MSG_TYPE_MOVE_SEND_ONCE)) | |
514 | ||
515 | typedef integer_t mach_msg_option_t; | |
516 | ||
517 | #define MACH_MSG_OPTION_NONE 0x00000000 | |
518 | ||
519 | #define MACH_SEND_MSG 0x00000001 | |
520 | #define MACH_RCV_MSG 0x00000002 | |
521 | #define MACH_RCV_LARGE 0x00000004 | |
522 | ||
523 | #define MACH_SEND_TIMEOUT 0x00000010 | |
524 | #define MACH_SEND_INTERRUPT 0x00000040 /* libmach implements */ | |
525 | #define MACH_SEND_CANCEL 0x00000080 | |
526 | #define MACH_SEND_ALWAYS 0x00010000 /* internal use only */ | |
527 | #define MACH_SEND_TRAILER 0x00020000 | |
528 | ||
529 | #define MACH_RCV_TIMEOUT 0x00000100 | |
530 | #define MACH_RCV_NOTIFY 0x00000200 | |
531 | #define MACH_RCV_INTERRUPT 0x00000400 /* libmach implements */ | |
532 | #define MACH_RCV_OVERWRITE 0x00001000 | |
533 | ||
534 | /* | |
535 | * NOTE: a 0x00------ RCV mask implies to ask for | |
536 | * a MACH_MSG_TRAILER_FORMAT_0 with 0 Elements, | |
537 | * which is equivalent to a mach_msg_trailer_t. | |
538 | */ | |
539 | #define MACH_RCV_TRAILER_NULL 0 | |
540 | #define MACH_RCV_TRAILER_SEQNO 1 | |
541 | #define MACH_RCV_TRAILER_SENDER 2 | |
55e303ae | 542 | #define MACH_RCV_TRAILER_AUDIT 3 |
1c79356b A |
543 | |
544 | #define MACH_RCV_TRAILER_TYPE(x) (((x) & 0xf) << 28) | |
545 | #define MACH_RCV_TRAILER_ELEMENTS(x) (((x) & 0xf) << 24) | |
546 | #define MACH_RCV_TRAILER_MASK ((0xff << 24)) | |
547 | ||
1c79356b | 548 | #define GET_RCV_ELEMENTS(y) (((y) >> 24) & 0xf) |
9bccf70c A |
549 | #define REQUESTED_TRAILER_SIZE(y) \ |
550 | ((mach_msg_trailer_size_t) \ | |
551 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_NULL) ? \ | |
552 | sizeof(mach_msg_trailer_t) : \ | |
553 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SEQNO) ? \ | |
554 | sizeof(mach_msg_seqno_trailer_t) : \ | |
55e303ae A |
555 | ((GET_RCV_ELEMENTS(y) == MACH_RCV_TRAILER_SENDER) ? \ |
556 | sizeof(mach_msg_security_trailer_t) : \ | |
557 | sizeof(mach_msg_audit_trailer_t))))) | |
1c79356b A |
558 | /* |
559 | * Much code assumes that mach_msg_return_t == kern_return_t. | |
560 | * This definition is useful for descriptive purposes. | |
561 | * | |
562 | * See <mach/error.h> for the format of error codes. | |
563 | * IPC errors are system 4. Send errors are subsystem 0; | |
564 | * receive errors are subsystem 1. The code field is always non-zero. | |
565 | * The high bits of the code field communicate extra information | |
566 | * for some error codes. MACH_MSG_MASK masks off these special bits. | |
567 | */ | |
568 | ||
569 | typedef kern_return_t mach_msg_return_t; | |
570 | ||
571 | #define MACH_MSG_SUCCESS 0x00000000 | |
572 | ||
573 | ||
574 | #define MACH_MSG_MASK 0x00003e00 | |
575 | /* All special error code bits defined below. */ | |
576 | #define MACH_MSG_IPC_SPACE 0x00002000 | |
577 | /* No room in IPC name space for another capability name. */ | |
578 | #define MACH_MSG_VM_SPACE 0x00001000 | |
579 | /* No room in VM address space for out-of-line memory. */ | |
580 | #define MACH_MSG_IPC_KERNEL 0x00000800 | |
581 | /* Kernel resource shortage handling an IPC capability. */ | |
582 | #define MACH_MSG_VM_KERNEL 0x00000400 | |
583 | /* Kernel resource shortage handling out-of-line memory. */ | |
584 | ||
585 | #define MACH_SEND_IN_PROGRESS 0x10000001 | |
586 | /* Thread is waiting to send. (Internal use only.) */ | |
587 | #define MACH_SEND_INVALID_DATA 0x10000002 | |
588 | /* Bogus in-line data. */ | |
589 | #define MACH_SEND_INVALID_DEST 0x10000003 | |
590 | /* Bogus destination port. */ | |
591 | #define MACH_SEND_TIMED_OUT 0x10000004 | |
592 | /* Message not sent before timeout expired. */ | |
593 | #define MACH_SEND_INTERRUPTED 0x10000007 | |
594 | /* Software interrupt. */ | |
595 | #define MACH_SEND_MSG_TOO_SMALL 0x10000008 | |
596 | /* Data doesn't contain a complete message. */ | |
597 | #define MACH_SEND_INVALID_REPLY 0x10000009 | |
598 | /* Bogus reply port. */ | |
599 | #define MACH_SEND_INVALID_RIGHT 0x1000000a | |
600 | /* Bogus port rights in the message body. */ | |
601 | #define MACH_SEND_INVALID_NOTIFY 0x1000000b | |
602 | /* Bogus notify port argument. */ | |
603 | #define MACH_SEND_INVALID_MEMORY 0x1000000c | |
604 | /* Invalid out-of-line memory pointer. */ | |
605 | #define MACH_SEND_NO_BUFFER 0x1000000d | |
606 | /* No message buffer is available. */ | |
607 | #define MACH_SEND_TOO_LARGE 0x1000000e | |
608 | /* Send is too large for port */ | |
609 | #define MACH_SEND_INVALID_TYPE 0x1000000f | |
610 | /* Invalid msg-type specification. */ | |
611 | #define MACH_SEND_INVALID_HEADER 0x10000010 | |
612 | /* A field in the header had a bad value. */ | |
613 | #define MACH_SEND_INVALID_TRAILER 0x10000011 | |
614 | /* The trailer to be sent does not match kernel format. */ | |
615 | #define MACH_SEND_INVALID_RT_OOL_SIZE 0x10000015 | |
9bccf70c | 616 | /* compatibility: no longer a returned error */ |
1c79356b A |
617 | |
618 | #define MACH_RCV_IN_PROGRESS 0x10004001 | |
619 | /* Thread is waiting for receive. (Internal use only.) */ | |
620 | #define MACH_RCV_INVALID_NAME 0x10004002 | |
621 | /* Bogus name for receive port/port-set. */ | |
622 | #define MACH_RCV_TIMED_OUT 0x10004003 | |
623 | /* Didn't get a message within the timeout value. */ | |
624 | #define MACH_RCV_TOO_LARGE 0x10004004 | |
625 | /* Message buffer is not large enough for inline data. */ | |
626 | #define MACH_RCV_INTERRUPTED 0x10004005 | |
627 | /* Software interrupt. */ | |
628 | #define MACH_RCV_PORT_CHANGED 0x10004006 | |
9bccf70c | 629 | /* compatibility: no longer a returned error */ |
1c79356b A |
630 | #define MACH_RCV_INVALID_NOTIFY 0x10004007 |
631 | /* Bogus notify port argument. */ | |
632 | #define MACH_RCV_INVALID_DATA 0x10004008 | |
633 | /* Bogus message buffer for inline data. */ | |
634 | #define MACH_RCV_PORT_DIED 0x10004009 | |
635 | /* Port/set was sent away/died during receive. */ | |
636 | #define MACH_RCV_IN_SET 0x1000400a | |
9bccf70c | 637 | /* compatibility: no longer a returned error */ |
1c79356b A |
638 | #define MACH_RCV_HEADER_ERROR 0x1000400b |
639 | /* Error receiving message header. See special bits. */ | |
640 | #define MACH_RCV_BODY_ERROR 0x1000400c | |
641 | /* Error receiving message body. See special bits. */ | |
642 | #define MACH_RCV_INVALID_TYPE 0x1000400d | |
643 | /* Invalid msg-type specification in scatter list. */ | |
644 | #define MACH_RCV_SCATTER_SMALL 0x1000400e | |
645 | /* Out-of-line overwrite region is not large enough */ | |
646 | #define MACH_RCV_INVALID_TRAILER 0x1000400f | |
647 | /* trailer type or number of trailer elements not supported */ | |
648 | #define MACH_RCV_IN_PROGRESS_TIMED 0x10004011 | |
649 | /* Waiting for receive with timeout. (Internal use only.) */ | |
650 | ||
91447636 A |
651 | |
652 | __BEGIN_DECLS | |
653 | ||
9bccf70c A |
654 | /* |
655 | * Routine: mach_msg_overwrite | |
656 | * Purpose: | |
657 | * Send and/or receive a message. If the message operation | |
658 | * is interrupted, and the user did not request an indication | |
659 | * of that fact, then restart the appropriate parts of the | |
660 | * operation silently (trap version does not restart). | |
661 | * | |
662 | * Distinct send and receive buffers may be specified. If | |
663 | * no separate receive buffer is specified, the msg parameter | |
664 | * will be used for both send and receive operations. | |
665 | * | |
666 | * In addition to a distinct receive buffer, that buffer may | |
667 | * already contain scatter control information to direct the | |
668 | * receiving of the message. | |
669 | */ | |
1c79356b A |
670 | |
671 | extern mach_msg_return_t mach_msg_overwrite( | |
672 | mach_msg_header_t *msg, | |
673 | mach_msg_option_t option, | |
674 | mach_msg_size_t send_size, | |
675 | mach_msg_size_t rcv_size, | |
676 | mach_port_name_t rcv_name, | |
677 | mach_msg_timeout_t timeout, | |
678 | mach_port_name_t notify, | |
679 | mach_msg_header_t *rcv_msg, | |
680 | mach_msg_size_t rcv_limit); | |
681 | ||
91447636 A |
682 | #ifndef KERNEL |
683 | ||
9bccf70c A |
684 | /* |
685 | * Routine: mach_msg | |
686 | * Purpose: | |
687 | * Send and/or receive a message. If the message operation | |
688 | * is interrupted, and the user did not request an indication | |
689 | * of that fact, then restart the appropriate parts of the | |
690 | * operation silently (trap version does not restart). | |
691 | */ | |
1c79356b A |
692 | extern mach_msg_return_t mach_msg( |
693 | mach_msg_header_t *msg, | |
694 | mach_msg_option_t option, | |
695 | mach_msg_size_t send_size, | |
696 | mach_msg_size_t rcv_size, | |
697 | mach_port_name_t rcv_name, | |
698 | mach_msg_timeout_t timeout, | |
699 | mach_port_name_t notify); | |
700 | ||
91447636 A |
701 | #endif /* KERNEL */ |
702 | ||
703 | __END_DECLS | |
704 | ||
1c79356b | 705 | #endif /* _MACH_MESSAGE_H_ */ |