2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
59 * File: ipc/ipc_table.h
63 * Definitions for tables, used for IPC capabilities (ipc_entry_t)
64 * and dead-name requests (ipc_port_request_t).
67 #ifndef _IPC_IPC_TABLE_H_
68 #define _IPC_IPC_TABLE_H_
70 #include <mach/mach_types.h>
71 #include <mach/boolean.h>
72 #include <mach/vm_param.h>
74 #include <ipc/ipc_types.h>
77 * The is_table_next field of an ipc_space_t points to
78 * an ipc_table_size structure. These structures must
79 * be elements of an array, ipc_table_entries.
81 * The array must end with two elements with the same its_size value.
82 * Except for the terminating element, the its_size values must
83 * be strictly increasing. The largest (last) its_size value
84 * must be less than or equal to MACH_PORT_INDEX(MACH_PORT_DEAD).
86 * 1) MACH_PORT_INDEX(MACH_PORT_DEAD) isn't a valid index
87 * in the table, so ipc_entry_get won't allocate it.
88 * 2) MACH_PORT_MAKE(index+1, 0) and MAKE_PORT_MAKE(size, 0)
89 * won't ever overflow.
92 * The ipr_size field of the first element in a table of
93 * dead-name requests (ipc_port_request_t) points to the
94 * ipc_table_size structure. The structures must be elements
95 * of ipc_table_dnrequests. ipc_table_dnrequests must end
96 * with an element with zero its_size, and except for this last
97 * element, the its_size values must be strictly increasing.
99 * The is_table_next field points to the ipc_table_size structure
100 * for the next larger size of table, not the one currently in use.
101 * The ipr_size field points to the currently used ipc_table_size.
104 struct ipc_table_size
{
105 ipc_table_elems_t its_size
; /* number of elements in table */
108 extern ipc_table_size_t ipc_table_entries
;
109 extern ipc_table_size_t ipc_table_requests
;
111 /* Initialize IPC capabilities table storage */
112 extern void ipc_table_init(void) __attribute__((section("__TEXT, initcode")));
115 * Note that ipc_table_alloc, ipc_table_realloc, and ipc_table_free
116 * all potentially use the VM system. Hence simple locks can't
117 * be held across them.
119 * We can't use a copying realloc, because the realloc happens
120 * with the data unlocked. ipc_table_realloc remaps the data,
124 /* Allocate a table */
125 extern void * ipc_table_alloc(
128 /* Reallocate a big table */
129 extern void * ipc_table_realloc(
135 extern void ipc_table_free(
139 #define it_entries_reallocable(its) \
140 ((its)->its_size * sizeof(struct ipc_entry) >= PAGE_SIZE)
142 #define it_entries_alloc(its) \
144 ipc_table_alloc(it_entries_reallocable(its) ? \
145 round_page((its)->its_size * sizeof(struct ipc_entry)) : \
146 (its)->its_size * sizeof(struct ipc_entry) \
149 #define it_entries_realloc(its, table, nits) \
152 round_page((its)->its_size * sizeof(struct ipc_entry)), \
154 round_page((nits)->its_size * sizeof(struct ipc_entry)) \
157 #define it_entries_free(its, table) \
158 ipc_table_free(it_entries_reallocable(its) ? \
159 round_page((its)->its_size * sizeof(struct ipc_entry)) : \
160 (its)->its_size * sizeof(struct ipc_entry), \
164 #define it_requests_alloc(its) \
165 ((ipc_port_request_t) \
166 ipc_table_alloc((its)->its_size * \
167 sizeof(struct ipc_port_request)))
169 #define it_requests_free(its, table) \
170 ipc_table_free((its)->its_size * \
171 sizeof(struct ipc_port_request), \
174 #endif /* _IPC_IPC_TABLE_H_ */