Sync usage with man page.
[netbsd-mini2440.git] / sys / compat / mach / mach_port.h
blobe7da98eb158dff0321169e8650e2fe3aa1c27925
1 /* $NetBSD: mach_port.h,v 1.39 2007/12/05 08:33:30 ad Exp $ */
3 /*-
4 * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Emmanuel Dreyfus
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #ifndef _MACH_PORT_H_
33 #define _MACH_PORT_H_
35 #define MACH_PORT_REF(mp) (mp)->mp_refcount++
36 #define MACH_PORT_UNREF(mp) if (--(mp)->mp_refcount <= 0) mach_port_put(mp)
38 #define MACH_PORT_NULL (struct mach_right *)0
39 #define MACH_PORT_DEAD (struct mach_right *)-1
41 #define MACH_PORT_RIGHT_SEND 0
42 #define MACH_PORT_RIGHT_RECEIVE 1
43 #define MACH_PORT_RIGHT_SEND_ONCE 2
44 #define MACH_PORT_RIGHT_PORT_SET 3
45 #define MACH_PORT_RIGHT_DEAD_NAME 4
46 #define MACH_PORT_RIGHT_NUMBER 5
48 #define MACH_PORT_TYPE_SEND (1 << (MACH_PORT_RIGHT_SEND + 16))
49 #define MACH_PORT_TYPE_RECEIVE (1 << (MACH_PORT_RIGHT_RECEIVE + 16))
50 #define MACH_PORT_TYPE_SEND_ONCE (1 << (MACH_PORT_RIGHT_SEND_ONCE + 16))
51 #define MACH_PORT_TYPE_PORT_SET (1 << (MACH_PORT_RIGHT_PORT_SET + 16))
52 #define MACH_PORT_TYPE_DEAD_NAME (1 << (MACH_PORT_RIGHT_DEAD_NAME + 16))
53 #define MACH_PORT_TYPE_PORT_RIGHTS \
54 (MACH_PORT_TYPE_SEND | MACH_PORT_TYPE_RECEIVE | MACH_PORT_TYPE_SEND_ONCE)
55 #define MACH_PORT_TYPE_PORT_OR_DEAD \
56 (MACH_PORT_TYPE_PORT_RIGHTS | MACH_PORT_TYPE_DEAD_NAME)
57 #define MACH_PORT_TYPE_ALL_RIGHTS \
58 (MACH_PORT_TYPE_PORT_OR_DEAD|MACH_PORT_TYPE_PORT_SET)
59 #define MACH_PORT_TYPE_REF_RIGHTS \
60 (MACH_PORT_TYPE_SEND | MACH_PORT_TYPE_SEND_ONCE | MACH_PORT_TYPE_DEAD_NAME)
62 /* port_deallocate */
64 typedef struct {
65 mach_msg_header_t req_msgh;
66 mach_ndr_record_t req_ndr;
67 mach_port_name_t req_name;
68 } mach_port_deallocate_request_t;
70 typedef struct {
71 mach_msg_header_t rep_msgh;
72 mach_ndr_record_t rep_ndr;
73 mach_kern_return_t rep_retval;
74 mach_msg_trailer_t rep_trailer;
75 } mach_port_deallocate_reply_t;
77 /* port_allocate */
79 typedef struct {
80 mach_msg_header_t req_msgh;
81 mach_ndr_record_t req_ndr;
82 mach_port_right_t req_right;
83 } mach_port_allocate_request_t;
85 typedef struct {
86 mach_msg_header_t rep_msgh;
87 mach_ndr_record_t rep_ndr;
88 mach_kern_return_t rep_retval;
89 mach_port_name_t rep_name;
90 mach_msg_trailer_t rep_trailer;
91 } mach_port_allocate_reply_t;
93 /* port_insert_right */
95 typedef struct {
96 mach_msg_header_t req_msgh;
97 mach_msg_body_t req_body;
98 mach_msg_port_descriptor_t req_poly;
99 mach_ndr_record_t req_ndr;
100 mach_port_name_t req_name;
101 } mach_port_insert_right_request_t;
103 typedef struct {
104 mach_msg_header_t rep_msgh;
105 mach_ndr_record_t rep_ndr;
106 mach_kern_return_t rep_retval;
107 mach_msg_trailer_t rep_trailer;
108 } mach_port_insert_right_reply_t;
110 /* port_type */
112 typedef struct {
113 mach_msg_header_t req_msgh;
114 mach_ndr_record_t req_ndr;
115 mach_port_name_t req_name;
116 } mach_port_type_request_t;
118 typedef struct {
119 mach_msg_header_t rep_msgh;
120 mach_ndr_record_t rep_ndr;
121 mach_kern_return_t rep_retval;
122 mach_port_type_t rep_ptype;
123 mach_msg_trailer_t rep_trailer;
124 } mach_port_type_reply_t;
126 /* port_set_attributes */
128 #define MACH_PORT_LIMITS_INFO 1
129 #define MACH_PORT_RECEIVE_STATUS 2
130 #define MACH_PORT_DNREQUESTS_SIZE 3
132 typedef struct mach_port_status {
133 mach_port_name_t mps_pset;
134 mach_port_seqno_t mps_seqno;
135 mach_port_mscount_t mps_mscount;
136 mach_port_msgcount_t mps_qlimit;
137 mach_port_msgcount_t mps_msgcount;
138 mach_port_rights_t mps_sorights;
139 mach_boolean_t mps_srights;
140 mach_boolean_t mps_pdrequest;
141 mach_boolean_t mps_nsrequest;
142 unsigned int mps_flags;
143 } mach_port_status_t;
145 typedef struct mach_port_limits {
146 mach_port_msgcount_t mpl_qlimit;
147 } mach_port_limits_t;
149 typedef struct {
150 mach_msg_header_t req_msgh;
151 mach_ndr_record_t req_ndr;
152 mach_port_name_t req_name;
153 mach_port_flavor_t req_flavor;
154 mach_msg_type_number_t req_count;
155 mach_integer_t req_port_info[0];
156 } mach_port_set_attributes_request_t;
158 typedef struct {
159 mach_msg_header_t rep_msgh;
160 mach_ndr_record_t rep_ndr;
161 mach_kern_return_t rep_retval;
162 mach_msg_trailer_t rep_trailer;
163 } mach_port_set_attributes_reply_t;
165 /* port_get_attributes */
167 #define MACH_PORT_QLIMIT_DEFAULT ((mach_port_msgcount_t) 5)
168 #define MACH_PORT_QLIMIT_MAX ((mach_port_msgcount_t) 16)
170 typedef struct {
171 mach_msg_header_t req_msgh;
172 mach_ndr_record_t req_ndr;
173 mach_port_name_t req_name;
174 mach_port_flavor_t req_flavor;
175 mach_msg_type_number_t req_count;
176 } mach_port_get_attributes_request_t;
178 typedef struct {
179 mach_msg_header_t rep_msgh;
180 mach_ndr_record_t rep_ndr;
181 mach_kern_return_t rep_retval;
182 mach_msg_type_number_t rep_count;
183 mach_integer_t rep_info[10];
184 mach_msg_trailer_t rep_trailer;
185 } mach_port_get_attributes_reply_t;
187 /* port_insert_member */
189 typedef struct {
190 mach_msg_header_t req_msgh;
191 mach_ndr_record_t req_ndr;
192 mach_port_name_t req_name;
193 mach_port_name_t req_pset;
194 } mach_port_insert_member_request_t;
196 typedef struct {
197 mach_msg_header_t rep_msgh;
198 mach_ndr_record_t rep_ndr;
199 mach_kern_return_t rep_retval;
200 mach_msg_trailer_t rep_trailer;
201 } mach_port_insert_member_reply_t;
203 /* port_move_member */
205 typedef struct {
206 mach_msg_header_t req_msgh;
207 mach_ndr_record_t req_ndr;
208 mach_port_name_t req_member;
209 mach_port_name_t req_after;
210 } mach_port_move_member_request_t;
212 typedef struct {
213 mach_msg_header_t rep_msgh;
214 mach_ndr_record_t rep_ndr;
215 mach_kern_return_t rep_retval;
216 mach_msg_trailer_t rep_trailer;
217 } mach_port_move_member_reply_t;
219 /* port_destroy */
221 typedef struct {
222 mach_msg_header_t req_msgh;
223 mach_ndr_record_t req_ndr;
224 mach_port_name_t req_name;
225 } mach_port_destroy_request_t;
227 typedef struct {
228 mach_msg_header_t rep_msgh;
229 mach_ndr_record_t rep_ndr;
230 mach_kern_return_t rep_retval;
231 mach_msg_trailer_t rep_trailer;
232 } mach_port_destroy_reply_t;
234 /* port_request_notification */
236 typedef struct {
237 mach_msg_header_t req_msgh;
238 mach_msg_body_t req_body;
239 mach_msg_port_descriptor_t req_notify;
240 mach_ndr_record_t req_ndr;
241 mach_port_name_t req_name;
242 mach_msg_id_t req_msgid;
243 mach_port_mscount_t req_count;
244 } mach_port_request_notification_request_t;
246 typedef struct {
247 mach_msg_header_t rep_msgh;
248 mach_msg_body_t rep_body;
249 mach_msg_port_descriptor_t rep_previous;
250 mach_msg_trailer_t rep_trailer;
251 } mach_port_request_notification_reply_t;
253 /* port_get_refs */
255 typedef struct {
256 mach_msg_header_t req_msgh;
257 mach_ndr_record_t req_ndr;
258 mach_port_name_t req_name;
259 mach_port_right_t req_right;
260 } mach_port_get_refs_request_t;
262 typedef struct {
263 mach_msg_header_t rep_msgh;
264 mach_ndr_record_t rep_ndr;
265 mach_kern_return_t rep_retval;
266 mach_port_urefs_t rep_refs;
267 mach_msg_trailer_t rep_trailer;
268 } mach_port_get_refs_reply_t;
270 /* port_mod_refs */
272 typedef struct {
273 mach_msg_header_t req_msgh;
274 mach_ndr_record_t req_ndr;
275 mach_port_name_t req_name;
276 mach_port_right_t req_right;
277 mach_port_delta_t req_delta;
278 } mach_port_mod_refs_request_t;
280 typedef struct {
281 mach_msg_header_t rep_msgh;
282 mach_ndr_record_t rep_ndr;
283 mach_kern_return_t rep_retval;
284 mach_msg_trailer_t rep_trailer;
285 } mach_port_mod_refs_reply_t;
287 /* Kernel-private structures */
289 extern struct mach_port *mach_clock_port;
290 extern struct mach_port *mach_io_master_port;
291 extern struct mach_port *mach_bootstrap_port;
292 extern struct mach_port *mach_saved_bootstrap_port;
294 /* In-kernel Mach port right description */
295 struct mach_right {
296 mach_port_t mr_name; /* The right name */
297 struct lwp *mr_lwp; /* points back to struct lwp */
298 int mr_type; /* right type (recv, send, sendonce) */
299 LIST_ENTRY(mach_right) mr_list; /* Right list for a process */
300 int mr_refcount; /* Reference count */
301 struct mach_right *mr_notify_destroyed; /* notify destroyed */
302 struct mach_right *mr_notify_dead_name; /* notify dead name */
303 struct mach_right *mr_notify_no_senders; /* notify no senders */
305 /* Revelant only if the right is on a port set */
306 LIST_HEAD(mr_set, mach_right) mr_set;
307 /* The right set list */
309 /* Revelant only if the right is not on a port set */
310 struct mach_port *mr_port; /* Port we have the right on */
311 LIST_ENTRY(mach_right) mr_setlist; /* Set list */
313 /* Revelant only if the right is part of a port set */
314 struct mach_right *mr_sethead; /* Points back to right set */
317 mach_port_t mach_right_newname(struct lwp *, mach_port_t);
318 struct mach_right *mach_right_get(struct mach_port *,
319 struct lwp *, int, mach_port_t);
320 void mach_right_put(struct mach_right *, int);
321 void mach_right_put_shlocked(struct mach_right *, int);
322 void mach_right_put_exclocked(struct mach_right *, int);
323 struct mach_right *mach_right_check(mach_port_t, struct lwp *, int);
325 /* In-kernel Mach port description */
326 struct mach_port {
327 struct mach_right *mp_recv; /* The receive right on this port */
328 int mp_count; /* Count of queued messages */
329 TAILQ_HEAD(mp_msglist, /* Queue pending messages */
330 mach_message) mp_msglist;
331 krwlock_t mp_msglock; /* Lock for the queue */
332 int mp_refcount; /* Reference count */
333 int mp_flags; /* Flags, see below */
334 int mp_datatype; /* Type of field mp_data, see below */
335 void *mp_data; /* Data attached to the port */
338 /* mp_flags for struct mach_port */
339 #define MACH_MP_INKERNEL 0x01 /* Receiver is inside the kernel */
340 #define MACH_MP_DATA_ALLOCATED 0x02 /* mp_data was malloc'ed */
342 /* mp_datatype for struct mach_port */
343 #define MACH_MP_NONE 0x0 /* No data */
344 #define MACH_MP_LWP 0x1 /* (struct lwp *) */
345 #define MACH_MP_DEVICE_ITERATOR 0x2 /* (struct mach_device_iterator *) */
346 #define MACH_MP_IOKIT_DEVCLASS 0x3 /* (struct mach_iokit_devclass *) */
347 #define MACH_MP_PROC 0x4 /* (struct proc *) */
348 #define MACH_MP_NOTIFY_SYNC 0x5 /* int */
349 #define MACH_MP_MEMORY_ENTRY 0x6 /* (struct mach_memory_entry *) */
350 #define MACH_MP_EXC_INFO 0x7 /* (struct mach_exc_info *) */
351 #define MACH_MP_SEMAPHORE 0x8 /* (struct mach_semaphore *) */
353 void mach_port_init(void);
354 struct mach_port *mach_port_get(void);
355 void mach_port_put(struct mach_port *);
356 void mach_remove_recvport(struct mach_port *);
357 void mach_add_recvport(struct mach_port *, struct lwp *);
358 int mach_port_check(struct mach_port *);
359 #ifdef DEBUG_MACH
360 void mach_debug_port(void);
361 #endif
363 #endif /* _MACH_PORT_H_ */