1 /* $NetBSD: mach_port.h,v 1.38 2005/12/11 12:20:20 christos Exp $ */
2
3 /*-
4 * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by 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_PORT_H_
40 #define _MACH_PORT_H_
41
42 #define MACH_PORT_REF(mp) (mp)->mp_refcount++
43 #define MACH_PORT_UNREF(mp) if (--(mp)->mp_refcount <= 0) mach_port_put(mp)
44
45 #define MACH_PORT_NULL (struct mach_right *)0
46 #define MACH_PORT_DEAD (struct mach_right *)-1
47
48 #define MACH_PORT_RIGHT_SEND 0
49 #define MACH_PORT_RIGHT_RECEIVE 1
50 #define MACH_PORT_RIGHT_SEND_ONCE 2
51 #define MACH_PORT_RIGHT_PORT_SET 3
52 #define MACH_PORT_RIGHT_DEAD_NAME 4
53 #define MACH_PORT_RIGHT_NUMBER 5
54
55 #define MACH_PORT_TYPE_SEND (1 << (MACH_PORT_RIGHT_SEND + 16))
56 #define MACH_PORT_TYPE_RECEIVE (1 << (MACH_PORT_RIGHT_RECEIVE + 16))
57 #define MACH_PORT_TYPE_SEND_ONCE (1 << (MACH_PORT_RIGHT_SEND_ONCE + 16))
58 #define MACH_PORT_TYPE_PORT_SET (1 << (MACH_PORT_RIGHT_PORT_SET + 16))
59 #define MACH_PORT_TYPE_DEAD_NAME (1 << (MACH_PORT_RIGHT_DEAD_NAME + 16))
60 #define MACH_PORT_TYPE_PORT_RIGHTS \
61 (MACH_PORT_TYPE_SEND | MACH_PORT_TYPE_RECEIVE | MACH_PORT_TYPE_SEND_ONCE)
62 #define MACH_PORT_TYPE_PORT_OR_DEAD \
63 (MACH_PORT_TYPE_PORT_RIGHTS | MACH_PORT_TYPE_DEAD_NAME)
64 #define MACH_PORT_TYPE_ALL_RIGHTS \
65 (MACH_PORT_TYPE_PORT_OR_DEAD|MACH_PORT_TYPE_PORT_SET)
66 #define MACH_PORT_TYPE_REF_RIGHTS \
67 (MACH_PORT_TYPE_SEND | MACH_PORT_TYPE_SEND_ONCE | MACH_PORT_TYPE_DEAD_NAME)
68
69 /* port_deallocate */
70
71 typedef struct {
72 mach_msg_header_t req_msgh;
73 mach_ndr_record_t req_ndr;
74 mach_port_name_t req_name;
75 } mach_port_deallocate_request_t;
76
77 typedef struct {
78 mach_msg_header_t rep_msgh;
79 mach_ndr_record_t rep_ndr;
80 mach_kern_return_t rep_retval;
81 mach_msg_trailer_t rep_trailer;
82 } mach_port_deallocate_reply_t;
83
84 /* port_allocate */
85
86 typedef struct {
87 mach_msg_header_t req_msgh;
88 mach_ndr_record_t req_ndr;
89 mach_port_right_t req_right;
90 } mach_port_allocate_request_t;
91
92 typedef struct {
93 mach_msg_header_t rep_msgh;
94 mach_ndr_record_t rep_ndr;
95 mach_kern_return_t rep_retval;
96 mach_port_name_t rep_name;
97 mach_msg_trailer_t rep_trailer;
98 } mach_port_allocate_reply_t;
99
100 /* port_insert_right */
101
102 typedef struct {
103 mach_msg_header_t req_msgh;
104 mach_msg_body_t req_body;
105 mach_msg_port_descriptor_t req_poly;
106 mach_ndr_record_t req_ndr;
107 mach_port_name_t req_name;
108 } mach_port_insert_right_request_t;
109
110 typedef struct {
111 mach_msg_header_t rep_msgh;
112 mach_ndr_record_t rep_ndr;
113 mach_kern_return_t rep_retval;
114 mach_msg_trailer_t rep_trailer;
115 } mach_port_insert_right_reply_t;
116
117 /* port_type */
118
119 typedef struct {
120 mach_msg_header_t req_msgh;
121 mach_ndr_record_t req_ndr;
122 mach_port_name_t req_name;
123 } mach_port_type_request_t;
124
125 typedef struct {
126 mach_msg_header_t rep_msgh;
127 mach_ndr_record_t rep_ndr;
128 mach_kern_return_t rep_retval;
129 mach_port_type_t rep_ptype;
130 mach_msg_trailer_t rep_trailer;
131 } mach_port_type_reply_t;
132
133 /* port_set_attributes */
134
135 #define MACH_PORT_LIMITS_INFO 1
136 #define MACH_PORT_RECEIVE_STATUS 2
137 #define MACH_PORT_DNREQUESTS_SIZE 3
138
139 typedef struct mach_port_status {
140 mach_port_name_t mps_pset;
141 mach_port_seqno_t mps_seqno;
142 mach_port_mscount_t mps_mscount;
143 mach_port_msgcount_t mps_qlimit;
144 mach_port_msgcount_t mps_msgcount;
145 mach_port_rights_t mps_sorights;
146 mach_boolean_t mps_srights;
147 mach_boolean_t mps_pdrequest;
148 mach_boolean_t mps_nsrequest;
149 unsigned int mps_flags;
150 } mach_port_status_t;
151
152 typedef struct mach_port_limits {
153 mach_port_msgcount_t mpl_qlimit;
154 } mach_port_limits_t;
155
156 typedef struct {
157 mach_msg_header_t req_msgh;
158 mach_ndr_record_t req_ndr;
159 mach_port_name_t req_name;
160 mach_port_flavor_t req_flavor;
161 mach_msg_type_number_t req_count;
162 mach_integer_t req_port_info[0];
163 } mach_port_set_attributes_request_t;
164
165 typedef struct {
166 mach_msg_header_t rep_msgh;
167 mach_ndr_record_t rep_ndr;
168 mach_kern_return_t rep_retval;
169 mach_msg_trailer_t rep_trailer;
170 } mach_port_set_attributes_reply_t;
171
172 /* port_get_attributes */
173
174 #define MACH_PORT_QLIMIT_DEFAULT ((mach_port_msgcount_t) 5)
175 #define MACH_PORT_QLIMIT_MAX ((mach_port_msgcount_t) 16)
176
177 typedef struct {
178 mach_msg_header_t req_msgh;
179 mach_ndr_record_t req_ndr;
180 mach_port_name_t req_name;
181 mach_port_flavor_t req_flavor;
182 mach_msg_type_number_t req_count;
183 } mach_port_get_attributes_request_t;
184
185 typedef struct {
186 mach_msg_header_t rep_msgh;
187 mach_ndr_record_t rep_ndr;
188 mach_kern_return_t rep_retval;
189 mach_msg_type_number_t rep_count;
190 mach_integer_t rep_info[10];
191 mach_msg_trailer_t rep_trailer;
192 } mach_port_get_attributes_reply_t;
193
194 /* port_insert_member */
195
196 typedef struct {
197 mach_msg_header_t req_msgh;
198 mach_ndr_record_t req_ndr;
199 mach_port_name_t req_name;
200 mach_port_name_t req_pset;
201 } mach_port_insert_member_request_t;
202
203 typedef struct {
204 mach_msg_header_t rep_msgh;
205 mach_ndr_record_t rep_ndr;
206 mach_kern_return_t rep_retval;
207 mach_msg_trailer_t rep_trailer;
208 } mach_port_insert_member_reply_t;
209
210 /* port_move_member */
211
212 typedef struct {
213 mach_msg_header_t req_msgh;
214 mach_ndr_record_t req_ndr;
215 mach_port_name_t req_member;
216 mach_port_name_t req_after;
217 } mach_port_move_member_request_t;
218
219 typedef struct {
220 mach_msg_header_t rep_msgh;
221 mach_ndr_record_t rep_ndr;
222 mach_kern_return_t rep_retval;
223 mach_msg_trailer_t rep_trailer;
224 } mach_port_move_member_reply_t;
225
226 /* port_destroy */
227
228 typedef struct {
229 mach_msg_header_t req_msgh;
230 mach_ndr_record_t req_ndr;
231 mach_port_name_t req_name;
232 } mach_port_destroy_request_t;
233
234 typedef struct {
235 mach_msg_header_t rep_msgh;
236 mach_ndr_record_t rep_ndr;
237 mach_kern_return_t rep_retval;
238 mach_msg_trailer_t rep_trailer;
239 } mach_port_destroy_reply_t;
240
241 /* port_request_notification */
242
243 typedef struct {
244 mach_msg_header_t req_msgh;
245 mach_msg_body_t req_body;
246 mach_msg_port_descriptor_t req_notify;
247 mach_ndr_record_t req_ndr;
248 mach_port_name_t req_name;
249 mach_msg_id_t req_msgid;
250 mach_port_mscount_t req_count;
251 } mach_port_request_notification_request_t;
252
253 typedef struct {
254 mach_msg_header_t rep_msgh;
255 mach_msg_body_t rep_body;
256 mach_msg_port_descriptor_t rep_previous;
257 mach_msg_trailer_t rep_trailer;
258 } mach_port_request_notification_reply_t;
259
260 /* port_get_refs */
261
262 typedef struct {
263 mach_msg_header_t req_msgh;
264 mach_ndr_record_t req_ndr;
265 mach_port_name_t req_name;
266 mach_port_right_t req_right;
267 } mach_port_get_refs_request_t;
268
269 typedef struct {
270 mach_msg_header_t rep_msgh;
271 mach_ndr_record_t rep_ndr;
272 mach_kern_return_t rep_retval;
273 mach_port_urefs_t rep_refs;
274 mach_msg_trailer_t rep_trailer;
275 } mach_port_get_refs_reply_t;
276
277 /* port_mod_refs */
278
279 typedef struct {
280 mach_msg_header_t req_msgh;
281 mach_ndr_record_t req_ndr;
282 mach_port_name_t req_name;
283 mach_port_right_t req_right;
284 mach_port_delta_t req_delta;
285 } mach_port_mod_refs_request_t;
286
287 typedef struct {
288 mach_msg_header_t rep_msgh;
289 mach_ndr_record_t rep_ndr;
290 mach_kern_return_t rep_retval;
291 mach_msg_trailer_t rep_trailer;
292 } mach_port_mod_refs_reply_t;
293
294 /* Kernel-private structures */
295
296 extern struct mach_port *mach_clock_port;
297 extern struct mach_port *mach_io_master_port;
298 extern struct mach_port *mach_bootstrap_port;
299 extern struct mach_port *mach_saved_bootstrap_port;
300
301 /* In-kernel Mach port right description */
302 struct mach_right {
303 mach_port_t mr_name; /* The right name */
304 struct lwp *mr_lwp; /* points back to struct lwp */
305 int mr_type; /* right type (recv, send, sendonce) */
306 LIST_ENTRY(mach_right) mr_list; /* Right list for a process */
307 int mr_refcount; /* Reference count */
308 struct mach_right *mr_notify_destroyed; /* notify destroyed */
309 struct mach_right *mr_notify_dead_name; /* notify dead name */
310 struct mach_right *mr_notify_no_senders; /* notify no senders */
311
312 /* Revelant only if the right is on a port set */
313 LIST_HEAD(mr_set, mach_right) mr_set;
314 /* The right set list */
315
316 /* Revelant only if the right is not on a port set */
317 struct mach_port *mr_port; /* Port we have the right on */
318 LIST_ENTRY(mach_right) mr_setlist; /* Set list */
319
320 /* Revelant only if the right is part of a port set */
321 struct mach_right *mr_sethead; /* Points back to right set */
322 };
323
324 mach_port_t mach_right_newname(struct lwp *, mach_port_t);
325 struct mach_right *mach_right_get(struct mach_port *,
326 struct lwp *, int, mach_port_t);
327 void mach_right_put(struct mach_right *, int);
328 void mach_right_put_shlocked(struct mach_right *, int);
329 void mach_right_put_exclocked(struct mach_right *, int);
330 struct mach_right *mach_right_check(mach_port_t, struct lwp *, int);
331
332 /* In-kernel Mach port description */
333 struct mach_port {
334 struct mach_right *mp_recv; /* The receive right on this port */
335 int mp_count; /* Count of queued messages */
336 TAILQ_HEAD(mp_msglist, /* Queue pending messages */
337 mach_message) mp_msglist;
338 struct lock mp_msglock; /* Lock for the queue */
339 int mp_refcount; /* Reference count */
340 int mp_flags; /* Flags, see below */
341 int mp_datatype; /* Type of field mp_data, see below */
342 void *mp_data; /* Data attached to the port */
343 };
344
345 /* mp_flags for struct mach_port */
346 #define MACH_MP_INKERNEL 0x01 /* Receiver is inside the kernel */
347 #define MACH_MP_DATA_ALLOCATED 0x02 /* mp_data was malloc'ed */
348
349 /* mp_datatype for struct mach_port */
350 #define MACH_MP_NONE 0x0 /* No data */
351 #define MACH_MP_LWP 0x1 /* (struct lwp *) */
352 #define MACH_MP_DEVICE_ITERATOR 0x2 /* (struct mach_device_iterator *) */
353 #define MACH_MP_IOKIT_DEVCLASS 0x3 /* (struct mach_iokit_devclass *) */
354 #define MACH_MP_PROC 0x4 /* (struct proc *) */
355 #define MACH_MP_NOTIFY_SYNC 0x5 /* int */
356 #define MACH_MP_MEMORY_ENTRY 0x6 /* (struct mach_memory_entry *) */
357 #define MACH_MP_EXC_INFO 0x7 /* (struct mach_exc_info *) */
358 #define MACH_MP_SEMAPHORE 0x8 /* (struct mach_semaphore *) */
359
360 void mach_port_init(void);
361 struct mach_port *mach_port_get(void);
362 void mach_port_put(struct mach_port *);
363 void mach_remove_recvport(struct mach_port *);
364 void mach_add_recvport(struct mach_port *, struct lwp *);
365 int mach_port_check(struct mach_port *);
366 #ifdef DEBUG_MACH
367 void mach_debug_port(void);
368 #endif
369
370 #endif /* _MACH_PORT_H_ */
Cache object: 8b356efdbad991b6db7e0b2cc13fe119
|