]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
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. | |
de355530 | 11 | * |
37839358 A |
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 | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
1c79356b A |
25 | /* |
26 | * Mach Operating System | |
27 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
28 | * All Rights Reserved. | |
29 | * | |
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. | |
35 | * | |
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. | |
39 | * | |
40 | * Carnegie Mellon requests users of this software to return to | |
41 | * | |
42 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
43 | * School of Computer Science | |
44 | * Carnegie Mellon University | |
45 | * Pittsburgh PA 15213-3890 | |
46 | * | |
47 | * any improvements or extensions that they make and grant Carnegie Mellon | |
48 | * the rights to redistribute these changes. | |
49 | */ | |
50 | /* | |
51 | */ | |
52 | /* | |
53 | * File: ipc/ipc_table.h | |
54 | * Author: Rich Draves | |
55 | * Date: 1989 | |
56 | * | |
57 | * Definitions for tables, used for IPC capabilities (ipc_entry_t) | |
58 | * and dead-name requests (ipc_port_request_t). | |
59 | */ | |
60 | ||
61 | #ifndef _IPC_IPC_TABLE_H_ | |
62 | #define _IPC_IPC_TABLE_H_ | |
63 | ||
91447636 | 64 | #include <mach/mach_types.h> |
1c79356b A |
65 | #include <mach/boolean.h> |
66 | #include <mach/vm_param.h> | |
67 | ||
91447636 A |
68 | #include <ipc/ipc_types.h> |
69 | ||
1c79356b A |
70 | /* |
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. | |
74 | * | |
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). | |
79 | * This ensures that | |
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. | |
84 | * | |
85 | * | |
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. | |
92 | * | |
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. | |
96 | */ | |
97 | ||
91447636 | 98 | struct ipc_table_size { |
1c79356b | 99 | ipc_table_elems_t its_size; /* number of elements in table */ |
91447636 | 100 | }; |
1c79356b A |
101 | |
102 | extern ipc_table_size_t ipc_table_entries; | |
103 | extern ipc_table_size_t ipc_table_dnrequests; | |
104 | ||
105 | /* Initialize IPC capabilities table storage */ | |
106 | extern void ipc_table_init(void); | |
107 | ||
108 | /* | |
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. | |
112 | * | |
113 | * We can't use a copying realloc, because the realloc happens | |
114 | * with the data unlocked. ipc_table_realloc remaps the data, | |
115 | * so it is OK. | |
116 | */ | |
117 | ||
118 | /* Allocate a table */ | |
91447636 | 119 | extern void * ipc_table_alloc( |
1c79356b A |
120 | vm_size_t size); |
121 | ||
122 | /* Reallocate a big table */ | |
91447636 | 123 | extern void * ipc_table_realloc( |
1c79356b | 124 | vm_size_t old_size, |
91447636 | 125 | void * old_table, |
1c79356b A |
126 | vm_size_t new_size); |
127 | ||
128 | /* Free a table */ | |
129 | extern void ipc_table_free( | |
130 | vm_size_t size, | |
91447636 | 131 | void * table); |
1c79356b | 132 | |
765c9de3 A |
133 | #define it_entries_reallocable(its) \ |
134 | ((its)->its_size * sizeof(struct ipc_entry) >= PAGE_SIZE) | |
135 | ||
1c79356b A |
136 | #define it_entries_alloc(its) \ |
137 | ((ipc_entry_t) \ | |
765c9de3 | 138 | ipc_table_alloc(it_entries_reallocable(its) ? \ |
91447636 | 139 | round_page((its)->its_size * sizeof(struct ipc_entry)) : \ |
765c9de3 A |
140 | (its)->its_size * sizeof(struct ipc_entry) \ |
141 | )) | |
1c79356b A |
142 | |
143 | #define it_entries_realloc(its, table, nits) \ | |
144 | ((ipc_entry_t) \ | |
145 | ipc_table_realloc( \ | |
91447636 A |
146 | round_page((its)->its_size * sizeof(struct ipc_entry)), \ |
147 | (void *)(table), \ | |
148 | round_page((nits)->its_size * sizeof(struct ipc_entry)) \ | |
1c79356b A |
149 | )) |
150 | ||
151 | #define it_entries_free(its, table) \ | |
765c9de3 | 152 | ipc_table_free(it_entries_reallocable(its) ? \ |
91447636 | 153 | round_page((its)->its_size * sizeof(struct ipc_entry)) : \ |
765c9de3 | 154 | (its)->its_size * sizeof(struct ipc_entry), \ |
91447636 | 155 | (void *)(table) \ |
1c79356b A |
156 | ) |
157 | ||
158 | #define it_dnrequests_alloc(its) \ | |
159 | ((ipc_port_request_t) \ | |
160 | ipc_table_alloc((its)->its_size * \ | |
161 | sizeof(struct ipc_port_request))) | |
162 | ||
163 | #define it_dnrequests_free(its, table) \ | |
164 | ipc_table_free((its)->its_size * \ | |
165 | sizeof(struct ipc_port_request), \ | |
91447636 | 166 | (void *)(table)) |
1c79356b A |
167 | |
168 | #endif /* _IPC_IPC_TABLE_H_ */ |