]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ipc/ipc_space.h
xnu-792.10.96.tar.gz
[apple/xnu.git] / osfmk / ipc / ipc_space.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
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_space.h
54 * Author: Rich Draves
55 * Date: 1989
56 *
57 * Definitions for IPC spaces of capabilities.
58 */
59
60 #ifndef _IPC_IPC_SPACE_H_
61 #define _IPC_IPC_SPACE_H_
62
63
64 #include <mach/mach_types.h>
65 #include <mach/boolean.h>
66 #include <mach/kern_return.h>
67 #include <mach/vm_types.h>
68
69 #include <sys/appleapiopts.h>
70
71 #ifdef __APPLE_API_PRIVATE
72 #ifdef MACH_KERNEL_PRIVATE
73 #include <mach_kdb.h>
74 #include <kern/macro_help.h>
75 #include <kern/kern_types.h>
76 #include <kern/lock.h>
77 #include <kern/task.h>
78 #include <kern/zalloc.h>
79 #include <ipc/ipc_entry.h>
80 #include <ipc/ipc_splay.h>
81 #include <ipc/ipc_types.h>
82
83 /*
84 * Every task has a space of IPC capabilities.
85 * IPC operations like send and receive use this space.
86 * IPC kernel calls manipulate the space of the target task.
87 *
88 * Every space has a non-NULL is_table with is_table_size entries.
89 * A space may have a NULL is_tree. is_tree_small records the
90 * number of entries in the tree that, if the table were to grow
91 * to the next larger size, would move from the tree to the table.
92 *
93 * is_growing marks when the table is in the process of growing.
94 * When the table is growing, it can't be freed or grown by another
95 * thread, because of krealloc/kmem_realloc's requirements.
96 *
97 */
98
99 typedef natural_t ipc_space_refs_t;
100
101 struct ipc_space {
102 decl_mutex_data(,is_ref_lock_data)
103 ipc_space_refs_t is_references;
104
105 decl_mutex_data(,is_lock_data)
106 boolean_t is_active; /* is the space alive? */
107 boolean_t is_growing; /* is the space growing? */
108 ipc_entry_t is_table; /* an array of entries */
109 ipc_entry_num_t is_table_size; /* current size of table */
110 struct ipc_table_size *is_table_next; /* info for larger table */
111 struct ipc_splay_tree is_tree; /* a splay tree of entries */
112 ipc_entry_num_t is_tree_total; /* number of entries in the tree */
113 ipc_entry_num_t is_tree_small; /* # of small entries in the tree */
114 ipc_entry_num_t is_tree_hash; /* # of hashed entries in the tree */
115 boolean_t is_fast; /* for is_fast_space() */
116 };
117
118 #define IS_NULL ((ipc_space_t) 0)
119
120 extern zone_t ipc_space_zone;
121
122 #define is_alloc() ((ipc_space_t) zalloc(ipc_space_zone))
123 #define is_free(is) zfree(ipc_space_zone, (is))
124
125 extern ipc_space_t ipc_space_kernel;
126 extern ipc_space_t ipc_space_reply;
127 #if DIPC
128 extern ipc_space_t ipc_space_remote;
129 #endif /* DIPC */
130 #if DIPC || MACH_KDB
131 extern ipc_space_t default_pager_space;
132 #endif /* DIPC || MACH_KDB */
133
134 #define is_fast_space(is) ((is)->is_fast)
135
136 #define is_ref_lock_init(is) mutex_init(&(is)->is_ref_lock_data, 0)
137
138 #define ipc_space_reference_macro(is) \
139 MACRO_BEGIN \
140 mutex_lock(&(is)->is_ref_lock_data); \
141 assert((is)->is_references > 0); \
142 (is)->is_references++; \
143 mutex_unlock(&(is)->is_ref_lock_data); \
144 MACRO_END
145
146 #define ipc_space_release_macro(is) \
147 MACRO_BEGIN \
148 ipc_space_refs_t _refs; \
149 \
150 mutex_lock(&(is)->is_ref_lock_data); \
151 assert((is)->is_references > 0); \
152 _refs = --(is)->is_references; \
153 mutex_unlock(&(is)->is_ref_lock_data); \
154 \
155 if (_refs == 0) \
156 is_free(is); \
157 MACRO_END
158
159 #define is_lock_init(is) mutex_init(&(is)->is_lock_data, 0)
160
161 #define is_read_lock(is) mutex_lock(&(is)->is_lock_data)
162 #define is_read_unlock(is) mutex_unlock(&(is)->is_lock_data)
163 #define is_read_sleep(is) thread_sleep_mutex((event_t)(is), \
164 &(is)->is_lock_data, \
165 THREAD_UNINT)
166
167 #define is_write_lock(is) mutex_lock(&(is)->is_lock_data)
168 #define is_write_lock_try(is) mutex_try(&(is)->is_lock_data)
169 #define is_write_unlock(is) mutex_unlock(&(is)->is_lock_data)
170 #define is_write_sleep(is) thread_sleep_mutex((event_t)(is), \
171 &(is)->is_lock_data, \
172 THREAD_UNINT)
173
174 #define is_reference(is) ipc_space_reference(is)
175 #define is_release(is) ipc_space_release(is)
176
177 #define is_write_to_read_lock(is)
178
179 #define current_space_fast() (current_task_fast()->itk_space)
180 #define current_space() (current_space_fast())
181
182 /* Create a special IPC space */
183 extern kern_return_t ipc_space_create_special(
184 ipc_space_t *spacep);
185
186 /* Create new IPC space */
187 extern kern_return_t ipc_space_create(
188 ipc_table_size_t initial,
189 ipc_space_t *spacep);
190
191 /* Mark a space as dead and cleans up the entries*/
192 extern void ipc_space_destroy(
193 ipc_space_t space);
194
195 /* Clean up the entries - but leave the space alive */
196 extern void ipc_space_clean(
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_ */