|
|
1.1.1.2 root 1: /*
1.1 root 2: * Mach Operating System
3: * Copyright (c) 1992-1987 Carnegie Mellon University
4: * All Rights Reserved.
1.1.1.2 root 5: *
1.1 root 6: * Permission to use, copy, modify and distribute this software and its
7: * documentation is hereby granted, provided that both the copyright
8: * notice and this permission notice appear in all copies of the
9: * software, derivative works or modified versions, and any portions
10: * thereof, and that both notices appear in supporting documentation.
1.1.1.2 root 11: *
1.1 root 12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1.1.1.2 root 15: *
1.1 root 16: * Carnegie Mellon requests users of this software to return to
1.1.1.2 root 17: *
1.1 root 18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
1.1.1.2 root 22: *
1.1 root 23: * any improvements or extensions that they make and grant Carnegie Mellon
24: * the rights to redistribute these changes.
25: */
26: /*
27: * File: mach/message.h
28: *
29: * Mach IPC message and primitive function definitions.
30: */
31:
32: #ifndef _MACH_MESSAGE_H_
33: #define _MACH_MESSAGE_H_
34:
35: #include <mach/kern_return.h>
36: #include <mach/port.h>
37:
38:
39: /*
40: * The timeout mechanism uses mach_msg_timeout_t values,
41: * passed by value. The timeout units are milliseconds.
42: * It is controlled with the MACH_SEND_TIMEOUT
43: * and MACH_RCV_TIMEOUT options.
44: */
45:
46: typedef natural_t mach_msg_timeout_t;
47:
48: /*
49: * The value to be used when there is no timeout.
50: * (No MACH_SEND_TIMEOUT/MACH_RCV_TIMEOUT option.)
51: */
52:
53: #define MACH_MSG_TIMEOUT_NONE ((mach_msg_timeout_t) 0)
54:
55: /*
56: * The kernel uses MACH_MSGH_BITS_COMPLEX as a hint. It it isn't on, it
57: * assumes the body of the message doesn't contain port rights or OOL
58: * data. The field is set in received messages. A user task must
59: * use caution in interpreting the body of a message if the bit isn't
60: * on, because the mach_msg_type's in the body might "lie" about the
61: * contents. If the bit isn't on, but the mach_msg_types
62: * in the body specify rights or OOL data, the behaviour is undefined.
63: * (Ie, an error may or may not be produced.)
64: *
65: * The value of MACH_MSGH_BITS_REMOTE determines the interpretation
66: * of the msgh_remote_port field. It is handled like a msgt_name.
67: *
68: * The value of MACH_MSGH_BITS_LOCAL determines the interpretation
69: * of the msgh_local_port field. It is handled like a msgt_name.
70: *
71: * MACH_MSGH_BITS() combines two MACH_MSG_TYPE_* values, for the remote
72: * and local fields, into a single value suitable for msgh_bits.
73: *
74: * MACH_MSGH_BITS_COMPLEX_PORTS, MACH_MSGH_BITS_COMPLEX_DATA, and
75: * MACH_MSGH_BITS_CIRCULAR should be zero; they are used internally.
76: *
77: * The unused bits should be zero.
78: */
79:
80: #define MACH_MSGH_BITS_ZERO 0x00000000
81: #define MACH_MSGH_BITS_REMOTE_MASK 0x000000ff
82: #define MACH_MSGH_BITS_LOCAL_MASK 0x0000ff00
83: #define MACH_MSGH_BITS_COMPLEX 0x80000000U
84: #define MACH_MSGH_BITS_CIRCULAR 0x40000000 /* internal use only */
85: #define MACH_MSGH_BITS_COMPLEX_PORTS 0x20000000 /* internal use only */
86: #define MACH_MSGH_BITS_COMPLEX_DATA 0x10000000 /* internal use only */
87: #define MACH_MSGH_BITS_MIGRATED 0x08000000 /* internal use only */
88: #define MACH_MSGH_BITS_UNUSED 0x07ff0000
89:
90: #define MACH_MSGH_BITS_PORTS_MASK \
91: (MACH_MSGH_BITS_REMOTE_MASK|MACH_MSGH_BITS_LOCAL_MASK)
92:
93: #define MACH_MSGH_BITS(remote, local) \
94: ((remote) | ((local) << 8))
95: #define MACH_MSGH_BITS_REMOTE(bits) \
96: ((bits) & MACH_MSGH_BITS_REMOTE_MASK)
97: #define MACH_MSGH_BITS_LOCAL(bits) \
98: (((bits) & MACH_MSGH_BITS_LOCAL_MASK) >> 8)
99: #define MACH_MSGH_BITS_PORTS(bits) \
100: ((bits) & MACH_MSGH_BITS_PORTS_MASK)
101: #define MACH_MSGH_BITS_OTHER(bits) \
102: ((bits) &~ MACH_MSGH_BITS_PORTS_MASK)
103:
104: /*
105: * Every message starts with a message header.
106: * Following the message header are zero or more pairs of
107: * type descriptors (mach_msg_type_t/mach_msg_type_long_t) and
108: * data values. The size of the message must be specified in bytes,
109: * and includes the message header, type descriptors, inline
110: * data, and inline pointer for out-of-line data.
111: *
112: * The msgh_remote_port field specifies the destination of the message.
113: * It must specify a valid send or send-once right for a port.
114: *
115: * The msgh_local_port field specifies a "reply port". Normally,
116: * This field carries a send-once right that the receiver will use
117: * to reply to the message. It may carry the values MACH_PORT_NULL,
118: * MACH_PORT_DEAD, a send-once right, or a send right.
119: *
120: * The msgh_seqno field carries a sequence number associated with the
121: * received-from port. A port's sequence number is incremented every
122: * time a message is received from it. In sent messages, the field's
123: * value is ignored.
124: *
125: * The msgh_id field is uninterpreted by the message primitives.
126: * It normally carries information specifying the format
127: * or meaning of the message.
128: */
129:
130: typedef unsigned int mach_msg_bits_t;
131: typedef unsigned int mach_msg_size_t;
132: typedef natural_t mach_msg_seqno_t;
133: typedef integer_t mach_msg_id_t;
134:
135: typedef struct {
136: mach_msg_bits_t msgh_bits;
137: mach_msg_size_t msgh_size;
138: mach_port_t msgh_remote_port;
139: mach_port_t msgh_local_port;
140: mach_port_seqno_t msgh_seqno;
141: mach_msg_id_t msgh_id;
142: } mach_msg_header_t;
143:
144: /*
145: * There is no fixed upper bound to the size of Mach messages.
146: */
147:
148: #define MACH_MSG_SIZE_MAX ((mach_msg_size_t) ~0)
149:
150: /*
151: * Compatibility definitions, for code written
152: * when there was a msgh_kind instead of msgh_seqno.
153: */
154:
155: #define MACH_MSGH_KIND_NORMAL 0x00000000
156: #if 0
157: /* code using this is likely to break, so better not to have it defined */
158: #define MACH_MSGH_KIND_NOTIFICATION 0x00000001
159: #endif
160: #define msgh_kind msgh_seqno
161: #define mach_msg_kind_t mach_port_seqno_t
162:
163: /*
164: * The msgt_number field specifies the number of data elements.
165: * The msgt_size field specifies the size of each data element, in bits.
166: * The msgt_name field specifies the type of each data element.
167: * If msgt_inline is TRUE, the data follows the type descriptor
168: * in the body of the message. If msgt_inline is FALSE, then a pointer
169: * to the data should follow the type descriptor, and the data is
170: * sent out-of-line. In this case, if msgt_deallocate is TRUE,
171: * then the out-of-line data is moved (instead of copied) into the message.
172: * If msgt_longform is TRUE, then the type descriptor is actually
173: * a mach_msg_type_long_t.
174: *
175: * The actual amount of inline data following the descriptor must
176: * a multiple of the word size. For out-of-line data, this is a
177: * pointer. For inline data, the supplied data size (calculated
178: * from msgt_number/msgt_size) is rounded up. This guarantees
179: * that type descriptors always fall on word boundaries.
180: *
181: * For port rights, msgt_size must be 8*sizeof(mach_port_t).
182: * If the data is inline, msgt_deallocate should be FALSE.
183: * The msgt_unused bit should be zero.
184: * The msgt_name, msgt_size, msgt_number fields in
185: * a mach_msg_type_long_t should be zero.
186: */
187:
188: typedef unsigned int mach_msg_type_name_t;
189: typedef unsigned int mach_msg_type_size_t;
190: typedef natural_t mach_msg_type_number_t;
191:
192: typedef struct {
193: unsigned int msgt_name : 8,
194: msgt_size : 8,
195: msgt_number : 12,
196: msgt_inline : 1,
197: msgt_longform : 1,
198: msgt_deallocate : 1,
199: msgt_unused : 1;
200: } mach_msg_type_t;
201:
202: typedef struct {
203: mach_msg_type_t msgtl_header;
204: unsigned short msgtl_name;
205: unsigned short msgtl_size;
206: natural_t msgtl_number;
207: } mach_msg_type_long_t;
208:
209:
210: /*
211: * Known values for the msgt_name field.
212: *
213: * The only types known to the Mach kernel are
214: * the port types, and those types used in the
215: * kernel RPC interface.
216: */
217:
218: #define MACH_MSG_TYPE_UNSTRUCTURED 0
219: #define MACH_MSG_TYPE_BIT 0
220: #define MACH_MSG_TYPE_BOOLEAN 0
221: #define MACH_MSG_TYPE_INTEGER_16 1
222: #define MACH_MSG_TYPE_INTEGER_32 2
223: #define MACH_MSG_TYPE_CHAR 8
224: #define MACH_MSG_TYPE_BYTE 9
225: #define MACH_MSG_TYPE_INTEGER_8 9
226: #define MACH_MSG_TYPE_REAL 10
227: #define MACH_MSG_TYPE_INTEGER_64 11
228: #define MACH_MSG_TYPE_STRING 12
229: #define MACH_MSG_TYPE_STRING_C 12
230:
231: /*
232: * Values used when sending a port right.
233: */
234:
235: #define MACH_MSG_TYPE_MOVE_RECEIVE 16 /* Must hold receive rights */
236: #define MACH_MSG_TYPE_MOVE_SEND 17 /* Must hold send rights */
237: #define MACH_MSG_TYPE_MOVE_SEND_ONCE 18 /* Must hold sendonce rights */
238: #define MACH_MSG_TYPE_COPY_SEND 19 /* Must hold send rights */
239: #define MACH_MSG_TYPE_MAKE_SEND 20 /* Must hold receive rights */
240: #define MACH_MSG_TYPE_MAKE_SEND_ONCE 21 /* Must hold receive rights */
241:
242: /*
243: * Values received/carried in messages. Tells the receiver what
244: * sort of port right he now has.
245: *
246: * MACH_MSG_TYPE_PORT_NAME is used to transfer a port name
247: * which should remain uninterpreted by the kernel. (Port rights
248: * are not transferred, just the port name.)
249: */
250:
251: #define MACH_MSG_TYPE_PORT_NAME 15
252: #define MACH_MSG_TYPE_PORT_RECEIVE MACH_MSG_TYPE_MOVE_RECEIVE
253: #define MACH_MSG_TYPE_PORT_SEND MACH_MSG_TYPE_MOVE_SEND
254: #define MACH_MSG_TYPE_PORT_SEND_ONCE MACH_MSG_TYPE_MOVE_SEND_ONCE
255:
256: #define MACH_MSG_TYPE_LAST 22 /* Last assigned */
257:
258: /*
259: * A dummy value. Mostly used to indicate that the actual value
260: * will be filled in later, dynamically.
261: */
262:
263: #define MACH_MSG_TYPE_POLYMORPHIC ((mach_msg_type_name_t) -1)
264:
265: /*
266: * Is a given item a port type?
267: */
268:
269: #define MACH_MSG_TYPE_PORT_ANY(x) \
270: (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
271: ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
272:
273: #define MACH_MSG_TYPE_PORT_ANY_SEND(x) \
274: (((x) >= MACH_MSG_TYPE_MOVE_SEND) && \
275: ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
276:
277: #define MACH_MSG_TYPE_PORT_ANY_RIGHT(x) \
278: (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
279: ((x) <= MACH_MSG_TYPE_MOVE_SEND_ONCE))
280:
281: typedef integer_t mach_msg_option_t;
282:
283: #define MACH_MSG_OPTION_NONE 0x00000000
284:
285: #define MACH_SEND_MSG 0x00000001
286: #define MACH_RCV_MSG 0x00000002
287:
288: #define MACH_SEND_TIMEOUT 0x00000010
289: #define MACH_SEND_NOTIFY 0x00000020
290: #define MACH_SEND_INTERRUPT 0x00000040 /* libmach implements */
291: #define MACH_SEND_CANCEL 0x00000080
292: #define MACH_RCV_TIMEOUT 0x00000100
293: #define MACH_RCV_NOTIFY 0x00000200
294: #define MACH_RCV_INTERRUPT 0x00000400 /* libmach implements */
295: #define MACH_RCV_LARGE 0x00000800
296:
297: #define MACH_SEND_ALWAYS 0x00010000 /* internal use only */
298:
299:
300: /*
301: * Much code assumes that mach_msg_return_t == kern_return_t.
302: * This definition is useful for descriptive purposes.
303: *
304: * See <mach/error.h> for the format of error codes.
305: * IPC errors are system 4. Send errors are subsystem 0;
306: * receive errors are subsystem 1. The code field is always non-zero.
307: * The high bits of the code field communicate extra information
308: * for some error codes. MACH_MSG_MASK masks off these special bits.
309: */
310:
311: typedef kern_return_t mach_msg_return_t;
312:
313: #define MACH_MSG_SUCCESS 0x00000000
314:
315: #define MACH_MSG_MASK 0x00003c00
316: /* All special error code bits defined below. */
317: #define MACH_MSG_IPC_SPACE 0x00002000
318: /* No room in IPC name space for another capability name. */
319: #define MACH_MSG_VM_SPACE 0x00001000
320: /* No room in VM address space for out-of-line memory. */
321: #define MACH_MSG_IPC_KERNEL 0x00000800
322: /* Kernel resource shortage handling an IPC capability. */
323: #define MACH_MSG_VM_KERNEL 0x00000400
324: /* Kernel resource shortage handling out-of-line memory. */
325:
326: #define MACH_SEND_IN_PROGRESS 0x10000001
327: /* Thread is waiting to send. (Internal use only.) */
328: #define MACH_SEND_INVALID_DATA 0x10000002
329: /* Bogus in-line data. */
330: #define MACH_SEND_INVALID_DEST 0x10000003
331: /* Bogus destination port. */
332: #define MACH_SEND_TIMED_OUT 0x10000004
333: /* Message not sent before timeout expired. */
334: #define MACH_SEND_WILL_NOTIFY 0x10000005
335: /* Msg-accepted notification will be generated. */
336: #define MACH_SEND_NOTIFY_IN_PROGRESS 0x10000006
337: /* Msg-accepted notification already pending. */
338: #define MACH_SEND_INTERRUPTED 0x10000007
339: /* Software interrupt. */
340: #define MACH_SEND_MSG_TOO_SMALL 0x10000008
341: /* Data doesn't contain a complete message. */
342: #define MACH_SEND_INVALID_REPLY 0x10000009
343: /* Bogus reply port. */
344: #define MACH_SEND_INVALID_RIGHT 0x1000000a
345: /* Bogus port rights in the message body. */
346: #define MACH_SEND_INVALID_NOTIFY 0x1000000b
347: /* Bogus notify port argument. */
348: #define MACH_SEND_INVALID_MEMORY 0x1000000c
349: /* Invalid out-of-line memory pointer. */
350: #define MACH_SEND_NO_BUFFER 0x1000000d
351: /* No message buffer is available. */
352: #define MACH_SEND_NO_NOTIFY 0x1000000e
353: /* Resource shortage; can't request msg-accepted notif. */
354: #define MACH_SEND_INVALID_TYPE 0x1000000f
355: /* Invalid msg-type specification. */
356: #define MACH_SEND_INVALID_HEADER 0x10000010
357: /* A field in the header had a bad value. */
358:
359: #define MACH_RCV_IN_PROGRESS 0x10004001
360: /* Thread is waiting for receive. (Internal use only.) */
361: #define MACH_RCV_INVALID_NAME 0x10004002
362: /* Bogus name for receive port/port-set. */
363: #define MACH_RCV_TIMED_OUT 0x10004003
364: /* Didn't get a message within the timeout value. */
365: #define MACH_RCV_TOO_LARGE 0x10004004
366: /* Message buffer is not large enough for inline data. */
367: #define MACH_RCV_INTERRUPTED 0x10004005
368: /* Software interrupt. */
369: #define MACH_RCV_PORT_CHANGED 0x10004006
370: /* Port moved into a set during the receive. */
371: #define MACH_RCV_INVALID_NOTIFY 0x10004007
372: /* Bogus notify port argument. */
373: #define MACH_RCV_INVALID_DATA 0x10004008
374: /* Bogus message buffer for inline data. */
375: #define MACH_RCV_PORT_DIED 0x10004009
376: /* Port/set was sent away/died during receive. */
377: #define MACH_RCV_IN_SET 0x1000400a
378: /* Port is a member of a port set. */
379: #define MACH_RCV_HEADER_ERROR 0x1000400b
380: /* Error receiving message header. See special bits. */
381: #define MACH_RCV_BODY_ERROR 0x1000400c
382: /* Error receiving message body. See special bits. */
383:
384:
385: extern mach_msg_return_t
386: mach_msg_trap
387: (mach_msg_header_t *msg,
388: mach_msg_option_t option,
389: mach_msg_size_t send_size,
390: mach_msg_size_t rcv_size,
391: mach_port_t rcv_name,
392: mach_msg_timeout_t timeout,
393: mach_port_t notify);
394:
395: extern mach_msg_return_t
396: mach_msg
397: (mach_msg_header_t *msg,
398: mach_msg_option_t option,
399: mach_msg_size_t send_size,
400: mach_msg_size_t rcv_size,
401: mach_port_t rcv_name,
402: mach_msg_timeout_t timeout,
403: mach_port_t notify);
404:
1.1.1.2 root 405: extern __typeof (mach_msg) __mach_msg;
406: extern __typeof (mach_msg_trap) __mach_msg_trap;
1.1 root 407:
408: #endif /* _MACH_MESSAGE_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.