2 * Copyright (c) 2000-2004 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@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 * File: ipc/ipc_table.h
57 * Definitions for tables, used for IPC capabilities (ipc_entry_t)
58 * and dead-name requests (ipc_port_request_t).
61 #ifndef _IPC_IPC_TABLE_H_
62 #define _IPC_IPC_TABLE_H_
64 #include <mach/mach_types.h>
65 #include <mach/boolean.h>
66 #include <mach/vm_param.h>
68 #include <ipc/ipc_types.h>
71 * The is_table_next field of an ipc_space_t points to
72 * an ipc_table_size structure. These structures must
73 * be elements of an array, ipc_table_entries.
75 * The array must end with two elements with the same its_size value.
76 * Except for the terminating element, the its_size values must
77 * be strictly increasing. The largest (last) its_size value
78 * must be less than or equal to MACH_PORT_INDEX(MACH_PORT_DEAD).
80 * 1) MACH_PORT_INDEX(MACH_PORT_DEAD) isn't a valid index
81 * in the table, so ipc_entry_get won't allocate it.
82 * 2) MACH_PORT_MAKE(index+1, 0) and MAKE_PORT_MAKE(size, 0)
83 * won't ever overflow.
86 * The ipr_size field of the first element in a table of
87 * dead-name requests (ipc_port_request_t) points to the
88 * ipc_table_size structure. The structures must be elements
89 * of ipc_table_dnrequests. ipc_table_dnrequests must end
90 * with an element with zero its_size, and except for this last
91 * element, the its_size values must be strictly increasing.
93 * The is_table_next field points to the ipc_table_size structure
94 * for the next larger size of table, not the one currently in use.
95 * The ipr_size field points to the currently used ipc_table_size.
98 struct ipc_table_size
{
99 ipc_table_elems_t its_size
; /* number of elements in table */
102 extern ipc_table_size_t ipc_table_entries
;
103 extern ipc_table_size_t ipc_table_dnrequests
;
105 /* Initialize IPC capabilities table storage */
106 extern void ipc_table_init(void);
109 * Note that ipc_table_alloc, ipc_table_realloc, and ipc_table_free
110 * all potentially use the VM system. Hence simple locks can't
111 * be held across them.
113 * We can't use a copying realloc, because the realloc happens
114 * with the data unlocked. ipc_table_realloc remaps the data,
118 /* Allocate a table */
119 extern void * ipc_table_alloc(
122 /* Reallocate a big table */
123 extern void * ipc_table_realloc(
129 extern void ipc_table_free(
133 #define it_entries_reallocable(its) \
134 ((its)->its_size * sizeof(struct ipc_entry) >= PAGE_SIZE)
136 #define it_entries_alloc(its) \
138 ipc_table_alloc(it_entries_reallocable(its) ? \
139 round_page((its)->its_size * sizeof(struct ipc_entry)) : \
140 (its)->its_size * sizeof(struct ipc_entry) \
143 #define it_entries_realloc(its, table, nits) \
146 round_page((its)->its_size * sizeof(struct ipc_entry)), \
148 round_page((nits)->its_size * sizeof(struct ipc_entry)) \
151 #define it_entries_free(its, table) \
152 ipc_table_free(it_entries_reallocable(its) ? \
153 round_page((its)->its_size * sizeof(struct ipc_entry)) : \
154 (its)->its_size * sizeof(struct ipc_entry), \
158 #define it_dnrequests_alloc(its) \
159 ((ipc_port_request_t) \
160 ipc_table_alloc((its)->its_size * \
161 sizeof(struct ipc_port_request)))
163 #define it_dnrequests_free(its, table) \
164 ipc_table_free((its)->its_size * \
165 sizeof(struct ipc_port_request), \
168 #endif /* _IPC_IPC_TABLE_H_ */