2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 * File: mach/message.h
55 * Mach IPC message and primitive function definitions.
58 #ifndef _MACH_MESSAGE_H_
59 #define _MACH_MESSAGE_H_
62 /* Have to have MIG parameter check for kernel */
64 #define _MIG_KERNEL_SPECIFIC_CODE_ 1
65 #endif /* MACH_KERNEL */
67 /* static templates are slower and bigger */
68 /* #define UseStaticTemplates 0 */
70 #include <mach/kern_return.h>
71 #include <mach/port.h>
75 * The timeout mechanism uses mach_msg_timeout_t values,
76 * passed by value. The timeout units are milliseconds.
77 * It is controlled with the MACH_SEND_TIMEOUT
78 * and MACH_RCV_TIMEOUT options.
81 typedef natural_t mach_msg_timeout_t
;
84 * The value to be used when there is no timeout.
85 * (No MACH_SEND_TIMEOUT/MACH_RCV_TIMEOUT option.)
88 #define MACH_MSG_TIMEOUT_NONE ((mach_msg_timeout_t) 0)
91 * The kernel uses MACH_MSGH_BITS_COMPLEX as a hint. It it isn't on, it
92 * assumes the body of the message doesn't contain port rights or OOL
93 * data. The field is set in received messages. A user task must
94 * use caution in interpreting the body of a message if the bit isn't
95 * on, because the mach_msg_type's in the body might "lie" about the
96 * contents. If the bit isn't on, but the mach_msg_types
97 * in the body specify rights or OOL data, the behavior is undefined.
98 * (Ie, an error may or may not be produced.)
100 * The value of MACH_MSGH_BITS_REMOTE determines the interpretation
101 * of the msgh_remote_port field. It is handled like a msgt_name.
103 * The value of MACH_MSGH_BITS_LOCAL determines the interpretation
104 * of the msgh_local_port field. It is handled like a msgt_name.
106 * MACH_MSGH_BITS() combines two MACH_MSG_TYPE_* values, for the remote
107 * and local fields, into a single value suitable for msgh_bits.
109 * MACH_MSGH_BITS_CIRCULAR should be zero; is is used internally.
111 * The unused bits should be zero and are reserved for the kernel
112 * or for future interface expansion.
115 #define MACH_MSGH_BITS_ZERO 0x00000000
116 #define MACH_MSGH_BITS_REMOTE_MASK 0x000000ff
117 #define MACH_MSGH_BITS_LOCAL_MASK 0x0000ff00
118 #define MACH_MSGH_BITS_COMPLEX 0x80000000U
119 #define MACH_MSGH_BITS_USER 0x8000ffffU
121 #define MACH_MSGH_BITS_CIRCULAR 0x40000000 /* internal use only */
122 #define MACH_MSGH_BITS_USED 0xc000ffffU
124 #define MACH_MSGH_BITS_PORTS_MASK \
125 (MACH_MSGH_BITS_REMOTE_MASK|MACH_MSGH_BITS_LOCAL_MASK)
127 #define MACH_MSGH_BITS(remote, local) \
128 ((remote) | ((local) << 8))
129 #define MACH_MSGH_BITS_REMOTE(bits) \
130 ((bits) & MACH_MSGH_BITS_REMOTE_MASK)
131 #define MACH_MSGH_BITS_LOCAL(bits) \
132 (((bits) & MACH_MSGH_BITS_LOCAL_MASK) >> 8)
133 #define MACH_MSGH_BITS_PORTS(bits) \
134 ((bits) & MACH_MSGH_BITS_PORTS_MASK)
135 #define MACH_MSGH_BITS_OTHER(bits) \
136 ((bits) &~ MACH_MSGH_BITS_PORTS_MASK)
139 * Every message starts with a message header.
140 * Following the message header are zero or more pairs of
141 * type descriptors (mach_msg_type_t/mach_msg_type_long_t) and
142 * data values. The size of the message must be specified in bytes,
143 * and includes the message header, type descriptors, inline
144 * data, and inline pointer for out-of-line data.
146 * The msgh_remote_port field specifies the destination of the message.
147 * It must specify a valid send or send-once right for a port.
149 * The msgh_local_port field specifies a "reply port". Normally,
150 * This field carries a send-once right that the receiver will use
151 * to reply to the message. It may carry the values MACH_PORT_NULL,
152 * MACH_PORT_DEAD, a send-once right, or a send right.
154 * The msgh_seqno field carries a sequence number associated with the
155 * received-from port. A port's sequence number is incremented every
156 * time a message is received from it. In sent messages, the field's
159 * The msgh_id field is uninterpreted by the message primitives.
160 * It normally carries information specifying the format
161 * or meaning of the message.
164 typedef unsigned int mach_msg_bits_t
;
165 typedef natural_t mach_msg_size_t
;
166 typedef integer_t mach_msg_id_t
;
169 #define MACH_MSG_SIZE_NULL (mach_msg_size_t *) 0
171 typedef unsigned int mach_msg_type_name_t
;
173 #define MACH_MSG_TYPE_MOVE_RECEIVE 16 /* Must hold receive rights */
174 #define MACH_MSG_TYPE_MOVE_SEND 17 /* Must hold send rights */
175 #define MACH_MSG_TYPE_MOVE_SEND_ONCE 18 /* Must hold sendonce rights */
176 #define MACH_MSG_TYPE_COPY_SEND 19 /* Must hold send rights */
177 #define MACH_MSG_TYPE_MAKE_SEND 20 /* Must hold receive rights */
178 #define MACH_MSG_TYPE_MAKE_SEND_ONCE 21 /* Must hold receive rights */
179 #define MACH_MSG_TYPE_COPY_RECEIVE 22 /* Must hold receive rights */
181 typedef unsigned int mach_msg_copy_options_t
;
183 #define MACH_MSG_PHYSICAL_COPY 0
184 #define MACH_MSG_VIRTUAL_COPY 1
185 #define MACH_MSG_ALLOCATE 2
186 #define MACH_MSG_OVERWRITE 3
188 #define MACH_MSG_KALLOC_COPY_T 4
189 #endif /* MACH_KERNEL */
191 typedef unsigned int mach_msg_descriptor_type_t
;
193 #define MACH_MSG_PORT_DESCRIPTOR 0
194 #define MACH_MSG_OOL_DESCRIPTOR 1
195 #define MACH_MSG_OOL_PORTS_DESCRIPTOR 2
196 #define MACH_MSG_OOL_VOLATILE_DESCRIPTOR 3
202 mach_msg_size_t pad2
;
203 unsigned int pad3
: 24;
204 mach_msg_descriptor_type_t type
: 8;
205 } mach_msg_type_descriptor_t
;
210 mach_msg_size_t pad1
;
211 unsigned int pad2
: 16;
212 mach_msg_type_name_t disposition
: 8;
213 mach_msg_descriptor_type_t type
: 8;
214 } mach_msg_port_descriptor_t
;
219 mach_msg_size_t size
;
220 boolean_t deallocate
: 8;
221 mach_msg_copy_options_t copy
: 8;
222 unsigned int pad1
: 8;
223 mach_msg_descriptor_type_t type
: 8;
224 } mach_msg_ool_descriptor_t
;
229 mach_msg_size_t count
;
230 boolean_t deallocate
: 8;
231 mach_msg_copy_options_t copy
: 8;
232 mach_msg_type_name_t disposition
: 8;
233 mach_msg_descriptor_type_t type
: 8;
234 } mach_msg_ool_ports_descriptor_t
;
238 mach_msg_port_descriptor_t port
;
239 mach_msg_ool_descriptor_t out_of_line
;
240 mach_msg_ool_ports_descriptor_t ool_ports
;
241 mach_msg_type_descriptor_t type
;
242 } mach_msg_descriptor_t
;
246 mach_msg_size_t msgh_descriptor_count
;
249 #define MACH_MSG_BODY_NULL (mach_msg_body_t *) 0
250 #define MACH_MSG_DESCRIPTOR_NULL (mach_msg_descriptor_t *) 0
254 mach_msg_bits_t msgh_bits
;
255 mach_msg_size_t msgh_size
;
256 mach_port_t msgh_remote_port
;
257 mach_port_t msgh_local_port
;
258 mach_msg_size_t msgh_reserved
;
259 mach_msg_id_t msgh_id
;
262 #define MACH_MSG_NULL (mach_msg_header_t *) 0
266 mach_msg_header_t header
;
267 mach_msg_body_t body
;
270 typedef unsigned int mach_msg_trailer_type_t
;
272 #define MACH_MSG_TRAILER_FORMAT_0 0
274 typedef unsigned int mach_msg_trailer_size_t
;
278 mach_msg_trailer_type_t msgh_trailer_type
;
279 mach_msg_trailer_size_t msgh_trailer_size
;
280 } mach_msg_trailer_t
;
284 mach_msg_trailer_type_t msgh_trailer_type
;
285 mach_msg_trailer_size_t msgh_trailer_size
;
286 mach_port_seqno_t msgh_seqno
;
287 } mach_msg_seqno_trailer_t
;
296 mach_msg_trailer_type_t msgh_trailer_type
;
297 mach_msg_trailer_size_t msgh_trailer_size
;
298 mach_port_seqno_t msgh_seqno
;
299 security_token_t msgh_sender
;
300 } mach_msg_security_trailer_t
;
302 typedef mach_msg_security_trailer_t mach_msg_format_0_trailer_t
;
304 #define MACH_MSG_TRAILER_FORMAT_0_SIZE sizeof(mach_msg_format_0_trailer_t)
305 #define MACH_MSG_TRAILER_MINIMUM_SIZE sizeof(mach_msg_trailer_t)
306 #define MAX_TRAILER_SIZE MACH_MSG_TRAILER_FORMAT_0_SIZE
308 #define KERNEL_SECURITY_TOKEN_VALUE { {0, 1} }
309 extern security_token_t KERNEL_SECURITY_TOKEN
;
311 typedef integer_t mach_msg_options_t
;
315 mach_msg_header_t header
;
316 } mach_msg_empty_send_t
;
320 mach_msg_header_t header
;
321 mach_msg_trailer_t trailer
;
322 } mach_msg_empty_rcv_t
;
326 mach_msg_empty_send_t send
;
327 mach_msg_empty_rcv_t rcv
;
330 /* utility to round the message size - will become machine dependent */
331 #define round_msg(x) (((mach_msg_size_t)(x) + sizeof (natural_t) - 1) & \
332 ~(sizeof (natural_t) - 1))
335 * There is no fixed upper bound to the size of Mach messages.
338 #define MACH_MSG_SIZE_MAX ((mach_msg_size_t) ~0)
341 * Compatibility definitions, for code written
342 * when there was a msgh_kind instead of msgh_seqno.
345 #define MACH_MSGH_KIND_NORMAL 0x00000000
347 /* code using this is likely to break, so better not to have it defined */
348 #define MACH_MSGH_KIND_NOTIFICATION 0x00000001
350 #define msgh_kind msgh_seqno
351 #define mach_msg_kind_t mach_port_seqno_t
354 * The msgt_number field specifies the number of data elements.
355 * The msgt_size field specifies the size of each data element, in bits.
356 * The msgt_name field specifies the type of each data element.
357 * If msgt_inline is TRUE, the data follows the type descriptor
358 * in the body of the message. If msgt_inline is FALSE, then a pointer
359 * to the data should follow the type descriptor, and the data is
360 * sent out-of-line. In this case, if msgt_deallocate is TRUE,
361 * then the out-of-line data is moved (instead of copied) into the message.
362 * If msgt_longform is TRUE, then the type descriptor is actually
363 * a mach_msg_type_long_t.
365 * The actual amount of inline data following the descriptor must
366 * a multiple of the word size. For out-of-line data, this is a
367 * pointer. For inline data, the supplied data size (calculated
368 * from msgt_number/msgt_size) is rounded up. This guarantees
369 * that type descriptors always fall on word boundaries.
371 * For port rights, msgt_size must be 8*sizeof(mach_port_t).
372 * If the data is inline, msgt_deallocate should be FALSE.
373 * The msgt_unused bit should be zero.
374 * The msgt_name, msgt_size, msgt_number fields in
375 * a mach_msg_type_long_t should be zero.
378 typedef natural_t mach_msg_type_size_t
;
379 typedef natural_t mach_msg_type_number_t
;
382 * Values received/carried in messages. Tells the receiver what
383 * sort of port right he now has.
385 * MACH_MSG_TYPE_PORT_NAME is used to transfer a port name
386 * which should remain uninterpreted by the kernel. (Port rights
387 * are not transferred, just the port name.)
390 #define MACH_MSG_TYPE_PORT_NONE 0
392 #define MACH_MSG_TYPE_PORT_NAME 15
393 #define MACH_MSG_TYPE_PORT_RECEIVE MACH_MSG_TYPE_MOVE_RECEIVE
394 #define MACH_MSG_TYPE_PORT_SEND MACH_MSG_TYPE_MOVE_SEND
395 #define MACH_MSG_TYPE_PORT_SEND_ONCE MACH_MSG_TYPE_MOVE_SEND_ONCE
397 #define MACH_MSG_TYPE_LAST 22 /* Last assigned */
400 * A dummy value. Mostly used to indicate that the actual value
401 * will be filled in later, dynamically.
404 #define MACH_MSG_TYPE_POLYMORPHIC ((mach_msg_type_name_t) -1)
407 * Is a given item a port type?
410 #define MACH_MSG_TYPE_PORT_ANY(x) \
411 (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
412 ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
414 #define MACH_MSG_TYPE_PORT_ANY_SEND(x) \
415 (((x) >= MACH_MSG_TYPE_MOVE_SEND) && \
416 ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
418 #define MACH_MSG_TYPE_PORT_ANY_RIGHT(x) \
419 (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
420 ((x) <= MACH_MSG_TYPE_MOVE_SEND_ONCE))
422 typedef integer_t mach_msg_option_t
;
424 #define MACH_MSG_OPTION_NONE 0x00000000
426 #define MACH_SEND_MSG 0x00000001
427 #define MACH_RCV_MSG 0x00000002
428 #define MACH_RCV_LARGE 0x00000004
430 #define MACH_SEND_TIMEOUT 0x00000010
431 #define MACH_SEND_INTERRUPT 0x00000040 /* libmach implements */
432 #define MACH_SEND_CANCEL 0x00000080
433 #define MACH_SEND_ALWAYS 0x00010000 /* internal use only */
434 #define MACH_SEND_TRAILER 0x00020000
436 #define MACH_RCV_TIMEOUT 0x00000100
437 #define MACH_RCV_NOTIFY 0x00000200
438 #define MACH_RCV_INTERRUPT 0x00000400 /* libmach implements */
439 #define MACH_RCV_OVERWRITE 0x00001000
442 * NOTE: a 0x00------ RCV mask implies to ask for
443 * a MACH_MSG_TRAILER_FORMAT_0 with 0 Elements,
444 * which is equivalent to a mach_msg_trailer_t.
446 #define MACH_RCV_TRAILER_NULL 0
447 #define MACH_RCV_TRAILER_SEQNO 1
448 #define MACH_RCV_TRAILER_SENDER 2
450 #define MACH_RCV_TRAILER_TYPE(x) (((x) & 0xf) << 28)
451 #define MACH_RCV_TRAILER_ELEMENTS(x) (((x) & 0xf) << 24)
452 #define MACH_RCV_TRAILER_MASK ((0xff << 24))
454 extern mach_msg_trailer_size_t trailer_size
[];
456 #define GET_RCV_ELEMENTS(y) (((y) >> 24) & 0xf)
457 #define REQUESTED_TRAILER_SIZE(y) (trailer_size[GET_RCV_ELEMENTS(y)])
460 * Much code assumes that mach_msg_return_t == kern_return_t.
461 * This definition is useful for descriptive purposes.
463 * See <mach/error.h> for the format of error codes.
464 * IPC errors are system 4. Send errors are subsystem 0;
465 * receive errors are subsystem 1. The code field is always non-zero.
466 * The high bits of the code field communicate extra information
467 * for some error codes. MACH_MSG_MASK masks off these special bits.
470 typedef kern_return_t mach_msg_return_t
;
472 #define MACH_MSG_SUCCESS 0x00000000
475 #define MACH_MSG_MASK 0x00003e00
476 /* All special error code bits defined below. */
477 #define MACH_MSG_IPC_SPACE 0x00002000
478 /* No room in IPC name space for another capability name. */
479 #define MACH_MSG_VM_SPACE 0x00001000
480 /* No room in VM address space for out-of-line memory. */
481 #define MACH_MSG_IPC_KERNEL 0x00000800
482 /* Kernel resource shortage handling an IPC capability. */
483 #define MACH_MSG_VM_KERNEL 0x00000400
484 /* Kernel resource shortage handling out-of-line memory. */
486 #define MACH_SEND_IN_PROGRESS 0x10000001
487 /* Thread is waiting to send. (Internal use only.) */
488 #define MACH_SEND_INVALID_DATA 0x10000002
489 /* Bogus in-line data. */
490 #define MACH_SEND_INVALID_DEST 0x10000003
491 /* Bogus destination port. */
492 #define MACH_SEND_TIMED_OUT 0x10000004
493 /* Message not sent before timeout expired. */
494 #define MACH_SEND_INTERRUPTED 0x10000007
495 /* Software interrupt. */
496 #define MACH_SEND_MSG_TOO_SMALL 0x10000008
497 /* Data doesn't contain a complete message. */
498 #define MACH_SEND_INVALID_REPLY 0x10000009
499 /* Bogus reply port. */
500 #define MACH_SEND_INVALID_RIGHT 0x1000000a
501 /* Bogus port rights in the message body. */
502 #define MACH_SEND_INVALID_NOTIFY 0x1000000b
503 /* Bogus notify port argument. */
504 #define MACH_SEND_INVALID_MEMORY 0x1000000c
505 /* Invalid out-of-line memory pointer. */
506 #define MACH_SEND_NO_BUFFER 0x1000000d
507 /* No message buffer is available. */
508 #define MACH_SEND_TOO_LARGE 0x1000000e
509 /* Send is too large for port */
510 #define MACH_SEND_INVALID_TYPE 0x1000000f
511 /* Invalid msg-type specification. */
512 #define MACH_SEND_INVALID_HEADER 0x10000010
513 /* A field in the header had a bad value. */
514 #define MACH_SEND_INVALID_TRAILER 0x10000011
515 /* The trailer to be sent does not match kernel format. */
516 #define MACH_SEND_INVALID_RT_OOL_SIZE 0x10000015
517 /* The OOL buffer size is too large for RT behavior */
519 #define MACH_RCV_IN_PROGRESS 0x10004001
520 /* Thread is waiting for receive. (Internal use only.) */
521 #define MACH_RCV_INVALID_NAME 0x10004002
522 /* Bogus name for receive port/port-set. */
523 #define MACH_RCV_TIMED_OUT 0x10004003
524 /* Didn't get a message within the timeout value. */
525 #define MACH_RCV_TOO_LARGE 0x10004004
526 /* Message buffer is not large enough for inline data. */
527 #define MACH_RCV_INTERRUPTED 0x10004005
528 /* Software interrupt. */
529 #define MACH_RCV_PORT_CHANGED 0x10004006
530 /* Port moved into a set during the receive. */
531 #define MACH_RCV_INVALID_NOTIFY 0x10004007
532 /* Bogus notify port argument. */
533 #define MACH_RCV_INVALID_DATA 0x10004008
534 /* Bogus message buffer for inline data. */
535 #define MACH_RCV_PORT_DIED 0x10004009
536 /* Port/set was sent away/died during receive. */
537 #define MACH_RCV_IN_SET 0x1000400a
538 /* Port is a member of a port set. */
539 #define MACH_RCV_HEADER_ERROR 0x1000400b
540 /* Error receiving message header. See special bits. */
541 #define MACH_RCV_BODY_ERROR 0x1000400c
542 /* Error receiving message body. See special bits. */
543 #define MACH_RCV_INVALID_TYPE 0x1000400d
544 /* Invalid msg-type specification in scatter list. */
545 #define MACH_RCV_SCATTER_SMALL 0x1000400e
546 /* Out-of-line overwrite region is not large enough */
547 #define MACH_RCV_INVALID_TRAILER 0x1000400f
548 /* trailer type or number of trailer elements not supported */
549 #define MACH_RCV_IN_PROGRESS_TIMED 0x10004011
550 /* Waiting for receive with timeout. (Internal use only.) */
552 extern mach_msg_return_t
mach_msg_overwrite_trap(
553 mach_msg_header_t
*msg
,
554 mach_msg_option_t option
,
555 mach_msg_size_t send_size
,
556 mach_msg_size_t rcv_size
,
557 mach_port_name_t rcv_name
,
558 mach_msg_timeout_t timeout
,
559 mach_port_name_t notify
,
560 mach_msg_header_t
*rcv_msg
,
561 mach_msg_size_t rcv_limit
);
563 extern mach_msg_return_t
mach_msg_overwrite(
564 mach_msg_header_t
*msg
,
565 mach_msg_option_t option
,
566 mach_msg_size_t send_size
,
567 mach_msg_size_t rcv_size
,
568 mach_port_name_t rcv_name
,
569 mach_msg_timeout_t timeout
,
570 mach_port_name_t notify
,
571 mach_msg_header_t
*rcv_msg
,
572 mach_msg_size_t rcv_limit
);
574 extern mach_msg_return_t
mach_msg_trap(
575 mach_msg_header_t
*msg
,
576 mach_msg_option_t option
,
577 mach_msg_size_t send_size
,
578 mach_msg_size_t rcv_size
,
579 mach_port_name_t rcv_name
,
580 mach_msg_timeout_t timeout
,
581 mach_port_name_t notify
);
583 extern mach_msg_return_t
mach_msg(
584 mach_msg_header_t
*msg
,
585 mach_msg_option_t option
,
586 mach_msg_size_t send_size
,
587 mach_msg_size_t rcv_size
,
588 mach_port_name_t rcv_name
,
589 mach_msg_timeout_t timeout
,
590 mach_port_name_t notify
);
592 #endif /* _MACH_MESSAGE_H_ */