]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/ipc_space.h
xnu-344.49.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_space.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
32 *
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
38 *
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53 /*
54 */
55 /*
56 * File: ipc/ipc_space.h
57 * Author: Rich Draves
58 * Date: 1989
59 *
60 * Definitions for IPC spaces of capabilities.
61 */
62
63 #ifndef _IPC_IPC_SPACE_H_
64 #define _IPC_IPC_SPACE_H_
65
66
67 #include <mach/mach_types.h>
68 #include <mach/boolean.h>
69 #include <mach/kern_return.h>
70 #include <mach/vm_types.h>
71
72 #include <sys/appleapiopts.h>
73
74 #ifdef __APPLE_API_PRIVATE
75 #ifdef MACH_KERNEL_PRIVATE
76 #include <mach_kdb.h>
77 #include <kern/macro_help.h>
78 #include <kern/kern_types.h>
79 #include <kern/lock.h>
80 #include <kern/task.h>
81 #include <kern/zalloc.h>
82 #include <ipc/ipc_entry.h>
83 #include <ipc/ipc_splay.h>
84 #include <ipc/ipc_types.h>
85
86 /*
87 * Every task has a space of IPC capabilities.
88 * IPC operations like send and receive use this space.
89 * IPC kernel calls manipulate the space of the target task.
90 *
91 * Every space has a non-NULL is_table with is_table_size entries.
92 * A space may have a NULL is_tree. is_tree_small records the
93 * number of entries in the tree that, if the table were to grow
94 * to the next larger size, would move from the tree to the table.
95 *
96 * is_growing marks when the table is in the process of growing.
97 * When the table is growing, it can't be freed or grown by another
98 * thread, because of krealloc/kmem_realloc's requirements.
99 *
100 */
101
102 typedef natural_t ipc_space_refs_t;
103
104 struct ipc_space {
105 decl_mutex_data(,is_ref_lock_data)
106 ipc_space_refs_t is_references;
107
108 decl_mutex_data(,is_lock_data)
109 boolean_t is_active; /* is the space alive? */
110 boolean_t is_growing; /* is the space growing? */
111 ipc_entry_t is_table; /* an array of entries */
112 ipc_entry_num_t is_table_size; /* current size of table */
113 struct ipc_table_size *is_table_next; /* info for larger table */
114 struct ipc_splay_tree is_tree; /* a splay tree of entries */
115 ipc_entry_num_t is_tree_total; /* number of entries in the tree */
116 ipc_entry_num_t is_tree_small; /* # of small entries in the tree */
117 ipc_entry_num_t is_tree_hash; /* # of hashed entries in the tree */
118 boolean_t is_fast; /* for is_fast_space() */
119 };
120
121 #define IS_NULL ((ipc_space_t) 0)
122
123 extern zone_t ipc_space_zone;
124
125 #define is_alloc() ((ipc_space_t) zalloc(ipc_space_zone))
126 #define is_free(is) zfree(ipc_space_zone, (vm_offset_t) (is))
127
128 extern ipc_space_t ipc_space_kernel;
129 extern ipc_space_t ipc_space_reply;
130 #if DIPC
131 extern ipc_space_t ipc_space_remote;
132 #endif /* DIPC */
133 #if DIPC || MACH_KDB
134 extern ipc_space_t default_pager_space;
135 #endif /* DIPC || MACH_KDB */
136
137 #define is_fast_space(is) ((is)->is_fast)
138
139 #define is_ref_lock_init(is) mutex_init(&(is)->is_ref_lock_data, \
140 ETAP_IPC_IS_REF)
141
142 #define ipc_space_reference_macro(is) \
143 MACRO_BEGIN \
144 mutex_lock(&(is)->is_ref_lock_data); \
145 assert((is)->is_references > 0); \
146 (is)->is_references++; \
147 mutex_unlock(&(is)->is_ref_lock_data); \
148 MACRO_END
149
150 #define ipc_space_release_macro(is) \
151 MACRO_BEGIN \
152 ipc_space_refs_t _refs; \
153 \
154 mutex_lock(&(is)->is_ref_lock_data); \
155 assert((is)->is_references > 0); \
156 _refs = --(is)->is_references; \
157 mutex_unlock(&(is)->is_ref_lock_data); \
158 \
159 if (_refs == 0) \
160 is_free(is); \
161 MACRO_END
162
163 #define is_lock_init(is) mutex_init(&(is)->is_lock_data, ETAP_IPC_IS)
164
165 #define is_read_lock(is) mutex_lock(&(is)->is_lock_data)
166 #define is_read_unlock(is) mutex_unlock(&(is)->is_lock_data)
167 #define is_read_sleep(is) thread_sleep_mutex((event_t)(is), \
168 &(is)->is_lock_data, \
169 THREAD_UNINT)
170
171 #define is_write_lock(is) mutex_lock(&(is)->is_lock_data)
172 #define is_write_lock_try(is) mutex_try(&(is)->is_lock_data)
173 #define is_write_unlock(is) mutex_unlock(&(is)->is_lock_data)
174 #define is_write_sleep(is) thread_sleep_mutex((event_t)(is), \
175 &(is)->is_lock_data, \
176 THREAD_UNINT)
177
178 #define is_reference(is) ipc_space_reference(is)
179 #define is_release(is) ipc_space_release(is)
180
181 #define is_write_to_read_lock(is)
182
183 #define current_space_fast() (current_task_fast()->itk_space)
184 #define current_space() (current_space_fast())
185
186 /* Create a special IPC space */
187 extern kern_return_t ipc_space_create_special(
188 ipc_space_t *spacep);
189
190 /* Create new IPC space */
191 extern kern_return_t ipc_space_create(
192 ipc_table_size_t initial,
193 ipc_space_t *spacep);
194
195 /* Mark a space as dead and cleans up the entries*/
196 extern void ipc_space_destroy(
197 ipc_space_t space);
198
199 #endif /* MACH_KERNEL_PRIVATE */
200 #endif /* __APPLE_API_PRIVATE */
201
202 #ifdef __APPLE_API_UNSTABLE
203 #ifndef MACH_KERNEL_PRIVATE
204
205 extern ipc_space_t current_space(void);
206
207 #endif /* !MACH_KERNEL_PRIVATE */
208 #endif /* __APPLE_API_UNSTABLE */
209
210 /* Take a reference on a space */
211 extern void ipc_space_reference(
212 ipc_space_t space);
213
214 /* Realase a reference on a space */
215 extern void ipc_space_release(
216 ipc_space_t space);
217
218 #endif /* _IPC_IPC_SPACE_H_ */