]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * The contents of this file constitute Original Code as defined in and | |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
25 | /* | |
26 | * Mach Operating System | |
27 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University | |
28 | * All Rights Reserved. | |
29 | * | |
30 | * Permission to use, copy, modify and distribute this software and its | |
31 | * documentation is hereby granted, provided that both the copyright | |
32 | * notice and this permission notice appear in all copies of the | |
33 | * software, derivative works or modified versions, and any portions | |
34 | * thereof, and that both notices appear in supporting documentation. | |
35 | * | |
36 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
37 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
38 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
39 | * | |
40 | * Carnegie Mellon requests users of this software to return to | |
41 | * | |
42 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
43 | * School of Computer Science | |
44 | * Carnegie Mellon University | |
45 | * Pittsburgh PA 15213-3890 | |
46 | * | |
47 | * any improvements or extensions that they make and grant Carnegie Mellon | |
48 | * the rights to redistribute these changes. | |
49 | */ | |
50 | /* | |
51 | */ | |
52 | /* | |
53 | * File: mach/port.h | |
54 | * | |
55 | * Definition of a Mach port | |
56 | * | |
57 | * Mach ports are the endpoints to Mach-implemented communications | |
58 | * channels (usually uni-directional message queues, but other types | |
59 | * also exist). | |
60 | * | |
61 | * Unique collections of these endpoints are maintained for each | |
62 | * Mach task. Each Mach port in the task's collection is given a | |
63 | * [task-local] name to identify it - and the the various "rights" | |
64 | * held by the task for that specific endpoint. | |
65 | * | |
66 | * This header defines the types used to identify these Mach ports | |
67 | * and the various rights associated with them. For more info see: | |
68 | * | |
69 | * <mach/mach_port.h> - manipulation of port rights in a given space | |
70 | * <mach/message.h> - message queue [and port right passing] mechanism | |
71 | * | |
72 | */ | |
73 | ||
74 | #ifndef _MACH_PORT_H_ | |
75 | #define _MACH_PORT_H_ | |
76 | ||
77 | #include <stdint.h> | |
78 | #include <mach/boolean.h> | |
79 | #include <mach/machine/vm_types.h> | |
80 | ||
81 | /* | |
82 | * mach_port_name_t - the local identity for a Mach port | |
83 | * | |
84 | * The name is Mach port namespace specific. It is used to | |
85 | * identify the rights held for that port by the task whose | |
86 | * namespace is implied [or specifically provided]. | |
87 | * | |
88 | * Use of this type usually implies just a name - no rights. | |
89 | * See mach_port_t for a type that implies a "named right." | |
90 | * | |
91 | */ | |
92 | ||
93 | typedef natural_t mach_port_name_t; | |
94 | typedef mach_port_name_t *mach_port_name_array_t; | |
95 | ||
96 | #ifdef KERNEL | |
97 | ||
98 | /* | |
99 | * mach_port_t - a named port right | |
100 | * | |
101 | * In the kernel, "rights" are represented [named] by pointers to | |
102 | * the ipc port object in question. There is no port namespace for the | |
103 | * rights to be collected. | |
104 | * | |
105 | * Actually, there is namespace for the kernel task. But most kernel | |
106 | * code - including, but not limited to, Mach IPC code - lives in the | |
107 | * limbo between the current user-level task and the "next" task. Very | |
108 | * little of the kernel code runs in full kernel task context. So very | |
109 | * little of it gets to use the kernel task's port name space. | |
110 | * | |
111 | * Because of this implementation approach, all in-kernel rights for | |
112 | * a given port coalesce [have the same name/pointer]. The actual | |
113 | * references are counted in the port itself. It is up to the kernel | |
114 | * code in question to "just remember" how many [and what type of] | |
115 | * rights it holds and handle them appropriately. | |
116 | * | |
117 | */ | |
118 | ||
119 | #ifndef MACH_KERNEL_PRIVATE | |
120 | /* | |
121 | * For kernel code that resides outside of Mach proper, we opaque the | |
122 | * port structure definition. | |
123 | */ | |
124 | struct ipc_port ; | |
125 | ||
126 | #endif /* MACH_KERNEL_PRIVATE */ | |
127 | ||
128 | typedef struct ipc_port *ipc_port_t; | |
129 | ||
130 | #define IPC_PORT_NULL ((ipc_port_t) 0) | |
131 | #define IPC_PORT_DEAD ((ipc_port_t)~0) | |
132 | #define IPC_PORT_VALID(port) \ | |
133 | ((port) != IPC_PORT_NULL && (port) != IPC_PORT_DEAD) | |
134 | ||
135 | typedef ipc_port_t mach_port_t; | |
136 | ||
137 | #else /* KERNEL */ | |
138 | ||
139 | /* | |
140 | * mach_port_t - a named port right | |
141 | * | |
142 | * In user-space, "rights" are represented by the name of the | |
143 | * right in the Mach port namespace. Even so, this type is | |
144 | * presented as a unique one to more clearly denote the presence | |
145 | * of a right coming along with the name. | |
146 | * | |
147 | * Often, various rights for a port held in a single name space | |
148 | * will coalesce and are, therefore, be identified by a single name | |
149 | * [this is the case for send and receive rights]. But not | |
150 | * always [send-once rights currently get a unique name for | |
151 | * each right]. | |
152 | * | |
153 | */ | |
154 | ||
155 | #ifndef _MACH_PORT_T | |
156 | #define _MACH_PORT_T | |
157 | typedef mach_port_name_t mach_port_t; | |
158 | #endif | |
159 | ||
160 | #endif /* KERNEL */ | |
161 | ||
162 | typedef mach_port_t *mach_port_array_t; | |
163 | ||
164 | /* | |
165 | * MACH_PORT_NULL is a legal value that can be carried in messages. | |
166 | * It indicates the absence of any port or port rights. (A port | |
167 | * argument keeps the message from being "simple", even if the | |
168 | * value is MACH_PORT_NULL.) The value MACH_PORT_DEAD is also a legal | |
169 | * value that can be carried in messages. It indicates | |
170 | * that a port right was present, but it died. | |
171 | */ | |
172 | ||
173 | #define MACH_PORT_NULL 0 /* intentional loose typing */ | |
174 | #define MACH_PORT_DEAD ((mach_port_name_t) ~0) | |
175 | #define MACH_PORT_VALID(name) \ | |
176 | (((name) != MACH_PORT_NULL) && \ | |
177 | ((name) != MACH_PORT_DEAD)) | |
178 | ||
179 | ||
180 | /* | |
181 | * For kernel-selected [assigned] port names, the name is | |
182 | * comprised of two parts: a generation number and an index. | |
183 | * This approach keeps the exact same name from being generated | |
184 | * and reused too quickly [to catch right/reference counting bugs]. | |
185 | * The dividing line between the constituent parts is exposed so | |
186 | * that efficient "mach_port_name_t to data structure pointer" | |
187 | * conversion implementation can be made. But it is possible | |
188 | * for user-level code to assign their own names to Mach ports. | |
189 | * These are not required to participate in this algorithm. So | |
190 | * care should be taken before "assuming" this model. | |
191 | * | |
192 | */ | |
193 | ||
194 | #ifndef NO_PORT_GEN | |
195 | ||
196 | #define MACH_PORT_INDEX(name) ((name) >> 8) | |
197 | #define MACH_PORT_GEN(name) (((name) & 0xff) << 24) | |
198 | #define MACH_PORT_MAKE(index, gen) \ | |
199 | (((index) << 8) | (gen) >> 24) | |
200 | ||
201 | #else /* NO_PORT_GEN */ | |
202 | ||
203 | #define MACH_PORT_INDEX(name) (name) | |
204 | #define MACH_PORT_GEN(name) (0) | |
205 | #define MACH_PORT_MAKE(index, gen) (index) | |
206 | ||
207 | #endif /* NO_PORT_GEN */ | |
208 | ||
209 | ||
210 | /* | |
211 | * These are the different rights a task may have for a port. | |
212 | * The MACH_PORT_RIGHT_* definitions are used as arguments | |
213 | * to mach_port_allocate, mach_port_get_refs, etc, to specify | |
214 | * a particular right to act upon. The mach_port_names and | |
215 | * mach_port_type calls return bitmasks using the MACH_PORT_TYPE_* | |
216 | * definitions. This is because a single name may denote | |
217 | * multiple rights. | |
218 | */ | |
219 | ||
220 | typedef natural_t mach_port_right_t; | |
221 | ||
222 | #define MACH_PORT_RIGHT_SEND ((mach_port_right_t) 0) | |
223 | #define MACH_PORT_RIGHT_RECEIVE ((mach_port_right_t) 1) | |
224 | #define MACH_PORT_RIGHT_SEND_ONCE ((mach_port_right_t) 2) | |
225 | #define MACH_PORT_RIGHT_PORT_SET ((mach_port_right_t) 3) | |
226 | #define MACH_PORT_RIGHT_DEAD_NAME ((mach_port_right_t) 4) | |
227 | #define MACH_PORT_RIGHT_NUMBER ((mach_port_right_t) 5) | |
228 | ||
229 | typedef natural_t mach_port_type_t; | |
230 | typedef mach_port_type_t *mach_port_type_array_t; | |
231 | ||
232 | #define MACH_PORT_TYPE(right) \ | |
233 | ((mach_port_type_t)(((mach_port_type_t) 1) \ | |
234 | << ((right) + ((mach_port_right_t) 16)))) | |
235 | #define MACH_PORT_TYPE_NONE ((mach_port_type_t) 0L) | |
236 | #define MACH_PORT_TYPE_SEND MACH_PORT_TYPE(MACH_PORT_RIGHT_SEND) | |
237 | #define MACH_PORT_TYPE_RECEIVE MACH_PORT_TYPE(MACH_PORT_RIGHT_RECEIVE) | |
238 | #define MACH_PORT_TYPE_SEND_ONCE MACH_PORT_TYPE(MACH_PORT_RIGHT_SEND_ONCE) | |
239 | #define MACH_PORT_TYPE_PORT_SET MACH_PORT_TYPE(MACH_PORT_RIGHT_PORT_SET) | |
240 | #define MACH_PORT_TYPE_DEAD_NAME MACH_PORT_TYPE(MACH_PORT_RIGHT_DEAD_NAME) | |
241 | ||
242 | /* Convenient combinations. */ | |
243 | ||
244 | #define MACH_PORT_TYPE_SEND_RECEIVE \ | |
245 | (MACH_PORT_TYPE_SEND|MACH_PORT_TYPE_RECEIVE) | |
246 | #define MACH_PORT_TYPE_SEND_RIGHTS \ | |
247 | (MACH_PORT_TYPE_SEND|MACH_PORT_TYPE_SEND_ONCE) | |
248 | #define MACH_PORT_TYPE_PORT_RIGHTS \ | |
249 | (MACH_PORT_TYPE_SEND_RIGHTS|MACH_PORT_TYPE_RECEIVE) | |
250 | #define MACH_PORT_TYPE_PORT_OR_DEAD \ | |
251 | (MACH_PORT_TYPE_PORT_RIGHTS|MACH_PORT_TYPE_DEAD_NAME) | |
252 | #define MACH_PORT_TYPE_ALL_RIGHTS \ | |
253 | (MACH_PORT_TYPE_PORT_OR_DEAD|MACH_PORT_TYPE_PORT_SET) | |
254 | ||
255 | /* Dummy type bits that mach_port_type/mach_port_names can return. */ | |
256 | ||
257 | #define MACH_PORT_TYPE_DNREQUEST 0x80000000 | |
258 | ||
259 | /* User-references for capabilities. */ | |
260 | ||
261 | typedef natural_t mach_port_urefs_t; | |
262 | typedef integer_t mach_port_delta_t; /* change in urefs */ | |
263 | ||
264 | /* Attributes of ports. (See mach_port_get_receive_status.) */ | |
265 | ||
266 | typedef natural_t mach_port_seqno_t; /* sequence number */ | |
267 | typedef natural_t mach_port_mscount_t; /* make-send count */ | |
268 | typedef natural_t mach_port_msgcount_t; /* number of msgs */ | |
269 | typedef natural_t mach_port_rights_t; /* number of rights */ | |
270 | ||
271 | /* | |
272 | * Are there outstanding send rights for a given port? | |
273 | */ | |
274 | #define MACH_PORT_SRIGHTS_NONE 0 /* no srights */ | |
275 | #define MACH_PORT_SRIGHTS_PRESENT 1 /* srights */ | |
276 | typedef unsigned int mach_port_srights_t; /* status of send rights */ | |
277 | ||
278 | typedef struct mach_port_status { | |
279 | mach_port_name_t mps_pset; /* containing port set */ | |
280 | mach_port_seqno_t mps_seqno; /* sequence number */ | |
281 | mach_port_mscount_t mps_mscount; /* make-send count */ | |
282 | mach_port_msgcount_t mps_qlimit; /* queue limit */ | |
283 | mach_port_msgcount_t mps_msgcount; /* number in the queue */ | |
284 | mach_port_rights_t mps_sorights; /* how many send-once rights */ | |
285 | boolean_t mps_srights; /* do send rights exist? */ | |
286 | boolean_t mps_pdrequest; /* port-deleted requested? */ | |
287 | boolean_t mps_nsrequest; /* no-senders requested? */ | |
288 | natural_t mps_flags; /* port flags */ | |
289 | } mach_port_status_t; | |
290 | ||
291 | #define MACH_PORT_QLIMIT_DEFAULT ((mach_port_msgcount_t) 5) | |
292 | #define MACH_PORT_QLIMIT_MAX ((mach_port_msgcount_t) 16) | |
293 | ||
294 | typedef struct mach_port_limits { | |
295 | mach_port_msgcount_t mpl_qlimit; /* number of msgs */ | |
296 | } mach_port_limits_t; | |
297 | ||
298 | typedef integer_t *mach_port_info_t; /* varying array of natural_t */ | |
299 | ||
300 | /* Flavors for mach_port_get/set_attributes() */ | |
301 | typedef int mach_port_flavor_t; | |
302 | #define MACH_PORT_LIMITS_INFO 1 /* uses mach_port_status_t */ | |
303 | #define MACH_PORT_RECEIVE_STATUS 2 /* uses mach_port_limits_t */ | |
304 | #define MACH_PORT_DNREQUESTS_SIZE 3 /* info is int */ | |
305 | ||
306 | #define MACH_PORT_LIMITS_INFO_COUNT ((natural_t) \ | |
307 | (sizeof(mach_port_limits_t)/sizeof(natural_t))) | |
308 | #define MACH_PORT_RECEIVE_STATUS_COUNT ((natural_t) \ | |
309 | (sizeof(mach_port_status_t)/sizeof(natural_t))) | |
310 | #define MACH_PORT_DNREQUESTS_SIZE_COUNT 1 | |
311 | ||
312 | /* | |
313 | * Structure used to pass information about port allocation requests. | |
314 | * Must be padded to 64-bits total length. | |
315 | */ | |
316 | typedef struct mach_port_qos { | |
317 | boolean_t name:1; /* name given */ | |
318 | boolean_t prealloc:1; /* prealloced message */ | |
319 | boolean_t pad1:30; | |
320 | natural_t len; | |
321 | } mach_port_qos_t; | |
322 | ||
323 | #if !defined(_POSIX_C_SOURCE) && !defined(_NO_PORT_T_FROM_MACH) | |
324 | /* | |
325 | * Mach 3.0 renamed everything to have mach_ in front of it. | |
326 | * These types and macros are provided for backward compatibility | |
327 | * but are deprecated. | |
328 | */ | |
329 | typedef mach_port_t port_t; | |
330 | typedef mach_port_name_t port_name_t; | |
331 | typedef mach_port_name_t *port_name_array_t; | |
332 | ||
333 | #define PORT_NULL ((port_t) 0) | |
334 | #define PORT_DEAD ((port_t) ~0) | |
335 | #define PORT_VALID(name) \ | |
336 | ((port_t)(name) != PORT_NULL && (port_t)(name) != PORT_DEAD) | |
337 | ||
338 | #endif /* !_POSIX_C_SOURCE && !_NO_PORT_T_FROM_MACH */ | |
339 | ||
340 | #endif /* _MACH_PORT_H_ */ |