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