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