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