]>
Commit | Line | Data |
---|---|---|
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 | * NOTICE: This file was modified by McAfee Research in 2004 to introduce | |
58 | * support for mandatory and extensible security protections. This notice | |
59 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
60 | * Version 2.0. | |
61 | */ | |
62 | /* | |
63 | */ | |
64 | /* | |
65 | * File: ipc/ipc_space.h | |
66 | * Author: Rich Draves | |
67 | * Date: 1989 | |
68 | * | |
69 | * Definitions for IPC spaces of capabilities. | |
70 | */ | |
71 | ||
72 | #ifndef _IPC_IPC_SPACE_H_ | |
73 | #define _IPC_IPC_SPACE_H_ | |
74 | ||
75 | ||
76 | #include <mach/mach_types.h> | |
77 | #include <mach/boolean.h> | |
78 | #include <mach/kern_return.h> | |
79 | #include <mach/vm_types.h> | |
80 | ||
81 | #include <sys/appleapiopts.h> | |
82 | ||
83 | #ifdef __APPLE_API_PRIVATE | |
84 | #if MACH_KERNEL_PRIVATE | |
85 | #include <mach_kdb.h> | |
86 | #include <kern/macro_help.h> | |
87 | #include <kern/kern_types.h> | |
88 | #include <kern/lock.h> | |
89 | #include <kern/task.h> | |
90 | #include <kern/zalloc.h> | |
91 | #include <ipc/ipc_entry.h> | |
92 | #include <ipc/ipc_splay.h> | |
93 | #include <ipc/ipc_types.h> | |
94 | ||
95 | /* | |
96 | * Every task has a space of IPC capabilities. | |
97 | * IPC operations like send and receive use this space. | |
98 | * IPC kernel calls manipulate the space of the target task. | |
99 | * | |
100 | * Every space has a non-NULL is_table with is_table_size entries. | |
101 | * A space may have a NULL is_tree. is_tree_small records the | |
102 | * number of entries in the tree that, if the table were to grow | |
103 | * to the next larger size, would move from the tree to the table. | |
104 | * | |
105 | * is_growing marks when the table is in the process of growing. | |
106 | * When the table is growing, it can't be freed or grown by another | |
107 | * thread, because of krealloc/kmem_realloc's requirements. | |
108 | * | |
109 | */ | |
110 | ||
111 | typedef natural_t ipc_space_refs_t; | |
112 | ||
113 | struct ipc_space { | |
114 | decl_lck_mtx_data(,is_ref_lock_data) | |
115 | ipc_space_refs_t is_references; | |
116 | ||
117 | decl_lck_mtx_data(,is_lock_data) | |
118 | boolean_t is_active; /* is the space alive? */ | |
119 | boolean_t is_growing; /* is the space growing? */ | |
120 | ipc_entry_t is_table; /* an array of entries */ | |
121 | ipc_entry_num_t is_table_size; /* current size of table */ | |
122 | struct ipc_table_size *is_table_next; /* info for larger table */ | |
123 | struct ipc_splay_tree is_tree; /* a splay tree of entries */ | |
124 | ipc_entry_num_t is_tree_total; /* number of entries in the tree */ | |
125 | ipc_entry_num_t is_tree_small; /* # of small entries in the tree */ | |
126 | ipc_entry_num_t is_tree_hash; /* # of hashed entries in the tree */ | |
127 | boolean_t is_fast; /* for is_fast_space() */ | |
128 | ||
129 | task_t is_task; /* associated task */ | |
130 | }; | |
131 | ||
132 | #define IS_NULL ((ipc_space_t) 0) | |
133 | ||
134 | extern zone_t ipc_space_zone; | |
135 | ||
136 | #define is_alloc() ((ipc_space_t) zalloc(ipc_space_zone)) | |
137 | #define is_free(is) zfree(ipc_space_zone, (is)) | |
138 | ||
139 | extern ipc_space_t ipc_space_kernel; | |
140 | extern ipc_space_t ipc_space_reply; | |
141 | #if DIPC | |
142 | extern ipc_space_t ipc_space_remote; | |
143 | #endif /* DIPC */ | |
144 | #if DIPC || MACH_KDB | |
145 | extern ipc_space_t default_pager_space; | |
146 | #endif /* DIPC || MACH_KDB */ | |
147 | ||
148 | #define is_fast_space(is) ((is)->is_fast) | |
149 | ||
150 | #define is_ref_lock_init(is) lck_mtx_init(&(is)->is_ref_lock_data, &ipc_lck_grp, &ipc_lck_attr) | |
151 | #define is_ref_lock_destroy(is) lck_mtx_destroy(&(is)->is_ref_lock_data, &ipc_lck_grp) | |
152 | ||
153 | #define ipc_space_reference_macro(is) \ | |
154 | MACRO_BEGIN \ | |
155 | lck_mtx_lock(&(is)->is_ref_lock_data); \ | |
156 | assert((is)->is_references > 0); \ | |
157 | (is)->is_references++; \ | |
158 | lck_mtx_unlock(&(is)->is_ref_lock_data); \ | |
159 | MACRO_END | |
160 | ||
161 | #define ipc_space_release_macro(is) \ | |
162 | MACRO_BEGIN \ | |
163 | ipc_space_refs_t _refs; \ | |
164 | \ | |
165 | lck_mtx_lock(&(is)->is_ref_lock_data); \ | |
166 | assert((is)->is_references > 0); \ | |
167 | _refs = --(is)->is_references; \ | |
168 | lck_mtx_unlock(&(is)->is_ref_lock_data); \ | |
169 | \ | |
170 | if (_refs == 0) { \ | |
171 | is_lock_destroy(is); \ | |
172 | is_ref_lock_destroy(is); \ | |
173 | is_free(is); \ | |
174 | } \ | |
175 | MACRO_END | |
176 | ||
177 | #define is_lock_init(is) lck_mtx_init(&(is)->is_lock_data, &ipc_lck_grp, &ipc_lck_attr) | |
178 | #define is_lock_destroy(is) lck_mtx_destroy(&(is)->is_lock_data, &ipc_lck_grp) | |
179 | ||
180 | #define is_read_lock(is) lck_mtx_lock(&(is)->is_lock_data) | |
181 | #define is_read_unlock(is) lck_mtx_unlock(&(is)->is_lock_data) | |
182 | #define is_read_sleep(is) lck_mtx_sleep(&(is)->is_lock_data, \ | |
183 | LCK_SLEEP_DEFAULT, \ | |
184 | (event_t)(is), \ | |
185 | THREAD_UNINT) | |
186 | ||
187 | #define is_write_lock(is) lck_mtx_lock(&(is)->is_lock_data) | |
188 | #define is_write_lock_try(is) lck_mtx_try_lock(&(is)->is_lock_data) | |
189 | #define is_write_unlock(is) lck_mtx_unlock(&(is)->is_lock_data) | |
190 | #define is_write_sleep(is) lck_mtx_sleep(&(is)->is_lock_data, \ | |
191 | LCK_SLEEP_DEFAULT, \ | |
192 | (event_t)(is), \ | |
193 | THREAD_UNINT) | |
194 | ||
195 | #define is_reference(is) ipc_space_reference(is) | |
196 | #define is_release(is) ipc_space_release(is) | |
197 | ||
198 | #define is_write_to_read_lock(is) | |
199 | ||
200 | #define current_space_fast() (current_task_fast()->itk_space) | |
201 | #define current_space() (current_space_fast()) | |
202 | ||
203 | /* Create a special IPC space */ | |
204 | extern kern_return_t ipc_space_create_special( | |
205 | ipc_space_t *spacep); | |
206 | ||
207 | /* Create new IPC space */ | |
208 | extern kern_return_t ipc_space_create( | |
209 | ipc_table_size_t initial, | |
210 | ipc_space_t *spacep); | |
211 | ||
212 | /* Mark a space as dead and cleans up the entries*/ | |
213 | extern void ipc_space_destroy( | |
214 | ipc_space_t space); | |
215 | ||
216 | /* Clean up the entries - but leave the space alive */ | |
217 | extern void ipc_space_clean( | |
218 | ipc_space_t space); | |
219 | ||
220 | #endif /* MACH_KERNEL_PRIVATE */ | |
221 | #endif /* __APPLE_API_PRIVATE */ | |
222 | ||
223 | #ifdef __APPLE_API_UNSTABLE | |
224 | #ifndef MACH_KERNEL_PRIVATE | |
225 | ||
226 | extern ipc_space_t current_space(void); | |
227 | ||
228 | #endif /* !MACH_KERNEL_PRIVATE */ | |
229 | #endif /* __APPLE_API_UNSTABLE */ | |
230 | ||
231 | /* Take a reference on a space */ | |
232 | extern void ipc_space_reference( | |
233 | ipc_space_t space); | |
234 | ||
235 | /* Realase a reference on a space */ | |
236 | extern void ipc_space_release( | |
237 | ipc_space_t space); | |
238 | ||
239 | #endif /* _IPC_IPC_SPACE_H_ */ |