|
|
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;
1.1.1.4 ! root 139: union {
! 140: mach_port_t msgh_local_port;
! 141: unsigned long msgh_protected_payload;
! 142: };
1.1 root 143: mach_port_seqno_t msgh_seqno;
144: mach_msg_id_t msgh_id;
145: } mach_msg_header_t;
146:
147: /*
148: * There is no fixed upper bound to the size of Mach messages.
149: */
150:
151: #define MACH_MSG_SIZE_MAX ((mach_msg_size_t) ~0)
152:
153: /*
154: * Compatibility definitions, for code written
155: * when there was a msgh_kind instead of msgh_seqno.
156: */
157:
158: #define MACH_MSGH_KIND_NORMAL 0x00000000
159: #if 0
160: /* code using this is likely to break, so better not to have it defined */
161: #define MACH_MSGH_KIND_NOTIFICATION 0x00000001
162: #endif
163: #define msgh_kind msgh_seqno
164: #define mach_msg_kind_t mach_port_seqno_t
165:
166: /*
167: * The msgt_number field specifies the number of data elements.
168: * The msgt_size field specifies the size of each data element, in bits.
169: * The msgt_name field specifies the type of each data element.
170: * If msgt_inline is TRUE, the data follows the type descriptor
171: * in the body of the message. If msgt_inline is FALSE, then a pointer
172: * to the data should follow the type descriptor, and the data is
173: * sent out-of-line. In this case, if msgt_deallocate is TRUE,
174: * then the out-of-line data is moved (instead of copied) into the message.
175: * If msgt_longform is TRUE, then the type descriptor is actually
176: * a mach_msg_type_long_t.
177: *
178: * The actual amount of inline data following the descriptor must
179: * a multiple of the word size. For out-of-line data, this is a
180: * pointer. For inline data, the supplied data size (calculated
181: * from msgt_number/msgt_size) is rounded up. This guarantees
182: * that type descriptors always fall on word boundaries.
183: *
184: * For port rights, msgt_size must be 8*sizeof(mach_port_t).
185: * If the data is inline, msgt_deallocate should be FALSE.
186: * The msgt_unused bit should be zero.
187: * The msgt_name, msgt_size, msgt_number fields in
188: * a mach_msg_type_long_t should be zero.
189: */
190:
191: typedef unsigned int mach_msg_type_name_t;
192: typedef unsigned int mach_msg_type_size_t;
193: typedef natural_t mach_msg_type_number_t;
194:
195: typedef struct {
196: unsigned int msgt_name : 8,
197: msgt_size : 8,
198: msgt_number : 12,
199: msgt_inline : 1,
200: msgt_longform : 1,
201: msgt_deallocate : 1,
202: msgt_unused : 1;
203: } mach_msg_type_t;
204:
205: typedef struct {
206: mach_msg_type_t msgtl_header;
207: unsigned short msgtl_name;
208: unsigned short msgtl_size;
209: natural_t msgtl_number;
210: } mach_msg_type_long_t;
211:
212:
213: /*
214: * Known values for the msgt_name field.
215: *
216: * The only types known to the Mach kernel are
217: * the port types, and those types used in the
218: * kernel RPC interface.
219: */
220:
221: #define MACH_MSG_TYPE_UNSTRUCTURED 0
222: #define MACH_MSG_TYPE_BIT 0
223: #define MACH_MSG_TYPE_BOOLEAN 0
224: #define MACH_MSG_TYPE_INTEGER_16 1
225: #define MACH_MSG_TYPE_INTEGER_32 2
226: #define MACH_MSG_TYPE_CHAR 8
227: #define MACH_MSG_TYPE_BYTE 9
228: #define MACH_MSG_TYPE_INTEGER_8 9
229: #define MACH_MSG_TYPE_REAL 10
230: #define MACH_MSG_TYPE_INTEGER_64 11
231: #define MACH_MSG_TYPE_STRING 12
232: #define MACH_MSG_TYPE_STRING_C 12
233:
234: /*
235: * Values used when sending a port right.
236: */
237:
238: #define MACH_MSG_TYPE_MOVE_RECEIVE 16 /* Must hold receive rights */
239: #define MACH_MSG_TYPE_MOVE_SEND 17 /* Must hold send rights */
240: #define MACH_MSG_TYPE_MOVE_SEND_ONCE 18 /* Must hold sendonce rights */
241: #define MACH_MSG_TYPE_COPY_SEND 19 /* Must hold send rights */
242: #define MACH_MSG_TYPE_MAKE_SEND 20 /* Must hold receive rights */
243: #define MACH_MSG_TYPE_MAKE_SEND_ONCE 21 /* Must hold receive rights */
244:
245: /*
246: * Values received/carried in messages. Tells the receiver what
247: * sort of port right he now has.
248: *
249: * MACH_MSG_TYPE_PORT_NAME is used to transfer a port name
250: * which should remain uninterpreted by the kernel. (Port rights
251: * are not transferred, just the port name.)
252: */
253:
254: #define MACH_MSG_TYPE_PORT_NAME 15
255: #define MACH_MSG_TYPE_PORT_RECEIVE MACH_MSG_TYPE_MOVE_RECEIVE
256: #define MACH_MSG_TYPE_PORT_SEND MACH_MSG_TYPE_MOVE_SEND
257: #define MACH_MSG_TYPE_PORT_SEND_ONCE MACH_MSG_TYPE_MOVE_SEND_ONCE
258:
1.1.1.4 ! root 259: #define MACH_MSG_TYPE_PROTECTED_PAYLOAD 23
! 260:
! 261: #define MACH_MSG_TYPE_LAST 23 /* Last assigned */
1.1 root 262:
263: /*
264: * A dummy value. Mostly used to indicate that the actual value
265: * will be filled in later, dynamically.
266: */
267:
268: #define MACH_MSG_TYPE_POLYMORPHIC ((mach_msg_type_name_t) -1)
269:
270: /*
271: * Is a given item a port type?
272: */
273:
274: #define MACH_MSG_TYPE_PORT_ANY(x) \
275: (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
276: ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
277:
278: #define MACH_MSG_TYPE_PORT_ANY_SEND(x) \
279: (((x) >= MACH_MSG_TYPE_MOVE_SEND) && \
280: ((x) <= MACH_MSG_TYPE_MAKE_SEND_ONCE))
281:
282: #define MACH_MSG_TYPE_PORT_ANY_RIGHT(x) \
283: (((x) >= MACH_MSG_TYPE_MOVE_RECEIVE) && \
284: ((x) <= MACH_MSG_TYPE_MOVE_SEND_ONCE))
285:
286: typedef integer_t mach_msg_option_t;
287:
288: #define MACH_MSG_OPTION_NONE 0x00000000
289:
290: #define MACH_SEND_MSG 0x00000001
291: #define MACH_RCV_MSG 0x00000002
292:
293: #define MACH_SEND_TIMEOUT 0x00000010
294: #define MACH_SEND_NOTIFY 0x00000020
295: #define MACH_SEND_INTERRUPT 0x00000040 /* libmach implements */
296: #define MACH_SEND_CANCEL 0x00000080
297: #define MACH_RCV_TIMEOUT 0x00000100
298: #define MACH_RCV_NOTIFY 0x00000200
299: #define MACH_RCV_INTERRUPT 0x00000400 /* libmach implements */
300: #define MACH_RCV_LARGE 0x00000800
301:
302: #define MACH_SEND_ALWAYS 0x00010000 /* internal use only */
303:
304:
305: /*
306: * Much code assumes that mach_msg_return_t == kern_return_t.
307: * This definition is useful for descriptive purposes.
308: *
309: * See <mach/error.h> for the format of error codes.
310: * IPC errors are system 4. Send errors are subsystem 0;
311: * receive errors are subsystem 1. The code field is always non-zero.
312: * The high bits of the code field communicate extra information
313: * for some error codes. MACH_MSG_MASK masks off these special bits.
314: */
315:
316: typedef kern_return_t mach_msg_return_t;
317:
318: #define MACH_MSG_SUCCESS 0x00000000
319:
320: #define MACH_MSG_MASK 0x00003c00
321: /* All special error code bits defined below. */
322: #define MACH_MSG_IPC_SPACE 0x00002000
323: /* No room in IPC name space for another capability name. */
324: #define MACH_MSG_VM_SPACE 0x00001000
325: /* No room in VM address space for out-of-line memory. */
326: #define MACH_MSG_IPC_KERNEL 0x00000800
327: /* Kernel resource shortage handling an IPC capability. */
328: #define MACH_MSG_VM_KERNEL 0x00000400
329: /* Kernel resource shortage handling out-of-line memory. */
330:
331: #define MACH_SEND_IN_PROGRESS 0x10000001
332: /* Thread is waiting to send. (Internal use only.) */
333: #define MACH_SEND_INVALID_DATA 0x10000002
334: /* Bogus in-line data. */
335: #define MACH_SEND_INVALID_DEST 0x10000003
336: /* Bogus destination port. */
337: #define MACH_SEND_TIMED_OUT 0x10000004
338: /* Message not sent before timeout expired. */
339: #define MACH_SEND_WILL_NOTIFY 0x10000005
340: /* Msg-accepted notification will be generated. */
341: #define MACH_SEND_NOTIFY_IN_PROGRESS 0x10000006
342: /* Msg-accepted notification already pending. */
343: #define MACH_SEND_INTERRUPTED 0x10000007
344: /* Software interrupt. */
345: #define MACH_SEND_MSG_TOO_SMALL 0x10000008
346: /* Data doesn't contain a complete message. */
347: #define MACH_SEND_INVALID_REPLY 0x10000009
348: /* Bogus reply port. */
349: #define MACH_SEND_INVALID_RIGHT 0x1000000a
350: /* Bogus port rights in the message body. */
351: #define MACH_SEND_INVALID_NOTIFY 0x1000000b
352: /* Bogus notify port argument. */
353: #define MACH_SEND_INVALID_MEMORY 0x1000000c
354: /* Invalid out-of-line memory pointer. */
355: #define MACH_SEND_NO_BUFFER 0x1000000d
356: /* No message buffer is available. */
357: #define MACH_SEND_NO_NOTIFY 0x1000000e
358: /* Resource shortage; can't request msg-accepted notif. */
359: #define MACH_SEND_INVALID_TYPE 0x1000000f
360: /* Invalid msg-type specification. */
361: #define MACH_SEND_INVALID_HEADER 0x10000010
362: /* A field in the header had a bad value. */
363:
364: #define MACH_RCV_IN_PROGRESS 0x10004001
365: /* Thread is waiting for receive. (Internal use only.) */
366: #define MACH_RCV_INVALID_NAME 0x10004002
367: /* Bogus name for receive port/port-set. */
368: #define MACH_RCV_TIMED_OUT 0x10004003
369: /* Didn't get a message within the timeout value. */
370: #define MACH_RCV_TOO_LARGE 0x10004004
371: /* Message buffer is not large enough for inline data. */
372: #define MACH_RCV_INTERRUPTED 0x10004005
373: /* Software interrupt. */
374: #define MACH_RCV_PORT_CHANGED 0x10004006
375: /* Port moved into a set during the receive. */
376: #define MACH_RCV_INVALID_NOTIFY 0x10004007
377: /* Bogus notify port argument. */
378: #define MACH_RCV_INVALID_DATA 0x10004008
379: /* Bogus message buffer for inline data. */
380: #define MACH_RCV_PORT_DIED 0x10004009
381: /* Port/set was sent away/died during receive. */
382: #define MACH_RCV_IN_SET 0x1000400a
383: /* Port is a member of a port set. */
384: #define MACH_RCV_HEADER_ERROR 0x1000400b
385: /* Error receiving message header. See special bits. */
386: #define MACH_RCV_BODY_ERROR 0x1000400c
387: /* Error receiving message body. See special bits. */
388:
389:
390: extern mach_msg_return_t
391: mach_msg_trap
392: (mach_msg_header_t *msg,
393: mach_msg_option_t option,
394: mach_msg_size_t send_size,
395: mach_msg_size_t rcv_size,
396: mach_port_t rcv_name,
397: mach_msg_timeout_t timeout,
398: mach_port_t notify);
399:
400: extern mach_msg_return_t
401: mach_msg
402: (mach_msg_header_t *msg,
403: mach_msg_option_t option,
404: mach_msg_size_t send_size,
405: mach_msg_size_t rcv_size,
406: mach_port_t rcv_name,
407: mach_msg_timeout_t timeout,
408: mach_port_t notify);
409:
1.1.1.2 root 410: extern __typeof (mach_msg) __mach_msg;
411: extern __typeof (mach_msg_trap) __mach_msg_trap;
1.1 root 412:
413: #endif /* _MACH_MESSAGE_H_ */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.