xref: /trueos/sys/sys/mach/ipc/ipc_space.h (revision c618297218800e84f1cdd1070cad32c285e84a86)
1 /*
2  * Copyright 1991-1998 by Open Software Foundation, Inc.
3  *              All Rights Reserved
4  *
5  * Permission to use, copy, modify, and distribute this software and
6  * its documentation for any purpose and without fee is hereby granted,
7  * provided that the above copyright notice appears in all copies and
8  * that both the copyright notice and this permission notice appear in
9  * supporting documentation.
10  *
11  * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
12  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13  * FOR A PARTICULAR PURPOSE.
14  *
15  * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
16  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17  * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
18  * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
19  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21 /*
22  * MkLinux
23  */
24 /* CMU_HIST */
25 /*
26  * Revision 2.7  91/06/17  15:46:29  jsb
27  * 	Renamed NORMA conditionals.
28  * 	[91/06/17  10:45:36  jsb]
29  *
30  * Revision 2.6  91/05/14  16:36:57  mrt
31  * 	Correcting copyright
32  *
33  * Revision 2.5  91/03/16  14:48:45  rpd
34  * 	Added is_growing.
35  * 	[91/03/04            rpd]
36  *
37  * Revision 2.4  91/02/05  17:23:48  mrt
38  * 	Changed to new Mach copyright
39  * 	[91/02/01  15:51:32  mrt]
40  *
41  * Revision 2.3  90/09/28  16:55:23  jsb
42  * 	Added NORMA_IPC support.
43  * 	[90/09/28  14:04:12  jsb]
44  *
45  * Revision 2.2  90/06/02  14:51:43  rpd
46  * 	Created for new IPC.
47  * 	[90/03/26  21:03:27  rpd]
48  *
49  */
50 /* CMU_ENDHIST */
51 /*
52  * Mach Operating System
53  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
54  * All Rights Reserved.
55  *
56  * Permission to use, copy, modify and distribute this software and its
57  * documentation is hereby granted, provided that both the copyright
58  * notice and this permission notice appear in all copies of the
59  * software, derivative works or modified versions, and any portions
60  * thereof, and that both notices appear in supporting documentation.
61  *
62  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
63  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
64  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
65  *
66  * Carnegie Mellon requests users of this software to return to
67  *
68  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
69  *  School of Computer Science
70  *  Carnegie Mellon University
71  *  Pittsburgh PA 15213-3890
72  *
73  * any improvements or extensions that they make and grant Carnegie Mellon
74  * the rights to redistribute these changes.
75  */
76 /*
77  */
78 /*
79  *	File:	ipc/ipc_space.h
80  *	Author:	Rich Draves
81  *	Date:	1989
82  *
83  *	Definitions for IPC spaces of capabilities.
84  */
85 
86 #ifndef	_IPC_IPC_SPACE_H_
87 #define _IPC_IPC_SPACE_H_
88 
89 #include <sys/mach/kern_return.h>
90 
91 #include <vm/uma.h>
92 #include <sys/mach/ipc/ipc_entry.h>
93 #include <sys/mach/ipc/ipc_types.h>
94 #include <sys/lock.h>
95 #include <sys/rwlock.h>
96 
97 /*
98  *	Every task has a space of IPC capabilities.
99  *	IPC operations like send and receive use this space.
100  *	IPC kernel calls manipulate the space of the target task.
101  *
102  *	Every space has a non-NULL is_table with is_table_size entries.
103  *	A space may have a NULL is_tree.  is_tree_small records the
104  *	number of entries in the tree that, if the table were to grow
105  *	to the next larger size, would move from the tree to the table.
106  *
107  *	is_growing marks when the table is in the process of growing.
108  *	When the table is growing, it can't be freed or grown by another
109  *	thread, because of krealloc/kmem_realloc's requirements.
110  *
111  */
112 
113 typedef natural_t ipc_space_refs_t;
114 
115 struct ipc_space {
116 	decl_mutex_data(,is_ref_lock_data)
117 	ipc_space_refs_t is_references;
118 	LIST_HEAD(, ipc_entry) is_entry_list;
119 	struct rwlock is_lock_data;
120 	boolean_t is_active;		/* is the space alive? */
121 	boolean_t is_growing;		/* is the space growing? */
122 	ipc_entry_t *is_table;		/* an array of entries */
123 	ipc_entry_num_t is_table_size;	/* current size of table */
124 	struct ipc_table_size *is_table_next; /* info for larger table */
125 	task_t is_task;
126 	ipc_entry_num_t is_tree_total;	/* number of entries in the tree */
127 	ipc_entry_num_t is_tree_small;	/* # of small entries in the tree */
128 	ipc_entry_num_t is_tree_hash;	/* # of hashed entries in the tree */
129 	boolean_t is_fast;              /* for is_fast_space() */
130 };
131 
132 #define	IS_NULL			((ipc_space_t) 0)
133 
134 extern uma_zone_t ipc_space_zone;
135 
136 #define is_alloc()		((ipc_space_t) uma_zalloc(ipc_space_zone, M_WAITOK))
137 #define	is_free(is)		uma_zfree(ipc_space_zone, (is))
138 
139 extern ipc_space_t ipc_space_kernel;
140 extern ipc_space_t ipc_space_reply;
141 
142 #define is_fast_space(is)	((is)->is_fast)
143 
144 #define	is_ref_lock_init(is)	mach_mutex_init(&(is)->is_ref_lock_data, \
145 					   "ETAP_IPC_IS_REF")
146 
147 #define	ipc_space_reference_macro(is)					\
148 MACRO_BEGIN								\
149 	mtx_lock(&(is)->is_ref_lock_data);				\
150 	assert((is)->is_references > 0);				\
151 	(is)->is_references++;						\
152 	mtx_unlock(&(is)->is_ref_lock_data);				\
153 MACRO_END
154 
155 #define	ipc_space_release_macro(is)					\
156 MACRO_BEGIN								\
157 	ipc_space_refs_t _refs;						\
158 									\
159 	mtx_lock(&(is)->is_ref_lock_data);				\
160 	assert((is)->is_references > 0);				\
161 	_refs = --(is)->is_references;					\
162 	mtx_unlock(&(is)->is_ref_lock_data);				\
163 									\
164 	if (_refs == 0)							\
165 		is_free(is);		\
166 MACRO_END
167 #define	is_lock_init(is)	rw_init(&(is)->is_lock_data, "ETAP_IPC_IS")
168 
169 #define	is_read_lock(is)	rw_rlock(&(is)->is_lock_data)
170 #define is_read_unlock(is)	rw_runlock(&(is)->is_lock_data)
171 
172 #define	is_write_lock(is)	rw_wlock(&(is)->is_lock_data)
173 #define	is_write_lock_try(is)	rw_trywlock(&(is)->is_lock_data)
174 #define is_write_unlock(is)	rw_wunlock(&(is)->is_lock_data)
175 
176 #define	is_write_to_read_lock(is) rw_downgrade(&(is)->is_lock_data)
177 
178 
179 /* Take a reference on a space */
180 extern void ipc_space_reference(
181 	ipc_space_t	space);
182 
183 /* Realase a reference on a space */
184 extern void ipc_space_release(
185 	ipc_space_t	space);
186 
187 #define	is_reference(is)	ipc_space_reference(is)
188 #define	is_release(is)		ipc_space_release(is)
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 /* Create a special IPC space */
196 extern kern_return_t ipc_space_create_special(
197 	ipc_space_t	*spacep);
198 
199 /* Mark a space as dead and cleans up the entries*/
200 extern void ipc_space_destroy(
201 	ipc_space_t	space);
202 
203 #endif	/* _IPC_IPC_SPACE_H_ */
204