2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
28 * Revision 1.1.1.1 1998/09/22 21:05:28 wsanchez
29 * Import of Mac OS X kernel (~semeria)
31 * Revision 1.2 1998/05/29 23:50:33 youngwor
32 * Added infrastructure for shared port space support
34 * Revision 1.1.1.1 1998/03/07 02:26:16 wsanchez
35 * Import of OSF Mach kernel (~mburg)
37 * Revision 1.1.8.3 1995/01/06 19:46:05 devrcs
38 * mk6 CR668 - 1.3b26 merge
40 * [1994/10/14 03:41:41 dwm]
42 * Revision 1.1.8.2 1994/09/23 02:12:26 ezf
43 * change marker to not FREE
44 * [1994/09/22 21:30:53 ezf]
46 * Revision 1.1.8.1 1994/08/18 23:11:45 widyono
47 * RT IPC from RT2_SHARED
48 * [1994/08/18 15:49:24 widyono]
50 * Revision 1.1.6.1 1994/07/29 07:33:22 widyono
51 * Define default target size, ITS_SIZE_NONE
52 * [1994/07/28 22:27:01 widyono]
54 * Revision 1.1.2.4 1993/07/22 16:17:33 rod
55 * Add ANSI prototypes. CR #9523.
56 * [1993/07/22 13:33:33 rod]
58 * Revision 1.1.2.3 1993/06/07 22:11:46 jeffc
59 * CR9176 - ANSI C violations: trailing tokens on CPP
60 * directives, extra semicolons after decl_ ..., asm keywords
61 * [1993/06/07 19:02:58 jeffc]
63 * Revision 1.1.2.2 1993/06/02 23:34:02 jeffc
64 * Added to OSF/1 R1.3 from NMK15.0.
65 * [1993/06/02 21:11:17 jeffc]
67 * Revision 1.1 1992/09/30 02:29:14 robert
74 * Revision 2.5 91/05/14 16:37:52 mrt
75 * Correcting copyright
77 * Revision 2.4 91/03/16 14:49:01 rpd
78 * Added ipc_table_realloc.
81 * Revision 2.3 91/02/05 17:24:19 mrt
82 * Changed to new Mach copyright
83 * [91/02/01 15:52:19 mrt]
85 * Revision 2.2 90/06/02 14:52:02 rpd
86 * Created for new IPC.
87 * [90/03/26 21:04:35 rpd]
92 * Mach Operating System
93 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
94 * All Rights Reserved.
96 * Permission to use, copy, modify and distribute this software and its
97 * documentation is hereby granted, provided that both the copyright
98 * notice and this permission notice appear in all copies of the
99 * software, derivative works or modified versions, and any portions
100 * thereof, and that both notices appear in supporting documentation.
102 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
103 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
104 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
106 * Carnegie Mellon requests users of this software to return to
108 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
109 * School of Computer Science
110 * Carnegie Mellon University
111 * Pittsburgh PA 15213-3890
113 * any improvements or extensions that they make and grant Carnegie Mellon
114 * the rights to redistribute these changes.
119 * File: ipc/ipc_table.h
120 * Author: Rich Draves
123 * Definitions for tables, used for IPC capabilities (ipc_entry_t)
124 * and dead-name requests (ipc_port_request_t).
127 #ifndef _IPC_IPC_TABLE_H_
128 #define _IPC_IPC_TABLE_H_
130 #include <mach/boolean.h>
131 #include <mach/vm_param.h>
134 * The is_table_next field of an ipc_space_t points to
135 * an ipc_table_size structure. These structures must
136 * be elements of an array, ipc_table_entries.
138 * The array must end with two elements with the same its_size value.
139 * Except for the terminating element, the its_size values must
140 * be strictly increasing. The largest (last) its_size value
141 * must be less than or equal to MACH_PORT_INDEX(MACH_PORT_DEAD).
143 * 1) MACH_PORT_INDEX(MACH_PORT_DEAD) isn't a valid index
144 * in the table, so ipc_entry_get won't allocate it.
145 * 2) MACH_PORT_MAKE(index+1, 0) and MAKE_PORT_MAKE(size, 0)
146 * won't ever overflow.
149 * The ipr_size field of the first element in a table of
150 * dead-name requests (ipc_port_request_t) points to the
151 * ipc_table_size structure. The structures must be elements
152 * of ipc_table_dnrequests. ipc_table_dnrequests must end
153 * with an element with zero its_size, and except for this last
154 * element, the its_size values must be strictly increasing.
156 * The is_table_next field points to the ipc_table_size structure
157 * for the next larger size of table, not the one currently in use.
158 * The ipr_size field points to the currently used ipc_table_size.
161 typedef natural_t ipc_table_index_t
; /* index into tables */
162 typedef natural_t ipc_table_elems_t
; /* size of tables */
164 typedef struct ipc_table_size
{
165 ipc_table_elems_t its_size
; /* number of elements in table */
168 #define ITS_NULL ((ipc_table_size_t) 0)
169 #define ITS_SIZE_NONE -1
171 extern ipc_table_size_t ipc_table_entries
;
172 extern ipc_table_size_t ipc_table_dnrequests
;
174 /* Initialize IPC capabilities table storage */
175 extern void ipc_table_init(void);
178 * Note that ipc_table_alloc, ipc_table_realloc, and ipc_table_free
179 * all potentially use the VM system. Hence simple locks can't
180 * be held across them.
182 * We can't use a copying realloc, because the realloc happens
183 * with the data unlocked. ipc_table_realloc remaps the data,
187 /* Allocate a table */
188 extern vm_offset_t
ipc_table_alloc(
191 /* Reallocate a big table */
192 extern vm_offset_t
ipc_table_realloc(
194 vm_offset_t old_table
,
198 extern void ipc_table_free(
202 #define it_entries_reallocable(its) \
203 ((its)->its_size * sizeof(struct ipc_entry) >= PAGE_SIZE)
205 #define it_entries_alloc(its) \
207 ipc_table_alloc(it_entries_reallocable(its) ? \
208 round_page((its)->its_size * sizeof(struct ipc_entry)) : \
209 (its)->its_size * sizeof(struct ipc_entry) \
212 #define it_entries_realloc(its, table, nits) \
215 round_page((its)->its_size * sizeof(struct ipc_entry)), \
216 (vm_offset_t)(table), \
217 round_page((nits)->its_size * sizeof(struct ipc_entry)) \
220 #define it_entries_free(its, table) \
221 ipc_table_free(it_entries_reallocable(its) ? \
222 round_page((its)->its_size * sizeof(struct ipc_entry)) : \
223 (its)->its_size * sizeof(struct ipc_entry), \
224 (vm_offset_t)(table) \
227 #define it_dnrequests_alloc(its) \
228 ((ipc_port_request_t) \
229 ipc_table_alloc((its)->its_size * \
230 sizeof(struct ipc_port_request)))
232 #define it_dnrequests_free(its, table) \
233 ipc_table_free((its)->its_size * \
234 sizeof(struct ipc_port_request), \
235 (vm_offset_t)(table))
237 #endif /* _IPC_IPC_TABLE_H_ */