1 /* $NetBSD: mach_message.h,v 1.26 2005/02/26 23:10:19 perry Exp $ */
2
3 /*-
4 * Copyright (c) 2001-2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas and Emmanuel Dreyfus.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #ifndef _MACH_MESSAGE_H_
40 #define _MACH_MESSAGE_H_
41
42 typedef unsigned int mach_msg_bits_t;
43 typedef unsigned int mach_msg_size_t;
44 typedef unsigned int mach_msg_id_t;
45 typedef unsigned int mach_msg_timeout_t;
46 typedef unsigned int mach_msg_option_t;
47 typedef unsigned int mach_msg_type_name_t;
48 typedef unsigned int mach_msg_type_number_t;
49
50 /*
51 * Options
52 */
53 #define MACH_MSG_OPTION_NONE 0x00000000
54 #define MACH_SEND_MSG 0x00000001
55 #define MACH_RCV_MSG 0x00000002
56 #define MACH_RCV_LARGE 0x00000004
57 #define MACH_SEND_TIMEOUT 0x00000010
58 #define MACH_SEND_INTERRUPT 0x00000040
59 #define MACH_SEND_CANCEL 0x00000080
60 #define MACH_RCV_TIMEOUT 0x00000100
61 #define MACH_RCV_NOTIFY 0x00000200
62 #define MACH_RCV_INTERRUPT 0x00000400
63 #define MACH_RCV_OVERWRITE 0x00001000
64 #define MACH_SEND_ALWAYS 0x00010000
65 #define MACH_SEND_TRAILER 0x00020000
66
67 /* mach_msg error codes */
68 #define MACH_MSG_SUCCESS 0x00000000
69 #define MACH_MSG_MASK 0x00003e00
70 #define MACH_MSG_IPC_SPACE 0x00002000
71 #define MACH_MSG_VM_SPACE 0x00001000
72 #define MACH_MSG_IPC_KERNEL 0x00000800
73 #define MACH_MSG_VM_KERNEL 0x00000400
74 #define MACH_SEND_MSG 0x00000001
75 #define MACH_SEND_TIMEOUT 0x00000010
76 #define MACH_SEND_INTERRUPT 0x00000040
77 #define MACH_SEND_CANCEL 0x00000080
78 #define MACH_SEND_ALWAYS 0x00010000
79 #define MACH_SEND_TRAILER 0x00020000
80 #define MACH_SEND_IN_PROGRESS 0x10000001
81 #define MACH_SEND_INVALID_DATA 0x10000002
82 #define MACH_SEND_INVALID_DEST 0x10000003
83 #define MACH_SEND_TIMED_OUT 0x10000004
84 #define MACH_SEND_INTERRUPTED 0x10000007
85 #define MACH_SEND_MSG_TOO_SMALL 0x10000008
86 #define MACH_SEND_INVALID_REPLY 0x10000009
87 #define MACH_SEND_INVALID_RIGHT 0x1000000a
88 #define MACH_SEND_INVALID_NOTIFY 0x1000000b
89 #define MACH_SEND_INVALID_MEMORY 0x1000000c
90 #define MACH_SEND_NO_BUFFER 0x1000000d
91 #define MACH_SEND_TOO_LARGE 0x1000000e
92 #define MACH_SEND_INVALID_TYPE 0x1000000f
93 #define MACH_SEND_INVALID_HEADER 0x10000010
94 #define MACH_SEND_INVALID_TRAILER 0x10000011
95 #define MACH_SEND_INVALID_RT_OOL_SIZE 0x10000015
96 #define MACH_RCV_IN_PROGRESS 0x10004001
97 #define MACH_RCV_INVALID_NAME 0x10004002
98 #define MACH_RCV_TIMED_OUT 0x10004003
99 #define MACH_RCV_TOO_LARGE 0x10004004
100 #define MACH_RCV_INTERRUPTED 0x10004005
101 #define MACH_RCV_PORT_CHANGED 0x10004006
102 #define MACH_RCV_INVALID_NOTIFY 0x10004007
103 #define MACH_RCV_INVALID_DATA 0x10004008
104 #define MACH_RCV_PORT_DIED 0x10004009
105 #define MACH_RCV_IN_SET 0x1000400a
106 #define MACH_RCV_HEADER_ERROR 0x1000400b
107 #define MACH_RCV_BODY_ERROR 0x1000400c
108 #define MACH_RCV_INVALID_TYPE 0x1000400d
109 #define MACH_RCV_SCATTER_SMALL 0x1000400e
110 #define MACH_RCV_INVALID_TRAILER 0x1000400f
111 #define MACH_RCV_IN_PROGRESS_TIMED 0x10004011
112
113 #define MACH_MSG_OPTION_BITS "\177\2" \
114 "b\00send_msg\0b\01rcv_msg\0" \
115 "b\02rcv_large\0b\03invalid[0x8]\0" \
116 "b\04send_timeout\0b05invalid[0x20]\0" \
117 "b\06send_interrupt\0b\05send_cancel\0" \
118 "b\06rcv_timeout\0b\07rcv_notify\0" \
119 "b\10rcv_interrupt\0b\11invalid[0x800]\0" \
120 "b\12rcv_overwrite\0b\13invalid[0x2000]\0" \
121 "b\14invalid[0x4000]\0b\15invalid[0x8000]\0" \
122 "b\16send_always\0b\17send_trailer\0"
123
124 #define MACH_MSGH_BITS_REMOTE_MASK 0x000000ff
125 #define MACH_MSGH_BITS_LOCAL_MASK 0x0000ff00
126 #define MACH_MSGH_BITS_COMPLEX 0x80000000
127 #define MACH_MSGH_LOCAL_BITS(bits) (((bits) >> 8) & 0xff)
128 #define MACH_MSGH_REMOTE_BITS(bits) ((bits) & 0xff)
129 #define MACH_MSGH_REPLY_LOCAL_BITS(bits) (((bits) << 8) & 0xff00)
130
131 #define MACH_MSG_TYPE_MOVE_RECEIVE 16
132 #define MACH_MSG_TYPE_MOVE_SEND 17
133 #define MACH_MSG_TYPE_MOVE_SEND_ONCE 18
134 #define MACH_MSG_TYPE_COPY_SEND 19
135 #define MACH_MSG_TYPE_MAKE_SEND 20
136 #define MACH_MSG_TYPE_MAKE_SEND_ONCE 21
137 #define MACH_MSG_TYPE_COPY_RECEIVE 22
138
139 typedef unsigned int mach_msg_copy_options_t;
140
141 #define MACH_MSG_PHYSICAL_COPY 0
142 #define MACH_MSG_VIRTUAL_COPY 1
143 #define MACH_MSG_ALLOCATE 2
144 #define MACH_MSG_OVERWRITE 3
145 #define MACH_MSG_KALLOC_COPY_T 4
146 #define MACH_MSG_PAGE_LIST_COPY_T 5
147
148 typedef unsigned int mach_msg_descriptor_type_t;
149
150 #define MACH_MSG_PORT_DESCRIPTOR 0
151 #define MACH_MSG_OOL_DESCRIPTOR 1
152 #define MACH_MSG_OOL_PORTS_DESCRIPTOR 2
153 #define MACH_MSG_OOL_VOLATILE_DESCRIPTOR 3
154
155 #define MACH_MAX_MSG_LEN 65536
156
157 typedef struct {
158 mach_msg_bits_t msgh_bits;
159 mach_msg_size_t msgh_size;
160 mach_port_t msgh_remote_port;
161 mach_port_t msgh_local_port;
162 mach_msg_size_t msgh_reserved;
163 mach_msg_id_t msgh_id;
164 } mach_msg_header_t;
165
166 #define MACH_MSG_TRAILER_FORMAT_0 0
167 typedef u_int32_t mach_msg_trailer_type_t;
168 typedef u_int32_t mach_msg_trailer_size_t;
169 typedef struct {
170 mach_msg_trailer_type_t msgh_trailer_type;
171 mach_msg_trailer_size_t msgh_trailer_size;
172 } mach_msg_trailer_t;
173
174 typedef struct {
175 void* pad1;
176 mach_msg_size_t pad2;
177 unsigned int pad3 : 24;
178 mach_msg_descriptor_type_t type : 8;
179 } mach_msg_type_descriptor_t;
180
181 typedef struct {
182 mach_port_t name;
183 mach_msg_size_t pad1;
184 unsigned int pad2 : 16;
185 mach_msg_type_name_t disposition : 8;
186 mach_msg_descriptor_type_t type : 8;
187 } mach_msg_port_descriptor_t;
188
189 typedef struct {
190 void * address;
191 mach_msg_size_t count;
192 mach_boolean_t deallocate: 8;
193 mach_msg_copy_options_t copy: 8;
194 mach_msg_type_name_t disposition : 8;
195 mach_msg_descriptor_type_t type : 8;
196 } mach_msg_ool_ports_descriptor_t;
197
198 typedef struct {
199 void * address;
200 mach_msg_size_t size;
201 mach_boolean_t deallocate : 8;
202 mach_msg_copy_options_t copy : 8;
203 unsigned int pad1 : 8;
204 mach_msg_descriptor_type_t type : 8;
205 } mach_msg_ool_descriptor_t;
206
207 typedef struct {
208 mach_msg_size_t msgh_descriptor_count;
209 } mach_msg_body_t;
210
211 #define MACH_REQMSG_OVERFLOW(args, test) \
212 (((u_long)&test - (u_long)args->smsg) > args->ssize)
213
214 struct mach_short_reply {
215 mach_msg_header_t sr_header;
216 mach_msg_trailer_t sr_trailer;
217 };
218
219 struct mach_complex_msg {
220 mach_msg_header_t mcm_header;
221 mach_msg_body_t mcm_body;
222 union {
223 mach_msg_type_descriptor_t gen[1];
224 mach_msg_port_descriptor_t port[1];
225 mach_msg_ool_ports_descriptor_t ool_ports[1];
226 mach_msg_ool_descriptor_t ool[1];
227 } mcm_desc;
228 };
229
230 /* Kernel-private structures */
231
232 struct mach_trap_args {
233 struct lwp *l; /* Current task (doing the Mach system call) */
234 struct lwp *tl; /* Target task */
235 void *smsg; /* Sent message */
236 void *rmsg; /* Reply message */
237 size_t ssize; /* Sent message size */
238 size_t *rsize; /* Reply message maximum size, may be lowered */
239 };
240
241 struct mach_service {
242 int srv_id;
243 int (*srv_handler)(struct mach_trap_args *);
244 const char *srv_name;
245 size_t srv_reqlen; /* Minimum length of the request message */
246 size_t srv_replen; /* Maximum length of the reply message */
247 };
248 extern struct mach_service mach_services_table[];
249
250
251 /* In-kernel Mach messages description */
252 struct mach_message {
253 mach_msg_header_t *mm_msg; /* In-kernel copy of the message */
254 size_t mm_size; /* Message size */
255 TAILQ_ENTRY(mach_message) mm_list;
256 /* List of pending messages */
257 struct mach_port *mm_port; /* The port on which msg is queued */
258 struct lwp *mm_l; /* The thread that sent it */
259 };
260
261 /* Flags for mach_ool_copy{in|out} */
262 #define MACH_OOL_NONE 0x0
263 #define MACH_OOL_FREE 0x1 /* Free kernel buffer after copyout */
264 #define MACH_OOL_TRACE 0x2 /* ktrace OOL data */
265
266 inline int mach_ool_copyin(struct proc *, const void *, void **, size_t, int);
267 inline int mach_ool_copyout(struct proc *, void *, void **, size_t, int);
268 inline void mach_set_trailer(void *, size_t);
269 inline void mach_set_header(void *, void *, size_t);
270 inline void mach_add_port_desc(void *, mach_port_name_t);
271 inline void mach_add_ool_ports_desc(void *, void *, int);
272 inline void mach_add_ool_desc(void *, void *, size_t);
273 void mach_message_init(void);
274 struct mach_message *mach_message_get(mach_msg_header_t *,
275 size_t, struct mach_port *, struct lwp *);
276 void mach_message_put(struct mach_message *);
277 void mach_message_put_shlocked(struct mach_message *);
278 void mach_message_put_exclocked(struct mach_message *);
279 #ifdef DEBUG_MACH
280 void mach_debug_message(void);
281 #endif
282
283 #endif /* !_MACH_MESSAGE_H_ */
Cache object: 7d0e9c8bf26e7a26d392783c4e80e03d
|