]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ipc/ipc_table.h
xnu-344.49.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_table.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
de355530 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * @OSF_COPYRIGHT@
27 */
28/*
29 * HISTORY
30 *
31 * Revision 1.1.1.1 1998/09/22 21:05:28 wsanchez
32 * Import of Mac OS X kernel (~semeria)
33 *
34 * Revision 1.2 1998/05/29 23:50:33 youngwor
35 * Added infrastructure for shared port space support
36 *
37 * Revision 1.1.1.1 1998/03/07 02:26:16 wsanchez
38 * Import of OSF Mach kernel (~mburg)
39 *
40 * Revision 1.1.8.3 1995/01/06 19:46:05 devrcs
41 * mk6 CR668 - 1.3b26 merge
42 * 64bit cleanup
43 * [1994/10/14 03:41:41 dwm]
44 *
45 * Revision 1.1.8.2 1994/09/23 02:12:26 ezf
46 * change marker to not FREE
47 * [1994/09/22 21:30:53 ezf]
48 *
49 * Revision 1.1.8.1 1994/08/18 23:11:45 widyono
50 * RT IPC from RT2_SHARED
51 * [1994/08/18 15:49:24 widyono]
52 *
53 * Revision 1.1.6.1 1994/07/29 07:33:22 widyono
54 * Define default target size, ITS_SIZE_NONE
55 * [1994/07/28 22:27:01 widyono]
56 *
57 * Revision 1.1.2.4 1993/07/22 16:17:33 rod
58 * Add ANSI prototypes. CR #9523.
59 * [1993/07/22 13:33:33 rod]
60 *
61 * Revision 1.1.2.3 1993/06/07 22:11:46 jeffc
62 * CR9176 - ANSI C violations: trailing tokens on CPP
63 * directives, extra semicolons after decl_ ..., asm keywords
64 * [1993/06/07 19:02:58 jeffc]
65 *
66 * Revision 1.1.2.2 1993/06/02 23:34:02 jeffc
67 * Added to OSF/1 R1.3 from NMK15.0.
68 * [1993/06/02 21:11:17 jeffc]
69 *
70 * Revision 1.1 1992/09/30 02:29:14 robert
71 * Initial revision
72 *
73 * $EndLog$
74 */
75/* CMU_HIST */
76/*
77 * Revision 2.5 91/05/14 16:37:52 mrt
78 * Correcting copyright
79 *
80 * Revision 2.4 91/03/16 14:49:01 rpd
81 * Added ipc_table_realloc.
82 * [91/03/04 rpd]
83 *
84 * Revision 2.3 91/02/05 17:24:19 mrt
85 * Changed to new Mach copyright
86 * [91/02/01 15:52:19 mrt]
87 *
88 * Revision 2.2 90/06/02 14:52:02 rpd
89 * Created for new IPC.
90 * [90/03/26 21:04:35 rpd]
91 *
92 */
93/* CMU_ENDHIST */
94/*
95 * Mach Operating System
96 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
97 * All Rights Reserved.
98 *
99 * Permission to use, copy, modify and distribute this software and its
100 * documentation is hereby granted, provided that both the copyright
101 * notice and this permission notice appear in all copies of the
102 * software, derivative works or modified versions, and any portions
103 * thereof, and that both notices appear in supporting documentation.
104 *
105 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
106 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
107 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
108 *
109 * Carnegie Mellon requests users of this software to return to
110 *
111 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
112 * School of Computer Science
113 * Carnegie Mellon University
114 * Pittsburgh PA 15213-3890
115 *
116 * any improvements or extensions that they make and grant Carnegie Mellon
117 * the rights to redistribute these changes.
118 */
119/*
120 */
121/*
122 * File: ipc/ipc_table.h
123 * Author: Rich Draves
124 * Date: 1989
125 *
126 * Definitions for tables, used for IPC capabilities (ipc_entry_t)
127 * and dead-name requests (ipc_port_request_t).
128 */
129
130#ifndef _IPC_IPC_TABLE_H_
131#define _IPC_IPC_TABLE_H_
132
133#include <mach/boolean.h>
134#include <mach/vm_param.h>
135
136/*
137 * The is_table_next field of an ipc_space_t points to
138 * an ipc_table_size structure. These structures must
139 * be elements of an array, ipc_table_entries.
140 *
141 * The array must end with two elements with the same its_size value.
142 * Except for the terminating element, the its_size values must
143 * be strictly increasing. The largest (last) its_size value
144 * must be less than or equal to MACH_PORT_INDEX(MACH_PORT_DEAD).
145 * This ensures that
146 * 1) MACH_PORT_INDEX(MACH_PORT_DEAD) isn't a valid index
147 * in the table, so ipc_entry_get won't allocate it.
148 * 2) MACH_PORT_MAKE(index+1, 0) and MAKE_PORT_MAKE(size, 0)
149 * won't ever overflow.
150 *
151 *
152 * The ipr_size field of the first element in a table of
153 * dead-name requests (ipc_port_request_t) points to the
154 * ipc_table_size structure. The structures must be elements
155 * of ipc_table_dnrequests. ipc_table_dnrequests must end
156 * with an element with zero its_size, and except for this last
157 * element, the its_size values must be strictly increasing.
158 *
159 * The is_table_next field points to the ipc_table_size structure
160 * for the next larger size of table, not the one currently in use.
161 * The ipr_size field points to the currently used ipc_table_size.
162 */
163
164typedef natural_t ipc_table_index_t; /* index into tables */
165typedef natural_t ipc_table_elems_t; /* size of tables */
166
167typedef struct ipc_table_size {
168 ipc_table_elems_t its_size; /* number of elements in table */
169} *ipc_table_size_t;
170
171#define ITS_NULL ((ipc_table_size_t) 0)
172#define ITS_SIZE_NONE -1
173
174extern ipc_table_size_t ipc_table_entries;
175extern ipc_table_size_t ipc_table_dnrequests;
176
177/* Initialize IPC capabilities table storage */
178extern void ipc_table_init(void);
179
180/*
181 * Note that ipc_table_alloc, ipc_table_realloc, and ipc_table_free
182 * all potentially use the VM system. Hence simple locks can't
183 * be held across them.
184 *
185 * We can't use a copying realloc, because the realloc happens
186 * with the data unlocked. ipc_table_realloc remaps the data,
187 * so it is OK.
188 */
189
190/* Allocate a table */
191extern vm_offset_t ipc_table_alloc(
192 vm_size_t size);
193
194/* Reallocate a big table */
195extern vm_offset_t ipc_table_realloc(
196 vm_size_t old_size,
197 vm_offset_t old_table,
198 vm_size_t new_size);
199
200/* Free a table */
201extern void ipc_table_free(
202 vm_size_t size,
203 vm_offset_t table);
204
765c9de3
A
205#define it_entries_reallocable(its) \
206 ((its)->its_size * sizeof(struct ipc_entry) >= PAGE_SIZE)
207
1c79356b
A
208#define it_entries_alloc(its) \
209 ((ipc_entry_t) \
765c9de3 210 ipc_table_alloc(it_entries_reallocable(its) ? \
de355530 211 round_page((its)->its_size * sizeof(struct ipc_entry)) : \
765c9de3
A
212 (its)->its_size * sizeof(struct ipc_entry) \
213 ))
1c79356b
A
214
215#define it_entries_realloc(its, table, nits) \
216 ((ipc_entry_t) \
217 ipc_table_realloc( \
de355530 218 round_page((its)->its_size * sizeof(struct ipc_entry)), \
1c79356b 219 (vm_offset_t)(table), \
de355530 220 round_page((nits)->its_size * sizeof(struct ipc_entry)) \
1c79356b
A
221 ))
222
223#define it_entries_free(its, table) \
765c9de3 224 ipc_table_free(it_entries_reallocable(its) ? \
de355530 225 round_page((its)->its_size * sizeof(struct ipc_entry)) : \
765c9de3 226 (its)->its_size * sizeof(struct ipc_entry), \
1c79356b
A
227 (vm_offset_t)(table) \
228 )
229
230#define it_dnrequests_alloc(its) \
231 ((ipc_port_request_t) \
232 ipc_table_alloc((its)->its_size * \
233 sizeof(struct ipc_port_request)))
234
235#define it_dnrequests_free(its, table) \
236 ipc_table_free((its)->its_size * \
237 sizeof(struct ipc_port_request), \
238 (vm_offset_t)(table))
239
240#endif /* _IPC_IPC_TABLE_H_ */