]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/ipc_table.h
xnu-1456.1.26.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_table.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * @OSF_COPYRIGHT@
30 */
31 /*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
35 *
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.
41 *
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.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56 /*
57 */
58 /*
59 * File: ipc/ipc_table.h
60 * Author: Rich Draves
61 * Date: 1989
62 *
63 * Definitions for tables, used for IPC capabilities (ipc_entry_t)
64 * and dead-name requests (ipc_port_request_t).
65 */
66
67 #ifndef _IPC_IPC_TABLE_H_
68 #define _IPC_IPC_TABLE_H_
69
70 #include <mach/mach_types.h>
71 #include <mach/boolean.h>
72 #include <mach/vm_param.h>
73
74 #include <ipc/ipc_types.h>
75
76 /*
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.
80 *
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).
85 * This ensures that
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.
90 *
91 *
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.
98 *
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.
102 */
103
104 struct ipc_table_size {
105 ipc_table_elems_t its_size; /* number of elements in table */
106 };
107
108 extern ipc_table_size_t ipc_table_entries;
109 extern ipc_table_size_t ipc_table_dnrequests;
110
111 /* Initialize IPC capabilities table storage */
112 extern void ipc_table_init(void) __attribute__((section("__TEXT, initcode")));
113
114 /*
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.
118 *
119 * We can't use a copying realloc, because the realloc happens
120 * with the data unlocked. ipc_table_realloc remaps the data,
121 * so it is OK.
122 */
123
124 /* Allocate a table */
125 extern void * ipc_table_alloc(
126 vm_size_t size);
127
128 /* Reallocate a big table */
129 extern void * ipc_table_realloc(
130 vm_size_t old_size,
131 void * old_table,
132 vm_size_t new_size);
133
134 /* Free a table */
135 extern void ipc_table_free(
136 vm_size_t size,
137 void * table);
138
139 #define it_entries_reallocable(its) \
140 ((its)->its_size * sizeof(struct ipc_entry) >= PAGE_SIZE)
141
142 #define it_entries_alloc(its) \
143 ((ipc_entry_t) \
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) \
147 ))
148
149 #define it_entries_realloc(its, table, nits) \
150 ((ipc_entry_t) \
151 ipc_table_realloc( \
152 round_page((its)->its_size * sizeof(struct ipc_entry)), \
153 (void *)(table), \
154 round_page((nits)->its_size * sizeof(struct ipc_entry)) \
155 ))
156
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), \
161 (void *)(table) \
162 )
163
164 #define it_dnrequests_alloc(its) \
165 ((ipc_port_request_t) \
166 ipc_table_alloc((its)->its_size * \
167 sizeof(struct ipc_port_request)))
168
169 #define it_dnrequests_free(its, table) \
170 ipc_table_free((its)->its_size * \
171 sizeof(struct ipc_port_request), \
172 (void *)(table))
173
174 #endif /* _IPC_IPC_TABLE_H_ */