2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
54 * File: ipc/ipc_space.h
58 * Definitions for IPC spaces of capabilities.
61 #ifndef _IPC_IPC_SPACE_H_
62 #define _IPC_IPC_SPACE_H_
65 #include <mach/mach_types.h>
66 #include <mach/boolean.h>
67 #include <mach/kern_return.h>
68 #include <mach/vm_types.h>
70 #include <sys/appleapiopts.h>
72 #ifdef __APPLE_API_PRIVATE
73 #ifdef MACH_KERNEL_PRIVATE
75 #include <kern/macro_help.h>
76 #include <kern/kern_types.h>
77 #include <kern/lock.h>
78 #include <kern/task.h>
79 #include <kern/zalloc.h>
80 #include <ipc/ipc_entry.h>
81 #include <ipc/ipc_splay.h>
82 #include <ipc/ipc_types.h>
85 * Every task has a space of IPC capabilities.
86 * IPC operations like send and receive use this space.
87 * IPC kernel calls manipulate the space of the target task.
89 * Every space has a non-NULL is_table with is_table_size entries.
90 * A space may have a NULL is_tree. is_tree_small records the
91 * number of entries in the tree that, if the table were to grow
92 * to the next larger size, would move from the tree to the table.
94 * is_growing marks when the table is in the process of growing.
95 * When the table is growing, it can't be freed or grown by another
96 * thread, because of krealloc/kmem_realloc's requirements.
100 typedef natural_t ipc_space_refs_t
;
103 decl_mutex_data(,is_ref_lock_data
)
104 ipc_space_refs_t is_references
;
106 decl_mutex_data(,is_lock_data
)
107 boolean_t is_active
; /* is the space alive? */
108 boolean_t is_growing
; /* is the space growing? */
109 ipc_entry_t is_table
; /* an array of entries */
110 ipc_entry_num_t is_table_size
; /* current size of table */
111 struct ipc_table_size
*is_table_next
; /* info for larger table */
112 struct ipc_splay_tree is_tree
; /* a splay tree of entries */
113 ipc_entry_num_t is_tree_total
; /* number of entries in the tree */
114 ipc_entry_num_t is_tree_small
; /* # of small entries in the tree */
115 ipc_entry_num_t is_tree_hash
; /* # of hashed entries in the tree */
116 boolean_t is_fast
; /* for is_fast_space() */
119 #define IS_NULL ((ipc_space_t) 0)
121 extern zone_t ipc_space_zone
;
123 #define is_alloc() ((ipc_space_t) zalloc(ipc_space_zone))
124 #define is_free(is) zfree(ipc_space_zone, (is))
126 extern ipc_space_t ipc_space_kernel
;
127 extern ipc_space_t ipc_space_reply
;
129 extern ipc_space_t ipc_space_remote
;
132 extern ipc_space_t default_pager_space
;
133 #endif /* DIPC || MACH_KDB */
135 #define is_fast_space(is) ((is)->is_fast)
137 #define is_ref_lock_init(is) mutex_init(&(is)->is_ref_lock_data, 0)
139 #define ipc_space_reference_macro(is) \
141 mutex_lock(&(is)->is_ref_lock_data); \
142 assert((is)->is_references > 0); \
143 (is)->is_references++; \
144 mutex_unlock(&(is)->is_ref_lock_data); \
147 #define ipc_space_release_macro(is) \
149 ipc_space_refs_t _refs; \
151 mutex_lock(&(is)->is_ref_lock_data); \
152 assert((is)->is_references > 0); \
153 _refs = --(is)->is_references; \
154 mutex_unlock(&(is)->is_ref_lock_data); \
160 #define is_lock_init(is) mutex_init(&(is)->is_lock_data, 0)
162 #define is_read_lock(is) mutex_lock(&(is)->is_lock_data)
163 #define is_read_unlock(is) mutex_unlock(&(is)->is_lock_data)
164 #define is_read_sleep(is) thread_sleep_mutex((event_t)(is), \
165 &(is)->is_lock_data, \
168 #define is_write_lock(is) mutex_lock(&(is)->is_lock_data)
169 #define is_write_lock_try(is) mutex_try(&(is)->is_lock_data)
170 #define is_write_unlock(is) mutex_unlock(&(is)->is_lock_data)
171 #define is_write_sleep(is) thread_sleep_mutex((event_t)(is), \
172 &(is)->is_lock_data, \
175 #define is_reference(is) ipc_space_reference(is)
176 #define is_release(is) ipc_space_release(is)
178 #define is_write_to_read_lock(is)
180 #define current_space_fast() (current_task_fast()->itk_space)
181 #define current_space() (current_space_fast())
183 /* Create a special IPC space */
184 extern kern_return_t
ipc_space_create_special(
185 ipc_space_t
*spacep
);
187 /* Create new IPC space */
188 extern kern_return_t
ipc_space_create(
189 ipc_table_size_t initial
,
190 ipc_space_t
*spacep
);
192 /* Mark a space as dead and cleans up the entries*/
193 extern void ipc_space_destroy(
196 /* Clean up the entries - but leave the space alive */
197 extern void ipc_space_clean(
200 #endif /* MACH_KERNEL_PRIVATE */
201 #endif /* __APPLE_API_PRIVATE */
203 #ifdef __APPLE_API_UNSTABLE
204 #ifndef MACH_KERNEL_PRIVATE
206 extern ipc_space_t
current_space(void);
208 #endif /* !MACH_KERNEL_PRIVATE */
209 #endif /* __APPLE_API_UNSTABLE */
211 /* Take a reference on a space */
212 extern void ipc_space_reference(
215 /* Realase a reference on a space */
216 extern void ipc_space_release(
219 #endif /* _IPC_IPC_SPACE_H_ */